function trim(str)
{
 return jQuery.trim(str);
}

function leftstr(str,len)
{
 return String(str).substr(0,len);
}

function rightstr(str,len)
{
 if (len <= 0) return "";
 if (len > String(str).length) return str;
 var olen = String(str).length;
 return String(str).substring(olen, olen -len);
}

function myreplace(wh,wi,str)
{
 while(str.indexOf(wh) != -1) 
 {str = str.replace(wh,wi); }
 return str;
}



function str2int(str)
{
 if (!str)    return 0;	
 if (typeof(str)=='string') str=myreplace(' ','',str);
 if (str=='') return 0;	
 return parseInt(str,10);
}
function str2num(str)
{
 if (!str)    return 0;	
 if (typeof(str)=='string') str=myreplace(' ','',str);
 if (str=='') return 0;	
 return parseFloat(str);
}

function num2int(x)
{
 return Math.round(x);
}


function int2str(i)
{
 return i+'';
}
function num2str(x)
{
 return x+'';
}

function int0(val,len)
{
 return str_pad(val,len,'0','STR_PAD_LEFT');
}


function has_prefix(str,prefix)
{
 var l1=str.length;
 var l2=prefix.length;
 if(!l2)   return false;
 if(l1<l2) return false;
 return (leftstr(str,l2)==prefix);
}




function str_pad (input, pad_length, pad_string, pad_type)
{
    var half = '', pad_to_go;
     var str_pad_repeater = function (s, len) {
        var collect = '', i;
 
        while (collect.length < len) {collect += s;}
        collect = collect.substr(0,len); 
        return collect;
    };
 
    input += '';    pad_string = pad_string !== undefined ? pad_string : ' ';
    
    if (pad_type != 'STR_PAD_LEFT' && pad_type != 'STR_PAD_RIGHT' && pad_type != 'STR_PAD_BOTH') { pad_type = 'STR_PAD_RIGHT'; }
    if ((pad_to_go = pad_length - input.length) > 0) {
        if (pad_type == 'STR_PAD_LEFT') { input = str_pad_repeater(pad_string, pad_to_go) + input; }        else if (pad_type == 'STR_PAD_RIGHT') { input = input + str_pad_repeater(pad_string, pad_to_go); }
        else if (pad_type == 'STR_PAD_BOTH') {
            half = str_pad_repeater(pad_string, Math.ceil(pad_to_go/2));
            input = half + input + half;
            input = input.substr(0, pad_length);        }
    }
 
    return input;
}


function addslashes (str) 
{
 return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\u0000/g, "\\0");
}

function stripslashes (str) 
{
 return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':                return '\u0000';
            case '':
                return '';
            default:
                return n1;   
		}
    });
}

