// JavaScript Document
function urlJump(selectMenu) {
	var i = selectMenu.selectedIndex;
	var c = selectMenu[i].className;	
	var href = selectMenu[i].value;
	//alert(c);
	if(i > 0){
		if(c == 'p')
			window.open(href,'new','width=600,height=600,resizable=yes,scrollbars=yes');
		else 
			window.location = href;
	} 
}

//loads copy right year
function loadYear(){
var d = new Date();
document.write(d.getFullYear());
//document.write(d.getYear());
}

function checkAccreditationDIV(){
	var items = document.getElementsByTagName("div");
	var i;
	for(i=0; i< items.length;i++){		
		if((items[i].className != null) && (items[i].className == "right_button")){
				accbttn_flag =  true;
			}
	}
}


/* onload function to call function */
function addLoadEvent(func){
	var oldonload = window.onload;
	 if(typeof window.onload != 'function'){
	 	window.onload = func;
	 } else {
	 	window.onload = function() {
			oldonload();
			func();
		}
	 }
}

/* reset form fields with default values */
function resetFields(whichform){
	for(var i=0;i<whichform.elements.length; i++){
		var element = whichform.elements[i];
			if(element.type == "submit") continue;
				if(!element.defaultValue) continue;
			element.onfucus = function(){
				if(this.value == this.defaultValue){
					this.value = "";
				}
			}
			element.onblur = function(){
				if(this.value == ""){
					this.value = this.defaultValue;
				}
			}
			
	}

}

/* check for empty form fields */
function isFilled(field){
	if(field.value.length < 1 || field.value == field.defaultValue){
		return false;
	} else {
		return true;
	}
}

/* check for basic valid email syntax */
function isEmail(field){
	if(field.value.indexOf("@") == -1 || field.value.indexOf(".") == -1){
		return false;
	} else {
		return true;
	}
}

/* get form object and loop through and validate form elements */
function validateForm(whichform){
	for(var i=0; i<whichform.elements.length; i++){
		var element = whichform.elements[i];
			if(element.className.indexOf("required") != -1){
				if(!isFilled(element)){
					displayName = element.name.replace(/_/," ");
				alert("Please fill in the " + displayName + " field.");
				return false;
				}
			}
		if((element.name.indexOf("email") != -1) || (element.name.indexOf("Email") != -1)){
			if(!isEmail(element)){
				displayName = element.name.replace(/_/," ");
				alert("The " + displayName + " field must be a valid email address.");
				return false;
			}
		}
	}
	
	return true;
}

/* get form object on submit */
function prepareForms(){
	for(var i=0;i < document.forms.length; i++){
		var thisform = document.forms[i];
		resetFields(thisform);
		thisform.onsubmit = function() { return validateForm(this); }
	}
}


/***********************************************
* IFrame SSI script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
* dynammically resize iframe
***********************************************/
function dyniframesize() {
	var dyniframe=new Array()
	for (i=0; i<iframeids.length; i++){
		if (document.getElementById){ //begin resizing iframe procedure
		dyniframe[dyniframe.length] = document.getElementById(iframeids[i]);
		if (dyniframe[i] && !window.opera){
			dyniframe[i].style.display="block";
			if (dyniframe[i].contentDocument && dyniframe[i].contentDocument.body.offsetHeight) //ns6 syntax
				dyniframe[i].height = dyniframe[i].contentDocument.body.offsetHeight+FFextraHeight; 
			else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //ie5+ syntax
				dyniframe[i].height = dyniframe[i].Document.body.scrollHeight;
			}
		}
			//reveal iframe for lower end browsers? (see var above):
			if ((document.all || document.getElementById) && iframehide=="no"){
			var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
			tempobj.style.display="block";
		}
	}
}

/********************
* reset search field
*********************/
function resetField(form,field){
	eval("document." + form + "." + field + ".value=\"\"");
}

/*****************************************************
* show/hide
* used on News Page - can be used elsewhere
* if passed a link with name= "foo" will show/hide a div id= "foo_container"
*****************************************************/
function showHideDiv(whichlink) {
	if (!document.getElementById) return false;
	var num = whichlink.getAttribute("name");
	var story_id = num + "_container";
	var story_div = document.getElementById(story_id);
	if ( story_div.style.display == 'none') {
		story_div.style.display = 'block';
	}else{
		story_div.style.display = 'none';
	}
	return false;
}


/* generic pop up window with W/H parameters */
function openWindow(page,name,w,h){	
	var evalString = "window.open(";
								  
	if(page == ""){
		return false;
	} else {
		evalString += "'" + page + "'";
		
		if(name != ""){
			evalString += ",'" + name + "'";
		}	
		
		if(h != "" || w != ""){
		evalString += ",'";
			if(w != ""){
				evalString += "width = " + w + ",";
			}
			if(h != ""){
				evalString += "height = " + h;
			}
		evalString += "'";
		}
	}	
	
	evalString += ")";
	
	eval(evalString);
	}



/************************************
* return next element sibling node
*************************************/
function getNextSibling(startBrother){
  endBrother = startBrother.nextSibling;
  while(endBrother.nodeType != 1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
}


/************************************
* boolean: node not a comment
*************************************/
function notComment(e){
	if(e.nodeType != 8)
		return true;
	else
		return false;
	}
	

/************************************
* boolean: node is text node
*************************************/
function isText(e){
	if(e.nodeType == 3)
		return true;
	else
		return false;
}


/************************************
* hide element if no content
*************************************/
function hideRegion(element){
	var el = document.getElementsByTagName(element);
	var eCount = el.length;
	var kid;
	var test;
	var x;
	var keep = false;
	
	for(var i=0;i<eCount;i++){
	curr = el[i];
	kid = getNextSibling(curr);			
	test = kid.nodeName;
	keep = false;
	if(test == 'UL' || test == 'ul'){
		//alert(kid.nodeName);
		if(kid.hasChildNodes){
			var list = kid.childNodes;
			for(var j=0;j<list.length;j++){
				y = list[j];
				x = y.nodeName;
				if(x == 'LI' || x == 'li'){
					if(y.hasChildNodes){
						var s = y.childNodes;
							for(var k=0;k<s.length;k++){
									if(notComment(s[k]) && isText(s[k])){	
											keep = true;
										}
								}
						}
					

				}
				//alert(list[j].nodeName);
			}
		}
				
				if(!keep){//hide element if no <li> tags in <ul> sibling
					el[i].style.display = "none";						
				}	
										
		}
												
	}
				  
}
