var rollovers = new Array();
var browser = new checkBrowser();
var preloadFlag = false;

function checkBrowser() { this.browser = navigator.userAgent.toLowerCase(); this.version = navigator.appVersion.toLowerCase(); this.mac = this.version.indexOf("mac")!= -1 ? 1 : 0; this.ns = (this.browser.indexOf("mozilla")!=-1&&this.browser.indexOf("compatible")==-1&&document.layers) ? 1 : 0; this.ie = (document.all) ? 1 : 0; this.dom = (document.getElementById) ? 1 : 0; this.domie = (this.dom&&this.ie) ? 1 : 0; this.domns = (this.dom&&!this.ie) ? 1 : 0; this.rollover = true; this.min = (this.ns||(this.ie&&(this.mac&&this.version.indexOf("msie 4")!=-1))||this.dom); return this; }
function reloadWindow() { window.location.href = window.location.href; }
function getElement(obj) { if (document.getElementById) { return document.getElementById(obj); } if (document.all) { return document.all[obj]; } if (document.layers) { return getLayer(obj, document); } }
function moveLayer(obj, x, y) { if (obj=getElement(obj)) { if (browser.dom) { obj.style.left = x + 'px'; obj.style.top = y + 'px' } ; if (browser.ie) { obj.style.pixelLeft = x; obj.style.pixelTop = y; } } else return false; }
function layerX(obj) { if (obj=getElement(obj)) { if (browser.ie) { return (obj.style.pixelLeft) ? obj.style.pixelLeft : obj.offsetLeft } ; if (browser.dom) { return (obj.style.left) ? parseInt(obj.style.left) : parseInt(obj.offsetLeft); } } else return null; }
function layerY(obj) { if (obj=getElement(obj)) { if (browser.ie) { return (obj.style.pixelTop) ? obj.style.pixelTop : obj.offsetTop } ; if (browser.dom) { return (obj.style.top) ? parseInt(obj.style.top) : parseInt(obj.offsetTop); } } else return null; }
function layerHeight(obj) { if (obj=getElement(obj)) { if (browser.dom) { return (obj.style.height) ? parseInt(obj.style.height) : parseInt(obj.offsetHeight) } ;	 if (browser.ie) { return (obj.style.pixelHeight) ? obj.style.pixelHeight : obj.offsetHeight; } } else return null; }
function layerWidth(obj) { if (obj=getElement(obj)) { if (browser.dom) { return (obj.style.width) ? parseInt(obj.style.width) : parseInt(obj.offsetWidth) } ;	 if (browser.ie) { return (obj.style.pixelWidth) ? obj.style.pixelWidth : obj.offsetWidth; } } else return null; }
function layerVisible(obj,visible) { if (obj=getElement(obj)) { if (browser.ie||browser.dom) { obj.style.visibility = visible } ; if (browser.ns) { obj.visibility = (visible=='visible') ? 'show' : 'hide'; } } else return null; }
function layerBgColor(obj,color) { if (obj=getElement(obj)) { obj.style.backgroundColor = color; } }
function layerColor(obj,color) { if (obj=getElement(obj)) { obj.style.color = color; } }
function clipLayer(obj,clipleft, cliptop, clipright, clipbottom) { if (obj=getElement(obj)) { obj.style.clip = 'rect(' + cliptop + 'px ' + clipright + 'px ' + clipbottom + 'px ' + clipleft +'px)'; } }
function getzIndex(obj) { return (obj=getElement(obj)) ? obj.style.zIndex : null; }
function setzIndex(obj,z) { if (obj=getElement(obj)) { if (browser.ie||browser.dom) obj.style.zIndex = z; } }
function setStyle(obj,style) { if (obj) { if (!browser.domie) { obj.setAttribute("style",style); } else { obj.style.cssText = style; } } };
function addRollover(obj) { if (rollovers) { rollovers[obj.id] = {on:obj.on, off:obj.off}; newImage(obj.on); } }
function rollover(obj) { if (rollovers) { if (getElement(obj)) { getElement(obj).src = rollovers[obj].on; } } }
function rollout(obj) { if (rollovers) { if (getElement(obj)) { getElement(obj).src = rollovers[obj].off; } } } 
function newImage(arg) { if (document.images) { rslt = new Image(); rslt.src = arg; return rslt; } } 

function getFormElement(element) {
	ref = false;
	if (document.forms.length) {
		if (document.forms[0][element]) {
			ref = document.forms[0][element];
		}
	}
	return ref;
}

function getFormRecord(element) {
	ref = false;
	if (document.forms.length) {
		if (document.forms[0][element]) {
			ref = document.forms[0][element];
		}
	}
	return ref;
}

function getFormChk(element) {
	ref = false;
	if (document.forms.length) {
		if (document.forms[0][element]) {
			ref = document.forms[0][element];
		}
	}
	return ref;
}

function toggleDateChkBox(element,text) {
	if (getFormChk('chk_'+element) && getElement(text))
	{
		getFormChk('chk_'+element).checked = false;
		getFormRecord(element).value = '';
		getElement(text).innerHTML = '-';
	}
}

function setFormElement(element,value)
{
	if (getFormElement(element))
	{
		if (getFormElement(element).length != null)
		{
			for (loop=0;loop<getFormElement(element).length;loop++)
			{
				if (getFormElement(element)[loop].value == value) { getFormElement(element)[loop].checked = true; }
			}
		} else {
			getFormElement(element).value = value;
		}
	}
}

function formSetAction(obj) {
	if (typeof(obj) == 'object') {
		for (key in obj) {
			setFormElement(key,obj[key]);
		}
		submitForm();
	}
	return false;
}

function submitForm() {
	if (tinyMCE)
	{
		tinyMCE.triggerSave(false);
	}
	if (document.forms[0].onsubmit)
	{
		if (!document.forms[0].onsubmit()) { return false; }
	}
	document.forms[0].onsubmit = null;
	document.forms[0].submit();
	return false;
}

function init()
{
	//
}

function calendarCallback(date, month, year, formID)
{
	element = getFormRecord(formID);
	if (element)
	{
		getElement('calendar_'+formID).innerHTML = ''; // Be nice to IE5.x for Mac
		getElement('calendar_'+formID).innerHTML = constructDate(date,month,year,"dd mmm, yyyy");
		if (getFormChk('chk_'+formID).type == 'checkbox') { getFormChk('chk_'+formID).checked = true; }
		element.value = constructDate(date,month,year,"yyyy-mm-dd");
	}
}

function constructDate(d,m,y,format)
{
	monthName =	new Array("January","February","March","April","May","June","July","August","September","October","November","December")
	sTmp = format
	sTmp = sTmp.replace ("dd","<e>")
	sTmp = sTmp.replace ("d","<d>")
	sTmp = sTmp.replace ("<e>",padZero(d))
	sTmp = sTmp.replace ("<d>",d)
	sTmp = sTmp.replace ("mmm","<o>")
	sTmp = sTmp.replace ("mm","<n>")
	sTmp = sTmp.replace ("m","<m>")
	sTmp = sTmp.replace ("<m>",m)
	sTmp = sTmp.replace ("<n>",padZero(m))
	sTmp = sTmp.replace ("<o>",monthName[m-1])
	return sTmp.replace ("yyyy",y)
}

function padZero(num) {
	return (num	< 10)? '0' + num : num ;
}

function popup_box(obj)
{
	target = obj.target;
	link = obj.href;
	scrx = screen.width;
	scry = screen.height;
	
	width = 690;
	height = 400;
	
	winX = (scrx/2)-(width/2);
	winY = (scry/2)-(height/2);
	enlargementWin = open(link,target,'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=no,width='+width+',height='+height+',left='+winX+',top='+winY+',screenX='+winX+',screenY='+winY+',resizeable=no');
	enlargementWin.moveTo(winX,winY);
	enlargementWin.focus();
	return false;
}

function toggleView(element,div,msg)
{
    flag = (getElement(element).innerHTML == 'Show '+msg);
    getElement(element).innerHTML = (flag) ? 'Hide '+msg : 'Show '+msg;
    getElement(div).style.display = (flag) ? 'block' : 'none';
    return false;
}

function winCoords(w,h)
{
	scrw = screen.width;
	scrh = screen.height;
	winX = (scrw/2)-(w/2);
	winY = (scrh/2)-(h/2);
	return {x:winX,y:winY,w:w,h:h,scrw:scrw,scrh:scrh};
}

function searchPopup()
{
	win = new winCoords(600,480);
	newWin = open(null,'_search','directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width='+win.w+',height='+win.h+',left='+win.x+',top='+win.y+',screenX='+win.x+',screenY='+win.y+',resizeable=no');
	newWin.moveTo(win.x,win.y);
	newWin.focus();
	return false;
}
