﻿// JScript File


        // General Functions - To be moved to utils.js
    
        function createCookie(name,value,days)
        {
	        if (days)
	        {
		        var date = new Date();
		        date.setTime(date.getTime()+(days*24*60*60*1000));
		        var expires = "; expires="+date.toGMTString();
	        }
	        else var expires = "";
	        document.cookie = name+"="+value+expires+"; path=/";
        }

        function readCookie(name)
        {
	        var nameEQ = name + "=";
	        var ca = document.cookie.split(';');
	        for(var i=0;i < ca.length;i++)
	        {
		        var c = ca[i];
		        while (c.charAt(0)==' ') c = c.substring(1,c.length);
		        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	        }
	        return null;
        }
        
        function eraseCookie(name)
        {
	        createCookie(name,"",-1);
        }

    function myEncode(source, sp)
    {
        if (source == null)
        {
            return null;
        }
        var target = "";
        for (i = 0; i < source.length; i++)
        {
            var c = source.charCodeAt(i);
            target += (sp == null ? "%" : sp)  + c;
        }
        return target;
    }
    function myDecode(source, sp)
    {
        if (source == null)
        {
            return null;
        }
        try
        {
            var t = source.split(sp == null ? "%" : sp);
            var target = "";
            for (i = 0; i < t.length; i++)
            {
                //alert(t[i]);
                if (t[i].length > 0)
                {
                    target += String.fromCharCode(Number(t[i]));
                }
            }
            return target;
        }
        catch (e)
        {
            return null;
        }
    }
 
 
        function getXmlHttp(verb, address, data, func, id, finicallback, contenttype)
        {
            var xmlhttp=false;
            /*@cc_on @*/
            /*@if (@_jscript_version >= 5)
            // JScript gives us Conditional compilation, we can cope with old IE versions.
            // and security blocked creation of the objects.
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                try
                {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (E)
                {
                    xmlhttp = false;
                }
            }
            @end @*/
            if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	            try {
		            xmlhttp = new XMLHttpRequest();
	            } catch (e) {
		            xmlhttp=false;
	            }
            }
            if (!xmlhttp && window.createRequest) {
	            try {   
		            xmlhttp = window.createRequest();
	            } catch (e) {
		            xmlhttp=false;
	            }
            }
            xmlhttp.onreadystatechange=function()
            {
                if (func != null)
                {
                    if (id == null)
                    {
                        func(xmlhttp);
                    }
                    else 
                    {
                        func(xmlhttp, id, finicallback);
                    }
                }
            }
            xmlhttp.open(verb, ROOTDIR + address,true);
            xmlhttp.setRequestHeader('Content-Type', contenttype == null ? 'application/x-www-form-urlencoded' : contenttype); 
            xmlhttp.setRequestHeader('Content-Length',  null == data ? '0' : data.length); 
            xmlhttp.send(data);
            //alert(data);
            
            return xmlhttp;
        }

        function loadxml(text)
        {
            var xmlDoc;
            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)}
            }
            return xmlDoc;
        }
 
        function showDiv(name)
        {
            document.getElementById(name).style.display = "block";
        }
        
        function hideDiv(name)
        {
            document.getElementById(name).style.display = "none";
        }
        
    function querySt(ji)
    {
        hu = window.location.search.substring(1);
        gy = hu.split("&");
        for (i=0;i<gy.length;i++)
        {
            ft = gy[i].split("=");
            if (ft[0] == ji)
            {
                return ft[1];
            }
        }
        return null;
    } 
    
