// JavaScript Document\

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
//window.sidebar.addPanel(title, url, "");
window.external.AddFavorite(url, title);
else if(window.opera && window.print){ // opera
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click();
}
else if(document.all)// ie
window.external.AddFavorite(url, title);
}

//End of Bookmark code

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, 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 ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

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;					
	}
		
		
	function register_Validate() {
		var x=document.register;
		var emailID=document.register.email;
		if(x.fname.value=="")
		{
			alert("Please enter your first name.");
			x.fname.focus();
			return false;
		}
		if(x.dob.value=="")
		{
			alert("Please enter your date of birth.");
			x.dob.focus();
			return false;
		}
		if(isDate(x.dob.value)==false)
		{
			x.dob.focus();
			return false;
		}
		
		if(x.location.value=="Not Set")
		{
			alert("Please select location.");
			x.location.focus();
			return false;
		}
		if(x.Postcode.value=="")
		{
			alert("Please enter postcode.");
			x.Postcode.focus();
			return false;
		}
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter Email ID");
			emailID.focus();
			return false;
			}
			if (echeck(emailID.value)==false){
				emailID.value="";
				emailID.focus();
				return false;
			}
		if(x.homephone.value=="")
		{
			alert("Please enter phone number at home.");
			x.homephone.focus();
			return false;
		}
		
		if(x.password.value=="")
		{
			alert("Please enter password.");
			x.password.focus();
			return false;
		}
		if(x.confPassword.value=="")
		{
			alert("Please re-enter your password.");
			x.confPassword.focus();
			return false;
		}
		
		if(x.confPassword.value==x.password.value)
		{
			
		}
		else
		{
			alert("Both password field values should be equal.");
			x.password.focus();
			return false;
		}
		
		return true;
	}//formValidate()
	
	
	function register_Vacancy(){
		var frm = document.registervacancy;
		var emailID=document.registervacancy.email;
		if(frm.company_name.value=="")
		{
			alert("Please enter company name.");
			frm.company_name.focus();
			return false;
		}
		if(frm.contact_person.value=="")
		{
			alert("Please enter contact person name.");
			frm.contact_person.focus();
			return false;
		}
		if(frm.Position.value=="")
		{
			alert("Please enter position.");
			frm.Position.focus();
			return false;
		}
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter Email ID");
			emailID.focus();
			return false;
			}
		if (echeck(emailID.value)==false){
			emailID.value="";
			emailID.focus();
			return false;
		}
		if(frm.Telephone.value=="")
		{
			alert("Please enter your telephone number.");
			frm.Telephone.focus();
			return false;
		}
		if(frm.vacancybased.value=="")
		{
			alert("Please enter, Where is the vacancy based?.");
			frm.vacancybased.focus();
			return false;
		}
		if(frm.category.value=="")
		{
			alert("Please select job category.");
			frm.category.focus();
			return false;
		}
		if(frm.Jobtitle.value=="")
		{
			alert("Please enter job title .");
			frm.Jobtitle.focus();
			return false;
		}
		if(frm.Role.value=="")
		{
			alert("Please enter role description.");
			frm.Role.focus();
			return false;
		}
		if(frm.Salary.value=="")
		{
			alert("Please enter salary & benefits.");
			frm.Salary.focus();
			return false;
		}
		
		return true;	
	}

  // :::::::::::::: Password Change form validation :::::::::::::::::
			
	function validatePassChange()
		{
		var frm = document.changepass;
		
		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;
		
	}
	
	function validate_login_form()
		{
		var frm = document.signin;
		
		if (frm.email.value == "")
		{
			alert("Please enter your email id.");
			frm.email.focus();
			return false;
		}
		if (frm.password.value == "")
		{
			alert("Please enter your password.");
			frm.password.focus();
			return false;
		}
	
		
		return true;
		
	}
	
	function upload_cv_validate()
	{
		var x=document.upload_cv;
		var emailID=document.upload_cv.email;
		if(x.name.value=="")
		{
			alert("Please enter your name.");
			x.name.focus();
			return false;
		}
		if(x.location.value=="Not Set")
		{
			alert("Please select location.");
			x.location.focus();
			return false;
		}
		if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter Email ID");
		emailID.focus();
		return false;
		}
		if (echeck(emailID.value)==false){
			emailID.value="";
			emailID.focus();
			return false;
		}
		if(x.cv.value=="")
		{
			alert("Please browse your cv.");
			x.cv.focus();
			return false;
		}
		if(document.getElementById("confirm").checked)
		{
		}
		else
		{
			alert("Please confirm, you have read and understood the information above.");
			document.getElementById("confirm").focus();
			return false;
		}
		return true;
	}
	
function validate_ContactUs()
	{
		var frm=document.contactus;
		
		var emailID=document.contactus.email;
		if(frm.name.value=="")
		{
			alert("Please enter your name.");
			frm.name.focus();
			return false;
		}
		if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter 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;
		}
		if(frm.message.value=="")
		{
			alert("Please enter your message.");
			frm.message.focus();
			return false;
		}
		if(document.getElementById("confirm").checked)
		{
		}
		else
		{
			alert("Please confirm, you have read and understood the information above.");
			document.getElementById("confirm").focus();
			return false;
		}
		return true;
	}
	
	
	function validate_Send()
	{
		var frm=document.sendtofriend;
		
		var emailID=document.sendtofriend.email;
		
		var f_emailID=document.sendtofriend.f_email;
		if(frm.name.value=="")
		{
			alert("Please enter your name.");
			frm.name.focus();
			return false;
		}
		if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter Email ID");
		emailID.focus();
		return false;
		}
		if (echeck(emailID.value)==false){
			emailID.value="";
			emailID.focus();
			return false;
		}
		
		if(frm.f_name.value=="")
		{
			alert("Please enter your friend's name.");
			frm.f_name.focus();
			return false;
		}
		if ((f_emailID.value==null)||(f_emailID.value=="")){
		alert("Please Enter Your Friend's Email ID");
		f_emailID.focus();
		return false;
		}
		if (echeck(f_emailID.value)==false){
			f_emailID.value="";
			f_emailID.focus();
			return false;
		}
		
		if(frm.message.value=="")
		{
			alert("Please enter your message.");
			frm.message.focus();
			return false;
		}
		return true;
	}
	
	function check_confirm()
	{
		if(document.getElementById("confirm").checked){
			window.location="register.php";
		}
		else{
			alert("Please confirm, you have read and understood the information above.");
			document.getElementById("confirm").focus();
			}
	}
	
