﻿

////

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;
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
		}
	}
////
function is_object (mixed_var) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Legaev Andrey
    // +   improved by: Michael White (http://getsprink.com)
    // *     example 1: is_object('23');
    // *     returns 1: false
    // *     example 2: is_object({foo: 'bar'});
    // *     returns 2: true
    // *     example 3: is_object(null);
    // *     returns 3: false
    if (Object.prototype.toString.call(mixed_var) === '[object Array]') {
        return false;
    }
    return mixed_var !== null && typeof mixed_var == 'object';
}

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;
	}
////   
   

function number_format(number, decimals, dec_point, thousands_sep) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}   
   
  ////
function growDiv(divID, finalHeight, inc)
	{
	if (inc == null) inc = 3;
//	var inc = 3;
	d = document.getElementById(divID);
	if (d.offsetHeight < finalHeight)
		{

		newHeight = parseInt(d.offsetHeight + inc);
		if (newHeight > finalHeight)
			{
			newHeight = finalHeight;
			}
		d.style.height = newHeight + 'px';
		if (newHeight < finalHeight)
			{
			setTimeout('growDiv(\'' + divID + '\', ' + finalHeight + ', ' + inc + ')', 15);
			}
		}
	}


  ////
function shrinkDiv(divID, finalHeight, inc)
	{
	if (inc == null) inc = 3;
	d = document.getElementById(divID);
	if (d.offsetHeight > finalHeight)
		{

		newHeight = parseInt(d.offsetHeight - inc);
		if (newHeight < finalHeight)
			{
			newHeight = finalHeight;
			}
		d.style.height = newHeight + 'px';
		if (newHeight > finalHeight)
			{
			setTimeout('shrinkDiv(\'' + divID + '\', ' + finalHeight + ', ' + inc+ ')', 15);
			}
		}
	}



 function gettype( mixed_var ) {  
     // Returns the type of the variable    
     //   
     // version: 812.3015  
     // discuss at: http://phpjs.org/functions/gettype  
     // +   original by: Paulo Ricardo F. Santos  
     // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
     // +   improved by: Douglas Crockford (http://javascript.crockford.com)  
     // -    depends on: is_float  
     // -    depends on: is_array  
     // -    depends on: is_object  
     // %        note 1: lacks resource type  
     // %        note 2: 1.0 is simplified to 1 before it can be accessed by the function, this makes  
     // %        note 21: it different from the PHP implementation. We can't fix this unfortunately.  
     // *     example 1: gettype(1);  
     // *     returns 1: 'integer'  
     // *     example 2: gettype(undefined);  
     // *     returns 2: 'undefined'  
     // *     example 3: gettype({0: 'Kevin van Zonneveld'});  
     // *     returns 3: 'array'  
     // *     example 4: gettype('foo');  
     // *     returns 4: 'string'  
     // *     example 5: gettype({0: function () {return false;}});  
     // *     returns 5: 'array'  
     var type;  
   
     var typeOf = function (value) {  
         // From: http://javascript.crockford.com/remedial.html  
         var s = typeof value;  
         if (s === 'object') {  
             if (value) {  
                 if (typeof value.length === 'number' &&  
                         !(value.propertyIsEnumerable('length')) &&  
                         typeof value.splice === 'function') {  
                     s = 'array';  
                 }  
             } else {  
                 s = 'null';  
             }  
         }  
         return s;  
     }  
   
     switch (type = typeOf(mixed_var)) {  
         case 'number':  
             return (is_float(mixed_var)) ? 'double' : 'integer';  
             break;  
         case 'object':  
         case 'array':  
             if (is_array(mixed_var)) {  
                 return 'array';  
             } else if (is_object(mixed_var)) {  
                 return 'object';  
             }  
             break;  
		default:
			return 'unknown';
     }  
     return type;  
        }

function is_float (mixed_var) {
    if (typeof mixed_var !== 'number') {
        return false;
    } 
    return !!(mixed_var % 1);
}
  function is_array(input){
    return typeof(input)=='object'&&(input instanceof Array);
  }
function is_object (mixed_var){
    if (mixed_var instanceof Array) {        return false;
    } else {
        return (mixed_var !== null) && (typeof( mixed_var ) == 'object');
    }
}

////

function updateDivById(divID, content)
	{
	d = document.getElementById(divID);
	d.innerHTML = content;
	}

////



