/* Popup */

function openPopup(url) {
	 window.open(url, "popup_id", "scrollbars=no,resizable,width=425,height=344");
	 return false;
}

/* Validation required */

function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null||value==""||value=="0")
		  {alert(alerttxt);return false;}
		else {return true}
	}
}

/* Validation de courriel */

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Please enter a valid e-mail address")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Please enter a valid e-mail address")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please enter a valid e-mail address")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Please enter a valid e-mail address")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please enter a valid e-mail address")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Please enter a valid e-mail address")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Please enter a valid e-mail address")
		return false
	 }

	 return true					
}
 
/* Section contact */

function validate_contact_form(contact_form)
{
	with (contact_form)
	{
		if (validate_required(Nom,"Please enter your name")==false)
		  {Nom.focus();return false;}
	}
	with (contact_form)
	{
		if (validate_required(Courriel,"Please enter your e-mail")==false)
		  {Courriel.focus();return false;}
	}
	
	var emailID2=document.contact_form.Courriel
	if ((emailID2.value==null)||(emailID2.value=="")){
		alert("Please enter a valid e-mail address")
		emailID2.focus()
		return false
	}
	if (echeck(emailID2.value)==false){
		emailID2.value=""
		emailID2.focus()
		return false
	}
	
	with (contact_form)
	{
		if (validate_required(Message,"Please enter your message")==false)
		  {Message.focus();return false;}
	}
}

/* Section bon de commande */

function validate_form(commande_form)
{
	with (commande_form)
	{
		if (validate_required(t_total,"Please enter your order")==false)
		  {t_total.focus();return false;}
	}
	with (commande_form)
	{
		if (validate_required(Nom,"Please enter your name")==false)
		  {Nom.focus();return false;}
	}
	with (commande_form)
	{
		if (validate_required(Courriel,"Please enter your e-mail")==false)
		  {Courriel.focus();return false;}
	}
	
	var emailID2=document.commande_form.Courriel
	if ((emailID2.value==null)||(emailID2.value=="")){
		alert("Please enter a valid e-mail address")
		emailID2.focus()
		return false
	}
	if (echeck(emailID2.value)==false){
		emailID2.value=""
		emailID2.focus()
		return false
	}
	
	with (commande_form)
	{
		if (validate_required(Adresse,"Please enter your address")==false)
		  {Adresse.focus();return false;}
	}
	with (commande_form)
	{
		if (validate_required(Telephone,"Please enter your phone number")==false)
		  {Telephone.focus();return false;}
	}
}

/* Bon de commande : totaux */

function copyData(from,to,price) { to.value = from.value*price; }

function copyDataTotal(from1,from2,from3,from4,from5,from6,from7,from8,from9,tototal) { tototal.value = parseInt(from1.value)+parseInt(from2.value)+parseInt(from3.value)+parseInt(from4.value)+parseInt(from5.value)+parseInt(from6.value)+parseInt(from7.value)+parseInt(from8.value)+parseInt(from9.value); }
