var MAXCONT=75;

function downloadResume(user_id)
{
	document.getElementById("hidActionFrame").src = "download_resume.php?txtUserId="+user_id;
}

function downloadDocument(job_id)
{
	document.getElementById("hidActionFrame").src = "download_document.php?txtJobId="+job_id;
}

function registraion()
{
	document.frmMain.action="registration.php";
	document.frmMain.submit();
}

function openVideoWindow(jid)
{
	var url="job_detail.php?jobId=" + jid;
	window.open(url,'jobwindow','width=600,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes');
}

function showJobSeeker(uid)
{
	var url="jobseeker_detail.php?jobSeekerId=" + uid;
	window.open(url,'jobwindow','width=600,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes');
}

function showClient(cid)
{
	var url="client_detail.php?clientId=" + cid;
	window.open(url,'jobwindow','width=600,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes');
}

function submitGroupForm()
{
	var frm = document.frmMain;
		if(frm.txtGroupName.value=='')
	   {
		   alert('Please Enter Group Name');
		   frm.txtGroupName.focus();
		   return false;
	   }
	
		if( frm["cmbRightUser[]"].length>0)
		{
			for(i=0;i< frm["cmbRightUser[]"].length;i++)
			{
				 frm["cmbRightUser[]"][i].selected=true;
			}
		}
		else
		{
			alert("Please select a user.");
			return false;
		}
	
}

function checkForgotPassword()
{
  if(document.frmMain.txtUserName.value=='')
  {
	   alert('Please Enter Email Id');
	   document.frmMain.txtUserName.focus();
	   return false;
  }	 
}

function checkLogin()
 {
   if(document.frmMain.txtUserName.value=='')
   {
	   alert('Please Enter Admin Id');
	   document.frmMain.txtUserName.focus();
	   return false;
   }
	else if(document.frmMain.txtPassword.value=='')
   {
	   alert('Please Enter Password');
	   document.frmMain.txtPassword.focus();
	   return false;
   }	
   else
   {
   	 return true;
   }	 
			 
 }

function deleteJobSeeker(jid,act)
{
	document.frmMain.action="submit_jobseeker.php";
	var blnFlag = window.confirm("Do you want delete this jobseeker?");
	if(blnFlag)
	{
		document.frmMain.txtJobSeekerId.value=jid;
		document.frmMain.frmAction.value=act;
		document.frmMain.submit();
	}
}

function backToSearch()
{
	document.frmMain.action="jobsearch_result.php";
	document.frmMain.submit();
}

function editJobSeeker(jid,act)
{
	document.frmMain.action="manage_jobseeker.php";
	document.frmMain.txtJobSeekerId.value=jid;
	document.frmMain.frmAction.value=act;
	document.frmMain.submit();
}

function sendEmailCGroup(gid,gname)
{
	document.frmMain.action="send_client_email.php";
	document.frmMain.txtGroupId.value=gid;
	document.frmMain.txtGroupName.value=gname;
	document.frmMain.submit();
}

function editCGroup(gid,act)
{
	document.frmMain.action="manage_client_group.php";
	document.frmMain.txtGroupId.value=gid;
	document.frmMain.frmAction.value=act;
	document.frmMain.submit();
}

function deleteCGroup(gid,act)
{
	document.frmMain.action="submit_client_group.php";
	var blnFlag = window.confirm("Do you want delete this client group?");
	if(blnFlag)
	{
		document.frmMain.txtGroupId.value=gid;
		document.frmMain.frmAction.value=act;
		document.frmMain.submit();
	}
}

function sendEmailJGroup(gid,gname)
{
	document.frmMain.action="send_jobseeker_email.php";
	document.frmMain.txtGroupId.value=gid;
	document.frmMain.txtGroupName.value=gname;
	document.frmMain.submit();
}

function editJGroup(gid,act)
{
	document.frmMain.action="manage_jobseeker_group.php";
	document.frmMain.txtGroupId.value=gid;
	document.frmMain.frmAction.value=act;
	document.frmMain.submit();
}

function deleteJGroup(gid,act)
{
	document.frmMain.action="submit_jobseeker_group.php";
	var blnFlag = window.confirm("Do you want delete this jobseeker group?");
	if(blnFlag)
	{
		document.frmMain.txtGroupId.value=gid;
		document.frmMain.frmAction.value=act;
		document.frmMain.submit();
	}
}

function deleteJob(jid,act)
{
	document.frmMain.action="submit_job.php";
	var blnFlag = window.confirm("Do you want delete this job?");
	if(blnFlag)
	{
		document.frmMain.txtJobId.value=jid;
		document.frmMain.frmAction.value=act;
		document.frmMain.submit();
	}
}

function editJobStatus(jid,act,strStatus)
{
	document.frmMain.action="submit_job.php";
	document.frmMain.txtJobId.value=jid;
	document.frmMain.txtStatus.value=strStatus;
	document.frmMain.frmAction.value=act;
	document.frmMain.submit();
}

function editJob(jid,act)
{
	document.frmMain.action="manage_job.php";
	document.frmMain.txtJobId.value=jid;
	document.frmMain.frmAction.value=act;
	document.frmMain.submit();
}

function jobDetail(jid)
{
	document.frmMain.action="job_detail.php";
	document.frmMain.txtJobId.value=jid;
	document.frmMain.submit();
}

function deleteClient(jid,act)
{
	document.frmMain.action="submit_client.php";
	var blnFlag = window.confirm("Do you want delete this client?");
	if(blnFlag)
	{
		document.frmMain.txtClientId.value=jid;
		document.frmMain.frmAction.value=act;
		document.frmMain.submit();
	}
}

function editClient(jid,act)
{
	document.frmMain.action="manage_client.php";
	document.frmMain.txtClientId.value=jid;
	document.frmMain.frmAction.value=act;
	document.frmMain.submit();
}

function trim(obj)
{
	var strVal = obj.value;
	var newstr="";
	var retstr="";
	var strlen=strVal.length;  
	for(var start=0;start<strlen;start++)
	{
		if(strVal.substring(start,start+1)!=" ")
		{ 
			newstr = strVal.substring(start,strlen); 
			break;
		}
	}
	
	strlen = newstr.length ; 
	
	for(start=strlen;start>0;start--)
	{
		if(newstr.substring(start-1,start)!=" ")
		{
			retstr=newstr.substring(0,start); 
			break;
		}
	}
	obj.value = retstr;
	
	var objVal = obj.value;
    var strSpecialChars = "`~!@#$%^&*()_-+=|{[}]\\\";:',\\\\<.>/?";
    var strFlagAlpha = 0;
    var strFlagNum = 0;
    var strFlagSpecial = 0;
    
    for(var j=0; j<objVal.length; j++)
    {
         var alphaa = objVal.charAt(j);
         var hh = alphaa.charCodeAt(0);
         if((hh > 64 && hh < 91) || (hh > 96 && hh < 123))
         {
              strFlagAlpha = 1;
         }
         if((hh > 47 && hh < 59))
         {
              strFlagNum = 1;
         }
         if(strSpecialChars.indexOf(alphaa)!=-1)
         {
              strFlagSpecial = 1;
         }
    }
    if(strFlagAlpha==0 && strFlagNum==0 && strFlagSpecial==0)
    {
       obj.value = '';
    }
}



function replaceSpecialChars(obj)
{
	var str=""; 
	var j=0;
	var strValue = obj.value;
	for(var i=0; i< strValue.length;i++) 
	{
		if(strValue.charAt(i) == '<' && strValue.charAt(i+1) != ' ')
		{  
			str= str+strValue.substring(j,i)+'< '
			j=i+1		
		}
		if((strValue.charAt(i) =="'") ||(strValue.charAt(i) == "\"") || (strValue.charAt(i) == "~") ) 
		{
			str= str+strValue.substring(j,i)+"`"
			j=i+1		
		}

		if((strValue.charAt(i) =="\\"))
		{
			str= str+strValue.substring(j,i)+"/"
			j=i+1		
		}
		if(strValue.charCodeAt(i) == 8211)
	    {
	    	str=str+strValue.substring(j,i)+"-";
	    	j=i+1;
	    }
	    if(strValue.charCodeAt(i) == 8220 || strValue.charCodeAt(i) == 8221)
	    {
	    	str=str+strValue.substring(j,i)+"`";
	    	j=i+1;
	    }
	}
	obj.value = replaceContChars(str + strValue.substring(j));
}

function replaceContChars(strValue)
{
	//Split String
	var strSplitText = strValue.split(" ");

	//Length of array
	var iLen = strSplitText.length;

	//lenght of each item in array
	var	iStrLen = 0;

	//String with required spaces
	var strMain = "";

	//Temp String Holder
	var strTemp = "";

	for(var iVal=0; iVal < iLen; iVal++)
	{
		strTemp = strSplitText[iVal];
		iStrLen = strTemp.length;

		while(iStrLen > MAXCONT)
		{
			strMain = strMain + strTemp.substr(0,MAXCONT) + " ";
			strTemp = strTemp.substr(MAXCONT,iStrLen);
			iStrLen = strTemp.length;//Recalculate length
		}
		strMain = strMain + strTemp;

		strSplitText[iVal] = strMain;
		//Clear string for next use.
		strMain="";
	}	

	//Return the string after joining it with space.
	return(strSplitText.join(" "));

}

function checkEmail(emailStr) 
{
   if (emailStr.length == 0) 
   {
       return true;
   }
   var emailPat=/^(.+)@(.+)$/;
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
   var validChars="\[^\\s" + specialChars + "\]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
   var matchArray=emailStr.match(emailPat);
   if (matchArray == null) 
   {
       return false;
   }
   var user=matchArray[1];
   var domain=matchArray[2];
   if (user.match(userPat) == null) 
   {
       return false;
   }
   var IPArray = domain.match(ipDomainPat);
   if (IPArray != null) 
   {
       for (var i = 1; i <= 4; i++) 
   {
          if (IPArray[i] > 255) 
      {
             return false;
          }
       }
       return true;
   }
   var domainArray=domain.match(domainPat);
   if (domainArray == null) 
   {
       return false;
   }
   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;
   if ((domArr[domArr.length-1].length < 2) || (domArr[domArr.length-1].length > 3)) 
   {
       return false;
   }
   if (len < 2) 
   {
       return false;
   }
   return true;
}

function validate_jobseeker()
{
	var frm = document.frmMain;
	var selectedGenderIndex = frm.txtGender.selectedIndex;
	var gender = frm.txtGender.options[selectedGenderIndex].value;
	
	var selectedEducationIndex = frm.txtEducation.selectedIndex;
	var strEducation = frm.txtEducation.options[selectedEducationIndex].value;
	
	var selectedExpertiesIndex = frm.txtExperties.selectedIndex;
	var strExperties = frm.txtExperties.options[selectedExpertiesIndex].value;
	
	var selectedExperienceIndex = frm.txtExperience.selectedIndex;
	var strExperience = frm.txtExperience.options[selectedExperienceIndex].value;
	
	if(frm.txtEmail.value=="")
    {
     	alert("Email ID is a compulsory field.Please enter Email ID");
		frm.txtEmail.focus();
      	return false;
    }
	
    if(frm.txtEmail.value!="" && (!checkEmail(frm.txtEmail.value)))
    {
     	alert("Please Enter Valid Email ID.");
		frm.txtEmail.focus();
      	return false;
    }
    
    if(frm.txtPassword.value=="")
    {
     	alert("Please enter Password.");
     	frm.txtPassword.focus();
      	return false;
    }
    
	if(frm.txtRepassword.value=="")
    {
    	alert("Please enter confirm Password.");
     	frm.txtRepassword.focus();
      	return false;
    }
	
	if(frm.txtPassword.value != frm.txtRepassword.value)
    {
		alert("Password and confirm password are not matched. Please enter password and confirm password same.");
		frm.txtRepassword.focus();
		return false;
    }
	
	if(frm.txtFirstName.value=="")
    {
		alert("Please enter first name.");
		frm.txtFirstName.focus();
		return false;
    }

	if(frm.txtLastName.value=="")
    {
		alert("Please enter last name.");
		frm.txtLastName.focus();
		return false;
    }
	
	if(gender=="")
	{
		alert("Please select Gender.");
		frm.txtGender.focus();
		return false;
	}
	
	if(frm.txtNationality.value=="")
    {
		alert("Please enter Nationality.");
		frm.txtNationality.focus();
		return false;
    }

	if(frm.txtContactNo.value=="")
    {
		alert("Please enter Contact No.");
		frm.txtContactNo.focus();
		return false;
    }
	
	if(strEducation=="")
	{
		alert("Please select Education Level.");
		frm.txtEducation.focus();
		return false;
	}
	
	if(strExperties=="")
	{
		alert("Please select Experties Area.");
		frm.txtExperties.focus();
		return false;
	}
	
	if(frm.txtLocation.value=="")
    {
		alert("Please enter Current Location.");
		frm.txtLocation.focus();
		return false;
    }
	
	if(strExperience=="")
	{
		alert("Please select Total Experience.");
		frm.txtExperience.focus();
		return false;
	}
	
	if(frm.txtCurrentSalary.value=="")
    {
		alert("Please enter Current Salary.");
		frm.txtCurrentSalary.focus();
		return false;
    }
	
	if(frm.txtResume.value=="")
    {
		alert("Please upload a resume.");
		frm.txtResume.focus();
		return false;
    }
}


function validate_client()
{
	var frm = document.frmMain;
	var selectedCityIndex = frm.txtCountry.selectedIndex;
	var country = frm.txtCountry.options[selectedCityIndex].value;
	
	if(frm.txtEmail.value=="")
    {
     	alert("Email ID is a compulsory field.Please enter Email ID");
		frm.txtEmail.focus();
      	return false;
    }
	
    if(frm.txtEmail.value!="" && (!checkEmail(frm.txtEmail.value)))
    {
     	alert("Please Enter Valid Email ID.");
		frm.txtEmail.focus();
      	return false;
    }
    
    if(frm.txtPassword.value=="")
    {
     	alert("Please enter Password.");
     	frm.txtPassword.focus();
      	return false;
    }
    
	if(frm.txtRepassword.value=="")
    {
    	alert("Please enter confirm Password.");
     	frm.txtRepassword.focus();
      	return false;
    }
	
	if(frm.txtPassword.value != frm.txtRepassword.value)
    {
		alert("Password and confirm password are not matched. Please enter password and confirm password same.");
		frm.txtRepassword.focus();
		return false;
    }
	
	if(frm.txtCompanyName.value=="")
    {
		alert("Please enter Company Name.");
		frm.txtCompanyName.focus();
		return false;
    }

	if(frm.txtContactPerson.value=="")
    {
		alert("Please enter Contact Person.");
		frm.txtContactPerson.focus();
		return false;
    }
	
	if(frm.txtCompanyType.value=="")
    {
		alert("Please enter Company Type.");
		frm.txtCompanyType.focus();
		return false;
    }

	if(frm.txtIndustryType.value=="")
    {
		alert("Please enter Industry Type.");
		frm.txtIndustryType.focus();
		return false;
    }
	
	if(frm.txtAddress.value=="")
    {
		alert("Please enter Address.");
		frm.txtAddress.focus();
		return false;
    }
	
	if(country=="")
	{
		alert("Please select Country.");
		frm.txtCountry.focus();
		return false;
	}
	
	if(frm.txtState.value=="")
    {
		alert("Please enter State.");
		frm.txtState.focus();
		return false;
    }
	
	if(frm.txtCity.value=="")
    {
		alert("Please enter City.");
		frm.txtCity.focus();
		return false;
    }
	
	if(frm.txtPhoneNo.value=="")
    {
		alert("Please enter Phone No.");
		frm.txtPhoneNo.focus();
		return false;
    }
}

function validate_job()
{
	var frm = document.frmMain;
	var selectedMonthIndex = frm.cmbPostingMonth.selectedIndex;
	var selectedMonth = frm.cmbPostingMonth.options[selectedMonthIndex].value;
	
	var selectedDateIndex = frm.cmbPostingDate.selectedIndex;
	var selectedDate = frm.cmbPostingDate.options[selectedDateIndex].value;
	
	var selectedYearIndex = frm.cmbPostingYear.selectedIndex;
	var selectedYear = frm.cmbPostingYear.options[selectedYearIndex].value;
	
	var selectedExperienceIndex = frm.txtExperience.selectedIndex;
	var strExperience = frm.txtExperience.options[selectedExperienceIndex].value;
	
	var selectedExpertiesIndex = frm.txtFunctionalArea.selectedIndex;
	var strExperties = frm.txtFunctionalArea.options[selectedExpertiesIndex].value;
	
	if(frm.txtJobPosition.value=="")
    {
     	alert("Please enter Job Position.");
		frm.txtJobPosition.focus();
      	return false;
    }
	
    if(selectedMonth=="" || selectedDate =="" || selectedYear == "")
    {
     	alert("Please select Posting Date.");
     	frm.cmbPostingMonth.focus();
      	return false;
    }
    
	if(frm.txtJobType.value=="")
    {
    	alert("Please enter Job Type.");
     	frm.txtJobType.focus();
      	return false;
    }
	
	if(strExperience=="")
	{
		alert("Please select Total Experience.");
		frm.txtExperience.focus();
		return false;
	}
	
	if(frm.txtQualification.value=="")
    {
		alert("Please enter Qualification.");
		frm.txtQualification.focus();
		return false;
    }

	if(frm.txtLocation.value=="")
    {
		alert("Please enter Location.");
		frm.txtLocation.focus();
		return false;
    }

	if(frm.txtKeySkills.value=="")
    {
		alert("Please enter KeySkills.");
		frm.txtKeySkills.focus();
		return false;
    }

	if(frm.txtRequirements.value=="")
    {
		alert("Please enter Requirements.");
		frm.txtRequirements.focus();
		return false;
    }
	
	if(strExperties=="")
	{
		alert("Please select Experties Area.");
		frm.txtFunctionalArea.focus();
		return false;
	}
	
	if(frm.txtJobResponsibility.value=="")
    {
		alert("Please enter Job Responsibility.");
		frm.txtJobResponsibility.focus();
		return false;
    }
	
	if(frm.txtUploadDocument.value=="")
    {
		alert("Please upload a document.");
		frm.txtUploadDocument.focus();
		return false;
    }
}

function checkPassword()
{
	var frm = document.frmMain;
	
	if(frm.txtPassword.value=="")
    {
     	alert("Please enter Password.");
     	frm.txtPassword.focus();
      	return false;
    }
    
	if(frm.txtRepassword.value=="")
    {
    	alert("Please enter confirm Password.");
     	frm.txtRepassword.focus();
      	return false;
    }
	
	if(frm.txtPassword.value != frm.txtRepassword.value)
    {
		alert("Password and confirm password are not matched. Please enter password and confirm password same.");
		frm.txtRepassword.focus();
		return false;
    }
	
}

