function isFilledField(el){
	if(el.value==''){
		alert(el.title + ' is Mandatory');
		el.focus();
		return(false);
	}
	return(true);
}

function validateGeneral(frm){
	for(var i=0; i<frm.elements.length; i++){
		var el=frm.elements[i];
		if(el.lang=='must'){
			if(!isFilledField(el)) return false;
		}
	}
	return(true);
}

function check_employer_registration(frm){
	if(!validateGeneral(frm)) return false;
	
	return true;
}

function checkAvailableEmail(el){
	callAjax('check-email-available.php', 'email='+el.value, function(t){
		var ans=eval(t);
		if(ans[0].status==0){alert(ans[0].msg);el.value='';el.focus();}
	}
	);
}

function callAjax(strURL,strPostData,functionName) {
    var xmlHttpReq = false;
    var self = this;
	var msg="";
    // Mozilla/Safari
	
	www=(window.location.href.toLowerCase().indexOf("//www.")>0)?"http://www.":"http://";
	strURL=strURL.replace("http://",www);

    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
		
        if (self.xmlHttpReq.readyState == 4) 
		{
			functionName(self.xmlHttpReq.responseText);
		}
		else
		{
			//alert(self.xmlHttpReq.readyState);
		}
    }
	
    self.xmlHttpReq.send(strPostData);
}

function toggleDisplay(id){
	document.getElementById(id).style.display=(document.getElementById(id).style.display=='none')?'':'none';
}

function selectCheckBoxes(el, val){
	if(!el) return;
	if(!el.length){
		el.checked=val;
		return;
	}
	for(var i=0; i < el.length; i++){
		el[i].checked=val;
	}
	
}

function applyForJob(jobid){
	callAjax('apply-for-job.php', 'id='+jobid, function(t){
															if(t=='ok'){
																alert('Successfully applied for the job');
																if(document.getElementById('div_apply')) document.getElementById('div_apply').innerHTML='<img src="images/apply-dis.gif" alt="Already Applied" title="You have already applied for this job">';
															}
															else{
																alert(t);
															}
															}
	);
}

function subscribeNewsletter(email){
	callAjax('subscribe-newsletter.php', 'email='+email, function(t){
																  alert(t);
																  }
																  );
}