var xcms_fadetimer = 100;
var xcms_timer = null;
var ddownOrder = false;

function hide(what){
	document.getElementById(what).style.display = 'none';
}
function show(what){
	if (!document.getElementById(what))return false;
	if (document.getElementById(what).style.display == 'none')document.getElementById(what).style.display = '';
	else document.getElementById(what).style.display = 'none';
	return true;
}
function forceShow(what){
	if (document.getElementById(what))document.getElementById(what).style.display = '';
}
function iVal(){
	var ch = '/';
	document.forms[0]['in'].value = hex_md5(''+document.forms[0]['in'].value);
	document.forms[0]['password'].value = hex_md5(''+document.forms[0]['in'].value+''+document.forms[0]['challenge'].value);
	document.forms[0]['in'].value = '';
	for(var i=0;i<6200;i++){
		window.status = 'Processing Secure Login... '+parseInt((i/6200)*100)+'%';
	}
	window.status = 'done.';
	return true;
}
var toc = true;
function forumVal(){
	if(toc==false){
		alert('Please read the terms and conditions completely, and submit the form when done!');
		return false;
	}
	else return true;
}
function doLen(){
	var d = document.forms[0]['description'];
	if (d.value.length<255)return true;
	else {
		d.value = d.value.substr(0,255);
		return false;
	}
}
function pop(where,x,y){
	var newWin = window.open(where,'','toolbar=no,status=no,menubar=yes,bookmarks=no,scrollbars=yes,width='+x+',height='+y);
}
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];}
}
function SetCookie (name, value) {
		var date = new Date();
		date.setTime(date.getTime()+(31*24*60*60*1000));
		document.cookie = name + "=" + escape (value) + "; expires=" + date.toGMTString() + "; path=/";
}

function setC(form) {
             var expdate = new Date ();
             expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
             SetCookie (form.name, form.value, expdate);
}
function getCookieVal(offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1) endstr = document.cookie.length;
   return unescape (document.cookie.substring(offset, endstr));
}
function GetCookie(name) {
   var arg = name+"=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) return unescape(getCookieVal(j));
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
   }
   return null;
}
function parseGlobals(mode){
	var QS = window.location.href;
	var elmts = new Array();
	var vars  = new Array();
	var vals  = new Array();
	elmts = QS.split('&');
	for (var i = 0;i<elmts.length;i++){
		var param = new Array();
		param = elmts[i].split('=');
		vars[i] = param[0];
		vals[i] = param[1];
		//alert(vars[i]+'='+vals[i]);
	}
	switch(mode){
		case "quiz":
		for(var i=0;i<vars.length;i++){
			if (vars[i] == "score"){
				var score = vals[i];
			}
			if (vars[i] == "rank"){
				var rank = vals[i];
			}
		}
		if (score == "undefined" || score == null)document.writeln('<span style="color:red">Warning! Script malfunction: Please make sure the quiz is not corrupted.</span>');
		if (rank  == "undefined" || rank  == null)document.writeln('<span style="color:red">Warning! Script malfunction: Please make sure the quiz is not corrupted.</span>');
		var block = document.getElementById('main').innerHTML;
		document.getElementById('main').innerHTML = block.replace('[=score]',score);
		break;
	}
}

var t = null;
var l = null;

function dshow(what){
	if (!$(what))return false;
	document.getElementById(what).style.display = '';
	return true;
}
function dhide(what){
	if (!document.getElementById(what))return false;
	document.getElementById(what).style.display = 'none';
	return true;
}
function buildDropdown(){
	document.writeln('<table id="dropdown" border="0" cellpadding="0" cellspacing="0"><tr>');
	if (ddownOrder == false){
		for(var i=0;i<menu.length;i++){
			if(menu[i] == null)continue;
			var param = new Array();
			param = submenu[i].split(',');
			if (param[0] != null && param[0] != "undefined")document.writeln('<td onmouseover="document.getElementById(\'m'+i+'\').className=\'entrySel\';dshow(\'s'+i+'\')" onmouseout="document.getElementById(\'m'+i+'\').className=\'entry\';dhide(\'s'+i+'\')"><div id="m'+i+'" class="entry">'+menu[i]+'</div>');
			else document.writeln('<td><div id="m'+i+'" class="entry">'+menu[i]+'</div>');
			if (submenu[i] != '' && submenu[i] != null){
				document.writeln('<div id="s'+i+'" style="display:none" class="links">');
				for(var j=0;j<param.length;j++){
					document.writeln('<div class="off" onmouseover="this.className=\'over\'" onmouseout="this.className=\'off\'">'+param[j]+'</div>');
				}
				document.writeln('</div></td>');
			}
		}
	}
	else{
		var sortmenu = new Array();
		sortmenu = ddownOrder.split(',');
		for(var i=0;i<sortmenu.length;i++){
			var index = sortmenu[i];
			if(sortmenu[i] == null)continue;
			var param = new Array();
			param = submenu[index].split(',');
			if (param[0] != null && param[0] != "undefined")document.writeln('<td onmouseover="document.getElementById(\'m'+i+'\').className=\'entrySel\';dshow(\'s'+i+'\')" onmouseout="document.getElementById(\'m'+i+'\').className=\'entry\';dhide(\'s'+i+'\')"><div id="m'+i+'" class="entry">'+menu[index]+'</div>');
			else document.writeln('<td><div id="m'+i+'" class="entry">'+menu[index]+'</div>');
			if (submenu[index] != '' && submenu[index] != null){
				document.writeln('<div id="s'+i+'" style="display:none" class="links">');
				for(var j=0;j<param.length;j++){
					document.writeln('<div class="off" onmouseover="this.className=\'over\'" onmouseout="this.className=\'off\'">'+param[j]+'</div>');
				}
				document.writeln('</div></td>');
			}
		}		
	}
	document.writeln('</tr></table>');
	return true;
}
function $(what){
	if (document.getElementById(what))return document.getElementById(what);
	else return false;
}
function fade(what,orig){
	if (!$(what))return false;
	if (xcms_timer = null){
		if (document.all)$(what).style.filter = "alpha(opacity="+orig+")";
		else $(what).style.opacity = ""+(orig/100);
		xcms_fadetimer = orig;
		dshow(what);
	}
	//window.status = xcms_fadetimer+' FF:'+(xcms_fadetimer/100)+' Original: '+orig;
	if (document.all){
		$(what).style.filter = "alpha(opacity="+xcms_fadetimer+")";
	}
	else{
		$(what).style.opacity = ''+(xcms_fadetimer/100)+'';
	}
	if (xcms_fadetimer>0){
		xcms_fadetimer-= 5;
		xcms_timer = setTimeout("fade('"+what+"',"+orig+")",30);
	}
	else {
		clearTimeout(xcms_timer);
		xcms_timer = null;
		hide(what);
		if (document.all)$(what).style.filter  = 'alpha(opacity='+orig+')';
		else $(what).style.opacity = ''+(orig/100);
		xcms_fadetimer = orig;
	}
	return true;
}