var locStr=document.location.href;
menu_status = new Array();
  if (navigator.appName == "Netscape") {
        //  window.addEventListener("load", function(e) { init(); }, false);
	 if (document.addEventListener) {  
		document.addEventListener("DOMContentLoaded", init, false);
	} 
 } else {
	window.onload = init;
 }
function init() {
      dsds_onload();
      // alert(locStr);
      var start = locStr.lastIndexOf("/"+1 );
      if (start <1) {
         start = locStr.lastIndexOf("_"+1 );
      }
      locStr = locStr.substring(start);

      var group = get_cookie (locStr + "_group");
      if (group && group != "") {
        hideShowTabs(group);
	// alert(document.cookie);
      } else {
        document.getElementById('s1').style.display="block";
      } 
      var question = get_cookie (locStr + '_question');
      if (question && question != "") {
        document.getElementById(question).style.display="block";
      }
};
function dsds_onload() {
	var ln=1, // lnk number
	lo=1; // lnk object
	
	for (; lo; ++ln) {
		lo = document.getElementById('lnk' + ln);
		if (lo) {
			lo.appId = 'app' + ln;
			lo.onclick = dsds_onclick;
		}
	}
	window.currentAppId = null; // global
}
// assumes app elements have display:none initially
function dsds_onclick() {
	var e;
        // alert("click");
	if (currentAppId && currentAppId != this.appId) {
		e = document.getElementById(currentAppId);
		e.style.display = 'none';
	}
	e = document.getElementById(this.appId);
	if (e.style.display == 'block') {
		e.style.display = 'none';
		currentAppId = null;
	}
	else {
		e.style.display = 'block';
		currentAppId = this.appId;
                set_cookie(locStr + "_question",currentAppId);

	}
	return false;
}
var curOpen = '';
function hideShowTabs(active) {
	// alert("curOpen:"+curOpen);
	if(curOpen == active){
		document.getElementById(active).style.display = 'none';
		curOpen = '';
	} else {
		for(var i=1; i<=1; i++) {
				document.getElementById('s'+i).style.display = 'none';
		}	
		document.getElementById(active).style.display = 'block';
		curOpen = active;	
		set_cookie(locStr + "_group",curOpen);
	}
	  dsds_onload();
}
function get_cookie ( cookie_name )
{
	var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

	if ( results )
	return ( unescape ( results[1] ) );
	else
	return null;
}

function set_cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = 30 * 1000 * 60;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );

}
