﻿////

winW = 630;
winH = 460;

function getWidth (){ return document.body.offsetWidth || window.innerWidth || document.documentElement.clientWidth || 0; }
function getHeight(){ return document.body.offsetHeight || window.innerHeight || document.documentElement.clientHeight || 0; }

// var window.popupWin = null;

var isIE = false;

try
	{
	window.popupWin = parent.popupWin;
	}
catch(e)
	{
	window.popupWin = null;
	}

if (parseInt(navigator.appVersion)>3) 
	{
	if (navigator.appName=="Netscape") 
		{
		isIE = false;
		winW = window.innerWidth;
		winH = window.innerHeight;
		}
	if (navigator.appName.indexOf("Microsoft")!=-1) 
		{
		isIE = true;
//alert(document.body.offsetWidth);
//alert(window.innerWidth);
//alert(document.documentElement.clientWidth);
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
		}
	}
////

function getWindowDimensions()
	{
	if (navigator.appName=="Netscape") 
		{
		winW = window.innerWidth;
		winH = window.innerHeight;
		}
	if (navigator.appName.indexOf("Microsoft")!=-1) 
		{
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
		if (winW==0 || winH==0)
			{
			winW = document.getElementsByTagName('body')[0].clientWidth;
			winH = document.getElementsByTagName('body')[0].clientHeight;
			}
		}
	}
////
function updateDiv(divID, content)
	{
	document.getElementById(divID).innerHTML = content;
	}
////
function openPopupWindow(url, width, height, left, top)
	{
	try
		{
		if (pageSalt=='foobar') foobar = true;
		}
	catch(e)
		{
		pageSalt = 'salt';
		}
	if (!isset(height)) height= 400;
	if (!isset(width)) width= 600;

	if (!isset(left)) left= 20;
	if (!isset(top)) top= 20;

	var arr=url.split("/");
	var cnt = arr.length - 1;
	arr = arr[cnt].split('.');
	var windowName = arr[0];

	if (pageSalt != null) windowName += '_' + pageSalt;
	str = 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',toolbar=1,resizable=1,status=1,menubar=1,location=1,scrollbars=1';
//	str = 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',toolbar=0,resizable=1,status=0,menubar=0,location=0,scrollbars=1';

	window.popupWin = window.open(url, windowName, str);
	try
		{
		window.frames['leftnav'].popupWin = window.popupWin;
		window.frames['masthead'].popupWin = window.popupWin;
		window.frames['content'].popupWin = window.popupWin;
		}
	catch(e)
		{
		}
	WindowObjectReference = window.popupWin;
	window.name = 'opener';
	frms = document.getElementsByTagName('frame');
	window.hasFocus = false;

	}
////
function focusChild()
	{
	}


function isset(somevar)
	{
	try
		{
		if (somevar == 'undefined')
			{
			return false;
			} else {
			return true;
			}
		}
	catch(e)
		{
		return false;
		}
	}
////

function URLencode(sStr) {
    return escape(sStr)
       .replace(/\+/g, '%2B')
          .replace(/\"/g,'%22')
             .replace(/\'/g, '%27');
  }
////

function urlencode(str) {
str = escape(str);
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}
////

function urldecode(str) {
str = str.replace('+', ' ');
str = unescape(str);
return str;
}

////

function findDivPos(obj) 
	{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
		{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
			{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
			}
		}
	return [curtop, curleft];
	}
////
function stripslashes(str) 
	{
	str=str.replace(/\'/g,'\'');
	str=str.replace(/\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
	}

////

function createXMLHttp()  // cross platform XMLHttpRequest solution for versions < IE 7
	{
	if (typeof XMLHttpRequest != "undefined") 
		{
		return new XMLHttpRequest();
		} 
	else if (window.ActiveXObject) 
		{
		var aVersions = [ "MSXML2.XMLHttp.5.0",
		"MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
		"MSXML2.XMLHttp","Microsoft.XMLHttp"
		];
		
		for (var i = 0; i < aVersions.length; i++) 
			{
			try 
				{
				var oXmlHttp = new ActiveXObject(aVersions[i]);
				return oXmlHttp;
				} 
			catch (oError) 
				{
		//Do nothing
				}
			}
		}
	throw new Error("XMLHttp object could be created.");
	}
	
////

function encodeNameAndValue(sName, sValue)
	{
	var sParam = encodeURIComponent(sName);
	sParam += "=";
	sParam += encodeURIComponent(sValue);
	return sParam;
	}

////

function getRequestBody(oForm) // takes an object form's elements and puts them into a query string for get / post submission
	{
	var aParam =  new Array();
	for (var i=0;i<oForm.elements.length;i++)
		{
		var oField = oForm.elements[i];
		switch (oField.type)
			{
			case 'button':
			case 'reset':
				break;

			case 'submit':

			case 'checkbox':
			case 'radio':
				if (!oField.checked)
					{
					break;
					}			
			case 'submit':
			case 'text':
			case 'hidden':
			case 'password':
				aParam.push(encodeNameAndValue(oField.name, oField.value));
				break;
			default:
				switch(oField.tagName.toLowerCase())
					{
					case "select":
						aParam.push(encodeNameAndValue(oField.name, oField.options[oField.selectedIndex].value));
						break;
					default:
						aParam.push(encodeNameAndValue(oField.name, oField.value));
					}
			}
		}	
	return aParam.join("&");
	}  

////

function ChangeClassProperty(sClassName,sProperty,sValue)
	{
	sClassName="."+sClassName;
	var sheets = document.styleSheets;
	var rules;
	var styleObj;
	for (var i=0; i< sheets.length;  i++)
		{
		rules=sheets[i].cssRules || sheets[i].rules;
		for (var j=0; j<rules.length; j++)
			{
			if (rules[j].selectorText && rules[j].selectorText==sClassName)
				{
				styleObj=rules[j].style;
				styleObj[sProperty]=sValue;
				break;
				}
			}
		}
	return;
	}

////
function addLoadEvent(func) 
	{ 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') 
		{  
		window.onload = func;  
		} else {  
		window.onload = function() 
			{  
			if (oldonload) 
				{  
				oldonload();  
				}  
			func();  
			}  
		}  
	}  
////

 this.Sleep = function ZZzzzZZzzzzzzZZZz(naptime){
      naptime ;
      var sleeping = true;
      var now = new Date();
      var alarm;
      var startingMSeconds = now.getTime();
//      alert("starting nap at timestamp: " + startingMSeconds + "\nWill sleep for: " + naptime + " ms");
      while(sleeping){
         alarm = new Date();
         alarmMSeconds = alarm.getTime();
         if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
      }      
 //     alert("Wakeup!");
   }
   
   
   
   
/////////////
// window focus   
   
   var dt = new Date();
var pageSalt = 'foobar_' + dt.getTime();
isFocus = true;


function FocusTrigger() 
	{
	try
		{
		fCnt = document.getElementById("focusCnt");
		fCnt.innerHTML = fCnt.innerHTML/1 + 1;
		}
	catch(e)
		{
		}
	}
function BlurTrigger() 
	{
	try
		{
		bCnt = document.getElementById("blurCnt");
		bCnt.innerHTML = bCnt.innerHTML/1 + 1;
		}
	catch(e)
		{
		}
	}

function checkForChild()
	{
	var popup = '';
	var popupOpen = false;
	try
		{
		popup = self.popupWin.name;
		popupOpen = !popupWin.closed;
		}
	catch (e)
		{
		popupWin = null;
		}
	if (popupOpen)
		{
		isFocus = false;
		popupWin.focus();
		popupWin.checkForChild();
		} else {
		isFocus = true;
		}
	}

function showWindowInfo()
	{
return; // rest of function is for dev
	var pop = document.getElementById("popNm");
	var foc = document.getElementById("focusSpan");
	var up = document.getElementById("update");
	dt = new Date();

	var popupOpen = false;
	try
		{
		popup = self.popupWin.name;
		popupOpen = !self.popupWin.closed;
		}
	catch (e)
		{
		popup = 'there is no popup window';
		}
	if (popupOpen)
		{
		isFocus = false;
		} else {
		isFocus = true;
		}
	pop.innerHTML = popup;
	foc.innerHTML = (isFocus? 'Yes' : 'No');
	up.innerHTML = dt.getTime();
	}
   

window.onfocus = function ()
	{
	checkForChild();
	}
////
function fadeIn(objId,opacity, increment) 
	{
	if (opacity <= 100) 
		{
		obj = document.getElementById(objId);
		setOpacity(obj, opacity);
		opacity += increment;
		if (opacity > 100) opacity = 100; 
		window.setTimeout("fadeIn('"+objId+"',"+opacity+", " + increment + ")", 20);
		}
	}

////
function fadeOut(objId,opacity, increment) 
	{
	if (opacity >= 0) 
		{
		obj = document.getElementById(objId);
		setOpacity(obj, opacity);
		opacity -= increment;
		if (opacity<0) opacity = 0; 
		window.setTimeout("fadeOut('"+objId+"',"+opacity+", '" + increment + "')", 20);
		}
	}



////
function setOpacity(obj, opacity) 
	{

	opacity = (opacity == 100)?99.999:opacity;
	
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
	}
////   
   
   
   