var FocusName;
var ajax_moudle;
var xmlHttp;
var xmlHttp2;
var xmlHttp3;
/**
This sets up the XMLHTTP object we're using for the dynamic lookups.
*/
function getXMLHTTP(){
	var A = null;
	try{
		A = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			A = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(oc){
			A = null;
		}
	}
	if(!A && typeof XMLHttpRequest != "undefined") {
		A = new XMLHttpRequest();
	}
	return A;
}


///////the following is some functions that are defined by user 

function makeRequest(url) {
	xmlHttp3 = getXMLHTTP();
	if (!xmlHttp3) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	xmlHttp3.onreadystatechange = alertContents;
	xmlHttp3.open('get', url, true);
	xmlHttp3.send(null);
}

function alertContents() {
	if (xmlHttp3.readyState == 4) {
		if (xmlHttp3.status == 200) {
			var s = xmlHttp3.responseText.split(/<!-- AJAX-EVAL/i);
			if (typeof(s[1]) != "undefined") {
				document.getElementById("show_content").innerHTML = s[0];
				eval(s[1]);
				setTimeout("takeBackValue()",1);
			} else {
				document.getElementById("show_content").innerHTML = xmlHttp3.responseText;
			}
			keepstaus();
			if(ajax_moudle == "timesheet"){
				//modified by jack 
				//kim modified use getElementsByName 20080703
				//kim modified fixed the bug:If we use autosave mode in the timesheet and we move the cursor from one field to  another field the value the second field loses his the cursor 20080811
				focus_value = document.getElementById("focus_name").value;
				if(focus_value!=''){
					//alert(document.getElementById("focus_name").value);
					//document.getElementById(focus_value).focus();
					setTimeout("document.getElementById(focus_value).focus()",1);
				}
			}
			setTimeout("ontop()",100);
		} else { 
			alert('There was a problem with the request.');
		}
	}
}


//first ---------------------------------------------------------
function executeQuery (objspanname,objoption,urlString,sqlstr,selectedvalue){
	xmlHttp=getXMLHTTP();
	if(xmlHttp){
		urlString = urlString + "?sqlstr=" + sqlstr + "&objspanname=" + objspanname + "&objoption=" + objoption + "&selectedvalue="+selectedvalue+"&" + new Date().getTime();
		xmlHttp.open("GET", urlString , true);
		xmlHttp.onreadystatechange = getreturntext;
		xmlHttp.send(null);
	}
}

function getreturntext(){
	if(typeof(xmlHttp)!="undefined")//edit by kim 20080303   
   {
		if (xmlHttp.readyState == 4 && xmlHttp.responseText) {
			eval(xmlHttp.responseText);
		}
   }
}

//second ---------------------------------------------------------
function executeQuery2 (objspanname,objoption,urlString,sqlstr,selectedvalue){
	xmlHttp2 = getXMLHTTP();
	if(xmlHttp2){
		urlString = urlString + "?sqlstr=" + sqlstr + "&objspanname=" + objspanname + "&objoption=" + objoption + "&selectedvalue="+selectedvalue+"&" + new Date().getTime();
		xmlHttp2.open("GET", urlString , true);
		xmlHttp2.onreadystatechange = getreturntext2;
		xmlHttp2.send(null);
	}
}

function getreturntext2(){
	if(typeof(xmlHttp)!="undefined")//edit by kim 20080303   
	{
		if (xmlHttp2.readyState == 4 && xmlHttp2.responseText) {
			eval(xmlHttp2.responseText);
		}
	}
}

function createoption(objspanname,selectname,valuestr,captionstr,selectedvalue){
	var valuearray = valuestr.split(",");
	var captionarray = captionstr.split(",");
	var droplist = '';
	droplist += selectname;
	if(typeof(show_only) == "undefined"){	
		droplist += '<option value="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
	}
	if(valuestr != ""){
		for(var i=0;i<valuearray.length;i++){
			if(selectedvalue == valuearray[i]){
				droplist += '<option value="' + valuearray[i] + '" selected>' + captionarray[i] + '</option>';
			}else{
				droplist += '<option value="' + valuearray[i] + '">' + captionarray[i] + '</option>';
			}
		}
	}
	droplist += '</select>';
	var myspanobj=document.getElementById(objspanname);
	myspanobj.innerHTML = droplist;
}
//---------------------------------------------------------

