﻿// JScript File

// Page Init
pageInit = function() {
	var sfNavLi = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i < sfNavLi.length; i++) {
		sfNavLi[i].onmouseover = function() {
			this.className += " sfhover";
		}
		sfNavLi[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	var sfInput = document.getElementsByTagName("input");
	for (var i=0; i < sfInput.length; i++) {
		sfInput[i].onfocus=function() {
			this.className += " sffocus";
		}
		sfInput[i].onblur = function() {
			this.className = this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
	var sfTextarea = document.getElementsByTagName("textarea");
	for (var i=0; i < sfTextarea.length; i++) {
		sfTextarea[i].onfocus=function() {
			this.className += " sffocus";
		}
		sfTextarea[i].onblur = function() {
			this.className = this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", pageInit);

// Submit on enter clicked
function submitEnter(myfield, e)
{
	var keycode;
	if (window.event)
		keycode = window.event.keyCode;
	else if (e)
		keycode = e.which;
	else
		return true;

	if (keycode == 13)
	{
		//document.getElementById(myfield).click();
		window.location='/SearchResults.aspx?searchterm='+document.getElementById('searchtext').value;
		return false;
	}
	else
		return true;
}

// Content Page Font Resizer
// Last Updated: 12/17/2007
function fontResize(size) {
    var litContent = document.getElementById("litContent");
    switch (size) {
        case "normal":
            litContent.style.fontSize = "1em";
            break;
        case "medium":
            litContent.style.fontSize = "1.2em";
            break;
        case "large":
            litContent.style.fontSize = "1.4em";
            break;
    }
}

// Search Submit
function searchfocus(e){
    var characterCode //literal character code will be stored in this variable

    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }else{
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }
    if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
        alert(document.getElementById("searchtext").value);
        window.location='/SearchResults.aspx?searchterm=' + document.getElementById("searchtext").value;
        //document.forms[0].submit() //submit the form
        return false
    }else{
        return true
    }
}



// JScript File for the Print, Email, Bookmark page functions
// Print
function printpage(){
    document.getElementById("hdn_Title").value = document.title;
    document.getElementById("hdn_Content").value = document.getElementById("main_content").innerHTML;

    document.forms[1].submit();
}

// Email
function emailpage(bookmarkUrl){
}

// Bookmark
function bookmarkpage(bookmarkUrl){
    var bookmarkTitle = document.title;
    
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(bookmarkTitle,bookmarkUrl,"");
        
    } else if (window.external) { // IE Favorite
        window.external.AddFavorite(bookmarkUrl,bookmarkTitle);
        
    } else if (window.opera && window.print) { // Opera Hotlist
        var elem = document.getElementById('menu_bookmark');
        elem.setAttribute('href',bookmarkUrl);
        elem.setAttribute('title',bookmarkTitle);
        elem.setAttribute('rel','sidebar');
        elem.click();
    }
}

// Textbox char count
// fieldname, warningname, remainingname, maxchars
function CheckFieldLength(fn,rn,mc) {
  var len = fn.value.length;
  if (len > mc) {
    fn.value = fn.value.substring(0,mc);
    len = mc;
  }
  
  document.getElementById(rn).innerHTML = mc - len;
}

//show / hide elements on click
//showhide('id of item to show/hide','showclass','hideclass',this);
function showhide(item,showClass,hideClass,self){
    var e = document.getElementById(item).style;
    if (e.display == 'block'){
        self.className = showClass;
        e.display = 'none';
    }else{
        self.className = hideClass;
        e.display = 'block';
    }
}

//swap elements on click
//swaptoggle('id of item to show','id of item to hide',this);
function swaptoggle(showItem,hideItem,self){
    var eShow = document.getElementById(showItem).style;
    var eHide = document.getElementById(hideItem).style;
    if (eShow.display == 'block'){
        eShow.display = 'none';
        eHide.display = 'block';
    }else{
        eShow.display = 'block';
        eHide.display = 'none';
    }
}

//hide textbox value onclick - usage: add swap_value class to text box
$(function() { swapValues = []; $(".swap_value").each(function(i) { swapValues[i] = $(this).val(); $(this).focus(function() { if ($(this).val() == swapValues[i]) { $(this).val("") } }).blur(function() { if ($.trim($(this).val()) == "") { $(this).val(swapValues[i]) } }) }) });

