function addDays(myDate,days) 
{
    return new Date(myDate.getTime() + days*24*60*60*1000);
}


function randomNum (  startNum, endNum )
{
	// arguments - pass 2 integers, the first possible random number to return, and the last possible number to return
	// returns a single integer between the range of startNum and endNum
	
	var plusNum = endNum - startNum;
	var ranNum = Math.round( (Math.random() * plusNum) + startNum);
	return ( ranNum );
}


function setCookie(name, value, days)
{
	if(value == "")
	{
		var the_value = "true";
	}
	else
	{
		var the_value = value;
	}
	var the_date = addDays(new Date(), days);
	var the_cookie_date = the_date.toGMTString();
	var the_cookie = name + " = " + the_value;
	the_cookie = the_cookie + ";path=/;expires=" + the_cookie_date;
	//alert(the_cookie);
	document.cookie = the_cookie;
}

function getCookie(cookiename)
{
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return ""; 
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}



// THIS SCRIPT DOES THE DOUBLE SWAP (CLOSES THE POP-UP, CHANGES THE PARENT)
// USAGE: <A HREF="#" onClick="DoubleSwap('http://www.domain.com')">text link</A>
function DoubleSwap(URL)
{
	window.opener.location = URL;
	window.close();
}

// THIS SCRIPT RUNS THE POPUP WINDOWS
// USAGE: <a href="javascript:NewWindow('page.html', 'nameOfWindow', 500, 300, 1, 1)">Text Link</a>
function NewWindow(url, myname, w, h, scroll, resize) 
{
	winprops = 'height='+h+',width='+w+',top=10,left=10,scrollbars='+scroll+',resizable='+resize+',toolbar=0'
	win = window.open(url, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// THIS SCRIPT RUNS A POPUP WINDOW THAT ONLY DISPLAYS ONCE EVERY 0.5 days:
// USAGE: onLoad="popup('page.html', 'nameOfWindow', 500, 300, 1, 1)"
function popup(url, myname, w, h, scroll, resize)
{
	//get cookie:
	popupDisplayed = getCookie(popupDisplayed);
	
	if(popupDisplayed != 'Y')
	{
		NewWindow(url, myname, w, h, scroll, resize);
	}
	
	//set cookie:
	setCookie('popupDisplayed', 'Y', '0.5');
}




// THIS SCRIPT RUNS THE DROPDOWN MENUS
// USAGE: <DIV CLASS="navBlock" onMouseOver="this.className='navBlockHover'; change('subs1', 'subNavHover'); change('flash', 'flashHide'); change('flash2', 'flashHide')" onMouseOut="this.className='navBlock'; change('subs1', 'subNavHide'); change('flash', 'flashShow'); change('flash2', 'flashShow')" onClick="this.className='navBlock'; change('subs1', 'subNavHide'); change('flash', 'flashShow'); change('flash2', 'flashShow')" STYLE="margin-left: 10px; width: 130px;">
function change(id, newClass)
{
	if(document.getElementById(id) == null)
	{
		//do nothing
	}
	else
	{
		var identity = document.getElementById(id);
		identity.className = newClass;
	}
}



//Perspectives specific functions//
function setmyclass () {
	var locate = window.location;
	setCookie('myclass', locate, '365');
	change('setmyclass', 'hidden');
	change('findnewclass', 'displayed');
}

function findnewclass () {
	setCookie('myclass', '', '-1');
	change('findnewclass', 'hidden');
	change('setmyclass', 'displayed');
	// forward the window to the Find A Class page on the Perspectives site...
	//alert('You will be forwarded to http://www.kintera.org/site/lookup.asp?c=eqLLI0OFKrF&b=2818097')
	window.location = "http://www.kintera.org/site/lookup.asp?c=eqLLI0OFKrF&b=2818097";
	  
}

function displayMyClassBtn() {
	var urlredirection=getCookie('myclass'); 
	if(urlredirection== "undefined" || urlredirection== "" || urlredirection== null) {
		change('findnewclass', 'hidden');
		change('setmyclass', 'displayed');
	}
	else
	{
		change('setmyclass', 'hidden');
		change('findnewclass', 'displayed');
	}	
}











