function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function test(){
    if(document.signup.shipping_same_as_billing.checked)
        {

            document.signup.shipping_address.value=document.signup.address.value;
            document.signup.shipping_address2.value=document.signup.address2.value;
            document.signup.shipping_city.value=document.signup.city.value;
            document.signup.shipping_state.value=document.signup.state.value;
            document.signup.shipping_zip.value=document.signup.zip.value;
            document.signup.shipping_country.value=document.signup.country.value;
            document.signup.shipping_phone.value=document.signup.phone.value;
            document.signup.shipping_fax.value=document.signup.fax.value;
            document.signup.shipping_name_first.value=document.signup.name_first.value;
            document.signup.shipping_name_last.value=document.signup.name_last.value;
            document.signup.shipping_company.value=document.signup.company.value;


        } else {
            document.signup.shipping_address.value="";
            document.signup.shipping_address2.value="";
            document.signup.shipping_city.value="";
            document.signup.shipping_state.value="";
            document.signup.shipping_zip.value="";
            document.signup.shipping_country.value="";
            document.signup.shipping_phone.value="";
            document.signup.shipping_fax.value="";
            document.signup.shipping_company.value="";
            document.signup.shipping_name_first.value="";
            document.signup.shipping_name_last.value="";
        }

}



function validate(login)
{

     //if (IsNumeric(document.signup.zip.value) == false)
   //   {
    //  alert("Please check - non numeric value!");
    //  return false;
    //  }
      
    var at="@"
    var dot="."

    if (login.value.indexOf(at)==-1){
        alert("Invalid E-mail ID ...please enter whole ID ");
        return false;

    }

    if (login.value.indexOf(dot)==-1){
        alert("Invalid E-mail ID ...please enter properly");
        return false;

    }

    if(!document.signup.accept_terms.checked)
    {
        alert("please accept all terms");
        return false;
    }

    if(trim(document.signup.login.value, "") == "")
    {
        alert("please enter the username");
        document.signup.login.focus();
        return false;
    }


    if(trim(document.signup.password.value,"")=="")
    {
        alert("please enter the password");
        document.signup.password.focus();
        return false;
    }

    if(trim(document.signup.password2.value,"")=="")
    {
        alert("please enter  confirm password");
        document.signup.password2.focus();
        return false;
    }

    if(trim(document.signup.name_first.value,"")=="")
    {
        alert("please enter Your First name");
        document.signup.name_first.focus();
        return false;
    }
    if(trim(document.signup.name_last.value,"")=="")
    {
        alert("please enter last name");
        document.signup.name_last.focus();
        return false;
    }
   // if(trim(document.signup.company.value,"")=="")
  //  {
        //alert("Plz enter your company name");
       // document.signup.company.focus();
        //return false;
   // }

    if((document.signup.password.value)!=(document.signup.password2.value))
    {
        alert("please confirm the password");
        document.signup.password.focus();
        return false;
    }


    //if(trim(document.signup.business_type.value,"")=="")
    //{
        //alert("Plz enter business types");
       // document.signup.business_type.focus();
      //  return false;
 //   }

    //if(trim(document.signup.knowledge_source.value,"")=="")
 //   {
  //      alert("please enter knowledge source");
  //      document.signup.knowledge_source.focus();
  //      return false;
   // }
    if(trim(document.signup.address.value,"")=="")
    {
        alert("please enter your address");
        document.signup.address.focus();
        return false;-54151
    }

 
    if(trim(document.signup.city.value,"")=="")
    {
        alert("please enter city");
        document.signup.city.focus();
        return false;
    }

    if(trim(document.signup.zip.value,"")=="")
    {
        alert("please enter zip code");
        document.signup.zip.focus();
       return false;
    }

    if(trim(document.signup.phone.value,"")=="")
    {
        alert("please enter phone no");
        document.signup.phone.focus();
        return false;
    }

   // if(trim(document.signup.shipping_company.value,"")=="")
    //{
        //alert("please enter shipping company name");
        //document.signup.shipping_company.focus();
       // return false;
  //  }

    if(trim(document.signup.shipping_name_first.value,"")=="")
    {
        alert("please enter shipping first name");
        document.signup.shipping_name_first.focus();
        return false;
    }

    if(trim(document.signup.shipping_name_last.value,"")=="")
    {
        alert("Plz confirm Shipping last name");
        document.signup.shipping_name_last.focus();
        return false;
    }

    if(trim(document.signup.shipping_address.value,"")=="")
    {
        alert("please confirm shipping address");
        document.signup.shipping_address.focus();
        return false;
    }

   /* if(trim(document.signup.shipping_address2.value,"")=="")
    {
        alert("Plz confirm Shipping address 2");
        document.signup.shipping_address2.focus();
        return false;
    } */

    if(trim(document.signup.shipping_city.value,"")=="")
    {
        alert("please confirm shipping city");
        document.signup.shipping_city.focus();
        return false;
    } 

    if(trim(document.signup.shipping_zip.value,"")=="")
    {
        alert("please confirm the shipping zip");
        document.signup.shipping_zip.focus();
        return false;
    }




    if(trim(document.signup.shipping_phone.value,"")=="")
    {
        alert("please confirm shipping phone no");
        document.signup.shipping_phone.focus();
        return false;
    }

}

function IsNumeric(strString)
   //  check for valid numeric strings
   {

   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

		function emptyValidation2(fieldList, msgdiv) {
				
				var field=new Array();
				field=fieldList.split("~");
				var counter=0;
				for(i=0;i<field.length;i++) {
					if( trim(document.getElementById(field[i]).value) == "" || trim(document.getElementById(field[i]).value) =="0" ) {
						document.getElementById(field[i]).style.border="#FF0000 1px solid";
						counter++;
					} else {
						document.getElementById(field[i]).style.border="#999999 1px solid";
						
					}
				}		
				
				if(counter>0) {
					var o = document.getElementById(msgdiv);
					o.className = 'error';
					o.innerHTML='Please populate the required fields.';
					return false;				
				}  else {
					return true;
				}		
				
		}
		
		function creditCardValidate() {
			
			var checkValidation=emptyValidation2('type~card_number~ex_month~ex_year~holder_name~address~city~state~zip~country', 'msgdiv');
			if(checkValidation == false) {
				return false;
			} else {
			
				document.getElementById("type").style.visibility = 'hidden';
				document.getElementById("ex_month").style.visibility = 'hidden';
				document.getElementById("ex_year").style.visibility = 'hidden';
				document.getElementById("state").style.visibility = 'hidden';
				document.getElementById("country").style.visibility = 'hidden';	
				
				showLayerH();
				
				setTimeout("frmsubmit()", 3000);
			}
			
		}

		function frmsubmit() {
			document.signup.submit();
		}
				function isnum(e,fieldid){var txtvalue=document.getElementById(fieldid).value;var k=0;for(var i=0;i<txtvalue.length;i++){var c;document.all ?c=e.keyCode:c=e.which;if(((txtvalue.charAt(i)>='0')&&(txtvalue.charAt(i)<="9"))||(txtvalue.charAt(i)=='-')||(c==8)||(c==32)){}else{k++};}if(k!=0)document.getElementById(fieldid).value=txtvalue.substring(0,txtvalue.length-1);}

function isSpace(tbox, chr) {	
tbox.value=tbox.value.replace(chr,''); //replaces specified character with nothing
}

