//Get Debug cookie
var Debug = getCookie("ASKdebug");

//Close right panel by default
 setCookie ("RightMenu", "off", "state.mn.us");

//Give Early Netscapers a warning and upgrade advice
if (navigator.appName.indexOf("Netscape") != -1)
      {
        browserCode = "_NN";
        if (parseInt(navigator.appVersion) < 5){
          document.writeln ('Note: this page uses javascript not');
          document.writeln ('  supported by Netscape 4.7 (or earlier) browsers.');
          document.writeln (' To make use of print friendy displays, user preferences and accurate styles please ');
          document.writeln (' upgrade at http://channels.netscape.com/ns/browsers/default.jsp  ');
        }
      }

//Deal with cookies
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));
}

function setCookie(name, value, domain) {
  var curCookie = name + "=" + escape(value) +
      ((domain) ? "; domain=" + domain : "");
  document.cookie = curCookie;
}

function setCookiePath(name, value, domain) {
	//alert('test cookie');
	var path = '/';
	document.cookie= name + "=" + escape(value) +
        ((domain) ? "; domain=" + domain : "") +
        ((path) ? "; path=" + path : "");
}


function CookieCheck()
{
        var LeftMenu = getCookie("LeftMenu");
        if (LeftMenu == "off"){
                eventHideLeft();
        }
        var RightMenu = getCookie("RightMenu");
        if (RightMenu == "off"){
                eventHideRight();
        }
}

function Show() {


	  var argv = Show.arguments;
  	  var argc = argv.length;
 	  for (var i = 0; i < argc; i++) {
          if (Debug =="1"){
		alert ('Showing:' +argv[i]);
	  }
		 var item = document.getElementById(argv[i]);
		if (item !=null){
                        item.style.display='';
                }

        }
      }
function Hide() {
	  var argv = Hide.arguments;
  	  var argc = argv.length;
 	  for (var i = 0; i < argc; i++) {
        	if (Debug =="1"){
                alert ('Hiding:' +argv[i]);
          }
		var item = document.getElementById(argv[i]);
                if (item !=null){
                        item.style.display='none';
                }

        }
      }
        
function ShowHide(x,y){
        Show(x);
        Hide(y);
}


function ClearDropdown(Name){
	   f=document.InputForm.elements[Name];
		for (i=1; i<f.length; i++) {
			//alert('testing:'+ f.options[i].value);
			f.options[i].selected = false;
   	  	} 
}



// Print Friendly
function eventPrintFriendly()
{
	Hide('TopNav','BlueBar','Themes','NavRight','NavLeft','Footer');
	Show ('Address');
}

// Nav Bar Colapse
function eventShowLeft()
{
	Show('NavLeft','HideLeftButton');
	Hide('ShowLeftButton');
        setCookie ("LeftMenu", "on", "state.mn.us");
}
function eventShowRight()
{
	Show('NavRight','HideRightButton');
	Hide('ShowRightButton');
        setCookie ("RightMenu", "on", "state.mn.us");
}

function eventHideLeft()
{
	Show('ShowLeftButton');
        Hide('NavLeft','HideLeftButton');
        setCookie ("LeftMenu", "off", "state.mn.us");
}

function eventHideRight()
{
	Show('ShowRightButton');
	Hide('NavRight','HideRightButton');
        setCookie ("RightMenu", "off", "state.mn.us");
}


// toggleClass: Send in the class name and turn visiblity of a class on or off
//
// Example: onFocus="toggleClass('.Imagery','none');toggleClass('.Elevation','')

// This will hide the Imagery class and show the Elevation class.  The function works by iterating 
// Through the stylesheets.  Initial state of the classes must be declared in the stylesheet for
// this function to work.


function toggleClass(className,display) {
	for (i=0; i<document.styleSheets.length; i++ ){
	ss=document.styleSheets[i];
                if (ss.cssRules) {
                	for (x=0; x<ss.cssRules.length; x++){
                        if (ss.cssRules[x].selectorText==className){
                           		 st=ss.cssRules[x].style;
                                 st.setProperty("display",display,"");
                        } 
                    } 
                } else if (ss.rules) {
                	for (x=0; x<ss.rules.length; x++){
                     	if (ss.rules[x].selectorText==className){
                               st=ss.rules[x].style;
                               	st.display=display;
                        }
                	}
                } 
     } 
}



// FollowupQuestions: Depending on element of dropdown menu selected, show addional previously hidden div
//
// Example: onChange="FollowupQuestion('SourceElevation','Other','SourceElevationOther')" 

// This will, upon selection of the "SourceElevation" drop down value of "Other" show the div 
// area called "SourceElevationOhter". Assumes the form being manipulated is the first on the page.

function FollowupQuestion(menu,option,displaydiv){
	string = "document.forms[0]." + menu + ".options[document.forms[0]." + menu + ".selectedIndex].value";
	value = eval(string);
	if (value==option){
		Show (displaydiv)
	} else {
		Hide (displaydiv)
		//Purge content of field
		field = "document.forms[0]." + displaydiv;
		clear = eval(field);
		if (clear){
			if (clear.type =="text" || clear.type == "textarea"){
				clear.value = "";
			}
		}	
	}
}

