

// branding form with logo

function branding(){ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	 }

	var zip = document.getElementById("zip").value;
	var url="include/check.php?field=branding&zip="+zip;
	xmlHttp.onreadystatechange=brandingx;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// show branding

function brandingx() { 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		
		var zip = document.getElementById("zip").value;
		var info = xmlHttp.responseText;
		
		if (zip.length > 4){
			document.getElementById("branding").innerHTML = "<img src="+info+" height='50' width='180' border='0'>";			
			return false;
		}else{
			document.getElementById("branding").innerHTML = "";
		}

	}
}

//do we need to mark 11111,22222,33333,...... to non-enable?


// testing here - delete
//function showthis(){ 
//	xmlHttp=GetXmlHttpObject();
//	if (xmlHttp==null){
//		alert ("Browser does not support HTTP Request");
//		return;
//	 }
//
//	var url="include/check.php?field=showbrand";
//	xmlHttp.onreadystatechange=showthisx;
//	xmlHttp.open("GET",url,true);
//	xmlHttp.send(null);
//}
//
//// show branding
//function showthisx() { 
//	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
//			document.getElementById("showthis").innerHTML = xmlHttp.responseText;
//	}
//}




// checking age

function markage(){ 
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	 }

	var age = document.getElementById("age").selectedIndex;
	
	if (age == 0){
		document.getElementById("markagebad").style.visibility = "visible";
		document.getElementById("markagebad").style.display = "true";	
		document.getElementById("markagegood").style.visibility = "hidden";
		document.getElementById("markagegood").style.display = "false";	
	} else {
		document.getElementById("markagegood").style.visibility = "visible";
		document.getElementById("markagegood").style.display = "true";	
		document.getElementById("markagebad").style.visibility = "hidden";
		document.getElementById("markagebad").style.display = "false";	
	}

}


// checking income

function markincome(){ 
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	 }

	var income = document.getElementById("income").selectedIndex;
	
	if (income == 0){
		document.getElementById("markincomebad").style.visibility = "visible";
		document.getElementById("markincomebad").style.display = "true";	
		document.getElementById("markincomegood").style.visibility = "hidden";
		document.getElementById("markincomegood").style.display = "false";	
	} else {
		document.getElementById("markincomegood").style.visibility = "visible";
		document.getElementById("markincomegood").style.display = "true";	
		document.getElementById("markincomebad").style.visibility = "hidden";
		document.getElementById("markincomebad").style.display = "false";	
	}

}


// checking marital status

function markstatus(){ 
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	 }

	var my_mar_status = document.getElementById("my_mar_status").selectedIndex;
	
	if (my_mar_status == 0){
		document.getElementById("markstatusbad").style.visibility = "visible";
		document.getElementById("markstatusbad").style.display = "true";	
		document.getElementById("markstatusgood").style.visibility = "hidden";
		document.getElementById("markstatusgood").style.display = "false";	
	} else {
		document.getElementById("markstatusgood").style.visibility = "visible";
		document.getElementById("markstatusgood").style.display = "true";	
		document.getElementById("markstatusbad").style.visibility = "hidden";
		document.getElementById("markstatusbad").style.display = "false";	
	}

}


// checking first name

function markfname(){ 
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	 }

	var fname = document.getElementById("fname").value;
	
	if (fname == ""){
		document.getElementById("markfnamebad").style.visibility = "visible";
		document.getElementById("markfnamebad").style.display = "true";	
		document.getElementById("markfnamegood").style.visibility = "hidden";
		document.getElementById("markfnamegood").style.display = "false";	
	} else {
		document.getElementById("markfnamegood").style.visibility = "visible";
		document.getElementById("markfnamegood").style.display = "true";	
		document.getElementById("markfnamebad").style.visibility = "hidden";
		document.getElementById("markfnamebad").style.display = "false";	
	}

}


// checking last name

function marklname(){ 
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	 }

	var lname = document.getElementById("lname").value;
	
	if (lname == ""){
		document.getElementById("marklnamebad").style.visibility = "visible";
		document.getElementById("marklnamebad").style.display = "true";	
		document.getElementById("marklnamegood").style.visibility = "hidden";
		document.getElementById("marklnamegood").style.display = "false";	
	} else {
		document.getElementById("marklnamegood").style.visibility = "visible";
		document.getElementById("marklnamegood").style.display = "true";	
		document.getElementById("marklnamebad").style.visibility = "hidden";
		document.getElementById("marklnamebad").style.display = "false";	
	}

}


// checking email

function markemail(){ 
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	 }

	var email = document.getElementById("email").value;
	
	if (email == ""){		
		document.getElementById("markemailbad").style.visibility = "visible";
		document.getElementById("markemailbad").style.display = "true";	
		document.getElementById("markemailgood").style.visibility = "hidden";
		document.getElementById("markemailgood").style.display = "false";	
	} else {
		
		if (email != "" || email != "No Spam or Junk Email will be Sent"){
			var error = "";
			var tfld = trim(document.getElementById("email").value); // value of field with whitespace trimmed off
			var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
			var illegalChars= /[\'\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
			if (!emailFilter.test(tfld)) { //test email for illegal characters
				document.getElementById("markemailbad").style.visibility = "visible";
				document.getElementById("markemailbad").style.display = "true";	
				document.getElementById("markemailgood").style.visibility = "hidden";
				document.getElementById("markemailgood").style.display = "false";	
			} else if (document.getElementById("email").value.match(illegalChars)) {
				document.getElementById("markemailbad").style.visibility = "visible";
				document.getElementById("markemailbad").style.display = "true";	
				document.getElementById("markemailgood").style.visibility = "hidden";
				document.getElementById("markemailgood").style.display = "false";	
			
			}	else {
				
				document.getElementById("markemailgood").style.visibility = "visible";
				document.getElementById("markemailgood").style.display = "true";	
				document.getElementById("markemailbad").style.visibility = "hidden";
				document.getElementById("markemailbad").style.display = "false";	
			}
		
		}
	}
}


// checking occupation

function markoccupation(){ 
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	 }

	var occupation = document.getElementById("occupation").value;
	
	if (occupation == ""){
		document.getElementById("markoccupationbad").style.visibility = "visible";
		document.getElementById("markoccupationbad").style.display = "true";	
		document.getElementById("markoccupationgood").style.visibility = "hidden";
		document.getElementById("markoccupationgood").style.display = "false";	
	} else {
		document.getElementById("markoccupationgood").style.visibility = "visible";
		document.getElementById("markoccupationgood").style.display = "true";	
		document.getElementById("markoccupationbad").style.visibility = "hidden";
		document.getElementById("markoccupationbad").style.display = "false";	
	}
}


// checking main phone

function markmainphone(){ 
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	 }

	var mainPhoneArea = document.getElementById("mainPhoneArea").value;
	var mainPhone = document.getElementById("mainPhone").value;
	
	if (mainPhoneArea == "xxx"){
		mainPhoneArea = "";}

	if (mainPhone == "xxxxxxx"){
		mainPhone = "";}

	if (mainPhoneArea.length < 3 || mainPhone.length < 7){
		document.getElementById("markmainphonebad").style.visibility = "visible";
		document.getElementById("markmainphonebad").style.display = "true";	
		document.getElementById("markmainphonegood").style.visibility = "hidden";
		document.getElementById("markmainphonegood").style.display = "false";	
	} else {
		document.getElementById("markmainphonegood").style.visibility = "visible";
		document.getElementById("markmainphonegood").style.display = "true";	
		document.getElementById("markmainphonebad").style.visibility = "hidden";
		document.getElementById("markmainphonebad").style.display = "false";	
	}
}




// CHECK FORM 1 IN MARKET

function checkform1(){
	
	var msg = "";
	var age = document.getElementById("age").selectedIndex;
	var zip = document.getElementById("zip").value;
	var income = document.getElementById("income").selectedIndex;
	var my_mar_status = document.getElementById("my_mar_status").selectedIndex;
	var fname = document.getElementById("fname").value;
	var lname = document.getElementById("lname").value;
	var email = document.getElementById("email").value;
	var occupation = document.getElementById("occupation").value;
	var mainPhoneArea = document.getElementById("mainPhoneArea").value;
	var mainPhone = document.getElementById("mainPhone").value;
	
	var genderelemt = document.form1.elements["sex"];
	
	var gflag = 0;
	for(var i = 0; i < genderelemt.length; i++) {
		//alert(genderelemt[i].name);
		if(genderelemt[i].checked) {
			gflag = 1;
		}
	}
	
	if(gflag == 0) {
		msg = msg+"Please select the gender,\n";
	}

	if (zip == ""){
		msg = msg+"Please provide your Zip Code,\n";}
	
	if (age == 0){
		msg = msg+"Please provide your Age,\n";}

	if (income == 0){
		msg = msg+"Please provide your Income,\n";}

	if (my_mar_status == 0){
		msg = msg+"Please provide your Marital Status,\n";}

	if (fname == ""){
		msg = msg+"Please provide your First Name,\n";}

	if (lname == ""){
		msg = msg+"Please provide your Last Name,\n";}


	if (email == "" || email == "No Spam or Junk Email will be Sent"){
		msg = msg+"Please provide your Email Address,\n";}


	if (email != "" || email != "No Spam or Junk Email will be Sent"){
		var error = "";
		var tfld = trim(document.getElementById("email").value); // value of field with whitespace trimmed off
		var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
		var illegalChars= /[\'\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
		if (!emailFilter.test(tfld)) { //test email for illegal characters
			msg = msg+"Please provide a valid Email Address,\n";
		} else if (document.getElementById("email").value.match(illegalChars)) {
			msg = msg+"Please provide a valid Email Address,\n";
		}
	}


	if (occupation == ""){
		msg = msg+"Please provide your Occupation,\n";}

	if (mainPhoneArea == "" || mainPhoneArea == "xxx"){
		msg = msg+"Please provide your Area Code,\n";}

	if (mainPhone == "" || mainPhone == "xxxxxxx"){
		msg = msg+"Please provide your Main Phone Number,\n";}


	if (msg != ""){
		var url = "_alerts.php?msg=" + msg;	
		url = url + "&KeepThis=true&TB_iframe=true&width=300&height=175";
		tb_show("Wait a minute! We're missing some details ...", url);
		return false
	}
}




// GENERAL FUNCTIONS DOWN HERE


// necessities first

var xmlHttp;
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	//Internet Explorer
	try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
			catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
}
return xmlHttp;
}



// auto cursor to next field

	function movenext(field,nextFieldID){
	  if(field.value.length >= field.maxLength){
		document.getElementById(nextFieldID).focus();
	  }
	}


// populate field with text and remove on entry of field

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}


// numbers only

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	
	// decimal point jump
	else if (dec && (keychar == "."))
	   {
	   myfield.form.elements[dec].focus();
	   return false;
	   }
	else
	   return false;
}



// letters only

function alpha(e) {
//     var k;
//     document.all ? k = e.keyCode : k = e.which;
//	
//	if ((key==null) || (key==0) || (key==8) || 
//		(key==9) || (key==13) || (key==27) ||
//		(k > 64 && k < 91) || (k > 96 && k < 123) || (k == 8))
//		return true;
	}



// removing spaces

function trim(s){
  return s.replace(/^\s+|\s+$/, '');
}
