//Copyright (c) 2005 Service First Webmasters, Inc. All Rights Reserved.
function setSize(){
	//checks browser size
	//find browser window dimensions
			var myWidth = 0, myHeight = 0;
		  //find the dimensions of the browser window
		  if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  } 

	//if browser is smaller than 1024, change to showing displaySmall
	if (myWidth < 1024) {
			setVisible('displayMedium','no');
			setVisible('displayLarge','no');
			setVisible('displaySmall','yes');
	}
	//if browser is larger than 1100, change to showing displayLarge
	if (myWidth > 1150) {
			setVisible('displayMedium','no');
			setVisible('displayLarge','yes');
			setVisible('displaySmall','no');
	}
	//if browser is between 1100 and 1024, change to showing displayMedium
	if (myWidth <= 1150 && myWidth >= 1024) {
			setVisible('displayMedium','yes');
			setVisible('displayLarge','no');
			setVisible('displaySmall','no');
	}
	
}

function setVisible(id, visible){// expects id and either yes or no
	if (testObject(id)){
		var el = document.getElementById(id);
		if (visible == "yes") {
			el.style.display = 'block';
			el.style.visibility = 'visible';
			//WCH.Apply(id);
			//uncomment if you have flyouts that go over dropdowns, checkboxes or radio buttons. Be sure to add the WCH.js link to the head of each page.
		} else {
			el.style.display = 'none';
			el.style.visibility = 'hidden';
			//WCH.Discard(id);
			//uncomment if you have flyouts that go over dropdowns, checkboxes or radio buttons. Be sure to add the WCH.js link to the head of each page.
		}
	}
}

function setDims(width,height) {
//if the current URL does not have the parameter names supplied in the qs, reload this page with those elements in the qs
//regardless, store the browser window dimensions in hidden form elements for retrieval by .NET
//first get the URL
var currentURL = window.location.href;
//save the values
var haveWidth = IndexFinder(currentURL, width + "=");
var haveHeight = IndexFinder(currentURL, height + "=");
//find browser window dimensions
			var myWidth = 0, myHeight = 0;
		  //find the dimensions of the browser window
		  if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  } 
//find out if the URL has w and h
	if (haveWidth == -1 || haveHeight == -1){
		//we have no qs with these parameters, so reload.
		   //remove the current qs, if there is one, and add ours
		  var endURL = IndexFinder(currentURL,"?")
		  if (endURL != -1) {
		  currentURL = currentURL.substring(0,endURL);
		  }
		  
		  
	     //redirect by replacing the most current item in the history list	
		 window.location.replace(currentURL + '?' + width + '=' + myWidth + '&' + height + '=' + myHeight);
	}
var dims = document.getElementById('dimensions');
		  dims.value = ' window is ' + myWidth + 'px by ' + myHeight + 'px ' + ' and url is ' + currentURL;
	//store the dimensions for .NET's use when the user clicks Next or Last
	//NOTE: in practice these elements will have 'c1_' or 'c2_' prepended!!!!!
	    document.getElementById('currentWidth').value = myWidth;
		document.getElementById('currentHeight').value = myHeight;
}

function IndexFinder(str1,str2)
{
  var s = str1.indexOf(str2);
  return(s);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function getOutOfFrame(){
	if (top.location != self.location){
		top.location = self.location;
	}
}
// stuff to make the right click action work
var mouse_x = 0;
var mouse_y = 0;
var distance_to_right_edge = 0;
var distance_to_bottom = 0;
var contextmenu = null;

addLoadEvent(onstart);

function onstart() {
  contextmenu = document.getElementById('thecontextmenu');
  addGenericEvent(document,'mousemove',mousemove);
  addGenericEvent(document,'click',hide_contextmenu);
}


function context_menuitem_highlight(element, color) {
  element.className = 'highlight';
}

function context_menuitem_unhighlight(element) {
  element.className = '';
}

function show_contextmenu(event) {

  get_page_boundaries();
  contextmenu.style.left = mouse_x+"px";
  contextmenu.style.top = mouse_y+"px";
  contextmenu.style.visibility = "visible";
  
  // adjust menu if near window edge
  if (distance_to_right_edge < contextmenu.offsetWidth)
    contextmenu.style.left = 2+mouse_x - contextmenu.offsetWidth+"px";  // The 2+ is not some dumb kludge - 
  if (distance_to_bottom < contextmenu.offsetHeight)                    // it places the menu just under the pointer,
    contextmenu.style.top = 2+mouse_y - contextmenu.offsetHeight+"px";  // instead of just outside
  
  try {
    window.getSelection().collapseToStart();  // try to compensate for tendency to treat right-clicking as text selection
  } catch (e) {} // do nothing
  
  // prevent the event from bubbling up and causing the regular browser context menu to appear.
  event.cancelBubble = true;
	if (event.stopPropagation) event.stopPropagation(); 
  if (event.preventDefault) event.preventDefault();
  
  return false;
}

function hide_contextmenu() {
  contextmenu.style.visibility = "hidden";
}


function addLoadEvent(func) {
  if (window.addEventListener)
    window.addEventListener("load",func,false);
  else if (document.addEventListener)
    document.addEventListener("load",func,false);
  else if (window.attachEvent)
    window.attachEvent("onload",func);
  else if (document.attachEvent)
    document.attachEvent("onload",func);
}

function addGenericEvent(source, trigger, func) {
  if (source.addEventListener)
    source.addEventListener(trigger,func,false);
  else if (source.attachEvent)
    source.attachEvent("on"+trigger,func);
}

function window_x() {
  if (window.screenX)
    return window.screenX
  else if (window.screenLeft)
    return window.screenLeft;
}

function window_y() {
  if (window.screenY)
    return window.screenY
  else if (window.screenTop)
    return window.screenTop;
}

function mousemove(e) { 
  if (e && e.clientX && typeof(window.scrollY) == 'number') { // Moz
    mouse_x = e.clientX + window.scrollX;
    mouse_y = e.clientY + window.scrollY;
    event_target = e.target;
  }
  else if (window.event) { // IE
    if (document.documentElement)   // Explorer 6 Strict
    {
      mouse_x = window.event.clientX + document.documentElement.scrollLeft - 4;
      mouse_y = window.event.clientY + document.documentElement.scrollTop - 4;
    }
    else if (document.body) // all other Explorers
    {
      mouse_x=window.event.clientX+document.body.scrollLeft-4;
      mouse_y=window.event.clientY+document.body.scrollTop-4;
    }
 
    mouse_window_x = window.event.clientX;
    mouse_window_y = window.event.clientY;
  }
}

function get_page_boundaries()
{
  if (window.innerWidth) {
    distance_to_right_edge = window.innerWidth-(mouse_x - window.scrollX)
    distance_to_bottom = window.innerHeight-(mouse_y - window.scrollY);
    
    //alert(window.innerHeight+' '+mouse_y);
  } else if (document.body.clientWidth) {
    distance_to_right_edge = document.body.clientWidth-mouse_x;
    distance_to_bottom = document.body.clientHeight-mouse_y;
  }
}

// end of right click stuff


function setYAH(){
	getOutOfFrame();
	var numLinks = 50; //the total count of links for which to check if YAH should be applied
	var navObject = null;
	var bNavObject = null;
	var hNavObject = null;
	var pNavObject = null;
	var here = self.location + "";
	var theQ = here.indexOf("?");
	var simpleHere = here;
	if (theQ >0 ){
		simpleHere = here.substring(0,theQ);
	} 
	var navLinkID = "";
	var bNavLinkID = "";
	var hNavLinkID = "";
	var pNavLinkID = "";
	
	//set YAH on the logo div
	navLinkID = "logo";
	if (testObject(navLinkID)) {
			navObject = document.getElementById(navLinkID);
			if (simpleHere.indexOf("index") > 0){//we are at the home page
				setClass(navLinkID,'logoDivYAH');
			}
	}
		
	for (var i = 1; i <= numLinks; i++) {
		navLinkID = "nav" + i;
		bNavLinkID = "bnav" + i;
		hNavLinkID ="hnav" + i;
		pNavLinkID ="pnav" + i;
		if (testObject(navLinkID)) {
			navObject = document.getElementById(navLinkID);
			if (simpleHere == navObject.href){
				setClass(navLinkID,'YAH');
			}
		}
		if (testObject(bNavLinkID)) {
			bNavObject = document.getElementById(bNavLinkID);
			if (simpleHere == bNavObject.href){
				setClass(bNavLinkID,'YAH');
			}
		}
		if (testObject(hNavLinkID)) {
			hNavObject = document.getElementById(hNavLinkID);
			if (simpleHere == hNavObject.href){
				setClass(hNavLinkID,'YAH');
			}
		}
		if (testObject(pNavLinkID)) {
			pNavObject = document.getElementById(pNavLinkID);
			if (simpleHere == pNavObject.href){
				setClass(pNavLinkID,'YAH');
			}
		}
	}
}

function setClass(objectID,newClass){
	var object = document.getElementById(objectID);
	object.className = newClass;
}

function testObject(objectID){
	return document.getElementById(objectID);
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
