// JavaScript Document



function radioSet(x)  {

	if(x.checked == true)  {

		document.getElementById('rBronze').checked = true;

		document.getElementById('rSilver').checked = true;

		document.getElementById('rGold').checked = true;

		document.getElementById('rPlat').checked = true;

	}

}





function reps(x) {

	var y,z1,z2;

	y=x.numberRep.value;



	for(z2=1;z2<=y;z2++)  {



		eval('document.getElementById("sp' + z2 + '").style.display = "inline"');

		eval('document.getElementById("Rep' + z2 + '").innerHTML="Representative ' + z2 + '"');

		eval('document.getElementById("Rep' + z2 + 'A").innerHTML="Lunch Ticket"');

	}

	for(z3=z2; z3<13; z3++)  {

		eval('document.getElementById("sp' + z3 + '").style.display = "none"');

		eval('document.getElementById("Rep' + z3 + '_Lunch").checked = false');

	}

		totLunch(x);

}



function totLunch(x)  {



	var booth1 = parseFloat(x.Booths_10x10.value);

	var booth2 = parseFloat(x.Booths_20x10.value);

	var boothTot = booth1 + booth2;

//alert("booth1 = " + booth1 + ", booth2 = " + booth2 + ", boothTot = " + boothTot);

	var lnchCompl = boothTot * 2;

//		x.Complmentary_Lunch.value = lnchCompl;

	var y = parseFloat(x.numberRep.value);



	var count = 0;

	var lnchExtra = 0;

	for (ctr=1; ctr<=y ; ctr++) {   //How many lunches requested total

		ReqLn = eval('x.Rep' + ctr + '_Lunch.checked');

		if(ReqLn == true)  {

			count++;

		}

	}

	if(count<lnchCompl)  {

		var lnchCom = count;

	}

		else {

			var lnchCom = lnchCompl;

		}

	document.getElementById("lnch1").innerHTML = "&nbsp;" + lnchCom + "&nbsp;";

	x.Complement_Lunches.value = lnchCom;

	if (count > lnchCompl) {

		var lnchExtra = count - lnchCompl;

	}

	x.Additional_Lunches.value = lnchExtra;

	document.getElementById("lnch2").innerHTML = "&nbsp;" + lnchExtra + "&nbsp;";



}



function setLunch(rep)  {

	z = rep.id;



	var y;

	var xLoc1 = z.lastIndexOf("_");

	var xLoc2 = z.substring(xLoc1 + 1);

	eval("y = 'Rep" + xLoc2 + "_Lunch'");

	document.getElementById(y).checked = true;

	var x = document.getElementById("Contact_Form");

	totLunch(x);



}



var Vname = new Array(

		"Company_Name",

		"Company_Address",

		"Company_City",

		"Company_State",

		"Company_ZIP",

		"Company_Authorized",

		"Company_AreaCode",

		"Company_FirstThree",

		"Company_LastFour",

		"Contact_Name",

		"Contact_Address",

		"Contact_City",

		"Contact_State",

		"Contact_ZIP",

		"Contact_AreaCode",

		"Contact_FirstThree",

		"Contact_LastFour");



var Vmsg = new Array(

		"You must enter the Company Name to complete this Application",

		"You Must enter your Company\'s Address  to complete this Application",

		"You must enter your company\'s City  to complete this Application",

		"You must enter your State to complete this Application",

		"You must enter your ZIP Code to complete this Application",

		"You must enter the Name of the Authorizing person to complete this Application",

		"You must enter your Area Code to complete this Application",

		"You must enter your Phone Number to complete this Application",

		"You must enter your Phone Number to complete this Application",

		"You must enter a Contact Name to complete this Application",

		"You must enter the Contact Person\'s Address to complete this Application",

		"You must enter the Contact Person\'s City to complete this Application",

		"You must enter the Contact Person\'s State to complete this Application",

		"You must enter the Contact Person\'s State to complete this application",

		"You must enter the Contact Person\'s Area Code to complete this Application",

		"You must enter the Contact Person\'s Phone number to complete this Application",

		"You must enter the Contact Person\'s Phone Number to complete this Application");



function validateEmail(elementValue){      

   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

   return emailPattern.test(elementValue); 

 }



function validate(x,valid)  {

	

	var ctrLn = Vname.length;

	var z;

		for (ctr=0;ctr<ctrLn;ctr++)  {

			z = Vname[ctr];

			if(x[z].value == "")  {

				valid="false";

				x[z].focus();

				alert(Vmsg[ctr]);

				break;

			}

		}



	chkEmail = x.Company_Email.value;

		if(!validateEmail(chkEmail) && valid == "true")  {

			alert("The Company Email address you entered is not valid.  Please re-enter.");

			x.Company_Email.focus();

			valid = "false";

			}

	chkEmail = x.Contact_Email.value;

		if(!validateEmail(chkEmail) && valid == "true")  {

			alert("The Contact Person\'s Email address you entered is not valid.  Please re-enter.");

			x.Contact_Email.focus();

			valid = "false";

			}

//	alert("Validate =  " + valid);

	if(valid == "false")  {

		return false;

	} else  {

		return true;

	}

}

	

function process(x)  {

	var valid = "true";

	if(validate(x,valid))  {

		

//	alert("Process True");

	return true;

	}

	else {

//		alert("Process False");

		return false;

		}

}



	