﻿var isIE = false;
var isFF = false;


if (navigator.userAgent.indexOf(' MSIE ') > -1 && !(navigator.userAgent.indexOf(' MSIE 8.0') > -1)) {
    isIE = true;
}
else if (navigator.userAgent.indexOf(' Firefox/') > -1) {
    isFF = true
}
else if (navigator.userAgent.indexOf(' Safari/') > -1) {
isFF = true
}
else if (navigator.userAgent.indexOf('Opera/') > -1) {
isFF = true

}


var browserWindowWidth,browserWindowHeight;
function getXMLDoc(str){
    try //Internet Explorer
      {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async="false";
      xmlDoc.loadXML(text);
      }
    catch(e)
      {
      try //Firefox, Mozilla, Opera, etc.
        {
        parser=new DOMParser();
        xmlDoc=parser.parseFromString(text,"text/xml");
        }
      catch(e) {alert(e.message)}
      }
}


function handleSayHello() {
	if (receiveReq.readyState == 4) {
		
	}
}

function CalcWindowDimensions(){    
    if(typeof window.innerWidth!="undefined") 
    {
	    browserWindowWidth = window.innerWidth;
	    browserWindowHeight = window.innerHeight;
    }
    else if (typeof document.documentElement.offsetWidth != "undefined") 
    {
	    browserWindowWidth = document.documentElement.offsetWidth;
	    browserWindowHeight = document.documentElement.offsetHeight;
    }
    else 
    {
	    browserWindowWidth = document.body.offsetWidth;
	    browserWindowHeight = document.body.offsetHeight;
    }  
}


function showModalMessage(message) {    
    var overlayDiv = document.getElementById("overlayDiv");
    CalcWindowDimensions();     
    overlayDiv.style.top = Math.round(browserWindowHeight * 0.65) + 'px';    
    overlayDiv.style.left = Math.round(browserWindowWidth * 0.38) + 'px';    
    
    //alert(overlayDiv.style.top);
    //alert(browserWindowHeight);
    
    document.getElementById('templateDiv').innerHTML = "<table border='0' cellspacing='0' cellpadding='0' class='loadingTable' id='modalMessage'><tr><td><center><p id='msg'>" + message + "</p><p class='loadingImg' id='loadingImg'><img src='Images\/loading.gif' /></p></center></td></tr></table>";
    el = document.getElementById("overlay");
    el.style.visibility = "visible";
    window.focus();
}

function closeModalWindow(){
    el = document.getElementById("overlay");
    el.style.visibility = "hidden";
}

function getValue(val){
    if ((val == null) || (val == ''))
        return  "\u00a0"; // = &nbsp;
        
    return val;
}


 //Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
    if (isFF) {
        return new XMLHttpRequest(); //Not IE
    } else if(window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP"); //IE
    } else {
        //Display your error message here. 
        //and inform the user they might want to upgrade
        //their browser.
        alert("Your browser doesn't support the XmlHttpRequest object.  Better upgrade to Firefox.");
    }
}			

//Get our browser specific XmlHttpRequest object.
var receiveReq = getXmlHttpRequestObject();		


function callServer(act,res,prm1,prm2,prm3,prm4) {            
    
    //If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
    if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
        //Setup the connection as a GET call to SayHello.html.
        //True explicity sets the request to asyncronous (default).
        receiveReq.open("GET", 'AjaxHandler.ashx?act=' + act + "&p1=" + prm1 + "&p2=" + prm2 + "&p3=" + prm3 + "&p4=" + prm4 , true);
        //Set the function that will be called when the XmlHttpRequest objects state changes.
        receiveReq.onreadystatechange = res; 
        //Make the actual request.		       
        receiveReq.send(null);
    }			
}