
// ----------------------- Search pop-open layers ("CHOOSING AND USING...") -----------------------


var num=10;

function Set_Cookie( name, value) 
{

document.cookie = name + "=" +escape( value ) + ";path=/" ; 
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );	
	if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
}
	
// this deletes the cookie when called
function Delete_Cookie( name) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" + ";path=/" + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function clearPopupsStatus(){
	Delete_Cookie("popups"); 
	Set_Cookie("popups", ""); 
}

var popups = '';
function setPopupsStatus()
{
	
	for (i = 0 ; i < num ; i++)
	{
 		var elementId = 'choosingUsing_' + i;
		var objElement = document.getElementById(elementId); 
		if (objElement != null){
			if (objElement.style.display == 'block')
				popups += i+":open&";
			else
				popups += i+":closed&";
	
		}
	}
	Delete_Cookie("popups"); 
	Set_Cookie("popups",  popups);
}


function getPopupsStatus(){
	if (Get_Cookie('popups')) 
	{ 
		arrowUp = new Image;
		arrowDown = new Image;
		arrowUp.src = "images/btnExpandClsd.gif";
		arrowDown.src = "images/btnExpand.gif";
		var popups_all = Get_Cookie('popups'); 
		var separated_values = popups_all.split("&");
		var property_value = "";
		var theInfo = new Array();

		for (var loop = 0; loop < separated_values.length-1; loop++)
		{
			property_value = separated_values[loop];
			var broken_info = property_value.split(":");
			var the_property = broken_info[0];
			var the_value = broken_info[1];
			theInfo[the_property] = the_value;
		}
		
		for (var loop = 0;loop  < theInfo.length ; loop++)
		{
			var elementId = 'choosingUsing_' + loop;
			var objElement = document.getElementById(elementId);
			var arrow = document[ elementId + '_arrow' ];
			if (objElement != null){
				if (theInfo[loop] == 'open')
					{	
					objElement.style.display = 'block';
					if(arrow)
						arrow.src = arrowDown.src;
					}
				else
				{
					objElement.style.display = 'none';
					if(arrow)
					{
						arrow.src = arrowUp.src;
					}
				}
			}
		} 
	}  
}

	
function toggleVisibility( elementID ) {
	arrowUp = new Image;
	arrowDown = new Image;
	arrowUp.src = "images/btnExpandClsd.gif";
	arrowDown.src = "images/btnExpand.gif";
	var objElement = document.getElementById( elementID );
	var arrow = document[ elementID + '_arrow' ];
	if ( objElement != null ) {
		if ( objElement.style.display == 'block' ) {
			objElement.style.display = 'none';
			if(arrow)
			{
				arrow.src = arrowUp.src;
			}
			clickWasToOpen = false;
		}
		else {
			objElement.style.display = 'block';
			if(arrow)
				arrow.src = arrowDown.src;
			clickWasToOpen = true;
		}
	}
	setTimeout( "setPopupsStatus();", 100 );
}

var clickWasToOpen = true; // as opposed to a click that closes the layer

// Click-stream logging of C&U visibility toggling
function logCUClick( url ) {
	if ( clickWasToOpen )
		dlese_asyncRequest( url, donothing );
}
 
function donothing() {}

var popWin = null;
function popupWin(url, w, h){
	if(!w)
		w = 750;
	if(!h)
		h = 650;

	popWin=window.open(url, "popWin", "scrollbars,resizable,width="+w+",height="+h);
	if(popWin == null)
		alert("Please enable popups for this site. The help window could not be displayed.");
	else
		popWin.focus();
}

