function textCounter(field){
    if ( field.value.length > 500 )
  {
    field.focus();
    alert( 'Textarea value can only be 500 characters in length.' );
    return false;
  }
  else
  {
    return true;
  }

    
    
}
function alphNumeric_pwd(obj){
       var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
       var num = "0123456789";
       var alphnum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	  var checkStr = obj.value;
	  var allValid = true;
          var allnum = true;
          var allAlpNum = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
    	        ch = checkStr.charAt(i);
		    for (j = 0;  j < checkOK.length;  j++)
		      if (ch == checkOK.charAt(j))
        		break;
		    if (j == checkOK.length)
		    {
	    	  allValid = false;
                 
    		  break;
		    }
  	}
       
       
         for (i = 0;  i < checkStr.length;  i++)
	  {
    	ch = checkStr.charAt(i);
		    for (j = 0;  j < num.length;  j++)
		      if (ch == num.charAt(j))
        		break;
		    if (j == num.length)
		    {
	    	    allnum = false;

    		  break;
                    }    
                    
                    }
       
       for (i = 0;  i < checkStr.length;  i++)
	  {
    	ch = checkStr.charAt(i);
		    for (j = 0;  j < alphnum.length;  j++)
		      if (ch == alphnum.charAt(j))
        		break;
		    if (j == alphnum.length)
		    {
	    	  allAlpNum = false;
                   
    		  break;
		    }
         }
        
         
  	
  if (allValid)
  {  
   
    alert("Password must be Alphanumeric");
    obj.focus();
      obj.value="";
    return false;
  }
  
  if (allnum)
  {  
   
    alert("Password must be Alphanumeric");
    obj.focus();
      obj.value="";
    return false;
  }
  
  if (!allAlpNum)
  {  
   
    alert("Password must be Alphanumeric");
    obj.focus();
      obj.value="";
    return false;
  }
  
  
  if(obj.value.length < 5){
       alert("Password must contain  min 5 characters!");
       obj.focus();
        obj.value="";
     return false; 
    }
  return true;
}
function isAlphau(obj){
           
        

	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
	  var checkStr = obj.value;
	  var allValid = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
    	   ch = checkStr.charAt(i);
		    for (j = 0;  j < checkOK.length;  j++)
		      if (ch == checkOK.charAt(j))
        		break;
		    if (j == checkOK.length)
		    {
	    	  allValid = false;
    		  break;
		    }
  	}
  if (!allValid)
  {
    alert("Please enter only letter characters in the field.");
    obj.focus();
     obj.value="";
    return false;
  }
  
if (obj.value.length<5) {
 
   alert("User Name contain atleast 5 characters ");
   obj.focus();
   obj.value="";
   return false;
}
  return true;
}
 
 
 function isAlpha(obj){
           
        

	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	  var checkStr = obj.value;
	  var allValid = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
    	   ch = checkStr.charAt(i);
		    for (j = 0;  j < checkOK.length;  j++)
		      if (ch == checkOK.charAt(j))
        		break;
		    if (j == checkOK.length)
		    {
	    	  allValid = false;
    		  break;
		    }
  	}
  if (!allValid)
  {
    alert("Please enter only characters in the field.");
    obj.focus();
    obj.value="";
    return false;
  }
 }
 
 function isNumeric(obj)
  {
	  var checkOK = "0123456789";
	  var checkStr = obj.value;
	  var allValid = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
    	ch = checkStr.charAt(i);
		    for (j = 0;  j < checkOK.length;  j++)
		      if (ch == checkOK.charAt(j))
        		break;
		    if (j == checkOK.length)
		    {
	    	  allValid = false;
    		  break;
		    }
  	}
  if (!allValid)
  {
    alert("Please enter only numeric values in the field.");
    obj.value="";
    obj.focus();
    return (false);
  }
   return true;
  
}

function validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="") {
			alert(alerttxt);
			return false;
		}
		else {
			return true;
		}
	}
}

function validate_email(field,alerttxt) {
   
	with (field) {
                if (value==null||value=="") {
			alert(alerttxt);
			return false;
		}
		
	    else if (apos<1||dotpos-apos<2) {
                apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
	}
}
function validate_Select(){
    
    if(document.aspnetForm.BusinessType[document.aspnetForm.BusinessType.selectedIndex].value== ""){
        alert("Please Select Business Type");
       return false;
         }
       else{
           return true;
       }
    
}


function validate_countrycodephone(){
   var obj = document.getElementById('txtPhoneCountryCode');
    var value = document.getElementById('txtPhoneCountryCode').value;
    
    if (value == "" ){
    
    alert("Please specify your Country Code");
    return false;
    }
    
    else if(value.length<3){
         value="";
         obj.focus();
         alert(" Country Code must contain atleast 3 characters!");
          return false;
    }
    else {
       
        var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

  

   //  test strString consists of valid characters listed above
   for (i = 0; i < value.length && blnResult == true; i++)
      {
      strChar = value.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
      if(blnResult == false){
       value="";
       obj.focus();
          alert("Country Code must contain numeric value")
      }
   return blnResult;
 
    }

 validate_citycodephone();
   
   
  
    
}

function validate_citycodephone(){
   var obj = document.getElementById('txtPhoneCityCode');
    var value = document.getElementById('txtPhoneCityCode').value;
    
    if (value == "" ){
    
    alert("Please specify your City Code");
    return false;
    }
    
    else if(value.length<3){
         value="";
         obj.focus();
         alert("City Code must contain atleast 3 characters!");
          return false;
    }
    else {
       
        var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

  

   //  test strString consists of valid characters listed above
   for (i = 0; i < value.length && blnResult == true; i++)
      {
      strChar = value.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
      if(blnResult == false){
       value="";
       obj.focus();
          alert("City Code contain numeric value")
      }
   return blnResult;
 
    }

 validate_phone();
   
   
  
    
}

function validate_phone(){
   var obj = document.getElementById('txtPhone');
    var value = document.getElementById('txtPhone').value;
    
    if (value == "" ){
    
    alert("Please specify your phone number");
    return false;
    }
    
    else if(value.length<7){
         value="";
         obj.focus();
         alert(" phone number must contain atleast 7 characters!");
          return false;
    }
    else {
       
        var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

  

   //  test strString consists of valid characters listed above
   for (i = 0; i < value.length && blnResult == true; i++)
      {
      strChar = value.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
      if(blnResult == false){
       value="";
       obj.focus();
          alert("Phone number must contain numeric value")
      }
   return blnResult;
 
    }

 return true;
   
   
  
    
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(obj) {
               var str = obj.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.aspnetForm.email_ID;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

function isAlphanumeric(obj){
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	  var checkStr = obj.value;
	  var allValid = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
    	ch = checkStr.charAt(i);
		    for (j = 0;  j < checkOK.length;  j++)
		      if (ch == checkOK.charAt(j))
        		break;
		    if (j == checkOK.length)
		    {
	    	  allValid = false;
    		  break;
		    }
  	}
  if (!allValid)
  {
    alert("Please enter only letter and numeric characters in the field.");
    obj.focus();
      obj.value="";
    return false;
  }
  return true;
}
function validate_pwd(){
    
    if(document.regForm.pwd.value ==""){
    document.regForm.pwd.focus();
        alert("Please specify your Password! "); 
        
     return false; 
    }
   else if(document.regForm.pwd.value.length < 5){
       document.regForm.pwd.value="";
       document.regForm.pwd.focus();
       alert("Password must contain  min 5 characters!");
        
     return false; 
    }
   else if(document.regForm.c_pwd.value ==""){
   document.regForm.pwd.focus();
        alert("Please specify your Verify Password! "); 
        
     return false; 
    }
   
    
    
    else if( document.regForm.pwd.value != document.regForm.c_pwd.value) 
     { 
      alert("Please verify the password!");
      document.regForm.pwd.focus();
       document.regForm.pwd.value="";
     document.regForm.c_pwd.value="";
     return false; 
     } 
     
     else{
         return true;
     }
    
}


function validate_check(){
 
if (!document.regForm.knowus[0].checked && !document.regForm.knowus[1].checked && !document.regForm.knowus[2].checked && !document.regForm.knowus[3].checked){

alert("Please mansion How did you know about us?");
return false;

}
else if(!document.regForm.busi[0].checked && !document.regForm.busi[1].checked && !document.regForm.busi[2].checked && !document.regForm.busi[3].checked){
alert("Please mansion Describes your Business");
return false;
}else {
   return true;
}

}

function validate_usernameLogin(){
    
if(document.login.usr.value==""){
alert("Please specify your Username ");

return false;
}


else{
return true;
}
}

function validate_pwdLogin(){

if(document.login.pwd.value ==""){
alert("Please specify your Password! ");

return false;
}

return true;
}
function validate_login(thisform) {

with (thisform) {

 

if (validate_usernameLogin()==false) {

return false;
}

if (validate_pwdLogin()==false) {

return false;
}

return true;
}
}
function clean(obj){

 obj.value="";
   
} 

function validate_FeedBabkform(thisform){

        
	with (thisform) {
       
            if (validate_required(fname,"Please specify your Firstname!")==false) {
			fname.focus();
			return false;
		    }
			if (validate_required(phone,"Please specify your Phone No!")==false) {
			phone.focus();
			return false;
		    }
			if (validate_required(emailId,"Please specify your Email Id!")==false) {
			emailId.focus();
			return false;
		    }
			if (validate_required(comment,"Comment is required!")==false) {
			emailId.focus();
			return false;
		    }
		} 

}
function validate_username(){
   
   if(document.regForm.usr.value==""){
   document.regForm.usr.focus();
        alert("Please specify your Username "); 
        
     return false; 
    }
    
   
  else{
      return true;
  }
}

function validate_regform(thisform) {
        
	with (thisform) {
       if(ValidCaptcha()==false)
{
return false;
}		
                 
       if (validate_username()==false) {
			
			return false;
		} 
                
           if (validate_pwd()==false) {
			
			return false;
		}
            if (validate_required(fnm,"Please specify your Firstname!")==false) {
			fnm.focus();
			return false;
		}
                if (validate_required(lnm,"Please specify your Lastname!")==false) {
			lnm.focus();
			return false;
		}
                 if (validate_required(co_nme,"Please specify your Company Name!")==false) {
			co_nme.focus();
			return false;
		}
              if (validate_required(buildnme,"Please specify your Building Name / Suite !")==false) {
			buildnme.focus();
			return false;
		}  
                 if (validate_required(city,"Please specify your City!")==false) {
			city.focus();
			return false;
		}
                if (validate_required(state,"Please specify your State!")==false) {
			state.focus();
			return false;
		}
                if (validate_required(country,"Please specify your Country!")==false) {
			country.focus();
			return false;
		}
                if (validate_required(pincode,"Please specify your Pincode!")==false) {
			pincode.focus();
			return false;
		}
		
		
        if (validate_countrycodephone()==false) {
			
			return false;
		}
         if (ValidateForm()==false) {
			
			return false;
		}
              if (validate_Select()==false) {
			
			return false;
		}
		
                
                 
           return true;
	}
}

function validate_usernameInvenLogin(){
    
if(document.Invenlogin.usr.value==""){
alert("Please specify your Username ");

return false;
}


else{
return true;
}
}

function validate_pwdInvenLogin(){

if(document.Invenlogin.pwd.value ==""){
alert("Please specify your Password! ");

return false;
}

return true;
}
function validate_Invenlogin(thisform) {

with (thisform) {



if (validate_usernameInvenLogin()==false) {

return false;
}

if (validate_pwdInvenLogin()==false) {

return false;
}

return true;
}
}

function initRequest() {
       if (window.XMLHttpRequest) {
           return new XMLHttpRequest();
       } else if (window.ActiveXObject) {
           isIE = true;
           return new ActiveXObject("Microsoft.XMLHTTP");
       }
   }

function checkUser(obj){
   

    var fldVal = obj.value;
   
    
     var url = 'http://www.dajhaveri.com/daj/ajaxAction.do?usrNme='+fldVal ;
    
           var req = initRequest();
           req.onreadystatechange = function() {
               if (req.readyState == 4) {
                   if (req.status == 200) {
                       parseMessages(req.responseXML);
                   } else if (req.status == 204){
                        parseMessages(req.responseXML);
                   }
               }
           };
           req.open("GET", url, true);
           req.send(null);
}

 function parseMessages(responseXML) {
 
  var message = responseXML.getElementsByTagName("message")[0];
   var check =  message.childNodes[0].nodeValue;
  
   var mdiv = document.getElementById("checkUsr");
   if(check=='invalid'){
     
        document.getElementById('usr').value = "";
		 document.getElementById('usr').focus();
       mdiv.innerHTML = "<div style=\"color:red\">Username already exit Please change and try again  </ div>";

   }else{
        mdiv.innerHTML = "";
   }
  
 }
 
 function ValidCaptcha(){

var str1 = document.getElementById('txtCaptcha').value.replace(/\s/g, "");
var str2 = document.getElementById('secuCode').value.replace(/\s/g, "");

if (str1 == str2){
return true;
}else{
alert("Please enter given Security Code");
return false;
}

}

