// Stop all JavaScript errors

/*
function stoperror(){
	return true;
}
window.onerror=stoperror;
*/

// Popups

function popup(url)
{
 popupWindow=window.open(url,"WebEd","toolbar=no,directories=no,status=yes,scrollbars=yes,resizable=yes,menubar=no");
 popupWindow.focus();
}

function popupTerm(url)
{
 popupTermWindow=window.open(url,"Term","width=600,height=400,toolbar=no,directories=no,status=yes,scrollbars=yes,resizable=yes,menubar=no");
 popupTermWindow.focus();
}

// Generic rollover functions

function overImage(imgName) {
	if (document.images) {
		imgOn = eval(imgName + "on.src");
		document [imgName].src = imgOn;	
	}
}

function offImage(imgName) {
	if (document.images) {
		imgOff = eval(imgName + "off.src");
		document [imgName].src = imgOff;	
	}
}

function overNav(which) {
	document.getElementById(which).className = "rednav";
}

function offNav(which) {
	document.getElementById(which).className = "bluenav";
}

// Cookie functions

function getCookie( 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 setCookie( name, value, path, expires, domain, secure ) {
  var today = new Date();
  today.setTime( today.getTime() );
  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() : "" ) + //expires.toGMTString()
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

function deleteCookie( name, path, domain ) {
  if ( getCookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// Nav Open/Close functions

navContent=new Array();

function navClose(whichDiv) {
	document.getElementById('nav'+whichDiv+'Image').src=eval('nav'+whichDiv+'off.src');
	navContent[whichDiv]=document.getElementById('nav'+whichDiv).innerHTML;
	document.getElementById('nav'+whichDiv).innerHTML='';
	setCookie('nav'+whichDiv+'Status',0,'/',365);
}

function switchNav(whichDiv) {
	if (document.getElementById('nav'+whichDiv).innerHTML=='') {
		document.getElementById('nav'+whichDiv+'Image').src=eval('nav'+whichDiv+'on.src');
		document.getElementById('nav'+whichDiv).innerHTML=navContent[whichDiv];
		setCookie('nav'+whichDiv+'Status',1,'/',365);
	} else {
		navClose(whichDiv);
	}
}

function switchDiv(whichDiv) {
	if (document.getElementById(whichDiv).innerHTML=='') {
		document.getElementById(whichDiv).innerHTML=document.getElementById(whichDiv+'Hold').innerHTML;
		document.getElementById(whichDiv+'Hold').innerHTML='';
	} else {
		document.getElementById(whichDiv+'Hold').innerHTML=document.getElementById(whichDiv).innerHTML;
		document.getElementById(whichDiv).innerHTML='';
	}
}

function navStart(whichDiv) {
	if (getCookie('nav'+whichDiv+'Status')==0) {
		navClose(whichDiv);
	}
}

// Preload and name all rollover images

function loadImages() {
	Nhomeon = new Image();
	Nhomeon.src = "http://www.alta.org/images/N-home1.gif";
	Nhomeoff = new Image();
	Nhomeoff.src = "http://www.alta.org/images/N-home0.gif";
	Nmemberson = new Image();
	Nmemberson.src = "http://www.alta.org/images/N-members1.gif";
	Nmembersoff = new Image();
	Nmembersoff.src = "http://www.alta.org/images/N-members0.gif";
	Nconsumerson = new Image();
	Nconsumerson.src = "http://www.alta.org/images/N-consumers1.gif";
	Nconsumersoff = new Image();
	Nconsumersoff.src = "http://www.alta.org/images/N-consumers0.gif";
	Njoinon = new Image();
	Njoinon.src = "http://www.alta.org/images/N-join1.gif";
	Njoinoff = new Image();
	Njoinoff.src = "http://www.alta.org/images/N-join0.gif";
	Nabouton = new Image();
	Nabouton.src = "http://www.alta.org/images/N-about1.gif";
	Naboutoff = new Image();
	Naboutoff.src = "http://www.alta.org/images/N-about0.gif";
	Nmeetingson = new Image();
	Nmeetingson.src = "http://www.alta.org/images/N-meetings1.gif";
	Nmeetingsoff = new Image();
	Nmeetingsoff.src = "http://www.alta.org/images/N-meetings0.gif";
	Nadvocacyon = new Image();
	Nadvocacyon.src = "http://www.alta.org/images/N-advocacy1.gif";
	Nadvocacyoff = new Image();
	Nadvocacyoff.src = "http://www.alta.org/images/N-advocacy0.gif";
	Nnewsroomon = new Image();
	Nnewsroomon.src = "http://www.alta.org/images/N-newsroom1.gif";
	Nnewsroomoff = new Image();
	Nnewsroomoff.src = "http://www.alta.org/images/N-newsroom0.gif";
	Npublicationson = new Image();
	Npublicationson.src = "http://www.alta.org/images/N-publications1.gif";
	Npublicationsoff = new Image();
	Npublicationsoff.src = "http://www.alta.org/images/N-publications0.gif";
	Ntrainingon = new Image();
	Ntrainingon.src = "http://www.alta.org/images/N-training1.gif";
	Ntrainingoff = new Image();
	Ntrainingoff.src = "http://www.alta.org/images/N-training0.gif";
	Nstoreon = new Image();
	Nstoreon.src = "http://www.alta.org/images/N-store1.gif";
	Nstoreoff = new Image();
	Nstoreoff.src = "http://www.alta.org/images/N-store0.gif";
	Nresourceson = new Image();
	Nresourceson.src = "http://www.alta.org/images/N-resources1.gif";
	Nresourcesoff = new Image();
	Nresourcesoff.src = "http://www.alta.org/images/N-resources0.gif";
}

if (document.images) {
	loadImages();
}


// Returns a handle to the named layer.

function getLayer(name) {

	if (document.layers) {
		return(document.layers[name]);
	}
	else {
		layer = document.getElementById(name);
		if (layer) {
			return(layer);
		} else {
			return(null);
		}
	}
}


// Hides the named layer

function hideLayer(name) {

	var layer = getLayer(name);

	if (layer.style) {
		layer.style.visibility="hidden";	
	} else {
		layer.visibility="hide";
	}

}


// Shows the named layer

function showLayer(name) {

	var layer = getLayer(name);

	if (layer.style) {
		layer.style.visibility="visible";	
	} else {
		layer.visibility="show";
	}

}

function getInnerText(node,ignorewhitespace)
{
 var text = "";
 // if the node has children, loop through them
 if(node.hasChildNodes())
 {
  var children = node.childNodes;
  for(var i=0; i<children.length; i++)
  {
   // if node is a text node append it
   if(children[i].nodeName == "#text")
   {
    if(ignorewhitespace)
    {
     if(!/^\s+$/.test(children[i].nodeValue))
     {
      text = text.concat(children[i].nodeValue);
     }
    }
    else
    {
     text = text.concat(children[i].nodeValue);
    }
   }
   // if node is a line break append \n
   else if(children[i].nodeName == "BR")
   {
    text = text.concat("\n");
   }
   // otherwise call this function again to get the text
   else
   {
    text = text.concat(getInnerText(children[i]));
   }
  }
 }
 // it has no children, so get the text
 else
 {
  // if node is a text node append it
  if(node.nodeName == "#text")
  {
   text = text.concat(node.nodeValue);
  }
  // if node is a line break append \n
  else if(node.nodeName == "BR")
  {
   text = text.concat("\n");
  }
 }
 return text;
}


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2400;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

