function Street_Address_onchange()
{
	if(document.OrderForm.Billing_company.checked == true)
		document.OrderForm.Billing_Street_Address.value = 	document.OrderForm.Street_Address.value;
}

function Suite_onchange() 
{
	if(document.OrderForm.Billing_company.checked == true)
		document.OrderForm.Billing_Suite.value = 	document.OrderForm.Suite.value;
}

function State_onchange() 
{
	if(document.OrderForm.Billing_company.checked == true)
		document.OrderForm.Billing_State.value = 	document.OrderForm.State.value;
}

function City_onchange() 
{
	if(document.OrderForm.Billing_company.checked == true)
		document.OrderForm.Billing_City.value = 	document.OrderForm.City.value;		
}

function zipcode_onchange() 
{
	if(document.OrderForm.Billing_company.checked == true)
		document.OrderForm.Billing_zip_code.value = 	document.OrderForm.zip_code.value;	
}

function Country_onchange() 
{
	if(document.OrderForm.Billing_company.checked == true)
			document.OrderForm.Billing_Country.selectedIndex = 	document.OrderForm.Country.selectedIndex;	
}

function FirstName_onchange() 
{
	if(document.OrderForm.Support_Billing.checked == true)
		document.OrderForm.Support_First_Name.value = document.OrderForm.Billing_First_Name.value;

}

function LastName_onchange() 
{
	if(document.OrderForm.Support_Billing.checked == true)
		document.OrderForm.Support_Last_Name.value = document.OrderForm.Billing_Last_Name.value;
}

function MiddleName_onchange()
{
	if(document.OrderForm.Support_Billing.checked == true)
		document.OrderForm.Support_Middle_Name.value = document.OrderForm.Billing_Middle_Name.value;
}

function EMail_onchange()
{
	if(document.OrderForm.Support_Billing.checked == true)
		document.OrderForm.Support_EMail.value = document.OrderForm.Billing_EMail.value;
}

function Phone_onchange() 
{
	if(document.OrderForm.Support_Billing.checked == true)
				document.OrderForm.Support_Phone.value = document.OrderForm.Billing_Phone.value;	
}

function billsupport_onclick()
{
	if(document.OrderForm.Support_Billing.checked == true)
	{
		document.OrderForm.Support_First_Name.value = document.OrderForm.Billing_First_Name.value;
		document.OrderForm.Support_First_Name.readOnly = true;
		document.OrderForm.Support_Middle_Name.value = document.OrderForm.Billing_Middle_Name.value;
		document.OrderForm.Support_Middle_Name.readOnly = true;
		document.OrderForm.Support_Last_Name.value = document.OrderForm.Billing_Last_Name.value;
		document.OrderForm.Support_Last_Name.readOnly = true;
		document.OrderForm.Support_Phone.value = document.OrderForm.Billing_Phone.value;
		document.OrderForm.Support_Phone.readOnly = true;
		document.OrderForm.Support_EMail.value = document.OrderForm.Billing_EMail.value;
		document.OrderForm.Support_EMail.readOnly = true;
	}
	else
	{
		document.OrderForm.Support_First_Name.value = "";
		document.OrderForm.Support_First_Name.readOnly = false;
		document.OrderForm.Support_Middle_Name.value = "";
		document.OrderForm.Support_Middle_Name.readOnly = false;
		document.OrderForm.Support_Last_Name.value = "";
		document.OrderForm.Support_Last_Name.readOnly = false;
		document.OrderForm.Support_Phone.value = "";
		document.OrderForm.Support_Phone.readOnly = false;
		document.OrderForm.Support_EMail.value = "";
		document.OrderForm.Support_EMail.readOnly = false;
	}
}


function billcompany_onclick()
{
	if(document.OrderForm.Billing_company.checked == true)
	{
		document.OrderForm.Billing_Street_Address.value = 	document.OrderForm.Street_Address.value;
		document.OrderForm.Billing_Suite.value = 	document.OrderForm.Suite.value;
		document.OrderForm.Billing_State.value = 	document.OrderForm.State.value;
		document.OrderForm.Billing_City.value = 	document.OrderForm.City.value;		
		document.OrderForm.Billing_zip_code.value = 	document.OrderForm.zip_code.value;	
		document.OrderForm.Billing_Country.selectedIndex = 	document.OrderForm.Country.selectedIndex;	
		document.OrderForm.Billing_Street_Address.readOnly = 	true;
		document.OrderForm.Billing_Suite.readOnly = 	true;
		document.OrderForm.Billing_State.readOnly = 	true;
		document.OrderForm.Billing_City.readOnly = 	true;		
		document.OrderForm.Billing_zip_code.readOnly = 	true;	
		document.OrderForm.Billing_Country.readOnly = true;	
	}
	else
	{
		document.OrderForm.Billing_Street_Address.value = 	"";
		document.OrderForm.Billing_Suite.value = 	"";
		document.OrderForm.Billing_State.value = 	"";
		document.OrderForm.Billing_City.value = 	"";		
		document.OrderForm.Billing_zip_code.value = 	"";	
		document.OrderForm.Billing_Country.selectedIndex = 0;	
		document.OrderForm.Billing_Street_Address.readOnly = 	false;
		document.OrderForm.Billing_Suite.readOnly = 	false;
		document.OrderForm.Billing_State.readOnly = 	false;
		document.OrderForm.Billing_City.readOnly = 	false;
		document.OrderForm.Billing_zip_code.readOnly = 	false;	
		document.OrderForm.Billing_Country.readOnly = false;	
	}
}

function EMail_id(str)
{
var exp = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
if(exp.test(str))
	return true;
else
	return false;
}

function Phone(str)
{
var exp = /^(([A-Z])*([a-z])*([0-9])*(\-)*(\.)*(\+)*(\()*(\))*(\s)*)*$/
if(exp.test(str))
	return true;
else
	return false;
}

function Cardnumber(str)
{
var exp=/^([0-9]+\s*)+$/;
if(exp.test(str))
	return true;
else
	return false;
}

function Accountnumber(str)
{
var exp=/^([1-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9])$/;
if(exp.test(str))
	return true;
else
	return false;
}

function number(str)
{
var exp=/^([0-9]+)+$/;
if(exp.test(str))
	return true;
else
	return false;
}

function zipcode(str)
{
var exp=/^((([0-9])*([A-Z])*([a-z])*(\s)*)*)$/;
if(exp.test(str))
	return true;
else
	return false;
}

function Trim(str)
{
var exp=/^(\s)+|(\s)+$/g;
return(str.replace(exp,""));
}

function min(str,min)
{
	var s=Trim(str);

	if(s.length < min)
		return false;

	return true;
}

function max(str,max)
{
	var s=Trim(str);

	if(s.length > max)
		return false;

	return true;
}

function check(str,mn,mx,field)
{
	if(!min(str,mn))
	{
		alert("Please enter alteast " + mn + " characters for " + field);
		return false;
	}
	
	if(mx >  0) 
	{
		if(!max(str,mx))
		{
			alert("Please enter atmost " + mx + " characters for " + field);
			return false;
		}
	}
	
	return true;
}



function submit1_onclick() {

var str = document.OrderForm.Company_Name.value;
	
	if(!check(str,2,255,"Company Name"))
	{
		document.OrderForm.Company_Name.focus();
		return false;
	}
			
	str = document.OrderForm.Street_Address.value;

	if(!check(str,5,255,"Street Address"))
	{
		document.OrderForm.Street_Address.focus();
		return false;
	}
		
	str = document.OrderForm.City.value;
	
	if(!check(str,2,50,"City"))
	{
		document.OrderForm.City.focus();
		return false;
	}
			
	str = document.OrderForm.State.value;
	
	if(!check(str,2,50,"State"))
	{
		document.OrderForm.State.focus();
		return false;
	}
	
	
	str = document.OrderForm.zip_code.value;
	
	if(!check(str,5,20,"Zip Code"))
	{
		document.OrderForm.zip_code.focus();
		return false;
	}
	
	if(!zipcode(str))
	{
		alert("Please enter only Numbers, Characters or space for Zip Code field");
		document.OrderForm.zip_code.focus();
		return false;
	}
	
	str = document.OrderForm.Billing_First_Name.value;
	
	if(!check(str,2,50,"Billing First Name"))
	{
		document.OrderForm.Billing_First_Name.focus();
		return false;
	}
	
	str = document.OrderForm.Billing_Last_Name.value;
	
	if(!check(str,2,50,"Billing Last Name"))
	{
		document.OrderForm.Billing_Last_Name.focus();
		return false;
	}
	
	str = document.OrderForm.Billing_Phone.value;
	
	if(!check(str,10,25,"Billing Phone"))
	{
		document.OrderForm.Billing_Phone.focus();
		return false;
	}

	if(!Phone(str))
	{
		alert("Please enter only Number,(,) or space in Phone number field");
		document.OrderForm.Billing_Phone.focus();
		return false;
	}
		
	str = document.OrderForm.Billing_EMail.value;
	
	if(!check(str,6,255,"Billing EMail"))
	{
		document.OrderForm.Billing_EMail.focus();
		return false;
	}
	
	if(!EMail_id(str))
	{
		alert("Please enter valid Billing Email ID");
		document.OrderForm.Billing_EMail.focus();
		return false;
	}
		
	str = document.OrderForm.Billing_Street_Address.value;

	if(!check(str,5,255,"Billing Street Address"))
	{
		document.OrderForm.Billing_Street_Address.focus();
		return false;
	}
		
	str = document.OrderForm.Billing_City.value;
	
	if(!check(str,2,50,"Billing City"))
	{
		document.OrderForm.Billing_City.focus();
		return false;
	}
			
	str = document.OrderForm.Billing_State.value;
	
	if(!check(str,2,50,"Billing State"))
	{
		document.OrderForm.Billing_State.focus();
		return false;
	}
	
	str = document.OrderForm.Billing_zip_code.value;
	
	if(!check(str,5,20,"Billing Zip Code"))
	{
		document.OrderForm.Billing_zip_code.focus();
		return false;
	}
	
	if(!zipcode(str))
	{
		alert("Please enter only Numbers,Characters or space for Billing Zip Code field");
		document.OrderForm.Billing_zip_code.focus();
		return false;
	}

	
	
	str = document.OrderForm.Support_First_Name.value;
	
	if(!check(str,2,50,"Support First Name"))
	{
		document.OrderForm.Support_First_Name.focus();
		return false;
	}
	
	str = document.OrderForm.Support_Last_Name.value;
	
	if(!check(str,2,50,"Support Last Name"))
	{
		document.OrderForm.Support_Last_Name.focus();
		return false;
	}
	
	str = document.OrderForm.Support_Title.value;
	
	if(!check(str,2,50,"Support Title"))
	{
		document.OrderForm.Support_Title.focus();
		return false;
	}

	
	str = document.OrderForm.Support_Phone.value;
	
	if(!check(str,10,25,"Support Phone"))
	{
		document.OrderForm.Support_Phone.focus();
		return false;
	}

	if(!Phone(str))
	{
		alert("Please enter only Number,(,) or space in Support Phone number field");
		document.OrderForm.Support_Phone.focus();
		return false;
	}
		
	str = document.OrderForm.Support_EMail.value;
	
	if(!check(str,6,255,"Support EMail"))
	{
		document.OrderForm.Support_EMail.focus();
		return false;
	}
	
	if(!EMail_id(str))
	{
		alert("Please enter valid Support Email ID");
		document.OrderForm.Support_EMail.focus();
		return false;
	}
	
	str = document.OrderForm.Card_Number.value;

	if(!check(str,6,255,"Credit Card Number"))
	{
		document.OrderForm.Card_Number.focus();
		return false;
	}
	
	if(!Cardnumber(str))
	{
		alert("Please enter only Number or space in the Credit Card Number Field");
		document.OrderForm.Card_Number.focus();
		return false;
	}

	
	return true;
	
}

