// these are functions that need to appear on every page
function validateEmail() {
	var e = document.getElementById("newsletter_email").value;

	if (e == "") {
		alert("Please enter an email address in the field provided!");
		return false;
	} else if (e.indexOf("@") == -1 || e.indexOf(".") == -1) {
		alert("Please enter a valid email address in the field provided!");
		return false;
	} else {
		return true;
	}
	
}

function address(which) {
	document.getElementById("addresses").className = "sel_" + which;
}

//leaving the senate servers so we have to display this message:
function openWin(urlToOpen) {
	window.open(site_webroot + "redirect/?r=" + encodeURIComponent(location.hostname) + "&u=" + encodeURIComponent(urlToOpen));
}

//leaving the current site, but staying on senate servers.
function openSenateWin(urlToOpen) {
	window.open(urlToOpen);	
}


//used throughout the site to show link descriptions in the status bar instead of javascript window.opens.
function showLinkDescription(linkDesc) {
	//alert("linkDesc:" + linkDesc);
	window.status="hello there";	
	//alert(window.status);
	
	
}

//called on mouse out to clear the status bar.
function clearStatus() {
	
	window.status="";	
	
}



function search() {
		document.getElementById("supra_nav_links").style.display = "none";
		document.getElementById("supra_nav_search").style.display = "";
		document.getElementById("search_terms").focus();
	}
	
	function validateSearch() {
		if (document.getElementById("search_terms").value != "") {
			return true;
		} else {
			return false;
		}
	}
	
	function hideSearch() {
		document.getElementById("supra_nav_search").style.display = "none";
		document.getElementById("supra_nav_links").style.display = "";
	}
	
//font size functions
var currentSize = 1;
var textIncrease = null; 
var textDecrease = null; 

/**
function setCookie(name, value) {
	var today = new Date();
	today.setYear(today.getYear()+7);
	var expirationDate = today.toGMTString();
	var cookieData = (name + "=" + value);
	document.cookie = "brown_user_preferences=" + cookieData +";expires=" + expirationDate + ";path=/"; }
**/


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 = expires * 1000 * 60 * 60 * 24;
	}
	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" : "" );
}
			


/**
function getCookie() {
	//alert(document.cookie);
	if(document.cookie != "") {
		var cookieData = document.cookie;
		cookieData = cookieData.substring((cookieData.indexOf("=") + 1), cookieData.length);
		if(cookieData.indexOf("font")) {
			fontSize = cookieData.substring((cookieData.lastIndexOf("=") + 1), cookieData.length);
			return(fontSize); }
	} else { /* alert("there is no cookie"); */ //}}

// 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 ) );
}
/*
function setFontPreference(toSize) {
	//setCookie("font", toSize) }
	Set_Cookie( "font", toSize, 1, "/", "brown.creativengine.com", false )	
}

function setFontSize(inc,savePref)
{

  var p = document.getElementsByTagName('p');
  for(n=0; n<p.length; n++) {
    if(p[n].style.fontSize) {
       var size = parseInt(p[n].style.fontSize.replace("px", ""));
    } else {
       var size = 12;
    }
    p[n].style.fontSize = (size * 1) + (inc * 1) + 'px';
   }
   
   var a = document.getElementsByTagName('a');
  for(n=0; n<a.length; n++) {
    if(a[n].style.fontSize) {
       var size = parseInt(a[n].style.fontSize.replace("px", ""));
    } else {
       var size = 12;
    }
    a[n].style.fontSize = (size * 1) + (inc * 1) + 'px';
   }
   
   if(savePref) {
   	setFontPreference((size * 1) + (inc * 1));
   	//alert("just set font size cookie to : " + (size * 1) + (inc * 1));
   	//alert("font size cookie is: " + Get_Cookie("font"));
   }
}

function setPageFontSizeOnLoad() { 
	//every time a page loads, check if the font size pref is set, and set the font size
	var fontSize;
	if(Get_Cookie("font")) {
		fontSize=Get_Cookie("font");
		//alert("setting font size on load to : " + fontSize);
		//setFontSize(Get_Cookie("font"),false);
		
	
		var p = document.getElementsByTagName('p');
		  for(n=0; n<p.length; n++) {

			if(p[n].style.fontSize) {
			   var size = parseInt(p[n].style.fontSize.replace("px", ""));
			} else {
			   var size = 12;
			}
			p[n].style.fontSize =fontSize + 'px';
		   }
		   
		  var a = document.getElementsByTagName('a');
		  for(n=0; n<a.length; n++) {
			if(a[n].style.fontSize) {
				if (original_a_font_size == 0) original_p_font_size = p[n].style.fontSize;
			   var size = parseInt(a[n].style.fontSize.replace("px", ""));
			} else {
			   var size = 12;
			}
			a[n].style.fontSize = fontSize + 'px';
		   }
   
   	}
}
*/

function CE_FixIE6(which) {
	document.getElementById("font_select").style.cssText = "background-position:0px 0px";
	document.getElementById("font_select_med").style.cssText = "background-position:0px 0px";
	document.getElementById("font_select_large").style.cssText = "background-position:0px 0px";
	if (which == "") {
		document.getElementById("font_select").style.cssText = "background-position:0px -14px";
	} else {
		document.getElementById("font_select_" + which).style.cssText = "background-position:0px -14px";
	}
}

function CE_SetPageFont(which) {
	document.body.className = "body_" + which;
	document.getElementById("supra_nav_links").className = which;
	document.getElementById("supra_nav_links").setAttribute("className", which);

	// IE6 hack
	if (document.all && !window.XMLHttpRequest) {
		CE_FixIE6(which);
	}
	var domain = site_webroot.substring(site_webroot.indexOf("http://") + 7, site_webroot.length - 1);
	Set_Cookie("font_size", which, 1, "/", domain, false);
}

function CE_LoadPageFont() {
	if(Get_Cookie("font_size")) {
		fs = Get_Cookie("font_size");
		document.body.className = "body_" + fs;
		document.getElementById("supra_nav_links").className = fs;
		
		// IE6 hack
		if (document.all && !window.XMLHttpRequest) {
			CE_FixIE6(fs);
		}
	}
}
