function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}
var http = createRequestObject();
var nextid;
var accessId;

function sendReq(firstid,secondid) 
{
	this.nextid = secondid;
	var action=firstid.value;
	//alert(action)
	http.open('get','../templates/ajax.php?sid='+action+'&sel_state=true');
	http.onreadystatechange = handleResponse2; //Function which handels the response.
	http.send(null);
}

function sendReq8(firstid,secondid) 
{
	this.nextid = secondid;
	var action=firstid.value;
	//alert(action)
	http.open('get','../templates/ajax.php?sid2='+action+'&sel_round=true');
	http.onreadystatechange = handleResponse2; //Function which handels the response.
	http.send(null);
}


function sendReq5(firstid,secondid) 
{
	this.nextid = secondid;
	var action=firstid.value;
	//alert(action)
	http.open('get','../templates/ajax.php?sid='+action+'&sel_state=true');
	http.onreadystatechange = handleResponse5; //Function which handels the response.
	http.send(null);
}

function sendReqTest(firstid,secondid) 
{
	this.nextid = secondid;
	var action=firstid.value;
	//alert(action)
	http.open('get','../templates/ajax.php?tid='+action+'&sel_round=true');
	http.onreadystatechange = handleResponsetestid; //Function which handels the response.
	http.send(null);
}
/*

function sendTest(first_id,second_id,t){
	this.nextid = second_id;
	this.td = t;
	var action = first_id.value;
	http.open('get','../templates/ajax.php?tid='+action+'&txt_weight=true');
	http.onreadystatechange = handleResponseTest;
	http.send(null);
}
*/

function sendReq1(firid,secid) 
{
	this.nextid = secid;
	var action=firid.value;
	//alert(action)
	http.open('get','../templates/ajax.php?sid1='+action+'&sel_state=true');
	http.onreadystatechange = handleResponse3; //Function which handels the response.
	http.send(null);
}



function getSpecialize(obj,secondid) 
{
	this.nextid = secondid;
	var action=obj.value;
	//alert(action)
	if(action == 3)
	{
		alert("rey...rey...")
	}
	else
	{
		http.open('get','../templates/ajax.php?eduLevel='+action);
		http.onreadystatechange = handleResponse2; //Function which handels the response.
		http.send(null);
	}
}

function checkBranch(obj,secondid)
{
	this.nextid = secondid;
	var action=obj.value;
	http.open('get','ajax.php?branchCode='+obj.value);	
	http.onreadystatechange = handleResponseBC; //Function which handels the response.
	http.send(null);	
}


function checkEmpCode(obj,secondid)
{
	this.nextid = secondid;
	var action=obj.value;
	//alert(action)
	http.open('get','ajax.php?EmpCode='+obj.value);	
	http.onreadystatechange = handleResponseEMPCD; //Function which handels the response.
	http.send(null);	
}

function getAccess(obj,id)
{
	this.accessId = id;
	var dept=obj.value;
	//alert(dept)
	http.open('get','ajax.php?dept='+dept);
	http.onreadystatechange = handleAccessLevel; //Function which handels the response.
	http.send(null);
	
}


var obj;
var idChk1,idParam1,idWtage1,idMVal1;
function getTestParam(obj,idChk1,idParam1,idWtage1,idMVal1,tabid)
{
	this.idChk1 = document.getElementById(idChk1);
	this.idParam1 = document.getElementById(idParam1);
	this.idWtage1 = document.getElementById(idWtage1);
	this.idMVal1 = document.getElementById(idMVal1);

	http.open('get',"../templates/ajax.php?Test1id="+obj.value);
	http.onreadystatechange = handlegetTestName;
	http.send(null);

}

function handlegetTestName()
{
	if(http.readyState == 4)
	{
		var i;
		var response = http.responseText;
		alert(response)
		var update = new Array();		var abc=new Array();		var testparam=new Array();		
		var value = response.split('*');
		//alert(value.length)
		for(i = 0; i < value.length-1; i++)
		{
			testparam = value[i].split('#');
			//alert(testparam[0])
			var idChk1 = document.getElementById(id_Chk1);
			alert(document.getElementById(id_Chk1))
			var idParam1 = document.getElementById(id_Param1);
			idParam1 =  testparam[0];
			//alert(idParam1)
			//var idWtage1 = document.getElementById(this.id_Wtage1);
			//var idMVal1 = document.getElementById(this.id_MVal1);
			idChk1.innerHTML = "<input type='checkbox' name='txtChk1[i]' size='2' value=''>";//value='"+testParam[0]+"'
			//id_Param1.innerHTML = "<input type='text' name='txtParam1[]' size='2' value='"+testParam[0]+"'>";
			//idWtage1.innerHTML = "<input type='text' name='txtWtage1[]' size='2' value='"+testParam[1]+"'>";
			//idMVal1.innerHTML  = "<input type='text' name='txtMVal1[]' size='2' value='"+testParam[2]+"'>";
	
			//idChk1.title = '';
			//id_Param1.title = testParam[0];		
			//idWtage1.title = testParam[1];		
			//idMVal1.title = testParam[2];		
		}
		//get another selection box element 
		/*	 
		  update = value[1].split('|');		   
			  for(var index=0; index < update.length;index++)
			  {				
				 abc[index]=update[index]
			  }
			
			  var next_selection =document.getElementById(ind.id);			 		  
			  // remove all the previous items in the list box....
			  for (; next_selection.length > 0;  )
			  {
			    	next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     addOption(next_selection,'Select','0');
				 return;
			 }
			  addOption(next_selection,'Select','0');
			  for ( i=0; i<abc.length-1; i+=1)
			  {	
			  	//add all options in the selection box which got from the database....
			      if(abc[i] != "")
				    addOption(next_selection,abc[i],abc[i]);
			  }
		*/
	}
}

function addOption(selectbox,text,value )
{
	var optn = document.createElement("option");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}
/*
function addOptiontext(textbox,value){
	var option = document.
}
*/

//This is for location preference in CV profile(candidate_info.php)
function getLocation(obj,locationid)
{
		var position = obj.value;
		//alert(position.charAt(17))
		
		if(position.charAt(17)=='Y')
		{
			alert("For this POST, Permanant address is mandatory")
		}
		
		
	this.nextid = locationid;
	var action=obj.value;
	//alert(action);
	http.open('get','../templates/ajax.php?locationCode='+obj.value);	
	http.onreadystatechange = handleResponseLOC; //Function which handels the response.
	http.send(null);	
}


function handleResponseLOC()
{
//if it is in ready state...
	if(http.readyState == 4)
	{
		var response = http.responseText;
		//alert(response)
		var update = new Array();		var abc=new Array();
		if(response.indexOf('|' != -1)) 
		{
//			data will come like this  cd#name | cd1#name1 | cd2#name....
			  update = response.split('|');
			  for(var index=0; index < update.length;index++)
			  {
				  update1 =update[index].split('|');
				  if(update1[0] == '')
					  update1 = update;
				   abc[index]=update1[0].split('#');
			  }
			  //get another selection box element 
			  var next_selection =document.getElementById(nextid);
			  // remove all the previous items in the list box....
			  for ( ; next_selection.length > 0 ;  )
			  {
					next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     //addOption(next_selection,'Select','Select');
			     addOption(next_selection,'Nill','');
				 return;
			 }
			  //addOption(next_selection,'Select','Select');
			  for ( i=0; i<abc.length-1; i+=1)
			  {	
			  	//add all options in the selection box which got from the database....
			      if(abc[i][1] != "")
				    addOption(next_selection,abc[i][1],abc[i][0]);
			  }
		  }
	}
}
		
		
		
function handleResponsePA()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		//alert(response)
		var program = new Array();		var activity=new Array();		
		if(response.indexOf('|' != -1)) 
		{
//			data will come like this  cd#name | cd1#name1 | cd2#name....
			  program = response.split('|');
			  for(var index=0; index < program.length;index++)
			  {
				  program1 =program[index].split(',');
				  if(program1[0] == '')
					  program1 = program;
				   activity[index]=program1[0].split('#');
			  }
			  //get another selection box element 
			  var next_selection =document.getElementById(nextid);
			  // remove all the previous items in the list box....
			  for ( ; next_selection.length > 0 ;  )
			  {
					next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     addOption(next_selection,'Select','Select');
				 return;
			 }
			  addOption(next_selection,'Select','Select');
			  for ( i=0; i<activity.length-1; i+=1)
			  {	
			  	//add all options in the selection box which got from the database....
			      if(activity[i][1] != "")
				    addOption(next_selection,activity[i][1],activity[i][0]);
			  }
		  }
	}
}
function handleResponseAE()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		var events = new Array();		var activity=new Array();		
		if(response.indexOf('|' != -1)) 
		{
//			data will come like this  cd#name | cd1#name1 | cd2#name....
			  activity = response.split('|');
			  for(var index=0; index < activity.length;index++)
			  {
				  activity1 =activity[index].split(',');
				  if(activity1[0] == '')
					  activity1 = activity;
				   events[index]=activity1[0].split('#');
			  }
			  //get another selection box element 
			  var next_selection =document.getElementById(nextid);
			  // remove all the previous items in the list box....
			  for ( ; next_selection.length > 0 ;  )
			  {
					next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     addOption(next_selection,'Select','Select');
				 return;
			 }
			  addOption(next_selection,'Select','Select');
			  for ( i=0; i<events.length-1; i+=1)
			  {	
			  	//add all options in the selection box which got from the database....
			      if(events[i][1] != "")
				    addOption(next_selection,events[i][1],events[i][0]);
			  }
		  }
	}
}

function handleResponse2() {
//if it is in ready state...
	if(http.readyState == 4)
	{	
		var response = http.responseText;
		//alert(response);
		var update = new Array();		var abc=new Array();
		if(response.indexOf('|' != -1)) 
		{
//			data will come like this  cd#name | cd1#name1 | cd2#name....
			  update = response.split('|');
			  for(var index=0; index < update.length;index++)
			  {
				  update1 =update[index].split(',');
				  if(update1[0] == '')
					  update1 = update;
				   abc[index]=update1[0].split('#');
			  }
			  //get another selection box element 
			  var next_selection =document.getElementById(nextid);
			  // remove all the previous items in the list box....
			  for ( ; next_selection.length > 0 ;  )
			  {
					next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     addOption(next_selection,'Select','Select');
				 return;
			 }
			  addOption(next_selection,'Select','Select');
			  for ( i=0; i<abc.length-1; i+=1)
			  {	
			  	//add all options in the selection box which got from the database....
			      if(abc[i][1] != "")
				    addOption(next_selection,abc[i][1],abc[i][0]);
			  }
		  }
	}
}

function handleResponse5() {
//if it is in ready state...
	if(http.readyState == 4)
	{
		var response = http.responseText;
		//alert(response)
		var update = new Array();		var abc=new Array();
		if(response.indexOf('|' != -1)) 
		{
//			data will come like this  cd#name | cd1#name1 | cd2#name....
			  update = response.split('|');
			  for(var index=0; index < update.length;index++)
			  {
				  update1 =update[index].split(',');
				  if(update1[0] == '')
					  update1 = update;
				   abc[index]=update1[0].split('#');
			  }
			  //get another selection box element 
			  var next_selection =document.getElementById(nextid);
			  // remove all the previous items in the list box....
			  for ( ; next_selection.length > 0 ;  )
			  {
					next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     addOption(next_selection,'All','All');
				 return;
			 }
			  addOption(next_selection,'All','All');
			  for ( i=0; i<abc.length-1; i+=1)
			  {	
			  	//add all options in the selection box which got from the database....
			      if(abc[i][1] != "")
				    addOption(next_selection,abc[i][1],abc[i][0]);
			  }
		  }
	}
}
/*
function handleResponse12() {
//if it is in ready state...
	if(http.readyState == 4)
	{	alert(http.responseText);
		var response = http.responseText;
		alert(response);
		var update = new Array();		var abc=new Array();
		if(response.indexOf('|' != -1)) 
		{
//			data will come like this  cd#name | cd1#name1 | cd2#name....
			  update = response.split('|');
			  for(var index=0; index < update.length;index++)
			  {
				  update1 =update[index].split(',');
				  if(update1[0] == '')
					  update1 = update;
				   abc[index]=update1[0].split('#');
			  }
			  //get another selection box element 
			  var next_selection =document.getElementById(nextid);
			  // remove all the previous items in the list box....
			  for ( ; next_selection.length > 0 ;  )
			  {
					next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     addOption(next_selection,'Select','Select');
				 return;
			 }
			  addOption(next_selection,'Select','Select');
			  for ( i=0; i<abc.length-1; i+=1)
			  {	
			  	//add all options in the selection box which got from the database....
			      if(abc[i][1] != "")
				    addOption(next_selection,abc[i][1],abc[i][0]);
			  }
		  }
	}
}
*/
/*
function handleResponsetestid() {
//if it is in ready state...
	if(http.readyState == 4)
	{
		var response = http.responseText;
		//alert(response)
		var update = new Array();		var abc=new Array();
		if(response.indexOf('|' != -1)) 
		{
//			data will come like this  cd#name | cd1#name1 | cd2#name....
			  update = response.split('|');
			  for(var index=0; index < update.length;index++)
			  {
				  update1 =update[index].split(',');
				  if(update1[0] == '')
					  update1 = update;
				   abc[index]=update1[0].split('#');
			  }
			  //get another selection box element 
			  var next_selection =document.getElementById(this.nextid);
			  // remove all the previous items in the list box....
			  for ( ; next_selection.length > 0 ;  )
			  {
					next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     addOption(next_selection,'Select','Select');
				 return;
			 }
			  addOption(next_selection,'Select','Select');
			  for ( i=0; i<abc.length-1; i+=1)
			  {	
			  	//add all options in the selection box which got from the database....
			      if(abc[i][1] != "")
				    addOption(next_selection,abc[i][1],abc[i][0]);
			  }
		  }
	}
}



function handleResponseTest(){
	if(http.readyState == 4){
		var response = http.responseText;
		alert(response);
		var zone = new Array();
		var zone1 = new Array();
		var i=0;
		var wgtage = response.split('-');
		alert(wgtage);
		zone = wgtage[1].split('|');
		alert(zone);
		for(i=0;i < zone.length;i++)
		{
			//alert(zone)
			zone1 = zone[i].split('#');
			
			var next =document.getElementById(this.td[i]);
		//next.innerHTML = "<td><input type='text' name='text[i]' size='2' value=''></td>";
		next.innerHTML = "<td><input type='text' name='txt_zone[$i]' id='id_zone[i]' value='' size = '9'></td>";
		}
		alert(zone1);
		
		//var next_selection =document.getElementById(this.nextid);
		//idChk1.innerHTML = "<input type='checkbox' name='txtChk1[i]' size='2' value=''>";
		//var next_norm = document.getElementById(this.third_id);
		//var next_zone = document.getElementById(this.fourth_id);
		//alert(update[0]);
		 //   return;
		//}
	}
}*/
//function for getting values location map table
function handleResponse3() {
//if it is in ready state...
	if(http.readyState == 4){
		var response = http.responseText;
		//alert(response)
		var update = new Array();		var abc=new Array();
		if(response.indexOf('|' != -1))	{
//			data will come like this  cd#name | cd1#name1 | cd2#name....
			  update = response.split('|');
			  for(var index=0; index < update.length;index++)  {
				  update1 =update[index].split(',');
				  if(update1[0] == '')
					  update1 = update;
				   abc[index]=update1[0].split('#');
			  }
			  //get another selection box element 
			  var next_selection =document.getElementById(nextid);
			  // remove all the previous items in the list box....
			  for ( ; next_selection.length > 0 ;  ){
					next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     addOption(next_selection,'Select','Select');
				 return;
			 }
			  addOption(next_selection,'Select','Select');
			  for ( i=0; i<abc.length-1; i+=1)
			  {	
			  	//add all options in the selection box which got from the database....
			      if(abc[i][1] != "")
				    addOption(next_selection,abc[i][1],abc[i][0]);
			  }
		  }
	}
}



//this is for getting the accesslevels
function handleAccessLevel() {
//if it is in ready state...
	if(http.readyState == 4)
	{
		var response = http.responseText;
		//alert(response)
		var update = new Array();		var abc=new Array();
		if(response.indexOf('|' != -1)) 
		{
//			data will come like this  cd#name | cd1#name1 | cd2#name....
			  update = response.split('|');
			  for(var index=0; index < update.length;index++)
			  {
				  update1 =update[index].split(',');
				  if(update1[0] == '')
					  update1 = update;
				   abc[index]=update1[0].split('#');
			  }
			  //get another selection box element 
			  var next_selection =document.getElementById(this.accessId);
			  // remove all the previous items in the list box....
			  for (; next_selection.length > 0 ; )
			  {
					next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     addOption(next_selection,'Select','Select');
				 return;
			 }
			  addOption(next_selection,'Select','Select');
			  for ( i=0; i<abc.length-1; i+=1)
			  {	
			  	//add all options in the selection box which got from the database....
			      if(abc[i][1] != "")
				    addOption(next_selection,abc[i][1],abc[i][0]);
			  }
		  }
	}
}

//This is for branch screen
function handleResponseBC()
{
//if it is in ready state...
	if(http.readyState == 4)
	{
		var response = http.responseText;
		var did=document.getElementById("idMsg");
		var bcd=document.getElementById("idBcode");
		//alert(bcd)
		if(parseInt(response) > 0 )
		{	did.innerHTML="Branch code already exist";
			bcd.value='';
			bcd.focus();
		}
		else
		{
			did.innerHTML="";
		}
	}
}

//This is for staff screen
function handleResponseEMPCD()
{
//if it is in ready state...
	if(http.readyState == 4)
	{
		var response = http.responseText;
		var did=document.getElementById("idMsg");
		var bcd=document.getElementById("idEmpcd");
		if(parseInt(response) > 0 )
		{	did.innerHTML="Employee code already exist";
			bcd.value='';
			bcd.focus();
		}
		else
		{
			did.innerHTML="";
		}
	}
}

