var extraHttp = null;
var extraController = 0;

function silent_post(){

	extraController = 1;

	var text2 = "fname=" + encodeURIComponent(element("fname").value);
	text2 += "&lname=" + encodeURIComponent(element("lname").value);
	text2 += "&email=" + encodeURIComponent(element("email").value);
	var o = element("gender");
	var gender = o.options[o.selectedIndex].value
	text2 += "&gender=" + encodeURIComponent(gender);
	text2 += "&address=" + encodeURIComponent(element("addr").value);
	text2 += "&city=" + encodeURIComponent(element("city").value);
	text2 += "&state=" + encodeURIComponent(element("state").value);
	text2 += "&zip=" + encodeURIComponent(element("zip").value);
	var phone = element("phone1").value + element("phone2").value + element("phone3").value
	text2 += "&phone=" + encodeURIComponent(phone);
	o = element("birth_day");
	var birth_day = o.options[o.selectedIndex].value;
	o = element("birth_month");
	var birth_month = o.options[o.selectedIndex].value;
	o = element("birth_year");
	var birth_year = o.options[o.selectedIndex].value;
	var dob = birth_year + "-" + birth_month + "-" + birth_day
	text2 += "&dob=" + encodeURIComponent( dob );

	//below codes added to handle hidden field
	text2 += "&url=" + encodeURIComponent(element("myurl").value);
	text2 += "&ip=" + encodeURIComponent(element("myip").value);
	text2 += "&act_date=" + encodeURIComponent(element("mydt").value);
	text2 += "&own_rent=" + encodeURIComponent(element("myownrent").value);
	text2 += "&military=" + encodeURIComponent(element("mymilitary").value);
	text2 += "&listcode=" + encodeURIComponent(element("mylistcode").value);
	text2+="&address2=";

	url="handleProcess.php?"+text2;

	new Ajax.Request(url, {
	  method: 'get',
	  asynchronous:false,
	  onComplete: function(transport){
		extraController = 2;
		submit_form();
	}});

}

function extraHandler(){
	if(extraHttp.readyState == 4){
		extraController = 2;
		submit_form();
	}
}

function populate_hidden(){

	//for(i = 0; i < 9999999; i++)
	//	m = 1;

	//e1 = document.getElementById("myurl");
	//e1.value = window.location;

	if (typeof window.ActiveXObject != 'undefined'){
   		extraHttp = new ActiveXObject("Microsoft.XMLHTTP");
   	}
   	else
   		extraHttp = new XMLHttpRequest();


	extraHttp.onreadystatechange = extraHandler2;

   	url = "fetchinfo.php";

   	extraHttp.open('GET',url,true);
   	extraHttp.send(null);
}

function extraHandler2(){
	if(extraHttp.readyState == 4){

		myVar = extraHttp.responseText.split("|");
		e1 = document.getElementById("myip");
		e1.value = myVar[0];

		e1 = document.getElementById("mydt");
		e1.value = myVar[1];

		e1 = document.getElementById("myurl");
		e1.value = window.location;

	}
}

function load_element1( id, xhtml, script, post_function ){
	if ( xhtml.length > 0 ){

		get_http(xhtml,
			//done
			function(text){
				element(id).innerHTML = text;

				if (script.length > 0 ){
					include(script);
				}

					if(post_function == 1){
						//START:add in this block by Jimmy to populate hidden field
						populate_hidden();
						//END:add in this block by Jimmy to populate hidden field
					}

			},
			//receiving
			function(){
				element(id).innerHTML = "<div class=\"loading\">Receiving...</div>";
			},
			//waiting
			function(){
				element(id).innerHTML = "<div class=\"loading\">Waiting...</div>";
			},
			//sending
			function(){
				element(id).innerHTML = "<div class=\"loading\">Sending...</div>";
			}
		);
	}



}

