var nonums = /^[0-9]*$/;
var overlay = null;
// error message display
function showError(divId,errorText,x,y){
			var error = document.getElementById(divId);
			window.scrollTo(x,y);
			error.innerHTML = errorText;
}
 //poup window
 function popUpWindow(url) {
 	 window.open(url,"","width=350,height=350,left=600,top=100,scrollbars=1");
 }
 function Pop_Up_Window(url) {
 	 window.open(url,"","width=650,height=550,left=500,top=100,scrollbars=1");
 }
 function Pop_Up_BIdType(url) {
 	 window.open(url,"","width=400,height=300,left=600,top=300,scrollbars=1");
 }
 //trim functions
function jtrim(value) {
	return LTrim(RTrim(value));
}
function trim(value) {
	return LTrim(RTrim(value));
}
// Removes leading whitespaces
function LTrim(value) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim(value) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// user validation
function validateUserRegistrationForm(){
	var fName=document.myform.fullName.value;
	var zip=document.myform.zipCode.value;
	var year=document.myform.dobYear.value;
	var month=document.myform.dobMonth.value;
	var date=document.myform.dobDay.value;
	var email=document.myform.emailId.value;
	var ConfirmEmail=document.myform.confirmEmailId.value;
	var UName=document.myform.userName.value;
	var password=document.myform.password.value;
	var confirmpassword=document.myform.confirmPassword.value;
	var Pin=document.myform.code.value;
	var boxCheck = false;
	var d = new Date();
	var YY = parseInt(year);
	var MM = parseInt(month);
  	var DD = parseInt(date);
	var curr_year = d.getFullYear();
	var curr_month= d.getMonth() +1;
	var curr_day  = d.getDate();
	if((curr_month > MM)||(curr_month==MM & curr_day>=DD))	{
	var	age=YY;
	}
	else{
	var age=YY+1;
	}
	var diff=curr_year-age;
	if(trim(fName)==0){
			document.myform.fullName.focus();
			showError("errorRegister","Please enter Full Name",0,0);
			return false;
	}
	if(trim(zip)==0){									
		document.myform.zipCode.focus();
		showError("errorRegister","* Please enter zip code",0,0);
		return false;
	}
	if(date=="" || month=="" || year==""){
		showError("errorRegister","Please select correct date of birth",0,0);			
		return false;
	}
	if(diff<16){
		showError("errorRegister","Site Users Must be over 16 to register ",0,0);			
		return false;
	}
	if(trim(email)==""){
		document.myform.emailId.focus();
		showError("errorRegister","Please enter Email Id",0,0);
		return false;
	}
	if (email.length >0) {
		 i=email.indexOf("@")
		 j=email.indexOf(".",i)
		 k=email.indexOf(",")
		 kk=email.indexOf(" ")
		 jj=email.lastIndexOf(".")+1
		 len=email.length
		 	if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
		 	}else {			 		
		 		error = "Please enter a correct email address. <b>" +	email + "</b> is invalid.";
				document.myform.emailId.focus();
				showError("errorRegister",error,0,0);
				return false;
		 	}
	 }		
	if(trim(ConfirmEmail)==""){
		document.myform.confirmEmailId.focus();
		showError("errorRegister","Please enter Confirm Email Id",0,0);
		return false;
	}
	if (ConfirmEmail.length >0) {
		 i=ConfirmEmail.indexOf("@")
		 j=email.indexOf(".",i)
		 k=ConfirmEmail.indexOf(",")
		 kk=ConfirmEmail.indexOf(" ")
		 jj=ConfirmEmail.lastIndexOf(".")+1
		 len=ConfirmEmail.length
		 	if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
		 	}else {			 		
		 		error = "Please enter a correct ConfirmEmail address.";
				document.myform.confirmEmailId.focus();
				showError("errorRegister",error,0,0);
				return false;
		 	}
	 }		
	if(email!=ConfirmEmail){
		document.myform.confirmEmailId.focus();
		showError("errorRegister","Email Id does not match. Enter correct Email Id",0,0);			
		return false;
	}
	if(trim(UName)==0 && UName.length>5){
			document.myform.userName.focus();
			showError("availabilityChk","Please enter User Name",0,0);
			return false;
	}
	if(trim(password)==""){		
		document.myform.password.focus();
		showError("errorRegister","Please enter password",0,0);
		return false;
	}
	if(trim(confirmpassword)==""){			
		document.myform.confirmPassword.focus();
		showError("errorRegister","Please enter confirm password",0,0);			
		return false;
	}
	if(password!=confirmpassword){
		document.myform.confirmPassword.focus();
		showError("errorRegister","Password does not match. Enter correct password",0,0);			
		return false;
	}
	if(trim(Pin)==0){
			document.myform.code.focus();
			showError("errorRegister","Please enter Registration Pin",0,0);
			return false;
	}
 	if (document.myform.confirm.checked) {
		boxCheck = true; 
	}
	if (!boxCheck) {
		showError("errorRegister","Please Agree to the terms ",0,0);
		return false;
	}
}
function printTerms() {
   var s = document.myform.terms.value;
   var regExp=/\n/gi;
   s = s.replace(regExp,'<br>');
   pWin = window.open('','pWin','location=yes, menubar=yes, toolbar=yes');
   pWin.document.open();
   pWin.document.write('<html><head></head><body>');
   pWin.document.write(s);
   pWin.document.write('</body></html>');
   pWin.print();
   pWin.document.close();
   pWin.close();
}
// login validation
function validateUserLoginForm(){
	var UserId=document.myform.userId.value;
	var Password=document.myform.password.value;
	if(trim(UserId)==""){		
		document.myform.userId.focus();
		showError("errorLogin","Please enter User Name",0,0);
		return false;
	}
	if(trim(Password)==""){		
		document.myform.password.focus();
		showError("errorLogin","Please enter password",0,0);
		return false;
	}
}
function closeLayer(){
          overlay.hide();
 }
function Check(){
	var userId=document.myform.userName.value;
	if(trim(userId)==0){
			document.myform.userName.focus();
			alert('Please enter User Name to Check User Name Availability');
			return false;
	}
	var uri='CheckUserNameAvailability.php';
	var dataString="uName="+userId;
	userFormSubmitter.postFormData(uri,dataString,'checkDiv');
}
function validateBidPrice(){
	var bid=document.myform.bid.value;
	if(trim(bid)==0 || !nonums.test(bid)){
			document.myform.bid.focus();
			showError("errorBid","Please enter Bid Price",0,0);
			return false;
	}
}
function validateAwardAdvert(){
 	var radioCheck = false;
		for (i = 0; i < document.theform.uID.length; i++) {
			if (document.theform.uID[i].checked)
				radioCheck = true; 
		}
			if (!radioCheck) {
				showError("errorAward","Please Choose one to Award The Project",0,0);
				return false;
			}
}
function SendForgotPassMail(){
            var pass="";     
        pass = pass+ "<table width='400' border='0' align='center' cellpadding='0' cellspacing='0' class='borderRed'>";     
        pass = pass+ "<tr><td class='TextNavigation' bgcolor='#549a04'>Forgot Username/Password</td>";
		pass = pass+ "<td color='#CCCCCC' align='right' bgcolor='#549a04'><img src='../images/close.gif' border='0' onclick='closeLayer()'/></td></tr>";
	    pass = pass+ "<tr><td colspan='2' height='130' valign='middle' bgcolor='#F0F0F0'><div id='forgotpassMsg'><form  name='forgotPasswordForm'>";
     	pass = pass+ "<table border='0' align='center' cellpadding='2' cellspacing='4'>";
	    pass = pass+ "<tr><td colspan='2' align='center'></td></tr>";
        pass = pass+ "<tr><td colspan='2' ><div id='forgotpassError' class='errorMessage'>&nbsp;</div></td></tr>";
        pass = pass+ "<tr><td height='20' colspan='2'>Enter valid email id </td></tr>";
       	pass = pass+ "<tr><td>Email id</td><td>";
        pass = pass+ "<input name='emailid' type='text' size='30' maxlength='50' /></td></tr>";
        pass = pass+ "<tr><td height='30' colspan='2' align='center'><label><img src='../images/Send.gif' onClick='validateForgotPassword()' class='cursorHand'/>";
        pass = pass+ "</td></tr></table>";
        pass = pass+ "</form></div></td></tr>";
  		pass = pass+ "</table>";
                 
              var forgotpass = document.getElementById("mailDIV");
              forgotpass.innerHTML = pass;
              overlay = new YAHOO.widget.Overlay("mailDIV", { xy:[300,200],
              visible:true,
              width:"540px",
              effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:.1} } );
              overlay.render();
              overlay.show();
        }

function validateForgotPassword(){
     var email = document.forgotPasswordForm.emailid.value;
        var filter=/^.+@.+\..{2,3}$/
     if(trim(email)=="")
          {
               showError("forgotpassError","Please Enter Email Id");
                document.forgotPasswordForm.emailid.focus();
                return false;
          }
 if (filter.test( email)){
       var uri="userForgotPassword.php";
        var email = document.forgotPasswordForm.emailid.value;
         var dataString="emailId="+email;
         userFormSubmitter.postFormData(uri,dataString,'PasswordDiv');
} else {
        showError("forgotpassError","Please Enter Valid Email Id");
        document.forgotPasswordForm.emailid.focus();
    return false;
}

}
function ResendActivationMail(){
        var pass="";     
        pass = pass+ "<table width='400' border='0' align='center' cellpadding='0' cellspacing='0' class='borderRed'>";     
        pass = pass+ "<tr><td class='TextNavigation' bgcolor='#549a04'>Resend Activation Mail</td>";
		pass = pass+ "<td color='#CCCCCC' align='right' bgcolor='#549a04'><img src='../images/close.gif' border='0' onclick='closeLayer()'/></td></tr>";
	    pass = pass+ "<tr><td colspan='2' height='130' valign='middle' bgcolor='#F0F0F0'><div id='forgotpassMsg'><form  name='forgotPasswordForm'>";
     	pass = pass+ "<table border='0' align='center' cellpadding='2' cellspacing='4'>";
	    pass = pass+ "<tr><td colspan='2' align='center'></td></tr>";
        pass = pass+ "<tr><td colspan='2' ><div id='forgotpassError' class='errorMessage'>&nbsp;</div></td></tr>";
        pass = pass+ "<tr><td height='20' colspan='2'>Enter valid email id</td></tr>";
       	pass = pass+ "<tr><td>Email id</td><td>";
        pass = pass+ "<input name='emailid' type='text' size='30' maxlength='50' /></td></tr>";
        pass = pass+ "<tr><td height='30' colspan='2' align='center'><img src='../images/Send.gif' onClick='validateResendMail()' class='cursorHand'/>";
        pass = pass+ "</td></tr></table>";
        pass = pass+ "</form></div></td></tr>";
  		pass = pass+ "</table>";
          var forgotpass = document.getElementById("mailDIV");
          forgotpass.innerHTML = pass;
          overlay = new YAHOO.widget.Overlay("mailDIV", { xy:[300,200],
          visible:true,
          width:"540px",
          effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:.1} } );
          overlay.render();
          overlay.show();
        }

function validateResendMail(){
     var email = document.forgotPasswordForm.emailid.value;
        var filter=/^.+@.+\..{2,3}$/
     if(trim(email)=="")
          {
               showError("forgotpassError","Please Enter Email Id");
                document.forgotPasswordForm.emailid.focus();
                validation = false;
                return false;
          }
 if (filter.test( email)){
        var uri="resendActivationMail.php";
        var email = document.forgotPasswordForm.emailid.value;
         var dataString="emailId="+email;
        userFormSubmitter.postFormData(uri,dataString,'ResendMailDiv');
} else {
        showError("forgotpassError","Please Enter Valid Email Id");
        document.forgotPasswordForm.emailid.focus();
    return false;
}

     }
function HelpReport(){
	var email=document.myform.emailId.value;
	var Message=document.myform.Message.value;
	if(trim(email)==""){
		document.myform.emailId.focus();
		showError("errorHeader","Please enter Email Id",0,0);
		return false;
	}
	if (email.length >0) {
		 i=email.indexOf("@")
		 j=email.indexOf(".",i)
		 k=email.indexOf(",")
		 kk=email.indexOf(" ")
		 jj=email.lastIndexOf(".")+1
		 len=email.length
		 	if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
		 	}else {			 		
		 		error = "Please enter a correct email address. <b>" +	email + "</b> is invalid.";
				document.myform.emailId.focus();
				showError("errorHeader",error,0,0);
				return false;
		 	}
	 }		
	if(trim(Message)==""){
		document.myform.Message.focus();
		showError("errorHeader","Please enter Help Message",0,0);
		return false;
	}
}
function SendReport(){
	var Message=document.myform.Message.value;
	var UrlId=document.myform.UrlId.value;
	if(trim(UrlId)==""){
		document.myform.UrlId.focus();
		showError("errorHeader","Please enter Page URL",0,0);
		return false;
	}
	if(trim(Message)==""){
		document.myform.Message.focus();
		showError("errorHeader","Please enter Page Bug Report",0,0);
		return false;
	}
}
function SelectedUName(u){
	document.myform.userName.value = u;
}
function SelectionStars(){
	var starName=document.myform.stars.value;
	if(trim(starName)==""){
		document.myform.stars.focus();
		alert('please Select workerANT Stars');
		return false;
	}
	var location = "../features/workerANTStars.php?name=";
	window.location = location + starName;
}
function SelectionInterview(){
	var starName=document.myform.stars.value;
	if(trim(starName)==""){
		document.myform.stars.focus();
		alert('please Select workerANT Interview');
		return false;
	}
	var location = "../features/workerANTBigInterview.php?name=";
	window.location = location + starName;
}
function referalFriend(){
		var emailId = document.frm.to.value;
		var validation = emailFormatValidation(emailId);		
		if(validation == false){
			return false;
		}
}	
function emailFormatValidation(email){
		var subject = document.frm.subject.value;
		var to = email.split(",");
		for(var init=0 ; init<to.length ; init++){
			to[init] = trim(to[init]);
			if(trim(document.frm.to.value)==""){
				document.frm.to.focus();
				showError("errorMsg","Please Enter Email",0,0);			
				return false;
			}
			if(to[init].indexOf('<')!=-1){
				var email = to[init];
				email = email.split('<');
				var email2 = email[1];
				var index = email2.indexOf('>');
				email2 = email2.substr(0,index);
				to[init] = email2;
			}
			if (to[init].length >0) {
				i=to[init].indexOf("@")
				j=to[init].indexOf(".",i)
			 	k=to[init].indexOf(",")
				kk=to[init].indexOf(" ")
				jj=to[init].lastIndexOf(".")+1
				len=to[init].length
			 	if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {

				}else {			 		
		 			error = "Please Enter a correct Email Address.";
					document.frm.to.focus();
					showError("errorMsg",error,0,0);
					return false;
			 	}
			
			 }		
		}
		if(trim(document.frm.subject.value)==""){
			document.frm.subject.focus();
			showError("errorMsg","Please Enter Subject",0,0);			
			return false;
		}
}
function validateRatings()
 {
    var Exp=document.form.experience.value;
    if(trim(Exp)==0)
      {
    	alert("please enter Review");
    	document.form.experience.focus();
    	return false;
      }
    if(document.form.rating.value==0)
      {
    	alert("please enter Ratings");
    	document.form.rating.focus();
    	return false;
      }
 }

