
/////---------------------Professionals regiteration--------------------///

function prof_register()
{
 	    firstname  = document.getElementById('firstname').value		//professional register values
	    lastname   = document.getElementById('lastname').value 
		pr_type    = document.getElementById('prof_type').value 
		experience = document.getElementById('experience').value
 		enrollment = document.getElementById('enrollment').value
 		email_id   = document.getElementById('email_id').value
		address1   = document.getElementById('address1').value
 		phone1     = document.getElementById('c_phone1').value
		phone2     = document.getElementById('c_phone2').value
		comments   = document.getElementById('comments').value
 		state      = document.getElementById('state').value
 		region     = document.getElementById('region').value
		town       = document.getElementById('town').value
 		username   = document.getElementById('username').value
		password   = document.getElementById('password').value
		repassword = document.getElementById('repassword').value
		image_code = document.getElementById('secCode').value
		pincode    = document.getElementById('pincode').value
		
   		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 enroll_formate =/^[a-zA-Z0-9]+$/
		var fl_name = /^[-\sa-zA-Z]+$/
 		var chk='';
		var chk1='';
		
		// hide arrow images initailly
		hide_prof_div();
   		firs_char = firstname.charAt(0);
		
		/*----------------------------//enrollment//---------------------------------------*/		
 	if(pr_type=='A')
	 {
	   if(enrollment==0 )
		{
			if(error_lines<error_limit)
			{
				 error_count=error_count+1; 
				 error_messages[no_error]=error_count+". "+empty_enroll;
				 ++no_error;
				 ++error_lines;
				 image_set=1;
 			}
		}
		
 		if(!enroll_formate.test(enrollment) && enrollment!=0)
		{
			if(error_lines<error_limit)
			{
				++error_count;
				error_messages[no_error]=error_count+".  "+enroll_err;
				++no_error;
				++error_lines;
				image_set=1;
 			}
		}
		
		if (image_set==1)
		{
			error_img = 'number_'+error_count;
			document.getElementById('enroll_num').src='../images/'+error_img+'.gif';
			document.getElementById('enroll_num').style.visibility='visible';
			document.getElementById('enroll_arrow').style.visibility='visible';
			image_set=0;
		}
	}
//--------------------------// first name  //-----------///	
		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;
		}
		
/*----------------------------//Experience//---------------------------------------*/		
		if (experience== 0 )
		{
			if(error_lines<error_limit)
			{
				 error_count=error_count+1; 
				 error_messages[no_error]=error_count+". "+empty_exp;
				 ++no_error;
				 ++error_lines;
				 image_set=1;
 			}
		}
 		if(!digitcheck.test(experience) && experience!=0)
		{
			if(error_lines<error_limit)
			{
				++error_count;
				error_messages[no_error]=error_count+".  "+exp_err;
				++no_error;
				++error_lines;
				image_set=1;
 			}
		}
		if(digitcheck.test(experience) && experience!=0 && experience >=50) // maximum experience of 5o years.
		{
			if(error_lines<error_limit)
			{
				++error_count;
				error_messages[no_error]=error_count+".  "+max_exp;
				++no_error;
				++error_lines;
				image_set=1;
 			}
		}
		
		if (image_set==1)
		{
			error_img = 'number_'+error_count;
			document.getElementById('exp_num').src='../images/'+error_img+'.gif';
			document.getElementById('exp_num').style.visibility='visible';
			document.getElementById('exp_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_prof_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 = phone1.charAt(0);
  		if (phone1 == 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(phone1!=0 && !image_set)
		{
			if(!(digitcheck.test(phone1)) && (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(phone1)||(first_char=='+'))&& !image_set)
			{
				if(phone1.length < 7 || phone1.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('phone1_num').src='../images/'+error_img+'.gif';
			  document.getElementById('phone1_num').style.visibility='visible';
			  document.getElementById('phone1_arrow').style.visibility='visible';
			  image_set=0;
		 }

 /*----------------------------//Phone number//---------------------------------------*/	

 		if(phone2!=0 && !image_set)
		{
			first_char = phone2.charAt(0);
			if(!(digitcheck.test(phone2)) && (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(phone2)||(first_char=='+'))&& !image_set)
			{
				if(phone2.length < 7 || phone2.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('phone2_num').src='../images/'+error_img+'.gif';
			  document.getElementById('phone2_num').style.visibility='visible';
			  document.getElementById('phone2_arrow').style.visibility='visible';
			  image_set=0;
		 }
 /*-------------------------// Address//------------------------------------*/
		if (address1== 0)
		{
			if(error_lines<error_limit)
			{	
				 error_count=error_count+1; 
				 error_messages[no_error]=error_count+". "+empty_add;
				 no_error=no_error+1;
				 error_lines=error_lines+1;
				 image_set=1;
			}
		}
		
		if (image_set==1)
		{
			  error_img = 'number_'+error_count;
			  document.getElementById('addr_num').src='../images/'+error_img+'.gif';
			  document.getElementById('addr_num').style.visibility='visible';
			  document.getElementById('addr_arr').style.visibility='visible';
			  image_set=0;
		 }
		
//*----------------------------//State//---------------------------------------*//	

		if (state=="" )
		{
 			if(error_lines<error_limit)
			{
				  error_count=error_count+1;	
				  error_messages[no_error]=error_count+". "+state_empty;
				  ++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;
		}
		
 /*----------------------------//Region//---------------------------------------*/
		if (region=="")
		{
			
  			if(error_lines<error_limit)
			{
				  error_count=error_count+1;	
				  error_messages[no_error]=error_count+". "+empty_region;
				  ++no_error;
				  ++error_lines;
				  image_set=1;
			}
 		}
		
		if (image_set==1)
		{
			  error_img = 'number_'+error_count;
			  document.getElementById('reg_num').src='../images/'+error_img+'.gif';
			  document.getElementById('reg_num').style.visibility='visible';
			  document.getElementById('reg_arrow').style.visibility='visible';
			  image_set=0;
		}
		/*----------------// Pincode //----------------------------*/	
			
	if (pincode==0)
	{
		if(error_lines<error_limit)
		{
 			error_count=error_count+1;
			error_messages[no_error]=error_count+". "+empty_pincode;
			++no_error;
			error_lines=error_lines+1;
			image_set=1;
		}
 	}
	
	if((!digitcheck.test(pincode))&&(pincode!=0))
	{
		if(error_lines<error_limit)
		{
 			error_count=error_count+1;
			error_messages[no_error]=error_count+". "+pincode_valid;
			++no_error;
			error_lines=error_lines+1;
			image_set=1;
		}
 	}
	if (pincode.length < 6 && pincode!=0 && digitcheck.test(pincode))
	{
		if(error_lines<error_limit)
		{
 			error_count=error_count+1;
			error_messages[no_error]=error_count+". "+pincode_len;
			++no_error;
			error_lines=error_lines+1;
			image_set=1;
		}
 	}
	if (image_set==1)
		{
			  error_img = 'number_'+error_count;
			  document.getElementById('pin_num').src='../images/'+error_img+'.gif';
			  document.getElementById('pin_num').style.visibility='visible';
			  document.getElementById('pin_arrow').style.visibility='visible';
			  image_set=0;
		}
	/*----------------------------//Town//---------------------------------------*/	
 		if (town == "")
		{
  			if(error_lines<error_limit)
			{
				error_count=error_count+1;
				error_messages[no_error]=error_count+". "+empty_town;
				++no_error;
				error_lines=error_lines+1;
				image_set=1;
			}
 		}
		
		if (image_set==1)
		{
			  error_img = 'number_'+error_count;
			  document.getElementById('town_num').src='../images/'+error_img+'.gif';
			  document.getElementById('town_num').style.visibility='visible';
			  document.getElementById('town_arrow').style.visibility='visible';
			  image_set=0;
		}
		

/*-----------------//Comments  ///---------------------------------*/		
comm_text="Enter few words about yourself.";
 if (comments == comm_text )
	{
 		if(error_lines<error_limit)
		{
 			error_count=error_count+1;
			error_messages[no_error]=error_count+". "+empty_comments;
			++no_error;
			++error_lines;
			image_set=1;
 		}
	}
 if (comments!=0 && (comments.length > 500))
	{
 		if(error_lines<error_limit)
		{
 			error_count=error_count+1;
			error_messages[no_error]=error_count+". "+comments_lim;
			++no_error;
			++error_lines;
			image_set=1;
 		}
	}
 	if (image_set==1)
	{
		error_img = 'number_'+error_count;
		document.getElementById('comments_num').src='../images/'+error_img+'.gif';
		document.getElementById('comments_num').style.visibility='visible';
		document.getElementById('comments_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_prof_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;
				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';
			}
		}
		
		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;
				image_set=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;
				image_set=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;
				image_set=1;
			}
			if(password!= 0&&((password.length >= 6)&&(password.length <=12 )))
			{
				document.getElementById('passwd_num').style.visibility='hidden';
				document.getElementById('passwd_arrow').style.visibility='hidden';
			}
		}
		
		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;
					image_set=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 (image_set!=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';
							image_set=1;
							++no_error;
							++error_lines;
							flag=1;
 						}	
					}
				}
			}
		}  		
 		if (image_set!=1)
		{
 			document.getElementById('passwd_num').style.visibility='hidden';
			document.getElementById('passwd_arrow').style.visibility='hidden'; 
			document.getElementById('repasswd_num').style.visibility='hidden';
			document.getElementById('repasswd_arrow').style.visibility='hidden';
 		}	
 		if(error_count != 0)
		{
			image_set=0;
		}
	//-----------------------------------//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;
		}
 
 		if(error_count != 0)
		{
			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= (580+(no_error*pixel_per_line)) + 'px';
			return false;
					
		}else 
		{
			divTag.style.visibility='hidden';
			document.getElementById('div_error_msg').style.visibility='hidden';
		}
}

 //--------------------End of Professional register vaildation----------------------------//

//

function hide_msg()
{
	comm_text  = "Enter few words about yourself.";
	comments   = document.getElementById('comments').value
	if (comments == comm_text )
		{
			document.getElementById('comments').value="";
			
		}
}

function show_msg()
{
	
	comments   = document.getElementById('comments').value
	if (comments == "" )
		{
			document.getElementById('comments').value="Enter few words about yourself.";;
			
		}
}

