var d = document;

function cache_nav() {
	if (d.images) {
		var rolls = cache_rolls.arguments;
		d.rollOvers = new Array();
		d.rollDowns = new Array();
		d.rollNorms = new Array();
		for(i=0;i<rolls.length;i=i+2) {
			d.rollOvers[i] = new Image;
			d.rollOvers[i].src = "/images/" + rolls[i] + "_hov." + rolls[i+1];
			d.rollDowns[i] = new Image;
			d.rollDowns[i].src = "/images/" + rolls[i] + "_sel." + rolls[i+1];
			d.rollNorms[i] = new Image;
			d.rollNorms[i].src = "/images/" + rolls[i] + "_def." + rolls[i+1];
		}
	}	
}

/*
function img_out(theID)  { getObj(theID).src = "/images/" + theID + "_def.gif"; }
function img_over(theID) { getObj(theID).src= "/images/" + theID + '_hov.gif'; }
function img_down(theID) {  do nothing document.getElementById(theID).src= "/images/" + theID + '_hov.gif'; }
*/

function confirm_post(m) {
	var confirmed = confirm(m);
	if(confirmed) return true;
	else return false;
}

function cache_generic() {
	if (d.images) {
		var cacheArgs = cache_generic.arguments;
		if(d.cacheGens == undefined) {
			d.cacheGens = new Array();
		}
		
		var start = d.cacheGens.length;
		var end   = d.cacheGens.length + cacheArgs.length;
		
		for(var i=start;i<end;i++) {
			d.cacheGens[i] = new Image;
			d.cacheGens[i].src = cacheArgs[i - start];
		}
	}
}


function swap_sid(sid,n) { swap_generic(document.getElementById(sid),n); }

function swap_generic(obj,n) {
	obj.src = d.cacheGens[n-1].src;
}

function textLimit(field,limit) {
	if (field.value.length>limit) field.value = field.value.substring(0,limit);
}

function top_check() {
	if(top!=self) {
		top.location.href=self.location.href;
	}
}

function parent_check(theL) {
	if(top==self) {
		top.location.href=theL;
	}
}


//the DHTML micro-API *** from quirksmode.org
function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers) {
	 	this.obj = document.layers[name];
	 	this.style = document.layers[name];
	}
}
/* dataset functions */

function ds_order(formT,oV) {
	document.getElementById(formT+'_p').value='order';
	document.getElementById(formT+'_o').value=''+oV;
	document.getElementById(formT+'_s').value='1';
	document.getElementById('form_'+formT).submit();
}
function ds_page(formT,sV) {
	document.getElementById(formT+'_p').value='page';
	document.getElementById(formT+'_s').value=''+sV;
	document.getElementById('form_'+formT).submit();
}
function ds_pageG(formT,dV) {
	document.getElementById(formT+'_p').value='group';
	document.getElementById(formT+'_sp').value=''+dV;
	document.getElementById('form_'+formT).submit();
}




/* old */

function popup_center(popName,popURL,popW,popH,popResize,popScroll) {
	wLeft = (screen.availWidth - popW) / 2;
	wTop = (screen.availHeight - popH) /2;
	popHandle = window.open(popURL,popName,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+popScroll+",resizable="+popResize+",copyhistory=no,width=" + popW + ",height=" + popH + ",left=" + wLeft + ",top=" + wTop);
	popHandle.focus();
}

function popup_spec(popName,popURL,popW,popH,popResize,popScroll,wLeft,wTop) {
	popHandle = window.open(popURL,popName,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+popScroll+",resizable="+popResize+",copyhistory=no,width=" + popW + ",height=" + popH + ",left=" + wLeft + ",top=" + wTop);
	popHandle.focus();
}

function tag_out(theID) { sTc(theID,'','ccccaa'); }
function tag_over(theID,newCat) {
	sTc(theID,'aaaa99','ffffff');
	//return true;
}
function tag_down(theID) { sTc(theID,'aaaa99','333333'); }
function tag_click(theID,theL) { tag_over(theID); self.location = theL; }

function qh_tag_out(theID) { sTc(theID,'','ccccaa'); }
function qh_tag_over(theID) { sTc(theID,'aaaa99','ffffff'); }
function qh_tag_down(theID) { sTc(theID,'aaaa99','333333'); }
function qh_tag_click(theID) { qh_tag_over(theID); }

function update_user_list(newHTML) {
	top.document.getElementById('user_list').innerHTML=newHTML;
}

function update_top_message(newHTML) {
	top.document.getElementById('top_message').innerHTML=newHTML;
}

function sTc(theID,theBG,theT) {
	d.getElementById(theID).style.backgroundColor=(theBG!=''?'#':'')+theBG;
	d.getElementById(theID).style.color='#'+theT;
	d.getElementById(theID+'_link').style.color='#'+theT;
}

function concat_heck(str,len) {
	if(str.length > len) {
		str= str.substr(0,len-1);
		return str+"&hellip;";
	}
	else return str;
}
