// form validation function //
// feedback validation function //

//	^\d+\.\d+$/.test(S)   As currency , n decimals 
	
	
	//Regular expression for decimal numbers
/*	/^\d+$/                	 	All-digit
  /^[1-9]\d*$/            		All-digit, non-zero
  /^\s*[-+]\d+\s*$/       		Unbroken signed integer + spaces
  /^\d{1,5}$/             		1 to 5 digits
  /^\d+\.\d\d$/				As currency, 2 decimals
  /^\d+(\.\d{2})?$/        		As currency, 2 decimals optional
  /^[+-]?\d+(\.\d+)?(e[-+]?\d+)?$/i	Allows +3 -3.7 -3.4e+56 etc.
  not /\..*\./				Fewer than two dots
  /^\d{1,3}(,\d\d\d)*\.\d\d$/           Thou-Sep Number dot 2 decimals
  /^[A-Za-z0-9 ]{3,20}$/     text validation with space and digit
  /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/     US Phoen number validation (eg is (308)-135-7895 or 308-135-7895 or 308135-7895 or 3081357895.)
  /^[A-Za-z]\w{6,}$/;
  
    re= /^\d{1,2}\/\d{1,2}\/\d{4}$/;  date regular expression  
	
	var phone2 = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/; 
	
Phone2 format
phone:
339-4248
339-42-48
339 42 48
339 4248
3394248
(095) #phone#
(095)#phone#
+7 (095) #phone#
+7 (095)#phone#
+7(095) #phone#
+7(095)#phone#

function test1(str) {
    str = alltrim(str);
    return /^[-+]?[0-9]+(\.[0-9]+)?$/.test(str);
}
function test2(str) {
    str = alltrim(str);
    return /^[-+]?\d+(\.\d+)?$/.test(str);
}
function test3(str) {
    str = alltrim(str);
    return /^[-+]?\d{3,5}(\.\d{1,3})?$/.test(str);
}

/^\d+(\.\d+)?$|^\.\d+$/ // deciamla

var ck_password =  /^[A-Za-z0-9!@#$%^&*()_]{6,20}$/;


  */

function valid_postres(respstform)
{
	
	var cnd_fnam = respstform.cnd_fnam.value;
	var cnd_lnam = respstform.cnd_lnam.value;
	var cnd_mail = respstform.cnd_mail.value;
	var cnt_contact = respstform.cnt_contact.value;
	var cnt_contact_len =document.getElementById("cnt_contact");
	var cnd_addr = respstform.cnd_addr.value;
	var cnd_city = respstform.cnd_city.value;
	var cnd_pin = respstform.cnd_pin.value;
	var cnd_country = respstform.cnd_country.value;
	var cnd_nation = respstform.cnd_nation.value;
	var cnd_texp_yrs = respstform.cnd_texp_yrs.value;
	var cnd_texp_mnths = respstform.cnd_texp_mnths.value;
	var cnd_sexp_yrs = respstform.cnd_sexp_yrs.value;
	var cnd_sexp_mnths = respstform.cnd_sexp_mnths.value;
	var cnd_rexp_yrs = respstform.cnd_rexp_yrs.value;
	var cnd_rexp_mnths = respstform.cnd_rexp_mnths.value;
	var cnd_cursal = respstform.cnd_cursal.value;
	var cnd_expsal = respstform.cnd_expsal.value;
	var cnd_industry = respstform.cnd_industry.value;
	var cnd_edu = respstform.cnd_edu.value;
	
	var cnd_skill = respstform.cnd_skill.value;
	
	var cnd_note = respstform.cnd_note.value;
	var security_code = respstform.security_code.value;
	
	var alphaRegex = /^[a-zA-Z0-9]+(([\-\_ ][a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$/;
	var ck_spcl =/[~@#$%^&<>%{}\*]/;
	var alphanum=/^[A-Za-z0-9]{3,20}$/;
	var onlynum=/^[0-9]{1,2}$/;
	var onlynumeric=/^[0-9]{3,10}$/;
	//var valname=/^[A-Za-z]$/;
	var mailexp = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	var contactexp=/^[0-9]{5,20}$/;
	var alpharbetsrex=/^[a-zA-Z ]+(([\-\_ ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var valzip=/^[A-Za-z0-9]{4,10}$/;
	var valname=/^[A-Za-z]{1,30}$/;
	var alphanumsalary=/^[A-Za-z0-9 ]{1,100}$/;
	
	
	
	

		if(cnd_fnam == "") 
		{
		    inlineMsg('cnd_fnam','First name should not be left blank.');
		    return false;
  		}
		if(!cnd_fnam.match(valname)) 
		{
		    inlineMsg('cnd_fnam','You have entered an invalid first name.');
		    return false;
	  	}
		
		if(cnd_lnam == "") 
		{
		    inlineMsg('cnd_lnam','Last name should not be left blank.');
		    return false;
  		}
		if(!cnd_lnam.match(valname)) 
		{
		    inlineMsg('cnd_lnam','You have entered an invalid last name.');
		    return false;
	  	}
		
		
		if(cnd_mail == "") 
		{
		    inlineMsg('cnd_mail','Email address should not be left blank.');
		    return false;
  		}
		if(!cnd_mail.match(mailexp)) 
		{
		    inlineMsg('cnd_mail','You have entered an invalid email address.');
		    return false;
	  	}
		
		if(cnt_contact== "") 
		{
			 inlineMsg('cnt_contact','Contact number should not be left blank.');
		    return false;
		}
			if(!cnt_contact.match(contactexp)) 
			{
		    	inlineMsg('cnt_contact','You have entered an invalid contact number.');
		   	 	return false;
	  		}
  		
		
		if(cnd_addr== "") 
		{
			 inlineMsg('cnd_addr','Address should not be left blank.');
		    return false;
			}
			
			if(cnd_addr.match(ck_spcl)) 
			{
		  	  inlineMsg('cnd_addr','You have entered an invalid address.');
		   	 return false;
	  		}
		
		
		if(cnd_city== "") 
		{
			inlineMsg('cnd_city','City should not be left blank.');
		    return false;
		}
			if(!cnd_city.match(alpharbetsrex)) 
			{
		  	  inlineMsg('cnd_city','You have entered an invalid city.');
		   	 return false;
	  		}
		
		
		if(cnd_pin!= "") 
		{
			if(!cnd_pin.match(valzip)) 
			{
		  	  inlineMsg('cnd_pin','You have entered an invalid zip.');
		   	 return false;
	  		}
		}
		
		
		if(cnd_country == -1) 
		{
		    inlineMsg('cnd_country','You must select country.');
		    return false;
  		}
		
			if(cnd_nation== "") 
			{
				inlineMsg('cnd_nation','Nationality should not be left blank.');
		  	  return false;
			}
			if(!cnd_nation.match(alpharbetsrex)) 
			{
		  	  inlineMsg('cnd_nation','You have entered an invalid nationality.');
		   	 return false;
	  		}
		
		
		
		
		if(cnd_texp_yrs!= "") 
		{
		   if(cnd_texp_yrs <= 0) 
			{
				inlineMsg('cnd_texp_yrs','Years should not zero or less that zero.');
				return false;
			}
			if(!cnd_texp_yrs.match(onlynum)) 
			{
				inlineMsg('cnd_texp_yrs','You have entered an invalid years.');
				return false;
			}
		}
		
		if(cnd_texp_mnths!= "") 
		{
			if(!cnd_texp_mnths.match(onlynum)) 
			{
				inlineMsg('cnd_texp_mnths','You have entered an invalid months.');
				return false;
			}	
			if(cnd_texp_mnths < 0) 
			{
		   	 inlineMsg('cnd_texp_mnths','Months should not zero or less that zero.');
		   	 return false;
  			}
		}
		
		
		
		if(cnd_sexp_yrs!= "") 
		{
		   if(cnd_sexp_yrs <= 0) 
			{
				inlineMsg('cnd_sexp_yrs','Years should not zero or less that zero.');
				return false;
			}
			if(!cnd_sexp_yrs.match(onlynum)) 
			{
				inlineMsg('cnd_sexp_yrs','You have entered an invalid years.');
				return false;
			}
		}
		
		if(cnd_sexp_mnths!= "") 
		{
			if(!cnd_sexp_mnths.match(onlynum)) 
			{
				inlineMsg('cnd_sexp_mnths','You have entered an invalid months.');
				return false;
			}	
			if(cnd_sexp_mnths < 0) 
			{
		   	 inlineMsg('cnd_sexp_mnths','Months should not zero or less that zero.');
		   	 return false;
  			}
		}
		
		
		if(cnd_rexp_yrs!= "") 
		{
		   if(cnd_rexp_yrs <= 0) 
			{
				inlineMsg('cnd_rexp_yrs','Years should not zero or less that zero.');
				return false;
			}
			if(!cnd_rexp_yrs.match(onlynum)) 
			{
				inlineMsg('cnd_rexp_yrs','You have entered an invalid years.');
				return false;
			}
		}
		
		if(cnd_rexp_mnths!= "") 
		{
			if(!cnd_rexp_mnths.match(onlynum)) 
			{
				inlineMsg('cnd_rexp_mnths','You have entered an invalid months.');
				return false;
			}	
			if(cnd_rexp_mnths < 0) 
			{
		   	 inlineMsg('cnd_exp_mnths','Months should not zero or less that zero.');
		   	 return false;
  			}
		}
		
		if(cnd_cursal!= "") 
		{
			if(!cnd_cursal.match(alphanumsalary)) 
			{
				inlineMsg('cnd_cursal','You have entered an invalid current salary.');
				return false;
			}
			
			if(cnd_cursal <= 0) 
			{
				 inlineMsg('cnd_cursal','Current Salary should not zero or less that zero.');
				 return false;
			}
		}
		
		if(cnd_expsal!= "") 
		{
			if(!cnd_expsal.match(alphanumsalary)) 
			{
				inlineMsg('cnd_expsal','You have entered an invalid current salary.');
				return false;
			}
			
			if(cnd_expsal <= 0) 
			{
				 inlineMsg('cnd_expsal','Current Salary should not zero or less that zero.');
				 return false;
			}
		}
		
		if(cnd_industry == -1) 
		{
		    inlineMsg('cnd_industry','You must select industry.');
		    return false;
  		}
		
		if(cnd_skill== "") 
		{
			inlineMsg('cnd_skill','Key skills should not be left blank.');
		    return false;
		}
			if(cnd_skill.match(ck_spcl)) 
			{
		  	  inlineMsg('cnd_skill','You have entered an invalid key skills.');
		   	 return false;
	  		}
			
			
				if(cnd_edu == -1) 
		{
		    inlineMsg('cnd_edu','You must select higher education.');
		    return false;
  		}
		
		if(cnd_note!= "") 
		{
			if(cnd_note.match(ck_spcl)) 
			{
		  	  inlineMsg('cnd_note','You have entered an invalid note.');
		   	 return false;
	  		}
		}
			
			
			if(security_code == "") 
			{
				inlineMsg('security_code','Security code should not be left blank.');
			    return false;
			}
	return true;
}

function validate_login(emplgnfrm)
{
	var sof_emp_unam = emplgnfrm.sof_emp_unam.value;
	var sof_emp_pass = emplgnfrm.sof_emp_pass.value;
	
	if(sof_emp_unam == "") 
		{
		    inlineMsg('sof_emp_unam','Username should not be left blank.');
		    return false;
  		}
		if(sof_emp_pass == "") 
		{
		    inlineMsg('sof_emp_pass','Password should not be left blank.');
		    return false;
  		}
		return true;
	
}
/**Followoing code is for validate change password **/
function valid_changepass(chngpassfrm)
{
	var cur_pass = chngpassfrm.cur_pass.value;
	var new_pass = chngpassfrm.new_pass.value;
	var cnf_pass = chngpassfrm.cnf_pass.value;
	
	var ck_unam_pass =  /^[a-zA-Z0-9]+(([a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$/;
	
		if(cur_pass == "") 
		{
		    inlineMsg('cur_pass','Current password should not be left blank.');
		    return false;
  		}
		if(!cur_pass.match(ck_unam_pass)) 
		{
		    inlineMsg('cur_pass','You have entered an invalid current password.');
		    return false;
	  	}
		
		
		if(new_pass == "") 
		{
		    inlineMsg('new_pass','New password should not be left blank.');
		    return false;
  		}
		if(!new_pass.match(ck_unam_pass)) 
		{
		    inlineMsg('new_pass','You have entered an invalid new password.');
		    return false;
	  	}
		
		
		if(cnf_pass == "") 
		{
		    inlineMsg('cnf_pass','Confirm password should not be left blank.');
		    return false;
  		}
		if(!cnf_pass.match(ck_unam_pass)) 
		{
		    inlineMsg('cnf_pass','You have entered an invalid confirm password.');
		    return false;
	  	}
		
		if(cnf_pass != new_pass) 
		{
		    inlineMsg('cnf_pass','New password does not match with confirm password.');
		    return false;
  		}
	return true;
}
/**End of the code for change password**/
/**Following code is for the employer registration form**/
function valid_empuser(add_usrfrm)
{
	
	var usr_unam = add_usrfrm.usr_unam.value;
	var usr_pass = add_usrfrm.usr_pass.value;
	var usr_cpass = add_usrfrm.usr_cpass.value;
	
	
	var usr_companynam = add_usrfrm.usr_companynam.value;
	
	
	var usr_fnam = add_usrfrm.usr_fnam.value;
	var usr_lnam = add_usrfrm.usr_lnam.value;
	var usr_email = add_usrfrm.usr_email.value;
	var usr_contactno = add_usrfrm.usr_contactno.value;
	var usr_address = add_usrfrm.usr_address.value;
	var usr_city = add_usrfrm.usr_city.value;
	var usr_pin = add_usrfrm.usr_pin.value;
	var usr_state = add_usrfrm.usr_state.value;
	
	
	var alphaRegex = /^[a-zA-Z0-9]+(([\-\_ ][a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$/;
	var ck_spcl =/[~!@#$%^&<>%{}\*]/;
	var alphanum=/^[A-Za-z0-9]{3,20}$/;
	var onlynum=/^[0-9]{1,2}$/;
	var onlynumeric=/^[0-9]{3,10}$/;
	var ck_unam_pass =  /^[a-zA-Z0-9]+(([a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$/;
	var valname=/^[A-Za-z\.]{1,50}$/;
	var mailexp = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	var onlyphone=/^[0-9]{5,15}$/;
	
	var alphaspc = /^[a-zA-Z]+(([a-zA-Z ])?[a-zA-Z]*)*$/;
	var alphanumpin=/^[A-Za-z0-9]{4,20}$/;
	
	

		if(usr_unam == "") 
		{
		    inlineMsg('usr_unam','Username should not be left blank.');
		    return false;
  		}
		if(!usr_unam.match(ck_unam_pass)) 
		{
		    inlineMsg('usr_unam','You have entered an invalid username.');
		    return false;
	  	}
		
			if(usr_pass == "") 
		{
		    inlineMsg('usr_pass','Password should not be left blank.');
		    return false;
  		}
		if(!usr_pass.match(ck_unam_pass)) 
		{
		    inlineMsg('usr_pass','You have entered an invalid password.');
		    return false;
	  	}
		
		
		if(usr_cpass == "") 
		{
		    inlineMsg('usr_cpass','Confirm password should not be left blank.');
		    return false;
  		}
		if(!usr_cpass.match(ck_unam_pass)) 
		{
		    inlineMsg('usr_cpass','You have entered an invalid confirm password.');
		    return false;
	  	}
		
		if(usr_cpass!=usr_pass) 
		{
		    inlineMsg('usr_cpass','Password and Confirm password does not match.');
		    return false;
  		}
		
		
		
			if(usr_companynam == "") 
			{
				inlineMsg('usr_companynam','Company name should not be left blank.');
				return false;
			}
			if(!usr_companynam.match(alphaRegex)) 
			{
				inlineMsg('usr_companynam','You have entered an invalid company name.');
				return false;
			}
		
		if(usr_fnam == "") 
		{
		    inlineMsg('usr_fnam','First name should not be left blank.');
		    return false;
  		}
		if(!usr_fnam.match(valname)) 
		{
		    inlineMsg('usr_fnam','You have entered an invalid first name.');
		    return false;
	  	}
		
		
		if(usr_lnam == "") 
		{
		    inlineMsg('usr_lnam','Last name should not be left blank.');
		    return false;
  		}
		if(!usr_lnam.match(valname)) 
		{
		    inlineMsg('usr_lnam','You have entered an invalid last name.');
		    return false;
	  	}
		
		
		if(usr_email == "") 
		{
		    inlineMsg('usr_email','Email address should not be left blank.');
		    return false;
  		}
		if(!usr_email.match(mailexp)) 
		{
		    inlineMsg('usr_email','You have entered an invalid email address.');
		    return false;
	  	}
		
		if(usr_contactno == "") 
		{
		    inlineMsg('usr_contactno','Contact number should not be left blank.');
		    return false;
  		}
		if(!usr_contactno.match(onlyphone)) 
		{
		    inlineMsg('usr_contactno','You have entered an invalid email contact number.');
		    return false;
	  	}
		
		if(usr_address != "") 
		{
			if(usr_address.match(ck_spcl)) 
			{
				inlineMsg('usr_address','You have entered an invalid email address.');
				return false;
			}
		}
		
		if(usr_city != "") 
		{
			if(!usr_city.match(alphaspc)) 
			{
				inlineMsg('usr_city','You have entered an invalid email city.');
				return false;
			}
		}
		
		
		if(usr_pin != "") 
		{
			if(!usr_pin.match(alphanumpin)) 
			{
				inlineMsg('usr_pin','You have entered an invalid email pin/zip.');
				return false;
			}
		}
		
		if(usr_state != "") 
		{
			if(!usr_state.match(alphaspc)) 
			{
				inlineMsg('usr_state','You have entered an invalid email state.');
				return false;
			}
		}
		
	return true;
}
/**End of the code for employer registration**/
// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  /*var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;*/
  var topposition = topPosition(targetdiv) +10;
  var leftposition = leftPosition(targetdiv) ;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}


// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "./images/msg_arrow.gif"; 
}


/*Date Format (m/d/y)	^([\d]|1[0,1,2])/([0-9]|[0,1,2][0-9]|3[0,1])/\d{4}$	12/21/2005	TEST

Decimal Number	^\d*[0-9](\.\d*[0-9])?$	234.342	TEST

Document Filenames	^[a-zA-Z0-9-_\.]+\.(pdf|txt|doc|csv)$	world-domination.pdf	TEST

E-mail Address	^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$	info@netshiftmedia.com	TEST

HTML Color Codes	^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$	#00ccff	TEST

Image Filenames	^[a-zA-Z0-9-_\.]+\.(jpg|gif|png)$	new-pic_company.jpg	TEST

IP Address	^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$	192.168.0.1	TEST

Multimedia Filenames	^[a-zA-Z0-9-_\.]+\.(swf|mov|wma|mpg|mp3|wav)$	company-presentation.swf	TEST

MySQL Date Format	^\d{4}-(0[0-9]|1[0,1,2])-([0,1,2][0-9]|3[0,1])$	2005-09-02	TEST

Phone Number	^[2-9]\d{2}-\d{3}-\d{4}$	250-555-4542	TEST

Postal Code (CAD)	^([A-Z][0-9]){3}$	V2B2S3	TEST

Time Format (HH:MM)	^([0-1][0-9]|[2][0-3])(:([0-5][0-9])){1,2}$	12:29	TEST

URL	^(http[s]?://|ftp://)?(www\.)?[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)$	http://www.netshiftmedia.com	TEST

Versatile Phone Number	^(([0-9]{1})*[- .(]*([0-9a-zA-Z]{3})*[- .)]*[0-9a-zA-Z]{3}[- .]*[0-9a-zA-Z]{4})+$	1.245.532.3422	TEST*/// JavaScript Document
