function getInData() {
    var urlparams = "";
	urlparams = urlparams+"email=" + encodeURIComponent(document.getElementById("myanc").value);
	urlparams = urlparams+"&fname=" + encodeURIComponent(document.getElementById("fname").value);
	urlparams = urlparams+"&sname=" + encodeURIComponent(document.getElementById("sname").value);
	urlparams = urlparams+"&tel=" + encodeURIComponent(document.getElementById("tel").value);
	urlparams = urlparams+"&loc=" + encodeURIComponent(document.getElementById("loc").value);
	urlparams = urlparams+"&level=" + encodeURIComponent(document.getElementById("interest").value);
	urlparams = urlparams+"&web=" + encodeURIComponent(document.getElementById("web").value);
	return urlparams;
}

function actOnResult(responseXML) {

   var msg = responseXML.getElementsByTagName("msg")[0].firstChild.nodeValue;

	document.getElementById('ajaxresult').innerHTML = msg;
	document.getElementById('actform').className = "norm";
}
function CheckEmail(email) {
	if (email == "") return false;
	AtPos = email.indexOf("@")
	StopPos = email.lastIndexOf(".")
	if (AtPos < 1) return false;
	if (StopPos < (AtPos+3)) return false;
	if(StopPos > (email.length-3)) return false;
	return true;
}
function doVal() {
	var bad=0;
	var msg = "Please complete all details";
	if(CheckEmail(document.getElementById('myanc').value)==false) {
		bad=1;
		msg = "Invalid Email address";
		}
	if(document.getElementById('fname').value == "") bad=1;
	if(document.getElementById('sname').value == "") bad=1;
	if(document.getElementById('tel').value == "") bad=1;
	if(document.getElementById('loc').value == "") bad=1;
	if(document.getElementById('interest').value == "Please choose") bad=1;
	if(bad==1) {
		document.getElementById('ajaxsubmit').disabled = true;
		document.getElementById('ajaxsubmit').className = "fade";
		document.getElementById('ajaxmsg').innerHTML = msg;
		document.getElementById('ajaxmsg').className = "ajaxStop";
		}
	else {
		document.getElementById('ajaxmsg').className = "hide";
		document.getElementById('ajaxsubmit').className = "norm";
		document.getElementById('ajaxsubmit').disabled = false;
		}
}
function doButton() {
	document.getElementById('ajaxsubmit').disabled = true;
	document.getElementById('actform').className = "fade";
	document.getElementById('ajaxmsg').innerHTML = "<strong style=\"font-size: 24px;\">WORKING...</strong>";
	doAjax();
}

/* Generic AJAX function below ======== NO NEED TO EDIT BELOW =================================================*/

function createRequestObject(url, callback) {

    var req = init();
    req.onreadystatechange = processRequest;
        
    function init() {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    
    function processRequest () {
      if (req.readyState == 4) { // readyState of 4 signifies request is complete
        if (req.status == 200) { // status of 200 signifies sucessful HTTP call
          if (callback) callback(req.responseXML);
        }
      }
    }

    this.doGet = function() {
      req.open("GET", url, true);
      req.send(null);
    }
}

function doAjax(){
	var url = 'http://www.gianthand.com/ajax.php?' + getInData();
    var ajax = new createRequestObject(url, actOnResult); 
    ajax.doGet();
}
