// Wait messages BEGIN

function ShowWaitMessage(sControl, sMessage) {
  var objDivWaitMessage = document.all('divWaitMessage');
	if (objDivWaitMessage != undefined) {
	  objDivWaitMessage.innerHTML = sMessage;
		objDivWaitMessage.style.display = 'block';
	}

	if (sControl != '') {
		__doPostBack(sControl, '');
	}
}

// Wait messages END

// Download file
function DownLoadAttachment(nZatID) {
	var sUniqueUrlExt = popUniqueUrlExt();
	window.open('../../App_spzBase/Attachment/frmZAttachment.aspx?nZatID=' + nZatID,'windowX' + sUniqueUrlExt,'toolbar=0,status=0,scrollbars=no,resizable=no,width=1,height=1,top=0,left=0');							
}

// Show help
function ShowHelp(sForm) {
	// sForm e.g. frmproblemreport
	var sUniqueUrlExt = popUniqueUrlExt();
	window.open('../../App/Help/frmHelpViewer.aspx?sPageID=' + sForm,'HelpWin' + sUniqueUrlExt,'scrollbars=auto,width=400,height=500,resizable=yes,');
}

// spzCalendarDayViewContainer BEGIN
function dnavDayItemClick(sControl, nID, sObjectType, nLocationItem) {
	// Stop event bubbling to outer DIV tags. We will get events on both booked events and calendar clicked otherwise
	if (window.event)
	{
		// IE does not support W3C event model so we needhave special handling.
		event.cancelBubble = true;
	} else {
		// W3C standard
		event.stopPropagation = true;
	}
	
	if(nLocationItem == 0) {
		__doPostBack(sControl, 'DayItemClick:' + nID + ":" + sObjectType);
	}
	else {
		__doPostBack(sControl, 'LocationItemClick:' + nID + ":" + sObjectType);
	}
}

function dnavTimeClick(e, sControl, nColumnID) {
	var X = '';
	var Y = '';
	var browsername = navigator.userAgent.toLowerCase();
	if (browsername.indexOf("firefox") != -1)
	{
		X = e.layerX; // e.pageX 
		Y = e.layerY; // e.pageY
	} else {
		if (document.layers)
			{
				// NS (Mozilla)
				X = e.layerX;
				Y = e.layerY;
			} else {
				// IE
				X = event.x;
				Y = event.y;
			}
	}
	__doPostBack(sControl, 'TimeClicked:' + nColumnID + ":" + X + ":" + Y);
}
// spzCalendarDayViewContainer END


// spzMonthNavigator BEGIN
// Javascript function for clicking on a day.
function mnavDayClick(sControl, nDay) {
	__doPostBack(sControl, 'DayClicked:' + nDay);
}

// Javascript function for clicking on a month.
function mnavMonthChange(sControl, nYear, nMonth) {
	__doPostBack(sControl, 'MonthChange:' + nYear + ':' + nMonth);
}
// spzMonthNavigator END

// spzHirarchicalTreeBlock BEGIN
	var nPopupMenuActiveID = new Number(0);

  function calHierarchyPopup(sUrl, sTablePrefix, nNodeToOpenID, nRootID, nSubMenues, nTop, nLeft, nWidth, nHeight, sPopupFkUrl, sFkPopupColumnName, nPopupTop, nPopupLeft, nPopupHeight, nPopupWidth) {
   // Get popup level
   var nPopupLevel = popGetPopupLevel();
   // Top not specified?
   if (nTop == 0) {
    // Set default top
    nTop = (Number(nPopupLevel) + 1) * 25;
   }

   // Left not specified?
   if (nLeft == 0) {
    // Set default left
    nLeft = (Number(nPopupLevel) + 1) * 25;
   }

   // Width not specified?
   if (nWidth == 0) {
    // Set default width
    nWidth = 800;
   }

   // Height not specified?
   if (nHeight == 0) {
    // Set default height
    nHeight = 400;
   }

   var sUniqueUrlExt = popUniqueUrlExt();
   var sReturnValues;
   // Support for modal dialogs? (IE yes, FireFox no)
   if (window.showModalDialog) {
		sUrl =  sUrl + '?sTablePrefix=' + sTablePrefix + '&nNodeToOpenID=' + nNodeToOpenID + "&nRootID=" + nRootID + "&nSubMenues=" + nSubMenues + "&d=" + sUniqueUrlExt;
		sUrl =  sUrl + '&sPopupFkUrl=' + sPopupFkUrl + '&sFkPopupColumnName=' + sFkPopupColumnName + '&nPopupTop=' + nPopupTop + '&nPopupLeft=' + nPopupLeft + '&nPopupHeight=' + nPopupHeight + '&nPopupWidth=' + nPopupWidth;
		
    // OpenModalDialog sFeatures: dialogHeight (x px), dialogLeft (x px), dialogTop (x px), dialogWidth (x px), center (YES/no), dialogHide (yes/NO), edge (sunken/RAISED), help (YES/no), resizable (yes/NO), scroll (YES/no), status (yes/no), unadorned (yes/NO)
    sReturnValues = window.showModalDialog(sUrl, objMasterWindow, 'dialogTop:' + nTop + ';dialogLeft:' + nLeft + ';dialogWidth:' + nWidth + 'px;dialogHeight:' + nHeight + 'px;status:no;resizable:yes;help:no;center:no;'); // 
   }
  }

	function htreePopupMenuClickSendEvent(sControl, SelectedMenu, nOptions) {
		var sCommandArgument;
		sCommandArgument = '';
		var sActivationDate;
		
		// nOptions is bitwise value. It will have flags set in the hierarchy control that will require extra actions in
		// this javascript.
		// 1 = Prompt for activation date during copy of branch
		// 2 = Not implemented yet.
		// 4 = Not implemented yet.
		//
		var PROMPT_ACTIVATION_DATE = 1;
		
		switch(SelectedMenu)
		{
			case 1:
				//alert('Case 1: ' + nPopupMenuActiveID);
				sCommandArgument = 'htreePopupMenuShowDetails';
				break
			case 2:
				sCommandArgument = 'htreePopupMenuEdit';
				break
			case 3:
				sCommandArgument = 'htreePopupMenuDelete';
				break
			case 4:
				sCommandArgument = 'htreePopupMenuAddSubNode';
				break
			case 5:
				sCommandArgument = 'htreePopupMenuStartMove';
				break
			case 6:
				sCommandArgument = 'htreePopupMenuStartMerge';
				break
			case 7:
				sCommandArgument = 'htreeSelectAndClose';
				CloseDialog(0, nPopupMenuActiveID);
				return;
				break
			case 8:
				sCommandArgument = 'htreePopupStartCopyBranch';
				if((nOptions & PROMPT_ACTIVATION_DATE) == PROMPT_ACTIVATION_DATE)
				{
					var dCurrDate = new Date();
					var sMonth = '';
					var sDay = '';
					
					if((dCurrDate.getMonth() + 1) < 10)
						sMonth = '0' + dCurrDate.getMonth() + 1;
					else
						sMonth = dCurrDate.getMonth() + 1;

					if((dCurrDate.getDate()) < 10)
						sDay = '0' + dCurrDate.getDate();
					else
						sDay = dCurrDate.getDate();
						
					var bDone = 0;
					// unescape codes: Å-%C5, Ä-%C4, Ö-%D6, å-%E5, ä-%E4, ö-%F6
					while(bDone != 1)
					{
						// Ange aktiveringsdatum för ny organisationsstruktur
						sActivationDate = prompt(unescape('Ange aktiveringsdatum f%F6r ny organisationsstruktur:'), dCurrDate.getFullYear() + '-' + sMonth + '-' + sDay);
					
						// null if user hit cancel
						if(sActivationDate == null)
							return;
						else
						{
							var nYear = parseInt(sActivationDate.substr(0, 4));
							var nMonth = parseInt(sActivationDate.substr(5, 2));
							var nDay = parseInt(sActivationDate.substr(8, 2));
							
							bDone = 1;
							if((nMonth < 1) || (nMonth > 12))
								bDone = 0;
							if((nDay < 1) || (nDay > 31))
								bDone = 0;

							if(bDone == 0)
							{
								alert('Ogiltigt datum');
							}
							
							var dTmp = new Date();
							dTmp.setFullYear(nYear, nMonth-1, nDay);
							dTmp.setHours(0);
							dTmp.setMinutes(0, 0, 0);
							
							var dCurrDate = new Date();
							dCurrDate.setHours(0);
							dCurrDate.setMinutes(0, 0, 0);

							//alert(dTmp.getTime() + ' ## ' + dCurrDate.getTime());
							
							if(dTmp.getTime() <= dCurrDate.getTime())
							{
								// unescape codes: Å-%C5, Ä-%C4, Ö-%D6, å-%E5, ä-%E4, ö-%F6
								alert(unescape('Aktiveringsdatum m%E5ste vara efter dagens datum'));
								bDone = 0;
							}
							
						}
					}
					
					//alert(sActivationDate);
					__doPostBack(sControl, sCommandArgument + ':' + nPopupMenuActiveID + ':' + sActivationDate);
					return;
				}
				break
			default:
				__doPostBack(sControl, 'htreeCustomPopupMenuCommand:' + nPopupMenuActiveID + ':' + SelectedMenu);
				return;
				break
		}
		
		__doPostBack(sControl, sCommandArgument + ':' + nPopupMenuActiveID);

	}
	
	function htreePopupMenuClickAddNew(sControl, sPopupURL, sFormCaption, sFkMasterColumn, bLockMasterField, nTop, nLeft, nWidth, nHeight)		
	{
		// alert(sPopupURL + ' : ' + sFormCaption + ' : ' + sFkMasterColumn + ' : ' + nPopupMenuActiveID + ' : ' + bLockMasterField + ' : ' + nTop + ' : ' + nLeft + ' : ' + nWidth + ' : ' + nHeight);
		
		// nPopupMenuActiveID is a global varibale and is set each time user opens a menu
		popFkAddNew(sPopupURL, sFormCaption, sFkMasterColumn, nPopupMenuActiveID, bLockMasterField, nTop, nLeft, nWidth, nHeight);
		
		// This will create a raise postback but there is nothing saynig anything was ever added
		__doPostBack(sControl, 'BackFromAddNew:' + nPopupMenuActiveID);

	}

	function htreePopupMenuClickShowDetail(sControl, sPopupURL, sFormCaption, nTop, nLeft, nWidth, nHeight)		
	{
		//alert(sPopupURL + ' : ' + nPopupMenuActiveID + ' : ' + sFormCaption + ' : ' + nTop + ' : ' + nLeft + ' : ' + nWidth + ' : ' + nHeight);
		
		// nPopupMenuActiveID is a global varibale and is set each time user opens a menu
		popViewDetailsPopup(sPopupURL, nPopupMenuActiveID, sFormCaption, nTop, nLeft, nWidth, nHeight)

		// This will create a raise postback but there is nothing saynig anything was ever added
		__doPostBack(sControl, 'BackFromShowDetail:' + nPopupMenuActiveID);
	}

	function htreePopupMenuClickEditDetail(sControl, sPopupURL, sFormCaption, nTop, nLeft, nWidth, nHeight)		
	{
		//alert(sPopupURL + ' : ' + nPopupMenuActiveID + ' : ' + sFormCaption + ' : ' + nTop + ' : ' + nLeft + ' : ' + nWidth + ' : ' + nHeight);
		
		// nPopupMenuActiveID is a global varibale and is set each time user opens a menu
		popEditDetailsPopup(sPopupURL, nPopupMenuActiveID, sFormCaption, nTop, nLeft, nWidth, nHeight)

		// This will create a raise postback but there is nothing saynig anything was ever added
		__doPostBack(sControl, 'BackFromEditDetail:' + nPopupMenuActiveID);
	}



	function htreeCommand(sControl, sCommandArgument, nNodeID) {
		 // alert(sControl);
		__doPostBack(sControl, sCommandArgument + ':' + nNodeID);
	}


	function htreeMenuItem_MouseOut(sNodeID) {
		objNode = document.getElementById(sNodeID);
			
		if (objNode.className == 'xqh_MenuItemSelected_hover') {
			objNode.className = 'xqh_MenuItemSelected';
		} else {
			if (objNode.className == 'xqh_MenuItemMarked_hover') {
				objNode.className = 'xqh_MenuItemMarked';
			} else {
				if (objNode.className == 'xqh_MenuItemDisabled_hover') {
					objNode.className = 'xqh_MenuItemDisabled';
				}
				else
				{
				objNode.className = 'xqh_MenuItemNormal';
				}
			}
			
		}
	}
	
	function htreeMenuSubItem_MouseOut(sNodeID) {
		objNode = document.getElementById(sNodeID);
			
		if (objNode.className == 'xqh_SubItemSelected_hover') {
			objNode.className = 'xqh_SubItemSelected';
		} else {
			objNode.className = 'xqh_SubItemNormal';
		}
	}
 
	function getMouseX(e) {
			if (document.all) {
					//return window.event.x + document.body.scrollLeft; //By the name of God, WHY isn't this row working???
					return e.clientX;
				} else {
					return e.pageX;
				}
		}
		
	function getMouseY(e) {
			if (document.all) {
					return window.event.y + document.body.scrollTop;
				} else {
					return e.pageY;
				}
		}
				
	function htreeShow(object, e, nNodeID) {
		// nPopupMenuActiveID is global varible declared above. It's used in other Javascript function to send
		// the correct ID in popups and other.
		nPopupMenuActiveID = nNodeID;
		
		if (e != '') {
				if (document.all) {
						//x = e.clientX;
						//y = e.clientY + 10;
						x = getMouseX(e) + 5;
						y = getMouseY(e) + 90;
				}
				if (document.layers) {
						x = e.pageX;
						y = e.pageY - 90;
				}
		}
		
		if (document.layers && document.layers[object] != null) {
				document.layers[object].left = x;
				document.layers[object].top = y;
		}
		else if (document.all) {
				document.all[object].style.posLeft = x;
				document.all[object].style.posTop = y;
		}


		if (document.layers && document.layers[object] != null)
			document.layers[object].visibility = 'visible'; 
		else if (document.all)
			document.all[object].style.visibility = 'visible';
	}
			
	function htreeHide(object) {
		nPopupMenuActiveID = 0;
		
		if (document.layers && document.layers[object] != null)
			document.layers[object].visibility = 'hidden';
		else if (document.all)
			document.all[object].style.visibility = 'hidden';
	}
			
	function htreeAcceptDropTarget(sControl, nActionType, nTargetID, sTargetName) {
		switch(nActionType)
		{
			case 1:	// Move
				// unescape codes: Å-%C5, Ä-%C4, Ö-%D6, å-%E5, ä-%E4, ö-%F6
				// Är du säker på att du vill flytta den valda noden till noden
				if (confirm(unescape('%C4r du s%E4ker p%E5 att du vill flytta den valda noden till "' + sTargetName + '"?'))) {
					//alert('Yepp: ' + sControl + ' ' + nTargetID);
					htreeCommand(sControl, 'MoveNode', nTargetID);
				} else {
					//alert('Nope: ' + sControl);
					return;
				}
				break
			case 2:	// Merge
				// unescape codes: Å-%C5, Ä-%C4, Ö-%D6, å-%E5, ä-%E4, ö-%F6
				// Är du säker på att du vill sammanfoga den valda noden med noden
				if (confirm(unescape('%C4r du s%E4ker p%E5 att du vill sammanfoga den valda noden med noden "' + sTargetName + '"?')))
					htreeCommand(sControl, 'MergeNode', nTargetID);
				else
					return;
				break
			case 3: // Copy branch
				if (confirm(unescape('%C4r du s%E4ker p%E5 att du vill kopiera den valda noden till "' + sTargetName + '"?')))
					htreeCommand(sControl, 'CopyBranch', nTargetID);
				else
					return;
			
				break
		}
	}

// spzHirarchicalTreeBlock END

// Tab Sub Menu (spzTabSumMenu) BEGIN

function TabSubMenu_MouseOver(sMenuID){
	var objTabSubMenu = document.getElementById(sMenuID);
	if (objTabSubMenu != null) {objTabSubMenu.className = 'tsmSubMenu_hover';}
}

function TabSubMenu_MouseOut(sMenuID){
	var objTabSubMenu = document.getElementById(sMenuID);
	if (objTabSubMenu != null) {objTabSubMenu.className = 'tsmSubMenu';}
}

// Tab Sub Menu (spzTabSumMenu) END

/// Navigation menu (main drop down menu) BEGIN

function dropShowMenu(sMenuID)
	{
		var objMenu = document.getElementById(sMenuID);
		if (objMenu != null) {
			objMenu.className = 'dropMenu_hover';
			var objMenuContent = document.getElementById(sMenuID + 'Content');
			if (objMenuContent != null) {objMenuContent.style.visibility = 'visible';}
		}
	}

function dropHideMenu(sMenuID)
	{
		var objMenu = document.getElementById(sMenuID);
		if (objMenu != null) {
			objMenu.className = 'dropMenu';
			var objMenuContent = document.getElementById(sMenuID + 'Content');
			if (objMenuContent != null) {objMenuContent.style.visibility = 'hidden';}
		}
	}

function dropMenuItem_MouseOver(sNodeID) {
    objNode = document.getElementById(sNodeID);
    if (objNode != null) {objNode.className = objNode.className + '_hover';}
  }

function dropMenuItem_MouseOut(sNodeID) {
    objNode = document.getElementById(sNodeID);
    if (objNode.className == 'dropMenuItem_hover') {
	    objNode.className = 'dropMenuItem';
    }
  }
  
function MenuItem_MouseOver(sNodeID) {
  objNode = document.getElementById(sNodeID);
  objNode.className = objNode.className + '_hover';
}

function MenuSubItem_MouseOver(sNodeID) {
  objNode = document.getElementById(sNodeID);
  objNode.className = objNode.className + '_hover';
}

function MenuItem_MouseOut(sNodeID) {
  objNode = document.getElementById(sNodeID);
  	
  if (objNode.className == 'mnuItemSelected_hover') {
    objNode.className = 'mnuItemSelected';
  } else {
    objNode.className = 'mnuItemNormal';
  }
}

function MenuSubItem_MouseOut(sNodeID) {
  objNode = document.getElementById(sNodeID);
	
  if (objNode.className == 'mnuSubItemSelected_hover') {
    objNode.className = 'mnuSubItemSelected';
  } else {
    objNode.className = 'mnuSubItemNormal';
  }
}

/// Navigation menu BEGIN

/// Popup instead of Round Trip BEGIN

		var objMasterWindow;

		function popSetMasterWindow() {
			var nPopupLevel = popGetPopupLevel();

			// Master window?
			if (nPopupLevel == 0) {
				objMasterWindow = window;
			} else {
				objMasterWindow = dialogArguments;

				// Set popup title
				document.title = "My Popup Title";
			}
		}

		// Show popup as FK and show search result based on FK key
		function popFkView(sUrl, sFormCaption, sFkMasterColumn, nFkMasterID, bLockMasterField, nTop, nLeft, nWidth, nHeight) {
			// Add parameters
			if(sUrl.indexOf("?") == -1)
				sUrl += '?'
			else
				sUrl += '&'
			sUrl += 'nFkMasterID=' + nFkMasterID + '&sFkMasterColumn=' + sFkMasterColumn + '&bLockMasterField=' + bLockMasterField;
			
			var sGotoTab = 'SearchResult';
			var bEditMode = false;
			var bExpectReturnData = false;
			var nObjectID = 0;
			var bShowNewButton = true;
			var bShowDeleteButton = true;
			// Ignore return values
			popShowModalPopup(sUrl, nObjectID, sFormCaption, sGotoTab, bEditMode, bExpectReturnData, bShowNewButton, bShowDeleteButton, nTop, nLeft, nWidth, nHeight);

			// No submit
			return false;
		}

		// Call popup as FK popup but go to detail to add new record
		function popFkAddNew(sUrl, sFormCaption, sFkMasterColumn, nFkMasterID, bLockMasterField, nTop, nLeft, nWidth, nHeight) {
			// Add parameters
			if(sUrl.indexOf("?") == -1)
				sUrl += '?'
			else
				sUrl += '&'
			sUrl += 'nFkMasterID=' + nFkMasterID + '&sFkMasterColumn=' + sFkMasterColumn + '&bLockMasterField=' + bLockMasterField;
			
			var sGotoTab = 'Detail';
			var bEditMode = true;
			var bExpectReturnData = false;
			var nObjectID = 0;
			var bShowNewButton = true;
			var bShowDeleteButton = true;
			// Ignore return values
			popShowModalPopup(sUrl, nObjectID, sFormCaption, sGotoTab, bEditMode, bExpectReturnData, bShowNewButton, bShowDeleteButton, nTop, nLeft, nWidth, nHeight);

			// No submit
			return false;
		}

		// Show detail page in view mode
		function popViewDetailsPopup(sUrl, nObjectID, sFormCaption, nTop, nLeft, nWidth, nHeight) {
			if (nObjectID > 0) {
				var sGotoTab = 'Detail';
				var bEditMode = false;
				var bExpectReturnData = false;
				var bShowNewButton = false;
				var bShowDeleteButton = false;
				// Ignore return values
				popShowModalPopup(sUrl, nObjectID, sFormCaption, sGotoTab, bEditMode, bExpectReturnData, bShowNewButton, bShowDeleteButton, nTop, nLeft, nWidth, nHeight);
			} else {
				alert('Ingen post att visa!');
			}
			// No submit
			return false;
		}

		// Show detailed page in edit mode
		function popEditDetailsPopup(sUrl, nObjectID, sFormCaption, nTop, nLeft, nWidth, nHeight) {
			if (nObjectID > 0) {
				var sGotoTab = 'Detail';
				var bEditMode = true;
				var bExpectReturnData = false;
				var bShowNewButton = true;
				var bShowDeleteButton = true;
				// Ignore return values
				popShowModalPopup(sUrl, nObjectID, sFormCaption, sGotoTab, bEditMode, bExpectReturnData, bShowNewButton, bShowDeleteButton, nTop, nLeft, nWidth, nHeight);
			} else {
				alert('Ingen post att visa!');
			}
			// No submit
			return false;
		}

		function popFindAndBringPopup(sUrl, sFormCaption, nTop, nLeft, nWidth, nHeight) {
			var sGotoTab = 'Search';
			var bEditMode = false;
			var nObjectID = 0;
			var bExpectReturnData = true;
			var bShowNewButton = true;
			var bShowDeleteButton = true;
			var sReturnValues = popShowModalPopup(sUrl, nObjectID, sFormCaption, sGotoTab, bEditMode, bExpectReturnData, bShowNewButton, bShowDeleteButton, nTop, nLeft, nWidth, nHeight);
			return sReturnValues;
		}

		// Show popup detail page to enter new record
		function popEnterNewPopup(sUrl, sFormCaption, nTop, nLeft, nWidth, nHeight) {
			var sGotoTab = 'Detail';
			var bEditMode = true;
			var nObjectID = 0;
			var bExpectReturnData = true;
			var bShowNewButton = true;
			var bShowDeleteButton = true;
			var sReturnValues = popShowModalPopup(sUrl, nObjectID, sFormCaption, sGotoTab, bEditMode, bExpectReturnData, bShowNewButton, bShowDeleteButton, nTop, nLeft, nWidth, nHeight);
			return sReturnValues;
		}

		// Generic popup
		function popShowModalPopup(sUrl, nObjectID, sFormCaption, sGotoTab, bEditMode, bExpectReturnData, bShowNewButton, bShowDeleteButton, nTop, nLeft, nWidth, nHeight) {
			// Get popup level
			var nPopupLevel = popGetPopupLevel();

			// Top not specified?
			if (nTop == 0) {
				// Set default top
				nTop = (Number(nPopupLevel) + 1) * 25;
			}

			// Left not specified?
			if (nLeft == 0) {
				// Set default left
				nLeft = (Number(nPopupLevel) + 1) * 25;
			}

			// Width not specified?
			if (nWidth == 0) {
				// Set default width
				nWidth = 800;
			}

			// Height not specified?
			if (nHeight == 0) {
				// Set default height
				nHeight = 400;
			}

			var sUniqueUrlExt = popUniqueUrlExt();
			var sReturnValues;
			// Support for modal dialogs? (IE yes, FireFox no)
			if (window.showModalDialog) {
				// Add parameters
				if(sUrl.indexOf("?") == -1)
					sUrl += '?'
				else
					sUrl += '&'

				sUrl += 'hid_nPopupLevel=' + (nPopupLevel + 1) + '&sFormCaption=' + sFormCaption + '&nObjectID=' + nObjectID + '&sGotoTab=' + sGotoTab;
				sUrl += '&bEditMode=' + bEditMode + "&d=" + sUniqueUrlExt + "&bExpectReturnData=" + bExpectReturnData + "&bShowNewButton=" + bShowNewButton;
				sUrl += "&bShowDeleteButton=" + bShowDeleteButton;
				
				// OpenModalDialog sFeatures: dialogHeight (x px), dialogLeft (x px), dialogTop (x px), dialogWidth (x px), center (YES/no), dialogHide (yes/NO), edge (sunken/RAISED), help (YES/no), resizable (yes/NO), scroll (YES/no), status (yes/no), unadorned (yes/NO)
				sReturnValues = window.showModalDialog(sUrl, objMasterWindow, 'dialogTop:' + nTop + ';dialogLeft:' + nLeft + ';dialogWidth:' + nWidth + 'px;dialogHeight:' + nHeight + 'px;status:no;resizable:yes;help:no;center:no;');
				// Any return values?
				if (sReturnValues != '' && sReturnValues != null && sReturnValues != 'undefined') {
					// Check commands
	        saReturnValues = sReturnValues.split('[#]');
					for (var j = 0; j < saReturnValues.length; j++) {
						if (saReturnValues[j] == '[#popCloseAllPopups#]') {
							// Close this popup and pass return values 
							popClosePopup(sReturnValues);
							return '';
						}
					}
					// Return string values separated with [#]
					return sReturnValues;
				} else {
					// No return values
					return '';
				}
			} else {
				// TODO support for FireFox not completed
				// Open sFeatures: channelmode (yes/NO), directories (YES/no), fullscreen (yes/NO), height (x px), left (x px), location (YES/no), menubar (YES/no), resizable (YES/no), scrollbars (YES/no), titlebar (YES/no), top (x px), width (x px)
				sReturnValues = window.open(sUrl + '?nPopupLevel=' + (nPopupLevel + 1), '_blank', 'top=' + nTop + ',left=' + nLeft + ',width=' + nWidth + 'px,height=' + nHeight + 'px,toolbar=0,status=0,scrollbars=yes,resizable=yes,fullscreen=no');
			}
		}

		function popCloseAllPopups(sReturnValues) {
			var nPopupLevel = popGetPopupLevel();

			// Popup window?
			if (nPopupLevel != 0) {
				if (sReturnValues != '') {sReturnValues += '[#]';}
				window.returnValue = sReturnValues + '[#popCloseAllPopups#]';
				window.close();
			}
		}

		function popClosePopup(sReturnValues) {
			var nPopupLevel = popGetPopupLevel();

			// Popup window?
			if (nPopupLevel != 0) {
				window.returnValue = sReturnValues;
				window.close();
			}
			// No submit
			return false;
		}

		function popRedirectMasterWindow(sUrl) {
			// Master window exists?
			if (objMasterWindow != null && objMasterWindow != 'undefined' && objMasterWindow != '') {
				if (sUrl != '') {objMasterWindow.location.href = sUrl;}
				popCloseAllPopups('');
			}
		}

		function popSetCboValue(sCboID, sValues, bSubmit) {
			var objCbo = document.getElementById(sCboID);
			// Any values specified?
			if (sValues != '' && sValues != null && sValues != 'undefined') {
				// Get separate values
	      saValues = sValues.split('[#]');
				// Both nObjectID and sObjectCaption exists?
				if (saValues.length >= 2) {
					var nObjectID = saValues[0];
					var sObjectCaption = saValues[1];				
					// Select existing option (if any)
					if (dropSelectOptionByValue(objCbo, nObjectID, true) == 0) {
						// Add and select missing option
						dropAddOption(objCbo, nObjectID, sObjectCaption, true);
					}
					if (bSubmit == true) {
						// Reload form
						document.forms[0].submit;
						return true;
					} else {
						// No submit
						return false;
					}
				}
	    }
	    return false;
		}

		// Select option by value (returns list index)
		function dropSelectOptionByValue(objCbo, sValue, bSelect) {
			var i;
			for(i=objCbo.options.length-1;i>=0;i--) {
				if(objCbo.options[i].value == sValue) {
					// Found
					if (bSelect == true) objCbo.options[i].selected = true;
					return i + 1;
				}
			}
			// Not found
			return 0;
		}

		function dropAddOption(objCbo, sValue, sText, bSelect) {
			var objOption = document.createElement("OPTION");
			objOption.text = sText;
			objOption.value = sValue;
			objCbo.options.add(objOption);
			if (bSelect == true) {
				var nOptions = objCbo.options.length;
				objCbo.options[nOptions - 1].selected = true;
			}
		}

		function popGetPopupLevel() {
			// Get popup level
			var nPopupLevel = 0;
			var obj_nPopupLevel = document.getElementById('hid_nPopupLevel');
			if (obj_nPopupLevel) {nPopupLevel = Number(obj_nPopupLevel.value);}
			return nPopupLevel;
		}

		function popUniqueUrlExt() {
			// Creates a unique url value to prevent caching problems
			var d = new Date();
			var sReturn = String(d.getHours()) + String(d.getMinutes()) + String(d.getSeconds()) + String(d.getMilliseconds());
			return sReturn;
		}

/// Popup instead of Round Trip END

// Compiled script file for Spize Base Package
// Olof Rydergren Spize IT 2006-04-18

// -----------------------< TextBoxDefaultButton BEGIN >-------------------------
// Copied from TextBoxDefaultButton.js
// Trap default button on enter
// Spize IT 2005-05-17

function TrapDefaultButton(sButton) {
  if (document.all) {
		// Enter pressed?
    if (event.keyCode == 13) {
      event.returnValue = false;
      event.cancel = true;
      // Act on enter? 
      if (sButton != 'null') {
				__doPostBack(sButton,'');
			}
    } 
  } 
}

// -----------------------< TextBoxDefaultButton END >-------------------------

// -----------------------< spzTime BEGIN >-------------------------
//
// SpzTimer
// Olof Rydergren Spize IT 2006
// 

var m_objTimer = null;

function StartTimer(nSeconds, sExecuteFunction) {
	StopTimer();
	// Execute function sExecute after nSecounds
	m_objTimer = self.setTimeout(sExecuteFunction, nSeconds * 1000);
}

function StopTimer() {
	// Clear old timer (if any)
	if (m_objTimer != null) clearTimeout(m_objTimer);
}

// -----------------------< spzTime END >-------------------------

// -----------------------< spzAjax BEGIN >-------------------------
//
// SpzAjax - page must have function ProcessAjaxData(sAjaxData)
// Olof Rydergren Spize IT 2006
//

var m_objAjaxRequest = null;

function InitAjax() {
	try {
		m_objAjaxRequest = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			m_objAjaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				m_objAjaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				m_objAjaxRequest = null;
			}
		}
	}

	if (m_objAjaxRequest == null) alert("Error initializing Ajax XMLHttpRequest!");
}

function GetAjaxServerData(sUrl) {
	// Pass parameters in the url (can pass data in the send as well)
  m_objAjaxRequest.open("GET", sUrl, true);
  // Method to call when data from the server is ready
  m_objAjaxRequest.onreadystatechange = AjaxRequestCompleted;
  // Send the request
  m_objAjaxRequest.send(null);
}

function AjaxRequestCompleted() {
	// Response complete?
  if (m_objAjaxRequest.readyState == 4) {
		// Data loaded OK?
    if (m_objAjaxRequest.status == 200) {
      self.status = "Server is done!";
			// Process the return data
      var sAjaxData = m_objAjaxRequest.responseText;
      ProcessAjaxData(sAjaxData)
    } else if (m_objAjaxRequest.status == 404) {
      alert("Error: XMLHttpRequest URL does not exist");
    } else if (m_objAjaxRequest.status == 403) {
      alert("Error: XMLHttpRequest Access denied");
    } else if (m_objAjaxRequest.status == 500) {
      alert("Error: XMLHttpRequest Internal Server Error");
      alert(m_objAjaxRequest.responseText);
    } else {
      alert("Error: XMLHttpRequest status code is " + m_objAjaxRequest.status);
    }
	}
}

// -----------------------< spzAjax END >-------------------------

// -----------------------< ToolTipStay BEGIN >-------------------------

function ShowToolTipStay(sMessage, nOffsetX, nOffsetY) {
  if (nOffsetX == null) nOffsetX = 0;
  if (nOffsetY == null) nOffsetY = 0;
  var nPosX = event.clientX + document.body.scrollLeft + nOffsetX;
  var nPosY = event.clientY + document.body.scrollTop + nOffsetY;

  var objDivToolTipStayMsg = document.all('objToolTipStayMsg');
	if (objDivToolTipStayMsg != undefined) {
	  objDivToolTipStayMsg.innerHTML = sMessage;
	}

  var objDiv = document.all('objToolTipStay');
	if (objDiv != undefined) {
		objDiv.style.top = nPosY + 20;
		objDiv.style.left = nPosX;
		objDiv.style.visibility = 'visible';
	}
}

function HideToolTipStay() {
  var objDiv = document.all('objToolTipStay');
	if (objDiv != undefined) {
		objDiv.style.visibility = 'hidden';
	}
}

// -----------------------< ToolTipStay END >-------------------------

// -----------------------< QuickMessage BEGIN >-------------------------
//
// ZQuickMessage - Animated popup window - page must have div popup
// Olof Rydergren Spize IT 2006-03-30
//

// Popup size
var m_nPopupWindowHeight = 0;
var m_nPopupActualHeight = 0;
var m_nPopupHeaderHeight = 0;
var m_nPopupContentHeight = 0;
var m_nPopupWindowBottom = 0;
// Title
var m_sPopupTitle = '';
// Message
var m_sPopupMessage = '';
// Timers
var m_objPopupAnimationTimer = -1;
var m_objPopupHideTimer = -1;
// First time popup
var m_bFirstTimePopup = true;

// Max time to show the popup message (ms) - 5 minutes (300 000 ms)
var m_nPopupShowTime = 300000;

// ---< Page Methods BEGIN >---

// Set New Message polling interval
var m_nTimerSeconds = 60;
// Set function to execute
var m_sTimerExecuteFunction = 'GetNewPopupMessage()';

function InitQuickMessage() {
	InitAjax();
	// Start first time New Message polling timer
	StartTimer(3, m_sTimerExecuteFunction);	
}

function GetNewPopupMessage() {
	StopTimer();

	// Create unique url parameter
	var d = new Date();
  var sUrl = "../../App_spzBase/ZQuickMessage/frmZQuickMessageServer.aspx?d=" + String(d.getHours()) + String(d.getMinutes()) + String(d.getSeconds()) + String(d.getMilliseconds());

	// Call Ajax function
	GetAjaxServerData(sUrl)
}

// Mandatory page function for SpzAjax
function ProcessAjaxData(sAjaxData) {
	// Debug
	self.status = 'QuickMessage size: ' + sAjaxData.length;
	// alert('sAjaxData: ' + sAjaxData);

	// Show popup message?
	if (sAjaxData.length > 0) {
		// Show popup and recheck new messages when popup disappears
		ShowPopupMessage("Meddelande",sAjaxData);
	} else {
		// No more messages - Restart New Message polling timer
		StartTimer(m_nTimerSeconds, m_sTimerExecuteFunction);	
	}
}

// ---< Page Methods END >---

function ShowPopupMessage(sTitle, sMessage) {
	m_sPopupTitle = sTitle;
	m_sPopupMessage = sMessage;
	
	InitPopupWindow();
	ShowPopupWindow();
}

function InitPopupWindow() {
	var divQuickMessageWindow = document.getElementById('divQuickMessageWindow');
	var divQuickMessageHeader = document.getElementById('divQuickMessageHeader');
	var divQuickMessageContent = document.getElementById('divQuickMessageContent');

	// Get popup window bottom position
	m_nPopupWindowBottom = divQuickMessageWindow.style.bottom.substr(0, divQuickMessageWindow.style.bottom.length - 2);
	// Get header height
	m_nPopupHeaderHeight = divQuickMessageHeader.style.height.substr(0, divQuickMessageHeader.style.height.length - 2);
	// Get popup window full height
	m_nPopupWindowHeight = divQuickMessageWindow.style.height;
	m_nPopupWindowHeight = m_nPopupWindowHeight.substr(0, m_nPopupWindowHeight.length - 2); 
	// Reset animation height
	m_nPopupActualHeight = 0;
	// Calculate content height
	m_nPopupContentHeight = m_nPopupWindowHeight - (divQuickMessageContent.style.height.substr(0, divQuickMessageContent.style.height.length - 2));

	// Set reset flag
	m_bFirstTimePopup = true;
}

function ShowPopupWindow() {
	if (m_objPopupAnimationTimer != -1) return;

	var divQuickMessageWindow = document.getElementById('divQuickMessageWindow');
	divQuickMessageWindow.style.left = '';
	divQuickMessageWindow.style.top = '';
	divQuickMessageWindow.style.filter = '';

	// Sound alert (error: causes the screen to load twice)
	// document.all.objSound.src='../../App_spzBase/ZQuickMessage/NewQuickMessage.wav';

	// Stop timer?
	if (m_objPopupHideTimer != -1) clearInterval(m_objPopupHideTimer); m_objPopupHideTimer = -1;

	// Hide header
	document.getElementById('divQuickMessageHeader').style.display = 'none';
	// Hide content
	document.getElementById('divQuickMessageContent').style.display = 'none';

	// Set title
	document.getElementById('spnPopupTitle').innerHTML = m_sPopupTitle;
	// Set message
	document.getElementById('spnPopupMessage').innerHTML = m_sPopupMessage;

	// Reset actual height
	m_nPopupActualHeight = 0; 
	divQuickMessageWindow.style.height = m_nPopupActualHeight + 'px';
	divQuickMessageWindow.style.visibility = '';

	// Show popup window?
	if (!m_bFirstTimePopup) divQuickMessageWindow.style.display = '';

	// Start animation timer
	m_objPopupAnimationTimer = setInterval(PopupAnimationTimerEvent, (m_bFirstTimePopup?1000:20));
}

function PopupAnimationTimerEvent() {
	var divQuickMessageWindow = document.getElementById('divQuickMessageWindow');

	// First time popup?
	if (m_bFirstTimePopup) {
		// Show popup window
		divQuickMessageWindow.style.display = '';
		// Stop timer
		clearInterval(m_objPopupAnimationTimer);
		// Clear reset flag
		m_bFirstTimePopup = false;
		// Set animation timer to 20 ms
		m_objPopupAnimationTimer = setInterval(PopupAnimationTimerEvent, 20);
	}

	// Increase popup size (animation)
	m_nPopupActualHeight += 5;
	// Popup fully displayed?
	if (m_nPopupActualHeight >= m_nPopupWindowHeight) {
		// Adjust actual size
		m_nPopupActualHeight = m_nPopupWindowHeight;
		// Stop timer
		clearInterval(m_objPopupAnimationTimer);
		m_objPopupAnimationTimer = -1;
		// Show content div
		var divQuickMessageContent = document.getElementById('divQuickMessageContent');
		divQuickMessageContent.style.display = '';
		divQuickMessageContent.style.overflow = 'auto';
		// Set timer for hiding the popup after specified time?
		if (m_nPopupShowTime != -1) m_objPopupHideTimer = setInterval(PopupHideTimerEvent, m_nPopupShowTime);
	}

	// Show header div?
	if (m_nPopupHeaderHeight < m_nPopupActualHeight - 6) document.getElementById('divQuickMessageHeader').style.display = '';

	if ((m_nPopupActualHeight - m_nPopupContentHeight) > 0) {
		var divQuickMessageContent = document.getElementById('divQuickMessageContent')
		// Show content div
		divQuickMessageContent.style.display = '';
		divQuickMessageContent.style.height = (m_nPopupActualHeight - m_nPopupContentHeight) + 'px';
	}

	// Set new popup height (animation)
	divQuickMessageWindow.style.height = m_nPopupActualHeight + 'px';
}

function PopupHideTimerEvent() {
	// Stop timer
	clearInterval(m_objPopupHideTimer); 
	m_objPopupHideTimer = -1;
	
	// Hide popup
	var divQuickMessageWindow = document.getElementById('divQuickMessageWindow');
	divQuickMessageWindow.style.visibility = 'hidden';

	// Recheck new messages
	GetNewPopupMessage();
}

function ClosePopup() {
	if (m_objPopupAnimationTimer == -1) {
		// Hide popup
		var divQuickMessageWindow = document.getElementById('divQuickMessageWindow');
		divQuickMessageWindow.style.filter = '';
		divQuickMessageWindow.style.display = 'none';
		// Stop hide timer?
		if (m_objPopupHideTimer != -1) clearInterval(m_objPopupHideTimer); 
		m_objPopupHideTimer = -1;
	}

	// Recheck new messages
	GetNewPopupMessage();
}

// -----------------------< QuickMessage END >-------------------------

// -----------------------< BlockExpandCollapse BEGIN >-------------------------

// Copied from BlockExpandCollapse.js
// Spize IT 2005-08-28

function ExpandCollapseBlock(object) {
	if (document.all['hid_' + object + '_Expanded'].value != '1') {
		ExpandBlock(object);
	} else {
		CollapseBlock(object);
	}
}

function ExpandBlock(object) {
	var objContent = document.all[object + '_Container'];
	var objOpenBlockButtons = document.all[object + '_OpenBlockButtons'];
	var objExpandButton = document.all[object + '_ButtonExpandCollapse'];
	var objHiddenField = document.all['hid_' + object + '_Expanded'];

	objContent.style.display = 'block';
	if (objOpenBlockButtons != null) {
		objOpenBlockButtons.style.display = 'inline';
	}
	objExpandButton.className = 'ButtonExpandCollapse_close';
	objHiddenField.value = '1';
}

function CollapseBlock(object) {
	var objContent = document.all[object + '_Container'];
	var objOpenBlockButtons = document.all[object + '_OpenBlockButtons'];
	var objExpandButton = document.all[object + '_ButtonExpandCollapse'];
	var objHiddenField = document.all['hid_' + object + '_Expanded'];

	objContent.style.display = 'none';
	if (objOpenBlockButtons != null) {
		objOpenBlockButtons.style.display = 'none';
	}
	objExpandButton.className = 'ButtonExpandCollapse_open';
	objHiddenField.value = '0';
}

/* Edit Block */

function ShowHideEditBlock(object) {
	if (document.all['hid_' + object + '_Expanded'].value == '1') {
		if (document.all['hid_' + object + '_EditBlockVisible'].value != '1') {
			ShowEditBlock(object);
		} else {
			HideEditBlock(object);
		}
	}
}

function ShowEditBlock(object) {
	var objEditBlock = document.all[object + '_EditBlock'];
	var objButtonEdit = document.all[object + '_ButtonEdit'];
	var objHiddenField = document.all['hid_' + object + '_EditBlockVisible'];

	objEditBlock.style.display = 'block';
	objButtonEdit.className = 'ButtonEdit_close';
	objHiddenField.value = '1';
}

function HideEditBlock(object) {
	var objEditBlock = document.all[object + '_EditBlock'];
	var objButtonEdit = document.all[object + '_ButtonEdit'];
	var objHiddenField = document.all['hid_' + object + '_EditBlockVisible'];

	objEditBlock.style.display = 'none';
	objButtonEdit.className = 'ButtonEdit_open';
	objHiddenField.value = '0';
}

/* Search Block */

function ShowHideSearchBlock(object) {
	if (document.all['hid_' + object + '_Expanded'].value == '1') {
		if (document.all['hid_' + object + '_SearchBlockVisible'].value != '1') {
			ShowSearchBlock(object);
		} else {
			HideSearchBlock(object);
		}
	}
}

function ShowSearchBlock(object) {
	var objSearchBlock = document.all[object + '_SearchBlock'];
	var objButtonSearch = document.all[object + '_ButtonSearch'];
	var objHiddenField = document.all['hid_' + object + '_SearchBlockVisible'];

	objSearchBlock.style.display = 'block';
	objButtonSearch.className = 'ButtonSearch_close';
	objHiddenField.value = '1';
}

function HideSearchBlock(object) {
	var objSearchBlock = document.all[object + '_SearchBlock'];
	var objButtonSearch = document.all[object + '_ButtonSearch'];
	var objHiddenField = document.all['hid_' + object + '_SearchBlockVisible'];

	objSearchBlock.style.display = 'none';
	objButtonSearch.className = 'ButtonSearch_open';
	objHiddenField.value = '0';
}

// -----------------------< BlockExpandCollapse END >-------------------------

// -----------------------< DatePick BEGIN >-------------------------
// Copied from DatePick.js
// Swedish DatePick JavaScript include file
// Spize IT 2005-04-11

// - Date field -
// <input type="text" name="dDate2" value="2001-01-01" ID="dDate2" class="xqh_TextBox_Edit" size="10">
// <img src="Images_Neutral/icon_Calendar.gif" border="0" onClick="ShowDatePick('dDate2');return false;" alt="Visa kalender" style="cursor:pointer">

var m_objDatePick;
var m_objDatePickReturnField;

function InitDatePick(){
  // Current date
  var dtToday = new Date();

  // --- Properties ---
  this.isIE	= (document.all)?true:false;
  this.isDOM = (document.getElementById)?true:false;
  this.isIE4 = (document.all && !document.getElementById)?true:false;
  this.isNS4 = (document.layers)?true:false;

    // Object referens to div tag
  this.layer = null;
  this.arrDay = ['M&aring;','Ti','On','To','Fr','L&ouml;','S&ouml'];
  this.arrMonth = ['Jan','Feb','Mar','Apr','Maj','Jun','Jul','Aug','Sep','Okt','Nov','Dec'];
  this.arrMonthEng = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];

  // Days per month - normal year
  this.arrMonthLen = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  // Days per month - leap year	
  this.arrMonthLeap = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
  // Current year
  this.year = (dtToday.getYear() > 1900)?dtToday.getYear():dtToday.getYear() + 1900;
  // Current month
  this.month = dtToday.getMonth();	
  // Current day in month
  this.day = dtToday.getDate();
  // Calender position X
  this.posX = 1;
  // Calender position Y
  this.posY = 1;
  // Div tag created
  this.divCreated = false;

  // Methods
  this.creatediv = dtCreateEmptyDiv;
  this.show = dtPopShow;
  this.hide = dtPopHide;
  this.set = dtSetDateToField;
  this.isleapyear = dtCheckLeapYear;
  this.isweekend = dtCheckWeekend;
}

function ShowDatePick(sDateField, nOffsetX, nOffsetY){
  // optional parameters: nOffsetX, nOffsetY
  var nYear, nMonth
  var sDateFieldData = document.getElementById(sDateField).value;
  //if (sDateFieldData != ''){
    // Assuming date format yyyy-MM-dd
   // nYear = sDateFieldData.substring(0,4);
   // nMonth = (sDateFieldData.substring(5,6) == '0')?sDateFieldData.substring(6,7):sDateFieldData.substring(5,7);
   // nMonth = (nMonth > 0)?nMonth-1:nMonth=11;
 // } else {
 //   nYear = m_objDatePick.year
 //   nMonth = m_objDatePick.month
 // }
	//--------------------------------
	if (sDateFieldData != '')	{
		if (validateSwedishDate(sDateFieldData)== false){ 
			// unescape codes: Å-%C5, Ä-%C4, Ö-%D6, å-%E5, ä-%E4, ö-%F6
			alert(unescape('Fel datum format. Skall vara yyyy-mm-dd, anv%E4nder innevarande m%E5nad!'));
			nYear = m_objDatePick.year ;
			nMonth = m_objDatePick.month +1 ;
		}	else {
			var strSeparator = sDateFieldData.substring(4,5); //find date separator
			var arrayDate = sDateFieldData.split(strSeparator); //split date into month, day, year
			var nDay = parseInt(arrayDate[2],10); 
			nMonth = parseInt(arrayDate[1],10);
			nYear = parseInt(arrayDate[0],10);
		}
	} else {
		nYear = m_objDatePick.year ;
		nMonth = m_objDatePick.month +1 ;
  }
	
	//-------------------------------
  // m_objDatePick must exist and be initialized
  if (nOffsetX == null) nOffsetX = 0;
  if (nOffsetY == null) nOffsetY = 0;
  m_objDatePick.posX = event.clientX + document.body.scrollLeft + nOffsetX;
  m_objDatePick.posY = event.clientY + document.body.scrollTop + nOffsetY;
  // Date return field
  m_objDatePickReturnField = document.getElementById(sDateField);
  // Create div tag if not already created?
  if (m_objDatePick.divCreated == false){ m_objDatePick.creatediv(); }
  // Show calendar popup
  m_objDatePick.show(nYear, nMonth-1);
  return false;
}

function dtCreateEmptyDiv(){
  // Div already created?
  if (this.divCreated == true) return;

  // Create div
  var sHtml = '<div class="calpCalendar" name="divDatePick" ID="divDatePick" style="position:absolute"></div>';
  if (this.isIE){
	  document.body.insertAdjacentHTML('BeforeEnd', sHtml);
	  this.layer = document.all.tags('div')('divDatePick');
  }else if (this.isDOM){
	  var range= document.body.ownerDocument.createRange();
	  range.setStartBefore(document.body);
	  var parsedHTML = range.createContextualFragment(sHtml);
	  document.body.appendChild(parsedHTML);
	  this.layer = document.getElementById('divDatePick');
  }
  this.divCreated = true;
}

// Weekend?
function dtCheckWeekend(nDay){
  var bReturn = false;
  switch (nDay){
	  case 6:case 7:case 13:case 14:case 20:case 21:case 27:case 28:case 34:case 35:case 41:case 42:
		  bReturn = true;
		  break;
  }
  return bReturn;
}

// Leap year?
function dtCheckLeapYear(nYear){
  return (((nYear % 4) == 0) && ((nYear % 100) != 0) || ((nYear % 400) == 0))?true:false;
}

// Show calendar with specified year and month
function dtPopShow(nYear, nMonth){
  // Temp vars to handle different alternativs
  var sHtml, sHtmlMonth, sHtmlYear, sHtmlDay;
  var nArrayMonth = nMonth -1
  // The first day in the month to show
  var dtFirstDayOfMonth = new Date(this.arrMonthEng[nMonth] + ' 1, ' + nYear);
  //var dtFirstDayOfMonth = new Date(this.arrMonthEng[nArrayMonth] + ' 1, ' + nYear);
  // Position in week (weekday) for first day in month to show. If Sunday 0 set to 7
  var nPosWeekFirstDate = (dtFirstDayOfMonth.getDay() == 0)?7:dtFirstDayOfMonth.getDay();
  // Flag
  var bDayIsThisMonth = false;
  // Previous month
  var nMonthPrev	= (nMonth == 0)?11:nMonth - 1;
  // Previous year
  var nYearPrev	= (nMonthPrev == 11)?(nYear - 1):nYear;
  // Next month
  var nMonthNext	= (nMonth == 11)?0:nMonth + 1;
  // Next year
  var nYearNext	= (nMonthNext == 0)?(nYear + 1):nYear;
  // Temp variable to use right style class for layout
  var sClass;
  // Check if leap year
  var arrMonthLen	= (this.isleapyear(nYear))?this.arrMonthLeap:this.arrMonthLen;
  var sCursorHand = (this.isIE)?'cursor:pointer':'cursor:pointer';

  // Create header
  sHtml = '<table class="calpHeader">';
  sHtml += '  <tr>';
  // Previous month
  sHtml += '    <td class="calpNavArrow" colspan="2"><a style="' + sCursorHand + '" href="#" onClick="m_objDatePick.show(' + nYearPrev + ',' + nMonthPrev + ');return false;">&lt;&lt;</a></td>';
  // Name of month and year as header
  sHtml += '    <td class="calpHeaderTitle" colspan="3">' + this.arrMonth[nMonth] + ' ' + nYear + '</td>';
  // Next month
  sHtml += '    <td class="calpNavArrow"><a style="' + sCursorHand + '" href="#" onclick="m_objDatePick.show(' + nYearNext + ',' + nMonthNext + ');return false;">&gt;&gt;</a></td>';
  sHtml += '    <td align="right"><a href="#" onClick="m_objDatePick.hide();return false;">X</a></td>';
  sHtml += '  </tr>';
	sHtml += '</table>';
	
	sHtml += '<table class="calpData">';
	sHtml += '  <tr class="calpWeekDayNameRow">';
  // Add number of days (Mo-Su) to calender header
  for (var z = 0; z < 7; z++){
	  if (z == 5 || z == 6)
		  sHtml += '<td>' + this.arrDay[z] + '</td>';
	  else
		  sHtml += '<td>' + this.arrDay[z] + '</td>';
  }
  
	sHtml += '</tr>';
  // Add days in table
  for(var i = 1; i < 43; i++){
	  // Check if row break in table
	  if (i == 1 || i == 8 || i == 15 || i == 22 || i == 29 || i == 36) sHtml += '<tr class="calpWeekRow">';
	  // Check if month is before current month
	  if (i < nPosWeekFirstDate){
		  // Set year and month to current
		  sHtmlMonth = nMonthPrev;
		  sHtmlYear	= nYearPrev;
		  sHtmlDay = arrMonthLen[nMonthPrev] - nPosWeekFirstDate + i + 1;
		  sClass = (this.isweekend(i))?'calpDisabled':'calpDisabled';
		  bDayIsThisMonth = false;
	  } else if((i - nPosWeekFirstDate) >= arrMonthLen[nMonth]){
		  // Check if month is after current month
		  sHtmlMonth = nMonthNext;
		  sHtmlYear = nYearNext;
		  sHtmlDay = i - arrMonthLen[nMonth] - nPosWeekFirstDate + 1;
		  sClass = (this.isweekend(i))?'calpDisabled':'calpDisabled';
		  bDayIsThisMonth = false;
	  } else {
		  // Current month, set year, month and day
		  sHtmlMonth	= nMonth;
		  sHtmlYear	= nYear;
		  sHtmlDay	= i - nPosWeekFirstDate + 1;
		  // Today?
		  sClass = ((this.year == sHtmlYear) && (this.month == sHtmlMonth) && (this.day == sHtmlDay))?'calpToday':(this.isweekend(i))?'calpWeekend':'calpStd';
		  bDayIsThisMonth = true;
	  }

	  // Add 1 since Jan is 0 in array
	  sHtmlMonth += 1;

	  // Create HTML
	  if (bDayIsThisMonth){
		  sHtml += '<td style="' + sCursorHand + '" class="' + sClass + '" onClick="m_objDatePick.set(' + sHtmlYear + ', ' + sHtmlMonth + ', ' + sHtmlDay + ');">' + sHtmlDay + '</td>';
	  } else {
		  sHtml += '<td style="cursor:default" class="' + sClass + '">&nbsp;</td>';
	  }
	  // Check if change of row in table
	  if (i == 7 || i == 14 || i == 21 || i == 28 || i == 35 || i == 42) sHtml += '</tr>';
	}

  // Goto today link
  sHtml += '<tr class="calpHeader">';
  sHtml += '  <td colspan="7" class="calpHeader"><a style="' + sCursorHand + '" href="#" onClick="m_objDatePick.show(' + this.year + ',' + this.month + ');return false;">G&aring; till idag</a>'
  sHtml += '</tr>';

	// End table
	sHtml += "</table>\n";

	// Write calender
	if (this.isDOM || this.isIE4){
		this.layer.innerHTML = sHtml;
		this.layer.style.top = this.posY;
		this.layer.style.left = this.posX;
		this.layer.style.visibility = 'visible';
	}
}

function dtSetDateToField(nYear, nMonth, nDay){
	// Format date
	nMonth = (nMonth < 10)?'0' + nMonth.toString():nMonth.toString();
	nDay = (nDay < 10)?'0' + nDay.toString():nDay.toString();
	nYear = nYear.toString();
	var sDate = nYear + '-' + nMonth + '-' + nDay;

  // Set field
	m_objDatePickReturnField.value = sDate;

	// Hide date object
	this.hide();
}

function dtPopHide(){
  this.layer.style.visibility = "hidden";
}

// Init date pick
m_objDatePick = new InitDatePick();

// -----------------------< DatePick END >-------------------------

// -----------------------< ManyToMany BEGIN >-------------------------

// Many to many dialog
// Spize IT 2005-06-17

function ShowManyToManyDialog(sEventTarget, sDialogParameters) {
	var sResult = window.showModalDialog('../../App_spzBase/ZManyToMany/frmZModalLoader.aspx', sDialogParameters, 'scroll:no;dialogHeight:400px;dialogWidth:485px;help:no;status:no;');
	if ((sResult != null) && (sResult.length > 0)){
		__doPostBack(sEventTarget, sResult);
	}
}

// -----------------------< ManyToMany END >-------------------------


// -----------------------< TextArea BEGIN >-------------------------

/*****************************************************************
 Limit TextArea
 Sample:	<textarea name='name' class='TextBox' cols='20' rows='2' onKeyPress="return LimitTextArea_onKeyPress(this, event, 40);" onBlur="LimitTextArea_onBlur(this, 40);"></textarea>
'*****************************************************************/
// Leaving the textarea
function LimitTextArea_onBlur(object, lenlimit) {
  if (object.value.length > lenlimit) {
    alert('Max antal tecken \u00E4r ' + lenlimit + '. Texten kommer nu att begr\u00E4nsas till maxl\u00E4ngden.');
    object.value = object.value.substring(0,lenlimit);
    object.focus();
  }
}
// Keypress within the textarea
function LimitTextArea_onKeyPress(object, evnt, lenlimit){
	// IE?
  if (typeof(evnt.keyCode) != "undefined") {
		// Get ascii code
    var asciicode = evnt.keyCode;
  } else {
		// Netscape?
    if (typeof(evnt.which) != "undefined") {
			// Get ascii code
			var asciicode = evnt.which;
    } else {
			// Can not perform length checking - return True to accept keystroke
			return true;
    }
  }

	// Control keys < 31, 13 - CR, 8 - backspace
  if ((asciicode <= 31) && (asciicode != 13) ||  (asciicode == 8)) {
		// Accept the control key -it won't add any text to the box
    return true ;
  }

  // Now we check the length of the user enter text. Because when KeyPress is executed the character that the user has just
  // pressed is not in the text box yet, we test for Less Than instead of Equal To
  if (object.value.length < lenlimit) {
		// Limit not reached, accept keystroke
    return true;
  } else {
    // Ignore the keystroke
    return false;
  }
}

// -----------------------< TextArea END >-------------------------


// ---


// Move popup windows (div)
var checkZIndex = true;
var dragobject = null;
var tx;
var ty;
var ie5 = document.all != null && document.getElementsByTagName != null;

function getReal(el) {
	temp = el;
	while ((temp != null) && (temp.tagName != "BODY")) {
		if ((temp.className == "moveme") || (temp.className == "handle")){
			el = temp;
			return el;
		}
		temp = temp.parentElement;
	}
	return el;
}

function moveme_onmousedown() {
	el = getReal(window.event.srcElement)
	
	if (el.className == "moveme" || el.className == "handle") {
		if (el.className == "handle") {
			tmp = el.getAttribute("handlefor");
			if (tmp == null) {
				dragobject = null;
				return;
			} else {
				dragobject = eval(tmp);
			}
		} else { 
			dragobject = el;
		}
		
		if (checkZIndex) makeOnTop(dragobject);
		ty = window.event.clientY - getTopPos(dragobject);
		tx = window.event.clientX - getLeftPos(dragobject);
		
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	}	else {
		dragobject = null;
	}
}

function moveme_onmouseup() {
	if(dragobject) {
		dragobject = null;
	}
}

function moveme_onmousemove() {
	if (dragobject) {
		if (window.event.clientX >= 0 && window.event.clientY >= 0) {
			dragobject.style.left = window.event.clientX - tx;
			dragobject.style.top = window.event.clientY - ty;
		}
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	}
}

function getLeftPos(el) {
	if (ie5) {
		if (el.currentStyle.left == "auto") {
			return 0;
		} else {
			return parseInt(el.currentStyle.left);
		}
	} else {
		return el.style.pixelLeft;
	}
}

function getTopPos(el) {
	if (ie5) {
		if (el.currentStyle.top == "auto") {
			return 0;
		} else {
			return parseInt(el.currentStyle.top);
		}
	} else {
		return el.style.pixelTop;
	}
}

function makeOnTop(el) {
	var daiz;
	var max = 0;
	var da = document.all;
	
	for (var i=0; i<da.length; i++) {
		daiz = da[i].style.zIndex;
		if (daiz != "" && daiz > max)
			max = daiz;
	}
	el.style.zIndex = max + 1;
}

if (document.all) { //This only works in IE4 or better
	document.onmousedown = moveme_onmousedown;
	document.onmouseup = moveme_onmouseup;
	document.onmousemove = moveme_onmousemove;
}


function validateSwedishDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  //var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
  
	var objRegExp = /^\d{4}(\-|\/|\.|\s)\d{1,2}\1\d{1,2}$/
  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(4,5) //find date separator
    var arrayDate = strValue.split(strSeparator); //split date into year, month, day 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[2],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0) {
        return true; //found in lookup table, good date
      }
    }
    
    //check for February 
    var intMonth = parseInt(arrayDate[1],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[0]);
       if (intDay > 0 && intDay < 29) {
           return true;
       } else if (intDay == 29) {
         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
             (intYear % 400 == 0)) {
              // year div by 4 and ((not div by 100) or div by 400) ->ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}
