﻿
/////////////////////////////////////////////////////////
// set the lanuage cookie and bounce to the home page
function setLang(idLang)
{
	var d = new Date()
	d.setFullYear(d.getFullYear() + 1)

	document.cookie = "lang="+idLang+";expires="+d.toUTCString()+";path="+escape("/");
	if (location.href.indexOf("newsitem.aspx") != -1){
		location.href = location.href;
	}
	else {
		location.href = "/";
	}
}

/////////////////////////////////////////////////////////
// initialize the extranet chkbox click event
// on the registration page
function initXform()
{
	document.getElementById("chk_extranet").onclick = xformXpando;
}
function xformXpando()
{
	if (document.getElementById("chk_extranet").checked){
		document.getElementById("xform").style.display = "block";
	}
	else {
		document.getElementById("xform").style.display = "none";
	}
}

/////////////////////////////////////////////////////////
// clear the search form
function clrSearch()
{
	document.getElementById("s4").value = "";
	document.getElementById("cat_id").selectedIndex = -1;
	document.getElementById("catgroup").selectedIndex = -1;
	document.getElementById("year").selectedIndex = -1;
	document.getElementById("sdate").value = "";
	document.getElementById("edate").value = "";
}

/////////////////////////////////////////////////////////
// expando function for expandable divs
function expando()
{
	// get the link text
	var t = this.firstChild.nodeValue;

	// now get the "address" element sibling of "lnk"
	var addr = false;
	for (var x=0; x < this.parentNode.childNodes.length; x++){
		if (this.parentNode.childNodes[x].className == "address"){
			addr = this.parentNode.childNodes[x];
			break;
		}
	}
	if (!addr)
		return;

	if (addr.style.display == "none"){
		addr.style.display = "block";
		this.firstChild.nodeValue = "[-" + t.substring(2);
	}
	else {
		addr.style.display = "none";
		this.firstChild.nodeValue = "[+" + t.substring(2);
	}

	return false;
}

function init_expando_links()
{
	for (var x=0; x < document.links.length; x++){
		if (document.links[x].className == "expando"){
			document.links[x].onclick = expando;
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
// refresh the search form category list in response to a catgroup change
function doCatList(cgPtr)
{
	var req = createRequest();
	if (!req)
		return false;

	var clist = document.getElementById("cat_id");

	req.open("get","ajax.aspx?cmd=catlist&cgid="+escape(cgPtr.options[cgPtr.selectedIndex].value),true);
	req.onreadystatechange = function(){
								if (req.readyState == 4){
									if (req.status == 200){
										// remove the old option list
										for (var x=clist.options.length; x > 0; x--){
											clist.options[0] = null;
											//clist.options.remove(0);
										}
										// now insert the new items
										var json = eval("("+req.responseText+")");
										for (x = 0; x < json.length; x++){
											clist.options[x] = new Option(json[x][0],json[x][1]);
										}
									}
								}
							}
	req.send(null);
	return false;
}

////////////////////////////////////////////////////////////////////////////////
// create an XMLHttpRequest Object
function createRequest()
{
	var xhr = false;
	try {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");    // Trying Internet Explorer 
	}
	catch(e)    // Failed 
	{
		xhr = new XMLHttpRequest();    // Other browsers.
	}
	return xhr;
}
