// JavaScript Document

var quickSearch_state = 'none'; 
var menu_state = 'block'; 

function quickSearch() {

	if (menu_state == 'block') { 
		menu_state = 'none'; 
	} else { 
		menu_state = 'block'; 
	} 
	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		document.all.show_menu.style.display = menu_state
	} 
	if (document.layers) { //IS NETSCAPE 4 or below 
		document.layers['show_menu'].display = menu_state; 
	} 
	if (document.getElementById &&!document.all) { 
		hza = document.getElementById('show_menu'); 
		hza.style.display = menu_state; 
	} 
	
	if (quickSearch_state == 'block') { 
		quickSearch_state = 'none'; 
	} else { 
		quickSearch_state = 'block'; 
	} 
	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		document.all.show_quick_search.style.display = quickSearch_state
	} 
	if (document.layers) { //IS NETSCAPE 4 or below 
		document.layers['show_quick_search'].display = quickSearch_state; 
	} 
	if (document.getElementById &&!document.all) { 
		hza = document.getElementById('show_quick_search'); 
		hza.style.display = quickSearch_state; 
	} 
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var ie5=document.all && !window.opera
var ns6=document.getElementById

if (ie5||ns6) {
	document.write('<div id="popitmenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event)"></div>')
}

function iecompattest(){
	return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}

function showmenu(e, obj, which, offsetLeft, offsetTop, optWidth){
	if (!document.all&&!document.getElementById){
		return
	}
	clearhidemenu()
	
	arrObjPositon = findPos(obj)
	tLeft = arrObjPositon[0];
	tTop = arrObjPositon[1];
	
	menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
	menuobj.innerHTML=which
	menuobj.style.width=(typeof optWidth!="undefined")? optWidth : defaultMenuWidth
	menuobj.contentwidth=menuobj.offsetWidth
	menuobj.contentheight=menuobj.offsetHeight
	
	
	menuobj.style.left= (tLeft + offsetLeft) + "px"
	menuobj.style.top= (tTop + offsetTop) + "px"
	
	menuobj.style.visibility="visible"
	return false
}

function contains_ns6(a, b) {
	//Determines if 1 element in contained in another- by Brainjar.com
	while (b.parentNode){
		if ((b = b.parentNode) == a){
			return true;
		}
	}
	return false;
}

function hidemenu(){
	if (window.menuobj){
		menuobj.style.visibility="hidden"
	}
}

function dynamichide(e){
	if (ie5&&!menuobj.contains(e.toElement)) {
		hidemenu()
	} else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget)){
		hidemenu()
	}
}

function delayhidemenu(){
	delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
	if (window.delayhide) {
		clearTimeout(delayhide)
	}
}

if (ie5||ns6) {
	document.onclick=hidemenu
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);

	}
	return [curleft,curtop];
}



function switch_video(aId){
	document.getElementById('video_title').innerHTML = urldecode(document.getElementById('title_' + aId).value)
	document.getElementById('video_embed').innerHTML = urldecode(document.getElementById('embed_' + aId).value)
	document.getElementById('video_description').innerHTML = urldecode(document.getElementById('description_' + aId).value)

	
}


function urldecode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var histogram = {};
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
 
    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}

