﻿var section=document.getElementsByName("news-centercolumn-full");
var newsSection=document.getElementsByName("news-thumbnail");

function setNewsSection(index)
{
	
	var i=0;
	//reset
	for (i;i<section.length;i++)
	{
		
		section[i].style.display="block";	
		newsSection[i].style.display="block";
	}
	for (t=0;t<section.length;t++)
	{
		if(t!=(index-1))
		section[t].style.display="none";
	}	
}
//Rearrange News Emergency. 
function repositionElement()
{

	var emergencyTitle=document.getElementById("emergencyNew");
	//alert(pagetitle.length);
	
	if(emergencyTitle)
	{
		var pagetitle=document.body.getElementsByTagName("h1");		
		var oldTag;
		for(i=0;i<pagetitle.length;i++)
		{
			var t=pagetitle[i].getAttribute("name"); //IE
			
			if(t=="homeTitle")
			{				
				oldTag=pagetitle[i].innerHTML;
				pagetitle[i].parentNode.removeChild(pagetitle[i]);								
				break;}
			
			
		}
		var newdiv = document.createElement('h1');
		newdiv.setAttribute('class','pagetitle');		
		newdiv.innerHTML=oldTag;
		emergencyTitle.appendChild(newdiv);		
	
	}
}

/*
	Open new window for printing friendly
*/
function print_preview()
{
	
	print_ref=window.open('','',
  'width=650,height=600,left=100,top=25'
   +',menubar=1'
   +',toolbar=1'
   +',status=0'
   +',scrollbars=1'
   +',resizable=1');
  
   
   var content_vlue=document.getElementById("content").innerHTML;
   var footer_vlue=document.getElementById("footersite").innerHTML;
  
  var template_open='<html><head><title>Fairfax County Government</title>';
 
  template_open+='<link type="text/css" rel="stylesheet" href="/resources/public/web/templates/css/common.css">';
   var block='<div id="header" align="center"><img src="/resources/public/web/templates/images/pfHeader.jpg"></div>';
     
 	var template_body='</head>'+'<body>'+block+content_vlue+'<div id="clear">'+footer_vlue+'</div>'+'</body>';
  var template_close='</html>';
  
  print_ref.document.write(template_open+template_body+template_close);
  print_ref.document.close();
  print_ref.focus();
  print_ref.print();	
}
/****************************************************
*        				    *
*						    *
* Toggles Text Only mode                            *
*						    *
****************************************************/

/**
 * textOnly()
 *
 * Sets the mode to 'Text Only'
 *
 */
function textOnly() 
{
  
  
  
  setCookie("data", "text"); 
  
  changeFontSize(2);  
  setActiveStyleSheet('Text Only');
  //removeImages();

 
  
  
}
/**
	Set Active Style Sheet
*/
function setActiveStyleSheet(title)
{
	var i, a, main;	
	
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) 
   {	
   		if (title=='Text Only')
   		{
   				a.setAttribute("rel","stylesheet");
   		}
   		
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) 
       {			
       	a.disabled = true;
			//	alert("Disable "+a.getAttribute("href"));
		 	}
		
		
   if(a.getAttribute("title") == title) 
     	{
			 	a.disabled = false;		 	
			 //	alert("Active "+a.getAttribute("href"));
			 } 
		else
			{
				a.disabled=true;
			//	alert(a.getAttribute("href")+"\n sdfsfDisabled:"+a.disabled);
			}
		 	
		
		 }
		 //Test which one is disabled
		/* for(i=0; (a = document.getElementsByTagName("link")[i]); i++) 
   	{	
     
		 	alert(a.getAttribute("href")+"\n Disabled:"+a.disabled);
		
		 }
		 */
		 
}
/**
 * removeImages()
 * 
 * Removes all Images from the page
 * 
 */
function removeImages()
{
  var elements = document.getElementsByTagName('*');
  var images = [];
  
  
  for(var i = 0; i < elements.length; i++)
  {
    if(elements[i].tagName == 'img' || elements[i].tagName == 'IMG')
      images.push(elements[i]);
  }

  for(var j = 0; j < images.length; j++)
  {
    images[j].parentNode.removeChild(images[j]);
  }
}

/**
 * graphicVersion()
 * 
 * Sets the mode to 'Graphic Version'
 * 
 */
function graphicVersion()
{
  //change mode
  deleteCookie("data","/", "");

  //reload the images
  location.reload(true);

  //Switch the stylesheet
  setActiveStyleSheet('default');
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        "; path=/" +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
   //window.alert(document.cookie);

}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
function load()
{  		
	var nav=document.getElementById("nav-formatting");
	nav.style.visibility="visible";
	
	var mode = getCookie("data");
	  
  
  //set the mode  
  if(mode != null)
  {
     if(mode == "text")
     {     
        textOnly();   
     }
  }
 /* else
  	{
  		setActiveStyleSheet('default');
  	} */
  		
  
}


 
   
 

 
 

