/*
	Open new window for printer friendly
	This is only used by .NET 2.0 application master only
*/
function print_preview(absoluteLink)
{
	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="'+absoluteLink+'/resources/public/web/templates/css/deprecated.css">';
	template_open+='<link type="text/css" rel="stylesheet" href="'+absoluteLink+'/resources/public/web/templates/css/styles.css">';
	template_open+='<link type="text/css" rel="stylesheet" href="'+absoluteLink+'/resources/public/web/templates/css/application.css">';
	template_open+='<link type="text/css" rel="stylesheet" href="'+absoluteLink+'/resources/public/web/templates/css/common.css">';
	var block='<div id="header" align="center"><img src="'+absoluteLink+'/resources/public/web/templates/images/pfHeader.jpg"></div>';
	var template_body='</head>'+'<body>'+block+content_vlue+footer_vlue+'</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();	
}


/*********************************************/
/* ----------Add New Functionality ----------*/
/*********************************************/
/*
 * Changes the font size for the elements 'content' and 'nav-formatting'
 */
function changeFontSize(x)
{ 
	var rightside=document.getElementById('rightcolumn');
	var leftside = document.getElementById('leftcolumn');
	setCookie("fontSize",x);
	
  if(x == 1)
  {
  
    if (rightside)
    	rightside.style.fontSize='10px';
    if(leftside)
    leftside.style.fontSize='10px';
    document.getElementById('footersite').style.fontSize='10px';
   
    document.getElementById('content').style.fontSize='10px';
    document.getElementById('content').style.lineHeight='1.25em';

    document.getElementById('nav-formatting').style.fontSize='10px';
    document.getElementById('nav-formatting').style.lineHeight='0.9em';
  }
  if(x == 2)
  {

	 if (rightside)
		 rightside.style.fontSize='12px';
		 
     if(leftside)
    leftside.style.fontSize='12px';
    document.getElementById('footersite').style.fontSize='12px';
    
    
    document.getElementById('content').style.fontSize='12px';
    document.getElementById('content').style.lineHeight='1.3em';

    document.getElementById('nav-formatting').style.fontSize='10px';
    document.getElementById('nav-formatting').style.lineHeight='0.9em';

  }
  if(x == 3)
  {

	 if (rightside)
		rightside.style.fontSize='14px';
     if(leftside)
    leftside.style.fontSize='14px';
   


    document.getElementById('content').style.fontSize='14px';
    document.getElementById('content').style.lineHeight='1.45em';

    document.getElementById('nav-formatting').style.fontSize='10px';
    document.getElementById('nav-formatting').style.lineHeight='0.9em';
  }
}




/****************************************************
*        				    *
*						    *
* Toggles Text Only mode                            *
*						    *
****************************************************/

/**
 * textOnly()
 *
 * Sets the mode to 'Text Only'
 *
 */
function textOnly() 
{
  
  
  
  setCookie("data", "text"); 
  
  changeFontSize(2);  
  setActiveStyleSheet('Text Only');
  

 
  
  
}
/**
	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;
			
		 	}
		
		
   if(a.getAttribute("title") == title) 
     	{
			 	a.disabled = false;		 	
			
			 } 
		else
			{
				a.disabled=true;
		
			}
		 	
		
		 }
		
		 
}
/**
 * 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";
    }
}

/**
* load function
* call from page onload to display nav-formatting div, set the font size, and page mode(graphic/text only)
**/


function load()
{  		
	var nav=document.getElementById("nav-formatting");
	nav.style.visibility="visible";
	var mode = getCookie("data");
	var textSize= getCookie("fontSize");
  //set the mode  
  if(mode != null)
  {
     if(mode == "text")
     {     
        textOnly();   
     }
  }
  /*else
  	{
  		setActiveStyleSheet('default');
  	} */
  	if(textSize != null)
  	{
  	changeFontSize(textSize); 
  	}
}




