/*   -------------------------------
	 Text Sizer by Keith Schmeichel
	 sendittokeith@yahoo.com
     -------------------------------
	 To use, just create a css style for the font/attributes you want to change
	 
	 Note:
	 I have this working in all browsers except opera which at this time does not
	 appear to support the rules or cssRules attributes.
	  
	  ---------------------------------------------------------------------------------------------------
	  Disclaimer:  You may use this in its entirety, please give credit to the author
	  (me) Keith Schmeichel.  All rights reserved and stuff.  For questions/comments/ideas/help please
	  e-mail me at sendittokeith@yahoo.com.  For complaints, please send to: bgates@microsoft.com
	  ---------------------------------------------------------------------------------------------------
	  
	  ################################################
	  #		TTD:									 #
	  #		- Make compatable with NN / Mozilla		 #
	  #		- Set max/mins							 #
	  #		- turn off debugger, hide errors		 #
	  ################################################
	  
*/

	//BoldFont = true // Used to Bold fonts instead of increase/descrease size (good for navigation)
	HeaderMaxSize = 5; // Set the maximum size of the Header font
	FontMaxSize = 6; // Set max size for the standard font
	SubFont1MaxSize = 4; // Set another font size maximum
	inc = "" ; dec = ""
	onerror = errWindow // Utilized the debugger
	debug = false; // Will use pop-up window; false to disable popups and disable client error elerts


function SetFontSize(){
	// Check if text preference is saved in cookie
	if(document.cookie != null){
		
		var dc = document.cookie;
		var prefix = "fontsize";
	
		cname = document.cookie.split("=")[0];
		if(cname=="fontsize"){
		
			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;
			
			// The current value of the pixels
			lenValue = unescape(dc.substring(begin -1 + prefix.length, end));

			// Set text size based on preferences
			//theRules = document.
			//alert(lenValue);
			document.styleSheets[0].rules[0].style.fontSize = lenValue;

		}
		
	}
}

	function sizer(type){
	
		// Check wheter or not style sheets are even recognized
		if (!document.styleSheets) return;
	
			// Set style depending on browser
			// This one is for DOM (non Microsoft)
			if (document.styleSheets[0].cssRules){
				theRules = document.styleSheets[0].cssRules
			}
			else if (document.styleSheets[0].rules){
				// For Microsoft only
				theRules = document.styleSheets[0].rules
			}
				// Retrun if neither are valid	
				else return;


		//var theRules = new Array();

		if (type=="inc"){
	
			// Set bolder style to bold
			theRules[4].style.fontWeight = "bold";
	
			txt = theRules[0].style.fontSize;
			re = /\D/
			txt = txt.split(re).toString();
			txt = txt.replace(",,",""); // This is for NetScape			
			txt ++;
			theRules[0].style.fontSize = txt + "pt";
			
						
		}
		else if (type=="dec"){
		
			// Set bolder style to normal
			theRules[4].style.fontWeight = "normal";
		
			txt = theRules[0].style.fontSize;
			re = /\D/
			txt = txt.split(re).toString();
			txt = txt.replace(",,",""); // This is for NetScape			
			txt --;
			theRules[0].style.fontSize = txt + "pt";
		}
		else if (type=="getRef"){
		
			// Returns way of accessing style sheet
			return theRules;
		}
		else if (type=="setsize"){
			theRules[0].style.fontSize = "";
		}
				
	}
	
	
	// Stores the preferred size of the font in the cookie (oprs)
	// That is also written to by C# to log visits to home page.
	function SaveSizeToCookie(csavesize){
		
		// Get Browser Type
		var objpre;
		if(document.all){
			// Netscape 4
			objpre = document.all;
		}
		else if(document.getElementById){
			// IE / other
			objpre = document.getElementById;
		}
		
		// Determine if the box is checked or unchecked
		if(csavesize.checked){
			
			// Get reference to style by browser type
			var theRules = sizer("getRef");
			
			// Get the current size of the font
			var currentSize = theRules[0].style.fontSize;
			
			// Set cookie expiration date
			expireDate = new Date;
			expireDate.setMonth(expireDate.getMonth()+100);
			
			// Set the cookie with the name sizer
			document.cookie = "fontsize=" + currentSize + ";expires="
			+ expireDate.toGMTString();
			
			// alert user that cookie has been set
			alert('Thank you.  Your preferred text size has been saved.');
			
		}
		

	
	
	}
	
	
	// For debugging purposes
	// Written by Keith Schmeichel
	// Outputs debugging info in new window
	// rem out code between function just to stop errors from showing in browsers,
	// Or keep to show a pop-up debugging window
	
	function errWindow(errMsg, location, lineNum) {
	
		// Choose JavaScript Editor
		var JavaEditor = "NotePad.exe";
		
		if (debug==true){
			debugWin = window.open("", "debugWin", "height=200, width=300, resize=yes")
			debugWin.document.write("<H2>There was an error at line " + lineNum)
			debugWin.document.write("<BR>The error was: " + errMsg + "</H2>")
			debugWin.document.write("<br> edit document <br><a href='" + location + "'>" + location + "</a>")
			debugWin.document.close()
		}
		
		return true
	}
	
	
	function getSupportedJava(){
	
		if (document.getElementById){
			alert('supports element');
		}
		else if (document.all){
			alert('does not support element (probably NN4)');
		}
	}