/*************************
* METRICS JAVASCRIPT
* coremetrics/cmflag.js, metrics_flags.js , etc.
*************************/
// set flags for usage web metrics
	// ***NOTE*** make sure that flags for one-off pages are set to correct values:
	// scripts: 		 /coremetrics/cmflag.js 	AND 	/omniture/omniture_flag.js 
utm_flag_GE = false;	// urchin
ga_flag_GE = true;		// google analytics
//cm_flag_GE = true;		// coremetrics

function client_host_check(){
	if (om_flag_GE && (om_flag_GE===true)) {
	var ge_hosts="govexec.com,208.118.178.21";
	var valueArray=ge_hosts.split(",");
	for(var i=0;i<valueArray.length; i++){
		if(window.location.hostname.toLowerCase().indexOf(valueArray[i])>=0){
			om_flag_GE=true;break;}else{om_flag_GE=false
		}
	}
	return om_flag_GE;}
}
/*
function om_tags(){
om_flag_GE = false;
client_host_check();
if (om_flag_GE===true) 
	document.write('<script language="' + 'javascript1.1" type="text/javascript" src="/omniture/s_code.js"></' + 'script>');
return om_flag_GE;
}
//om_tags();
//document.write(om_flag_GE)
*/

/*************************
* AD SERVING JAVASCRIPT
* ad_serv.js
*************************/
total_ad_serving_options = 2;
// current ad banners rotation based on these values see legacy /rdsw/common/ppcAds.js
// 0 - two blocks
// 1 - one tower

function testSessionCookie() {document.cookie="testSessionCookie=Enabled; path=/";  if(getCookieValue("testSessionCookie")=="Enabled") return true; else return false;}
function writeSessionCookie(cookieName, cookieValue) {if(testSessionCookie()) {document.cookie=escape(cookieName)+"="+escape(cookieValue)+"; path=/"; return true;} else return false;}
function getCookieValue(cookieName){ var exp = new RegExp (escape(cookieName)+"=([^;]+)");  if (exp.test (document.cookie+";")) { exp.exec (document.cookie+";"); return unescape(RegExp.$1); } else return false;}
function getAdSize(){// define 
	if (!getCookieValue('adsToDisplay')) { 
		current_adSize = Math.ceil(jsrng) % total_ad_serving_options; 
	} else { 
		current_adSize = getCookieValue('adsToDisplay'); 
	}
	return current_adSize;
}
function setAdSize() { // make sure that next page viewed in the same browser has different size
	getAdSize();
	current_adSize==0 ? show="blocks" : show="tower";
	//	this_adpattern = 'show=' + show + ';';  // DRAFT: parent-companion ad provisions
	if (show=="blocks"){ AdTower_HTML="";}else{	AdTopBlock_HTML=""; AdBottomBlock_HTML="";}
	next_adSize = (parseInt(current_adSize)+1) % total_ad_serving_options;
	writeSessionCookie("adsToDisplay",next_adSize);
//window.alert("test: \n random=" + jsrng + "\n current_adSize=" + current_adSize + "\n next_adSize=" + next_adSize + "\n show=" + show); // + "\n" +AdTopBlock_HTML
}

/******************************
* EXTERNAL LINKS - 
* OPEN IN THE NEW WINDOW
* externalLinks.js
******************************/
function openInNewWindow() { 	// Change "_blank" to something like "newWindow" to load all links in the same new window
	var newWindow = window.open(this.getAttribute('href'), '_blank');
	newWindow.focus();
	return false;
}
function externalLinks() { 	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {
		// Find all links
		var link;
		var hre;
		var links = document.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			url = link.href.toLowerCase();
			if ( url && (link.getAttribute("rel") == "external" 
			|| (url.indexOf("http") === 0  && url.indexOf(".govexec.com") === -1 && url.indexOf("atlantic-media.us") === -1) // MT4 staging host 
			)) {
				link.setAttribute("target", "_blank"); // openInNewWindow;
			}
		}
	}
}
window.onload = externalLinks;


/******************************
* CLUSTERING - 
* MOST READ / EMAILED TABS
* clustering.js
******************************/
var mastertabvar=new Object();
mastertabvar.baseopacity=0;
mastertabvar.browserdetect="";

function showsubmenu(masterid, id){
	if (typeof highlighting!="undefined")
	clearInterval(highlighting)
	submenuobject=document.getElementById(id)
	
	// get all #maintab list items
	var menuitems=document.getElementById(masterid).getElementsByTagName("li");
	// loop through each list item
	for (var i=0; i<menuitems.length; i++){
		// see if list items child link has a class of selected
		if (menuitems[i].getElementsByTagName("a")[0].className == 'selected') {
			// it does so, remove it
			menuitems[i].getElementsByTagName("a")[0].className = '';
		} else {
			// it doesn't so add it
			menuitems[i].getElementsByTagName("a")[0].className = 'selected';
		}
	}
	
	mastertabvar.browserdetect=submenuobject.filters? "ie" : typeof submenuobject.style.MozOpacity=="string"? "mozilla" : ""
	hidesubmenus(mastertabvar[masterid])
	submenuobject.style.display="block"
	instantset(mastertabvar.baseopacity)
	highlighting=setInterval("gradualfade(submenuobject)",50)
}

function hidesubmenus(submenuarray){
	for (var i=0; i<submenuarray.length; i++)
	document.getElementById(submenuarray[i]).style.display="none"
}

function instantset(degree){
	if (mastertabvar.browserdetect=="mozilla")
		submenuobject.style.MozOpacity=degree/100
	else if (mastertabvar.browserdetect=="ie")
		submenuobject.filters.alpha.opacity=degree
}

function gradualfade(cur2){
	if (mastertabvar.browserdetect=="mozilla" && cur2.style.MozOpacity<1)
		cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
	else if (mastertabvar.browserdetect=="ie" && cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=10
	else if (typeof highlighting!="undefined") //fading animation over
		clearInterval(highlighting)
}

function initalizetab(tabid){
	mastertabvar[tabid]=new Array()
	var menuitems=document.getElementById(tabid).getElementsByTagName("li")
	for (var i=0; i<menuitems.length; i++){
		if (menuitems[i].getAttribute("rel")){
			menuitems[i].setAttribute("rev", tabid) //associate this submenu with main tab
			mastertabvar[tabid][mastertabvar[tabid].length]=menuitems[i].getAttribute("rel") //store ids of submenus of tab menu
			if (menuitems[i].className=="selected") //if (menuitems[i].getElementsByTagName("a").className=="selected")
				showsubmenu(tabid, menuitems[i].getAttribute("rel"))
				//menuitems[i].getElementsByTagName("a")[0].onmouseover=function(){
				
			menuitems[i].getElementsByTagName("a")[0].onclick=function() {
				//showsubmenu(this.parentNode.getAttribute("rev"), this.parentNode.getAttribute("rel"))
				//showsubmenu(this.parentNode.getAttribute("rev"), this.parentNode.getAttribute("rel"), this.className="selected")
				showsubmenu(this.parentNode.getAttribute("rev"), this.parentNode.getAttribute("rel"))
			}
		}
	}
}

/******************************
* POPUP WINDOW
******************************/
var popupwindow; self.name = 'mainscreen';
	function openPlayer(theUrl){popupwindow = window.open(theUrl,"mediaplayer","width=765,height=790,status=0,status=no,directories=no,toolbar=no,resizable=no,menubar=no,scrollbars=0,left=0,top=0"); if(popupwindow.focus) {popupwindow.focus();}}
//<a HREF="javascript:openPlayer('http://URL.com')">click</a> 


/******************************
* SWAP IMAGES - NAVIGATION
* swapimg.js
******************************/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("##")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/******************************
* WEB FORMS
******************************/
// Change default text when field is clicked
	function textFieldOnClick (t) {
		// current value of field is the same as the default text defined in the title tag
		if (t.value==t.title) {
			// empty the value
			t.value='';	
		} 
		// change selected field bg color to grey
		t.style.backgroundColor="#999";
	}
// Change update text when field is unclicked
	function textFieldOnBlur (t) {
		// fields value is empty
		if (t.value=='') {
			// restore value to default text defined in title tag
			t.value=t.title;	
		} 
		// change unclicked field bg color to white
		t.style.backgroundColor="#fff";
	}


/******************************
* LINK SHARING
******************************/
//facebook specific// inside <a> javascript:void(window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent('http://www.washingtonpost.com/wp-dyn/content/article/2008/10/10/AR2008101000003.html?referrer=facebook')+'&t='+encodeURIComponent('Dispelling Illusions'),'sharer','toolbar=no,width=642,height=436'));
//function fbs_click() { u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436'); return false;}