// JavaScript Document
var ajax = new sack();
// for paging in source applicant
function load_source(){

	var rand_num;
	var position_id = document.getElementById('position_id').value;
	var status_id = document.getElementById('status_id').value;
	var gender = document.getElementById('gender').value;
	var min_age = document.getElementById('min_age').value;
	var max_age = document.getElementById('max_age').value;
	var job_desc = document.getElementById('job_desc').value;
	var skills = document.getElementById('skills').value;
	
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqladd.php?what=ajax_load_source&position_id='+position_id+'&status_id='+status_id+'&gender='+gender+'&min_age='+min_age+'&max_age='+max_age+'&job_desc='+job_desc+'&skills='+skills;
	//ajax.onLoaded = get_load_principal_interactive; 
	//ajax.onInteractive = get_load_principal_interactive; 
	ajax.onCompletion = ajax.response;
	ajax.runAJAX();
}

function get_load_source()
{
var loadID = document.getElementById('loadSource');
loadID.innerHTML=  "<img src='img/ajax.gif'>";
}
// for paging in source applicant
function load_positions(){

	var rand_num;
	var cat_id = document.getElementById('cat_id').value;
		
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqladd.php?what=ajax_loadpositions&cat_id='+cat_id;
	//ajax.onLoading = get_load_valuesonloading;
	//ajax.onLoaded = get_load_valuesonloading;
	ajax.onCompletion = get_loadPOS;
	ajax.runAJAX();
}
function get_loadPOS() {
	eval(ajax.response);
}
function load_position(){

	var rand_num;
	var cat_id = document.getElementById('cat_id').value;
		
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqladd.php?what=ajax_loadposition&cat_id='+cat_id;
	//ajax.onLoading = get_load_valuesonloading;
	//ajax.onLoaded = get_load_valuesonloading;
	ajax.onCompletion = get_loadPO;
	ajax.runAJAX();
}
function get_loadPO() {
	eval(ajax.response);
}
function load_JOPOS(){

	var rand_num;
	var principal_id = document.getElementById('principal_id').value;
		
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqladd.php?what=load_JOPOS&principal_id='+principal_id;
	//ajax.onLoading = get_load_valuesonloading;
	//ajax.onLoaded = get_load_valuesonloading;
	ajax.onCompletion = get_loadJOPOS;
	ajax.runAJAX();
}
function get_loadJOPOS() {
	eval(ajax.response);
}
function load_position1(){

	var rand_num;
	var cat_id = document.getElementById('cat_id').value;
		
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqladd.php?what=ajax_loadposition1&cat_id='+cat_id;
	//ajax.onLoading = get_load_valuesonloading;
	//ajax.onLoaded = get_load_valuesonloading;
	ajax.onCompletion = get_loadPO1;
	ajax.runAJAX();
}
function get_loadPO1() {
	eval(ajax.response);
}
/* abbie 2008-12-10 - fixed the error in the ajax implementation of job order and visa dropdown*/
// for applicant process module
function load_values(){

	var rand_num;
	var principal_id = document.getElementById('principal_id').value;
		
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqladd.php?what=ajax_LoadProcess&principal_id='+principal_id;
	//ajax.onLoading = get_load_valuesonloading;
	//ajax.onLoaded = get_load_valuesonloading;
	ajax.onCompletion = get_load_values;
	ajax.runAJAX();
}
function get_load_valuesonloading()
{
	var id = document.getElementById('idloadjob');
	id.innerHTML =  '<img src=img/ajax.gif>';
}
function get_load_values()
{
//	var id = document.getElementById('idloadjob');
//	alert(ajax.response);
//	id.innerHTML =  ajax.response;
	eval(ajax.response);
}

/* end of abbie 2008-12-10 - fixed the error in the ajax implementation of job order and visa dropdown*/

//function load_visa(){

//	var rand_num;
//	var principal_id = document.getElementById('principal_id').value;
	
	//document.getElementById('jopos_id_new').value = document.getElementById('jopos_id').value;
	//document.getElementById('visapos_id_new').value = "";
	
	//rand_num=parseInt(Math.random()*99999999999);
 	//ajax.requestFile = 'sqladd.php?what=ajax_LoadVisa&principal_id='+principal_id;
	//ajax.onCompletion = get_load_visa;
	//ajax.runAJAX();
//}
//function get_load_visa()
//{
//	var idvisa = document.getElementById('idloadvisa');
//	idvisa.innerHTML =  ajax.response;
//}

//function load_visa_id()
//{
//	document.getElementById('visapos_id_new').value = document.getElementById('visapos_id').value;
//}
// for applicant process module


// for applicant line up / cv sent module
function load_principal(){

	var rand_num;
	var principal_id = document.getElementById('principal_id').value;
	document.getElementById('jo_pos_id_new').value = "";
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqladd.php?what=ajax_LoadCvsent&principal_id='+principal_id;
	ajax.onLoading = get_load_principalonloading; 
	ajax.onLoaded = get_load_principalonloading; 
	ajax.onCompletion = get_load_principal;
	ajax.runAJAX();
}

function get_load_principalonloading()
{
var id = document.getElementById('idloadjob');
id.innerHTML=  "<img src='img/ajax.gif'>";
}


function get_load_principal()
{
//var imageID = document.getElementById('loadImage');
//imageID.innerHTML=  "";
var id = document.getElementById('idloadjob');
id.innerHTML=  ajax.response;
}

function load_job_id() {
document.getElementById('jo_pos_id_new').value = jo_pos_id = document.getElementById('jo_pos_id').value;
}
// for applicant line up / cv sent module


// for applicant prsonel module, to check if lname, fname and mname is exist on adding record
function check_applicant(){
	var rand_num;
	var lastname = document.getElementById('lastname').value;
	var firstname = document.getElementById('firstname').value;
	var mname = document.getElementById('mname').value;
	if (lastname!="" && firstname!="" && mname!=""){
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqladd.php?what=check_addapplicant&lastname='+lastname+'&firstname='+firstname+'&mname='+mname;
	ajax.onCompletion = get_check_applicant;
	ajax.runAJAX();}
}

function get_check_applicant() { 
var id = document.getElementById('idLoadDiv');
id.innerHTML =  ajax.response;
}
// for applicant prsonel module, to check if lname, fname and mname is exist on adding record


// for applicant prsonel module, to check if lname, fname and mname is exist on editing record
function check_applicant_on_update(){
	var rand_num;
	var lastname = document.getElementById('lastname').value;
	var firstname = document.getElementById('firstname').value;
	var mname = document.getElementById('mname').value;
	var applicant_id = document.getElementById('applicant_id').value;
	if (lastname!="" && firstname!="" && mname!=""){
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqlupdate.php?what=check_addapplicant&lastname='+lastname+'&firstname='+firstname+'&mname='+mname+'&applicant_id='+applicant_id;
	ajax.onCompletion = get_check_applicant_on_update;
	ajax.runAJAX();}
}

function get_check_applicant_on_update() { 
var id = document.getElementById('idLoadDiv');
id.innerHTML =  ajax.response;
}
// for applicant prsonel module, to check if lname, fname and mname is exist on editing record


// for checking of principal if there is already exist and add record
function check_principal(){
	var rand_num;
	var name = document.getElementById('name').value;
	var address = document.getElementById('address').value;
	var city = document.getElementById('city').value;
	var country_id = document.getElementById('country_id').value;
	var fax = document.getElementById('fax').value;
	var telephone = document.getElementById('telephone').value;
	var email = document.getElementById('email').value;
	var contact_person = document.getElementById('contact_person').value;
	var contact_position = document.getElementById('contact_position').value;
	var RO = document.getElementById('RO').value;
	var month = document.getElementById('month').value;
	var day = document.getElementById('day').value;
	var year = document.getElementById('year').value;
	var month1 = document.getElementById('month1').value;
	var day1 = document.getElementById('day1').value;
	var year1 = document.getElementById('year1').value;
	var acc_no =  document.getElementById('acc_no').value;
	var username = document.getElementById('username').value;
	var password = document.getElementById('password').value;
	
	
	if (name==""){
	   	alert('Name of Principal is a required field.');
		document.getElementById('name').focus();
		return;
	}
	
	if (country_id==""){
	   	alert('Country is a required field.');
		document.getElementById('country_id').focus();
		return;
	}
	
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqladd.php?what=principal&name='+name+'&address='+address+'&city='+city+'&country_id='+country_id+'&fax='+fax+'&telephone='+telephone+'&email='+email+'&contact_person='+contact_person+'&contact_position='+contact_position+'&RO='+RO+'&month='+month+'&day='+day+'&year='+year+'&username='+username+'&password='+password+'&acc_no='+acc_no+'&month1='+month1+'&day1='+day1+'&year1='+year1;
	ajax.onCompletion = get_check_principal;
	ajax.runAJAX();
}

function get_check_principal()
{
eval(ajax.response);
}
// for checking of principal if there is already exist and add record



// for checking of principal if there is already exist and update record
function check_principal_onupdate(){
	var rand_num;
	var name = document.getElementById('name').value;
	var address = document.getElementById('address').value;
	var city = document.getElementById('city').value;
	var country_id = document.getElementById('country_id').value;
	var fax = document.getElementById('fax').value;
	var telephone = document.getElementById('telephone').value;
	var email = document.getElementById('email').value;
	var contact_person = document.getElementById('contact_person').value;
	var contact_position = document.getElementById('contact_position').value;
	var RO = document.getElementById('RO').value;
	var month = document.getElementById('month').value;
	var day = document.getElementById('day').value;
	var year = document.getElementById('year').value;
	var month1 = document.getElementById('month1').value;
	var day1 = document.getElementById('day1').value;
	var year1 = document.getElementById('year1').value;
	var acc_no =  document.getElementById('acc_no').value;
	var username = document.getElementById('username').value;
	var password = document.getElementById('password').value;
	var principal_id = document.getElementById('principal_id').value;
	
	
	if (name==""){
	   	alert('Name of Principal is a required field.');
		document.getElementById('name').focus();
		return;
	}
	
	if (country_id==""){
	   	alert('Country is a required field.');
		document.getElementById('country_id').focus();
		return;
	}
	
	rand_num=parseInt(Math.random()*99999999999);
 	ajax.requestFile = 'sqlupdate.php?what=principal&name='+name+'&address='+address+'&city='+city+'&country_id='+country_id+'&fax='+fax+'&telephone='+telephone+'&email='+email+'&contact_person='+contact_person+'&contact_position='+contact_position+'&RO='+RO+'&month='+month+'&day='+day+'&year='+year+'&username='+username+'&password='+password+'&acc_no='+acc_no+'&principal_id='+principal_id+'&month1='+month1+'&day1='+day1+'&year1='+year1;
	ajax.onCompletion = get_check_principal_onupdate;
	ajax.runAJAX();
}

function get_check_principal_onupdate()
{
var id = document.getElementById('idLoadDiv');
id.innerHTML =  ajax.response;
}
// for checking of principal if there is already exist and add record


// function ajax for account description

function ajax_Account_Desc(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajax_display');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var mode = document.getElementById('mode').value;
	var queryString = "?mode=" + mode;
	ajaxRequest.open("GET", "sqladd.php?what=acc_description" + queryString, true);
	ajaxRequest.send(null); 
}

// function ajax for account description


// function send sms
function send_sms(){

	var rand_num;
	var number = document.getElementById('number').value;
	var message = document.getElementById('message').value;
	var mylink = document.getElementById('mylink').value;
	var GSM_SIM = document.getElementById('GSM_SIM').value;
	var sendername = document.getElementById('sendername').value;
	var Fname = document.getElementById('Fname').value;
	var Position = document.getElementById('Position').value;
	var applicant_id1 = document.getElementById('applicant_id1').value; // ch
	
	
	if (number==""){
	   	alert('Number is a required field.');
		document.getElementById('number').focus();
		return;
	}
	
	if (message==""){
	   	alert('Message is a required field.');
		document.getElementById('message').focus();
		return;
	}
	
	rand_num=parseInt(Math.random()*99999999999);
 	requestFile = ''+mylink+'iris_sendsms_live.php?number='+number+'&message='+message+'&GSM_SIM='+GSM_SIM+'&sendername='+sendername+'&Fname='+Fname+'&Position='+Position+'&applicant_id1='+applicant_id1+'&showhtml=1'; // ch
	window.open (requestFile,"smswindow",'menubar=0,location=0,scrollbars=no,resizable=no,width=420,height=250,left=300,top=280', 0);
}
function get_sms_loading()
{
	var idSMS = document.getElementById('idsms');
	idSMS.innerHTML =  '<center><img src=img/ajaxsms.gif></center>';
}
function get_sms_loaded()
{
	var idSMS = document.getElementById('idsms');
	idSMS.innerHTML =  ajax.response;
}

// function send sms
