var isFlashInstalled=false;
noautoinstall = "";
if(navigator.appName == "Microsoft Internet Explorer" && 
                (navigator.appVersion.indexOf("Mac") != -1 || 
                 navigator.appVersion.indexOf("3.1") != -1)){
                        noautoinstall = "true";
        }

        if (navigator.appName == "Microsoft Internet Explorer" && noautoinstall != "true")
        {
                isFlashInstalled=true;
        }
        else if(navigator.plugins)
        {
                if(navigator.plugins["Shockwave Flash"] || navigator.plugins["Shockwave Flash 2.0"])
                {
                       isFlashInstalled=true;
                }
           }


function is_iemac(){
	var SniffVer=navigator.appVersion;
	SniffVer=SniffVer.substring(0,4);
	var SniffClient=navigator.appName;
	var SniffOS=navigator.platform;
	if(SniffOS=='MacPPC' && SniffClient=='Microsoft Internet Explorer'){
			return true;
			}
			else{return false;}
}


function docPopup(url){
						window.open(url,'popup');
}

function popupLinks(){
if(!document.getElementById)return false;
var aLinks=document.getElementsByTagName('a');
for (var i=0;i<aLinks.length;i++) {
	if (aLinks[i].className == 'popup')
			{
				aLinks[i].onclick = function ()
				{
					//alert(linktype);]
					//
					var linktype=this.getAttribute('href');
					var linktype_array=linktype.split(".");
					var linkex=linktype_array[linktype_array.length-1];
					//if(this.protocol=="file:"){
					if(linkex=='jpg' || linkex=='gif' || linkex=='ipx'){
						imgPopup(this.getAttribute('href'),this.getAttribute('title') );}
					else{docPopup(this.getAttribute('href'));}
				return false;
				}
				//return false;
			}
			aLinks[i].onkeypress = aLinks[i].onclick;
		}
}

function ReDraw(){
//needs attention
        var CurrentWidth=document.body.clientWidth;
        //alert(CurrentWidth);
        var NewWidth=CurrentWidth+1;
        //alert(NewWidth);
        document.body.style.width=NewWidth;
        document.body.style.width=CurrentWidth;
}

//function to switch style sheet
function setActiveStyleSheet(title){ 
if (is_iemac()){
	return false;
}
 var i, a, main;
  if (title) {
    for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
      if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title') ) {
       if(a.getAttribute('title')!='printstyle'){
		  // alert(a.getAttribute('title'));
	   		a.disabled = true;
	   	}
        if(a.getAttribute('title') == title && a.getAttribute('title')!='printstyle' ) a.disabled = false;
      }
    }
  }
ReDraw();
}
//function to get the name of style sheet from temp
function getActiveStyleSheet() {
    var i, a;
    for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
      if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title') && !a.disabled ) return a.getAttribute('title');
    }
    return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
    if(a.getAttribute('rel').indexOf('style') != -1
       && a.getAttribute('rel').indexOf('alt') == -1
       && a.getAttribute('title')
       )
       return a.getAttribute('title');
  }
  return null;
ReDraw();
}

//function to create cookies
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = '; expires='+date.toGMTString();
  }
  else expires = '';
  document.cookie = name+'='+value+expires+'; path=/';
}
//function to read cookies on selection of the accessiblity option
function readCookie(name) {
  var nameEQ = name + '=';
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
        createCookie(name,'',-1);
}
//comment in to activate
	//window.onload = function(e) {
	//var cookie = readCookie('second-themeName');
  	//var title = cookie ? cookie : getPreferredStyleSheet();
  	//setActiveStyleSheet(title);
//}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
  	createCookie('second-themeName', title, 365);
}

function changeTxtSize(direction){
		//alert('calling function correctly');
		var textIncrement=5;//percentage by which font size is increased
		if(document.body.style.fontSize==''){document.body.style.fontSize='75%';}
		if(direction=='dec'){textIncrement=-textIncrement;}
		//alert(textIncrement);
  		newFs=parseInt(document.body.style.fontSize)+textIncrement;
		createCookie('preferedFontSize', newFs,365);
		document.body.style.fontSize=newFs+'%';
		//alert(document.body.style.fontSize);
		
}


function swapTextTool(){
	
if(document.getElementById && !is_iemac()){
	var TC = document.getElementById('txtControls');
	//a.innerHTML="<a href=\"textsize.htm\">increase text size</a> | <a href=\"textsize.htm\">decrease text size</a>";
	var swappedtext='<h1>text controls</h1> ';
	swappedtext=swappedtext + '<div><h2><a href="#" onclick="javascript:setActiveStyleSheet(\'regular\'),setDefaultFontSize()">restore default <em>text size and style</em></a></h2></div>';
	swappedtext=swappedtext + '<div id="tCstyle" >';	
	swappedtext=swappedtext + '	Adjust appearance:';
	swappedtext=swappedtext + '	<ul id="switchstyle">';
	swappedtext=swappedtext + '		<li><a href="#" onclick="javascript:setActiveStyleSheet(\'contrast1\');" class="contrast1" title="use high constrast stylesheet- light text on dark background" ><img src=images/highcontract_blck.gif border=0 /></a></li>';
	swappedtext=swappedtext + '		<li><a href="#" onclick="javascript:setActiveStyleSheet(\'contrast2\');" class="contrast2" title="use high constrast stylesheet- dark text on light background" ><img src=images/highcontract_white.gif border=0/></a></li>';
	swappedtext=swappedtext + '		<li><a href="#" onclick="javascript:setActiveStyleSheet(\'regular\');" class="default" title="use standard style sheet - view default appearance" > <img src=images/default_contrast.gif border=0 /></a></li>';
	swappedtext=swappedtext + '	</ul>';
	swappedtext=swappedtext + '</div>';
	swappedtext=swappedtext + '<div id="tCsize">';
	swappedtext=swappedtext + '	Adjust font size:';
	swappedtext=swappedtext + '	<ul id="textsize">';
	swappedtext=swappedtext + '		<li><a href="#" onclick="javascript:changeTxtSize(\'inc\');" title="decrease font size"><img src="images/font_increase.gif" border="0" /></a></li>';
	swappedtext=swappedtext + '		<li><a href="#" onclick="javascript:changeTxtSize(\'dec\');" title="increase font size" ><img src="images/font_decrease.gif" border="0" /></a></li>';
	swappedtext=swappedtext + '		<li><a href="#" onclick="javascript:setDefaultFontSize();" title="Default Font Size" ><img src="images/font_normal.gif" border="0" /></a></li>';
	swappedtext=swappedtext + '	</ul>';
	swappedtext=swappedtext + '</div>';
	//document.write(swappedtext);
	TC.innerHTML=swappedtext;
	}
}
 
function getFontSize(){
 	  var pFS = readCookie('preferedFontSize');
		if(pFS)	{document.body.style.fontSize=pFS +'%';	}
 }
 function setDefaultFontSize(){
	 	createCookie('preferedFontSize','',-365);
		{document.body.style.fontSize='75%';	}
 }
 function getstyle(){
	 var pSS = readCookie('second-themeName');
	 setActiveStyleSheet(pSS);
 }

 function navOnLoad(pgid)
{
	var pageIdload=pgid;
	if(pageIdload)

document.getElementById(pageIdload).className="active";
//setActiveStyleSheet(pSS);
}
	 
function loadfunctions(pgID){
	getFontSize();
	//swapTextTool();
	popupLinks();
	getstyle();
	navOnLoad(pgID);
	
 }
window.onload=loadfunctions;

