// JavaScript Document

function echeck(str) 
	{
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

 		 return true;					
	}
	
	//minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
		
		
   function AddFAQs_validate()
	{
		var frm = document.AddFAQs;
		
		if (frm.header.value == "")
		{
			alert("Please enter news header.");
			frm.header.focus();
			return false;
		}
		if (parseInt(frm.desc_html.value.length) == 54)
		{
			alert("Please enter brief description.");
			//frm.desc_html.focus();
			return false;
		}
		
		return true;
		
	}
	
	function EditFAQs_validate()
	{
		var frm = document.EditFAQs;
		
		if (frm.header.value == "")
		{
			alert("Please enter news header.");
			frm.header.focus();
			return false;
		}
		if (frm.desc_html.value == "")
		{
			alert("Please enter brief description.");
			frm.desc_html.focus();
			return false;
		}
		
		return true;
		
	}
	
	function AddJobSector_validate()
	{
		var frm = document.AddJobSector;
		
		if (frm.sectorname.value == "")
		{
			alert("Please enter job sector name.");
			frm.sectorname.focus();
			return false;
		}
		return true;
		
	}
	
	function EditJobSector_validate()
	{
		var frm = document.EditJobSector;
		
		if (frm.sectorname.value == "")
		{
			alert("Please enter job sector name.");
			frm.sectorname.focus();
			return false;
		}
		return true;
		
	}
	
	function SubSector_validate()
	{
		var frm = document.SubSector;
		
		if (frm.parentSectorId.value == "")
		{
			alert("Please select job sector name.");
			frm.parentSectorId.focus();
			return false;
		}
		
		if (frm.sectorname.value == "")
		{
			alert("Please enter sub sector name.");
			frm.sectorname.focus();
			return false;
		}
		return true;
		
	}
	
	
	
	function AddJobRegion_validate()
	{
		var frm = document.AddJobRegion;
		
		if (frm.Regionname.value == "")
		{
			alert("Please enter region name.");
			frm.Regionname.focus();
			return false;
		}
		return true;
		
	}
	function SubLocation_validate()
	{
		var frm = document.SubLocation;
		
		if (frm.ParentLocationId.value == "")
		{
			alert("Please select location");
			frm.ParentLocationId.focus();
			return false;
		}
		if (frm.Regionname.value == "")
		{
			alert("Please enter sub location.");
			frm.Regionname.focus();
			return false;
		}
		return true;
		
	}
	
	function EditJobRegion_validate()
	{
		var frm = document.EditJobRegion;
		
		if (frm.Regionname.value == "")
		{
			alert("Please enter region name.");
			frm.Regionname.focus();
			return false;
		}
		return true;
		
	}
	
	function AddSalaryGroup_validate()
	{
		var frm = document.AddSalaryGroup;
		
		if (frm.salarytype.value == "")
		{
			alert("Please select salary type.");
			frm.salarytype.focus();
			return false;
		}
		if (frm.salary.value == "")
		{
			alert("Please enter salary.");
			frm.salary.focus();
			return false;
		}
		if (isNaN(frm.salary.value))
		{
			alert("Please enter numeric value as salary.");
			frm.salary.value = "";
			frm.salary.focus();
			return false;
		}
		return true;
		
	}
	
	function EditSalaryGroup_validate()
	{
		var frm = document.EditSalaryGroup;
		
		if (frm.salarytype.value == "")
		{
			alert("Please select salary type.");
			frm.salarytype.focus();
			return false;
		}
		if (frm.salary.value == "")
		{
			alert("Please enter salary.");
			frm.salary.focus();
			return false;
		}
		if (isNaN(frm.salary.value))
		{
			alert("Please enter numeric value as salary.");
			frm.salary.value = "";
			frm.salary.focus();
			return false;
		}
		return true;
		
	}
	
	function EditMember_validate()
	{
		var frm = document.EditMember;
		var emailID=document.EditMember.email;
		if (frm.firstname.value == "")
		{
			alert("Please enter your first name.");
			frm.firstname.focus();
			return false;
		}
		if (frm.address.value == "")
		{
			alert("Please enter your address.");
			frm.address.focus();
			return false;
		}
		if ((emailID.value==null)||(emailID.value=="")){
				alert("Please Enter your Email ID");
				emailID.focus();
				return false;
			}
			if (echeck(emailID.value)==false){
				emailID.value="";
				emailID.focus();
				return false;
			}
		if (frm.phone.value == "")
		{
			alert("Please enter your phone number.");
			frm.phone.focus();
			return false;
		}	
		
		return true;
		
	}
	
	function validate_login_form()
		{
		var frm = document.login;
		
		if (frm.userid.value == "")
		{
			alert("Please enter User Id.");
			frm.userid.focus();
			return false;
		}
		if (frm.password.value == "")
		{
			alert("Please enter password.");
			frm.password.focus();
			return false;
		}
	
		
		return true;
		
	}
	
	// :::::::::::::: Delete confirm ::::::::::::::
	
		function confirmDelete()
		{
			if(confirm("Confirm Delete !"))
			{
			   return true;	
			}
			else
			{
			   return false;	
			}
		}
	
	// :::::::::::::: End Delete confirm ::::::::::
	
	
	// :::::::::::::: Password Change form validation :::::::::::::::::
			
	function validatePassChange()
		{
		var frm = document.ChangePassword;
		
		if (frm.oldPassword.value == "")
		{
			alert("Please enter old password.");
			frm.oldPassword.focus();
			return false;
		}
		if (frm.newPassword.value == "")
		{
			alert("Please enter new password.");
			frm.newPassword.focus();
			return false;
		}
		if (frm.confirmPassword.value == "")
		{
			alert("Please enter confirm Password.");
			frm.confirmPassword.focus();
			return false;
		}
		if (frm.newPassword.value != frm.confirmPassword.value)
		{
			alert("New password and confirm Password value should be equal.");
			frm.newPassword.value="";
			frm.confirmPassword.value="";
			frm.newPassword.focus();
			return false;
		}
		
		return true;
		
	}
	
	// :::::::::::::: End of Password Change form validation :::::::::::::::::
	
	function EditQuery_validate()
	{
		var frm = document.EditQuery;
		
		if (frm.answer.value == "")
		{
			alert("Please enter answer field.");
			frm.answer.focus();
			return false;
		}
		return true;
		
	}
	
	function AddJobDetails_validate()
	{
		var frm = document.AddJobDetails;
		
		if (frm.jobtitle.value == "")
		{
			alert("Please enter job title.");
			frm.jobtitle.focus();
			return false;
		}
		if (frm.jobsector.value == "")
		{
			alert("Please select job sector.");
			frm.jobsector.focus();
			return false;
		}
		if (frm.salary.value == "")
		{
			alert("Please select salary.");
			frm.salary.focus();
			return false;
		}
		if (frm.region.value == "")
		{
			alert("Please select region.");
			frm.region.focus();
			return false;
		}
		if (frm.location.value == "")
		{
			alert("Please enter location.");
			frm.location.focus();
			return false;
		}
		if (frm.description.value == "")
		{
			alert("Please enter description.");
			frm.description.focus();
			return false;
		}
		if (frm.contactperson.value == "")
		{
			alert("Please enter contact person details.");
			frm.contactperson.focus();
			return false;
		}
		if (frm.Numbeofvacancies.value == "")
		{
			alert("Please enter Number of vacancies.");
			frm.Numbeofvacancies.focus();
			return false;
		}
		if (isNaN(frm.Numbeofvacancies.value))
		{
			alert("Please enter numeric value as number of vacancies.");
			frm.Numbeofvacancies.value="";
			frm.Numbeofvacancies.focus();
			return false;
		}
		if (frm.Agency_Direct.value == "")
		{
			alert("Please select job by Agency / Direct.");
			frm.Agency_Direct.focus();
			return false;
		}
		if (frm.JobType.value == "")
		{
			alert("Please select Job Type.");
			frm.JobType.focus();
			return false;
		}
		
		if (frm.exday.value == "")
		{
			alert("Please select day.");
			frm.exday.focus();
			return false;
		}
		if (frm.exmonth.value == "")
		{
			alert("Please select month.");
			frm.exmonth.focus();
			return false;
		}
		if (frm.exyear.value == "")
		{
			alert("Please select year.");
			frm.exyear.focus();
			return false;
		}
		if (frm.Keyword.value == "")
		{
			alert("Please enter keyword.");
			frm.Keyword.focus();
			return false;
		}
		
		return true;
		
	}
	
	function EditJobDetails_validate()
	{
		var frm = document.EditJobDetails;
		
		if (frm.jobtitle.value == "")
		{
			alert("Please enter job title.");
			frm.jobtitle.focus();
			return false;
		}
		if (frm.jobsector.value == "")
		{
			alert("Please select job sector.");
			frm.jobsector.focus();
			return false;
		}
		if (frm.salary.value == "")
		{
			alert("Please select salary.");
			frm.salary.focus();
			return false;
		}
		if (frm.region.value == "")
		{
			alert("Please select region.");
			frm.region.focus();
			return false;
		}
		if (frm.location.value == "")
		{
			alert("Please enter location.");
			frm.location.focus();
			return false;
		}
		if (frm.description.value == "")
		{
			alert("Please enter description.");
			frm.description.focus();
			return false;
		}
		if (frm.contactperson.value == "")
		{
			alert("Please enter contact person details.");
			frm.contactperson.focus();
			return false;
		}
		if (frm.Numbeofvacancies.value == "")
		{
			alert("Please enter Number of vacancies.");
			frm.Numbeofvacancies.focus();
			return false;
		}
		if (isNaN(frm.Numbeofvacancies.value))
		{
			alert("Please enter numeric value as number of vacancies.");
			frm.Numbeofvacancies.value="";
			frm.Numbeofvacancies.focus();
			return false;
		}
		if (frm.Agency_Direct.value == "")
		{
			alert("Please select job by Agency / Direct.");
			frm.Agency_Direct.focus();
			return false;
		}
		if (frm.JobType.value == "")
		{
			alert("Please select Job Type.");
			frm.JobType.focus();
			return false;
		}
		
		if (frm.exday.value == "")
		{
			alert("Please select day.");
			frm.exday.focus();
			return false;
		}
		if (frm.exmonth.value == "")
		{
			alert("Please select month.");
			frm.exmonth.focus();
			return false;
		}
		if (frm.exyear.value == "")
		{
			alert("Please select year.");
			frm.exyear.focus();
			return false;
		}
		if (frm.Keyword.value == "")
		{
			alert("Please enter keyword.");
			frm.Keyword.focus();
			return false;
		}
		
		return true;
		
	}
	
	function UserDetails_validate()
	{
		var frm = document.Users;
		
		if (frm.userid.value == "")
		{
			alert("Please enter user id.");
			frm.userid.focus();
			return false;
		}
		if (frm.password.value == "")
		{
			alert("Please enter password.");
			frm.password.focus();
			return false;
		}
		if (frm.authorization_type.value == "")
		{
			alert("Please select authorization type.");
			frm.authorization_type.focus();
			return false;
		}
		
		return true;
		
	}
	
	function UpdateDiscount(type)
	{
		
		if (type == "FREEJOB" || type == "FREELUV")
		{
			document.getElementById("discount").value = 100;
			document.getElementById("discount").readOnly=true;
		}
		else
		{
			document.getElementById("discount").value = 0;
			document.getElementById("discount").readOnly=false;
		}
	}
	
	function validate_promocode()
	{
		var frm = document.promocode;
		var dt=document.promocode.expiry
		if(frm.couponID.value=="")
		{
			alert("Please enter coupon id.");
			frm.couponID.focus();
			return false;
		}
		
		if(isNaN(frm.couponID.value))
		{
			alert("Please enter numeric value as coupon id.");
			frm.couponID.focus();
			return false;
		}
		if(frm.PCType.value=="")
		{
			alert("Please select promo code type.");
			frm.PCType.focus();
			return false;
		}
		
		if(frm.PCType.value=="FREEJOB" || frm.PCType.value=="FREELUV")
		{
			
		}
		else
		{
			if(frm.discount.value == "")
			{
				alert("Please enter coupon discount type.");
				frm.discount.focus();
				return false;
			}
		}
		
		if(frm.expiry.value=="")
		{
			alert("Please enter expiry date.");
			frm.expiry.focus();
			return false;
		}
		if (isDate(dt.value)==false)
		{
			dt.focus()
			return false
		}
		
		if(frm.totalCoupon.value=="")
		{
			alert("Please enter no. of coupon.");
			frm.totalCoupon.focus();
			return false;
		}
		if(frm.totalCoupon.value < 1)
		{
			alert("Total no. of coupon should not be less than one.");
			frm.totalCoupon.focus();
			return false;
		}
		
		return true;
	}
	
	function knowledgeBase_validate()
	{
		var frm = document.uploadknowledgeBase;
		
		if (frm.foldername.value == "")
		{
			alert("Please select folder name.");
			frm.foldername.focus();
			return false;
		}
		if (frm.KnowledgeBase.value == "")
		{
			alert("Please browse document file.");
			frm.KnowledgeBase.focus();
			return false;
		}
		var path11;
		path11 = (frm.KnowledgeBase.value.split("."));
	if(path11[path11.length-1].replace(" ","").toUpperCase()=="PDF" || path11[path11.length-1].replace(" ","").toUpperCase()=="DOC")
		{
		}
		else
		{
			alert("Document File should be in PDF or DOC format.");
			frm.KnowledgeBase.focus();
			return false;
		}
		
		return true;
		
	}
	
	function folder_validate()
	{
		frm  = document.create_folder;
		if (frm.foldername.value=="")
		{
			alert("Please enter folder name");
			frm.foldername.focus();
			return false;
		}
		return true;
	}
	
