// JavaScript Document
// JavaScript Document
function emailvalidation(entered, alertbox)
{
// E-mail Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos<2 || lastpos-dotpos<2)
	{
		if (alertbox) 
			{
			 alert(alertbox);
			 } 
			return false;
		}
else {
	return true;
	}
}
}

function valuevalidation(entered, min, max, alertbox, datatype)
{
// Value Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}


function digitvalidation(entered, min, max, alertbox, datatype)
{
// Digit Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{
	smalldatatype=datatype.toLowerCase();
	if (smalldatatype.charAt(0)=="i")
	{
		checkvalue=parseInt(value); 
		if (value.indexOf(".")!=-1) 
			{
				checkvalue=checkvalue+1
			}
	};
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}


function emptyvalidation(entered, alertbox)
{
// Emptyfield Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}


function contactus(thisform)
{
// This function checks the entire form before it is submitted
// Note: This function needs to be customized to fit your form

	with (thisform)
	{
		
		
	if (emptyvalidation(name,"Name field must not be empty.")==false)
		{
			name.focus();
			return false;
		};
		
	

	if (emailvalidation	(email,"Not a valid email.")==false) 
		{
			email.focus(); 
			return false;
		};
		
	if (emptyvalidation(state,"Don't leave the comments box blank.")==false)
		{
			state.focus();
			return false;
		};
	if (emptyvalidation(comments,"Don't leave the information box blank.")==false)
		{
			comments.focus();
			return false;
		};
	
	
	}
	
}

function narrative(thisform)
{
// This function checks the entire form before it is submitted
// Note: This function needs to be customized to fit your form

	with (thisform)
	{
		
		
	if (emptyvalidation(name,"Name field must not be empty.")==false)
		{
			name.focus();
			return false;
		};
		
	if (emailvalidation	(email,"Not a valid email.")==false) 
		{
			email.focus(); 
			return false;
		};
	
	
		
	if (emptyvalidation(comments,"Don't leave the narrative box blank.")==false)
		{
			comments.focus();
			return false;
		};
	
	
	}
	
}


function rentvalidation(thisform)
{
// This function checks the entire form before it is submitted
// Note: This function needs to be customized to fit your form
var retard;
	with (thisform)
	{
		
		
	if (emptyvalidation(first_name,"Please don't leave the first name field empty.")==false)
		{
			first_name.focus();
			return false;
		};
		
	if (emptyvalidation(lastname,"Please don't leave the last name field empty.")==false)
		{
			lastname.focus();
			return false;
		};
		
	if (digitvalidation(phone_number,1,12,"Please enter a valid telephone number","I")==false) 
	{
			phone_number.focus(); 
			return false;
	};
		
	if (emailvalidation	(email,"Not a valid email.")==false) 
	{
			email.focus(); 
			return false;
	};
	
	if (emptyvalidation(address,"Please enter the address of the event.")==false)
		{
			address.focus();
			return false;
		};
	if (emptyvalidation(city,"Please enter the city where the event will be held.")==false)
		{
			city.focus();
			return false;
		};
	if (digitvalidation(zipcode,1,12,"Please enter a valid zip code","I")==false) 
	{
			zipcode.focus(); 
			return false;
	};
	//alert(elements["bouncycastle[]"].length);
	if (emptycheckbox(elements["bouncycastle[]"],"Please choose at least one bouncy house.")==false)
		{
			elements["bouncycastle[]"][0].focus();
			return false;
		}
		
	
	}
	
}


function emptycheckbox(entered,alertbox)
{
	var i;
	var total;
	total = 0;
	//alert(entered.length);
		//i=entered.length;
		//alert (i);
		for (i=0; i<entered.length; i++)
		{
			if (entered[i].checked)
			total +=1;
		}
		//alert (total);
		if (total == 0) {
			alert(alertbox);
			return false;
		}
		else
			{ 
			return true;
			}
		
	
}



//place an order form validation

function validate_radiobox (entered, alertbox)
{
	course=false;
	
	with (entered)
	{
		i=0;
		for (i=0;i<entered.length;i++) 
		{
		if (entered[i].checked) 
			course=true;
			
		}
		if (!course) {
				if (alertbox) 
				{
				 alert(alertbox);
				 } 
				return false;
			}
		else {
		return true;
		}
	}
}
