// JavaScript Document
function valid()
{
   var f = document.appl_form;
  if(!empty_firstname(f.first_name,"First Name")||!empty_lastname(f.last_name,"Last Name")||!email(f.email,"Email Id")||!empty_email(f.email,"Email ID:")||!empty_gender(f.gender,"Gender")||!empty_phone(f.phone_no,"Phone Number")||!empty_country(f.country,"country")||!empty_username(f.username,"Username")||!empty_password(f.hashed_password,"Password")||!empty_confirmpassword(f.salt,"Password")||!empty_match(f.hashed_password,f.salt)||!empty_type(f.user_type)||!empty_occupation(f.occupation,"Occupation")||!empty_skills(f.skills,"Skills")||!empty_qualification(f.qualification,"Qualification")||!empty_design_exp(f.design_exp,"Experience")||!empty_description()||!empty_check(f.check))
   {

   return false;              
  }
  return true; 
}


function empty_firstname(name,id)
{ 

  field=name.value;
  if(field == "")
  { 
     alert("Please enter " + id);
     name.focus();
     return false;  
  }
  var digits=new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',                       'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' ');
  for(var i=0; i<field.length; i++)
    {	
	var cc=field.charAt(i);
  	if(!(cc==digits[0]|| cc==digits[1]|| cc==digits[2]|| cc==digits[3]||cc==digits[4]|| cc==digits[5]|| cc==digits[6]||cc==digits[7]
  	    || cc==digits[8]|| cc==digits[9]|| cc==digits[10]|| cc==digits[11]|| cc==digits[12]|| cc==digits[13]|| cc==digits[14]||
		cc==digits[15]|| cc==digits[16]|| cc==digits[17]|| cc==digits[18]|| cc==digits[19]|| cc==digits[20]|| cc==digits[21]|| cc==
		digits[22]|| cc==digits[23]|| cc==digits[24]|| cc==digits[25]|| cc==digits[26]|| cc==digits[27]|| cc==digits[28]|| cc==
		digits[29]|| cc==digits[30]|| cc==digits[31]|| cc==digits[32]|| cc==digits[33]|| cc==digits[34]|| cc==digits[35]|| cc==
		digits[36]|| cc==digits[37]|| cc==digits[38]|| cc==digits[39]|| cc==digits[40]|| cc==digits[41]|| cc==digits[42]|| cc==
		digits[43]|| cc==digits[44]|| cc==digits[45]|| cc==digits[46]|| cc==digits[47]|| cc==digits[48]|| cc==digits[49]|| cc==
		digits[50]|| cc==digits[51]|| cc==digits[52]|| cc==digits[53]))
   {
   	alert("Name should contain only Characters");
   	name.focus();
   	return false;
   }
} 
   if(field.indexOf(" ")==0)
  {
   alert("Spaces are not allowed before the First Name");
    name.value=""; 
   name.focus();
   return false;     
  }
   if(field.indexOf(" ")==field.length-1)
  {
   alert("Spaces are not allowed after the First Name");
   name.value=""; 
   name.focus();
   return false;     
  }
  
    var count1=name.value;
 var count2=count1.length;
 if(count2 < 3)
 {
   alert(id + " must be minimum of '3' characters");
   name.focus();
   return false;
 } 


   var temp = field;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   name.value=temp;
  
  return true;
   
   
	}

function empty_lastname(name,id)
{ 
	
  field=name.value;
  if(field == "")
  { 
     alert("Please enter " + id);
     name.focus();
     return false;  
  }
  
  var digits=new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',                       'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' ');
  for(var i=0; i<field.length; i++)
    {	
	var cc=field.charAt(i);
  	if(!(cc==digits[0]|| cc==digits[1]|| cc==digits[2]|| cc==digits[3]||cc==digits[4]|| cc==digits[5]|| cc==digits[6]||cc==digits[7]
  	    || cc==digits[8]|| cc==digits[9]|| cc==digits[10]|| cc==digits[11]|| cc==digits[12]|| cc==digits[13]|| cc==digits[14]||
		cc==digits[15]|| cc==digits[16]|| cc==digits[17]|| cc==digits[18]|| cc==digits[19]|| cc==digits[20]|| cc==digits[21]|| cc==
		digits[22]|| cc==digits[23]|| cc==digits[24]|| cc==digits[25]|| cc==digits[26]|| cc==digits[27]|| cc==digits[28]|| cc==
		digits[29]|| cc==digits[30]|| cc==digits[31]|| cc==digits[32]|| cc==digits[33]|| cc==digits[34]|| cc==digits[35]|| cc==
		digits[36]|| cc==digits[37]|| cc==digits[38]|| cc==digits[39]|| cc==digits[40]|| cc==digits[41]|| cc==digits[42]|| cc==
		digits[43]|| cc==digits[44]|| cc==digits[45]|| cc==digits[46]|| cc==digits[47]|| cc==digits[48]|| cc==digits[49]|| cc==
		digits[50]|| cc==digits[51]|| cc==digits[52]|| cc==digits[53]))
   {
   	alert("Name Should Contain only Characters");
	name.focus();
   	return false;
   } 
	}
	   if(field.indexOf(" ")==0)
  {
   alert("Spaces are not allowed before the Last Name");
   name.value=""; 
   name.focus();
   return false;     
  }
   if(field.indexOf(" ")==field.length-1)
  {
   alert("Spaces are not allowed after the Last Name");
    name.value=""; 
   name.focus();
   return false;     
  }
  
	
  
 var temp = field;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   name.value=temp;
  
  return true;
   
   
	}



function email(name,id)
{
  
  field=name.value;
  if(field == "")
  { 
     alert("Please enter " + id);
     name.focus();
     return false;  
  }
  for(i=0;i<=field.length;i++)
  {
   if((field.indexOf(" ")==i)) 
   {
	alert("Spaces are not allowed in" + id); 
	 name.focus();
	return false;
   }
   if(field.indexOf(" ")==0)
  {
   alert("Please enter valid email without spaces");
   x.value=""
   x.focus();
   return false;     
  }
 }
   return true;
}




function empty_email(name,id)
 {
		x=name.value;
  if(x.charAt(0)=="@")
  {
    alert(  x + " is not a valid "  +id);
    name.focus();
    return false;
  }
    var a,b,i,count=0;
   a=x.indexOf("@");
   b=x.lastIndexOf(".");
  for(i=0;i<x.length;i++)
  {
    if(x.charAt(i)=="@")
	count++;
  }
  if(count!=1)
  {
    alert( x + " is not a valid "  +id);
    name.focus();
   return false;
  }
  if(b-a<2)
  {
    alert( x + " is not a valid " +id);
    name.focus();
   return false;
  }
 var len = (x.length)-1;
  c=len-b;
  if(c>3 || c<2 )
  {   
   alert(x + " is not a valid "  +id);
   name.focus();
   return false;
  }
  
  
  
   return true;
		
}



  




function empty_gender(name,id)
{
  if ((document.appl_form.gender[0].checked == false ) && ( document.appl_form.gender[1].checked == false ) )
    {
        alert ( "Please select "+id );

return false;  
    }
	
return true;  
}


function empty_phone(name,id)
{
var pn;
var i;
var plen;
 
var digits=new Array()
  digits[0]="0"
  digits[1]="1"
  digits[2]="2"
  digits[3]="3"
  digits[4]="4"
  digits[5]="5"
  digits[6]="6"
  digits[7]="7"
  digits[8]="8"
  digits[9]="9"
  digits[10]="-"
  var pn= name.value;
  for(var i=0; i<pn.length; i++)
  {
  var cc=pn.charAt(i);
  if(!(cc==digits[0] || cc==digits[1] || cc==digits[2] || cc==digits[3] || cc==digits[4] || cc==digits[5] || cc==digits[6] || cc==
  digits[7] || cc==digits[8] || cc==digits[9]|| cc==digits[10] ))
  
    {
  alert("Please enter digits(0-9) only while entering your Phone Number");
  name.focus();
  return false;
  }
  }
  if(pn=="")
  {
    alert(" Please enter "+id);
    name.focus();
    return false;
    }
	 if(pn.length < 10)
  {
     alert("Phone Number should be minmum '10' digits ");
       name.focus();
     return false;
   } 
 
   return true;
   }

function empty_country(name,id)
{ 

  field=name.value;
  if(field == "Select your Country")
  { 
     alert("Please select your country");
     name.focus();
     return false;  
  }
 return true;
}

function empty_username(name,id)
{ 
 var  field=name.value;
  if(field == "")
  { 
     alert("Please enter " + id);
     name.focus();
     return false;  
  }
  var digits=new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0','-','_','.');
  for(var i=0; i<field.length; i++)
    {	
	var cc=field.charAt(i);
  	if(!(cc==digits[0]|| cc==digits[1]|| cc==digits[2]|| cc==digits[3]||cc==digits[4]|| cc==digits[5]|| cc==digits[6]||cc==digits[7]
  	    || cc==digits[8]|| cc==digits[9]|| cc==digits[10]|| cc==digits[11]|| cc==digits[12]|| cc==digits[13]|| cc==digits[14]||
		cc==digits[15]|| cc==digits[16]|| cc==digits[17]|| cc==digits[18]|| cc==digits[19]|| cc==digits[20]|| cc==digits[21]|| cc==
		digits[22]|| cc==digits[23]|| cc==digits[24]|| cc==digits[25]|| cc==digits[26]|| cc==digits[27]|| cc==digits[28]|| cc==
		digits[29]|| cc==digits[30]|| cc==digits[31]|| cc==digits[32]|| cc==digits[33]|| cc==digits[34]|| cc==digits[35]|| cc==
		digits[36]|| cc==digits[37]|| cc==digits[38]|| cc==digits[39]|| cc==digits[40]|| cc==digits[41]|| cc==digits[42]|| cc==
		digits[43]|| cc==digits[44]|| cc==digits[45]|| cc==digits[46]|| cc==digits[47]|| cc==digits[48]|| cc==digits[49]|| cc==digits[50]|| cc==digits[51]|| cc==digits[52]|| cc==digits[53]|| cc==digits[54]|| cc==digits[55]|| cc==digits[56]|| cc==digits[57]|| cc==digits[58]|| cc==digits[59]|| cc==digits[60]|| cc==digits[61]|| cc==digits[62]|| cc==digits[63]|| cc==digits[64]|| cc==digits[65]))
   {
   	alert(id + " cannot contain blank spaces & special symbols");
   	name.focus();
   	return false;
   } 
	}
 var count1=name.value;
 var count2=count1.length;
 if(count2 < 4)
 {
   alert(id + " should have atleast 4 characters");
   name.focus();
   return false;
 } 

  return true;
}




function empty_password(name,id)
{

var ps ;
ps=name.value;
  if(ps=="")
{  

   alert("Please enter " +id);
  
 
    name.focus();
    return false;
}

if(name.value.length <6)
{
  alert("Password should have atleast 6 characters");

name.focus();
return false;
}
return true;
}

function empty_confirmpassword(name,id)
{
var rps;
rps= name.value;
  if(rps == "")
 {
    alert("Please reenter password !");
 name.focus();
   return false;
   }

return true;
}

function empty_match(pw1,pw2)
{
	if(pw1.value != pw2.value)
	{
	alert("Mismatch password");

	pw2.value="";
	pw2.focus();
	return false;
	}
	return true;
}

function empty_type(name)
{
	field=name.value;
  if(field == "Select")
  { 
     alert("Please select User Type");
     name.focus();
     return false;  
  }
 return true;
}

function empty_occupation(name,id)
{ 

  field=name.value;
  if(field == "Select Occupation")
  { 
     alert("Please select " + id);
     name.focus();
     return false;  
  }
 return true;
}

function empty_skills(name,id)
{ 
var  field=name.value;
  if(field == "")
  { 
     alert("Please specify your key skills separated by commas ");
     name.focus();
     return false;  
  }
 return true;
}

function empty_qualification(name,id)
{ 

  field=name.value;
  if(field == "Select Qualification")
  { 
     alert("Please select your " + id);
     name.focus();
     return false;  
  }
 return true;
}

function empty_design_exp(name,id)
{ 

  field=name.value;
  if(field == "Select Experience")
  { 
     alert("Please select your Design Experience" );
     name.focus();
     return false;  
  }
 return true;
}

function empty_description()
{ 
var  field=document.appl_form.describe.value;
var field2=field.length;


  if(field == "")
  { 
     alert("Please describe about yourself");
    document.appl_form.describe.focus();
     return false;  
  }

  if(field2 < 150)
  {
	  alert("Please describe about you atleast of 150 characters");
	 document.appl_form.describe.focus();
	  return false;
  }
 return true;
}

function empty_check(name)
{
	
if (name.checked == false )
		{
			alert ("You need to agree Terms and Conditions to Register");
			return false;
		}

return true;
}
