function updateMap(field,v){
	/*Set the new Form Field*/
	document.getElementById(field).value=v;
	/*Set the Action Value*/
	document.getElementById('action').value='update_'+field;
	/*Submit the Form*/
	document.M.submit();
}


function switchSub(object){
	if(object.getElementsByTagName('ul').length > 0){
		fUl = object.getElementsByTagName('ul')[0];
		if(fUl.style['visibility'] != 'visible'){
			fUl.style['visibility'] = 'visible'
		}else{
			fUl.style['visibility'] = 'hidden'
		}
	}
}



function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}




function showSubmenu(whichDiv)
{
	var menus = new Array("subHome", "subProducts", "subData", "subServices","subPublications");
	
	for(var i = 0; i < menus.length; i++){
		
		if (document.getElementById)
		{
		// this is the way the standards work
		var style = document.getElementById(menus[i]).style;
		style.display = "none";
		}
		else if (document.all)
		{
		// this is the way old msie versions work
		var style = document.all[menus[i]].style;
		style.display = "none";
		}
		else if (document.layers)
		{
		// this is the way nn4 works
		var style = document.layers[menus[i]].style;
		style.display = "none";
		}		
	}
	
	
	if(whichDiv != 'none'){
	
	if (document.getElementById)
		{
		// this is the way the standards work
		var style = document.getElementById(whichDiv).style;
		style.display = "inline";
		}
	else if (document.all)
		{
		// this is the way old msie versions work
		var style = document.all[whichDiv].style;
		style.display = "inline";
		}
	else if (document.layers)
		{
		// this is the way nn4 works
		var style = document.layers[whichDiv].style;
		style.display = "inline";
		}
	
	}

}

var win_flag = 0;
function popNewWindow(url,name,features)
{
	win_flag = name
   new_window = window.open(url,name,features);
	new_window.focus();
}

function tinyPopup(url){
	OpenWin = window.open(url,"tinyPopup","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=300,height=250");
}
function snowfallPopup(url){
	OpenWin = window.open(url,"snowfallPopup","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=478,height=450");
}
function smallPopup(url){
	OpenWin = window.open(url,"smallPopup","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=500,height=500");
}
function snowsurveyPopup(url){
	OpenWin = window.open(url,"snowsurveyPopup","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=600,height=800");
}
function summaryPopup(url){
	OpenWin = window.open(url,"summaryPopup","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=625,height=500");
}
function droughtPopup(url){
	OpenWin = window.open(url,"droughtPopup","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=700,height=500");
}
function impactPopup(url){
	OpenWin = window.open(url,"impactPopup","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=750,height=500");
}
function climodPopup(url){
	OpenWin = window.open(url,"climodPopup","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=700,height=500");
}



function trim(myString){
 var newString = myString.replace(/^\s+|\s+$/g, "");
 return newString;
}


function obscureEmail(id,username,hostname,displayname){
    if (displayname=='' || displayname===undefined) displayname = username + '@' + hostname;
    if (document.getElementById(id)===null) {}
    else {
	var string = '<a href="mailto:' + username + '@' + hostname + '">' + displayname + '</a>';
	document.getElementById(id).innerHTML = string;
    }
}

$(document).ready(function() {
	obscureEmail('email_art','atd2','cornell.edu');
	obscureEmail('email_keith','kle1','cornell.edu');
	obscureEmail('email_kathy','kv14','cornell.edu');
	obscureEmail('email_jessica','jlr98','cornell.edu');
	obscureEmail('email_bill','noon','nrcc.cornell.edu');
	obscureEmail('email_dan','daz8','cornell.edu');
	obscureEmail('email_pam','pmv2','cornell.edu');
	obscureEmail('email_nrcc','nrcc','cornell.edu');
	obscureEmail('email_contact','nrcc','cornell.edu','Contact NRCC');
	obscureEmail('email_climod','climod_support','nrcc.cornell.edu');
    });



function changeImage(src,alt) {
	$('.featured_data')
		.item([
			{data_graphic:'<img src="'+src+'" alt="'+alt+'"/>'}
			])
		.chain();
}


function getURLVar(urlVarName) {
//CODE FROM http://techfeed.net/blog/index.cfm/2007/2/6/JavaScript-URL-variables
	//divide the URL in half at the '?'
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		//load all the name/value pairs into an array
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				//load the name/value pair into an array
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
					//I found a variable that matches, load it's value into the return variable
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	return urlVarValue;   
}
