String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function validate() {
var chk1 = true;
var msg = "" ;
//url{'images/blkasterik.jpeg'}>" ;

	
		var regexp_user = /^[A-Za-z0-9_-]+$/;
		var testnumber=/^[0-9]+$/;
//user_ID
if((document.user.user_ID.value.trim()=="")){
   chk1=false;
   msg =msg + "<li type=disc> User Name is empty.It is required. </br />";
   document.user.user_ID.style.border="1px solid red ";
    }else if(document.user.user_ID.value.length<6){
    chk1=false;
	msg = msg + "<li type=disc> User Name is less than 6 characters. </br />";
	document.user.user_ID.style.border="1 px solid red ";
     }else if(document.user.user_ID.value>30){
      chk1=false;
	  msg = msg + "<li type=disc> User Name is more than 30 characters. </br />";
	  document.user.user_ID.style.border="1px solid red ";
        }else if(!regexp_user.test(document.user.user_ID.value)){
		     chk1=false;
             msg =msg + "<li type=disc> There is a restricted character in your user name.\nOnly letters,numbers,";
			 msg=msg  + "underscore and hyphens are allowed,without any spaces.  </br />";
		     document.user.user_ID.style.border="1px solid red ";
		  }else if(document.user.user_ID.value.trim().charAt(0)=="_"){
		     chk1=false;
             msg =msg + "<li type=disc> User name can not start with an underscore. </br />";
		     document.user.user_ID.style.border="1px solid red ";
		  }else if(document.user.user_ID.value.trim().charAt(0)=="-"){
		     chk1=false;
             msg =msg + "<li type=disc> User name can not start with hyphen '-'. </br />";
		     document.user.user_ID.style.border="1px solid red ";
		  }else if(testnumber.test(document.user.user_ID.value.trim().charAt(0))){
		     chk1=false;
             msg =msg + "<li type=disc> User name can not start with number.  </br />";
		     document.user.user_ID.style.border="1px solid red ";
		  }
 
   else{
	 document.user.user_ID.value=document.user.user_ID.value.trim()
	 document.user.user_ID.style.border="1px solid white ";
	      }
		  
//email

email=(document.user.user_Email.value)        
if((document.user.user_Email.value.trim()=="")){
     chk1=false;
     msg=msg + " <li type=disc> Email is empty so invalid.It is required. </br />"
     document.user.user_Email.style.border="1px solid red " ;
 }else if(!validateEmailv2(email)){
      chk1=false;
	  msg = msg + "<li type=disc> Invalid Email ID. </br />";
	  document.user.user_Email.style.border="1px solid red ";
    }
       else{
	              document.user.user_Email.value=document.user.user_Email.value.trim()
				  document.user.user_Email.style.border=" 1px solid white ";
	        }

//password

if((document.user.user_Password.value=="")){
     chk1=false;
	 msg = msg + "<li type=disc> Password is empty.It is required. </br /> ";
	 document.user.user_Password.style.border="1px solid red" ;
   }else if(document.user.user_Password.value.length<6){
     chk1=false;
	 msg = msg + "<li type=disc> Password is less than 6 characters.</br />";
	 document.user.user_Password.style.border="1px solid red" ;
   }else if(document.user.user_Password.value.length>30){
      chk1=false;
	  msg = msg + "<li type=disc> Password is more than 30 characters. </br /> " ;
	  document.user.user_Password.style.border="1px solid red ";
     }else if(document.user.user_Password.value==document.user.user_ID.value){
		     chk1=false;
             msg =msg + "<li type=disc> Username and password can not be identical..  </br />";
			  document.user.user_Password.style.border="1px solid red ";
		  }else if(!regexp_user.test(document.user.user_Password.value)){
	    chk1=false;
		msg=msg + "<li type=disc> There is a restricted character in your Password.\nOnly letters,numbers,";
	    msg=msg  + "underscore and hyphens are allowed,without any spaces.  </br />";
		document.user.user_Password.style.border="1px solid red ";
	 }
		else{
	   document.user.user_Password.style.border="1px solid white ";
     }


//confirm password

if((document.user.user_Password.value=="")  ||  (document.user.user_Confirmpassword.value=="") || (document.user.user_Password.value!=document.user.user_Confirmpassword.value))
	{
	     chk1=false;
         msg =msg + "<li type=disc> Passwords typed do not match.Please retype your passwords.</br />";
         document.user.user_Confirmpassword.style.border="1px solid red ";
	}else if(document.user.user_Confirmpassword.value==""){
		  chk1=false;
		  msg = msg + "<li type=disc> Confirm Password is Empty.It is required. </br />";
		  document.user.user_Confirmpassword.style.border="1px solid red";
	   }
	   else{
	     document.user.user_Confirmpassword.style.border="1px solid white ";
	     }
		  
//security code
if(document.user.passline.value.trim()==""){
        chk1=false;
        msg =msg + "<li type=disc> Security Code is Empty.It is required. </br />";
        document.user.passline.style.border="1px solid red ";
	 }else{
	      document.user.passline.style.border="1px solid white ";
	      }

//disclaimer
				if(!document.user.agree_disc.checked) {
					chk1=false;
					msg=msg + " <li type=disc> Accepting Terms of Service is required.";
				}
				
	

//for check------------------
if(chk1==false){

document.getElementById("message23").innerHTML="<b>Please complete the following :</b> <br /><div style='padding-left:13px'><ul style=list-style-type: circle>" + msg +" </ul></div>";
document.getElementById("errortablecontent1").style.display="block";


	return false;
	
	
	}
	else{
	document.user.submit();}
}


function validateEmailv2(email)
			{
				if(email.length <= 0)
				{
				  return true;
				}
				var splitted = email.match("^(.+)@(.+)$");
				if(splitted == null) return false;
				if(splitted[1] != null )
				{
				  var regexp_userInd=/^\"?[\w-_\.]*\"?$/;
				  if(splitted[1].match(regexp_userInd) == null) return false;
				}
				if(splitted[2] != null)
				{
				  var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
				  if(splitted[2].match(regexp_domain) == null) 
				  {
					var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
					if(splitted[2].match(regexp_ip) == null) return false;
				  }// if
				  return true;
				}
			return false;
			}




function apply()
{
	if((document.user.user_ID.value.trim()=="") || (document.user.user_Email.value.trim()=="") || (document.user.user_Password.value=="") ||(document.user.user_Confirmpassword.value=="") || (document.user.passline.value.trim()=="") ){
	document.user.agree_disc.checked=false;
	return validate();
	}else{
		if(document.user.agree_disc.checked==false){
		document.getElementById("btnsubmit").src="images/join_desable.gif"
	    document.getElementById("btnsubmit").disabled=true;
		 return validate();
		}else{
		document.getElementById("btnsubmit").src="images/join.gif"
	    document.getElementById("btnsubmit").disabled=false;

		}
	}

   /* document.getElementById("btnsubmit").disabled=true;
	//alert("apply calddd1" +document.user.agree_disc.checked);

  if(document.user.agree_disc.checked==true)
  {
    document.getElementById("btnsubmit").disabled=false;
  }
  if(document.user.agree_disc.checked==false)
  {
    document.getElementById("btnsubmit").disabled=false;
  }
  */
}