﻿// JScript File
var xmlHttp;
var xmlHttp2;
var xmlHttp3;

var ctrObject ='';
var ctrObject2 ='';
var ctrObject3 ='';

function showData(path,query,value,objectcontrol)
{
    
   xmlHttp=GetXmlHttpObject();
   ctrObject=objectcontrol;
    
    if(xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    else
    {
        var url='';
        if((query!='') && (value!=''))
        {
            var arrquery=query.split(';');
            var arrvalue=value.split(';');
            
            for(var i=0;i<arrquery.length;i++)
            {
                url+=arrquery[i]+'='+arrvalue[i]+'&';
            }
            url=url.substring(0,url.lastIndexOf('&'));
            url=path+'?'+url;
         }
         else
         {
            url=path;
         }
        //alert(url);
        xmlHttp.onreadystatechange=stateChanged;
        xmlHttp.open("POST",url,true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", ctrObject.length);
        xmlHttp.send(url);
    }
}

function showData2(path,querystring,objectcontrol)
{
    xmlHttp2=GetXmlHttpObject();
    ctrObject2=objectcontrol;
    
    if(xmlHttp2==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    else
    {
        var url='';
        if(querystring!='')
        {
            
           url=path+'?'+querystring;
        }
        else
        {
           url=path;
        }
         
        //alert(url);
        xmlHttp2.onreadystatechange=stateChanged2;
        xmlHttp2.open("POST",url,true);
        xmlHttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp2.setRequestHeader("Content-length", ctrObject2.length);
        xmlHttp2.send(url);
    }
}

function showData3(path,objectcontrol)
{
    xmlHttp3=GetXmlHttpObject();
    ctrObject3=objectcontrol;
    
    if(xmlHttp3==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    else
    {
        var url='';
        url=path;
        //alert(url);
        xmlHttp3.onreadystatechange=stateChanged3;
        xmlHttp3.open("POST",url,true);
        xmlHttp3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp3.setRequestHeader("Content-length", ctrObject3.length);
        xmlHttp3.send(url);
    }
}

function stateChanged()
{
    document.getElementById(ctrObject).innerHTML='<img src="images/loading.gif" /> loading...';
   try
   {
        if (xmlHttp.readyState==4)
        { 
             if (xmlHttp.status==200)
             {
                document.getElementById(ctrObject).innerHTML = xmlHttp.responseText;
                //includeHTML(document.getElementById(ctrObject), xmlHttp.responseText);
             }
        }
    }
    catch(e)
    {
        alert(e.message)
    }
}

function stateChanged2()
{
    document.getElementById(ctrObject2).innerHTML='<img src="images/loading.gif" /> loading...';
   try
   {
        if (xmlHttp2.readyState==4)
        { 
             if (xmlHttp2.status==200)
             {
                document.getElementById(ctrObject2).innerHTML = xmlHttp2.responseText;
                //includeHTML(document.getElementById(ctrObject), xmlHttp.responseText);
             }
        }
    }
    catch(e)
    {
        alert(e.message)
    }
}

function stateChanged3()
{
    document.getElementById(ctrObject3).innerHTML='<img src="images/loading.gif" /> loading...';
   try
   {
        if (xmlHttp3.readyState==4)
        { 
             if (xmlHttp3.status==200)
             {
                document.getElementById(ctrObject3).innerHTML = xmlHttp3.responseText;
                //includeHTML(document.getElementById(ctrObject), xmlHttp.responseText);
             }
        }
    }
    catch(e)
    {
        alert(e.message)
    }
}

function includeHTML(component, html) {
	if (typeof(component) != 'object' || typeof(html) != 'string')
		return;

	component.innerHTML += html;
    //alert(component.innerHTML);
	var scripts = component.getElementsByTagName('script');
	if (!scripts) return;
	// load scripts
	for (var i = 0; i < scripts.length; i++) {
		var scriptclone = document.createElement('script');
		if (scripts[i].attributes.length > 0) {
			for (var j in scripts[i].attributes) {
				if (typeof(scripts[i].attributes[j]) != 'undefined'
				    && typeof(scripts[i].attributes[j].nodeName) != 'undefined'
				    && scripts[i].attributes[j].nodeValue != null
				    && scripts[i].attributes[j].nodeValue != '') {
					    scriptclone.setAttribute(scripts[i].attributes[j].nodeName, scripts[i].attributes[j].nodeValue);
				}
			}
		}
		scriptclone.text = scripts[i].text;
		scripts[i].parentNode.replaceChild(scriptclone, scripts[i]);
		eval(scripts[i].innerHTML);
	}
}


function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch(e)
    {
            // Internet Explorer
          try
          {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
    }
    
    return xmlHttp;
}


