// JavaScript Document

function chkQty(id){
	qty = document.getElementById("qty_" + id);
	if(qty.value <25){
		alert("Quantity can not be less than 25 !");
		return false;
	}else{
		return true;
	}
	//return true;
}

function validateInfo(frm){
	var strError="";		
	
	if(isBlank(frm.firstname.value))
		strError += "First Name(Business)\n";
	if(isBlank(frm.lastname.value))
		strError += "Last Name(Business)\n"
	if(isBlank(frm.address.value))
		strError += "Address(Business)\n";
	if(isBlank(frm.country.value))
		strError += "Country(Business)\n";
	if(isBlank(frm.city.value))
		strError += "City(Business)\n";
	if(isBlank(frm.state.value))
		strError += "State(Business)\n";
	if(isBlank(frm.zip.value))
		strError += "Zip Code(Business)\n";
	if(isBlank(frm.phone.value))
		strError += "Phone Number(Business)\n";
	if(isBlank(frm.email.value))
		strError += "Email(Business)\n";
	else if(checkEmail(frm.email.value)==0)
		strError += "Email(Business)\n";
		
	if(isBlank(frm.s_firstname.value))
		strError += "First Name(Shipping)\n";
	if(isBlank(frm.s_lastname.value))
		strError += "Last Name(Shipping)\n"
	if(isBlank(frm.s_address.value))
		strError += "Address(Shipping)\n";
	if(isBlank(frm.s_country.value))
		strError += "Country(Shipping)\n";
	if(isBlank(frm.s_city.value))
		strError += "City(Shipping)\n";
	if(isBlank(frm.s_state.value))
		strError += "State(Shipping)\n";
	if(isBlank(frm.s_zip.value))
		strError += "Zip Code(Shipping)\n";
	if(isBlank(frm.s_phone.value))
		strError += "Phone Number(Shipping)\n";
	if(isBlank(frm.s_email.value))
		strError += "Email(Shipping)\n";
	else if(checkEmail(frm.s_email.value)==0)
		strError += "Email(Shipping)\n";
	
	if(strError!=""){		
		alert("Invalid Fields\n------------------------------------\n"+strError);
		return false;
	}	
	return true;

}


////*********************************/
function saa(){
	if(document.getElementById('chksame').checked){
		frm = document.frmcustomerinfo;
		frm.s_firstname.value = frm.firstname.value;
		frm.s_lastname.value = frm.lastname.value;
		//frm.s_gender.value = frm.gender.value;
		frm.s_address.value = frm.address.value;
		frm.s_address2.value = frm.address2.value;
		frm.s_country.value = frm.country.value;
		frm.s_city.value = frm.city.value;
		frm.s_state.value = frm.state.value;
		frm.s_zip.value = frm.zip.value;
		frm.s_phone.value = frm.phone.value;
		frm.s_fax.value = frm.fax.value;
		frm.s_mobile.value = frm.mobile.value;
		frm.s_email.value = frm.email.value;
		
		if(document.getElementById('male').checked){
		document.getElementById('s_male').checked= true;
		} else if(document.getElementById('female').checked){
		document.getElementById('s_female').checked= true;
		}
	}
}


function checkEmail()
	{
	var strEmail, strError, countAtRate, countDot, i;
	var checkAtRate, checkDot;
	var ValidChars,CountValidChars;
	ValidChars="abcdefghijklmnopqrstuvwxyz0123456789_.@ABCDEFGHIJKLMNOPQRSTUVWXYZ-";
	strEmail = checkEmail.arguments[0];

	countAtRate=0;
	countDot=0;
	CountValidChars=0;
	if (strEmail.length >= 7)
		{
		for(i=0;i<strEmail.length;i++)
			{
			if(strEmail.charAt(i)=="@")
				countAtRate++;
			if(strEmail.charAt(i)==".")
				countDot++;
			CountValidChars=0;
			for(j=0;j<ValidChars.length;j++)
				{
				if(strEmail.charAt(i)==ValidChars.charAt(j))
					{
					CountValidChars++;
					}
				}
			if(CountValidChars==0)
				{
				strError=0;
				break;
				}
			}
		}
	checkAtRate=strEmail.indexOf("@",1);
	checkDot=strEmail.indexOf(".",1);
	for(i=1;i<countDot;i++)
		checkDot=strEmail.indexOf(".",checkDot+1);
	if(countAtRate==1 && countDot > 0 && strEmail.length >=7 && strError != 0)
		strError=1;
	else
		strError=0;
	if(checkDot>=strEmail.length-2)
		strError=0;
	if(strEmail.charAt(0)=="@" || strEmail.charAt(strEmail.length-1)=="@")
		strError=0;
	if(strEmail.charAt(0)=="." || strEmail.charAt(strEmail.length-1)==".")
		strError=0;
	if(checkDot < checkAtRate)
		strError=0;

	return strError;
}


function isBlank(C) {
	for (i=0;i<C.length;i++) {if (C.charAt(i) != " ") return false}
	return true;
}

function keyCheck(eventObj, obj)
{
	var keyCode	
	
	// Check For Browser Type
	if (document.all){ 
		keyCode=eventObj.keyCode
	}
	else{
		keyCode=eventObj.which
	}

	var str=obj.value
	if(keyCode==46){ 
		if (str.indexOf(".")>0){
			return false
		}
	}
	
	if((keyCode<48 || keyCode >58)){ // Allow only integers
		return false
	}
	
	return true
}


