// JavaScript Document
function loadcssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

 function loadcssfilecookie(){

	var whichCSS = getCookie("highacss");

	if (whichCSS == null || whichCSS == "")
	{
		whichCSS = "higha";
	}
			
	var filerefmain=document.createElement("link")
	filerefmain.setAttribute("rel", "stylesheet")
	filerefmain.setAttribute("type", "text/css")
	
	if (whichCSS == "higha") {
		filerefmain.setAttribute("href", "style/higha.css")
	} else {
		filerefmain.setAttribute("href", "style/charters.css")
	}

	if (typeof filerefmain!="undefined") {
			document.getElementsByTagName("head")[0].appendChild(filerefmain)
	}


}

function gup( name ){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href );  
	if( results == null )   {
		//loadcssfile("style/higha.css", "css");
		//loadcssfile("style/highanav.css", "css");
		// Check to see if the cookie has been set previously, if not 
		// default to higha css
		var whichCSS = getCookie("highacss");
		if (whichCSS == null)
		{
			setCookie("highacss","higha", 36000);
		}
		
	} else { 
		if( results[1] == "charters" ) {
			//loadcssfile("style/charters.css", "css");
			//loadcssfile("style/chartersnav.css", "css");
			setCookie("highacss","charters", 36000);
		}
		else {
			//loadcssfile("style/higha.css", "css");
			//loadcssfile("style/highanav.css", "css");
			setCookie("highacss","higha", 36000);
		}
	}
	loadcssfilecookie();
}


	  function setCookie(name, value, seconds) {
 
		if (typeof(seconds) != 'undefined') {
			var date = new Date();
			date.setTime(date.getTime() + (seconds*1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else {
			var expires = "";
		}

		document.cookie = name+"="+value+expires+"; path=/";
	
	}
 
	  function getCookie(name) {
 
		name = name + "=";
		var carray = document.cookie.split(';');
		
		for(var i=0;i < carray.length;i++) {
			var c = carray[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
		}
 
		return null;
	}

