// JavaScript Document
var enablepersist="1" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='<img src="">' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='<img src="">' //HTML for expand symbol.


if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}
function msg( $id, $name, $file ){
	document.msgme.to.value = $name;
	
}
function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var thestate=(ec=="expand")? "block" : "none"
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=thestate
inc++
}
revivestatus()
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(curobj, cid){
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

//////////////////////////// TEMP DEBUG /////////////////////////

function showDebug() {

	var debugDiv = document.getElementById('debug'); 

	if (debugDiv.style.visibility == 'hidden') {

		debugDiv.style.visibility = 'visible';

	} 

	

	else debugDiv.style.visibility = 'hidden';

}



function clearDebug() {

	document.getElementById('debug').innerHTML = '<table width="100%" border="0"> <tr> <td><h2>DO NOT REPORT!</h2></td><td align="right"><a href="javascript:clearDebug();">Clear</a></td></tr></table>';

	document.getElementById('debugLink').innerHTML = '<a href="javascript:showDebug();">Debug</a>';

	var debugDiv = document.getElementById('debug');

	debugDiv.style.visibility = 'hidden';

}

/* URL POPPER */

function popUp(URL) {

	day = new Date();

	id = day.getTime();

	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=550');");

}
	

/* BOOKMARK */

function bookmark(title, url) {

  if (document.all) window.external.AddFavorite(url, title);

  else if (window.sidebar) window.sidebar.addPanel(title, url, "");

}

var paused = false;

var pin = Math.random();


var stringBuffer = '';

var stringBufferActual = '';



var selectedUser = "";

	

/* ---------------------- AJAX ------------------------- */



/* Ajax function class */

/* Declarations */

var arAjx = new Array(1);

var arStops = new Array;







/* ajFetch function */

function ajFetch(url, destination, cycle, delay, noloading) {

	

	/* Execution timer */

	var timerOne = new Date();

	floatInt = timerOne.getTime();

	//

	

	var curInstance;

	if (cycle == null) {

		cycle = false;	

	}

	if (noloading == null) {

		noloading = false;	

	}

	

	if (arAjx.length == 1) {

		curInstance = 1;

		arAjx[1] = new Ajax;

	} else {

		var found = false;

		for (i=1;i<arAjx.length;i++) {

			if (arAjx[i].Is_Free()) {

				curInstance = i;

				found = true;

			}

		}

		

		if (!found) {

			arAjx.push(new Ajax);

			curInstance = arAjx.length;

			arAjx[curInstance] = new Ajax;

		}

	}

	

	if (noloading) { arAjx[curInstance].Set_Loading(false); }

	

	if (paused) {

		arAjx[curInstance].HTTP_Get(url+"&pause=1", destination);

	} else {

		arAjx[curInstance].HTTP_Get(url, destination);

	}

	

	if (arStops[destination] != true) {

		if (cycle) {

			setTimeout("ajFetch('"+url+"','"+destination+"',true,"+delay+");",delay);

		}

	} else {

		arStops[destination] = null;

	}

}



/* Ajax functions, objects, classes and callback */

function Ajax() {

	/* Declarations */

	/* Public methods */

	this.HTTP_Get = HTTP_Get;

	this.Is_Free = Is_Free;

	this.Set_Loading = Set_Loading;

		

	/* Private variables */

	var ajobj = XMLHTTP_object();

	var http_destobj = null;

	var free = true;

	var show_loading = true;



	/* Methods */

	function HTTP_Get(url, destination) {

		if (free && (url != null) && (destination != null) && ((ajobj.readyState == 0) || (ajobj.readyState == 4))) {

			http_destobj = destination;

			

			ajobj.open("GET", url, true);

			ajobj.onreadystatechange = HTTP_Get_CallBack;

			ajobj.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");

			ajobj.send(null);

			free = false;

		} else {

			return false;

		}

	}

	

	/* Get CallBack (Handle received data) */

	function HTTP_Get_CallBack() {

		if (ajobj.readyState == 4) {

			var results = ajobj.responseText;

			

			if (typeof(results)=='string' && results != null && results != '') {

				/* Function callback evaluator */

				if (eval("typeof(" + http_destobj + ") == 'function'")) { 

					/* Function detected, pass data to function */

					eval(http_destobj + "(results);");

				} else {

					/* Not a function, pass data to the html object */

					if (typeof document.getElementById(http_destobj).innerHTML != "undefined") {

						document.getElementById(http_destobj).innerHTML = results;

					}

				}

			}

			free = true;

		}

	}

	

	/* Helpers functions */

	function Is_Free() {

		return free;	

	}

	

	function Set_Loading(value) {

		show_loading = value;

	}

	

	/* AJAX OBJECT */

	function XMLHTTP_object() {

	  var xmlhttp;

	  /*@cc_on

	  @if (@_jscript_version >= 5)

		try {

		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

		} catch (e) {

		  try {

			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

		  } catch (E) {

			xmlhttp = false;

		  }

		}

	  @else

	  xmlhttp = false;

	  @end @*/

	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

		try {

		  xmlhttp = new XMLHttpRequest();

		} catch (e) {

		  xmlhttp = false;

		}

	  }

	  return xmlhttp;

	}

}



function ajStop(destination) {

	arStops[destination] = true;

}



/* --------------------- HELPERS ----------------------- */



/* Set Selection */

function setSelectionRange(input, selectionStart, selectionEnd) {

  if (input.setSelectionRange) {

    input.focus();

    input.setSelectionRange(selectionStart, selectionEnd);

  }

  else if (input.createTextRange) {

    var range = input.createTextRange();

    range.collapse(true);

    range.moveEnd('character', selectionEnd);

    range.moveStart('character', selectionStart);

    range.select();

  }

}



/* Object position gizmo */

function findPosX(obj) {

	var curleft = 0;

	if (obj.offsetParent) {

		while (obj.offsetParent) {

			curleft += obj.offsetLeft;

			obj = obj.offsetParent;

		}

	}

	else if (obj.x) curleft += obj.x;

	return curleft;

}



function findPosY(obj) {

	var curtop = 0;

	if (obj.offsetParent) {

		curtop += obj.offsetHeight;

		while (obj.offsetParent) {

			curtop += obj.offsetTop;

			obj = obj.offsetParent;

		}

	}

	else if (obj.y) {

		curtop += obj.y;

		curtop += obj.height;

	}

	return curtop;

}

	

/* Array pop gizmo */

function array_pop(array, itemname) {

	var i = 0;

	while (i < array.length) {

		if (array[i] == itemname) array.splice(i, 1);

		i++;

  	}

	return array;

}



/* URLencode/decode helper */

function urlDecode(str){

    str=str.replace(new RegExp('\\+','g'), ' ');

   	return unescape(str);

}

	

function urlEncode(str){

	str = escape(str);

	str=str.replace(new RegExp('\\+','g'), 'PPP910918271');

	str=str.replace(new RegExp('%20','g'), '+');

	return str;

}



/* Base64 Helpers */

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {

	if (input != null && input != '' && input != ' ') {

		var output = "";

		var chr1, chr2, chr3;

		var enc1, enc2, enc3, enc4;

		var i = 0;



		do {

			chr1 = input.charCodeAt(i++);

			chr2 = input.charCodeAt(i++);

			chr3 = input.charCodeAt(i++);



			enc1 = chr1 >> 2;

			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);

			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);

			enc4 = chr3 & 63;



			if (isNaN(chr2)) {

				enc3 = enc4 = 64;

			} else if (isNaN(chr3)) {

				enc4 = 64;

			}



			output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 

			keyStr.charAt(enc3) + keyStr.charAt(enc4);

		} while (i < input.length);

   		

		return output;

	}

}

function decode64(input) {

	var output = "";

	var chr1, chr2, chr3;

	var enc1, enc2, enc3, enc4;

	var i = 0;



	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");



	do {

		enc1 = keyStr.indexOf(input.charAt(i++));

		enc2 = keyStr.indexOf(input.charAt(i++));

		enc3 = keyStr.indexOf(input.charAt(i++));

		enc4 = keyStr.indexOf(input.charAt(i++));



		chr1 = (enc1 << 2) | (enc2 >> 4);

		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);

		chr3 = ((enc3 & 3) << 6) | enc4;



		output = output + String.fromCharCode(chr1);



		if (enc3 != 64) {

			output = output + String.fromCharCode(chr2);

		}

		if (enc4 != 64) {

			output = output + String.fromCharCode(chr3);

		}

	} while (i < input.length);

	

	return output;

}



/* trim helper */

function trim(str) {

	/* Removes white spaces on the beginning and on the end of a string */

	if (str != null && str != '') {

		while (str.charAt(0) == ' ')

			str = str.substring(1);

		while (str.charAt(str.length - 1) == ' ')

			str = str.substring(0, str.length - 1);

	}

	return str;

}