//window.onerror = exfoerr;
//var text1 = "";
//function exfoerr(msg, url, line) {
//    text1 = "Error Displayed\n\n";
//    text1 += "Error: " + msg + "\n";
//    text1 += "URL: " + url + "\n";
//    text1 += "Line Number: " + line + "\n\n";
//    text1 += "Click OK to continue.\n\n";
//    alert(text1);
//    return true;
//}


 /******************************
 * 
 * Cookie related functions
 * 
 ******************************/
 
 function setCookie(c_name, value, expiredays, domain, path) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    
    var _domain = domain && domain.length ? domain : null;
    var _path = path && path.length ? path : "/";  
    
    cookieString = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) 
            + ((_domain == null) ? "" : ";domain="+_domain.toLowerCase())
            + ";path=" + _path;
    
    //document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) + ";domain=" + window.location.hostname.replace("www.","") + ";path=/";
    document.cookie = cookieString;
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

/******************************
 * 
 * String related functions
 * 
 ******************************/

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

/******************************
* 
* AJAX related functions
* 
******************************/

var xmlhttp;
var xmlSuccessSwitch = '';
var xmlErrorSwitch = '';

function simpleajax(url, method, successCallback, failureCallback)
{
    var xmlhttp = false;
    /*@cc_on@*/
    /*@if (@_jscript_version >= 5) //Conditional compilation for JScript
    
    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;
        }
    }


    if (( method.toString().toUpperCase() != "GET" ) && ( method.toString().toUpperCase() != "POST"))
    {
        method = "POST";
    }

    xmlSuccessSwitch = successCallback;
    xmlErrorSwitch = failureCallback;
    
    xmlhttp.open(method, url, true);

    xmlhttp.onreadystatechange = function() {
        //call finished
        if (xmlhttp.readyState == 4) { //completed
            if (xmlhttp.status == 200) { //OK
                successCallback(xmlhttp.responseText);
            }
            else {
                failureCallback(xmlhttp.status);
            }
        }
    }

    xmlhttp.send(null);
}

function stripslashes(str) {
    switch (str) {
        case '\\':
            return '\\';
        case '0':                
            return '\u0000';
        case '':
            return '';
        default:
            return str;        
    }
};
