
fixIEBugIndexOf();

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function show_var(s,na,t){
	na ? na=true : na=false;
	t? t = t+"\t": t="\t";
	var r='';
	if (typeof(s)=="object") {
        var o = s;
        for (var i in o){
			if ((typeof(o[i])=="object" || typeof(o[i])=="array")&& o[i])
				o[i] = "\n"+	show_var(o[i],true,t);

            r += t+i+"="+o[i]+"\n";
		}
    }else if (typeof(s)=="array") {
        var a = s;
        for (var j=0; j< a.length; j++){
			if ((typeof(a[j])=="object" || typeof(a[j])=="array")&& a[j])
				a[j] = "\n"+	show_var(a[j],true,t);			
            r += t+j+"="+a[j]+"\n";
		}
    }else r=t+s;
	
	if (na) return r;
		else alert(r); 
}
function isSet( variable ){
	return( typeof( variable ) != 'undefined' );
}
function select_chbox_PSSearch(id){
	select_chbox(id);
	switch (id) {
		case 'parties':
			deselect_chbox('speakers');
		break;
		case 'speakers':
			deselect_chbox('parties');
			break;

	}
}
function select_chbox(id){
	var elem = document.getElementById('chbox_'+id); 
	if (elem){
		document.getElementById('chbox_'+id).checked = true;
	}
}
function deselect_chbox(id){
	var elem = document.getElementById('chbox_'+id); 
	if (elem){
		document.getElementById('chbox_'+id).checked = false;
	}
}
function toggle_checkbox(id){
	var elem = document.getElementById(id); 
	if (elem){
		
		elem.checked = !elem.checked;
	}
}

function getElementHeight(elem){
	if (document.getElementById(elem)){
		return document.getElementById(elem).offsetHeight;
	}else {
		return 0;
	}
}

function getClientWindSize(){
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	  //Non-IE
	  myWidth = window.innerWidth;
	  myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	  //IE 6+ in 'standards compliant mode'
	  myWidth = document.documentElement.clientWidth;
	  myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	  //IE 4 compatible
	  myWidth = document.body.clientWidth;
	  myHeight = document.body.clientHeight;
	}
	
	return Array(myWidth, myHeight);
}

function showHideElem(id){
	
	var elem = document.getElementById(id);

    if (elem){
        if (elem.style.display == 'none' || elem.style.display == ''){
            elem.style.display = 'block';
        }else {
            elem.style.display = 'none';
        }
    }
}

function checkFlashVersionWarning(){
	var version_good = DetectFlashVer(9,0,124);
	
	if (!version_good) {
		$(document).ready(function() {
			$('#main_warnings>.ui-state-error.ui-corner-all,#check_flash_version_warning').show();
		});
	}
} 

function fixIEBugIndexOf(){
	//Adding array.indexOf for compability with IE 
	if(!Array.prototype.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}
}

function socButtonHow(target,h){
    var url = $("img",target).attr("src");
    if (h==1)
        url = url.replace(/(.+?)(\w+?)(\.(jpeg|gif|jpg|png))/i,'$1$2_h$3');
    else
        url = url.replace(/(.+?)(\w+?)(?:_h)(\.(jpeg|gif|jpg|png))/i,'$1$2$3');
    
    $("img",target).attr("src",url);


}

