var dwfBrowser = '';
if (document.layers) {dwfBrowser = "nn4"};
if (document.all) {dwfBrowser = "ie4"};
if (window.navigator.userAgent.toLowerCase().match("gecko")) {dwfBrowser = "gecko"};
if (document.all&&navigator.userAgent.indexOf("Opera")==-1) {dwfBrowser = "ie"};

// table-row rollover variables.
var sMouseOverRowId='';
var sMouseOverColour='';
var sClickedRowId='';
var sClickedColour='';


function append(array, item) {
	array[array.length] = item
}

function arrayAdd(aArray, aItem) {
	aArray[aArray.length] = aItem
}

function arrayDeleteAtPos(array, intPos) {
	if (intPos < array.length && intPos >= 0) {
		var value = array[intPos]
		arrayDeleteValue(array, value)
	}
}

function arrayDeleteValue(array, value) {
	var intPos = arrayHas(array, value)
	if (intPos >= 0) {
		for (var intIndex=intPos;intIndex<array.length-1;intIndex++) {
			array[intIndex] = array[intIndex + 1]
		}
		array.length = array.length - 1
	}
}

function arrayHas(array, value) {
	for(var intIndex=0; intIndex<=array.length; intIndex++) {
		if (array[intIndex] + '' == value + '') return intIndex
	}
	return -1
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function containsIllegalPathChars(strPath) {
	//( ) [ ] \ : * ? " < > |
	if (strPath.indexOf('/') >= 0) return true;
	if (strPath.indexOf('(') >= 0) return true;
	if (strPath.indexOf(')') >= 0) return true;
	if (strPath.indexOf('[') >= 0) return true;
	if (strPath.indexOf(']') >= 0) return true;
	if (strPath.indexOf('\\') >= 0) return true;
	if (strPath.indexOf(':') >= 0) return true;
	if (strPath.indexOf('*') >= 0) return true;
	if (strPath.indexOf('?') >= 0) return true;
	if (strPath.indexOf('<') >= 0) return true;
	if (strPath.indexOf('>') >= 0) return true;
	if (strPath.indexOf('|') >= 0) return true;
	if (strPath.indexOf('&') >= 0) return true;
	return false;
}

function dwfQueryParams() {
	this.key_array = [];
	this.value_array = [];
	if (dwf.ajax_request_id) {
		append(this.key_array, '6C23B766-FD15-4BE8-80DE-AE8CBE5D93DB');
		append(this.value_array, '');
	}
	
	this.add = function(strKey, strValue) {
		append(this.key_array, strKey);
		append(this.value_array, strValue);
	}

	this.toString = function() {
		var strParams = '';
		for (var i=0; i<this.key_array.length; i++) {
			if (strParams > '') strParams += '&';
			strParams += (this.key_array[i] + '=' + this.value_array[i]);
		}
		strParams = strParams + '&' + Math.random(0, 1000) + '=' + Math.random(0, 1000)
		return strParams
	}
}

function dwfAjaxQuery(strPage) {
	this.page = strPage;
	this.key_array = [];
	this.value_array = [];
	this.dwfParams = new dwfQueryParams();
	
	this.addParam = function(strKey, strValue) {
		this.dwfParams.add(strKey, strValue);
	}

	this.execute = function() {
		var strURL = document.location.href;
		xend = strURL.lastIndexOf('?') + 1;
		var base_url = strURL.substring(0, xend);
		var full_url = base_url + 'Page=' + this.page + '&' + this.dwfParams.toString() + '&' + Math.random(0, 1000) + '=' + Math.random(0, 1000) + '&6C23B766-FD15-4BE8-80DE-AE8CBE5D93DB';
		try {
			var jsel = document.createElement('SCRIPT');
			jsel.language = 'javascript';
			jsel.type = 'text/javascript';
			jsel.src = full_url;
			document.body.appendChild(jsel);
		} catch(Ex) {
			alert('Error making ajax call: ' + Ex.description);
		}
	}
}

function trim(aString) {
	return aString.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_openBrWindow(theURL,winName,features) {
	var tTitle;
	if (theURL.substr(0,4) != "http") {
		theURL = "http://" + window.location.hostname + theURL;
	}
	if (features == null) {
		var win = window.open(theURL,winName);
	} else {
		var win = window.open(theURL,winName,features);
	}
	return win;
}

function getFieldValue(aFormName, aFieldName) {
	var strValue = null;
	switch(getFieldType(aFormName, aFieldName)) {
		case 'checkbox':
			var boolChecked = false;
			var str = 'document.' + aFormName + '.' + aFieldName + '.checked;';
			try {boolChecked = eval(str);} catch(e) {boolChecked = false;}
			if (boolChecked) {
				var str = 'document.' + aFormName + '.' + aFieldName + '.value;';
				try {strValue = eval(str);} catch(e) {strValue = '';}
			} else {
				strValue = '';
			}
			break;
		default:
			var str = 'document.' + aFormName + '.' + aFieldName + '.value;';
			try {strValue = eval(str);} catch(e) {strValue = '';}
			break;
	}
	return strValue;
}

function getFieldType(aFormName, aFieldName) {
	var strType = null;
	var str = 'strType = document.' + aFormName + '.' + aFieldName + '.type;';	
	eval(str);
	return strType;
}

function getFrame(strFrameName) {
	for (var i=0; i < parent.frames.length; i++) if (parent.frames[i].name == strFrameName) return parent.frames[i];
}

function getTopFrame(strFrameName) {
	for (var i=0; i < top.frames.length; i++) if (top.frames[i].name == strFrameName) return top.frames[i];
}

function getSubFrame(frm, strSubFrameName) {
	for (var i=0; i < frm.frames.length; i++) if (frm.frames[i].name == strSubFrameName) return frm.frames[i];
}

function setFieldValue(strFormName, strFieldName, strValue) {
	var str = 'document.forms["' + strFormName + '"].' + strFieldName + '.value="' + strValue + '";';
	eval(str);
}

function getFieldValueInt(aFormName, aFieldName) {
	var strValue = null;
	var str = 'strValue = document.' + aFormName + '.' + aFieldName + '.value;';
	eval(str);
	return parseInt(trim(strValue));
}

function getPos(objArray, value) {
	for(var i=0; i<objArray.length;i++) {
		if (objArray[i] + '' == value + '') return i
	}
	return -1
}

function getSelectText(objSelect) {
	var intIndex = objSelect.selectedIndex;
	var objOption = objSelect[intIndex];
	return objOption.text;
}

function getSelectValue(objSelect) {
	var intIndex = objSelect.selectedIndex;
	var objOption = objSelect[intIndex];
	return objOption.value;
}

function setFocus(aFormName, aFieldName) {
	var obj = null;
	var str = 'obj = document.' + aFormName + '.' + aFieldName;
	eval(str);
	obj.focus();
}

function getHTTPRoot() {
	var str = window.location.protocol + '//' + window.location.hostname + window.location.pathname;
	return str;
}

function getAppRoot() {
	var str = 'http://' + window.location.hostname + window.location.pathname;
	return str;
}

function getHTTPSRoot() {
/*	if (window.location.hostname == 'localhost') {
		var str = 'http://'+ window.location.hostname + window.location.pathname;
	} else {
		var str = 'https://'+ window.location.hostname + window.location.pathname;
	}
	return str;*/
	var str = 'https://'+ window.location.hostname + window.location.pathname;
	return str;
}

function getHTTPServer() {
	if (window.location.hostname == 'localhost') {
		var str = 'http://'+ window.location.hostname + pathFromURL(window.location.pathname);
	} else {
		var str = 'https://'+ window.location.hostname + '/';
	}
	return str;
}

function getMonitorWidth() {
	return screen.width;
}

function getMonitorHeight() {
	return screen.height;
}

function isNull(aItem) {
	var item = aItem + ''
	return ((item == 'null') || (item == 'undefined'))
}

function _preloadImages()
{
    var tImgFiles = preloadImages.arguments;

    if (document.preloadArray==null) document.preloadArray = new Array();
    var tPreloadSize = document.preloadArray.length;
	var tIndex = 0;
    for (tIndex = 0; tIndex < tImgFiles.length; tIndex++)
	{
		document.preloadArray[tPreloadSize] = new Image();
		document.preloadArray[tPreloadSize].src = tImgFiles[tIndex];
		tPreloadSize++;
  	}
}

function _setImage(aObjectName, aImageURL)
{
	tImageObject = eval(aObjectName);
	if (tImageObject != null)
	{
		tImageObject.src = aImageURL;
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function orderBy(strFieldName) {
	if (document.form1.orderby.value == strFieldName) {
		if (document.form1.direction.value == 'asc') {
			document.form1.direction.value = 'desc';
		} else {
			document.form1.direction.value = 'asc';
		}
	} else {
		document.form1.orderby.value = strFieldName;
		document.form1.direction.value = 'asc';
	}
	document.form1.PageNr.value = 1;
	document.form1.submit();
}

function pathFromURL(strURL) {
	var intURLLen = strURL.length
	var intLastIndex = strURL.lastIndexOf('/')
	return strURL.substring(0, intLastIndex + 1)
}

function right(str, intSize) {
	str = str + ''
	strOut = new String()

	if (isNull(intSize)) {
		strOut = str
	} else {
		if (intSize <= str.length) {
			strOut = str.substring(str.length - intSize, str.length)
		} else {
			strOut = str
		}
	}
	return strOut
}

function setStatusMsg(strMsg) {
	window.status = strMsg;
}

function setClass(obj, strClassName) {
    obj.className = strClassName;
}

function gotoPage(strMethod, intPageNr, strPageNrField) {
	document.form1.page.value = strMethod;
	var fldPageNr = eval('document.form1.' + strPageNrField)
	if (fldPageNr) fldPageNr.value = intPageNr;
//	document.form1.PageNr.value = intPageNr;
	document.form1.submit();
}

/*function gotoPage(strMethod, intPageNr, strPageNrField) {
	document.form1.page.value = strMethod;
	document.form1.PageNr.value = intPageNr;
	document.form1.submit();
}*/

function pageNav(objSelect, strMethod, strPageNrField) {
	document.form1.page.value = strMethod;
	/*var fldPageNr = eval('document.form1.' + strPageNrField)
	if (fldPageNr) fldPageNr.value = objSelect.value;*/
	document.form1.PageNr.value = objSelect.value;
	document.form1.submit();
}

function printWindow(objWin) {
	objWin.focus();
	if (objWin.print) {
	    objWin.print();
	} else {
	    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		objWin.document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box
	    WebBrowser1.outerHTML = "";
	}
}

function validateDate(strFormName, strName) {
	if (getFieldValue(strFormName, strName + '_day') == '') {
		alert('Please select a day');
		setFocus(strFormName, strName + '_day');
		return false;
	}
	if (getFieldValue(strFormName, strName + '_month') == '') {
		alert('Please select a month');
		setFocus(strFormName, strName + '_month');
		return false;
	}
	if (getFieldValue(strFormName, strName + '_year') == '') {
		alert('Please select a year');
		setFocus(strFormName, strName + '_year');
		return false;
	}
	return true
}

function verifyFloat(objField) {
	var strValue = objField.value;
	var strNewValue = '';
	for(var intIndex=0;intIndex<strValue.length;intIndex++) {
		var intCharCode = strValue.charCodeAt(intIndex);
		if (intCharCode == 46 || (intCharCode >= 48 && intCharCode <= 57)) {
			strNewValue += strValue.charAt(intIndex)
		}
	}
	var strNewValueArray = strNewValue.split('.')
	if (strNewValueArray.length > 1) {
		var strInt = strNewValueArray[0];
		var strFrac = strNewValueArray[1];
		strFrac = strFrac.replace(/\./gi, '')
		strNewValue = strInt + '.' + strFrac
	}
	objField.value = strNewValue;
}

function verifyInteger(objField) {
	var strValue = objField.value;
	var strNewValue = '';
	for(var intIndex=0;intIndex<strValue.length;intIndex++) {
		var intCharCode = strValue.charCodeAt(intIndex);
		if (intCharCode >= 48 && intCharCode <= 57) {
			strNewValue += strValue.charAt(intIndex)
		}
	}
	objField.value = strNewValue;
}

function verifyCode(objField) {
	var strValue = objField.value;
	var strNewValue = '';
	var intLegalCharArray = [48,49,50,51,52,53,54,55,56,57, 32, 65, 66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90, 95, 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122]
	for(var intIndex=0;intIndex<strValue.length;intIndex++) {
		var intCharCode = strValue.charCodeAt(intIndex);
		var intChar = strValue.charAt(intIndex)
		if (getPos(intLegalCharArray, intCharCode) >= 0) {
			if (intCharCode == 32) intChar = '_';
			if (intCharCode >= 97 && intCharCode <=122) intChar = intChar.toUpperCase();
			strNewValue += intChar
		}
	}
	objField.value = strNewValue;
}

function ajax_do(strPage, strParams) {
	var strURL = document.location.href;
	xend = strURL.lastIndexOf('?') + 1;
	var base_url = strURL.substring(0, xend);
	var strFullURL = base_url + 'Page=' + strPage + '&' + strParams + '&' + Math.random(0, 1000) + '=' + Math.random(0, 1000) + '&6C23B766-FD15-4BE8-80DE-AE8CBE5D93DB';
	// Create new JS element
	try {
		var jsel = document.createElement('SCRIPT');
		jsel.language = 'javascript';
		jsel.type = 'text/javascript';
		jsel.src = strFullURL;
		document.body.appendChild(jsel);
	} catch(Ex) {
		alert('Error making ajax call: ' + Ex.description);
	}
}

function getDivLeft(oDiv) {
	if(dwfBrowser == "nn4") {
		return oDiv.left;
	}
	else if(dwfBrowser == "ie4") {
		return oDiv.style.pixelLeft;
	}
	else if(dwfBrowser == "gecko") {
		return oDiv.style.left;
	}
	else if(dwfBrowser == "ie") {
		return oDiv.style.left;
	}
}

function getDivTop(oDiv) {
	if(dwfBrowser == "nn4") {
		return oDiv.top=intTop;
	}
	else if(dwfBrowser == "ie4") {
		return oDiv.style.pixelTop;
	}
	else if(dwfBrowser == "gecko") {
		return oDiv.style.top;
	}
	else if(dwfBrowser == "ie") {
		return oDiv.style.top;
	}
}

function setDivLoc(oDiv, intLeft, intTop, intWidth) {
	if(dwfBrowser == "nn4") {
		oDiv.left=intLeft;
		oDiv.top=intTop;
		if (intWidth) oDiv.right = oDiv.left + intWidth;
	}
	else if(dwfBrowser == "ie4") {
		oDiv.style.pixelLeft=intLeft;
		oDiv.style.pixelTop=(intTop + document.body.scrollTop);
		if (intWidth) oDiv.pixelRight = oDiv.style.pixelLeft + intWidth;
	}
	else if(dwfBrowser == "gecko") {
		oDiv.style.left=intLeft;
		oDiv.style.top=intTop;
		if (intWidth) oDiv.style.right = oDiv.style.left + intWidth;
	}
	else if(dwfBrowser == "ie") {
		oDiv.style.left = intLeft;
		oDiv.style.top = intTop;
		if (intWidth) oDiv.style.width = intWidth;
	}
}

function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
 }

function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
	    while(1)
	    {
	      curtop += obj.offsetTop;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.y)
    curtop += obj.y;
	return curtop;
}

function getElementHeight(strId) {
	if(document.getElementById(strId).clientHeight) {
		return document.getElementById(strId).clientHeight;
	} 
	else {
		if(document.getElementById(strId).offsetHeight) {
			alert(document.getElementById(strId).offsetHeight);
		}
	}
}

function getElementWidth(strId) {
	if(document.getElementById(strId).clientWidth) {
		return document.getElementById(strId).clientWidth;
	} 
	else {
		if(document.getElementById(strId).offsetWidth) {
			return document.getElementById(strId).offsetWidth;
		}
	}
}

function positionIFrame(divid, frmid) {
	var div = document.getElementById(divid);
	var frm = document.getElementById(frmid);
	frm.style.left = div.style.left;
	frm.style.top = div.style.top;
	frm.style.height = div.offsetHeight;
	frm.style.width = div.offsetWidth;
	frm.style.display = "block";	
}

function positionDiv(divid, frmid) {	
	var div = document.getElementById(divid);
	div.style.left=findPosX(document.getElementById("slct"))+ 5 + "px";
	div.style.top=findPosY(document.getElementById("slct"))+ 5 + "px";
	positionIFrame(divid, frmid);
}

function autoResizeDivPercent(strDivName, intPercentage) {
	if (isNull(intPercentage)) intPercentage = 100;
	if (intPercentage > 100) intPercentage = 100;
	var windowHeight = getViewPortHeight();
	var oDiv = MM_findObj(strDivName, document);
	if (oDiv) oDiv.style.height = parseInt((windowHeight * (intPercentage / 100))) + "px";
}

function autoResizeDivFixed(strDivName, intPixels) {
	if (intPixels < 0) intPixels = 0;
	var oDiv = MM_findObj(strDivName, document);
	var windowHeight = getViewPortHeight();
	if (oDiv) oDiv.style.height = (windowHeight - intPixels) + "px";
}

function getViewPortHeight() {
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		isIE = false;
		return window.innerHeight;
	} else if( document.documentElement && (document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.clientHeight;
		} else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		return document.body.clientHeight;
	}	
}

function getViewPortWidth() {
	if(typeof( window.innerWidth ) == 'number') {
		//Non-IE
		isIE = false;
		return window.innerWidth;
	} else if(document.documentElement && (document.documentElement.clientWidth)) {
		//IE 6+ in 'standards compliant mode'
		//browserWidth = document.documentElement.clientWidth;
		return document.documentElement.clientWidth;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		return document.body.clientWidth;
	}	
}

function setInnerHTML(strDivId, str) {
	var obj = MM_findObj(strDivId, document);
	if (obj) obj.innerHTML = unescape(str);
}

function appendInnerHTML(strDivId, str) {
	var obj = MM_findObj(strDivId, document);
	if (obj) obj.innerHTML += unescape(str);
}

function setObjectColour(strId, strColour) {
	var obj = MM_findObj(strId, document);
	if (obj) obj.style.backgroundColor = strColour;
}

function setTableRowBGColour(strTableId, strColour) {
	var obj = MM_findObj(strTableId, document);
	if (obj) {
		var rows = obj.getElementsByTagName('tr');
		for (var i=0; i<rows.length; i++) rows[i].style.backgroundColor = strColour;
	}
}

function highlightrow(strRowId, strColour) {
	if (sClickedRowId > '') {
		setBackgroundColor(sClickedRowId, strColour);
	}
/*	if (strRowId == sClickedRowId) {
		sClickedRowId='';
		sClickedColour='';
	} else {
		sClickedRowId=strRowId;
		sClickedColour=strColour;
		setBackgroundColor(strRowId, strColour);
	}*/
	if (strRowId != sClickedRowId) {
		setBackgroundColor(sClickedRowId, sMouseOverColour);
		sClickedRowId=strRowId;
		sClickedColour=strColour;
		setBackgroundColor(strRowId, strColour);
	}
}

function mouseOverRow(strRowId, strBackgroundColour, strCursor) {
	if (strRowId != sClickedRowId) {
		sMouseOverRowId=strRowId;
		sMouseOverColour = getBackgroundColour(strRowId);
		setBackgroundColor(strRowId, strBackgroundColour);
		setCursor(strRowId, strCursor);
	}
}

function mouseOutRow() {
	if (sMouseOverRowId != sClickedRowId) {
		setBackgroundColor(sMouseOverRowId, sMouseOverColour);
		setCursor(sMouseOverRowId, 'default');
		sMouseOverRowId='';
		sMouseOverColour= '';
	}
}

function getBackgroundColour(strId) {
	var obj = MM_findObj(strId, document);
	if (obj) return obj.style.backgroundColor;
}

function setBackgroundColor(strId, strColour) {
	var obj = MM_findObj(strId, document);
	if (obj) obj.style.backgroundColor = strColour;
}

function setCursor(strId, strCursor) {
	var obj = MM_findObj(strId, document);
	if (obj) obj.style.cursor = strCursor;
}

function img_moveby(img, x, y) {
	if (img) {
		alert(img.y);
		img.x=(img.x + x) + 'px';
		img.y=(img.y + y) + 'px';
	}
}

function btn_mousedown(obj) {
	img_moveby(obj, 1, 1);
}

function btn_mouseup(obj) {
	img_moveby(obj, -1, -1);
}

var dwf = {};

if (dwf !== undefined) {
	dwf.ajax_request_id = '6C23B766-FD15-4BE8-80DE-AE8CBE5D93DB';
}

