// JavaScript Document
function noSitesWork(thisForm)
		{
			for(i=0; i < thisForm.length; i++) 
			{
				elmnt = thisForm.elements[i]; 
				valu = thisForm.elements[i].value; 
				name = thisForm.elements[i].name;
				type = thisForm.elements[i].type;
				classy = thisForm.elements[i].className;
				if(classy != "fieldset")
				{		
					if(type == "radio" && name == "Pick_up") 
					{
						if(elmnt.checked && valu == "NO SITES WORK")
						{
							//alert("hide payment");
							document.getElementById("paymentSet").style.display = "none";
							document.getElementById("split").style.display = "none";
						}
						if((elmnt.checked && valu != "NO SITES WORK") && (document.getElementById("paymentSet").style.display == "none" && document.getElementById("split").style.display == "none"))
						{
							//alert("show payment");
							document.getElementById("paymentSet").style.display = "block";
							document.getElementById("split").style.display = "block";
						}													
					}			
				}
			}
		}

function calculateTotal(thisForm) 
{	
	var share = 0;		
	var dropbox = 0;
	if (thisForm.form_version.value == "fullcost") 
	{	 
		var salad = 0;
		var flowers = 0;
		var eggs = 0;		
		var shirts = 0;
		var payment = 0;
		var total = 0;
		var tshirtArray = new Array();
		//share
		if (thisForm.Share.checked==true) 
		{ 
			share = 875; 
		}	
		//salad
		if (thisForm.Salad.checked==true) 
		{ 
			salad = 160;
		}
				
		//drop box
		for (d=0; d < thisForm.Pick_up.length; d++) 
		{
			if (thisForm.Pick_up[d].checked==true) 
			{
				if (thisForm.Pick_up[d].value.substring(0,3) == "Box") 
				{ 
					dropbox = 45; 
				}			
			}			
		}
				
		//payment
		payment = 0;
		if(thisForm.Payment)
		{
		for (p=0; p < thisForm.Payment.length; p++) 
		{
	 		if (thisForm.Payment.selectedIndex==3) 
			{ 
				payment = 10; 
			}
		}
		}
		//full payment total
		total = share + salad + dropbox + payment;
	}
	//scholarship
	if (thisForm.form_version.value == "scholarship") 
	{
		share = thisForm.share_portion.value
		for (i=0; i < thisForm.Pick_up.length; i++) 
		{
			if (thisForm.Pick_up[i].checked==true) 
			{
				//alert(thisForm.Pick_up[i].value.substring(0,3))
				if (thisForm.Pick_up[i].value.substring(0,3) == "Box") 
				{ 
					dropbox = 45; 
				}			
			}			
		}
		//scholarship total
		total = parseInt(share) + parseInt(dropbox);
		thisForm.Payment_due.value = total;
	}	
	thisForm.Total_due.value = total;			
}

function validator(thisForm) 
{
	onorder = 0;
	nopu = 0;
	tn = 0;
	nopay = 0;
	mo = 0;
	dy = 0;
	pay = 0;
	version = thisForm.form_version.value;
	for(i=0; i < thisForm.length; i++) 
	{
		elmnt = thisForm.elements[i]; 
		valu = thisForm.elements[i].value; 
		name = thisForm.elements[i].name;
		type = thisForm.elements[i].type;
		classy = thisForm.elements[i].className;
		//tag = toLowerCase(thisForm.elements[i].tagName);
		if(classy != "fieldset")
		{
			msgname = "";
			if(name.indexOf("_") > 0) 
			{
				c = name.indexOf("_");
				newname = name.substring(0,c);
				newname2 = name.substring(c+1,name.length);
				msgname = newname + " " + newname2;
			}
			else 
			{
				msgname = name;
			}
			if (thisForm.elements[i].className == "validate") 
			{
				switch(type)  
				{
					case "text" :
						switch(name) 
						{
							case "Zip_code" :
								if(valu.length < 5) 
								{
									alert("Please enter at least 5 digits in the \""+msgname+"\" field.");
									elmnt.focus();
									return (false);			
								}
								break;
							case "Telephone" :							
								for(t=0; t < valu.length; t++) 
								{
									if(valu.charAt(t) == 0 || valu.charAt(t) == 1 || valu.charAt(t) == 2 || valu.charAt(t) == 3 || valu.charAt(t)==4 || valu.charAt(t)==5 || valu.charAt(t)==6 || valu.charAt(t)==7 || valu.charAt(t) == 8 || valu.charAt(t) == 9 ) 
									{
										tn += 1;
									}								
								}
								if (tn < 10) 
								{								
									alert("Please enter at least 10 digits in the \""+name+"\" field.");
    								elmnt.focus();
									return (false);								
								}
								break;
							case "Email" :
								//regular expression
								var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/; 
	
								//if email doesn't validate invoke alert message, move cursor to form field, and return form = false
								if (!re_mail.test(valu) || !valu) 
								{
									alert("Please enter a valid email address");
									elmnt.focus();		
									return (false);		
								}
								break;
							default :							
								if (valu == "") 
								{								
									//cannot be left empty
									if (msgname != "" ) 
									{
										passname = msgname;
									}
									else 
									{
										passname = name;
									}	
									alert("Please enter a value in the \""+ passname +"\" field.");
    								elmnt.focus();
									return (false);				
								}	
								break;	
						}
						break;
					case "radio" :										
						if (name == "Pick_up") 
						{
							if (elmnt.checked == false) 
							{ 
								nopu += 1; 
							}
							if (nopu == thisForm.Pick_up.length) 
							{ 
								alert("Please select a pick-up option from the list of Bulk drop or Drop box sites.");
								location.href="#pickup";
    							return (false);							
							}		
						}
						/* scholarship */
						if (name == "Payment") 
						{
							if (elmnt.checked == false) 
							{ 
								nopay += 1; 
							}
							if (nopay == thisForm.Payment.length) 
							{ 
								alert("Please select a payment option from one of the \""+msgname+"\" radio buttons.");
								location.href="#payment";
    							return (false);							
							}		
						}
						//}
						break;	
					case "select-one" :	
						for (y=0; y < thisForm.elements[i].length; y++) 
						{
						 	for(x=0; x < thisForm.Pick_up.length; x++)
							{
								if(thisForm.Pick_up[x].checked && thisForm.Pick_up[x].value == "NO SITES WORK")
								{
									checkpayment = "no";
								}
								else
								{
									checkpayment = "yes";
								}
							}
							if (thisForm.elements[i].selectedIndex == 0 && checkpayment == "yes") 
							{
								alert("Please select a payment option from the \""+msgname+"\" drop down box.");
    							elmnt.focus();
								return (false);		 							
								break;														
							}						
						 }						 
						break;
				}			
			}		
			if (version == "fullcost") 
			{
				if (name == "Share" || name == "Salad") 
				{					
					switch(type) 
					{
						case "checkbox" :
							if (elmnt.checked == true) 
							{ 
								onorder += 1; 
							}
							break;				
						case "select-one" :
							if (elmnt.selectedIndex > 0) 
							{ 
								onorder += 1; 
							}	
							break;
					}			
				}
			}				
		}
	}
	
	if (version == "fullcost" && onorder == 0) 
	{
		alert("Please select at least one item for your share - a full share or an item from the special options.");
		location.href="#order"
    	return (false);
	}	
	
	return (true);
}



