// client registeration JavaScript Document
function chkregister()
{
 	  firstname = document.getElementById('firstname').value		//client login values
 	   lastname = document.getElementById('lastname').value
 	   email_id = document.getElementById('email_id').value
 	      phone = document.getElementById('c_phone').value
	      state = document.getElementById('state_name').value
	  
	        city = document.getElementById('city').value
	    username = document.getElementById('username').value
	    password = document.getElementById('password').value
	  repassword = document.getElementById('repassword').value
	  image_code = document.getElementById('secCode').value
	  
	  client_hidediv();
 		
	  var error_count=0;
	  var error_lines=0;
	  var no_error=0;
	  var error_messages = new Array();	  		//array to store error messages
	     var ck_name = /^[a-zA-Z]+$/   
	  var digitcheck = /^[0-9]+$/
	  var image_set=0;
	    var email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	  var userchk = /^[a-zA-Z0-9_.]+$/
	  var fl_name = /^[-\sa-zA-Z]+$/
	   var chk = '';
	  var chk1 = '';

	  firs_char = firstname.charAt(0);
	  if ((firstname==0) ) 
	  {
		  if(error_lines<error_limit)
		  {	
			   error_count=error_count+1;
			   error_messages[no_error]=error_count+". "+fname_empty;
			   ++no_error;
			   error_lines=error_lines+1;
			   image_set=1;
		  }
	  }
	  if((!fl_name.test(firstname) || !ck_name.test(firs_char)) && firstname!=0)
	  {
		   if(error_lines<error_limit)
		   {
			   error_count=error_count+1;
			   error_messages[no_error]=error_count+". "+fname_err;
			   ++no_error;
			   ++error_lines;
			   image_set=1;
		   }
	 }
			  
	  if (firstname!=0 && fl_name.test(firstname))
	  {
		   if(firstname.length < 2 )
		   {
			   if(error_lines<error_limit)
			   {
				   error_count=error_count+1;	
				   error_messages[no_error]=error_count+". "+fname_shrt;
				   ++no_error;
				   ++error_lines;
				   image_set=1;
			   }
		   }
	  }
	  if(firstname!=0 && fl_name.test(firstname))
	  {
		  if(firstname.length > 20 )
		  {
			   if(error_lines<error_limit)
			   {
				   error_count=error_count+1;	
				   error_messages[no_error]=error_count+". "+fname_lng;
				   ++no_error;
				   ++error_lines;
				   image_set=1;
			   }
		  }
	  }
			   
	  if (image_set==1)
	  {
		error_img = 'number_'+error_count;
		document.getElementById('fname_num').src='../images/'+error_img+'.gif';
		document.getElementById('fname_num').style.visibility='visible';
		document.getElementById('fname_arrow').style.visibility='visible';
		image_set=0;
	  }
	
		/*----------------------------//Last name//---------------------------------------*/	
	  las_char = lastname.charAt(0);
	  
	  if ((lastname==0))
	  {
		   if(error_lines<error_limit)
		   {	
			   error_count=error_count+1;	
			   error_messages[no_error]=error_count+". "+lname_empty;
			   ++no_error;
			   error_lines=error_lines+1;
			   image_set=1;
		  }
	  }
  
	  if((!fl_name.test(lastname)|| !ck_name.test(las_char)) && lastname!=0)
	  {
		  if(error_lines<error_limit)
		  {
			error_count=error_count+1;
			error_messages[no_error]=error_count+". "+lname_err;
			++no_error;
			++error_lines;
			image_set=1;
		  }
	  }
			  
	  if (lastname!=0 && fl_name.test(lastname))
	  {
		  if(lastname.length < 2)
		  {
			  if(error_lines<error_limit)
			  {
				error_count=error_count+1;	
				error_messages[no_error]=error_count+". "+lname_shrt;
				++no_error;
				++error_lines;
				image_set=1;
			  }
		  }
	  } 
		   
	  if (lastname!=0 && fl_name.test(lastname))
	  {
		  if(lastname.length >20)
		  {
			  if(error_lines<error_limit)
			  {
				error_count=error_count+1;	
				error_messages[no_error]=error_count+". "+lname_lng;
				++no_error;
				++error_lines;
				image_set=1;
			  }
		  }
	  } 
		  
	  if (image_set==1)
	  {
		   error_img = 'number_'+error_count;
		   document.getElementById('lname_num').src='../images/'+error_img+'.gif';
		   document.getElementById('lname_num').style.visibility='visible';
		   document.getElementById('lname_arrow').style.visibility='visible';
		   image_set=0;
	  }
	
	/*----------------------------//Email Address//---------------------------------------*/
	
	  if (email_id==0 )
	  {
		  if(error_lines<error_limit)
		  {
			   error_count=error_count+1; 
			   error_messages[no_error]=error_count+". "+email_empty;
			   ++no_error;
			   ++error_lines;
			   image_set=1;
			   chk=1;
		  }
	  }
	  
	  if(!email.test(email_id) && email_id!=0)
	  {
		  if(error_lines<error_limit)
		  {
			  ++error_count;
			  error_messages[no_error]=error_count+".  "+email_err;
			  ++no_error;
			  ++error_lines;
			  image_set=1;
			  chk=1;
		  }
	  }
	  
	  if(chk != 1)
	  {
		  result=check_email();
		  if(result == 1)
		  {
			  if(error_lines<error_limit)
			  {	
				   error_count=error_count+1;
				   error_messages[no_error]=error_count+". "+email_valid;
				   ++no_error;
				   ++error_lines;
				   image_set=1;
			  }
		  }
	  }
					  
	  if (image_set==1)
	  {
		  error_img = 'number_'+error_count;
		  document.getElementById('email_num').src='../images/'+error_img+'.gif';
		  document.getElementById('email_num').style.visibility='visible';
		  document.getElementById('email_arrow').style.visibility='visible';
		  image_set=0;
	  }
		
 /*----------------------------//Phone number//---------------------------------------*/	
  
	  first_char = phone.charAt(0);
	  if (phone== 0)
	  {
		  if(error_lines<error_limit)
		  {	
			   error_count=error_count+1; 
			   error_messages[no_error]=error_count+". "+ph_empty;
			   no_error=no_error+1;
			   error_lines=error_lines+1;
			   image_set=1;
		  }
	  }
	  
	  if(phone!=0 && !image_set)
	  {
		  if(!(digitcheck.test(phone)) && (first_char!='+'))
		  {
			  if(error_lines<error_limit)
			  {
				  error_count=error_count+1;	 
				  error_messages[no_error]=error_count+". "+ph_err;
				  ++no_error;
				  ++error_lines;
				  image_set=1;
			  }
		  }
		  
		  if((digitcheck.test(phone)||(first_char=='+'))&& !image_set)
		  {
			  if(phone.length < 7 || phone.length >15 )
			  {
				  if(error_lines<error_limit)
				  {
					   error_count=error_count+1;	
					   error_messages[no_error]=error_count+". "+ph_less;
					   ++no_error;
					   ++error_lines;
					   image_set=1;
				  }
			  }
		  }
	  }
		  
	  if (image_set==1)
	  {
		error_img = 'number_'+error_count;
		document.getElementById('phone_num').src='../images/'+error_img+'.gif';
		document.getElementById('phone_num').style.visibility='visible';
		document.getElementById('phone_arrow').style.visibility='visible';
		image_set=0;
	   }
		/*----------------------------//State//---------------------------------------*/	
		
	  if (state!=0 )
	  {
		  if(!ck_name.test(state) && state!=0)
		  {
			  if(error_lines<error_limit)
			  {
				error_count=error_count+1;	
				error_messages[no_error]=error_count+". "+state_err;
				++no_error;
				++error_lines;
				image_set=1;
			  }
		  }
	  }
	  
	  if (image_set==1)
	  {
		error_img = 'number_'+error_count;
		document.getElementById('state_num').src='../images/'+error_img+'.gif';
		document.getElementById('state_num').style.visibility='visible';
		document.getElementById('state_arrow').style.visibility='visible';
		image_set=0;
	  }
		 
	/*----------------------------//City//---------------------------------------*/	
	 
	  if (city!=0)
	  {
		  if(!ck_name.test(city) && city!=0)
		  {
			if(error_lines<error_limit)
			{
				error_count=error_count+1;
				error_messages[no_error]=error_count+". "+city_err;
				++no_error;
				error_lines=error_lines+1;
				image_set=1;
			}
		  }
	  }
	  
	  if (image_set==1)
	  {
		error_img = 'number_'+error_count;
		document.getElementById('city_num').src='../images/'+error_img+'.gif';
		document.getElementById('city_num').style.visibility='visible';
		document.getElementById('city_arrow').style.visibility='visible';
		image_set=0;
	  }
	
	  /*----------------------------//Username//---------------------------------------*/	
	
	  user_char = username.charAt(0);
	  if (username== 0)
	  {
		if(error_lines<error_limit)
		{
			 error_count=error_count+1;  
			 error_messages[no_error]=error_count+". "+user_empty;
			 no_error=no_error+1;
			 error_lines=error_lines+1;
			 image_set=1;
			 chk1=1;
		}
	  }
	  
	  if((username!=0) && !image_set)
	  {
		  if(!userchk.test(username))
		  {
			  if(error_lines<error_limit)
			  {
				  error_count=error_count+1;	
				  error_messages[no_error]=error_count+". "+user_err;
				  ++no_error;
				  ++error_lines;
				  image_set=1;
				  chk1=1;
			  }
		  }
		  
		  if(!ck_name.test(user_char)&& !image_set)
		  {
			  if(error_lines<error_limit)
			  {
				  error_count=error_count+1;	
				  error_messages[no_error]=error_count+". "+user_errs;
				  ++no_error;
				  ++error_lines;
				  image_set=1;
				  chk1=1;
			  }
		  }
	  }
  
	  if (username!=0 && userchk.test(username)&& ck_name.test(user_char) && !image_set)
	  {
		if(username.length < 6)
		{
			if(error_lines<error_limit)
			{
				error_count=error_count+1;	
				error_messages[no_error]=error_count+". "+uname_shrt;
				++no_error;
				++error_lines;
				image_set=1;
				chk1=1;
			}
		}
	  } 
		   
	  if (username!=0 && ck_name.test(username)&& !image_set)
	  {
			if(username.length >12)
			{
				if(error_lines<error_limit)
				{
					error_count=error_count+1;	
					error_messages[no_error]=error_count+". "+uname_lng;
					++no_error;
					++error_lines;
					image_set=1;
					chk1=1;
				}
			}
	  } 
	  
  /////////////// Ajax to verify username is unique//////////////////	
	  if(chk1 != 1)
	  {
		  result=check_user();
		  if(result == 1)
		  {
			  if(error_lines<error_limit)
			  {	
				  error_count=error_count+1;
				  error_messages[no_error]=error_count+". "+user_exist;
				  ++no_error;
				  ++error_lines;
				  image_set=1;
			  }
		  }
	  }
			  
	  if (image_set==1)
	  {
		  error_img = 'number_'+error_count;
		  document.getElementById('usrname_num').src='../images/'+error_img+'.gif';
		  document.getElementById('usrname_num').style.visibility='visible';
		  document.getElementById('usrname_arrow').style.visibility='visible';
		  image_set=0;
	  }
				 
	/*-----------------------------------//Password and confirm password//-----------------------------*/
	  var flag=0;
  
	  if (password== 0)
	  { 
		  if(error_lines<error_limit)
		  {
			  ++error_count;
			  error_messages[no_error]=error_count+". "+pass_empty;
			  ++no_error;
			  ++error_lines;
			  flag=1;
   
			  error_img = 'number_'+error_count;
			  document.getElementById('passwd_num').src='../images/'+error_img+'.gif';
			  document.getElementById('passwd_num').style.visibility='visible';
			  document.getElementById('passwd_arrow').style.visibility='visible';
		  }
	  }
	  
	  if ((password.length < 6)&& (flag!=1))
	  {
		  if(error_lines<error_limit)
		  {
			  ++error_count;
			  error_messages[no_error]=error_count+". "+pass_shrt;
			  error_img = 'number_'+error_count;
			  document.getElementById('passwd_num').src='../images/'+error_img+'.gif';
			  document.getElementById('passwd_num').style.visibility='visible';
			  document.getElementById('passwd_arrow').style.visibility='visible';
			  ++no_error;
			  ++error_lines;
			  flag=1;
		  }
	  }
		   
	  if ((password.length >12 )&& (flag!=1))
	  {
		  if(error_lines<error_limit)
		  {
			  ++error_count;
			  error_messages[no_error]=error_count+". "+pass_long;
			  error_img = 'number_'+error_count;
			  document.getElementById('passwd_num').src='../images/'+error_img+'.gif';
			  document.getElementById('passwd_num').style.visibility='visible';
			  document.getElementById('passwd_arrow').style.visibility='visible';
			  ++no_error;
			  ++error_lines;
			  flag=1;
		  }
	  } 
	  
	  if (repassword==0)
	  { 
		  if(error_lines<error_limit)
		  {
			  ++error_count;
			  error_messages[no_error]=error_count+". "+confrm_empty;
			  error_img = 'number_'+error_count;
			  document.getElementById('repasswd_num').src='../images/'+error_img+'.gif';
			  document.getElementById('repasswd_num').style.visibility='visible';
			  document.getElementById('repasswd_arrow').style.visibility='visible';
			  ++no_error;
			  ++error_lines;
			  flag=1;
		  }
	  }
	  
	  if((password==username) && (flag!=1))
	  {
		  if(error_lines<error_limit)
		  {	
			  ++error_count;
			  error_messages[no_error]=error_count+". "+pass_usr;
			  if (image_set!=1)
			  {
				  error_img = 'number_'+error_count;
				  document.getElementById('passwd_num').src='../images/'+error_img+'.gif';
				  document.getElementById('passwd_num').style.visibility='visible';
				  document.getElementById('passwd_arrow').style.visibility='visible';
			   
				  ++no_error;
				  ++error_lines;
				  flag=1;
			  }	
		   }
	  }
				  
	  if((password!= 0 && repassword!=0 ))
	  {
		  if((password.length >= 6) && (password.length <= 12 ))
		  {
			  if(password!=repassword)
			  {
				  if(error_lines<error_limit)
				  {	
					  ++error_count;
					  error_messages[no_error]=error_count+". "+pasconf_err;
					  if (flag!=1)
					  {
						  error_img = 'number_'+error_count;
						  document.getElementById('repasswd_num').src='../images/'+error_img+'.gif';
						  document.getElementById('repasswd_num').style.visibility='visible';
						  document.getElementById('repasswd_arrow').style.visibility='visible';
						  document.getElementById('passwd_num').src='../images/'+error_img+'.gif';
						  document.getElementById('passwd_num').style.visibility='visible';
						  document.getElementById('passwd_arrow').style.visibility='visible';
						  ++no_error;
						  ++error_lines;
						  flag=1;
					  }	
				  }
			  }
		  }
	  }  
  //-----------------------------------//Image verification//----------------------------------------------------/ 			
		  
	  if(image_code==0)
	  { 
		  if(error_lines<error_limit)
		  {
			  ++error_count;
			  error_messages[no_error]=error_count+". "+img_code;
			  ++no_error;
			  ++error_lines;
			  image_set=1;
		  }
	  }
	  
	  if(image_code!=0)
	  { 
		///////////////// Ajax for image verification //////////////////	
		  result=image_valid();
		  if(result != 1)
		  {
			  if(error_lines<error_limit)
			  {
				  ++error_count;
				  error_messages[no_error]=error_count+". "+img_err;
				  ++no_error;
				  ++error_lines;
				  image_set=1;
			  }
		  }
	  }  
		  
	  if (image_set==1)
	  {
			error_img = 'number_'+error_count;
			document.getElementById('imagecd_num').src='../images/'+error_img+'.gif';
			document.getElementById('imagecd_num').style.visibility='visible';
			document.getElementById('imagecd_arrow').style.visibility='visible';
			image_set=0;
	  }
					  
	  var divTag=document.getElementById('div_error_msg')
	  divTag.setAttribute("align","left");
	  divTag.style.margin = "10px";
	  divTag.className ="registerDiv";	
	  divTag.style.visibility='visible';	
	  if(no_error>0)
	  {
		  var tempvar="";
						  
		  for(j=0; j < no_error;j++)
		  {
			  tempvar += error_messages[j]+'<br/>';
		  }
	  
		  divTag.innerHTML=tempvar;
		  document.getElementById('register').style.height= (385+(no_error*pixel_per_line)) + 'px';
		  return false;
	  }
}

//--------------------End of client register vaildation----------------------------//    

