﻿function UtilsClass() {
    
    //BROWSER
    this.IsBrowserNetscape = (window.navigator.appName.toLowerCase().indexOf("netscape") > -1);
    this.IsBrowserIE = (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1);
    
    //STRING COLLECTIONS && ARRAYS
    this.Contains = Contains;
    this.ContainsNoCase = ContainsNoCase;
    this.Replace = Replace;
    this.ReplaceUpper = ReplaceUpper;
    this.ReplaceStringOnce = ReplaceStringOnce;
    this.ReplaceOnceUpper = ReplaceOnceUpper;
    this.ReplaceOnceNoCase = ReplaceOnceNoCase;
    this.ReplaceStringOnceNoCase = ReplaceStringOnceNoCase;
    this.DeleteString = DeleteString;
    this.DeleteStringNoCase = DeleteStringNoCase;
    this.DeleteStringOnce = DeleteStringOnce;
    this.DeleteOnceUpper = DeleteOnceUpper;
    this.DeleteStringOnceNoCase = DeleteStringOnceNoCase;
    this.ClearCollection = ClearCollection;
    this.Split = Split;
    this.SplitAll = SplitAll;
    this.SplitNoEmpty = SplitNoEmpty;
    this.Split = Split;
    this.Trim = Trim;
    this.TrimLeading = TrimLeading;
    this.IsEmptyTrim = IsEmptyTrim;
    this.NotEmptyTrim = NotEmptyTrim;

    //DATE TIME
    this.GetTimezoneOffset;

    //IMAGES
    this.ScaleImageSize;    

    // URL && FORMS
    this.documentAll = documentAll;
    this.GetSafeHtml = Utils_GetSafeHtml;
    this.GetRootURL = GetRootURL;
    this.GetDomainRootURL = Utils_GetDomainRootURL;
    this.GetUrlArguments = GetUrlArguments;
    this.GetUrlArgumentValue = GetUrlArgumentValue;
    this.OpenfullScreenWithStatus;
    this.RemoveAllChildren = RemoveAllChildren;
    this.DisplayCurrentHTML = DisplayCurrentHTML;
    this.GetFormField = GetFormField;
    this.GetFormFields = GetFormFields;
    this.GetRandomURLAttribute = GetRandomURLAttribute;
    this.GetAbsoluteTop = GetAbsoluteTop;
    this.GetAbsoluteLeft = GetAbsoluteLeft;
    this.GetSreenResolutionHeight = Utils_GetSreenResolutionHeight;
    this.GetSreenResolutionWidth = Utils_GetSreenResolutionWidth;
    this.GetRightBorderWidth = GetRightBorderWidth;
    this.FindChild = FindChild;
    this.ShowDiv = ShowDiv;
    this.HideDiv = HideDiv;
    this.Hide = Utils_Hide;
    this.Show = Utils_Show;
    this.HideShow = Utils_HideShow;
    this.ShowHide = Utils_ShowHide;
    this.PxToInt = PxToInt;
    this.SubmitForm = Utils_SubmitForm;
    this.HidePageScrollbars = HidePageScrollbars;
    this.MaxWindow = maxWindow;  //Resize Window up on Entry
    this.OpenFullSreenWindow = OpenFullSreenWindow; //Theater Mode

    //Effects
    this.Highlight = Highlight;
   

    //VALIDATION && FORMATS  
    this.HasIllegalCharacters = HasIllegalCharacters;
    this.IsValidInt = IsValidInt;
    this.FormatDecimal = FormatDecimal;    
    this.ToFloat = Utils_ToFloat;    


    //AJAX
    this.CreateHttpRequest;
    this.SendRequestAsyn;
    this.SendRequest;
    this.StateChanged;


    //Timer
    this.Delay = Delay;

    //Cookie
    this.CreateCookie = CreateCookie;
    this.EraseCookie = EraseCookie;
    this.ReadCookie = ReadCookie;
    this.ListCookies = ListCookies; //Only for your domain.

    
}

var Utils = new UtilsClass();


function Contains(s, match) {
    try {
        if (s != null) {
            return (s.indexOf(match) >= 0);
        } else {
            return false;
        }

    }
    catch (e) { return false; }
}

function ContainsNoCase(s, match) {
    if (s != null) {
        return (s.toUpperCase().indexOf(match.toUpperCase()) >= 0);
    } else
        return false;
}

function ReplaceStringOnce(s, source, dest) {
    if (s != null) {
        var iPos = s.indexOf(source);
        if (iPos >= 0)
            return s.substring(0, iPos) + dest + s.substring(iPos + source.length, s.length);
    }
    return s;
}
function ReplaceStringOnceNoCase(s, source, dest) {
    if (s != null && source) {
        var sUpper = s.toUpperCase();
        var iPos = sUpper.indexOf(source.toUpperCase());
        if (iPos >= 0)
            return s.substring(0, iPos) + dest + s.substring(iPos + source.length, s.length);
    }
    return s;
}

function ReplaceOnceUpper(s, source, dest) {
    return ReplaceStringOnce(s.toUpperCase(), source.toUpperCase(), dest.toUpperCase());
}

function ReplaceOnceNoCase(s, source, dest) {
    return ReplaceStringOnceNoCase(s, source, dest);
}

function DeleteString(s, match) {
    if (s && match != null) {
        var result = "";
        var iPrev = 0;
        var iLength = match.length;
        var iPos = s.indexOf(match, iPrev);
        while (iPos >= 0) {
            result += s.substring(iPrev, iPos);
            iPrev = iPos + iLength;
            iPos = s.indexOf(match, iPrev);
        }
        if (iPrev < s.length)
            result += s.substring(iPrev, s.length);
        return result;
    } else
        return s;
}

function DeleteStringNoCase(s, match) {
    if (s && match != null) {
        var sUpper = s.toUpperCase();
        var matchUpper = match.toUpperCase();
        var result = "";
        var iPrev = 0;
        var iLength = match.length;
        var iPos = sUpper.indexOf(matchUpper, iPrev);
        while (iPos >= 0) {
            result += s.substring(iPrev, iPos);
            iPrev = iPos + iLength;
            iPos = sUpper.indexOf(matchUpper, iPrev);
        }
        if (iPrev < s.length)
            result += s.substring(iPrev, s.length);
        return result;
    } else
        return s;
}

function DeleteStringOnce(s, match) {
    var i1 = s.indexOf(match);
    if (i1 >= 0)
        return s.substring(0, i1) + s.substring(i1 + match.length, s.length);
    else
        return s;
}

function DeleteStringOnceNoCase(s, match) {
    var sUpper = s.toUpperCase();
    var i1 = sUpper.indexOf(match.toUpperCase());
    if (i1 >= 0)
        return s.substring(0, i1) + s.substring(i1 + match.length, s.length);
    else
        return s;
}

function DeleteOnceUpper(s, match) {
    return DeleteStringOnce(s.toUpperCase(), match.toUpperCase());
}

function Replace(s, sOld, sNew) {
    var result = "";
    if (sOld != null) {
        var iPrev = 0;
        var iLength = sOld.length;
        var iPos = s.indexOf(sOld, iPrev);
        while (iPos >= 0) {
            result += s.substring(iPrev, iPos) + sNew;
            iPrev = iPos + iLength;
            iPos = s.indexOf(sOld, iPrev);
        }
        if (iPrev < s.length)
            result += s.substring(iPrev, s.length);
        return result;
    } else
        return s;
}

function ReplaceNoCase(s, sOld, sNew) {
    var result = "";
    if (s && sOld != null) {
        var sUpper = s.toUpperCase();
        var sOldUpper = sOld.toUpperCase();
        var iPrev = 0;
        var iLength = sOld.length;
        var iPos = sUpper.indexOf(sOldUpper, iPrev);
        while (iPos >= 0) {
            result += s.substring(iPrev, iPos) + sNew;
            iPrev = iPos + iLength;
            iPos = sUpper.indexOf(sOldUpper, iPrev);
        }
        if (iPrev < s.length)
            result += s.substring(iPrev, s.length);
        return result;
    } else
        return s;
}

function ReplaceUpper(s, sOld, sNew) {
    return Replace(s.toUpperCase(), sOld.toUpperCase(), sNew.toUpperCase());
}

function Split(s, splitter) {
    var splites = new Array();
    if (s != null) {
        var i = 0;
        var part = s;
        do {
            var iPos = part.indexOf(splitter);
            if (iPos >= 0) {
                var spl = part.substring(0, iPos);
                if (spl.length > 0)
                    splites[i++] = spl;
                part = part.substring(iPos + 1, part.length);
            }
        } while (iPos >= 0);
        if (part.length > 0)
            splites[i] = part;
    }
    return splites;
}

function SplitAll(s, splitter) {
    var splites = new Array();
    if (s != null) {
        var i = 0;
        var part = s;
        do {
            var iPos = part.indexOf(splitter);
            if (iPos >= 0) {
                var spl = part.substring(0, iPos);
                splites[i++] = spl;
                part = part.substring(iPos + 1, part.length);
            }
        } while (iPos >= 0);
        splites[i] = part;
    }
    return splites;
}

function SplitNoEmpty(s, splitter) {
    return Split(s, splitter);
}

function Unsplit(arr, splitter, begin, end) {
    var s = new String();
    if (arr != null) {
        if (begin == null)
            begin = 0;
        if (end == null)
            end = arr.length - 1;
        if (end - begin >= 0) {
            for (var i = begin; i <= end; i++)
                s += arr[i] + splitter;
            s = s.substr(0, s.length - splitter.length);
        }
    }
    return s;
}

function Trim(s) {
    if (s != null && s.length > 0) {
        var iBegin = 0;
        while (iBegin < s.length && s.charAt(iBegin) == " ")
            iBegin++;

        var iEnd = s.length - 1;
        while (iEnd > 0 && s.charAt(iEnd) == " ")
            iEnd--;
        if (iBegin <= iEnd)
            if (iBegin > 0 || iEnd < s.length - 1)
            return s.substring(iBegin, iEnd + 1);
        else
            return s;
        else
            return "";
    } else
        return "";
}

function TrimLeading(s, leading) {
    if (s != null && s.length > 0) {
        var iBegin = 0;
        while (iBegin < s.length && s.charAt(iBegin) == leading)
            iBegin++;

        if (iBegin < s.length)
            return s.substring(iBegin, s.length);
        else
            return "";
    } else
        return "";
}

function IsEmptyTrim(s) {
    return (s == null || Trim(s).length <= 0);
}

function NotEmptyTrim(s) {
    return (s != null && Trim(s).length > 0);
}
function ShowDiv(div) {
    if (div != null) {
        div.style.display = "block";
    }
}

function HideDiv(div) {
    if (div != null) {
        div.style.display = "none";
    }
}

function Utils_Hide(id, doc) {
    var element = id;
    if (typeof (id) == "string")
        element = documentAll(id, doc);
    if (element != null) {
        element.style.display = "none";
    }
}

function Utils_Show(id, doc) {
    var element = id;
    if (typeof (id) == "string")
        element = documentAll(id, doc);
    if (element != null) {
        element.style.display = "";
    }
}
function Utils_HideShow(id, hide, doc) {
    var element = id;
    if (typeof (id) == "string")
        element = documentAll(id, doc);
    if (element != null) {
        element.style.display = (hide ? "none" : "");
    }
}

function Utils_ShowHide(id, show, doc) {
    var element = id;
    if (typeof (id) == "string")
        element = documentAll(id, doc);
    if (element != null) {
        element.style.display = (show ? "" : "none");
    }
}

function PxToInt(s) {
    if (s != null && s != "")
        return parseInt(s);
    else
        return 0;
}


function GetRootURL(doc) {
    if (!doc)
        doc = document;
    var location = doc.location.href;
    var pos = doc.location.href.indexOf("?");
    if (pos > 0)
        location = location.substring(0, pos);
    pos = location.lastIndexOf("/");
    var rootURL = location.substring(0, pos + 1);
    return rootURL;
}

function GetDomainRootURL(doc) {
    var iPos = 0;
    var Rpos = doc.location.href.indexOf("//");
    var location = doc.location.href;

    while (iPos != Rpos + 1) {
        iPos = location.lastIndexOf("/");
        if (iPos == Rpos + 1) {
            location = location + "/";
        }
        else {
            location = location.substring(0, iPos);
        }
    }
    return location;
}

function GetUrlArguments(url) {
    if (url == null)
        url = document.location.href;
    if (url != null) {
        var pos = url.indexOf("?");
        var args = url.substring(pos + 1);
        return args;
    } else return "";
}

function GetUrlArgumentValue(url, arg) {
    var args = GetUrlArguments(url);
    if (args != null) {
        var strings = Split(args, '&');
        for (var i = 0; i < strings.length; i++) {
            var s = strings[i];
            var pair = Split(s, '=');
            if (pair != null && pair.length == 2 && pair[0] == arg)
                return pair[1];
        }
    }
    return null;
}

function RemoveAllChildren(node) {
    if (node != null)
        for (var i = node.childNodes.length - 1; i >= 0; i--)
        node.removeChild(node.childNodes[i]);
}

function DisplayCurrentHTML(elementName, title) {
    var sFeatures = "height:550px;width:750px;menubar:yes;resizable:yes;titlebar:yes;toolbar:yes;status:yes;scrollbars:yes;";
    var win = window.open("", "_blank", sFeatures, true);
    win.document.write("<html>");
    if (title != null && title != "underfined")
        win.document.write("<head><title>" + title + "</title></head>");
    win.document.write("<body><form>");
    win.document.write(documentAll(elementName).innerHTML);
    win.document.write("</form></body></html>");
}

function HasIllegalCharacters(s, chars) {
    if (s != null && chars != null) {
        for (var i = 0; i < chars.length; i++) {
            if (s.indexOf(chars.charAt(i)) >= 0)
                return true;
        }
    }
    return false;
}

function IsValidInt(s) {
    s = Trim(s);
    if (s.length > 0) {
        try {
            var i = parseInt(s, 10);
            var s2 = "" + i;
            return (s2 == s);
        } catch (ee) {
            return false;
        }
    } else
        return false;
}

var IsBrowserNetscape = (window.navigator.appName.toLowerCase().indexOf("netscape") > -1);

function documentAll(id, doc, useNames) {

    if (doc == null)
        doc = document;

    //	if (IsBrowserNetscape) {
    //			return doc.forms[id];
    //			return doc.layers[id];
    var obj = null;
    if (useNames) {
        var objs = doc.getElementsByName(id);
        if (objs != null && objs.length > 0)
            obj = objs[0];
    }
    else
        obj = doc.getElementById(id);
    return obj;
}

function ClearCollection(collection) {
    if (collection != null) {
        for (var i = collection.length - 1; i >= 0; i--) {
            collection.remove(i);
        }
    }
}

function FindChild(node, tagName, startIndex) {
    tagName = tagName.toUpperCase();
    if (node != null) {
        for (var i = (startIndex == null ? 0 : startIndex); i < node.childNodes.length; i++)
            try {
            if (node.childNodes[i].tagName.toUpperCase() == tagName)
                return node.childNodes[i];
        } catch (ee) { }
    }
    return null;
}

function GetFormField(name, doc) {
    if (!IsBrowserNetscape)
        return documentAll(name, doc, true);
    else {
        if (doc == null)
            doc = document;
        return doc.forms[0].elements[name];
        //		return doc.forms["mainForm"].elements[name];
    }
}

function GetFormFields(name, doc) {
    if (doc == null)
        doc = document
    if (!IsBrowserNetscape)
        return doc.getElementsByName(name);
    else {
        if (doc == null)
            doc = document;
        return doc.forms[0].elements[name];
        //		return doc.forms["mainForm"].elements[name];
    }
}

function GetRandomURLAttribute(ampersand) {
    var rnd1 = Math.random() * 1000000000;
    return (ampersand != null && ampersand ? "&rnd" : "rnd") + rnd1.toString() + "=" + Math.random();
}

function GetAbsoluteTop(elem) {
    if (elem != null && elem != "undefined") {
        return elem.offsetTop + GetAbsoluteTop(elem.offsetParent);
    } else
        return 0;
}

function GetAbsoluteLeft(elem) {
    if (elem != null) {
        return elem.offsetLeft + GetAbsoluteLeft(elem.offsetParent);
    } else
        return 0;
}

function GetRightBorderWidth(elem) {
    if (elem != null) {
        var w = PxToInt(elem.style.borderRightWidth);
        //		if (left > 0)
        //		_TestAppend(" " + elem.tagName + elem.style.borderRightWidth);
        return w + GetRightBorderWidth(elem.offsetParent);
    } else
        return 0;
}

// Converts a float number into decimal representation adding grouping and adding/cutting decimal digits. 
// The number may be a string. Rounding to required decimals for float numbers is supported.
function FormatDecimal(f, decimals, group) {
    var s = null;
    if (f != null) {
        var minusOffset = 0;
        if (typeof (f) != "string") {
            var n = new Number(f);
            s = n.toFixed(decimals);

            if (f < 0)
                minusOffset = 1;
        }
        else {
            s = f;
            if (s.length > 0 && s[0] == '-')
                minusOffset = 1;
        }
        var point = s.indexOf(".");
        var sInt = "";
        var sDec = "";
        if (point >= 0) {
            sInt = s.substr(0, point);
            sDec = s.substring(point + 1);
        } else
            sInt = s;
        if (decimals == null)
            decimals = 2;
        sDec = (sDec + "0000000000").substr(0, decimals);
        if (group == null || !group) {
            var groupPos = sInt.length - 3;
            while (groupPos > minusOffset) {
                sInt = sInt.substr(0, groupPos) + "," + sInt.substring(groupPos);
                groupPos -= 3;
            }
        }
        if (decimals == 0)
            s = sInt;
        else
            s = sInt + "." + sDec;
    }
    return s;
}

function Utils_GetSafeHtml(html) {
    if (html != null) {
        var s = Replace(html, '<', "&lt;");
        s = Replace(s, '>', "&gt;");
        return s;
    } else
        return null;
}

function Utils_ToFloat(s, defVal) {
    s = Utils.Trim(s);
    s = Utils.Replace(s, ',', '');
    if (s.length > 0) {
        try {
            return parseFloat(s);
        } catch (ee) { }
    }
    return (defVal != null ? defVal : 0.0);
}

function Utils_SubmitForm(doc) {
    if (!doc)
        doc = document;
    if (doc.forms && doc.forms.length > 0) {
        var form = doc.forms[0];
        form.submit();
        return true;
    } else
        return false;
}

function Utils_GetDomainRootURL(doc) {
    var pos = doc.location.href.indexOf("//");
    pos = doc.location.href.indexOf("/", pos >= 0 ? pos + 2 : 0);
    if (pos >= 0) {
        pos = doc.location.href.indexOf("/", pos + 1);
        if (pos > 0)
            return doc.location.href.substring(0, pos + 1);
    }
    return doc.location.href;
}

function GetDomainRootURL(doc) {
    var iPos = 0;
    var Rpos = doc.location.href.indexOf("//");
    var location = doc.location.href;

    while (iPos != Rpos + 1) {
        iPos = location.lastIndexOf("/");
        if (iPos == Rpos + 1) {
            location = location + "/";
        }
        else {
            location = location.substring(0, iPos);
        }
    }
    return location;
}


function ShowSessionExpired(doc) {
    doc.location.href = "SessionExpired.htm";
    //doc.URL = "SessionExpired.htm";
}

function ParentAutoLogout(doc, original) {
    if (doc.parentWindow.parent && doc != doc.parentWindow.parent.document) {
        var root = Utils.GetDomainRootURL(doc);
        var rootParent = Utils.GetDomainRootURL(doc.parentWindow.parent.document);
        if (root && rootParent) {
            if (root == rootParent) {
                if (!ParentAutoLogout(doc.parentWindow.parent.document, false) && !original)
                    if (!Utils.SubmitForm(doc)) {
                    //ShowSessionExpired(doc);
                }
            }
            else if (!original)
                if (!Utils.SubmitForm(doc)) {
                //	ShowSessionExpired(doc);
            }
        } else
            return false;
    } else
        if (!original)
        if (!Utils.SubmitForm(doc)) {
        ShowSessionExpired(doc);
    }
    return true;
}

function CreateHttpRequest() {
    var request = null;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        request = new XMLHttpRequest();
        if (request.overrideMimeType) {
            request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
    return request;
}

//Sending a Request to a server and get Response--------------------------------

function SendRequest(url, params) {
    var xmlRequest = null;
    var xmlResponse = null;
    xmlRequest = Utils_CreateHttpRequest();

    if (xmlRequest == null) {
        alert("Browser does not support HTTP Request")
        return
    }

    xmlRequest.open("POST", url, false);
    xmlRequest.send(params);
    //Get response from the server
    var xmlResponse = xmlRequest.responseText;
    return xmlResponse;
}


//Sending a Request to a server and get Response asynchronously--------------------------------
//See help at http://www.w3schools.com/ajax/ajax_example.asp
var xmlRequest = null;
var xmlResponse = null;
var control = null;
function SendRequestAsyn(url, params, control) {
    xmlRequest = Utils_CreateHttpRequest();

    if (xmlRequest == null) {
        alert("Browser does not support HTTP Request")
        return
    }
    else {
        this.control = control;
    }

    xmlRequest.onreadystatechange = stateChanged
    xmlRequest.open("GET", url, true)
    xmlRequest.send(null)

}

function StateChanged() {
    if (xmlRequest.readyState == 4 || xmlRequest.readyState == "complete") {
        control.innerHTML = xmlRequest.responseText
    }
}

function Delay(millis) {
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while (curDate - date < millis);
} 




function OpenfullScreenWithStatus(document, url){
var durl = GetDomainRootURL(document) + url;
window.open(durl,null,
  "fullscreen=yes,top=0,left=0,status=yes,resizable=no,toolbar=no,menubar=no,scrollbars=yes,location=no");
}


function Utils_GetSreenResolutionHeight(window, document, excess) {
    var heightValue = 0;
    var widthValue = 0;

    if (window.innerHeight) {
        heightValue = window.innerHeight;
        widthValue = window.innerWidth;
    }
    else if ((document.documentElement) && (document.documentElement.clientHeight)) {
        heightValue = document.documentElement.clientHeight;
        widthValue = document.documentElement.clientWidth;
    }
    else if ((document.body) && (document.body.clientHeight)) {
        heightValue = document.body.clientHeight;
        widthValue = document.body.clientWidth;
    }

    return parseInt(heightValue - excess, 10);
}



function Utils_GetSreenResolutionWidth(window, document, excess) {
    var heightValue = 0;
    var widthValue = 0;

    if (window.innerHeight) {
        heightValue = window.innerHeight;
        widthValue = window.innerWidth;
    }
    else if ((document.documentElement) && (document.documentElement.clientHeight)) {
        heightValue = document.documentElement.clientHeight;
        widthValue = document.documentElement.clientWidth;
    }
    else if ((document.body) && (document.body.clientHeight)) {
        heightValue = document.body.clientHeight;
        widthValue = document.body.clientWidth;
    }

    return parseInt(widthValue - excess, 10);
}

function GetTimezoneOffset() {
    return now.getTimezoneOffset();
}

function ScaleImageSize(maxW, maxH, currW, currH) {
    var ratio = currH / currW;
    if (currW >= maxW && ratio <= 1) {
        currW = maxW;
        currH = currW * ratio;
    } else if (currH >= maxH) {
        currH = maxH;
        currW = currH / ratio;
    }
    return [currW, currH];
}

function Highlight(which, color) {
    if (document.all || document.getElementById)
        which.style.backgroundColor = color
}

function HidePageScrollbars(document) {
    document.documentElement.style.overflow = 'hidden';
}

function maxWindow(top, document, screen) {
     
     top.window.moveTo(0, 0);


    if (document.all) {
        top.window.resizeTo(screen.availWidth, screen.availHeight);
    }

    else if (document.layers || document.getElementById) {
        if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
}

function OpenFullSreenWindow(targeturl, window) {
    window.open(targeturl, "", "fullscreen,scrollbars")
}



function CreateCookie(name, value, days, document) {
    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 EraseCookie(name, document) {
    CreateCookie(name, "", -1, document);
}


function ReadCookie(name, document) {
    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 ListCookies(document) {
    var theCookies = document.cookie.split(';');
    var aString = '';
    for (var i = 1; i <= theCookies.length; i++) {
        aString += i + ' ' + theCookies[i - 1] + "\n";
    }
    return aString;
}
