// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function getElementsByTagNames(list,obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) { resultArray.push(tags[j]); }
	}
	var testNode = resultArray[0];
	if (!testNode) return [];
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) { return a.sourceIndex - b.sourceIndex; });
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) { return 3 - (a.compareDocumentPosition(b) & 6); });
	}
	return resultArray;
}
function fb(){
	var inputs = getElementsByTagNames('input,textarea');
	var v = new Array();
	for ( i = 0; i < inputs.length-1; i++ ){
		if ( inputs[i].getAttribute("placeholder") != null ){
			v[i] = inputs[i].getAttribute("placeholder");
			inputs[i].value = v[i];
			inputs[i].onfocus = function(){ this.value = ''; }
			inputs[i].onblur = function(){ this.value = this.getAttribute("placeholder"); }
		}
	}
}
function qb(c, id){
	$('qb-inner').innerHTML = '';
	new Ajax.Updater('qb-inner', '/qb/'+id+'?c='+c, {asynchronous:true, evalScripts:true});
	$('qb-inner').className = c;
	$('qb').style.display = 'block';
}
function qbhide(){ $('qb').style.display = 'none'; }
function qbshow(){ $('qb').style.display = 'block'; }
function jumpMenu(selObj, url, q){ window.location=url+'?'+q+'='+selObj.options[selObj.selectedIndex].value; }
function openCover(p){ window.open('dh'+p+'?f=1','','scrollbars=yes,toolbar=no,status=no,resizable=yes,width=1024,height=768'); }
function openPic(p,w,h){ window.open(+p+'?f=1','','scrollbars=yes,toolbar=no,status=no,resizable=yes,width='+w+',height='+h); }
function picOpen(p,w,h){ window.open('http://media.the-leaky-cauldron.org/gallery'+p,'','scrollbars=yes,toolbar=no,status=no,resizable=yes,width='+w+',height='+h); }
function adjust_popup(){
	var w, h, fixedW, fixedH, diffW, diffH;
    if (document.documentElement && document.body.clientHeight==0){     // Catches IE6 and FF in DOCMODE
    	fixedW = document.documentElement.clientWidth;
    	fixedH = document.documentElement.clientHeight;
    	window.resizeTo(fixedW, fixedH);
    	diffW = fixedW - document.documentElement.clientWidth;
    	diffH = fixedH - document.documentElement.clientHeight;
    	w = fixedW + diffW + 16; // Vert Scrollbar Always On in DOCMODE.
    	h = fixedH + diffH;
    	if (w >= screen.availWidth) h += 16;
   	} else if (document.all) {
	   	fixedW = document.body.clientWidth;
	   	fixedH = document.body.clientHeight;
	   	window.resizeTo(fixedW, fixedH);
	   	diffW = fixedW - document.body.clientWidth;
	   	diffH = fixedH - document.body.clientHeight;
	   	w = fixedW + diffW;
	   	h = fixedH + diffH;
	   	if (h >= screen.availHeight) w += 16;
	   	if (w >= screen.availWidth)  h += 16;
	} else {
		fixedW = window.innerWidth;
		fixedH = window.innerHeight;
		window.resizeTo(fixedW, fixedH);
		diffW = fixedW - window.innerWidth;
		diffH = fixedH - window.innerHeight;
		w = fixedW + diffW;
		h = fixedH + diffH;
		if (w >= screen.availWidth)  h += 16;
		if (h >= screen.availHeight) w += 16;
	}
    w = Math.min(w,screen.availWidth)+10;
    h = 120+Math.min(h,screen.availHeight)+130;
    window.resizeTo(w,h);
    window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}
function favadd(t, id){ new Ajax.Updater('fav', '/favadd/'+id+'?t='+t, {asynchronous:true, evalScripts:true}); }
function favrem(t, id){ new Ajax.Updater('fav', '/favrem/'+id+'?t='+t, {asynchronous:true, evalScripts:true}); }
function gup(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
  	var regex = new RegExp(regexS);
  	var results = regex.exec(window.location.href);
  	if(results == null){
    	return "";
  	}else{
    	return results[1];
  	}
}