var cstrDateFormat = "dd/mm/yyyy";

function VirtualPath(strFilePath)
{
	var intPos;
	
	if ((intPos = strFilePath.lastIndexOf("/")) > -1)
	{
		return strFilePath.substring(0, intPos);
	}
}

function HighLight(objRow)
{
	objRow.className = "Hover";
}

function UnHighLight(objRow)
{
	objRow.className = "Inactive";
}

function OnBrowse(strUrl)
{
	if (strUrl.indexOf("http://") == -1)
	{
		window.open("http://" + strUrl);
	}
	else
	{
		window.open(strUrl);
	}
}

function OnClose()
{
	window.close();
}

function isDigit()
{	
	var key = window.event.keyCode;
	
	if (((key > 47) && (key <  58)) || key == 13)
	{      
		return true;   
	}      
	
	return false;
}

function ZoomImage(strPictureName)
{
	var objImage = new Image();
	objImage.src = strPictureName;
	objImage.onload = function()
	{
		ZoomLoadedImage(objImage);
	}
	if (objImage.complete)					// Image is in cache -> onload event never occurs
	{
		ZoomLoadedImage(objImage);
	}
}

function ZoomLoadedImage(objImage)
{
	if (objImage.width > 800)
	{
		objImage.height = objImage.height * 800 / objImage.width;
		objImage.width = 800;
	}

	if (objImage.height > 600)
	{
		objImage.width = objImage.width * 600 / objImage.height;
		objImage.height = 600;
	}
	
	var intLeft = (screen.availWidth / 2) - (objImage.width / 2);
	var intTop = (screen.availHeight / 2) - (objImage.height / 2);
	var strSettings = "toolbar=no,status=no,help=no,resizable=no,left=" + intLeft + ",top="+ intTop + ",width=" + objImage.width + ",height=" + objImage.height;
	var objWindow = window.open(objImage.src, "", strSettings);
	var strHtml = "<html><head><title>Preview</title></head><body style='margin: 0 0 0 0'><img src='" +
		objImage.src + "' width=" + objImage.width + "height=" + objImage.height + "></body></html>";
		
	objWindow.document.write(strHtml);
	objWindow.resizeBy(objImage.width - objWindow.document.body.clientWidth, objImage.height - objWindow.document.body.clientHeight);
	objWindow.focus();
}

function PrintDocument(strContent)
{
	var intWidth = 800;
	var intHeight = 600;
	var intLeft = (screen.availWidth / 2) - (intWidth / 2);
	var intTop = (screen.availHeight / 2) - (intHeight / 2);
	var strSettings = "toolbar=no,status=no,help=no,scrollbars=yes,resizable=no,left=" + intLeft + ",top="+ intTop + ",width=" + intWidth + ",height=" + intHeight;
	var objWindow = window.open("", "", strSettings);
	var strHtml = "<html><head><title>Preview</title><script language=javascript>function Print(){window.print();}</script><style>body { font-size: 12px; font-family: Verdana; color: #000000 } td { font-size: 12px; font-family: Verdana; color: #000000 }</style></head><body style='margin: 0 0 0 0'>" +
		strContent + "</body></html>";
		
	objWindow.document.write(strHtml);
	objWindow.resizeBy(intWidth - objWindow.document.body.clientWidth, intHeight - objWindow.document.body.clientHeight);
	objWindow.focus();
	objWindow.location.reload(false);
	objWindow.Print();
}

function SwapImage(objImg, strPath)
{
	objImg.src = strPath;
}

function FindChild(objParent,objChild)
{
	for(;;)
	{
		if( objChild.tagName.toLowerCase() != "body")
		{
			if(objChild.id == objParent.id)
			{
				return true;
			}
			else
			{
				objChild = objChild.parentNode;
			}
		}
		else
		{
			return false;
		}
	}
}

/*----------------------------------------------------------------------------\
|                                   IE Emu                                    |
|-----------------------------------------------------------------------------|
|                         Created by Erik Arvidsson                           |
|                  (http://webfx.eae.net/contact.html#erik)                   |
|                      For WebFX (http://webfx.eae.net/)                      |
|-----------------------------------------------------------------------------|
| A emulation of Internet Explorer DHTML Object Model for Mozilla             |
|-----------------------------------------------------------------------------|
|                  Copyright (c) 1999 - 2004 Erik Arvidsson                   |
|-----------------------------------------------------------------------------|
| This software is provided "as is", without warranty of any kind, express or |
| implied, including  but not limited  to the warranties of  merchantability, |
| fitness for a particular purpose and noninfringement. In no event shall the |
| authors or  copyright  holders be  liable for any claim,  damages or  other |
| liability, whether  in an  action of  contract, tort  or otherwise, arising |
| from,  out of  or in  connection with  the software or  the  use  or  other |
| dealings in the software.                                                   |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| This  software is  available under the  three different licenses  mentioned |
| below.  To use this software you must chose, and qualify, for one of those. |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| The WebFX Non-Commercial License          http://webfx.eae.net/license.html |
| Permits  anyone the right to use the  software in a  non-commercial context |
| free of charge.                                                             |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| The WebFX Commercial license           http://webfx.eae.net/commercial.html |
| Permits the  license holder the right to use  the software in a  commercial |
| context. Such license must be specifically obtained, however it's valid for |
| any number of  implementations of the licensed software.                    |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| GPL - The GNU General Public License    http://www.gnu.org/licenses/gpl.txt |
| Permits anyone the right to use and modify the software without limitations |
| as long as proper  credits are given  and the original  and modified source |
| code are included. Requires  that the final product, software derivate from |
| the original  source or any  software  utilizing a GPL  component, such  as |
| this, is also licensed under the GPL license.                               |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| MPL - Mozilla Public License                    http://www.mozilla.org/MPL/ |
|                                                                             |
| The contents of this file are subject to the Mozilla Public License Version |
| 1.1 (the "License"); you may not use this file except in compliance with    |
| the License. You may obtain a copy of the License at                        |
| http://www.mozilla.org/MPL/                                                 |
|                                                                             |
| Software distributed under the License is distributed on an "AS IS" basis,  |
| WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License    |
| for the specific language governing rights and limitations under the        |
| License.                                                                    |
|                                                                             |
| The Original Code is IE Emu.                                                |
|                                                                             |
| The Initial Developer of the Original Code is Erik Arvidsson.               |
| Portions created by the Initial Developer are Copyright (C) 1999-2004       |
| the Initial Developer. All Rights Reserved.                                 |
|                                                                             |
| Contributor(s):                                                             |
|                                                                             |
|-----------------------------------------------------------------------------|
| 2002-??-?? | First version                                                  |
| 2004-04-13 | Impreved currentStyle emulation. Updated to not that the code  |
|            |is available under GPL, MPL or WebFX Non-Commercial License     |
|-----------------------------------------------------------------------------|
| Created 2002-??-?? | All changes are in the log above. | Updated 2004-04-13 |
\----------------------------------------------------------------------------*/

var ie = /MSIE/.test(navigator.userAgent);
var moz = !ie && navigator.product == "Gecko";


if (moz) {	// set up ie environment for Moz

	extendEventObject();
	//emulateAttachEvent();
	//emulateFromToElement();
	emulateEventHandlers(["click", "dblclick", "mouseover", "mouseout",
							"mousedown", "mouseup", "mousemove",
							"keydown", "keypress", "keyup"]);
	emulateAllModel();
	extendElementModel()
	emulateCurrentStyle();

	// It is better to use a constant for event.button
	Event.LEFT = 0;
	Event.MIDDLE = 1;
	Event.RIGHT = 2;
}
else {
	Event = {};
	// IE is returning wrong button number
	Event.LEFT = 1;
	Event.MIDDLE = 4;
	Event.RIGHT = 2;
}




/*
 * Extends the event object with srcElement, cancelBubble, returnValue,
 * fromElement and toElement
 */
function extendEventObject() {
	Event.prototype.__defineSetter__("returnValue", function (b) {
		if (!b) this.preventDefault();
		return b;
	});

	Event.prototype.__defineSetter__("cancelBubble", function (b) {
		if (b) this.stopPropagation();
		return b;
	});

	Event.prototype.__defineGetter__("srcElement", function () {
		var node = this.target;
		while (node.nodeType != 1) node = node.parentNode;
		return node;
	});

	Event.prototype.__defineGetter__("fromElement", function () {
		var node;
		if (this.type == "mouseover")
			node = this.relatedTarget;
		else if (this.type == "mouseout")
			node = this.target;
		if (!node) return;
		while (node.nodeType != 1) node = node.parentNode;
		return node;
	});

	Event.prototype.__defineGetter__("toElement", function () {
		var node;
		if (this.type == "mouseout")
			node = this.relatedTarget;
		else if (this.type == "mouseover")
			node = this.target;
		if (!node) return;
		while (node.nodeType != 1) node = node.parentNode;
		return node;
	});

	Event.prototype.__defineGetter__("offsetX", function () {
		return this.layerX;
	});
	Event.prototype.__defineGetter__("offsetY", function () {
		return this.layerY;
	});
}

/*
 * Emulates element.attachEvent as well as detachEvent
 */
function emulateAttachEvent() {
	HTMLDocument.prototype.attachEvent =
	HTMLElement.prototype.attachEvent = function (sType, fHandler) {
		var shortTypeName = sType.replace(/on/, "");
		fHandler._ieEmuEventHandler = function (e) {
			window.event = e;
			return fHandler();
		};
		this.addEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
	};

	HTMLDocument.prototype.detachEvent =
	HTMLElement.prototype.detachEvent = function (sType, fHandler) {
		var shortTypeName = sType.replace(/on/, "");
		if (typeof fHandler._ieEmuEventHandler == "function")
			this.removeEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
		else
			this.removeEventListener(shortTypeName, fHandler, true);
	};
}

/*
 * This function binds the event object passed along in an
 * event to window.event
 */
function emulateEventHandlers(eventNames) {
	for (var i = 0; i < eventNames.length; i++) {
		document.addEventListener(eventNames[i], function (e) {
			window.event = e;
		}, true);	// using capture
	}
}

/*
 * Simple emulation of document.all
 * this one is far from complete. Be cautious
 */

function emulateAllModel() {
	var allGetter = function () {
		var a = this.getElementsByTagName("*");
		var node = this;
		a.tags = function (sTagName) {
			return node.getElementsByTagName(sTagName);
		};
		return a;
	};
	HTMLDocument.prototype.__defineGetter__("all", allGetter);
	HTMLElement.prototype.__defineGetter__("all", allGetter);
}

function extendElementModel() {
	HTMLElement.prototype.__defineGetter__("parentElement", function () {
		if (this.parentNode == this.ownerDocument) return null;
		return this.parentNode;
	});

	HTMLElement.prototype.__defineGetter__("children", function () {
		var tmp = [];
		var j = 0;
		var n;
		for (var i = 0; i < this.childNodes.length; i++) {
			n = this.childNodes[i];
			if (n.nodeType == 1) {
				tmp[j++] = n;
				if (n.name) {	// named children
					if (!tmp[n.name])
						tmp[n.name] = [];
					tmp[n.name][tmp[n.name].length] = n;
				}
				if (n.id)		// child with id
					tmp[n.id] = n
			}
		}
		return tmp;
	});

	HTMLElement.prototype.contains = function (oEl) {
		if (oEl == this) return true;
		if (oEl == null) return false;
		return this.contains(oEl.parentNode);
	};
}

function emulateCurrentStyle() {
	HTMLElement.prototype.__defineGetter__("currentStyle", function () {
		return this.ownerDocument.defaultView.getComputedStyle(this, null);
		/*
		var cs = {};
		var el = this;
		for (var i = 0; i < properties.length; i++) {
			cs.__defineGetter__(properties[i], encapsulateObjects(el, properties[i]));
		}
		return cs;
		*/
	});
}

function emulateHTMLModel() {

	// This function is used to generate a html string for the text properties/methods
	// It replaces '\n' with "<BR"> as well as fixes consecutive white spaces
	// It also repalaces some special characters
	function convertTextToHTML(s) {
		s = s.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<BR>");
		while (/\s\s/.test(s))
			s = s.replace(/\s\s/, "&nbsp; ");
		return s.replace(/\s/g, " ");
	}

	HTMLElement.prototype.insertAdjacentHTML = function (sWhere, sHTML) {
		var df;	// : DocumentFragment
		var r = this.ownerDocument.createRange();

		switch (String(sWhere).toLowerCase()) {
			case "beforebegin":
				r.setStartBefore(this);
				df = r.createContextualFragment(sHTML);
				this.parentNode.insertBefore(df, this);
				break;

			case "afterbegin":
				r.selectNodeContents(this);
				r.collapse(true);
				df = r.createContextualFragment(sHTML);
				this.insertBefore(df, this.firstChild);
				break;

			case "beforeend":
				r.selectNodeContents(this);
				r.collapse(false);
				df = r.createContextualFragment(sHTML);
				this.appendChild(df);
				break;

			case "afterend":
				r.setStartAfter(this);
				df = r.createContextualFragment(sHTML);
				this.parentNode.insertBefore(df, this.nextSibling);
				break;
		}
	};

	HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
	   var r = this.ownerDocument.createRange();
	   r.setStartBefore(this);
	   var df = r.createContextualFragment(sHTML);
	   this.parentNode.replaceChild(df, this);

	   return sHTML;
	});

	HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
		switch (this.tagName) {
			case "AREA":
			case "BASE":
			case "BASEFONT":
			case "COL":
			case "FRAME":
			case "HR":
			case "IMG":
			case "BR":
			case "INPUT":
			case "ISINDEX":
			case "LINK":
			case "META":
			case "PARAM":
				return false;
		}
		return true;
	});

	HTMLElement.prototype.__defineGetter__("outerHTML", function () {
		var attr, attrs = this.attributes;
		var str = "<" + this.tagName;
		for (var i = 0; i < attrs.length; i++) {
			attr = attrs[i];
			if (attr.specified)
				str += " " + attr.name + '="' + attr.value + '"';
		}
		if (!this.canHaveChildren)
			return str + ">";

		return str + ">" + this.innerHTML + "</" + this.tagName + ">";
	});


	HTMLElement.prototype.__defineSetter__("innerText", function (sText) {
		this.innerHTML = convertTextToHTML(sText);
		return sText;
	});

	var tmpGet;
	HTMLElement.prototype.__defineGetter__("innerText", tmpGet = function () {
		var r = this.ownerDocument.createRange();
		r.selectNodeContents(this);
		return r.toString();
	});

	HTMLElement.prototype.__defineSetter__("outerText", function (sText) {
		this.outerHTML = convertTextToHTML(sText);
		return sText;
	});
	HTMLElement.prototype.__defineGetter__("outerText", tmpGet);

	HTMLElement.prototype.insertAdjacentText = function (sWhere, sText) {
		this.insertAdjacentHTML(sWhere, convertTextToHTML(sText));
	};
}

// Program: document.elementFromPoint(int clientX, int clientY) in Gecko
// Author: Jason Karl Davis (www.jasonkarldavis.com)
// Date: 15 June 2003
// Purpose: Emulate Internet Explorer's document.elementFromPoint method as described here:
// http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/elementfrompoint.asp
// Requirements: A browser built off of the 1.4 branch of Mozilla (or better)
// Distribution: You may freely distribute and use this script as long as these comments remain intact

if (navigator.product == "Gecko") 
{

	Document.prototype.elementFromPoint = function(x, y) 
	{
		this.addEventListener("mousemove", this.elementFromPoint__handler, false);
		var event = this.createEvent("MouseEvents");
		var box = this.getBoxObjectFor(this.documentElement);
		var screenDelta = { x: box.screenX, y: box.screenY };
		event.initMouseEvent("mousemove", true, false, this.defaultView, 0, x + screenDelta.x, y + screenDelta.y, x, y, false, false, false, false, 0, null);
		this.dispatchEvent(event);
		this.removeEventListener("mousemove", this.elementFromPoint__handler, false);
		return this.elementFromPoint__target;
	}

	Document.prototype.elementFromPoint__handler = function (event) 
	{
		this.elementFromPoint__target = event.explicitOriginalTarget;

		// reparent target if it is a text node to emulate IE's behavior
		if (this.elementFromPoint__target.nodeType == Node.TEXT_NODE)
		this.elementFromPoint__target = this.elementFromPoint__target.parentNode;

		// change an HTML target to a BODY target to emulate IE's behavior (if we are in an HTML document)
		if (this.elementFromPoint__target.nodeName.toUpperCase() == "HTML" && this.documentElement.nodeName.toUpperCase() == "HTML")
		this.elementFromPoint__target = this.getElementsByTagName("BODY").item(0);

		event.preventDefault();
		event.stopPropagation();
	}
	
	Document.prototype.elementFromPoint__target = null;
}

// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// for Netscape 6/Mozilla by Thor Larholm me@jscript.dk
// Usage: include this code segment at the beginning of your document
// before any other Javascript contents.

if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function
(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function
(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function
(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}

function printHidden(url) {
  document.body.insertAdjacentHTML("beforeEnd", "<iframe name=printHiddenFrame width=0 height=0></iframe>");
  doc = printHiddenFrame.document;
  doc.open();
  doc.write(
    "<frameset rows=\"100%\">" +
    "<frame name=printMe src=\""+url+"\">" +
    "</frameset>");
  doc.close();

if(document.all)
	var frameref = top.frames['printHiddenFrame'].printMe;
  else
	var frameref = top.frames['printHiddenFrame'];
  
  frameref.focus();
 frameref.print();
}
