/*  energycodes.gov Javascript
    Author: Geoffrey Elliott
    Updated: September 2003
*/

//  navSelect :: highlights the current page in the navigation bar

function navSelect(currentPage) {
    if(document.getElementById) {
        var navElement = document.getElementById(currentPage);
        if(navElement.style) {
            navElement.style.backgroundColor = "#eee";
            navElement.style.border = "1px solid #ccc";
            navElement.style.color = "#006";
			if(navElement.style) {
				$(".subNav"+currentPage).show();
			}
        }
    }
}

//  isEmail :: returns true if a given string is a valid email address

function isEmail(str) {
    // are regular expressions supported?
    var supported = 0;

    if (window.RegExp) {
        var tempStr = "a";
        var tempReg = new RegExp(tempStr);
        if (tempReg.test(tempStr))
            supported = 1;
    }

    if (!supported)
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

    return (!r1.test(str) && r2.test(str));
}

//  getSearchAsArray ::

function getSearchAsArray() {
   var results = new Array()

   if (navigator.version >= 3) {
      // Unescape and strip away leading question mark.
      var input = unescape(location.search.substring(1))
      if (input) {
         // Divide long string into array of name/value pairs.
         var srchArray = input.split("&")
         var tempArray = new Array()
         for (i = 0; i < srchArray.length; i++) {
            // Divide each name/value pair temporarily into a two-entry array.
            tempArray = srchArray[i].split("=")
            // Use temp array values as index identifier and value.
            results[tempArray[0]] = tempArray[1]
         }
      }
   }
   return results
}

//  newWindow :: creates a new window and loads a given URL

function newWindow(url) {
    //alert(url);
    var nwLeft = (screen.availWidth - 780) / 2;
    var nwTop = (screen.availHeight - 450) / 2;
    nw=window.open(url, "emslWindow", "scrollbars,toolbar,menubar,location,status,resizable,width=780,height=450");

    // Bug workaround for Netscape 2 on Unix and Mac
    if(parseInt(navigator.appVersion) == 2 && navigator.appName == 'Netscape') {
        nw=window.open(url, "emslWindow", "scrollbars,toolbar,menubar,location,status,resizable,width=750,height=450");
    }

    nw.moveTo(nwLeft,nwTop);
    nw.focus();
}

//  captureClick :: passes a URL to newWindow(), then returns false to keep the target="_new" from working

function captureClick(url) {
    newWindow(url);
    return false;
}


//  MM_reloadPage :: reloads the page for Netscape 4.  Called when page is loaded and onresize

function MM_reloadPage(init) {
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);



$(document).ready(function() {
			$("#main #mainNavigation .navCategory>a").click(function(){
		var linkID = $(this).attr("id");
   		$("#main #mainNavigation .navCategory .subNav" + linkID).slideToggle('slow');
   		return false;
 	});
});

jQuery(document).ready(function() {
  jQuery('a.resourceCenter')
    .append('<img src="http://www.pnl.gov/images/icons/page_white_go.png" class="icon resCent" alt="" title="This information is located in the Building Energy Codes Resource Center" />');
});  

jQuery(document).ready(function() {
  jQuery('a.subNav')
    .append('<img src="http://www.pnl.gov/images/icons/arrow_down.png" style="float: right;" class="icon" alt="" title="More Navigation Items" />');
});   


jQuery(document).ready(function(){
		$("div.topics p a").click(function(){
		var linkID = $(this).attr("id");
   		$("#ttl" + linkID).toggle("slow");
   		return false;
	 	});
});
   
    jQuery(function () {
    $("div.topics p").append(" |");    
   		return false;
	 	});
        
 jQuery(function () {
   // do something on document ready
   $("#expandAll").click(function(){
		$(".questList").show();
   		return false;
	});
 });

 jQuery(function () {
   // do something on document ready
   $("#collapseAll").click(function(){
		$(".questList").hide();
   		return false;
	});
 });		

