﻿//***********************************************//
//*                   D O M                     *//
//***********************************************//

function $(id)   { var obj=document.getElementById(id); if (obj==null) obj=document.getElementsByName(id)[0]; return obj }
function $s(id)  { return document.getElementById(id).style }
function $v(id)  { return document.getElementById(id).value }
function $ih(id) { return document.getElementById(id).innerHTML }
function $it(id) { return document.getElementById(id).innerText }
function s$v(id, val)  { document.getElementById(id).value = val }
function s$it(id, val) { document.getElementById(id).innerText = val }
function s$ih(id, val) { document.getElementById(id).innerHTML = val }
function $Show(id) { document.getElementById(id).style.display = "block" }
function $Hide(id) { document.getElementById(id).style.display = "none" }

function $fv(id) 
{
	var val, innerText, obj;
	
	obj = document.getElementById(id);
	if (obj == null) obj = document.getElementsByName(id)[0];

	if (obj.tagName != "SELECT")
		val = obj.value;
	else
	{
		var option = obj.options[obj.selectedIndex];
		//val = (option.value == "" && typeof(option.innerText) != "undefined" && option.innerText != "" ? option.innerText : option.value);
		val = option.value;
	}
	
	return val;
}
	
function StartsWith(str, subText)
{
	return (str.substr(0, subText.length) == subText);
}
	

//***********************************************//
//*         D E F E R     I M A G E S           *//
//***********************************************//

function OnDeferLoadImages()
{
	var aTagA, title, src;
	var aDivs = document.getElementsByTagName('div');

	for (var i = 0; i < aDivs.length; i++) {
		if (aDivs[i].className == "divImg") {
			aTagA = aDivs[i].getElementsByTagName("a");
			title =  aTagA[0].text;
			src =  aTagA[0].href;

			aTagA[0].innerHTML = '<img src="' + src + '" alt="' + title + '" title="' + title + '" />';
			aTagA[0].title = title;
		} else if (aDivs[i].className == "divImgOnly") {
			aTagA = aDivs[i].getElementsByTagName("a");
			title =  aTagA[0].text;
			src =  aTagA[0].href; 
			
			src = src.substr(src.indexOf("images/"));
			aDivs[i].innerHTML = '<img src="' + src + '" alt="' + title + '" title="' + title + '" />';
		}
	}
}


//***********************************************//
//*              B R O W S E R                  *//
//***********************************************//

function gIsBrowserIE()      { var b = (window.navigator.userAgent.indexOf("MSIE")    > -1);  return b; }
function gIsBrowserFirefox() { var b = (window.navigator.userAgent.indexOf("Firefox") > -1);  return b; }
function gIsBrowserOpera()   { var b = (window.navigator.userAgent.indexOf("Opera")   > -1);  return b; }

// special cases
function gIsBrowserIEStrictMode() { var b = ( IsBrowserIE() && document.documentElement && document.documentElement.scrollTop );  return b; }
function gIsBrowserMozilla()      { var b = ( !document.all );  return b; }


//***********************************************//
//*                E V E N T                    *//
//***********************************************//

function gAddEvent(obj, evType, fn)
{
	var rc = true;
	
	if (obj.addEventListener) obj.addEventListener(evType, fn, false);
	else if (obj.attachEvent) rc = obj.attachEvent("on"+evType, fn);
	else                      rc = false;
	
	return rc;
}


function gRemoveEvent(obj, evType, fn) //, useCapture)
{
	var rc = true;
	
	if (obj.removeEventListener) obj.removeEventListener(evType, fn, false);  //useCapture);
	else if (obj.detachEvent)    rc = obj.detachEvent("on"+evType, fn);
	else                         alert("Handler could not be removed");

	return rc;
}


//***********************************************//
//*               W I N D O W                   *//
//***********************************************//

function gGetViewportHeight()
{
	if (window.innerHeight != undefined)          return window.innerHeight;
	else if (document.compatMode == 'CSS1Compat') return document.documentElement.clientHeight;
	else if (document.body)                       return document.body.clientHeight; 
	else                                          return undefined; 
}


function gGetViewportWidth()
{
	if (window.innerWidth != undefined)           return window.innerWidth; 
    else if (document.compatMode == 'CSS1Compat') return document.documentElement.clientWidth; 
	else if (document.body)                       return document.body.clientWidth; 
	else                                          return undefined; 
}


function gGetScrollTop() 
{
	var scTop;
	
	if (!gIsBrowserIE())               scTop = self.pageYOffset;    
	else if (gIsBrowserIEStrictMode()) scTop = document.documentElement.scrollTop;
	else if (document.body)            scTop = document.body.scrollTop;
	else                               scTop = 0;
	
	return parseInt(scTop, 10);
}


function gGetScrollLeft() 
{
	var scLeft;
	
	if (!gIsBrowserIE())               scLeft = self.pageXOffset;    
	else if (gIsBrowserIEStrictMode()) scLeft = document.documentElement.scrollLeft;
	else if (document.body)            scLeft = document.body.scrollLeft;
	else                               scLeft = 0;
	
	return parseInt(scLeft, 10);
}



function gGetClientAreaSize()
{
	var body, iebody, clientArea;

	iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
	body   =  document.getElementsByTagName("BODY")[0];

	clientArea = new Object();
//alert("iebody.scrollLeft="+iebody.scrollLeft+"\n\ngGetViewportWidth="+gGetViewportWidth()+"\n\nbody.scrollWidth="+body.scrollWidth);
	clientArea.top    = (document.all ? iebody.scrollTop  : pageYOffset);
	clientArea.height =  gGetViewportHeight(); //  Math.min(gGetViewportHeight(), body.scrollHeight);
//	clientArea.left   = (document.all ? (gGetViewportWidth() > body.scrollWidth ? body.scrollWidth - gGetViewportWidth() : iebody.scrollLeft+gGetViewportWidth()-body.scrollWidth) : pageXOffset);
//	clientArea.left = (document.all ? iebody.scrollLeft + gGetViewportWidth() - body.scrollWidth : pageXOffset);
	clientArea.left = (document.all ? iebody.scrollLeft : pageXOffset);
	clientArea.width = gGetViewportWidth();
//alert("left="+clientArea.left+"\n\nwidth="+clientArea.width);
	return clientArea;
}


function MaximizePage() 
{
	//	Auto Maximize Window Script- By Nick Lowe (nicklowe@ukonline.co.uk)
	//  For full source code, 100's more free DHTML scripts, and Terms Of Use
	//  Visit http://www.dynamicdrive.com

	window.moveTo(-4,-4);

	if (document.all)   
		window.resizeTo(screen.availWidth+8,screen.availHeight+8);
	else 
	if (document.layers || document.getElementById) 
	{
		if (top.window.outerHeight<screen.availHeight || top.window.outerWidth<screen.availWidth)
		{
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}	
}

function CloseWindow() 
{
	//uncomment to open a new window and close this parent window without warning
	//var newwin=window.open("popUp.htm",'popup','');

	if(navigator.appName == "Microsoft Internet Explorer") {
//		this.focus();
//		self.opener = this;
//		self.close(); 

		window.opener=window.open('','_self','');
		window.opener.close();
		document.location.href="about:blank";
	} else { 
//		dom.allow_scripts_to_close_windows = true;
//		window.open('','_self',''); 
//		window.close(); 
		
		var answer = confirm("Do you wnat to close this window ?"); 
		
		if (answer){ 
			netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite'); 
			window.close(); 
		} else { 
			stop; 
		} 		
	}
} 



