var ObjForm = document.orderform


function showhidediv()
{		
	var objEntireDiv = document.getElementById('reg_dlg').style.display;
	if(objEntireDiv=='none')
	{
		document.getElementById('reg_dlg').style.display = 'block';
	}
	else
	{
		document.getElementById('reg_dlg').style.display = 'none';
	}	
	ResetFields(0);		
}

function resetform()
{
	ResetFields(0);
	DisableEnableFields(false);
}

function ResetFields(chkposition)
{	
	var ObjForm = document.orderform
	
	if(chkposition==0)
	{
		ObjForm.name.value				='';
		ObjForm.lastName.value			='';
		ObjForm.phone.value				='';
		ObjForm.phone2.value			='';
		ObjForm.email.value				='';
		ObjForm.password.value			='';
		ObjForm.password2.value			='';
		
		ObjForm.bill_name.value			='';
		ObjForm.bill_lastName.value		='';
		ObjForm.address.value			='';
		ObjForm.address2.value			='';
		ObjForm.city.value				='';
		ObjForm.zip.value				='';
	}
	
	ObjForm.ShippingFirstName.value	='';
	ObjForm.ShippingLastName.value	='';
	ObjForm.shippingAddress.value	='';
	ObjForm.shippingAddress2.value	='';
	ObjForm.shippingCity.value		='';
	ObjForm.shippingZip.value		='';
	
	if(chkposition==0)
	{
		for (var i=0;i<=ObjForm.countryCode.options.length-1; i++ )
		{						
			if (ObjForm.countryCode.options[i].value=="CA")
			{			
				ObjForm.countryCode.options[i].selected=true;		
				var ObjBillStates= parent.frames['FrmBillstates'];
				pNewLocation = "states.asp?billccode=CA";
				ObjBillStates.document.location=pNewLocation;
			}				
		}			
	}
	
	for (var i=0;i<=ObjForm.shippingCountryCode.options.length-1; i++ )
	{						
		if (ObjForm.shippingCountryCode.options[i].value=="CA")
		{			
			ObjForm.shippingCountryCode.options[i].selected=true;	
			var ObjShipStates= parent.frames['FrmShipstates'];
			pNewLocation = "Shipstates.asp?shipccode=CA";
			ObjShipStates.document.location=pNewLocation;
		}				
	}			
	ObjForm.Copy_billing_Add[1].checked 	=	true;
}


function DisableEnableFields(status)
{
	var ObjForm = document.orderform
	
	var ObjBillStates= parent.frames['FrmBillstates'].document.formbillsates.statecode;
	var ObjShipStates= parent.frames['FrmShipstates'].document.formshipsates.shippingStateCode;
	
	ObjForm.ShippingFirstName.readOnly=status;
	ObjForm.ShippingLastName.readOnly=status;
	ObjForm.shippingAddress.readOnly=status;
	ObjForm.shippingAddress2.readOnly=status;
	ObjForm.shippingCity.readOnly=status;
	ObjForm.shippingZip.readOnly=status;
	ObjForm.shippingCountryCode.disabled=status;
	ObjShipStates.disabled=status;			
}

function ShowBillState(val)
{
	var ObjForm = document.orderform	
	var ObjBillStates= parent.frames['FrmBillstates'];
	pNewLocation = "states.asp?billccode="+val;	
	ObjBillStates.document.location=pNewLocation;
	
	if(ObjForm.Copy_billing_Add[0].checked)
	{
		DisableEnableFields(false);
		ResetFields(1)
	}
}

function ShowShipState(val)
{
	var ObjForm = document.orderform	
	var ObjShipStates= parent.frames['FrmShipstates'];
	pNewLocation = "Shipstates.asp?shipccode="+val;	
	ObjShipStates.document.location=pNewLocation;
}

function checkbilling()
{
	var ObjForm = document.orderform		
	if(isEmptyString(trimString(ObjForm.bill_name.value)))
	{
		alert("Please Enter the Billing Name ");
		ObjForm.bill_name.select();
		ObjForm.bill_name.focus();
		return false;
	}
	
	if(isEmptyString(trimString(ObjForm.bill_lastName.value)))
	{
		alert("Please Enter the Billing Last Name ");
		ObjForm.bill_lastName.select();
		ObjForm.bill_lastName.focus();
		return false;
	}	
	
	if(isEmptyString(trimString(ObjForm.address.value)))
	{
		alert("Please Enter the address");
		ObjForm.address.select();
		ObjForm.address.focus();
		return false;
	}

	if(isEmptyString(trimString(ObjForm.city.value)))
	{
		alert("Please Enter The City");
		ObjForm.city.select();
		ObjForm.city.focus();
		 return false;
	}
	var ObjBillStates= parent.frames['FrmBillstates'].document.formbillsates.statecode;
	if(isEmptyString(trimString(ObjBillStates.value)))
	{			
		alert("Please provide the State");
		//parent.frames['FrmBillstates'].document.formbillsates.focus();
		return false;
	}
	if(isEmptyString(trimString(ObjForm.zip.value)))
	{
		alert("Please Enter The zip");
		ObjForm.zip.select();
		ObjForm.zip.focus();
		return false;
	}
	
	if(ObjForm.countryCode.value=='US' || ObjForm.countryCode.value=='CA')
	{
		if(!checkZip(ObjForm.countryCode.value,ObjForm.zip.value))
		{
			ObjForm.zip.select();
			ObjForm.zip.focus();
			return false;
		}
	}
	if(isEmptyString(trimString(ObjForm.countryCode.value)))
	{
		alert("Please Select Country");
		ObjForm.countryCode.focus();
		return false;
	}
	
	return true;
}


function CheckExisting()
{
	if (!isEmailAddr(document.orderform.email.value))
	{
		alert("Please enter a valid email address in the form: yourname@yourdomain.com");		
		return (false);
	}
	else
	{
		parent.frames['frmemaillcheck'].document.iframe_form.email.value=document.orderform.email.value;
		parent.frames['frmemaillcheck'].document.forms[0].submit();
	}
}


function validData()
{
	var ObjForm = document.orderform		
	if(isEmptyString(trimString(ObjForm.name.value)))
	{
		alert("Please Enter the first name");
		ObjForm.name.select();
		ObjForm.name.focus();
		return false;
	}
	
	if(isEmptyString(trimString(ObjForm.lastName.value)))
	{
		alert("Please Enter the last name");
		ObjForm.lastName.select();
		ObjForm.lastName.focus();
		return false;
	}

	if(isEmptyString(trimString(ObjForm.phone.value)))
	{
		alert("Please Enter the phone");
		ObjForm.phone.select();
		ObjForm.phone.focus();
		return false;
	}
	
	if(isEmptyString(trimString(ObjForm.email.value)))
	{
		alert("Please Enter the email");
		ObjForm.email.select();
		ObjForm.email.focus();
		return false;
	}
	else
	{
			if (!isEmailAddr(ObjForm.email.value))
			{
				alert("Please enter a valid email address in the form: yourname@yourdomain.com");
				ObjForm.email.select();
				ObjForm.email.focus();
				return false;
			}		
	}	
	if(trimString(document.getElementById('existsmail').innerHTML) !=="&nbsp;")
	{
			alert("Please enter another email address or retrieve your existing one");
			ObjForm.email.select();
			ObjForm.email.focus();
			return (false);
	}	
	
	if(isEmptyString(trimString(ObjForm.password.value)))
	{
		alert("Please Enter password");
		ObjForm.password.select();
		ObjForm.password.focus();
		return false;
	}
	
	if(isEmptyString(trimString(ObjForm.password2.value)))
	{
		alert("Please Enter Confirm password");
		ObjForm.password2.select();
		ObjForm.password2.focus();
		return false;
	}
	
	if(ObjForm.password.value !=ObjForm.password2.value)
	{
		alert("Password does not match with Confirm password");
		ObjForm.password2.select();
		ObjForm.password2.focus();
		return false;		
	}
	if(!checkbilling())
	{
		return false;
	}
	
	if(!checkshipping())
	{
		return false;
	}	
	if(ObjForm.Copy_billing_Add[1].checked)
	{
		var ObjBillStates= parent.frames['FrmBillstates'].document.formbillsates.statecode;	
		var ObjShipStates= parent.frames['FrmShipstates'].document.formshipsates.shippingStateCode;
		if(ObjForm.countryCode.value=='US' || ObjForm.countryCode.value=='CA')
		{	
			if(ObjForm.shippingCountryCode.value=='US' || ObjForm.shippingCountryCode.value=='CA')
			{
				
				var selIndex = ObjBillStates.selectedIndex;
				var selIndexship = ObjShipStates.selectedIndex;
				ObjForm.billLaststatecode.value		=	ObjBillStates.options[selIndex].value;
				ObjForm.shipLaststatecode.value		=	ObjShipStates.options[selIndexship].value;		
				ObjForm.billLaststatename.value		=	ObjBillStates.options[selIndex].text;
				ObjForm.shipLaststatename.value		=	ObjShipStates.options[selIndexship].text;	
			
				ObjForm.shipLastCountryCode.value	=	ObjForm.shippingCountryCode.value;	
				ObjForm.billLastCountryCode.value	=	ObjForm.countryCode.value;	
				ObjForm.lastseparateShipping.value	=	"0";			
			}
			else
			{				
				var selIndex = ObjBillStates.selectedIndex;
				ObjForm.billLaststatecode.value		=	ObjBillStates.options[selIndex].value;
				ObjForm.shipLaststatecode.value		=	'';		
				ObjForm.billLaststatename.value		=	ObjBillStates.options[selIndex].text;
				ObjForm.shipLaststatename.value		=	ObjShipStates.value;
				
				ObjForm.shipLastCountryCode.value	=	ObjForm.shippingCountryCode.value;	
				ObjForm.billLastCountryCode.value	=	ObjForm.countryCode.value;	
				ObjForm.lastseparateShipping.value	=	"0";	
			}
		}
		else
		{				
			if(ObjForm.shippingCountryCode.value=='US' || ObjForm.shippingCountryCode.value=='CA')
			{				
				var selIndexship = ObjShipStates.selectedIndex;
				ObjForm.billLaststatecode.value		=	'';
				ObjForm.shipLaststatecode.value		=	ObjShipStates.options[selIndexship].value;		
				ObjForm.billLaststatename.value		=	ObjBillStates.value;
				ObjForm.shipLaststatename.value		=	ObjShipStates.options[selIndexship].text;	
				
				ObjForm.shipLastCountryCode.value	=	ObjForm.shippingCountryCode.value;	
				ObjForm.billLastCountryCode.value	=	ObjForm.countryCode.value;	
				ObjForm.lastseparateShipping.value	=	"0";				
			}
			else
			{
				ObjForm.billLaststatecode.value		=	'';
				ObjForm.shipLaststatecode.value		=	'';
				ObjForm.billLaststatename.value		=	ObjBillStates.value;
				ObjForm.shipLaststatename.value		=	ObjShipStates.value;			
			
				ObjForm.shipLastCountryCode.value	=	ObjForm.shippingCountryCode.value;	
				ObjForm.billLastCountryCode.value	=	ObjForm.countryCode.value;
				ObjForm.lastseparateShipping.value	=	"0";
			}		
		}		
	}
	else
	{		
		SameasBill('yes')
	}
}

function fillshipasbill()
{	
	var ObjForm = document.orderform			
				
	ObjForm.ShippingFirstName.value		=	ObjForm.bill_name.value;
	ObjForm.ShippingLastName.value		=	ObjForm.bill_lastName.value;
	ObjForm.shippingAddress.value		=	ObjForm.address.value;
	ObjForm.shippingAddress2.value		=	ObjForm.address2.value;
	ObjForm.shippingCity.value			=	ObjForm.city.value;
	ObjForm.shippingZip.value		 	=	ObjForm.zip.value;
					
	//===================================================================================
	for (var i=0;i<=ObjForm.shippingCountryCode.options.length-1; i++ )
	{				
		if (ObjForm.shippingCountryCode.options[i].value==ObjForm.countryCode.value)
		{
			ObjForm.shippingCountryCode.options[i].selected=true;							
		}				
	}
	//===================================================================================
	//===================================================================================
	var ObjBillStates= parent.frames['FrmBillstates'].document.formbillsates.statecode;	
	var ObjShipStates= parent.frames['FrmShipstates'].document.formshipsates.shippingStateCode;
	if(ObjForm.countryCode.value=='US' || ObjForm.countryCode.value=='CA')
	{
		var ObjFrmShipStates= parent.frames['FrmShipstates'];
		pNewLocation = "Shipstates.asp?shipccode="+ObjForm.countryCode.value+"&blstatecode="+ObjBillStates.value;	
		ObjFrmShipStates.document.location=pNewLocation;				
		
		var selIndex = ObjBillStates.selectedIndex;
		ObjForm.billLaststatecode.value		=	ObjBillStates.options[selIndex].value;
		ObjForm.shipLaststatecode.value		=	ObjBillStates.options[selIndex].value;		
		ObjForm.billLaststatename.value		=	ObjBillStates.options[selIndex].text;
		ObjForm.shipLaststatename.value		=	ObjBillStates.options[selIndex].text;	
		
		ObjForm.shipLastCountryCode.value	=	ObjForm.shippingCountryCode.value;	
		ObjForm.billLastCountryCode.value	=	ObjForm.countryCode.value;	
		ObjForm.lastseparateShipping.value	=	"-1";
	}
	else
	{				
		var ObjFrmShipStates= parent.frames['FrmShipstates'];
		pNewLocation = "Shipstates.asp?shipccode="+ObjForm.countryCode.value+"&bstatename="+ObjBillStates.value;	
		ObjFrmShipStates.document.location=pNewLocation;			
		
		var selIndex = ObjBillStates.selectedIndex;
		ObjForm.billLaststatecode.value		=	'';
		ObjForm.shipLaststatecode.value		=	'';
		ObjForm.billLaststatename.value		=	ObjBillStates.value;
		ObjForm.shipLaststatename.value		=	ObjBillStates.value;	
		
		ObjForm.shipLastCountryCode.value	=	ObjForm.shippingCountryCode.value;	
		ObjForm.billLastCountryCode.value	=	ObjForm.countryCode.value;
		ObjForm.lastseparateShipping.value	=	"-1";
	}		
}

function SameasBill(wht)
{
	var ObjForm = document.orderform	
	if(wht=='yes')
	{				
		if(checkbilling())
		{				
			fillshipasbill();	
			DisableEnableFields(true);				
		}
		else
		{
			ObjForm.Copy_billing_Add[1].checked =true;
		}			
	}
	else
	{		
			DisableEnableFields(false)
			ResetFields(1)			
			ObjForm.billLaststatecode.value		= '';
			ObjForm.shipLaststatecode.value		= '';
			ObjForm.billLaststatename.value		= '';
			ObjForm.shipLaststatename.value		= '';	
	}				  
}




function checkshipping()
{
	var ObjForm = document.orderform	
	if(isEmptyString(trimString(ObjForm.ShippingFirstName.value)))
	{
		alert("Please Enter the Shipping Name ");
		ObjForm.ShippingFirstName.select();
		ObjForm.ShippingFirstName.focus();
		return false;
	}
	if(isEmptyString(trimString(ObjForm.ShippingLastName.value)))
	{
		alert("Please Enter the shipping Last Name ");
		ObjForm.ShippingLastName.select();
		ObjForm.ShippingLastName.focus();
		return false;
	}
	
	if(isEmptyString(trimString(ObjForm.shippingAddress.value)))
	{
		alert("Please Enter the Shipping address");
		ObjForm.shippingAddress.select();
		ObjForm.shippingAddress.focus();
		return false;
	}	
	
	if(isEmptyString(trimString(ObjForm.shippingCity.value)))
	{
		alert("Please Enter The Shipping City");
		ObjForm.shippingCity.select();
		ObjForm.shippingCity.focus();
		return false;
	}
	var ObjShipStates= parent.frames['FrmShipstates'].document.formshipsates.shippingStateCode;
	if(isEmptyString(trimString(ObjShipStates.value)))
	{			
		alert("Please Provide the Shipping State");
		//parent.frames['FrmBillstates'].document.formshipsates.focus();
		return false;
	}
		
	
	if(isEmptyString(trimString(ObjForm.shippingZip.value)))
	{
		alert("Please Enter The Shipping zip");
		ObjForm.shippingZip.select();
		ObjForm.shippingZip.focus();
		return false;
	}
	if(ObjForm.shippingCountryCode.value=='US' || ObjForm.shippingCountryCode.value=='CA')
	{
		if(!checkZip(ObjForm.shippingCountryCode.value,ObjForm.shippingZip.value))
		{
			ObjForm.shippingZip.select();
			ObjForm.shippingZip.focus();
			return false;
		}
	}
	if(isEmptyString(trimString(ObjForm.shippingCountryCode.value)))
	{
		alert("Please Select Shipping Country");
		ObjForm.shippingCountryCode.focus();
		return false;
	}
	
	
	
	
	return true;
}