
var user_valid =/^[a-zA-Z0-9_@.]+$/;
var pass_valid =/^[a-zA-Z0-9]+$/;
var name_exp=/^([A-Za-z]+[A-Za-z. ]+)$/;
var design_exp=/^([A-Za-z]+[A-Za-z. ]+)$/;
var pattern = /[^a-zA-Z0-9,.\-;\_\s]/;
function trim_ws(str)
{
        temp=str.replace(/^\s*/, "");
        temp=temp.replace(/\s*$/,"");
        return temp;
}
function rb_checkUser(user)
{
        if (user.search(/^[a-zA-Z0-9_@.]+$/) == -1)
                return false;
        else
                return true;
}

function rb_checkPassword(pass)
{       if (pass.search(/^[a-zA-Z0-9]+$/) == -1)
                return false;
        else
                return true;
}
//Description: Name Validates Function.
function rb_checkName(str)
{       if(!name_exp.test(str))
                return false;
        else
                return true;
}

function rb_checkDesignation(str)
{        if(!design_exp.test(str))
                return false;
        else
                return true;
}
//Description: Validates the email field.
function rb_checkEmail(email)
{       if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
                return false;
        else
                return true;
}
//Description: Validates the Website feild
function isValidURL(url) {
	var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
	if (urlRegxp.test(url) != true) {
		return false;
	} else {
		return true;
	}
}
//Description: Validates the Phone field.
function rb_checkPhone(phone)
{       if (phone.search(/^[0-9]+[0-9,\ -]*[0-9]$/) == -1)
                return false;
        else
                return true;
}

function ValidateClient()
{	  //Description: Validates the Email Id field.	
        var msg='';
	    var email=trim_ws(document.getElementById("email_id").value);
		var error=0;
        if(email == '')
        {	    msg+='Please enter your Master Email.<br>';
				document.getElementById("email_id").style.background="#FFDFEF";
 				error=error+1;
        }
        else if(!rb_checkEmail(email))
        {       msg+="'"+email+"' is not a valid Email ID.Please enter a valid Email ID<br>";
  			    document.getElementById("email_id").style.background="#FFDFEF";
                error=error+1;
        }
		else
		{		document.getElementById("email_id").style.background="#FFFFFF";
		}
        var user=trim_ws(document.getElementById("username").value);
		if(user == '')
        {       msg+='Username is compulsary.<br>';
				document.getElementById("username").style.background="#FFDFEF";
			    error=error+1;
		}
        else if(!rb_checkUser(user))
        {       msg+="'"+user+"' is not a valid UserName.Please enter a valid UserName.<br>";
				document.getElementById("username").style.background="#FFDFEF";
				error=error+1;
        }
		else if( (user.length<8) || (user.length>50) )
        {       msg+='Username should be between 8 - 50 characters long.<br>';
				document.getElementById("username").style.background="#FFDFEF";
			    error=error+1;
        }
	    else
		{		document.getElementById("username").style.background="#FFFFFF";
		}
		//Description: Validates the Password field.	
		var pass=trim_ws(document.getElementById("userpass").value);
		var cpass=trim_ws(document.getElementById("compass").value);
	    if(pass == '')
        {       msg+='Password filled cant be left blank.<br>';
				document.getElementById("userpass").style.background="#FFDFEF";
			    error=error+1;
        }
        else if(!rb_checkPassword(pass))
        {       msg+="'"+pass+"' is not a valid Password.Please enter a valid Password.<br>";
				document.getElementById("userpass").style.background="#FFDFEF";
				error=error+1;
        }
		else if( ( pass.length < 8) || (pass.length > 24) ) 
        {       msg+='Password  should be between 8 - 24 characters long.<br>';
				document.getElementById('userpass').style.background="#FFDFEF";
				error=error+1;
        }
		else
		{		document.getElementById("userpass").style.background="#FFFFFF";
		}
		//Description: Validates the Confirm Password field.	
		if(cpass == '')
        {       msg+='Please enter a Confirm Password.<br>';
				document.getElementById("compass").style.background="#FFDFEF";
			    error=error+1;
        }
        else if(!rb_checkPassword(cpass))
        {       msg+="'"+cpass+"' is not a valid confirm password.Please enter a valid Confirm Password.<br>";
				document.getElementById("compass").style.background="#FFDFEF";
				error=error+1;
        }
	    else if( (cpass.length < 8) || (cpass.length > 24) )
        {       msg+='Confirm password  should be between 8 - 24 characters long.<br>';
				document.getElementById('compass').style.background="#FFDFEF";
				error=error+1;
        }
		else if(pass != cpass)
		{	    msg+='Password and Confirm Password should match.<br>';
				document.getElementById("userpass").style.background="#FFDFEF";
				document.getElementById("compass").style.background="#FFDFEF";
				error=error+1;
		}
		else
		{		document.getElementById("userpass").style.background="#FFFFFF";
				document.getElementById("compass").style.background="#FFFFFF";
		}
		//Description: Validates the City  field.	
		var city_id=trim_ws(document.getElementById("City").value);
		if(city_id == 'none')
        {       msg+='Please select a City.<br>';
				document.getElementById("City").style.background="#FFDFEF";
			    error=error+1;
        }
		else
		{		document.getElementById("City").style.background="#FFFFFF";			
		}
		//Description: Validates the Company Name field.	
		var comp_id=trim_ws(document.getElementById("Company").value);
		if(comp_id == '')
        {       msg+='Please select a Company.<br>';
				document.getElementById("Company").style.background="#FFDFEF";
			    error=error+1;
        }
		else
		{		document.getElementById("Company").style.background="#FFFFFF";			
		}
		//Description: Validates the Other Company  field.	
		if(document.getElementById('Company').value=='0')
		{	 	var other_comp =(document.getElementById('othercompany').value);
				if(other_comp == '')
				{	 msg+='Please specify Company name  .<br>'
					 document.getElementById('othercompany').style.background="#FFDFEF";
					 error=error+1;
				}
				else
				{	document.getElementById('othercompany').style.background="#FFFFFF";
				}
		}
		//Description: Validates the Contact Person field.	
		var ctperson=trim_ws(document.getElementById("contperson").value);
		if(ctperson == '')
        {       msg+='Please enter a Contact person name.<br>';
				document.getElementById("contperson").style.background="#FFDFEF";
			    error=error+1;
        }
		else if(!rb_checkName(ctperson)) 
        {       msg+='Please enter a valid Contact person name.<br>';
			    document.getElementById("contperson").style.background="#FFDFEF";
                error=error+1;
        }
		else
		{		document.getElementById("contperson").style.background="#FFFFFF";			
		}
	    //Description: Validates the Designation field.	
	    var desig=trim_ws(document.getElementById("designation").value);
		if(desig == '')
        {       msg+='Please enter a Designation.<br>';
				document.getElementById("designation").style.background="#FFDFEF";
			    error=error+1;
        }
		else if(pattern.test(desig))
	 	{	msg+='In Designation special characters other than (Dot Comma Hyphen UnderScore And Semicolon) are not allowed<br>';
			document.getElementById("designation").style.background="#FFDFEF";
			error=error+1;
	 	}
		else
		{		document.getElementById("designation").style.background="#FFFFFF";			
		}
		
		//Description: Validates the Clite Type college then check field.	 
	   var c_type = document.getElementById('clitype').value;
	   if(c_type == '')
        {       msg+='Specify a Client Type. (Company/Consultant)<br>';
				document.getElementById("clitype").style.background="#FFDFEF";
			    error=error+1;
        }
		else if(c_type == 't')
		{			var instcity=trim_ws(document.getElementById('InstCity').value);
					if(instcity == 'none')
					{		msg+='Specify a College City.<br>';
							document.getElementById('InstCity').style.background="#FFDFEF";
							error=error+1;
					}
					else
					{		document.getElementById('InstCity').style.background="";			
					}
					//Description: Validates the Institute  field.	
					var inst_id=trim_ws(document.getElementById('Institute').value);
					if(inst_id == '')
					{		msg+='Specify an Institute.<br>';
							document.getElementById('Institute').style.background="#FFDFEF";
							error=error+1;
					}
					else
					{		document.getElementById('Institute').style.background="";			
					}
					//Description: Validates the Other Institute  field.	
					if(inst_id == '0')
					{		var otherinst_id=trim_ws(document.getElementById('otherInstitute').value);
							if(otherinst_id == '')
							{	msg+='Specify an Other Institute.<br>';
								document.getElementById('otherInstitute').style.background="#FFDFEF";
								error=error+1;
							}
							else
							{	document.getElementById('otherInstitute').style.background="";			
							}
					}
		}
		
		else
		{			document.getElementById("clitype").style.background="#FFFFFF";			
		}
		//Description: Validates the Pin Code field.	
		 var pin_code =trim_ws(document.getElementById('pin_code').value);
		 if(pin_code == '')
		 { 	    msg+='Please enter a Pincode No.<br>';
				document.getElementById("pin_code").style.background="#FFDFEF";
				error=error+1;
		 }
		 else if((pin_code.length < 6))
         {	 	msg+='Please enter Pincode 6 digit long.<br>';
				document.getElementById("pin_code").style.background="#FFDFEF";
               	error=error+1;
         }
		 else if(!rb_checkPhone(pin_code))
         {   	msg+='Please enter a valid Pincode No.<br>';
				document.getElementById("pin_code").style.background="#FFDFEF";
               	error=error+1;
         }
		 else
		 {		document.getElementById("pin_code").style.background="";			
		 }
		var contactno=trim_ws(document.getElementById("contact_no").value);
		var mobileno=trim_ws(document.getElementById("mobile_no").value);
	 	var cotcode=trim_ws(document.getElementById("countrycode").value);
		var stcode=trim_ws(document.getElementById("stdcode").value);
		if(contactno == '' && mobileno == '')
        {       msg+='Please enter atleast one contact no.<br>';
				document.getElementById("stdcode").style.background="#FFDFEF";
				document.getElementById("contact_no").style.background="#FFDFEF";
				document.getElementById("mobile_no").style.background="#FFDFEF";
                error=error+1;
        }
		else
		{		document.getElementById("stdcode").style.background="";
				document.getElementById("contact_no").style.background="";			
				document.getElementById("mobile_no").style.background="";			
		}
	 if(contactno != '')
        {
			if(cotcode == '')
			{		msg+='Please enter a Country Code.<br>';
					document.getElementById("countrycode").style.background="#FFDFEF";
					error=error+1;
			}
			else if(cotcode.length < 2)
			{		msg+='Please Country code atleast 2 digit long.<br>';
					document.getElementById("countrycode").style.background="#FFDFEF";
					error=error+1;
			}
			else
			{		document.getElementById("countrycode").style.background="";
			}
		}
		if(contactno != '')
        {			
		   if(!rb_checkPhone(contactno))
			{		msg+='Please enter a Contact No.<br>';
					document.getElementById("contact_no").style.background="#FFDFEF";
					error=error+1;
			}
			else if(contactno.length < 6)
			{		msg+='Please Contact no atleast 6 digit long.<br>';
					document.getElementById("contact_no").style.background="#FFDFEF";
					error=error+1;
			}
			else if(stcode == '')	
        	{	 msg+='Please enter a STD Code.<br>';
  			     document.getElementById("stdcode").style.background="#FFDFEF";
                 error=error+1;
        	}
		   else if(!rb_checkPhone(stcode))
			{		msg+='Please enter a valid STD code.<br>';
					document.getElementById("stdcode").style.background="#FFDFEF";
					error=error+1;
			}
			else if(stcode.length < 3)
			{		msg+='Please STD Code atleast 3 digits  long including 0.<br>';
					document.getElementById("stdcode").style.background="#FFDFEF";
					error=error+1;
			}
			else
			{	  	document.getElementById("contact_no").style.background="";
					document.getElementById("stdcode").style.background="";
			}
		}
	 if(mobileno != '')
        {
			if(!rb_checkPhone(mobileno))
			{		msg+='Please enter a valid Mobile no.<br>';
					document.getElementById("mobile_no").style.background="#FFDFEF";
					error=error+1;
			}
			else if(mobileno.length < 10)
			{		msg+='Please Mobile no atleast 10 digit long.<br>';
					document.getElementById("mobile_no").style.background="#FFDFEF";
					error=error+1;
			}
			else
			{		document.getElementById("mobile_no").style.background="";
			}
		}
		//Description: Validates the Fax No field.	
		var faxno=trim_ws(document.getElementById("fax_no").value);
		if(faxno != '')
        {
			if(!rb_checkPhone(faxno))
			{		msg+='Please enter a valid Fax no.<br>';
					document.getElementById("fax_no").style.background="#FFDFEF";
					error=error+1;
			}
			else if(faxno.length < 10)
			{		msg+='Please Fax no atleast 10 digit long.<br>';
					document.getElementById("fax_no").style.background="#FFDFEF";
					error=error+1;
			}
			else
			{		document.getElementById("fax_no").style.background="";
			}
		}
	//Description: Validates the Address field.	
	   var addr=trim_ws(document.getElementById("address").value);
	   if(addr == '')
        {       msg+='Please enter company address.<br>';
				document.getElementById("address").style.background="#FFDFEF";
			    error=error+1;
        }
		else
		{		document.getElementById("address").style.background="#FFFFFF";			
		}
	    //Description: Validates the Industry Type field.	
		var indus_id=trim_ws(document.getElementById("industry").value);
	    if(indus_id == '')
        {       msg+='Please select an Industry Type.<br>';
				document.getElementById("industry").style.background="#FFDFEF";
                error=error+1;
        }
		else
		{		document.getElementById("industry").style.background="#FFFFFF";			
		}
		 //Description: Validates the Website  field.	
        var wsite=trim_ws(document.getElementById("website").value);
		if(wsite != '')
        {      if(!isValidURL(wsite))
        		{
                msg+="'"+wsite+"' is not a valid Website url.Please enter a valid Website url.<br>";
				document.getElementById("website").style.background="#FFDFEF";
				error=error+1;
        		}
				else
				{
				document.getElementById("website").style.background="#FFFFFF";
				}
		}
	    if(error>0)
		{
			popup.alert(msg);
			return false;
		}
		else
        return true;
}


//Others Company List
function addOthrsCompany(thecomp) 	
{
   if(thecomp  == '0')
	      document.getElementById('ocompany').style.display='';
    else
		  document.getElementById('ocompany').style.display='none';
}
   