// #################################################################################
// <SCRIPT>
// K JS Library
// Javascript Universal Include File
// (c) 2004 ID-3 Technologies inc. All right reserved
// #################################################################################

// MenuPosition
var id3MenuRight = 1;
var id3MenuLeft = 2;
var id3MenuOver = 3;
var id3MenuUnder = 4;

// MenuOrientation
var id3MenuDownRight = 1;
var id3MenuDownLeft = 2;
var id3MenuUpRight = 3;
var id3MenuUpLeft = 4;

// MenuSpan
var id3MenuSpanVertical = 1;
var id3MenuSpanHorizontal = 2;

// MenuStyle
var id3MenuStylePopup = 0;
var id3MenuStylePanel = 1
var id3MenuStyleMap = 2
var id3MenuStyleTreeView = 3


var KScript = new KASP_GenObj();
var KMenu = new KMenuManagerObj();
var KForm = new KFormManagerObj();
var KModDisplay = new KModuleDisplayManagerObj();


// Generic client script object
function KASP_GenObj(){
	if(!this.callPrototype()){
		this.addMethod(findObj);
		this.addMethod(getAbsoluteLeft);
		this.addMethod(getAbsoluteTop);
		this.addMethod(MouseOver);
		this.addMethod(MouseOut);
		this.addMethod(PopupWindow);
		this.addMethod(ToggleLanguage);
		this.addMethod(SetLanguage);
	}

	// #################################################################################
	// getAbsoluteLeft
	// #################################################################################
	function getAbsoluteLeft(obj,iLeft){
		iLeft = (typeof(iLeft)=="undefined")?0:iLeft;
		if (obj.offsetParent != null){
			iLeft += obj.offsetLeft;
			return(this.getAbsoluteLeft(obj.offsetParent,iLeft));
		}
		else{
			return(iLeft);
		}
	}
	
	// #################################################################################
	// getAbsoluteTop
	// #################################################################################
	function getAbsoluteTop(obj,iTop){
		iTop = (typeof(iTop)=="undefined")?0:iTop;
		if (obj.offsetParent != null){
			iTop += obj.offsetTop;
			return(this.getAbsoluteTop(obj.offsetParent,iTop));
		}
		else{
			return(iTop);
		}
	}
	
	function MouseOver(){
		for (var i=0; i<MouseOver.arguments.length; i+=2) {
			var obj = MouseOver.arguments[i+1]
			obj.sNormImg = obj.src;
			obj.sOverImg = MouseOver.arguments[i];
			obj.src = obj.sOverImg;
		}
	}
	
	function MouseOut(){
		for (var i=0; i<MouseOut.arguments.length; i++) {
			var obj = MouseOut.arguments[i]
			obj.src = obj.sNormImg;
		}
	}
	
	function PopupWindow(URL,width,height,name){
		window.open(URL,name,"width=" + width + ",height=" + height + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes")
	}
	
	
	// ------------------------------------------
	// Cycle throught language list
	// ------------------------------------------
	function ToggleLanguage(sLang,sLanguageList){
		var sURL;
		var sChar;
		var arrLangs = new Array();
		var iCurLangIndex = 0
		arrLangs = sLanguageList.split("|");
		
		sURL = document.location + ""
		
		// clear old lang if found
		for (var i=0;i<arrLangs.length;i++){
			sURL = sURL.replace("?lang=" + arrLangs[i],"");
			sURL = sURL.replace("&lang=" + arrLangs[i],"");
			if (sLang == arrLangs[i]){
				iCurLangIndex = i;
			}
		}
		
		// check if the "?" is present in the URL
		if (sURL.indexOf("?") > 0) {
			sChar = "&";
		}else{
			sChar = "?";
		}
		
		// set lang destination
		if (iCurLangIndex == (arrLangs.length - 1)){
			sLang = arrLangs[0];
		}
		else{
			sLang = arrLangs[iCurLangIndex+1];
		}
		
		sURL = sURL + sChar + "lang=" + sLang;
		
		window.location = sURL;
	}
	
	function SetLanguage(sLang,sLanguageList){
		var sURL;
		var sChar;
		var arrLangs = new Array();
		
		arrLangs = sLanguageList.split("|");
		
		sURL = document.location + ""
		
		// clear old lang if found
		for (var i=0;i<arrLangs.length;i++){
			sURL = sURL.replace("?lang=" + arrLangs[i],"");
			sURL = sURL.replace("&lang=" + arrLangs[i],"");	
		}
		// check if the "?" is present in the URL
		if (sURL.indexOf("?") > 0) {
			sChar = "&";
		}else{
			sChar = "?";
		}
		
		sURL = sURL + sChar + "lang=" + sLang
		
		document.location = sURL
	}
	
	function findObj(n, d) {
		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=ID3_findObj(n,d.layers[i].document);
				
		if(!x && d.getElementById) 
			x=d.getElementById(n); 
			
		return x;
	}
}


function KFormManagerObj(){
	if(!this.callPrototype()){
		this.addMethod(toParameter);
		this.addMethod(submitToParameter);
	}
	
	function toParameter(oForm){
		
		var iParamCount;
		var oElm;
		var strParam
		var arrParam = new Array();
		
		iParamCount = 0;
		for(var i=0;i<oForm.elements.length ;i++){
			if (oForm.elements[i].name != '') {
				oElm = document.getElementsByName(oForm.elements[i].name);
				if ((typeof(oElm.length) != "undefined") && (typeof(oElm[0].type) != "undefined")) {
					bSelected = false;
					for (var j=0;j < oElm.length;j++) {
						
						switch(oElm[j].type) {
							case "checkbox" :
									if (oElm[j].checked) {
										arrParam[iParamCount] = oElm[j].name + ":" + oElm[j].value;
										iParamCount++;
									}
									break;
							case "radio" :
									if (oElm[j].checked) {
										arrParam[iParamCount] = oElm[j].name + ":" + oElm[j].value;
										iParamCount++;
									}
									break;
							case "hidden":
							case "password" :
							case "text" :
							case "textarea" :
							case "select-one" :
							
								arrParam[iParamCount] = oElm[j].name + ":" + oElm[j].value;
								iParamCount++;
								break;
								
						}
					}
				}
			}
		}
		
		var strParam = arrParam.join("|");
		return(strParam);
	}
	
	function submitToParameter(oForm,iTarget){
		iTarget = (typeof(iTarget) == "undefined")?0:iTarget;
		oForm.action += escape("&parameters=" + this.toParameter(oForm));
		
		if (iTarget == 0) {
			window.location = oForm.action;
		}
		else{
			var oWin = window.open(oForm.action,"FormResult","toolbar=no, menubar=no, width=760, height=440, scrollbars=yes, resizable=yes");
			oWin.focus();
		}
	}
}


function KMenuManagerObj(){
	if(!this.callPrototype()){
		this.addProperty("builder",KMenuBuilderObj);
		this.addProperty("ready",Boolean,false);
		this.addProperty("menus",Array);
		this.addProperty("currentMenu",Object,null);
		this.addProperty("currentMenuItem",Object,null);
		this.addProperty("hideTimeoutRef",Object,null);
		this.addProperty("hideTimeout",Number,500);
		this.addProperty("isInitialize",Boolean,false);
		this.addProperty("orientation",Number,id3MenuDownRight);
		this.addProperty("spanning",Number,id3MenuSpanVertical);
		
		this.addMethod(appendToStructure);
		this.addMethod(cancelHide);
		this.addMethod(hideMenu);
		this.addMethod(init);
		this.addMethod(setCurrentMenu);
		this.addMethod(setCurrentMenuGroup);
		this.addMethod(setCurrentMenuItem);
		this.addMethod(setOrientation);
		this.addMethod(setSpanning);
		this.addMethod(showMenu);
		this.addMethod(togglePanel);
		this.addMethod(toggleTreeNode);
	}
	
	function appendToStructure(strContent, groupId){
		var oDiv = document.getElementById("childHolder" + groupId);
		oDiv.innerHTML = strContent;
		oDiv.load = "true";
		oDiv = null;
	}
	
	function cancelHide(MenuId){
		for(var i=0;i<this.menus.count();i++){
			if (this.menus.items(i).id == MenuId){
				this.menus.items(i).hide();
				return
			}
		}
	}
	
	function hideMenu(MenuId){
		for(var i=0;i<this.menus.count();i++){
			if (this.menus.items(i).id == MenuId){
				this.menus.items(i).hide();
				return
			}
		}
	}
	
	function init(){
		// call external build function
		//alert(navigator.appCodeName + ":" + navigator.appName + " v" + navigator.appVersion + "." + navigator.appMinorVersion )
		gen_BuildMenus();
		this.menus = this.builder.menus;
		this.isInitialize = true;

		//this.menus = this.builder.generate();
	}
	
	function setCurrentMenu(strMenuGUID){
		if (this.isInitialize == false){
			this.init();
		}
		this.builder.setCurrentMenu(strMenuGUID);
	}
	
	function setCurrentMenuGroup(strGroupGUID){
		this.builder.setCurrentMenuGroup(strGroupGUID);
	}
	
	function setCurrentMenuItem(objMenuItem){
		
		if (Object.exist(this.currentMenuItem)){
			if (!this.currentMenuItem.isAncestorOf(objMenuItem.id)){
				this.currentMenuItem.hideSubmenu();
			}
		}
	
		this.currentMenuItem = objMenuItem;
	}
	
	function setOrientation(menuOrientation){
		this.orientation = menuOrientation;
	}
	
	function setSpanning(menuSpanning){
		this.spanning = menuSpanning;
	}
	
	function showMenu(MenuId,MenuGroupId,objRef,position){
		if (this.isInitialize == false){
			this.init();
		}
		for(var i=0;i<this.menus.count();i++){
			if (this.menus.items(i).id == MenuId){
				this.currentMenu = this.menus.items(i);
				this.menus.items(i).showMenu(MenuGroupId,objRef,position);
			}
			else{
				this.menus.items(i).hide(true);
			}
		}
	}
	
	function togglePanel(strItemId,MenuId){
		var oDivider = document.getElementById("div_" + strItemId);
		var oHead = document.getElementById("head_" + strItemId);
		var oPanel = document.getElementById("panel_" + strItemId);
		var oBtn = document.getElementById("button_" + strItemId);
		
		if (oHead.open != "true"){
			oHead.open = "true"
			
			oDivider.className = "KPanelDividerOpen";
			
			oPanel.style.display = "block";
			
			oBtn.className = "KPanelButtonMinus";
		}
		else{
			oHead.open = "false";
			
			oDivider.className = "KPanelDivider";
			
			oPanel.style.display = "none";
			
			oBtn.className = "KPanelButtonPlus";
		}
	}
	
	function toggleTreeNode(oImg,MenuId,GroupId){
		var sQuery = new String();
		var sSiteGUID = new String();
		var bIsMultiSelect = new Boolean();
		var oLoader = new Object();
		
		var oDiv = document.getElementById("childHolder" + GroupId);
		oLoader = document.getElementById("Loader_" + MenuId);
		
		if (oImg.src.indexOf("minus") > 0){
			oImg.src = "/images/plus.gif";
			oDiv.style.display = "none";
		}
		else{
			oImg.src = "/images/minus.gif";
			oDiv.style.display = "block";
			
			if (oDiv.load != "true"){
				if (oLoader != null){
					oLoader.contentWindow.location = "/structLoader.asp?PageGUID=" + GroupId + "&MenuGUID=" + MenuId;
				}
			}
		}
		oDiv = null;
		oImg = null;
	}
}

function KMenuBuilderObj(){
	if(!this.callPrototype()){
		this.addMethod(addGroup);
		this.addMethod(addMenu);
		this.addMethod(generate);
		this.addMethod(setCurrentMenu);
		
		this.addProperty("menus",Array);
		this.addProperty("currentMenu",KMenuObj,null);
		this.addProperty("currentMenuGroup",KMenuGroupObj,null);
		this.addProperty("currentMenuItem",KMenuItemObj,null);
	}

	function addGroup(GroupId){
		if (this.currentMenu != null){
			return(this.currentMenu.addGroup(GroupId));
		}
	}
		
	function addMenu(MenuId, HideTimeout, Title, Spanning, Position,Style,PositionElementRef){
		var oMenu = new KMenuObj();
		with (oMenu){
			id = MenuId;
			hideTimeout = HideTimeout;
			spanning = Spanning;
			position = Position;
			title = Title;
			positionElementRef = (typeof(PositionElementRef) == "undefined")?"":PositionElementRef;
		}
		
		//this.currentMenu = oMenu;
		this.menus.add(oMenu,MenuId);
	}

	function generate(){
		for(var i=0;i<this.menus.count();i++){
			this.menus.items(i).generate();
		}
		
		return(this.menus);
	}
	
	function setCurrentMenu(strMenuGUID){
		for (var i=0;i<this.menus.count();i++){
			if (this.menus.items(i).id == strMenuGUID){
				this.currentMenu = this.menus.items(i);
			}
		}
	}
}


function KMenuObj(){
	if (!this.callPrototype()){
		this.addMethod(addGroup);
		this.addMethod(cancelHide);
		this.addMethod(generate);
		this.addMethod(getElementByGUID);
		this.addMethod(hide);
		this.addMethod(getMenuItemByGUID);
		this.addMethod(setCurrentMenuItem);
		this.addMethod(setOrientation);
		this.addMethod(showMenu);
		
		this.addProperty("id",String);
		this.addProperty("groups",Array);
		this.addProperty("menuItems",Array);
		this.addProperty("currentMenuGroup",Object,null);
		this.addProperty("currentMenuItem",Object,null);
		this.addProperty("hideTimeoutRef",Object,null);
		this.addProperty("hideTimeout",Number,500);
		this.addProperty("orientation",Number,id3MenuDownRight);
		this.addProperty("spanning",Number,id3MenuSpanVertical);
		this.addProperty("position",Number,id3MenuRight);
		this.addProperty("positionElementRef",String,"");
		this.addProperty("style",Number, id3MenuStylePopup);
		this.addProperty("title",String);
	}
	
	function addGroup(GroupId){
		var oGroup = new KMenuGroupObj();
		with (oGroup){
			id = GroupId;
			setParentMenu(this);
		}
		this.groups.add(oGroup,GroupId);
		return(oGroup);
	}
	
	function cancelHide(){
		if (this.hideTimeoutRef != null){
			window.clearTimeout(this.hideTimeoutRef);
			this.hideTimeoutRef = null;
		}			
	}
	
	function generate(){
		
		for(var i=0;i<this.groups.count();i++){
			this.groups.items(i).generate();
		}
	}
	
	function getElementByGUID(){
	
	}
	
	function hide(bForceHide){
		bForceHide = (typeof(bForceHide) == "undefined")?false:bForceHide;
		if (this.hideTimeout > 0){
			if ( (this.hideTimeoutRef != null) || (bForceHide == true) ){
				for (var i=0;i<this.groups.count();i++){
					this.groups.items(i).hide();
				}
				this.hideTimeoutRef = null;
			}
			else{
				this.hideTimeoutRef = window.setTimeout("KMenu.hideMenu('" + this.id + "')",this.hideTimeout);
			}
		}
	}
	
	function getMenuItemByGUID(strItemGUID){
		var oItem = null;
		
		for (var i=0;i<this.groups.count();i++){
			oItem = this.groups.items(i).getElementByGUID(strItemGUID);
			
			if (oItem != null) {
				return(oItem);
			}
		}
		
		return(oItem);
	}

	function setCurrentMenuItem(objMenuItem){
		if (Object.exist(this.currentMenuItem)){
			if (Object.exist(objMenuItem)){
				if (!this.currentMenuItem.isAncestorOf(objMenuItem.id)){
					this.currentMenuItem.hideSubmenu();
				}
			}
			else{
				this.currentMenuItem.hideSubmenu();
			}
		}
	
		this.currentMenuItem = objMenuItem;
	}
	
	function setOrientation(menuOrientation){
		this.orientation = menuOrientation;
	}
	
	function showMenu(GroupId,objRef,position){
		var sGroupGUID;
		var oMethod;
		this.cancelHide();
		if (this.currentMenuGroup != null){
			this.currentMenuGroup.hide();
			this.currentMenuGroup = null;
		}
		
		if (this.currentMenuItem != null){
			this.currentMenuItem.hideSubmenu();
		}
	
		for (var i=0;i<this.groups.count();i++){
			if (this.groups.items(i).id == GroupId){
				this.currentMenuGroup = this.groups.items(i);
			}
		}
			
		// MenuGroup has not been build, build it
		if (this.currentMenuGroup == null){
			sGroupGUID = GroupId.replace(/Kgrp_/gi,"").replace(/-/gi,"_");
			try{
				
				oMethod = eval("BuildGroup_" + this.title + "_" + sGroupGUID);
				if (typeof(oMethod) == "function"){
					eval("BuildGroup_" + this.title + "_" + sGroupGUID + "()");
				}
				
				for (var i=0;i<this.groups.count();i++){
					if (this.groups.items(i).id == GroupId){
						this.currentMenuGroup = this.groups.items(i);
					}
				}
			}
			catch(e){
				return(false);
			}
		}
		
		switch(position){
			case id3MenuRight:
			case id3MenuUnder:
				this.orientation = id3MenuDownRight;
				break;
			case id3MenuLeft:
				this.orientation = id3MenuDownLeft;
				break;
			case id3MenuOver:
				this.orientation = id3MenuUpRight;
		}
		
		if (this.currentMenuGroup != null){
			if (this.positionElementRef != ""){
				objRef = document.getElementById(this.positionElementRef);
			}
			this.currentMenuGroup.show(objRef,position);
		}
	}

}


function KMenuGroupObj(){
	if(!this.callPrototype()){		
		this.addMethod(addItem);
		this.addMethod(ajdustItemsWidth);
		this.addMethod(createDivider);
		this.addMethod(hide);
		this.addMethod(hideChild);
		this.addMethod(generate);
		this.addMethod(getElementByGUID);
		this.addMethod(setParentItem);
		this.addMethod(setParentMenu);
		this.addMethod(show);
		this.addMethod(isRoot);
		
		this.addProperty("id",String);
		this.addProperty("menuItems",Array);
		this.addProperty("parentItem",Object,null);
		this.addProperty("parentMenu",Object,null);
		this.addProperty("inlineElement");
	}

	function addItem(ItemId,Caption,NbOfChild,bSelected,bStartGroup,sGroupLabel){
		var PageGUID = ItemId;
		bSelected = (typeof(bSelected) == "undefined")?false:bSelected;
		sGroupLabel = (typeof(sGroupLabel) == "undefined")?"":sGroupLabel;
		
		var oItem = new KMenuItemObj();
		with(oItem){
			id = ItemId;
			caption = Caption;
			pageGUID = PageGUID;
			nbOfChild = NbOfChild;
			selected = bSelected;
			startGroup = bStartGroup;
			groupLabel = sGroupLabel
			setParents(this.parentItem,this,this.parentMenu);
		}
		
		this.parentMenu.menuItems.add(oItem,ItemId);
		this.menuItems.add(oItem,ItemId);
		return(oItem);
	}

	function ajdustItemsWidth(){
		var iMaxWidth = new Number(0);
		// Find max width
/*		for (var i=0;i<this.menuItems.count();i++){
			if (iMaxWidth < this.menuItems.items(i).inlineElement.offsetWidth){
				iMaxWidth = this.menuItems.items(i).inlineElement.offsetWidth;
			}
		}
		
		// Set max width for all
		for (var i=0;i<this.menuItems.count();i++){
			this.menuItems.items(i).inlineElement.offsetWidth = iMaxWidth;
		}*/
	}

	function generate(){
		var oRow;
		var oCell;
		var oDiv = document.createElement("DIV");
		var iLineNumber = 0
		
		oDiv.className = "KPopupGroup_" + this.parentMenu.title;

		oDiv.style.display = "none";
		oDiv.style.position = "absolute";
		oDiv.style.top = 0;
		oDiv.style.left = 0;
		
		
		var oTable = document.createElement("TABLE");
		iLineNumber = 1
		oTable.cellPadding=0;
		oTable.cellSpacing=0;
		oTable.border=0;
		oTable.width="100%";
		//try{		
			iLineNumber = 2
			if (this.parentMenu.spanning == id3MenuSpanHorizontal){
				iLineNumber = 3
				oRow = oTable.insertRow(-1);
				iLineNumber = 4
			}
		
			iLineNumber = 5
			for (var i=0;i<this.menuItems.count();i++){
				iLineNumber = 6
				if (this.parentMenu.spanning == id3MenuSpanVertical){
					iLineNumber = 7
					oRow = oTable.insertRow(oTable.rows.length);
					iLineNumber = 8
				}
				
				iLineNumber = 9
				if (this.menuItems.items(i).startGroup){
					iLineNumber = 10
					oCell = oRow.insertCell(-1);
					iLineNumber = 11
					oCell.appendChild(this.createDivider(this.menuItems.items(i).groupLabel));
					iLineNumber = 12
					oRow = oTable.insertRow(-1);
					iLineNumber = 13
				}
				
				iLineNumber = 14
				oCell = oRow.insertCell(-1);
				iLineNumber = 15
				oCell.appendChild(this.menuItems.items(i).generate())
				iLineNumber = 16
			}
			iLineNumber = 17
			
		
			iLineNumber = 18
			oDiv.appendChild(oTable);
			iLineNumber = 19
			this.inlineElement = oDiv;
			iLineNumber = 20
			document.body.appendChild(oDiv);
			iLineNumber = 21
		/*}
		catch(e){
			alert(e.description + "\nLine number:" + iLineNumber);
		}*/
		
	}

	function getElementByGUID(strGUID){
		var oElm = null;
		for (var i=0;i<this.menuItems.count();i++){
			oElm = this.menuItems.getElementByGUID(strGUID);
			if (oElm != null){
				return(oElm);
			}
		}
		return(oElm);
	}
	
	function createDivider(strLabel){
		var oElm = document.createElement("DIV");
		
		if (strLabel != ""){
			var oLabel = document.createElement("DIV");
			oLabel.className = "KGroupLabel";
			oLabel.innerText = strLabel;
			oElm.appendChild(oLabel);
		}
		
		var oDivider = document.createElement("DIV");
		oDivider.className = "KGroupDivider";
		
		oElm.appendChild(oDivider);
		
		return(oElm);
	}

	function hide(){
		try{
			this.inlineElement.style.display = "none";
		
			this.hideChild();
		}
		catch(e){}
	}
	
	function hideChild(){
		for (var i=0;i<this.menuItems.count();i++){
			this.menuItems.items(i).hideSubmenu();
		}
	}
	
	function isRoot(){
		if (this.parentItem == null) {
			return(true);
		}
		else{
			return(false);
		}
	}

	function setParentItem(ParentItemId){
		
		for (var i=0;i<this.parentMenu.menuItems.count();i++){
			if (this.parentMenu.menuItems.items(i).id == ParentItemId){
				this.parentItem = this.parentMenu.menuItems.items(i);
			}
		}		

		if (this.parentItem != null){
			this.parentItem.submenu = this;
		}
	}

	function setParentMenu(ParentMenu){
		this.parentMenu = ParentMenu;
	}
	
	function show(objRef,MenuPosition){
		AsSubMenu  = (typeof(AsSubMenu) == "undefined")?false:AsSubMenu;
		MenuPosition = (typeof(MenuPosition) == "undefined")?this.parentMenu.position:MenuPosition;
		menuOrientation = this.parentMenu.orientation;
		
		var iTop,iLeft,iWidth;
		
		
		if(this.menuItems.count() != 0){
			
			
			this.inlineElement.style.display = "block";
			
			if (typeof(objRef) != "undefined"){
				iTop = ID3ASP_AbsoluteTop(objRef,0);
				iLeft = ID3ASP_AbsoluteLeft(objRef,0);
				switch(MenuPosition){
					case id3MenuUnder:
						iWidth = objRef.offsetWidth;
						iTop += objRef.offsetHeight;
						break;
					case id3MenuRight:
						iWidth = this.inlineElement.offsetWidth;
						iLeft += objRef.offsetWidth;
						break;
					case id3MenuOver:
						iWidth = objRef.offsetWidth;
						iTop -= this.inlineElement.offsetHeight;
						break;
					case id3MenuLeft:
						iWidth = this.inlineElement.offsetWidth;
						iLeft -= this.inlineElement.offsetWidth;
						break;
				}
				
				switch(menuOrientation){
					case id3MenuDownRight:
						if ((iLeft + this.inlineElement.offsetWidth) > (screen.availWidth - 20)){
							this.show(objRef,id3MenuLeft);
							this.parentMenu.setOrientation(id3MenuDownLeft);
							return(true);
						}
						else if((iTop + this.inlineElement.offsetHeight) > (screen.availHeight - 20)){
							iTop -= ((iTop + this.inlineElement.offsetHeight) - screen.availHeight)
						}
						break;
					case id3MenuUpRight:
						iTop -= (this.inlineElement.offsetHeight - objRef.offsetHeight);
						if ((iLeft + this.inlineElement.offsetWidth) > screen.availWidth){
							this.show(objRef,id3MenuLeft);
							this.parentMenu.setOrientation(id3MenuUpLeft);
							return(true);
						}
						else if(iTop < 0){
							iTop = 0;
						}
						break;
							
					case id3MenuDownLeft:
						if (iLeft < 0){
							this.show(objRef,id3MenuRight);
							this.parentMenu.setOrientation(id3MenuDownRight);
							return(true);
						}
						else if((iTop + this.inlineElement.offsetHeight) > screen.availHeight){
							iTop -= ((iTop + this.inlineElement.offsetHeight) - screen.availHeight)
						}
						break;
					case id3MenuUpLeft:
						iTop -= (this.inlineElement.offsetHeight - objRef.offsetHeight);
						if (iLeft < 0){
							this.show(objRef,id3MenuRight);
							this.parentMenu.setOrientation(id3MenuUpRight);
							return(true);
						}
						else if(iTop < 0){
							iTop = 0;
						}
						break;
				}						
				
				with(this.inlineElement.style){
					top = iTop - 1;
					left = iLeft;
					//width = iWidth;
				}
				
				this.ajdustItemsWidth(iWidth);
			}
		}
	}
}

function KMenuItemObj(){
	if(!this.callPrototype()){
		this.addMethod(generate);
		this.addMethod(getElementByGUID);
		this.addMethod(setParents);
		this.addMethod(hideSubmenu);
		this.addMethod(isAncestorOf);
		this.addMethod(isRoot);
		this.addMethod(mouseDown);
		this.addMethod(mouseUp);
		this.addMethod(mouseOut);
		this.addMethod(mouseOver);
		this.addMethod(showSubMenu);
		
		this.addProperty("inlineElement",Object,null);
		this.addProperty("id",String);
		this.addProperty("pageGUID",String);
		this.addProperty("nbOfChild",Number,0);
		this.addProperty("caption",String);
		this.addProperty("groupLabel",String,'');
		this.addProperty("parentItem",Object,null);
		this.addProperty("parentGroup",Object,null);
		this.addProperty("parentMenu",Object,null);
		this.addProperty("selected",Boolean,false);
		this.addProperty("startGroup",Boolean,false);
		this.addProperty("submenu",Object,null);
	}

	function generate(){
		var sArrow;
		var sColspan = "1";
		var oDiv = document.createElement("DIV");
		
		var strHTML = new String();
		
		if (this.selected){
			oDiv.className = "KMenuItemSelected";
		}
		else{
			oDiv.className = "KMenuItem";
		}
		oDiv.id = this.id;
		oDiv.onmouseover = this.mouseOver;
		oDiv.onmouseout = this.mouseOut;
		oDiv.onmousedown = this.mouseDown;
		oDiv.onmouseup = this.mouseUp;
		strHTML = "<TABLE cellpadding=0 cellspacing=0 border=0 width=100%>"
			
		strHTML += "<TR>"
		strHTML += "<TD width=100% nowrap=true><SPAN class='KLabel'>" + this.caption + "</SPAN></TD>";
		
		if (this.nbOfChild > 0){
			strHTML += "<TD class='KArrowCell'><SPAN class='KArrow'>&nbsp;</SPAN></TD>"
		}
		else{
			strHTML += "<TD class='KArrowCell'><SPAN class='KNoArrow'>&nbsp;</SPAN></TD>"
		}
		
		strHTML += "</TR></TABLE>";
		
		oDiv.innerHTML = strHTML;
		oDiv.kref = this;
		return(oDiv)
	}

	function getElementByGUID(strGUID){
		if (this.id == strGUID){
			return(this);
		}
		else{
			if (this.submenu != null){
				return(this.submenu.getElementByGUID(strGUID));
			}
			else{
				return(null);
			}
		}
	}

	function hideSubmenu(){
		if(this.submenu != null){
			this.submenu.hide()
		}
	}

	function isAncestorOf(strGUID){
		if (this.getElementByGUID(strGUID) != null){
			return(true);
		}
		else{
			return(false);
		}
	}

	function isRoot(){
		if(this.parentItem == null){
			return(true);
		}
		else{
			return(false);
		}
	}

	function mouseDown(){
//		document.body.innerHTML = '';
//		window.location = "?" + this.kref.pageGUID;
	}

	function mouseUp(){
		//document.body.innerHTML = '';
		//this.kref.parentMenu.hide();
		document.body.style.cursor = 'wait';
		window.location = "?" + this.kref.pageGUID;
	}
	
	function mouseOut(){
		if (!this.kref.selected){
			this.className = "KMenuItem";
		}
		this.kref.parentMenu.hide();
		
		if (typeof(KMenu_onItemMouseOut) != "undefined"){
			KMenu_onItemMouseOut();
		}
	}

	function mouseOver(){
		var lngParentWidth;
		this.kref.parentMenu.setCurrentMenuItem(this.kref);
		
		lngParentWidth = this.parentNode.style.width;
		if (isNaN(lngParentWidth)){
			lngParentWidth = Number(lngParentWidth.replace(/px/gi,""));
		}
		
		if ((lngParentWidth + 5) < Number(this.parentNode.offsetWidth)){
			//this.parentNode.style.width = this.parentNode.offsetWidth;
		}
		
		if (!this.kref.selected){
			this.className = "KMenuItemOver";
		}
		this.kref.parentGroup.hideChild();
		this.kref.showSubMenu(this);
		this.kref.parentMenu.cancelHide();
		
		if (typeof(KMenu_onItemMouseOver) != "undefined"){
			KMenu_onItemMouseOver();
		}
	}

	function setParents(ParentItem,ParentGroup,ParentMenu){
		this.parentItem = ParentItem;
		this.parentGroup = ParentGroup;
		this.parentMenu = ParentMenu;
	}
		
	function showSubMenu(objRef){
		var sGroupGUID;
		
		
		if (this.nbOfChild > 0){
			if(this.submenu == null){
				sGroupGUID = this.id.replace(/-/gi,"_");
				//sGroupGUID = GroupId.replace(/Kgrp_/gi,"").replace(/-/gi,"_");
				try{
					oMethod = eval("BuildGroup_" + this.parentMenu.title + "_" + sGroupGUID);
					if (typeof(oMethod) == "function"){
						eval("BuildGroup_" + this.parentMenu.title + "_" + sGroupGUID + "()");
					}
				}
				catch(e){
					return(false);
				}
			}
			
			if(this.submenu != null){
				var iTop = ID3ASP_AbsoluteTop(objRef,0);
				var iLeft = ID3ASP_AbsoluteLeft(objRef);				
				
				switch(this.parentMenu.orientation){
					case id3MenuUpRight:
						if (KMenu.spanning == id3MenuSpanHorizontal){
							this.submenu.show(objRef,id3MenuOver,true)
						}
						else{
							this.submenu.show(objRef,id3MenuRight,true)
						}
						break;
					case id3MenuDownRight:
						if (this.parentMenu.spanning == id3MenuSpanHorizontal){
							this.submenu.show(objRef,id3MenuUnder,true)
						}
						else{
							this.submenu.show(objRef,id3MenuRight,true)
						}
						break;
						
					case id3MenuDownLeft:
						if (this.parentMenu.spanning == id3MenuSpanHorizontal){
							this.submenu.show(objRef,id3MenuUnder,true)
						}
						else{
							this.submenu.show(objRef,id3MenuLeft,true)
						}
					case id3MenuUpLeft:
						if (this.parentMenu.spanning == id3MenuSpanHorizontal){
							this.submenu.show(objRef,id3MenuOver,true)
						}
						else{
							this.submenu.show(objRef,id3MenuLeft,true)
						}
						break;
				}						

			}
		}
		
	}
}

function KModuleDisplayManagerObj(){
	if(!this.callPrototype()){
		this.addMethod(initialize);
		
		this.addProperty("modEventCalendar",Object,null);
		this.addProperty("modThumbnails",Object,null);
	}	

	function initialize(){
		this.modEventCalendar = new KModEventCalendarManager();
		this.modThumbnails = new KModThumbnailsManager();
	}
	
	this.initialize();
}

function KModThumbnailsManager(){
	if(!this.callPrototype()){
		this.addMethod(changeFullImage);
		this.addMethod(changeImageFolder);
	}

	function changeFullImage(newSrc,newOriginalImage){
		var sAlt;
		
		var oImg = document.getElementById("KModThumbnails_FullImage");
		if (newSrc.indexOf("\\")>0){
			sAlt = newSrc.substr(newSrc.lastIndexOf("\\") + 1);
			if (sAlt.indexOf("&") > 0){
				sAlt = sAlt.substr(0,sAlt.indexOf("&"));
			}
		}
		oImg.src = newSrc;
		oImg.alt = sAlt;
		
		if (newOriginalImage != ''){
			oImg.onclick = function(){var oWin = window.open(newOriginalImage,'fullImage','toolbar=no,address=no,resizable=yes,width='+ (screen.availWidth/2) + ',height=' + (screen.availHeight/2));oWin.focus();};
		}

		oImg = null;
	}
	
	function changeImageFolder(newFolder,PageGUID){
		document.cookie = "KModThumbnails.ImageFolder." + PageGUID + "=" + newFolder;
		document.location = document.location;
	}
}


function KModEventCalendarManager(){
	if(!this.callPrototype()){
		this.addMethod(callHideDayPopup);
		this.addMethod(clearDayPreview);
		this.addMethod(hideDayPopup);
		this.addMethod(showDayPopup);
		this.addMethod(showDayPreview);
		this.addMethod(showDayEvent);
		this.addMethod(onPopupMouseOver);
		this.addMethod(onPopupMouseOut);
		
		this.addProperty("objHideTimeout",Object,null);
		this.addProperty("bolLockPreview",Boolean,false);
	}
	
	function callHideDayPopup(strPanelID){
		this.objHideTimeout = window.setTimeout("KModDisplay.modEventCalendar.hideDayPopup('" + strPanelID + "')",250);
	}
	
	function hideDayPopup(strPanelID){
		var oPopup = document.getElementById(strPanelID);
		
		if (typeof(oPopup) != "undefined"){
			oPopup.style.display = "none";
		}
		this.objHideTimeout = null;
	}
	
	function showDayPopup(strTitle, srcElement, arrItemID){
		var oPopup = srcElement.popupPanel;
		var oEventPanel;
		var iMaxHeight = 0;
		
		if (typeof(oPopup) == "undefined"){
			oPopup = document.createElement("DIV");
			oPopup.className = "KCalDayPopup";
			oPopup.style.display = "none";
			oPopup.id = "Popup_" + this.createGUID();
			oPopup.onmouseover = this.onPopupMouseOver;
			oPopup.onmouseout = this.onPopupMouseOut;
			oPopup.man = this;
			
			document.body.appendChild(oPopup);
			//srcElement.appendChild(oPopup);
			srcElement.popupPanel = oPopup;
			//oPopup.style.height = iMaxHeight;
			oPopup.style.position = "absolute";
			oPopup.style.top = KScript.getAbsoluteTop(srcElement,20);
			oPopup.style.left = KScript.getAbsoluteLeft(srcElement,20);
			/*oPopup.style.top = event.y + 20;
			oPopup.style.left = event.x + 20;*/
		}
		
		for (var i=0;i<arrItemID.length;i++){
			oEventPanel = document.getElementById("PopupEvent" + arrItemID[i]);
			//alert(oEventPanel.offsetHeight);
			if (oEventPanel != null){
				oPopup.appendChild(oEventPanel);
				iMaxHeight += oEventPanel.offsetHeight;
			}
		}
		
		oPopup.style.display = "block";	
	}
	
	function showDayPreview(previewPanelID,arrItemID){
		var oEventPanel;
		var iMaxHeight = 0;
		var oPreviewPanel = document.getElementById(previewPanelID);
		var oEventList;
		if (oPreviewPanel != null){
			oEventList = document.createElement("DIV");
						
			for (var i=0;i<arrItemID.length;i++){
				oEventPanel = document.getElementById("PopupEvent" + arrItemID[i]);
				if (oEventPanel != null){
					oEventList.insertAdjacentHTML("beforeEnd",oEventPanel.outerHTML);
					iMaxHeight += oEventPanel.offsetHeight;
				}
			}
			
			oPreviewPanel.innerHTML = oEventList.innerHTML;
		}
	}
	
	function showDayEvent(previewPanelID,arrItemID){
		var oEventPanel;
		var iMaxHeight = 0;
		var oPreviewPanel = document.getElementById(previewPanelID);
		var oEventList;
		if (oPreviewPanel != null){
			oEventList = document.createElement("DIV");
						
			for (var i=0;i<arrItemID.length;i++){
				oEventPanel = document.getElementById("PopupEvent" + arrItemID[i]);
				if (oEventPanel != null){
					oEventList.insertAdjacentHTML("beforeEnd",oEventPanel.outerHTML);
					iMaxHeight += oEventPanel.offsetHeight;
				}
			}
			
			oPreviewPanel.children(1).innerHTML = oEventList.innerHTML;
		}
	}
	
	function clearDayPreview(previewPanelID){
		var oPreviewPanel = document.getElementById(previewPanelID);
		if (oPreviewPanel != null){
			oPreviewPanel.innerHTML = "";
		}
	}
	
	function onPopupMouseOver(){
		if (this.man.objHideTimeout != null){
			window.clearTimeout(this.man.objHideTimeout);
			this.man.objHideTimeout = null;
		}
	}
	function onPopupMouseOut(){
		this.man.callHideDayPopup(this.id);
	}
}


// #################################################################################
// ID3ASP_AbsoluteTop
// #################################################################################
function ID3ASP_AbsoluteTop(obj,iTop){
	iTop = (typeof(iTop)=="undefined")?0:iTop;
	if (obj.offsetParent != null){
		iTop += obj.offsetTop;
		return(ID3ASP_AbsoluteTop(obj.offsetParent,iTop));
	}
	else{
		return(iTop);
	}
}

// #################################################################################
// ID3ASP_AbsoluteTop
// #################################################################################
function ID3ASP_AbsoluteLeft(obj,iLeft){
	iLeft = (typeof(iLeft)=="undefined")?0:iLeft;
	if (obj.offsetParent != null){
		iLeft += obj.offsetLeft;
		return(ID3ASP_AbsoluteLeft(obj.offsetParent,iLeft));
	}
	else{
		return(iLeft);
	}
}

// #################################################################################
// ID3FlaObj
// #################################################################################
function ID3FlaObj(swf, id, largeur, hauteur, ver, background, qualite){
	if (!this.callPrototype()){
		this.addProperty("params",String);
		this.addProperty("variables",String);
		this.addMethod(addParam);
		this.addMethod(addVar);
		this.addMethod(code);
	}
	
	if(background){this.addParam('bgcolor', background);}
	var qualiter = qualite ? qualite : 'high';
	this.addParam('quality', qualiter);
	
	function addParam(name, value){
		this.params += '<param name="'+name+'" value="'+value+'">';
	}
	
	function addVar(name, value){
		this.variables += name+"="+value+"&";
	}
	
	function code(idZone) {
		var codeFinal  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="'+id+'" name="'+id+'" width="'+largeur+'" height="'+hauteur+'">';
		codeFinal += '<param name="movie" value="'+swf+'">';

		if(this.params != ""){codeFinal += this.params;}
		if(this.variables != ""){codeFinal += '<param name="flashvars" value="'+this.variables+'">';}
		
		codeFinal += '<embed src="'+swf+'" width="'+largeur+'" height="'+hauteur+'" flashvars="'+this.variables+'" type="application/x-shockwave-flash"></embed>';
		codeFinal += "</object>";
		
		document.getElementById(idZone).innerHTML = codeFinal;
	}
}

function ID3OpenCalculator(lang){
	lang = lang.toLowerCase();
	window.open('http://www.remax-quebec.com/' + lang + '/propriete/hypodesjardins.jsp?price=150000&uls=&url=','Calculette','width=580,height=480,scrollbars=yes,toolbars=no');
}
