var Eight = {
        send2phoneUrl: 'http://wap1.go2.com/corp/send2phone/send2phone.php',
	xmlHttp: '',
	xmlResponse: '',

        clearPhn: function()
        {
		document.getElementById("phn").value = "";
        },
        wapPushForm: function() {
		if (null == document.getElementById("message")){
			alert('Development Error: this widget requires an object with an id of "message" in order to write status messages.');
			return false;
		}
                var phoneNumber = document.getElementById("phn").value;
                if(phoneNumber == '') {
                        alert('Please enter a valid phone number.');
                        return false;
                } else {

                        var rePhoneNumber = new RegExp(/^[1-9]\d{2}\s?\d{3}\d{4}$/);
                        if (!rePhoneNumber.test(phoneNumber)) {
                                alert('Please enter a valid phone number.');
                                return false;
                        }
                }
		try {
			// Firefox, Opera 8.0+, Safari
			Eight.xmlHttp=new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				Eight.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					Eight.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		var smsTextId = (null != document.getElementById("smsTextId").value) ? document.getElementById("smsTextId").value : "Default";
		Eight.send2phoneUrl = Eight.send2phoneUrl + "?phn=" + document.getElementById("phn").value + "&smsTextId=" + smsTextId;
		document.getElementById("message").innerHTML = '<p class="smswaplink">Sending Text...</p>';
		if (null != document.getElementById("debug")) alert(Eight.send2phoneUrl);
		Eight.xmlHttp.open("GET", Eight.send2phoneUrl, true);
		Eight.xmlHttp.onreadystatechange=function()
		{
			if (Eight.xmlHttp.readyState==4 || Eight.xmlHttp.readyState=="complete")
			{
				if (null != document.getElementById("debug")) alert(Eight.xmlHttp.responseText);
				try //Internet Explorer
				{
					Eight.xmlResponse = new ActiveXObject("Microsoft.XMLDOM");
				  	Eight.xmlResponse.async="false";
				  	Eight.xmlResponse.loadXML(Eight.xmlHttp.responseText);
				}
				catch(e)
				{
				  	try //Firefox, Mozilla, Opera, etc.
				  	{
						parser=new DOMParser();
						Eight.xmlResponse = parser.parseFromString(Eight.xmlHttp.responseText,"text/xml");
					}
					catch(e) {
						alert("Your browser does not support AJAX!");
						return false;
					}
				}

				if (null != document.getElementById("debug")) alert(Eight.xmlResponse);
				var oStatusColl = Eight.xmlResponse.getElementsByTagName("status");
				if (null != oStatusColl.length && oStatusColl.length > 0){
					var sCode = oStatusColl.item(0).getAttribute("code");
					if (sCode == "1"){
						document.getElementById("message").innerHTML = '<p class="smswaplink">Message sent.</p>';
					} else {
						document.getElementById("message").innerHTML = '<p class="smswaplink">Error. Try again. (Error code:' + sCode + ')</p>';
					}
				} else {
					document.getElementById("message").innerHTML = '<p class="smswaplink">Can\'t connect to server. Try again.</p>';
				}
			}
		}
		Eight.xmlHttp.send(null);
        }

}
