// JScript File

function addContactUs()
{
    hideImage('b4Submit2');
    var req1 = newXMLHttpRequest();
    req1.onreadystatechange = getReadyStateHandler(req1, showPCResult);    
    var str="show=1";
    str += "&txtFirstName=" + getValue(document.getElementById("txtFirstName"));
	str += "&txtEmail=" + getValue(document.getElementById("txtEmail"));
	str += "&txtPhone=" + getValue(document.getElementById("txtPhone"));
	str += "&txtBusinessName=" + getValue(document.getElementById("txtBusinessName"));
	str += "&txtPointOfSale=" + getValue(document.getElementById("txtPointOfSale"));
	str += "&txtAreasOfInterest=" + getValue(document.getElementById("txtAreasOfInterest"));
	str += "&rdoContactMethod=" + get_radio_value();
	str += "&txtBestTimeToCall=" + getValue(document.getElementById("txtBestTimeToCall"));
	
    req1.open("POST", "ContactUsPage.aspx");
    req1.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    req1.send(str);
    //alert(str);
    return false;
}


function get_radio_value()
{
var rad_val="";	
for (var i=0; i < document.Form.rdoContactMethod.length; i++)
   {
   if (document.Form.rdoContactMethod[i].checked)
      {
      rad_val = document.Form.rdoContactMethod[i].value;
      }
   }
	return rad_val;
}


function showPCResult(_msg)
{
    document.getElementById("dvContactUsMsg").innerHTML=_msg;
    //alert(_msg);
    if(_msg.indexOf("successfully")>=0)
    {
		setValue(document.getElementById("txtFirstName"),'');
        setValue(document.getElementById("txtEmail"),'');
        setValue(document.getElementById("txtPhone"),'');
        setValue(document.getElementById("txtBusinessName"),'');
        setValue(document.getElementById("txtPointOfSale"),'');
        setIndex(document.getElementById("txtAreasOfInterest"));
        setValue(document.getElementById("txtBestTimeToCall"),'');       
    }	
    showImage('b4Submit2');	
}

/*
 * Returns an new XMLHttpRequest object, or false if the browser
 * doesn't support it
 */
function newXMLHttpRequest() {

  var xmlreq = false;

  // Create XMLHttpRequest object in non-Microsoft browsers
  if (window.XMLHttpRequest) {
    xmlreq = new XMLHttpRequest();

  } else if (window.ActiveXObject) {

    try {
      // Try to create XMLHttpRequest in later versions
      // of Internet Explorer

      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
      
    } catch (e1) {

      // Failed to create required ActiveXObject
      
      try {
        // Try version supported by older versions
        // of Internet Explorer
      
        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (e2) {

        // Unable to create an XMLHttpRequest by any means
        xmlreq = false;
      }
    }
  }

return xmlreq;
}

 /*
	* Returns a function that waits for the specified XMLHttpRequest
	* to complete, then passes it XML response to the given handler function.
  * req - The XMLHttpRequest whose state is changing
  * responseXmlHandler - Function to pass the XML response to
  */
 function getReadyStateHandler(req, responseXmlHandler) {

   // Return an anonymous function that listens to the XMLHttpRequest instance
   return function () {

     // If the request's status is "complete"
     if (req.readyState == 4) {
       
       // Check that we received a successful response from the server
       if (req.status == 200) {

         // Pass the XML payload of the response to the handler function.
         responseXmlHandler(req.responseText ? req.responseText : req.responseXML);

       } else {

         // An HTTP problem has occurred
         alert("HTTP error "+req.status+": "+req.statusText);
       }
     }
   }
 }

function showImage(imgId1)
{
    var img1 = document.getElementById(imgId1);
    window.setTimeout(function(){img1.style.visibility = 'visible'; }, 200);
}
function hideImage(imgId1)
{
    var img1 = document.getElementById(imgId1);
    window.setTimeout(function(){img1.style.visibility = 'hidden'; }, 200);
}



function getValue(obj1)
{
	var strVal='';
	if(obj1) {strVal = obj1.value;}
	return strVal;
}

function getText(obj1)
{
	var strVal='';
	if(obj1) {strVal = obj1.text;}
	return strVal;
}


function setValue(obj1,stVal)
{
	var strVal=stVal;
	if(obj1) {obj1.value = strVal;}
}


function setIndex(obj1)
{
	if(obj1) {obj1.selectedIndex = 0;}
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

//alert("Ajax page Selectd");
