var currentDiv;
function showContent(listEl,content){
	if($(currentDiv)){
		$(currentDiv+"-li").className="";
		$(currentDiv).style.display="none";
	}
	currentDiv=content;
	$(currentDiv).style.display="block";
	$(currentDiv+"-li").className="selected";
}

/*
	Write Flash Object Into Divs
		Example:
			<div id="services-menu"></div>
			<script language="javascript">writeFlash('services-menu','services-flash','services-menu.swf','239','127','window','#FFFFFF');</script>
		// PARAMETER NOTES: wmode and bgcolor are not required
*/
function writeFlash(holderId,id,file,width,height,wmode,bgcolor) {
	var objectvar="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+width+"' height='"+height+"' id='"+id+"' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='"+file+"' /><param name='loop' value='false' /><param name='menu' value='false' /><param name='quality' value='high' />";
	if(bgcolor!=null){
		objectvar+="<param name='bgcolor' value='"+bgcolor+"' />";
		var embedbgcolor="bgcolor='"+bgcolor+"'";
	}
	if(wmode==null){
		wmode='transparent';	
	}
	objectvar+="<param name='wmode' value='"+wmode+"' /><embed src='"+file+"' loop='false' menu='false' quality='high' wmode='"+wmode+"' "+embedbgcolor+" width='"+width+"' height='"+height+"' id='"+id+"' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	document.getElementById(holderId).innerHTML = objectvar;
} 

function get(elName){
	if(document.getElementById){
		if(temp=document.getElementById(elName)){
			return temp;
		}
		else{
			return false;
		}
	}
	else{
		throw new Error("This browser does not support the function document.getElementById()");
	}
}

String.prototype.trim=function(){
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};
String.prototype.reverse=function(){
	var newStr="";
	for (i=0;i<=this.length;i++){
		newStr = this.charAt(i) + newStr;
	}
	return newStr;
}
String.prototype.replaceAll=function(needle,replacement){
	string=this;
	while(string.indexOf(needle)!=-1){
		string=string.replace(needle," ");
	}
	return string;
}	
String.prototype.toProperCase=function(){
	return this.toLowerCase().replace(/^(.)|\s(.)/g,function($1){return $1.toUpperCase();});
};
document.getElementsByClassName=function(clsName,names){
	if(typeof(clsName)=="string"){
		var retVal=new Array();
		var elements=document.getElementsByTagName("*");
		for(i=0;i<elements.length;i++){
			if(names){
				if(elements[i].className.indexOf(" ")>=0){
					var classes=elements[i].className.split(" ");
					for(var j=0;j<classes.length;j++){
						if(classes[j]==clsName){
							retVal.push(elements[i].id);
						}
					}
				}
				else if(elements[i].className==clsName){
					retVal.push(elements[i].id);
				}
			}
			else{
				if(elements[i].className.indexOf(" ")>=0){
					var classes=elements[i].className.split(" ");
					for(var j= 0;j < classes.length;j++){
						if(classes[j]==clsName){
							retVal.push(elements[i]);
						}
					}
				}
				else if(elements[i].className==clsName){
					retVal.push(elements[i]);
				}	
			}
		}
		return retVal;
	}
	else{
		throw new Error("document.getElementsByClassName() must be passed a string representation of a class name");	
	}
};
document.getElementsByAttribute=function(attribute,names){
	if(typeof(attribute)=="string"){
		var retVal = new Array();
		var elements = document.getElementsByTagName("*");
		for(i = 0;i < elements.length;i++){
			if(names==false){
				if(elements[i].getAttribute(attribute)){
					retVal.push(elements[i].id+":"+elements[i].getAttribute(attribute));
				}
			}
			else{
				if(elements[i].getAttribute(attribute)){
					retVal.push(elements[i].id)
				}
			}
		}
		return retVal;
	}
	else{
		throw new Error("document.getElementsByAttribute() must be passed a string representation of an attribute name");	
	}
};
Array.prototype.inArray = function (value,caseSensitive){
	for (i=0;i<this.length;i++) {
		if(!caseSensitive){
			if(this[i].toLowerCase()==value.toLowerCase()){
				return true;
			}
		}
		else{
			if(this[i]==value){
				return true;
			}
		}
	}
	return false;
};

function enforceNumeric(field,e,next,len,allowed){
	if(next && len){
		tab=true;
	}
	char=e.charCode?e.charCode:e.keyCode;
	if (char!=8&&char!=46){
		if (char<48||char>57){
			if(allowed&&allowed.length>0){
				for(i=0;i<allowed.length;i++){
					if(allowed.inArray(char)){
						if(tab===true){
							autoTab();	
						}
						return true;
					}
					else{
						return false;	
					}
				}
			}
			else{
				return false;	
			}
		}
		else{
			if(tab===true){
				autoTab();	
			}
			return true;
		}
	}
	else if(char==46){
		if(field.value.indexOf(".")==-1){
			if(tab===true){
				autoTab();	
			}
			return true;
		}
		else{
			return false;	
		}
	}
	
	function autoTab(){
		if(field.value.length==(len-1)){
			next.focus();
		}
	}
}

function enforceNumericAT(field,e,allowed){
	char=e.charCode?e.charCode:e.keyCode;
	if (char!=8&&char!=46){
		if (char<48||char>57){
			if(allowed&&allowed.length>0){
				for(i=0;i<allowed.length;i++){
					if(!allowed.inArray(char)){
						field.value=field.value.substring(0,(field.value.length-1));	
					}
				}
			}
			else{
				field.value=field.value.substring(0,(field.value.length-1));	
			}
		}
	}
	else if(char==46){
		if(!field.value.indexOf(".")==-1){
			field.value=field.value.substring(0,(field.value.length-1));	
		}
	}
}

function autoTab(field,len,next){
	if (window.XMLHttpRequest || window.ActiveXObject){
		if(field.value.length==len){
			next.focus();
		}
	}
	else{
		if(field.value.length==len){
			next.focus();
		}
	}
}

function enforceAlphaNumeric(field,e){
	char=e.charCode?e.charCode:e.keyCode;
	if((char>=48&&char<=57)||(char>=65&&char<=90)||(char>=97&&char<=122)){
		return true;
	}
	else{
		return false;	
	}
}
function rgbToHex(value){
	if (typeof(value)!=="string") {
		return false;
	}
	var result=value.match(/^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*/);
	if(result==null){ 
		return value; 
	}
	var rgb = +result[1] << 16 | +result[2] << 8 | +result[3];
	var hex="";
	var digits="0123456789ABCDEF";
	while(rgb!=0){ 
		hex=digits.charAt(rgb&0xf); 
		rgb >>>= 4; 
	} 
	while(hex.length<6){ 
		hex='0'+hex; 
	}
	return "#" + hex;
}

function setUp(c,msoverClass,ext){
	var a=new Array();
	a=document.getElementsByClassName(c);
	for(i=0; i<a.length; i++){
		a[i]['onmouseover']=function(){this.className=msoverClass;};
		a[i]['onmouseout']=function(){this.className=c;};
		if(ext.length>0){
			a[i].onclick=function(){document.location.href=this.id+"."+ext;};	
		}
		else{
			a[i].onclick=function(){document.location.href=this.id+".php";};	
		}
	}
	
}

function grayOut(vis, Opacity,Bgcolor,Zindex) {
	var zindex = Zindex || 50;
	var opacity = Opacity || 50;
	var opaque = (opacity/100);
	var bgcolor = Bgcolor || '#000000';
	var dark=document.getElementById('darkenScreenObject');
	if (!dark) {
		var tbody = document.getElementsByTagName("body")[0];
		var tnode = document.createElement('div');
		tnode.style.position='absolute';
		tnode.style.top='0px';
		tnode.style.left='0px';
		tnode.style.overflow='hidden';       
		tnode.style.display='none';
		tnode.id='darkenScreenObject';
		tbody.appendChild(tnode);
		dark=document.getElementById('darkenScreenObject');
	}
	if (vis){
		dark.style.opacity=opaque;                      
		dark.style.MozOpacity=opaque;                   
		dark.style.filter='alpha(opacity='+opacity+')'; 
		dark.style.zIndex=zindex;        
		dark.style.backgroundColor=bgcolor;  
		dark.style.width="100%";
		dark.style.height="100";
		dark.style.display='block';                          
	}
	else{
		dark.style.display='none';
	}
}


var liHovers = new Array();
liHovers[0] = new Array("top-nav","top-nav-blue","topNavBlueHover");
liHovers[1] = new Array("top-nav","top-nav-blue-selected","topNavBlueHover");
liHovers[2] = new Array("top-nav","top-nav-purple","topNavPurpleHover");
liHovers[3] = new Array("top-nav","top-nav-purple-selected","topNavPurpleHover");
liHovers[4] = new Array("mid-page-nav","","midPageNavHover","class");
liHovers[5] = new Array("about-dates","","aboutDatesHover");
liHovers[6] = new Array("about-companies","","aboutCompaniesHover");
liHovers[7] = new Array("about-financial","","aboutFinancialHover");
liHovers[8] = new Array("about-working","","aboutWorkingHover");
liHovers[9] = new Array("news-page-nav","","newsPageNavHover","class");
liHovers[10] = new Array("claims-nav","","claimsNavHover");
liHovers[11] = new Array("careers-nav","","careersNavHover");
liHovers[12] = new Array("why-gny","","whyGnyHover");
// IE 6 fix for li:hover
topNavHover = function() {
	for(var j=0; j<liHovers.length; j++){
		if(liHovers[j][3] == "class"){
			elements = document.getElementsByClassName(liHovers[j][0]);
			for(var x=0; x<elements.length; x++){
				var sfEls = elements[x].getElementsByTagName("LI");
				setHoverEvents(sfEls,liHovers[j]);
			}

		}else if(document.getElementById(liHovers[j][0])){
			var sfEls = document.getElementById(liHovers[j][0]).getElementsByTagName("LI");
			setHoverEvents(sfEls,liHovers[j]);
		}
	}
}

function setHoverEvents(sfEls,liHovers){
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].rolloverClassName = liHovers[2];
		if(liHovers[1].length > 0){
			if(sfEls[i].className == liHovers[1]){
				sfEls[i].onmouseover = function(e) {
					this.className+=" "+liHovers[2];
				};
				sfEls[i].onmouseout = function(e) {
					this.className = this.className.replace(new RegExp(" "+liHovers[2]+"\\b"), "");
				};
			}
		} else {
			sfEls[i].onmouseover = function(e) {
				this.className+=" "+liHovers[2];
			};
			sfEls[i].onmouseout = function(e) {
				this.className = this.className.replace(new RegExp(" "+liHovers[2]+"\\b"), "");
			};
		}
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

function showHide(id,section,anchorTag) {	
	current_news=id;
	$(current_news).style.display='block';
	
	if(section==1) {
		$('archive-link').style.display='none';
	} else if(section==2) {
		$('community-link').style.display='none';
	} else if(section==3) {
		$('stories-link').style.display='none';	
	}
	document.location.href="#"+anchorTag;	
}


if (window.attachEvent) window.attachEvent("onload", topNavHover);
