﻿String.prototype.trim = trim;
String.prototype.isEmpty = isEmpty;

function trim()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function isEmpty()
{
	return (this.trim() == "");
}

String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}
String.prototype.endsWith = function(str) {return (this.match(str +"$")!=null)}
String.prototype.replaceAll=function(s1, s2) { return this.replace(new RegExp(s1,"g"), s2); }

function ShowTip(txt)
{
    if(txt != null)            
        Tip(txt, DELAY, 1000 ,FADEIN, 200, FADEOUT, 100, FOLLOWMOUSE, false, OPACITY, 85, SHADOW, false)
}

function setCookie(c_name,value,expiredays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie = c_name + "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
} 

function htmlEncode(s) {
    var str = new String(s);
    str = str.replace(/&/g, "&amp;");
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    str = str.replace(/"/g, "&quot;");        
    
    return str;
}

function replaceQuotes(s) {
    var str = new String(s);
    str = str.replaceAll("\"", "\"+String.fromCharCode(34)+\"");        
    str = str.replaceAll("&quot;", "\"+String.fromCharCode(34)+\"");        
    str = str.replaceAll("'", "\"+String.fromCharCode(39)+\"");        
    
    return str;
}

function replaceLineBreaks(s) {
    var str = new String(s);    
    
    str = str.replaceAll("\n", " ");
    str = str.replaceAll("\r", "");
    
    return str;
}

function toggleScrollbars(hide)
{
    var theRules = new Array();
    
    if (document.styleSheets[0].cssRules)
        theRules = document.styleSheets[0].cssRules
    else if (document.styleSheets[0].rules)
        theRules = document.styleSheets[0].rules

    if(hide)
    {
        theRules[5].style.overflow = "hidden";
        theRules[5].style.overflowX = "hidden";
    }
    else
    {
        theRules[5].style.overflow = "scroll";
        theRules[5].style.overflowX = "auto";        
    }   
}  