var popupStatus = 0;
var actionTaken = false;
var t;
var popupOn = true;
var formlayer = 1;
var errorDone = false;

$(document).ready(function(){	
    //$('.field.text.inline.phonesi').mask("999-999-9999? x999999");  
	var contentHeight;
	var action = 0;
	
	/*contentHeight = (parseInt($("#content").css('height'))-723)+"px";
		$("#content").css({
			height: contentHeight  
		});
	contentHeight = (parseInt($("#noformContent").css('height'))-723)+"px";	
		$("#noformContent").css({
			height: contentHeight  
		});*/
		
	preload_image = new Image(25,25); 
    preload_image.src="images/images/form_bck2.png"; 
		
	$("#button").click(function(){
		actionTaken = false;
		clearTimeout(t);
		send();
	});

	$("#okbutton").click(function(){
		disablePopup();
		clearTimeout(t);
		actionTaken = true;					  
	});
	
	$(".formerror").css("visibility", "visible");
	$(".formerror").hide();
	
	$(".formerror").css("height", "auto");
	$(".formerror").css("overflow", "auto");
	
	$(".callaction").click(function() {
		if (action == 0) {
			$('.rightPanel').animate({ backgroundColor: '#555555'}, 250);
			action = 1;
		} else if (action == 1) {
			$('.rightPanel').animate({ backgroundColor: '#DADADA'}, 250);
			action = 0;
		}
	});
	//$(".callaction").click(function() {
		//$('.formBorder').css({
			//'background-image': 'url(images/form_bck2.png)'
		//}); 								
	//});

	

});

function Xhttp(url, postinfo) {
	//alert(url);
    if(window.XMLHttpRequest) {
    	try {
			xmlhttp = new XMLHttpRequest();
        } catch(e) {
			xmlhttp = false;
        }

    } else if(window.ActiveXObject) {
       	try {
        	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		xmlhttp = false;
        	}
		}
    }
	if(xmlhttp) {
		xmlhttp.open('POST', url, true);
		
		xmlhttp.onreadystatechange = function() {
	    	if (xmlhttp.readyState == 4) {
				var msg = xmlhttp.responseText;
				//alert(msg);
			}
	    }
	}
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(postinfo);
}

function send() {
	return true;
	/*
	var emailcheck = verifyEmail();
	//fieldC();
	if (errorDone || formlayer == 1 && emailcheck == true && document.getElementById('fname') != "") {
		Xhttp("senddata.php?fname="+document.getElementById('fname').value+"&email="+document.getElementById('email').value+"&phone="+document.getElementById('phone').value+"&formid=1", null);
		document.getElementById('phoneduplicate').value = document.getElementById('phone').value;
		document.getElementById('main-signup-form').submit();
	} else {
		var name = document.getElementById('fname').value;
		var fillin = "The following fields have not been filled out correctly:<ul>";
		var errors = 0;
		errorDone = true;
		if (document.getElementById('fname').value == "") {
			fillin = fillin + "<li>Your First Name</li>";
			errors = errors + 1;
			$(".trname").css({
				"background-color": "#fff692"
			});
			$(".field.text.inline.firsti").css({
				"background-color": "#fff692"
			});
		} else {
			$(".trname").css({
				"background-color": "inherit"
			});
			$(".field.text.inline.firsti").css({
				"background-color": "white"
			});
		}
		if (emailcheck == false) {
			errors = errors + 1;
			fillin = fillin + "<li>Your Email Address</li>";
			$(".tremail").css({
				"background-color": "#fff692"
			});
			$(".field.text.inline.emaili").css({
				"background-color": "#fff692"
			});
		} else {
			$(".tremail").css({
				"background-color": "inherit"
			});
			$(".field.text.inline.emaili").css({
				"background-color": "white"
			});
		}
		
		if (document.getElementById('phone').value == "") {
			errors = errors + 1;
			fillin = fillin + "<li>Your Phone Number</li>";
			$(".trphone").css({
				"background-color": "#fff692"
			});
			$(".field.text.inline.phonesi").css({
				"background-color": "#fff692"
			});
		} else {
			$(".trphone").css({
				"background-color": "inherit"
			});
			$(".field.text.inline.phonesi").css({
				"background-color": "white"
			});
		}
		
		if (document.getElementById('phone2').value == "") {
			errors = errors + 1;
			fillin = fillin + "<li>Your Phone Number</li>";
			$(".trphone2").css({
				"background-color": "#fff692"
			});
			$(".field.text.inline.phonesi2").css({
				"background-color": "#fff692"
			});
		} else {
			$(".trphone2").css({
				"background-color": "inherit"
			});
			$(".field.text.inline.phonesi2").css({
				"background-color": "white"
			});
		}
		
		if (document.getElementById('cell').value == "") {
			errors = errors + 1;
			fillin = fillin + "<li>Your Phone Number</li>";
			$(".trcell").css({
				"background-color": "#fff692"
			});
			$(".field.text.inline.cell").css({
				"background-color": "#fff692"
			});
		} else {
			$(".trcell").css({
				"background-color": "inherit"
			});
			$(".field.text.inline.cell").css({
				"background-color": "white"
			});
		}
		
		if (document.getElementById('btime').value == "") {
			errors = errors + 1;
			$(".trbtime").css({
				"background-color": "#fff692"
			});
			$(".field.text.inline.btimei").css({
				"background-color": "#fff692"
			});
		} else {
			$(".trbtime").css({
				"background-color": "inherit"
			});
			$(".field.text.inline.btimei").css({
				"background-color": "white"
			});
		}
		
		if (errors != 0) {
			$(".formerror").html("Please fill in the fields correctly.");
			$(".formerror").fadeIn("fast");
		}

		Xhttp("senddata.php?fname="+document.getElementById('fname').value+"&email="+document.getElementById('email').value+"&phone="+document.getElementById('phone').value+"&phone2="+document.getElementById('phone2').value+"&cell="+document.getElementById('cell').value+"&formid=1", null);
		//document.write("fname="+document.getElementById('fname').value+"&email="+document.getElementById('email').value+"&phone="+document.getElementById('phone').value);
	}*/
}

function sendagain() {
	if (!actionTaken) {
		document.getElementById('main-signup-form').submit();
	}
	actionTaken = false;
}

function verifyEmail(){
var status = false;     
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (document.getElementById('email').value.search(emailRegEx) == -1) {
		status = false; 
     } else {
          status = true;
     }
     return status;
}
