function print_r(o,re){
    var res = "";
    for(var name in o){
        if(o[name]){
            var val = o[name];
            switch(typeof(val)){
                case "string" :
                    val = val.replace(/</g,"&lt;").replace(/>/g,"&gt;")
                    break;
                case "function":
                    val = "function(){...}";
                    break;               
            }   
            res+=name+" => "+val+"\n";   
        }
    }
    res = "<pre>"+res+"</pre>"
    if(re) return res;
    var oSpan = document.getElementById("span_print_r");
    if(!oSpan){
        oSpan = document.createElement("span");       
        oSpan.id="span_print_r";
        document.body.insertBefore(oSpan,document.body.childNodes[0]);
    }
    oSpan.innerHTML = res;                             
}

function goSelectPage(obj){
	addQuery('page',obj.options[obj.selectedIndex].value);
}

function addQuery(key,val){
	var str=location.search;
	var reg=new RegExp(key+'=[a-zA-Z_0-9]*');
	if(str.indexOf(key)==-1){
		if(str.indexOf('?')>-1){
			str+='&'+key+'='+val;
		}else{
			str+='?'+key+'='+val;
		}
	}else{
		str=str.replace(reg,key+'='+val);
	}
	
	window.location.href=str;
}

function htmlspecialchars_decode (string, quote_style) {

    var optTemp = 0, i = 0, noquotes= false;
    if (typeof quote_style === 'undefined') {
        quote_style = 2;
   }

		
    string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
    var OPTS={
		'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE': 1,
		'ENT_HTML_QUOTE_DOUBLE': 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE': 4
    };

	if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { 
        quote_style = [].concat(quote_style);        for (i=0; i < quote_style.length; i++) {

            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            }            else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/&#0*39;/g, "'"); 
    }    if (!noquotes) {
        string = string.replace(/&quot;/g, '"');
    }

    string = string.replace(/&amp;/g, '&'); 

    return string;
}
