function ajaxPost(strMethod, strURL, strQuery) {
	if (strURL == '' || typeof(strURL)=='undefined')
		strURL='/Magic94Scripts/mgrqispi94.dll';

	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open(strMethod, strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4 ) {
			updatepage(self.xmlHttpReq);
        }
    }	
    self.xmlHttpReq.send(strQuery);
}

function ajaxSend(strQuery) {
	var strURL='/Magic94Scripts/mgrqispi94.dll';
	var strMethod = 'POST'

	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open(strMethod, strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() { return true; }	
    self.xmlHttpReq.send(strQuery);
}


function updatepage(strResponse){
	var XMLData = strResponse.responseXML.getElementsByTagName('divdata');
	var JSData = strResponse.responseXML.getElementsByTagName('parse');
	for (var x=0; x<XMLData.length; x++){
		var divid = XMLData[x].attributes.getNamedItem('divname').value;
		if (document.getElementById(divid)){
			if (navigator.appName == 'Microsoft Internet Explorer'){
				document.getElementById(divid).innerHTML = XMLData[x].firstChild.nodeValue;
			} else {
				document.getElementById(divid).innerHTML = XMLData[x].childNodes[1].nodeValue;
			}
		} else {
//			logError(5,'Data did not belong: '+divid);
		}
	}

	if (navigator.appName == 'Microsoft Internet Explorer'){
		for (var x=0; x<JSData.length; x++){
			eval(JSData[x].firstChild.nodeValue)
		}
	} else {
		for (var x=0; x<JSData.length; x++){
			eval(JSData[x].childNodes[1].nodeValue)
		}
	}

	fixPNG();
	try{ datePickerController.create(); } catch(e) { };

}

function getNodeValue(obj,tag){
	return (obj.getElementsByTagName(tag)[0].firstChild.nodeValue);
}

function create_request_string(theForm){
	var reqStr = "";
	
	for(i=0; i < theForm.elements.length; i++)	{
		isFormObject = false;
		switch (theForm.elements[i].tagName){
			case "INPUT":
			case "input":
				switch (theForm.elements[i].type){
					case "text":
					case "hidden":
					case "password":
						reqStr += theForm.elements[i].name + "=" + encodeURIComponent(theForm.elements[i].value);
						isFormObject = true;
						break;
				
					case "checkbox":
						if (theForm.elements[i].checked){
							reqStr += theForm.elements[i].name + "=" + encodeURIComponent(theForm.elements[i].value);
						}else{
							reqStr += theForm.elements[i].name + "=";
						}
						isFormObject = true;
						break;
					
					case "radio":
					if (theForm.elements[i].checked){
						reqStr += theForm.elements[i].name + "=" + encodeURIComponent(theForm.elements[i].value);
						isFormObject = true;
					}
				}
				break;
				
				case "TEXTAREA":
					reqStr += theForm.elements[i].name + "=" + encodeURIComponent(theForm.elements[i].value);
					isFormObject = true;
					break;
				
				case "SELECT":
					var sel = theForm.elements[i];
					reqStr += sel.name + "=" + encodeURIComponent(sel.options[sel.selectedIndex].value);
					isFormObject = true;
					break;
			}
	
		if ((isFormObject) && ((i+1)!= theForm.elements.length))
			reqStr += "&";
	}

	return reqStr;
} 

function ajaxPopUp(strMethod, strURL, strQuery, nobackground, inviewport, specialdivname, wide) {
	if (strURL == '' || typeof(strURL)=='undefined')
		strURL='/Magic94Scripts/mgrqispi94.dll';
	
	if (!nobackground)
		fadePurple(specialdivname);
		
//	showLoader();
		
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open(strMethod, strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            if(!wide)
				showPopup(self.xmlHttpReq.responseText, nobackground, inviewport, specialdivname);
			else
				showWidePopup(self.xmlHttpReq.responseText, nobackground, inviewport, specialdivname);			
			
			try{ datePickerController.create(); } catch(e) { };
        }
    }
    self.xmlHttpReq.send(strQuery);
}

function hideLoader(){
	if (document.getElementById('loaderdiv'))
		document.body.removeChild(document.getElementById('loaderdiv'))
}


function showMessage(message, needsconfirm){
	var DivRandNo = Math.floor(Math.random()*11);
	var messagediv = document.createElement('div');
	var divIdName = 'message_'+DivRandNo;
	
	messagediv.setAttribute('id',divIdName);
	messagediv.style.visibility = "hidden";

	document.body.appendChild(messagediv);

	if (navigator.appName == 'Microsoft Internet Explorer'){
		var p = document.getElementsByTagName('select');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "hidden";
		}
		
		p = document.getElementsByTagName('object');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "hidden";
			p[i].style.width = "0px";
		}
	} else {
		p = document.getElementsByTagName('embed');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "hidden";
			p[i].style.width = "0px";
		}
	}

	messagetoshow = message.replace(/x1x/g,"'"+divIdName+"'")
	messagediv.innerHTML = messagetoshow;

	messagediv.style.visibility = 'visible';
	fixPNG();
	
	var scriptelements = messagediv.getElementsByTagName('script');
	for (i =0;i<scriptelements.length;i++)
		eval(scriptelements[i].innerHTML);
	
	var inputs = messagediv.getElementsByTagName('input');
//	inputs[0].focus();

	if (needsconfirm == false){
		setTimeout('hideMessage("'+divIdName+'")',5000)
	}
}

function hideMessage(DivID){
	if(document.getElementById(DivID))
		document.body.removeChild(document.getElementById(DivID));

	if (navigator.appName == 'Microsoft Internet Explorer'){
		var p = document.getElementsByTagName('select');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "visible";
		}
		
		p = document.getElementsByTagName('object');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "visible";
			p[i].style.width = "";
		}
	} else {
		p = document.getElementsByTagName('embed');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "visible";
			p[i].style.width = "";
		}
	}
}

function fixPNG(){

	var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])
	
		if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	
	
		{
		   for(var i=0; i<document.images.length; i++)
		   {
			  var img = document.images[i]
			  var imgName = img.src.toUpperCase()
			  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			  {
				 var imgID = (img.id) ? "id='" + img.id + "' " : ""
				 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				 var imgStyle = "display:inline-block;" + img.style.cssText 
				 if (img.align == "left") imgStyle = "float:left;" + imgStyle
				 if (img.align == "right") imgStyle = "float:right;" + imgStyle
				 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				 var strNewHTML = "<span " + imgID + imgClass + imgTitle
				 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				 img.outerHTML = strNewHTML
				 i = i-1
			  }
		   }
		}

}
