// JavaScript Document
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=350,left = 362,top = 234');");
}

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("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

//This is to check space
function leftTrim(sString){
	while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
	return sString;
}

//Validate Order form 1
function validate_order1(frm){
	
	if(leftTrim(frm.first_name.value) == "") {
		alert("Please Enter the First Name");
		frm.first_name.focus();
		return false;
	}
	
	if(leftTrim(frm.last_name.value) == "") {
		alert("Please Enter the Last Name");
		frm.last_name.focus();
		return false;
	}
	
	if(leftTrim(frm.phone.value) == "") {
		alert("Please Enter the phone");
		frm.phone.focus();
		return false;
	}
	if (isNaN(frm.phone.value) || frm.phone.value.length<0 ){
	alert ('Invalid Telephone Number');
	frm.phone.focus();
	return false;
	}
	
	if(leftTrim(frm.email.value) == "") {
		alert("Please Enter the Email address");
		frm.email.focus();
		return false;
	}
	else{
		if(!echeck(frm.email.value)){
			frm.email.value = "";
			frm.email.focus();
			return false;
		}
	}

	return true;
}

//Validate Order form 3
//Radio button validation

function validate_order3() 
	{
		
		if(leftTrim(document.order3.purchaseOrder.value) == "") {
		alert("Please Enter the Purchase Order");
		document.order3.purchaseOrder.focus();
		return false;
		}
	
		if(leftTrim(document.order3.date.value) == "") {
		alert("Please Enter the Date");
		document.order3.date.focus();
		return false;
		}
		
		// place any other field validations that you require here
		// validate myradiobuttons
		
		myOption = -1;
		for (i=document.order3.color.length-1; i > -1; i--) {
		if (document.order3.color[i].checked) {
		myOption = i; i = -1;
		}
		}
		if (myOption == -1) {
		alert("You must select a color radio button");
		return false;
		}
		
		myOption1 = -1;
		for (i=document.order3.size.length-1; i > -1; i--) {
		if (document.order3.size[i].checked) {
		myOption1 = i; i = -1;
		}
		}
		if (myOption1 == -1) {
		alert("You must select a size radio button");
		return false;
		}

		//document.order3.submit(); 
		if(leftTrim(document.order3.quantity.value) == "") {
		alert("Please Enter the Quantity");
		document.order3.quantity.focus();
		return false;
		}
		
		if (isNaN(document.order3.quantity.value) || document.order3.quantity.value.length<0 ){
		alert ('Invalid Quantity');
		document.order3.quantity.focus();
		return false;
		}
		document.order3.submit()
		//return true;
	}

function validate_order3a() 
	{
		// place any other field validations that you require here
		// validate myradiobuttons
		myOption = -1;
		for (i=document.order3a.finish.length-1; i > -1; i--) {
		if (document.order3a.finish[i].checked) {
		myOption = i; i = -1;
		}
		}
		if (myOption == -1) {
		alert("You must select a Finish radio button");
		return false;
		}
		document.order3a.submit(); 
		//return true;
	}
	
function validate_order3b() 
	{
		// place any other field validations that you require here
		// validate myradiobuttons
		myOption = -1;
		for (i=document.order3b.weight.length-1; i > -1; i--) {
		if (document.order3b.weight[i].checked) {
		myOption = i; i = -1;
		}
		}
		if (myOption == -1) {
		alert("You must select a Weight radio button");
		return false;
		}
		
		myOption1 = -1;
		for (i=document.order3b.finish.length-1; i > -1; i--) {
		if (document.order3b.finish[i].checked) {
		myOption1 = i; i = -1;
		}
		}
		if (myOption1 == -1) {
		alert("You must select a Finish radio button");
		return false;
		}
		
		document.order3b.submit(); 
		//return true;
	}
	
function validate_order3c() 
	{
		// place any other field validations that you require here
		// validate myradiobuttons
		myOption = -1;
		for (i=document.order3c.weight.length-1; i > -1; i--) {
		if (document.order3c.weight[i].checked) {
		myOption = i; i = -1;
		}
		}
		if (myOption == -1) {
		alert("You must select a weight radio button");
		return false;
		}
		document.order3c.submit(); 
		//return true;
	}

function validate_order4() 
	{
		
		// place any other field validations that you require here
		// validate myradiobuttons
		
		myOption = -1;
		for (i=document.order4.binding.length-1; i > -1; i--) {
		if (document.order4.binding[i].checked) {
		myOption = i; i = -1;
		}
		}
		if (myOption == -1) {
		alert("You must select a Binding/Stapling radio button");
		return false;
		}
		
		myOption1 = -1;
		for (i=document.order4.covers.length-1; i > -1; i--) {
		if (document.order4.covers[i].checked) {
		myOption1 = i; i = -1;
		}
		}
		if (myOption1 == -1) {
		alert("You must select a Cover radio button");
		return false;
		}
		
		myOption2 = -1;
		for (i=document.order4.folding.length-1; i > -1; i--) {
		if (document.order4.folding[i].checked) {
		myOption2 = i; i = -1;
		}
		}
		if (myOption2 == -1) {
		alert("You must select a Folding radio button");
		return false;
		}
		
		
		document.order4.submit()
		//return true;
	}