/***********************************************
* Contractible Headers script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated Mar 23rd, 2004.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

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

if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none; padding:0px 0px 0px 0px;}')
document.write('</style>')
}

function getElementbyClass(classname){
ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
ccollect[inc++]=alltags[i]
}
}

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

function expandcontent(cid){
if (typeof ccollect!="undefined"){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
}
}

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 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"
getElementbyClass("switchcontent")
if (enablepersist=="on" && typeof ccollect!="undefined"){
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 (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


/****************************************************
* 
* 
* 
****************************************************/
function content_loader(divname)
{
	if (document.getElementById(divname))
			if (document.getElementById(divname).getAttribute('src'))
				PassAjaxResponseToFunction(document.getElementById(divname).getAttribute('src'), 'content_load', "\'"+divname+"\'");
}
function content_load(response, divname)
{
	document.getElementById(divname).innerHTML = response;
	init(document.getElementById(divname));
}
function anchor_loader(divname, src)
{
	if(document.getElementById(divname))
	{
		document.getElementById(divname).setAttribute('src', src);
		content_loader(divname);
	}
}
/********************************************************************
* 
* 
* 
*********************************************************************/
function content_init(obj) {
	if (!obj) return
	var divarr = obj.getElementsByTagName('div');
	for (var i = 0; i < divarr.length; i++) 
		if (divarr[i].getAttribute('src')) 
			content_loader(divarr[i].getAttribute('id'));
}

/****************************************************
* Create image rollovers for any image with the 
* the attribute 'hsrc'. The attribute should have 
* the down image. The parameter obj is a Dom object.
****************************************************/
function rollovers_init(obj)
{

	var imgarr = obj.getElementsByTagName('img');

	for (var i = 0; i < imgarr.length; i++) {
	
		if (imgarr[i].getAttribute('hsrc') && !imgarr[i].onmouseover) {
		
			imgarr[i].onmouseover = function() {
				var imgOriginSrc = this.getAttribute('src');
				this.setAttribute('src',this.getAttribute('hsrc'))
				this.setAttribute('hsrc',imgOriginSrc)
			}
			imgarr[i].onmouseout = function() {
				var imgOriginSrc = this.getAttribute('src');
				this.setAttribute('src',this.getAttribute('hsrc'))
				this.setAttribute('hsrc',imgOriginSrc)
			}
		}
	}
}
/********************************************************************
* Change all anchors tags within a DIV that has the target attribute
* to target another DIV rather than a frame, iframe or window. 
* The anchors will have there hrefs replaced with a 
* javascript function that loads the url to the 
* targeted DIV. 
* 
* Only DIVS with the attribute 'target' will be effected.
**********************************************************************/
function target_init(obj)
{
	if (!obj)
		return;

	if (!obj.getAttribute)		
		return;
	
	var attr = obj.getAttribute('target');
	if (!attr)
		return;

	var anchorarr = obj.getElementsByTagName('a');
	for (var i = 0; i < anchorarr.length; i++)
	{ 
		var link = anchorarr[i].getAttribute('href');
		if (link) 
			anchorarr[i].setAttribute("href", "javascript:anchor_loader(\'"+attr+"\',\'" +link+ "\')");
	}
}

/********************************************************************
* 
* 
* 
*********************************************************************/
function init(obj)
{
	target_init(obj);
	rollovers_init(obj);
	content_init(obj);
}

if(typeof window.onload == 'function')
{
	var existing = onload;
	window.onload = function()
	{
		existing();
		init(document);
	};
}
else
{
	window.onload = function()
	{
		init(document);
	};
}


// end DOM image rollover -->
/**
SAL - Simple Ajax Lib. 23-Sep-2005
by Nigel Liefrink
Email: leafrink@hotmail.com
*/

var debug = false;
/**
Browser Compatability function.
Returns the correct XMLHttpRequest depending on the current browser.
*/
function GetXmlHttp() {	
	var xmlhttp = false;
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
  }
	else if (window.ActiveXObject)// code for IE
	{
		try 
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp=false;
			}
		}
	}
	return xmlhttp;
}


/**
<summary>
Gets the response stream from the passed url, and then calls the callbackFuntion passing the response and the div_ids.
</summary>
<param name="url">The url to make the request to get the response data.</param>
<param name="callbackFunction">The function to call after the response has been recieved. the response <b>must</b> always be the first argument to the function.</param>
<param name="params"> (optional) Any other parameters you want to pass to the functions. (Note: only constants/strings/globals can be passed as params, most variables will be out of scope.) </param>
</summary>
<example>
	<code>
PassAjaxResponseToFunction('?getsomehtml=1', 'FunctionToHandleTheResponse', "\'div1\',\'div2\',\'div3\'');

function FunctionToHandleTheResponse(response, d1, d2, d3){
	var data = response.split(';');
	document.getElementById(d1).innerHTML = data[0];
	document.getElementById(d2).innerHTML = data[1];
	document.getElementById(d3).innerHTML = data[2];
}
	</code>
</example>
*/
function PassAjaxResponseToFunction(url, callbackFunction, params)
{		
  var xmlhttp = new GetXmlHttp();
  //now we got the XmlHttpRequest object, send the request.
  if (xmlhttp)
  {
    xmlhttp.onreadystatechange = function () 
                                {
	                                if (xmlhttp && xmlhttp.readyState==4)
	                                {//we got something back..
		                                if (xmlhttp.status==200)
		                                {
			                                var response = xmlhttp.responseText;
			                                var functionToCall = callbackFunction+'(response,'+params+')';
			                                if(debug){
				                                alert(response);
				                                alert (functionToCall);
			                                }
			                                eval(functionToCall);
		                                } else if(debug){
			                                document.write(xmlhttp.responseText);
		                                }
	                                }
                                }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
  }
}
/**
///<summary>
///Sets the innerHTML property of obj_id with the response from the passed url./
///</summary>
///<param name="url">The url to make the request to get the response data.</param>
///<param name="obj_id">The object or the id of the object to set the innerHTML for.</param>
*/
function SetInnerHTMLFromAjaxResponse(url, obj_id)
{		
  var xmlhttp = new GetXmlHttp();
  //now we got the XmlHttpRequest object, send the request.
  if (xmlhttp)
  {
    xmlhttp.onreadystatechange = function () 
                                {
	                                if (xmlhttp && xmlhttp.readyState==4)
	                                {//we got something back..
		                                if (xmlhttp.status==200)
		                                {
			                                if(debug){
				                                alert(xmlhttp.responseText);
			                                }
			                                if(typeof obj_id == 'object'){
				                                obj_id.innerHTML = xmlhttp.responseText;
			                                } else {
				                                document.getElementById(obj_id).innerHTML = xmlhttp.responseText;
			                                }
		                                } else if(debug){
			                                document.Write(xmlhttp.responseText);
		                                }
	                                }
                                }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
  }
}



