// =============================================================
// Prototypes
// The following javascript functions are considered
// public-domain or for public use as they were found on public
// sites. Credit is given where available. Copyright is retained
// by the original authors
// =============================================================


// JavaScript DateFormat
// http://www.codeproject.com/jscript/dateformat.asp
// a global month names array
var gsMonthNames = new Array(
	'January',
	'February',
	'March',
	'April',
	'May',
	'June',
	'July',
	'August',
	'September',
	'October',
	'November',
	'December'
);
var gsDayNames = new Array(
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
);
String.prototype.zf = function(l) { return '0'.string(l - this.length) + this; }
String.prototype.string = function(l) { var s = '', i = 0; while (i++ < l) { s += this; } return s; }
Number.prototype.zf = function(l) { return this.toString().zf(l); }


Date.prototype.format = function(f)
{
    if (!this.valueOf())
        return '&nbsp;';

    var d = this;

    return f.replace(/(yyyy|mmmm|mmm|mm|dddd|ddd|dd|hh|nn|ss|a\/p)/gi,
        function($1)
        {
            switch ($1.toLowerCase())
            {
            case 'yyyy': return d.getFullYear();
            case 'mmmm': return gsMonthNames[d.getMonth()];
            case 'mmm':  return gsMonthNames[d.getMonth()].substr(0, 3);
            case 'mm':   return (d.getMonth() + 1).zf(2);
            case 'dddd': return gsDayNames[d.getDay()];
            case 'ddd':  return gsDayNames[d.getDay()].substr(0, 3);
            case 'dd':   return d.getDate().zf(2);
            case 'hh':   return ((h = d.getHours() % 12) ? h : 12).zf(2);
            case 'nn':   return d.getMinutes().zf(2);
            case 'ss':   return d.getSeconds().zf(2);
            case 'a/p':  return d.getHours() < 12 ? 'AM' : 'PM';
            }
        }
    );
}

// innerText compatibility layer
// Found various incarnations on the web.
// http://www.codeproject.com/jscript/crossbrowserjavascript.asp?df=100&forumid=245519&exp=0&select=1712237
var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);

if (! isIE) {
  HTMLElement.prototype.__defineGetter__("innerText", 
          function () { return(this.textContent); });
  HTMLElement.prototype.__defineSetter__("innerText", 
          function (txt) { this.textContent = txt; });
}

// XML Functions
// Adapted from w3schools.com
function getXMLNodeValue(xml, nodeId)
{		
	// code for IE
	if (window.ActiveXObject)
	  {
	  var doc=new ActiveXObject("Microsoft.XMLDOM");
	  doc.async="false";
	  doc.loadXML(xml);
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else
	  {
	  var parser=new DOMParser();
	  var doc=parser.parseFromString(xml,"text/xml");
	  }
	
	var x=doc.documentElement;

	return x.getElementsByTagName(nodeId)[0].childNodes[0].nodeValue;

}

// String Functions

// This function ZeroFills a string to a specific length
function ZeroFill(inputNum, totalDigits)
{
	var retVal = inputNum.toString();
	while (retVal.length < totalDigits) 
		retVal = "0" + retVal; 
	return retVal;
} 

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos)
{
	if(pos=="random")
	{
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center")
	{
		LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null)
	{
		LeftPosition=0;TopPosition=20
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}