function checkAll(field)
	{
	if (field[0].checked == true){
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
	}
	else{
		for (i = 0; i < field.length; i++)
		field[i].checked = false ;
	}
	}
	
//Pop up a new window
function popup(aUrl,width,height) 
 { var w;
   var u;
   var s = 'scrollbars=no,menubar=no,status=no,toolbar=no,left=10,top=10,width=' + width + ',height=' + height;
   u = aUrl;w = window.open(u,'',s);
 }

function antispam(name,domain) {
    	document.location = "mailto:" + name + "@" + domain;
	}

function validateregister(form){

checkCompanyName = trim(form.txtCompanyName.value)
checkAddress = trim(form.txtAddress.value)
checkCity = trim(form.txtCity.value)
checkState = trim(form.txtState.value)
checkCountry = form.cbbCountry.selectedIndex
checkBusiness= form.cbbBusiness.selectedIndex
checkGivenName = trim(form.txtGivenName.value)
checkFamilyName = trim(form.txtFamilyName.value)
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")
checkLogin = trim(form.txtLogin.value)
checkPassword = trim(form.txtPassword.value)
checkPassword2 = trim(form.txtPassword2.value)

if (checkCompanyName.length < 1){
alert("Please enter your company name")
return false
}
else if (checkAddress.length < 1){
alert("Please enter your address")
return false
}
else if (checkCity.length < 1){
alert("Please enter your city")
return false
}
else if (checkState.length < 1){
alert("Please enter your state")
return false
}
else if (checkCountry == 0){
alert("Please choose your country")
return false
}
else if (checkBusiness == 0){
alert("Please choose your business type")
return false
}
else if (checkGivenName.length < 1){
alert("Please enter your given name")
return false
}
else if (checkFamilyName.length < 1){
alert("Please enter your family name")
return false
}
else if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email")
return false
}
else if (checkLogin.length < 1){
alert("Please enter your login name")
return false
}
else if (checkPassword.length < 1){
alert("Please enter your password")
return false
}
else if (checkPassword != checkPassword2){
alert("Both passwords are not matched. Please re-enter your password")
return false
}

return true
}

function validatelogin(form){

checkLogin = trim(form.txtLogin.value)
checkPassword = trim(form.txtPassword.value)

if (checkLogin.length < 1){
alert("Please enter your login name")
return false
}
else if (checkPassword.length < 1){
alert("Please enter your password")
return false
}

return true
}

function validatesearch(form){

checkSearch = trim(form.txtSearch.value)

if (checkSearch.length < 1){
alert("Please enter your keywords")
return false
}

return true
}

function validateprofile(form){

checkCompanyName = trim(form.txtCompanyName.value)
checkAddress = trim(form.txtAddress.value)
checkCity = trim(form.txtCity.value)
checkState = trim(form.txtState.value)
checkCountry = form.cbbCountry.selectedIndex
checkBusiness= form.cbbBusiness.selectedIndex
checkGivenName = trim(form.txtGivenName.value)
checkFamilyName = trim(form.txtFamilyName.value)
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")

if (checkCompanyName.length < 1){
alert("Please enter your company name")
return false
}
else if (checkAddress.length < 1){
alert("Please enter your address")
return false
}
else if (checkCity.length < 1){
alert("Please enter your city")
return false
}
else if (checkState.length < 1){
alert("Please enter your state")
return false
}
else if (checkCountry == 0){
alert("Please choose your country")
return false
}
else if (checkBusiness == 0){
alert("Please choose your business type")
return false
}
else if (checkGivenName.length < 1){
alert("Please enter your given name")
return false
}
else if (checkFamilyName.length < 1){
alert("Please enter your family name")
return false
}
else if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email")
return false
}

return true
}

function validateemail(form){

checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")

if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email")
return false
}
return true
}

function validateorder(form){

checkQuantity = trim(form.txtQuantity.value)

if (checkQuantity.length < 1){
alert("Please enter quantity")
return false
}
else if(isNaN(checkQuantity)) {
alert("Only numbers are allowed")
return false
}

return true
}

function validateupdateorder(form){

	for(i=0;i<form.txtQuantity.length;i++)
	{

checkQuantity = trim(form.txtQuantity[i].value)

if (checkQuantity.length < 1){
alert("Please enter quantity")
return false
}
else if(isNaN(checkQuantity)) {
alert("Only numbers are allowed")
return false
}
}
return true
}

function validateconfirmorder(form){
checkBilling = trim(form.txtBilling.value)
checkShipping = trim(form.txtShipping.value)

	if (checkBilling.length < 1){
	alert("Please enter your billing address")
	return false
	}
	else if (checkShipping.length < 1){
	alert("Please enter your shipping address")
	return false
	}
	else if (form.chkAgree.checked==false){
	alert("You must accept the Terms and Conditions before checkout.");
	return false;
	}
	
return true
}

/*	
function validateenquiry(form){
checkName = trim(form.txtName.value)
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")
checkPhone = trim(form.txtPhone.value)
checkCAPTCHA = trim(form.txtCAPTCHA.value)

if (checkName.length < 1){
alert("Please enter your name")
return false
}
else if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email.")
return false
}
else if (checkPhone.length < 1){
alert("Please enter your phone")
return false
}
else if (checkCAPTCHA.length < 1){
alert("Write the characters in the image above")
return false
}

return true
}

function validatecontact(form){
checkSubject = trim(form.txtSubject.value)
checkMessage = trim(form.txtMessage.value)
checkName = trim(form.txtName.value)
checkEmail = trim(form.txtEmail.value)
aliaspos = checkEmail.indexOf("@")
dotpos = checkEmail.lastIndexOf(".")
checkPhone = trim(form.txtPhone.value)
checkCAPTCHA = trim(form.txtCAPTCHA.value)

if (checkSubject.length < 1){
alert("Please enter your subject")
return false
}
else if (checkMessage.length < 1){
alert("Please enter your message")
return false
}
else if (checkName.length < 1){
alert("Please enter your name")
return false
}
else if (checkEmail.length < 1){
alert("Please enter your email")
return false
}
else if (aliaspos == -1 || dotpos == -1)
{ alert ("Not a valid email.")
return false
}
else if (checkPhone.length < 1){
alert("Please enter your phone")
return false
}
else if (checkCAPTCHA.length < 1){
alert("Write the characters in the image above")
return false
}

return true
}
*/

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
	
//howManyChecked('myform','cb_industry',6,1,'Industry');
function howManyChecked(whichForm,whichCheckBoxArray,myMax,myMin,whichQuestion)
/*
  This function takes 5 paramaters:
  whichForm -- the NAME of the form to be validated, a string
  whichCheckBoxArray -- the NAME of the checkbox to be checked, a string
  myMax -- the most you want the user to be able to check, an integer
  myMin -- the least you want the user to be able to check, an integer
  whichQuestion -- a short description of the question, a string
  
  example use:
  howManyChecked('myform','cb_industry',6,1,'Industry');
*/
{
	var _countChecked = 0;
	var err = 0;
	/* iterate through all the elements in the checkbox array */
	for(i=1;i<document[whichForm][whichCheckBoxArray].length;i++)
	{
		/* and check to see if each is checked */
		if(document[whichForm][whichCheckBoxArray][i].checked==true)
			/* if it is, increment a counter */
			{ _countChecked++; }
	}
	/* is the count too high? */
	if(_countChecked > myMax)
		{ alert('Limit '+myMax+' checks for '+whichQuestion);
			err = 1;}
	/* of is the count too low */
	else if(_countChecked < myMin)
		{ alert('You must fill out at least '+myMin+' entry(s) for '+whichQuestion);
			err = 1;}
	if (err == 1) { return false; }
}
		
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
  