


function editTopCategory(_obj, _xml){
	if (!ContentEdit){
	editCategoryID = _obj.myID;
	obj = _obj;
	loadContextMenu(_xml);
	}
}    


/* oncontextmenu funktioner */

var appState = new applicationState()

function applicationState() {
  this.contextMenu = null
}

function loadContextMenu(path) {
	var xmlDoc
	var xslDoc
	var contextMenu
	
	// tester variabel sat
	var ContentEdit = false
	
	onContextOnOff = false;

    if (ContentEdit){
		alert('Det er kun muligt at redigere én tekst ad gangen!');
	} else {
		if(path != "") {
		xmlDoc = new ActiveXObject('MSXML2.DOMDocument')
		xmlDoc.async = false;

		xslDoc = new ActiveXObject('MSXML2.DOMDocument')
		xslDoc.async = false;

		xmlDoc.load(path)
		xslDoc.load("site/oncontextmenu/context.xsl")
		
		if(appState.contextMenu != null) appState.contextMenu.removeNode(true)

		document.body.insertAdjacentHTML("beforeEnd", xmlDoc.documentElement.transformNode(xslDoc))
		contextMenu = document.body.childNodes(document.body.childNodes.length-1)

		contextMenu.style.left = window.event.x;
		contextMenu.style.top = window.event.y + document.body.scrollTop;

		appState.contextMenu = contextMenu
		window.event.cancelBubble = true
		}
	}
}

function loadContextMenuSub(obj) {
  var contextMenu
  var parentMenu

  parentMenu = returnContainer(obj)
  contextMenu = document.all[obj.id + "Sub"]
  contextMenu.style.display = "block"
  contextMenu.style.top = obj.offsetTop + parentMenu.style.pixelTop + 5	
  contextMenu.style.left = obj.offsetWidth + parentMenu.style.pixelLeft + 3
  parentMenu.subMenu = contextMenu
}

function contextHighlightRow(obj) {
  var parentMenu
  var subMenu
  var i
  
  parentMenu = returnContainer(obj)

  if(obj.selected == "false") {
    for(i=0; i < obj.childNodes.length; i++) {
      obj.childNodes(i).style.borderTop = "1px solid #08246B"
      obj.childNodes(i).style.borderBottom = "1px solid #08246B"
   obj.childNodes(i).style.background = "#B5BED6"

      if(obj.childNodes(i).cellIndex == 0) {
        obj.childNodes(i).style.borderLeft = "1px solid #08246B"
      }
      else if (obj.childNodes(i).cellIndex == obj.cells.length-1) {
        obj.childNodes(i).style.borderRight = "1px solid #08246B"
      }
    }

    if(parentMenu.subMenu != null && parentMenu != parentMenu.subMenu) {
      subMenu = parentMenu.subMenu

      while(subMenu != null) {
        subMenu.style.display = "none"
        subMenu = subMenu.subMenu
      }
    }
    obj.selected = "true"
  }
  else {
    for(i=0; i < obj.childNodes.length; i++) {
      if(i == 0) {
        obj.childNodes(i).style.borderTop = "1px solid " + obj.titlebar
        obj.childNodes(i).style.borderBottom = "1px solid " + obj.titlebar
  obj.childNodes(i).style.background = obj.titlebar
      }
      else {
        obj.childNodes(i).style.borderTop = "1px solid " + obj.background
        obj.childNodes(i).style.borderBottom = "1px solid " + obj.background
  obj.childNodes(i).style.background = obj.background
      }
      
      if(obj.childNodes(i).cellIndex == 0) {
        obj.childNodes(i).style.borderLeft = "1px solid " + obj.titlebar
      }
      else if (obj.childNodes(i).cellIndex == obj.cells.length-1) {
        obj.childNodes(i).style.borderRight = "1px solid " + obj.background
      }
    }
    obj.selected = "false"
  }
}

function clean() {
  if(appState.contextMenu != null) {
    contextMenu = appState.contextMenu.removeNode(true)
    contextMenu = null
  }
}

function returnContainer(container) {
  while(container.tagName != "DIV") {
    container = container.parentNode  
  }
  return container
}

/* Pop up */
function PopUp(url,name,width,height,left,top,resizable,scrollbars,menubar,directories,location,status) {
	//alert(url);
	SiteWin = window.open(url,name,'width='+width+',height='+height+',left='+left+',top='+top+',resizable='+resizable+',scrollbars='+scrollbars+',menubar='+menubar+',directories='+directories+',location='+location+',status='+status);
	return SiteWin;
}

function PopUpModal(_url,_height,_width,_resizable){
	//alert(_url);
	window.showModalDialog(_url,window,'dialogHeight:'+_height+'px;dialogWidth:'+_width+'px;edge:raised;help:no;scroll:no;status:no;resizable:'+_resizable+'');
}

/* ItemMaker */

function InputFieldCounter(Formname,ContentField,CounterField)
{			
	var counter = document.getElementById(CounterField);
	var field = document.getElementById(ContentField);
	//alert(counter);
	counter.innerText = "(" + (255-document[Formname](field.id).value.length) + ")";
}

/* Dashboard */

function moveDashboard(obj,direction){
	document.location.href='Do.aspx?Action=2000&Name='+TDEdit+'&Direction='+direction+'&dashboardTemplateID='+dashboardTemplateID+'&thisURL='+thisURL
}

function onoffDashboard(obj,onoff,xy){
	document.location.href='Do.aspx?Action=2100&Name='+TDEdit+'&OnOff='+onoff+'&XY='+xy+'&dashboardTemplateID='+dashboardTemplateID+'&thisURL='+thisURL
}


function insertNewRow(){
	document.location.href='Do.aspx?Action=2051&dashboardTemplateID='+dashboardTemplateID+'&thisURL='+thisURL
}

function insertNewColumn(){
	document.location.href='Do.aspx?Action=2050&dashboardTemplateID='+dashboardTemplateID+'&thisURL='+thisURL
}
    
    function updateTDAttribute(){
		document.location.href = '../../do.aspx?Name='+_Name+'&action=2200&txtBGColor='+_txtBGColor+'&txtBackground='+_txtBackground+'&txtHeight='+_txtHeight+'&txtWidth='+_txtWidth+'&txtValign='+_txtValign+'&txtAlign='+_txtAlign+'&txtClass='+_txtClass+'&txtStyle='+_txtStyle+'&DashboardTemplateID='+dashboardTemplateID+'&thisURL='+thisURL+''
    }


    function updateBodyAttribute(){
		document.location.href = '../../do.aspx?action=2300&bgcolor='+_txtBGColor+'&background='+_txtBackground+'&class='+_txtClass+'&bottommargin='+_txtBottommargin+'&topmargin='+_txtTopmargin+'&leftmargin='+_txtLeftmargin+'&rightmargin='+_txtRightmargin+'&marginheight='+_txtMarginheight+'&marginwidth='+_txtMarginwidth+'&DashboardTemplateID='+dashboardTemplateID+'&thisURL='+thisURL+''
	}
	
	
	function updatePageProperty(){
	document.location.href = '../../do.aspx?action=2310&Name='+_txtName+'&dashboardTemplateID='+dashboardTemplateID+'&AltText='+_txtAltText+'&Locked='+_txtLocked+'&Hidden='+_txtHidden+'&Published='+_txtPublished+'&URL='+_txtURL+'&NewWindow='+_txtNewWindow+'&ID='+editCategoryID+'&thisURL='+thisURL
	}	

	function updateDashboardProperty(){
	document.location.href = '../../do.aspx?action=2320&Name='+_txtName+'&Locked='+_txtLocked+'&System='+_txtSystem+'&ID='+dashboardTemplateID+'&thisURL='+thisURL
	}

	function copyDashboard(){
	document.location.href = '../../do.aspx?action=2330&Name='+_txtName+'&DashboardTemplateID='+dashboardTemplateID+'&thisURL='+thisURL
	}