// *********************************************************************
// Browser Detection
// *********************************************************************
	
	if(document.getElementById) { // IE 5 and up, NS 6 and up
		var upLevel = true;
		}
	else if(document.layers) { // Netscape 4
		var ns4 = true;
		document.getElementById = function() { return null; }
		}
	else if(document.all) { // IE 4
		var ie4 = true;
		document.getElementById = function() { return null; }
		}
		
	var agt=navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	var is_safari = (agt.indexOf("safari") != -1);
	var is_nav = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1)
	&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
	&& (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1)
	&& (!is_safari) );
	var is_nav2 = (is_nav && (is_major == 2));
	var is_nav3 = (is_nav && (is_major == 3));
	var is_nav4 = (is_nav && (is_major == 4)); 
	var is_nav4up = (is_nav && (is_major >= 4));
	var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
	(agt.indexOf("; nav") != -1)) );
	var is_nav6 = (is_nav && (is_major == 5));
	var is_nav6up = (is_nav && (is_major >= 5));
	var is_gecko = (agt.indexOf('gecko') != -1);
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (!is_safari) );
	var is_ie3 = (is_ie && (is_major < 4));
	var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4") != -1) );
	var is_ie4up = (is_ie && (is_major >= 4));
	var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0") != -1) );
	var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") != -1));
	var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
	var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
	var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.") != -1) );
	var is_ie6up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
	var is_opera = (agt.indexOf("opera") != -1);
	var is_mac = (agt.indexOf("mac") != -1);
	var is_iemac = (is_ie && is_mac);
	
	
	function FirefoxTwoCompatibility(){
		// If the browser is Firefox get the version number
		var ffv = 0;
		var ffn = "Firefox/"
		var ffp = navigator.userAgent.indexOf(ffn);
		if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
		// If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
		if (ffv >= 1.5) {
			Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
		}
	}

// *********************************************************************
// Page Element Manipulating Functions
// *********************************************************************

	// Gets a page element
	function getObject(ID) {
		if(upLevel) {
			var obj = document.getElementById(ID);
			}
		else if(obj) {
			var obj = eval('document.' + ID);
			}
		else if(obj) {
			var obj = eval('document.all.' + ID);
			}
		return obj
	}	

	// Hides a page element
	function hideObject(ID) {
		var obj = getObject(ID);
		if(obj!=null)
		{	
			if (ns4) {
				obj.visibility = "hide";
			}
			if (ie4 || upLevel) {
				obj.style.visibility = "hidden";
			}
		}
	}	
	
	// Removes a page element
	function removeObject(ID) {
		var obj = getObject(ID);	
		if(obj!=null)
		{				
			if (ns4) {
				obj.display = "none";
			}
			if (ie4 || upLevel) {
				obj.style.display = "none";
			}
		}
	}
	
	// Restores a page element
	function restoreObject(ID) {
		var obj = getObject(ID);	
		if(obj!=null)
		{				
			if (ns4) {
				obj.display = "block";
			}
			if (ie4 || upLevel) {
				obj.style.display = "block";
			}
		}
	}
	
	// Shows a hidden page element
	function showObject(ID) {
		var obj = getObject(ID);
		if(obj!=null)
		{		
			if (ns4) {
				obj.visibility = "show";
			}
			if (ie4 || upLevel) {
				obj.style.visibility = "visible";
			}	
		}
	}
	
	// Toggles the hiding and display of the div in ID
	function toggleDivDisplay(ID)
	{	
		var div = getObject(ID);
		if(div != null)
		{
			if (ns4) {
				if(div.display == 'none')
					restoreObject(div.id);
				else
					removeObject(div.id);
			}
			if (ie4 || upLevel) {
				if(div.style.display == 'none')
					restoreObject(div.id);
				else
					removeObject(div.id);
			}
		}
	}
	
	// Fills a page element with text/value data.
	function fillListItems(ID, listItems)
	{
		// Get the list to fill
		var list = getObject(ID);

		// Clear the options currently in the list
		emptyList(ID);
		
		// Load the itesm into the list
		for(var k=0; k < listItems.length; k++)
		{
			var item = listItems[k];
			list[k] = new Option(leftTrim(item.Name || item.Text),item.Value);
		}		
	}
	
	// Fills a page element with text/value data.
	function fillListItems_LeaveFirst(list, listItems)
	{
		var tempOption = list[0];
		// Clear the options currently in the list
		emptyList(list.id);
		list[0] = tempOption;
		
		// Load the items into the list
		for(var k = 1; k <= listItems.length; k++)
		{
			var item = listItems[k-1];
			if(item.Name || item.Text)
				list[k] = new Option(leftTrim(item.Name || item.Text), item.Value);
		}
	}
	
	// Selects an item from the list
	function selectFromList(list, value)
	{
		var listItem
		for (i = 0; i < list.length; i++) 
		{
			list.options[i].selected = (list.options[i].value == value);
		} 	
	}

	// Empties a page element that contains a list.
	function emptyList(ID)
	{
		var list = getObject(ID);
		//Clear the options currently in the list
		for (x = list.length; x >= 0; x = x - 1) {
			list[x] = null;
		}
	}
	
	function incomingToHash(listItems)
	{
	    return incomingAddToHash(new Array(), listItems);
	}
	
	function incomingAddToHash(hash, listItems)
	{
	    for(var i=0; i<listItems.length; i++)
	    {
	        var item = listItems[i];
	        if(item.Name || item.Text)
	            hash[item.Value] = leftTrim(item.Name || item.Text);
	    }
	    
	    return hash;
	}
	
	
	// Trims leading spaces
	function leftTrim(sString) 
	{
		if(sString)
		{
			while (sString.substring(0,1) == ' ')
			{
				sString = sString.substring(1, sString.length);
			}
		}
		return sString;
	}
	
	// Fires the submit when the enter key is pressed.
	function enterSubmit(control, validate) {
		
		var tmp;
		var agt = navigator.userAgent.toLowerCase();
		var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1)) ? 1 : 0;
		if (is_safari == 1){
			tmp = window.event.keyCode;			
		}
		else
		{
			if (window.navigator.appName == "Microsoft Internet Explorer"){
				tmp = window.event.keyCode;
			}
			else if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1){
				tmp = arguments.callee.caller.arguments[0].which;
		
			}
			else if (window.navigator.appName.toLowerCase().indexOf("mozilla") > -1){
				tmp = e.keyCode;
			}
		}
		if (( tmp == 13 ) || ((window.event) && (window.event.keyCode == 13))) 
		{
			if (validate == 'True') 
			{
				if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate())
				{
					__doPostBack(control,'');
				}
			} 
			else 
			{
				__doPostBack(control,'');
			}
			return true;
		} 
		else 
		{
			return false;
		}
	}
	
// *********************************************************************
// Cross-browser implementation of element.addEventListener()
// *********************************************************************

	    // Cross-browser implementation of element.addEventListener()
	    function addListener(element, type, expression, bubbling)
	    {
		    bubbling = bubbling || false;
		    if(window.addEventListener) { // Standard
			    element.addEventListener(type, expression, bubbling);
			    return true;
		    } else if(window.attachEvent) { // IE
			    element.attachEvent('on' + type, expression);
			    return true;
		    } else return false;
	    }
    	
	    function addOnloadEvent(fnc){
		    if ( typeof window.addEventListener != "undefined" )
			    window.addEventListener( "load", fnc, false );
		    else if ( typeof window.attachEvent != "undefined" ){
			    window.attachEvent( "onload", fnc );
		    }
		    else{
			    if ( window.onload != null ){
				    var oldOnload = window.onload;
				    window.onload = function ( e ){
									    oldOnload( e );
									    window[fnc]();
								    };
			    }
			    else 
				    window.onload = fnc;
		    }
	    }
	
// *********************************************************************
// Hover help window methods
// *********************************************************************

    /***********************************************
    * Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit http://www.dynamicdrive.com/ for this script and 100s more.
    ***********************************************/
    addOnloadEvent(createhintbox);
    		
    var horizontal_offset="5px" //horizontal offset of hint box from anchor link
    var innerpadding = "22" //padding x2 + boarder x2 from style "hintboxInner"

    var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
    var ie=document.all
    var ns6=document.getElementById&&!document.all	
    	
    function getposOffset(what, offsettype){
	    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	    var parentEl=what.offsetParent;
	    while (parentEl!=null){
	    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
	    parentEl=parentEl.offsetParent;
	    }
	    return totaloffset;
    }

    function iecompattest(){
	    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }

    function clearbrowseredge(obj, whichedge){
	    var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	    if (whichedge=="rightedge"){
	    var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
	    dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
	    if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
	    edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
	    }
	    else{
	    var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
	    dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
	    if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
	    edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
	    }
	    return edgeoffset
    }

    function showhint(menucontents, obj, e, tipwidth){
	    if ((ie||ns6) && document.getElementById("HintBox")){
	    dropmenuobj=document.getElementById("HintBox")
	    var innerWidth = tipwidth - innerpadding 
	    dropmenuobj.innerHTML= menucontents
	    dropmenuobj.style.left=dropmenuobj.style.top=-500

	    if (tipwidth!=""){
	    dropmenuobj.widthobj=dropmenuobj.style
	    dropmenuobj.widthobj.width=tipwidth + "px"

	    }
	    dropmenuobj.x=getposOffset(obj, "left")
	    dropmenuobj.y=getposOffset(obj, "top")
	    dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
	    dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
	    dropmenuobj.style.visibility="visible"
	    dropmenuobj.style.zIndex = 10

	    var theIframe = document.getElementById("iframePalette")

	    theIframe.style.visibility = "visible"
	    theIframe.style.width = dropmenuobj.offsetWidth
	    theIframe.style.height = dropmenuobj.offsetHeight
	    theIframe.style.top = dropmenuobj.offsetTop
	    theIframe.style.left = dropmenuobj.offsetLeft
	    theIframe.style.zIndex = dropmenuobj.style.zIndex - 1
	    theIframe.style.position="absolute"
	    theIframe.style.display = "block"

	    obj.onmouseout=hidetip
	    }
    }

    function hidetip(e){
	    dropmenuobj.style.visibility="hidden"
	    dropmenuobj.style.left="-500px"

	    var theIframe = document.getElementById("iframePalette")
	    theIframe.style.visibility=="hidden"
	    theIframe.style.left="-500px"
    }

    function createhintbox(){
	    var divblock=document.createElement("div")
	    divblock.setAttribute("id", "HintBox")
	    document.body.appendChild(divblock)

	    var iframeBlockE=document.createElement("iframe")
	    iframeBlockE.setAttribute("id", "iframePalette")
	    iframeBlockE.setAttribute("frameborder", "0")
	    iframeBlockE.setAttribute("scrolling", "no")
	    document.body.appendChild(iframeBlockE)
	    iframeBlockE.style.left=iframeBlockE.style.top=-500
	    iframeBlockE.style.visibility = "hidden"
    }

// *********************************************************************
// Query string parsing methods
// *********************************************************************

    function Querystring(qs) { // optionally pass a querystring to parse
	    this.params = new Object()
	    this.get=Querystring_get
    	
	    if (qs == null)
		    qs=location.search.substring(1,location.search.length)

	    if (qs.length == 0) return

        // Turn <plus> back to <space>
        // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	    qs = qs.replace(/\+/g, ' ')
	    var args = qs.split('&') // parse out name/value pairs separated via &
	
        // split out each name=value pair
	    for (var i=0;i<args.length;i++) {
		    var value;
		    var pair = args[i].split('=')
		    var name = unescape(pair[0])

		    if (pair.length == 2)
			    value = unescape(pair[1])
		    else
			    value = name
		
		    this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}


/*==========================================================================#
# * Function for adding a Filter to an Input Field                          #
# * @param  : [filterType  ] Type of filter 0=>Alpha, 1=>Num, 2=>AlphaNum   #
# * @param  : [evt         ] The Event Object                               #
# * @param  : [allowDecimal] To allow Decimal Point set this to true        #
# * @param  : [allowCustom ] Custom Characters that are to be allowed       #
#==========================================================================*/
function filterInput(filterType, evt, allowDecimal, allowCustom){
    var keyCode, Char, inputField, filter = '';
    var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var num   = '0123456789';
    // Get the Key Code of the Key pressed if possible else - allow
    if(window.event){
        keyCode = window.event.keyCode;
        evt = window.event;
    }else if (evt)keyCode = evt.which;
    else return true;
    // Setup the allowed Character Set
    if(filterType == 0) filter = alpha;
    else if(filterType == 1) filter = num;
    else if(filterType == 2) filter = alpha + num;
    if(allowCustom)filter += allowCustom;
    if(filter == '')return true;
    // Get the Element that triggered the Event
    inputField = evt.srcElement ? evt.srcElement : evt.target || evt.currentTarget;
    // If the Key Pressed is a CTRL key like Esc, Enter etc - allow
    if((keyCode==null) || (keyCode==0) || (keyCode==8) || (keyCode==9) || (keyCode==13) || (keyCode==27) )return true;
    // Get the Pressed Character
    Char = String.fromCharCode(keyCode);
    // If the Character is a number - allow
    if((filter.indexOf(Char) > -1)) return true;
    // Else if Decimal Point is allowed and the Character is '.' - allow
    else if(filterType == 1 && allowDecimal && (Char == '.') && inputField.value.indexOf('.') == -1)return true;
    else return false;
}

function isBrowserEarlyIE()
{
    var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
    var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

    return $.browser.msie && (ie55 || ie6);
}

function GetJSONObject(str)
{
    if(str.search("new Date") != -1)
        return eval("(" + str + ")");
    else
        return JSON.parse(str, JSONDateReviver);
}

function JSONDateReviver(key, value)
{
    var a;
    if (typeof value === 'string') {
        a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
        if (a) {
            return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                            +a[5], +a[6]));
        }
    }
    return value;
}
