//
//  Library that contains basic functions that work browser independent.
//  
//  Since:      
//      1-9-2005
//  Changed:
//      --
//  Version:    
//      0.9
//  Creator:    
//      Data Access Europe
//

if(typeof(browser) != "Object"){
    var browser = new Object();
}

//  Detect browser type
browser.check = function(sCheck)
{
	return navigator.userAgent.toLowerCase().indexOf(sCheck)+1;
};


browser.isKonqueror=(browser.check('konqueror'))?true:false;
browser.isSafari=(browser.check('safari'))?true:false;
browser.isOmniWeb=(browser.check('omniweb'))?true:false;
browser.isOpera=(browser.check('opera'))?true:false;
browser.isWebTV=(browser.check('webtv'))?true:false;
browser.iCab=(browser.check('icab'))?true:false;
browser.isIE=(browser.check('msie'))?true:false;
browser.isNN=(!browser.check('compatible'))?true:false;
browser.isMoz=(navigator.product=="Gecko")?true:false;

//
//  Used to add swapNode() function for mozilla too
//
if (browser.isMoz) {
    Node.prototype.swapNode = function (node) {
        var nextSibling = this.nextSibling;
        var parentNode = this.parentNode;
        node.parentNode.replaceChild(this, node);
        parentNode.insertBefore(node, nextSibling);  
    }
}



//
//  Used when a function needs to be called but nothing should happen.
//
browser.nothing = function(){

}


//  browser.events contains generic methods for event handling
browser.events = new Object();

//
//	Attaches an eventlistener to an element. It completes the event name for the
//  different browsers.
//
// 	Parameters:
//		theEvent		    Name of the event
//		element		        Html object to fetch event from
//		listener		    Function that handles the event
// 
browser.events.addGenericListener = function(theEvent, element, listener){
    if (browser.isSafari)
        element.addEventListener(theEvent, listener, false);
    else if (browser.isMoz)
        element.addEventListener(theEvent, listener, false);
    else
        element.attachEvent("on"+theEvent,listener);
}


//
//  Adds a keylistener to an element. The event names are different on 
//  different browsers.
//
//  Parameters:
//      element             Element to attach listener
//      listener            Function to fetch the event
//
browser.events.addKeyListener = function(element, listener){
    if (browser.isSafari)
        element.addEventListener("keydown", listener, false);
    else if (browser.isMoz)
        element.addEventListener("keypress", listener, false);
    else
        element.attachEvent("onkeydown",listener);
}


//
//  Removes an event listener from an element.
// 	
//  Parameters:
//		theEvent    Name of the event
//		element		Html object to fetch event from
//		listener	Function that handles the event
//
browser.events.removeGenericListener = function(theEvent, element, listener){
	if (browser.isIE){
		element.detachEvent("on" + theEvent,listener);	
	}else{
        element.removeEventListener(theEvent, listener, false);	
	}
}


//
//	Fetches the targetevent from the event object.
//
// 	Parameters:
//		e			        The event object (on some browsers)
//	Returns:
//		The html element
//
browser.events.getTarget = function(e){
    if(browser.isMoz)
        return e.currentTarget;
    else
        return event.srcElement;
}

//
//  Returns the keyCode of the last event. 
//
//  Params:
//      e   Event object on some browsers
//  Returns:
//      charCode (0 if not found) WARNING: IE does not have charCode an keyCode
//      will be returned but this wont work with special chars!
//
browser.events.getKeyCode = function(e){
	var iResult = 0;
    
    if (!e){
        var e = window.event;
    }

    if(e.keyCode){
        iResult = e.keyCode;
    }
    
    return iResult;
}

browser.events.getCharCode = function(e){
    var iResult = 0;
    
    if(!e){
        var e = window.event;
    }
    
    if(e.which){
        iResult = e.which;
    }else if(e.charCode){
        iResult = e.charCode;
    }else if(e.keyCode){
        iResult = e.keyCode;
    }
    
    return iResult;
}

//
//	Returns the vertical mouse position fetched from the event object.
//
// 	Parameters:
//		e				    Event object on some browsers
//	Returns:
//		Vertical mouse position
//
browser.events.getMouseY = function(e){
	if (browser.isMoz)
		return e.clientY;
	else
		return event.clientY;
}


//
//	Returns the horizontal mouse position fetched from the event object.
//
// 	Parameters:
//		e				    Event object on some browsers
//	Returns:
//		Horizontal mouse position
//
browser.events.getMouseX = function(e){
	if (browser.isMoz)
		return e.clientX;
	else
		return event.clientX;
}


//
//	Kills the current / given event.
//
// 	Parameters:
//		e				    Event object on some browsers
//
browser.events.stop = function(e){
	if (!e) var e = window.event;
    
	e.returnValue = false;
    e.cancelBubble = true;
    e.canceled = true;

    if(e.preventDefault){
        e.preventDefault();
    }
    if(e.stopPropagation){
        e.stopPropagation();
    }
}


//  Browser independent dom tools
browser.dom = new Object();

//
//	Sets the text of the cell.
//
// 	Parameters:
//		oCell			    The HTML Cell object
//		sValue		        The new text
// 
browser.dom.setCellText = function(oCell, sValue){
	if(browser.isMoz){
		oCell.textContent = sValue;
	}else{
		oCell.innerText = sValue;
	}
}

//
//  Gives the focus to an element. For IE the element needs to be made active
//  also. On FireFox the .focus() on input element causes an error but still 
//  works (this is a known FireFox bug).
//
//  Parameters:
//      oElement            Html object to give focus
//
browser.dom.setFocus = function(oElement){
    if(browser.isIE){
        oElement.focus();
        oElement.setActive();
    }else{
        oElement.focus();
    }
}

//
//  Returns the a parent object (or itself) with the requested tagname
//
//  Parameters:
//      oObj			    Object where to startt the search
//      sTagName		    Tagname of searched object
//
browser.dom.searchParent = function(oObj, sTagName){
	var oResult = null;
	sTagName = sTagName.toUpperCase();

	if(oObj.tagName == sTagName){
		oResult = oObj;
	}else if(oObj.parentNode != null){
		oResult = browser.dom.searchParent(oObj.parentNode, sTagName);
	}
	
	return oResult;
}

//
browser.dom.getElementById=!document.getElementById?function(sId){return document.all[sId]}:function(sId){return document.getElementById(sId)};

//
//  Used to fetch an attribute from an dom element. True and false strings are 
//  converted to boolean. If not found the default string is returned.
//
//  Params:
//      oDomObj     Dom element to fetch attribute
//      sProperty   Name of the property to fetch
//      sDefault    Value returned if no element found
//  Returns:
//      Attribute (default if not set)
//
browser.dom.getAttribute = function(oDomObj, sProperty, sDefault){
    var sResult = oDomObj.getAttribute(sProperty);
    
    if(sResult == null){
        sResult = sDefault
    }
    
    if(sResult == "true"){
        sResult = true;
    }else if(sResult == "false"){
        sResult = false;
    }
    
    return sResult;
}

//
//  Fetches the lenght of the selection in the input element.
//
//  Params:
//      oInputElement   Element wich value selection length is required
//  Returns:
//      Character length of the selection (0 if there is no selection)
//
browser.dom.getSelectionLength = function(oInputElement){
    var iResult = 0;
    
    if(oInputElement.selectionStart != null){
        iResult = oInputElement.selectionEnd - oInputElement.selectionStart;
    }else if(document.selection){
        var oRange = document.selection.createRange();
        if(oRange.text){
            var sText = oRange.text;
            
            if(oInputElement.value.indexOf(sText) != -1){
                iResult = sText.length;
            }
        }
    }
    
    return iResult;
}


//  Browser independent xml tools
browser.xml = new Object();

//
//  Finds child elements with the given name. For a strange reason the 
//  nodenames get the 'm:' addition. The internet explorer needs this addition
//  to find the node by name while firefox won't find it with the addition.
//
//  Params:
//      oNode       Xml Element to search in
//      sNodeName   Name of the searched node
//  Returns:
//      Array with the found nodes
//
browser.xml.find = function(oNode, sNodeName){
    if(browser.isIE){ 
        sNodeName = 'm:' + sNodeName; // The IE XML parser needs the 'm:' (wich also comes from nowhere)
                            // add to find while other browsers only find without
    }

    return oNode.getElementsByTagName(sNodeName);
}

//
//  Searches the first child with nodename (used to maintain possibility of 
//  optimization)
//
//  Params:
//      oNode       Xml Element to search in
//      sNodeName   Name of the searched node
//  Returns:
//      First child with name (null if not found)
//
browser.xml.findFirst = function(oNode, sNodeName){
    return browser.xml.find(oNode, sNodeName)[0];
}

//
//  Returns the content of the searched node.
//
//  Params:
//      oNode       Node to search
//      sNodeName   Name of node to gind
//  Returns:
//      Content of the node ("" if not found)
//
browser.xml.findNodeContent = function(oNode, sNodeName){
    var oXml, result = "";
    oXml = browser.xml.find(oNode, sNodeName)[0];
    
    if(oXml != null){
        oXml = oXml.firstChild;
        
        if(oXml != null){
            result = oXml.nodeValue;
        }
    }
    
    if(result == null){
        result = "";
    }
    
    return result;
}

//
//  Returns the name of the node without the 'm:' addition.
//
//  Params:
//      oNode   The XML node
//  Returns:
//      Name of the node withoud addition
//
browser.xml.getNodeName = function(oNode){
    return oNode.nodeName.substring(2, oNode.nodeName.length);
}

//
//  Replaces special characters to prefent XML errors
//
//  Params:
//      sValue  Value to encode
//  Returns:
//      Encoded value
browser.xml.encode = function(sValue){
    return '<![CDATA[' + sValue + ']]>';
}

//
//  Creates the xml request object used for sending xml requests to the server.
//  On IE the activex object should be used, other browsers have the native
//  version of the object. On ie it first tries to create the version 2 of the
//  element, else it uses the older version.
//
//  Returns:
//      XMLHttpRequest object
//
browser.xml.getXMLRequestObject = function(){
    var oResult = null;
    
    if(window.XMLHttpRequest){
        oResult = new XMLHttpRequest();
    }else if(window.ActiveXObject){
        try {
            oResult = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                oResult = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {

            }
        }
    }
    
    return oResult;
}

//  Gui contains default methods for gui use
browser.gui = new Object();



//
//  Hides all select boxes behind the object (only on IE)
//
//  Params:
//      oObject The object (mostly DIV)
//
browser.gui.hideSelectBoxes = function(oObject)
{
    if(oObject)
    {
        if(browser.isIE)
        {
            var iTop = browser.gui.getAbsoluteOffsetTop(oObject);
            var iBottom = iTop + oObject.offsetHeight;
            var iLeft = browser.gui.getAbsoluteOffsetLeft(oObject);
            var iRight = iLeft + oObject.offsetWidth;
		
            var oAllSelects = document.getElementsByTagName("select");
            for(i=0; i < oAllSelects.length; i++)
            {  
                var iTopSelect= browser.gui.getAbsoluteOffsetTop(oAllSelects[i]);
                var iBottomSelect= browser.gui.getAbsoluteOffsetTop(oAllSelects[i]) + oAllSelects[i].offsetHeight; 

                if(((iTopSelect>iTop && iTopSelect<iBottom) || (iBottomSelect>iTop && iBottomSelect<iBottom)) || (iTopSelect<iTop && iBottomSelect>iBottom))  
                {
                    var iLeftSelect= browser.gui.getAbsoluteOffsetLeft(oAllSelects[i]);
                    var iRightSelect= browser.gui.getAbsoluteOffsetLeft(oAllSelects[i]) + oAllSelects[i].offsetWidth;
                    if((iLeftSelect > iLeft && iLeftSelect<iRight || (iRightSelect > iLeft && iRightSelect<iRight)) || (iLeftSelect<iLeft && iRightSelect>iRight))
                    {
                        var sVisibilityState = oAllSelects[i].getAttribute("VisibilityState");
                        if(sVisibilityState == null)
                        {
                            if(oAllSelects[i].style.visibility)
                            {
                                sVisibilityState = oAllSelects[i].style.visibility;
                            }
                            else
                            {
                                sVisibilityState = "";
                            }
							
                            if(sVisibilityState != "hidden")
                            {
                                oAllSelects[i].setAttribute("VisibilityState", sVisibilityState);
                                oAllSelects[i].setAttribute("VisibilityCount", "1");
                                oAllSelects[i].style.visibility = "hidden";
                            }
                        }
                        else
                        {
                            var iVisibilityCount = parseInt(oAllSelects[i].getAttribute("VisibilityCount"));
                            oAllSelects[i].setAttribute("VisibilityCount",iVisibilityCount+1);
                        }
                    }
                }
            }
        }
    } 
}
	

//
//  Restores all the hidden selectboxes of the function 'hideSelectboxes'
//
//  Params:
//      oObject The object
//
browser.gui.displaySelectBoxes = function(oObject)
{

    if(oObject)
    {
        if(browser.isIE)
        {
            var iTop = browser.gui.getAbsoluteOffsetTop(oObject);
            var iBottom = iTop + oObject.offsetHeight;
            var iLeft = browser.gui.getAbsoluteOffsetLeft(oObject);
            var iRight = iLeft + oObject.offsetWidth;
		
            var oAllSelects = document.getElementsByTagName("select");
            for(i=0; i < oAllSelects.length; i++)
            {   
                var iTopSelect= browser.gui.getAbsoluteOffsetTop(oAllSelects[i]);
                var iBottomSelect= browser.gui.getAbsoluteOffsetTop(oAllSelects[i]) + oAllSelects[i].offsetHeight; 
            
                if(((iTopSelect>iTop && iTopSelect<iBottom) || (iBottomSelect>iTop && iBottomSelect<iBottom)) || (iTopSelect<iTop && iBottomSelect>iBottom))
                {            
                    var iLeftSelect= browser.gui.getAbsoluteOffsetLeft(oAllSelects[i]);
                    var iRightSelect= browser.gui.getAbsoluteOffsetLeft(oAllSelects[i]) + oAllSelects[i].offsetWidth;
                    if((iLeftSelect > iLeft && iLeftSelect<iRight || (iRightSelect > iLeft && iRightSelect<iRight)) || (iLeftSelect<iLeft && iRightSelect>iRight))
                    {   
                        var sVisibilityState = oAllSelects[i].getAttribute("VisibilityState");
                        if(sVisibilityState !=null)
                        {
                            var iVisibilityCount = parseInt(oAllSelects[i].getAttribute("VisibilityCount"));
                            if(iVisibilityCount <=1)
                            {   
                                oAllSelects[i].removeAttribute("VisibilityCount");
                                oAllSelects[i].style.visibility = sVisibilityState;
                                oAllSelects[i].removeAttribute("VisibilityState");
                            }
                            else
                            {
                                oAllSelects[i].setAttribute("VisibilityCount", iVisibilityCount - 1);	
                            }
                        }
                    }
                } 
            }
        }
    }	 
}

//
//  Get the full display width (of the frame / window)
//
browser.gui.getViewportHeight = function() 
{
  if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}

//
//  Get the full display height (of the frame / window)
//
browser.gui.getViewportWidth = function() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}

//
//  This Function measures the offsetLeft position of the object that is 
//  referred to plus all its parent elements. The returnvalue is the total of
//  the object and the parent elements
//
//  Params:
//      oObject The object to get left offset from
//  Returns:
//      Total left offset of object
//
browser.gui.getAbsoluteOffsetLeft = function(oObject)
{
    var iReturnValue = 0;
    var bAddMain = true;
    var oStartObject = oObject;
    
    if (oObject) if (oObject.id == "add" || oObject.id == "view") bAddMain = false;	
    while (oObject!=null)
	  {
        iReturnValue += oObject.offsetLeft;
		 if (oObject.id == "add" || oObject.id == "view") iReturnValue += browser.dom.getElementById("middlebottom").scrollLeft;
        if (oObject.id == "main" && oStartObject.parentNode.id != "main") iReturnValue -= browser.dom.getElementById("middlebottom").scrollLeft;
        if (oObject.id == "Modal") iReturnValue += window.top.oModalDialog_CurrentDialog[window.top.oModalDialog_CurrentDialog.length-1].iX;
        if (oObject.id == "editframe") iReturnValue += window.top.browser.dom.getElementById("editframe").offsetLeft;
        oObject = oObject.offsetParent;
    }
    if (browser.dom.getElementById("MainDialog") && bAddMain) iReturnValue -= browser.dom.getElementById("MainDialog").scrollLeft   
	
    return iReturnValue
}


//
//  This Function measures the offsetTop position of the object that is 
//  referred to plus all its parent elements. The returnvalue is the total of
//  the object and the parent elements
//
//  Params:
//      oObject The object to get top offset from
//  Returns:
//      Total top offset of the object
//
browser.gui.getAbsoluteOffsetTop = function(oObject) 
{
    var iReturnValue = 0;
    var bAddMain = true;
    var oStartObject = oObject;
    
    if (oObject) if (oObject.id == "add" || oObject.id == "view") bAddMain = false;
    while (oObject!=null)
    {
        iReturnValue += oObject.offsetTop;
		if (oObject.id == "add" || oObject.id == "view") iReturnValue += browser.dom.getElementById("middlebottom").scrollTop;
        if (oObject.id == "main" && oStartObject.parentNode.id != "main") iReturnValue -= browser.dom.getElementById("middlebottom").scrollTop;
        if (oObject.id == "Modal") iReturnValue += window.top.oModalDialog_CurrentDialog[window.top.oModalDialog_CurrentDialog.length-1].iY;
        if (oObject.id == "editframe") iReturnValue += window.top.browser.dom.getElementById("editframe").offsetTop;
		    oObject = oObject.offsetParent;
    }
    if (browser.dom.getElementById("MainDialog") && bAddMain) iReturnValue -= browser.dom.getElementById("MainDialog").scrollTop;
    
    return iReturnValue
}


//  Math browser indepentdent math methods 
browser.math = new Object();

//
//  Converts string to integer, first it removens 0 chars in front.
//
//  Params:
//      sValue  String to convert
//  Result:
//      Integer value
//
browser.math.stringToInt = function(sValue){
    while(sValue.charAt(0) == '0'){
        sValue = sValue.substr(1);
    }
    
    return parseInt(sValue);
}


function getElementsByClassName(oElm,sTagName,sClassName)
{
	var aElements=(sTagName=="*"&&document.all)?document.all:oElm.getElementsByTagName(sTagName);
	var aReturnElements=new Array();
	sClassName=sClassName.replace(/\-/g,"\\-");
	var oRegExp=new RegExp("(^|\\s)"+sClassName+"(\\s|$)");
	var oElement;

	iPos=aElements.length;
	while(iPos--)
	{
		oElement=aElements[iPos];
		if(oRegExp.test(oElement.className))
		{
			aReturnElements[aReturnElements.length]=oElement;
		}
	}
	return (aReturnElements)
};


setAttributeClass=function(oElement,sClass){if(oElement)(oElement.getAttribute("className"))?oElement.setAttribute('className',sClass)/*IE*/:oElement.setAttribute('class',sClass)/*FF,NN,OP*/};
getAttributeClass=function(oElement){return oElement.getAttribute('className')||oElement.getAttribute('class');};


function stripHTML(oldString)
{
	return (trimAll(oldString.replace(/<\S[^>]*>/g, " ")).replace("&nbsp;", " "));
};


// Hi-light the selected button and set the current selected button to not selected
function selectobject(oButton,oEvent){
    var sFileBrowserType = browser.dom.getElementById("MainDialog").getAttribute("Type");
	  var sType = oButton.getAttribute("Type");
	  var sName = unescape(oButton.getAttribute("Name"))
	
	  var ev=oEvent||window.event;
	  var bNoAdd = false;

	  if (sType != "Folder" && (sType != "Category" || sFileBrowserType == "SelectPageCategory") && (sType != "WebshopProductGrp" || sFileBrowserType == "SelectPageCategory") && (sType!="MultiItemPage"|| sFileBrowserType == "SelectPageCategory") && (sType!="Catalog"|| sFileBrowserType == "SelectPageCategory") && sName != "Folder Up" && sName != "Category Up")
	  {
		if (sFileBrowserType != "SelectImageGallery" || !ev) clearobjectselection();
		else
		{
            if(ev.modifiers?ev.modifiers&Event.CTRL_MASK:(ev.ctrlKey||false))
	        {
		        //if (ev.keyCode==65) selectAll(); //ctrl-a
		        toggleselection(oButton);
		        bNoAdd = true;
	        }
	        else if(ev.modifiers?ev.modifiers&Event.SHFT_MASK:(ev.shiftKey||false)) 
	        {
	            ShiftSelect(oButton.getAttribute("ObjectId"),browser.dom.getElementById("selectedobjectid").value);
	        }
	        else clearallobjectselection();
		    
		}

        if (!bNoAdd)
        {
        browser.dom.getElementById("selectedobjectid").value = oButton.getAttribute("ObjectID");
      	    if (!isNaN(oButton.getAttribute("DocumentId"))) browser.dom.getElementById("selecteddocumentid").value = oButton.getAttribute("DocumentId");
            browser.dom.getElementById("selectedobjectname").value = oButton.getAttribute("Name");
			browser.dom.getElementById("selecteddocumentdescription").value = oButton.getAttribute("Description");
            browser.dom.getElementById("selectedobjectlink").value = oButton.getAttribute("FileUrl");
            browser.dom.getElementById("selectedobjectthumb").value = oButton.getAttribute("ThumbPath");
            browser.dom.getElementById("selectedobjecttype").value = oButton.getAttribute("Type");
		    browser.dom.getElementById("selectedobjectprice").value = oButton.getAttribute("Price");
		    browser.dom.getElementById("selectedobjectnumber").value = oButton.getAttribute("Number");
		    browser.dom.getElementById("selectedobjectvat").value = oButton.getAttribute("VAT");
		    browser.dom.getElementById("selectedobject").value = oButton.getAttribute("Type") + oButton.getAttribute("ObjectID");		
            
            browser.dom.getElementById(browser.dom.getElementById("selectedobject").value).className = "drag drop iconover";
        }
    }
}


function selectsingleobject(oButton){
	var sType = oButton.getAttribute("Type");
	var sName = unescape(oButton.getAttribute("Name"))
	
	if (sType != "Folder" && (sType != "Category" || sFileBrowserType == "SelectPageCategory") && (sType != "WebshopProductGrp" || sFileBrowserType == "SelectPageCategory") && (sType!="Catalog"|| sFileBrowserType == "SelectPageCategory") && sName != "Folder Up" && sName != "Category Up")
	{
        browser.dom.getElementById("selectedobjectid").value = oButton.getAttribute("ObjectID");
        if (!isNaN(oButton.getAttribute("DocumentId"))) browser.dom.getElementById("selecteddocumentid").value = oButton.getAttribute("DocumentId");
        browser.dom.getElementById("selectedobjectname").value = oButton.getAttribute("Name");
        browser.dom.getElementById("selectedobjectlink").value = oButton.getAttribute("FileUrl");
        browser.dom.getElementById("selectedobjectthumb").value = oButton.getAttribute("ThumbPath");
        browser.dom.getElementById("selectedobjecttype").value = oButton.getAttribute("Type");
        browser.dom.getElementById("selectedobjectprice").value = oButton.getAttribute("Price");
        browser.dom.getElementById("selectedobjectnumber").value = oButton.getAttribute("Number");
        browser.dom.getElementById("selectedobjectvat").value = oButton.getAttribute("VAT");
        browser.dom.getElementById("selectedobject").value = oButton.getAttribute("Type") + oButton.getAttribute("ObjectID");
        
        browser.dom.getElementById(browser.dom.getElementById("selectedobject").value).className = "drag drop iconover";
	}
}

function deselectsingleobject(oButton){
	var sType = oButton.getAttribute("Type");
	var sName = unescape(oButton.getAttribute("Name"))

	if (sType != "Folder" && (sType != "Category" || sFileBrowserType == "SelectPageCategory") && (sType != "WebshopProductGrp" || sFileBrowserType == "SelectPageCategory") && (sType!="Catalog"|| sFileBrowserType == "SelectPageCategory") && sName != "Folder Up" && sName != "Category Up")
	{
        browser.dom.getElementById("selectedobjectid").value = oButton.getAttribute("ObjectID");
        if (!isNaN(oButton.getAttribute("DocumentId"))) browser.dom.getElementById("selecteddocumentid").value = oButton.getAttribute("DocumentId");
        browser.dom.getElementById("selectedobjectname").value = oButton.getAttribute("Name");
        browser.dom.getElementById("selectedobjectlink").value = oButton.getAttribute("FileUrl");
        browser.dom.getElementById("selectedobjectthumb").value = oButton.getAttribute("ThumbPath");
        browser.dom.getElementById("selectedobjecttype").value = oButton.getAttribute("Type");
        browser.dom.getElementById("selectedobjectprice").value = oButton.getAttribute("Price");
        browser.dom.getElementById("selectedobjectnumber").value = oButton.getAttribute("Number");
        browser.dom.getElementById("selectedobjectvat").value = oButton.getAttribute("VAT");
        browser.dom.getElementById("selectedobject").value = oButton.getAttribute("Type") + oButton.getAttribute("ObjectID");
        
        browser.dom.getElementById(browser.dom.getElementById("selectedobject").value).className = "drag drop icon";
	}
}

// Make the current selected oButton not selected
// For Filebrowser
function clearobjectselection(){
	  
	  if (browser.dom.getElementById("selectedobject").value)
	  {
	  	browser.dom.getElementById(browser.dom.getElementById("selectedobject").value).className = "drag drop icon";
	  }	  
	
    browser.dom.getElementById("selectedobjectid").value = "";
    browser.dom.getElementById("selectedobjectname").value = "";
    browser.dom.getElementById("selectedobjecttype").value = "";
}

function clearallobjectselection(){
    
    var aDivColl=getElementsByClassName(browser.dom.getElementById("MainDialog"),"div","iconover");
    
    for(var iPos in aDivColl)
    {    
        aDivColl[iPos].className ="drag drop icon";
    } 
	
    browser.dom.getElementById("selectedobjectid").value = "";
    browser.dom.getElementById("selectedobjectname").value = "";
    browser.dom.getElementById("selectedobjecttype").value = "";
}

function toggleselection(oButton){

    if (getAttributeClass(oButton) == "drag drop icon" || getAttributeClass(oButton) == "drag icon")
    {
        oButton.className = "drag drop iconover";
    }
    else
    {
        oButton.className = "drag drop icon";
    }
    
}

function SelectAllOptions(oSelectObject){
	var iLength = oSelectObject.options.length;
	for (var i=0; i < iLength; i++){
		oSelectObject.options[i].selected = true;
	}
}

function getRadioVal(rb){
	var L = rb.length; var ret = "";
	for (var i = 0 ; i< L ; i++) {
		if(rb[i].checked) {
			ret = rb[i].value;
			break;
		}
	}
	return(ret);
}

function OpenFileBrowser(sComponentType, sForm, sHiddenInput){
	
  var oDialog = new window.top.ModalDialog(Math.min(900,window.top.browser.gui.getViewportWidth()),500);
  
  switch (sComponentType)
	{
      case 'SelectDocument'    : oDialog.sTitle='Select Document'           ; break;
      case 'SelectImage'       : oDialog.sTitle='Select Image'              ; break;
      case 'SelectFlash'       : oDialog.sTitle='Select Flash'              ; break;
      case 'SelectFile'        : oDialog.sTitle='Select File'               ; break;
      case 'SelectPage'        : oDialog.sTitle='Select Page'               ; break;
      case 'SelectDocStruc'    : oDialog.sTitle='Select Document Structure' ; break;
      case 'SelectASPTemplate' : oDialog.sTitle='Select ASP Template'       ; break;
	  case 'SelectProduct'	   : oDialog.sTitle='Select product' 		    ; break;
	  case 'SelectAccount'	   : oDialog.sTitle='Select Account'			; break;	
      default                  : oDialog.sTitle='Select Object'             ; break;
	}
	
	oDialog.showPage("FileBrowser/default.asp?ReturnEvent=ImageSet&componenttype=" + sComponentType + "&form=" + sForm + "&hiddeninput=" + sHiddenInput);

	if(sComponentType == "SelectDocument")
	{
		AddDocumentName();
	}
} //OpenFileBrowser

var gsElementOnOver;

function ShowHelpText(oElementOnOver){
    
    gbOpen=true;
    gsElementOnOver = oElementOnOver.id

	if (!window.top.browser.dom.getElementById("tooltip"))
	{
	    var oPopup = window.top.document.createElement('span');
	    oPopup.setAttribute('id','tooltip')
	    window.top.document.body.appendChild(oPopup);
	}
  	else
    {
  	    var oPopup=window.top.browser.dom.getElementById("tooltip");
    }

    oPopup.innerHTML = browser.dom.getElementById(oElementOnOver.getAttribute("tooltip")).innerHTML

    DoShowHelp(oElementOnOver.id);    
}


function ShowHelp(oElementOnOver)
{
    var sUrl = "";
    
    if (!window.top.browser.dom.getElementById("tooltip"))
    {
        var oPopup = window.top.document.createElement('span');
        oPopup.setAttribute('id','tooltip')
        window.top.document.body.appendChild(oPopup);
    }
    else
    {        
        var oPopup=window.top.browser.dom.getElementById("tooltip");
    }	
    
	gbOpen=true;
	gsElementOnOver = oElementOnOver.id;
    
    var sWindowType = "language";
    var oBody = browser.dom.getElementById("bodydiv");
    
    if (oBody) {
        sWindowType = oBody.getAttribute("Type");        
        sUrl = "";        
        if (document.body.id == "Modal") sUrl = ".";        
    } else {
        sWindowType = "language";
        sUrl = ".";
    }  
    
    if (oElementOnOver.getAttribute("tooltip") == "true") sWindowType = "language";   
    var iObjectId = oElementOnOver.getAttribute("ObjectId");
    var sType = oElementOnOver.getAttribute("Type");
    
    var sDesign="";    
    if (sWindowType=="designmanagement") {
        sDesign += "&objectname=" + oElementOnOver.getAttribute("filename");
        sDesign += "&created=" + oElementOnOver.getAttribute("CreatedOn");
        sDesign += "&updated=" + oElementOnOver.getAttribute("UpdatedOn");
    }
	
	if (sWindowType != "membermanagement" && sWindowType != "webshopmanagement" && sWindowType != "WebshopSettings" && sWindowType != "WebshopImportExport" && sWindowType != "controlpanel")
	{
		oPopup.innerHTML = window.top.browser.dom.getElementById("LoadingDiv").innerHTML;
		oPopup.style.display="block";
		var iLeft = window.top.browser.gui.getViewportWidth() - oPopup.offsetWidth;
		var iTop = window.top.browser.gui.getViewportHeight() - oPopup.offsetHeight;
		oPopup.style.display="none";    
		
		oPopup.style.top=Math.min(browser.gui.getAbsoluteOffsetTop(oElementOnOver),iTop)+"px";		
		oPopup.style.zIndex = "20000";
		oPopup.style.display = "block";	

		if (window.top.browser.gui.getViewportWidth() - Math.min(browser.gui.getAbsoluteOffsetLeft(oElementOnOver)+oElementOnOver.offsetWidth,iLeft) <= oPopup.offsetWidth)
		{	
			oPopup.style.left = browser.gui.getAbsoluteOffsetLeft(oElementOnOver)- oPopup.offsetWidth +"px";
		}
		else
		{
			oPopup.style.left=Math.min(browser.gui.getAbsoluteOffsetLeft(oElementOnOver)+oElementOnOver.offsetWidth,iLeft)+"px";
		}	
	}	
	
	sUrl += "./ObjectBrowser/ToolTip.asp?objectid=" + iObjectId + "&windowtype=" + sWindowType + "&objecttype=" + sType + "&element=" + oElementOnOver.id + sDesign;
	
	xmlhttpPost(sUrl,"tooltip",true, 500,oPopup.innerHTML);
}; //ShowHelp

function DoShowHelp(sElementOnOver)	
{   
	sElementOnOver = unescape(sElementOnOver);

	if (gbOpen && sElementOnOver==gsElementOnOver){		
		oElementOnOver = browser.dom.getElementById(sElementOnOver);
		
		gbOpen=false;
	  
    if (!window.top.gbDragging && !window.top.gbDragSelect)
    {
	    if (!window.top.browser.dom.getElementById("tooltip"))
	    {
		    var oPopup = window.top.document.createElement('span');
		    oPopup.setAttribute('id','tooltip')
		    window.top.document.body.appendChild(oPopup);
	    }
  	    else
        {
  	        var oPopup=window.top.browser.dom.getElementById("tooltip");
        }	
	    
	    if(oPopup.style.display!="block")
	    {
	        if (oPopup.innerHTML != "")	
	        {            
	            oPopup.style.display="block";
	            var iLeft = window.top.browser.gui.getViewportWidth() - oPopup.offsetWidth;
	            var iTop = window.top.browser.gui.getViewportHeight() - oPopup.offsetHeight;
	            oPopup.style.display="none";

		        oPopup.style.left=Math.min(browser.gui.getAbsoluteOffsetLeft(oElementOnOver)+oElementOnOver.offsetWidth,iLeft)+"px";
		        oPopup.style.top=Math.min(browser.gui.getAbsoluteOffsetTop(oElementOnOver),iTop)+"px";		
		        oPopup.style.zIndex = "20000";
		        oPopup.style.display = "block";
	        }
	    }
    }
  }
}; //DoShowHelp

function HideHelp()
{
	gbOpen = false;
	window.top.browser.dom.getElementById("tooltip").style.display="none";
}; //HideHelp

function ShowMenu(sString)
{	
	if(window.top.browser.dom.getElementById('menu' + sString).style.display!="block" && !gbNoContext)
	{	
		HideMenus();
	
		oPopup=window.top.browser.dom.getElementById('menu' + sString);		
	  if (!oPopup.innerHTML=='')
	  {
	  oPopup.style.display="block";
	  var iLeft = window.top.browser.gui.getViewportWidth() - oPopup.offsetWidth;
	  var iTop = window.top.browser.gui.getViewportHeight() - oPopup.offsetHeight;
	  oPopup.style.display="none";
	
		oPopup.style.left=Math.min(browser.gui.getAbsoluteOffsetLeft(browser.dom.getElementById(sString))-50,iLeft)+"px";
		oPopup.style.top=Math.min(browser.gui.getAbsoluteOffsetTop(browser.dom.getElementById(sString))+20,iTop)+"px";
		
		oPopup.style.display="block";
		}
	}
	return false;
}; //ShowMenu

function ShowContextMenu(e)
{
	if(browser.dom.getElementById("nav").style.display!="block" || window.top.browser.dom.getElementById("nav").style.display!="block")
	{			
		var x = browser.events.getMouseX(e);
    var y = browser.events.getMouseY(e);
		
		HideMenus();
	
		oPopup=browser.dom.getElementById("nav")||window.top.browser.dom.getElementById("nav");
		
	  oPopup.style.display="block";
	  var iLeft = window.top.browser.gui.getViewportWidth() - oPopup.offsetWidth;
	  var iTop = window.top.browser.gui.getViewportHeight() - oPopup.offsetHeight;
	  oPopup.style.display="none";
	
		oPopup.style.left=Math.min(x,iLeft)+'px';
		oPopup.style.top=Math.min(y,iTop)+'px';
		
		oPopup.style.display="block";
	}
	return false;
}; //ShowContextMenu

function HideContextMenu()
{
	if (browser.dom.getElementById("nav")) browser.dom.getElementById("nav").style.display="none";
	if (window.top.browser.dom.getElementById("nav")) window.top.browser.dom.getElementById("nav").style.display="none";
}; //HideContextMenu

function HideMenus()
{
	window.top.browser.dom.getElementById("tooltip").style.display="none";
	window.top.browser.dom.getElementById("menuview").style.display="none";
	window.top.browser.dom.getElementById("menuadd").style.display="none";
	window.top.browser.dom.getElementById("nav").style.display="none";
}; //HideMenus

browser.gui.addButton = function(sOnClick,sText,sColor,sPath,sId)
{
    idstring ="" 
	  if (typeof(sId) != "undefined" && sId != "" && sId != "undefined") idstring = 'id="' + sId + '"'
	  document.write ('<div onclick="' + sOnClick + '" ' + idstring + ' class="ButtonImage">');
    document.write ('<div style="background-repeat:no-repeat;background-image:url('+sPath+'Images/Global/Button' + sColor + 'Background_01.gif);height:27px;width:10px;float:left"></div>');
    document.write ('<div id="buttonText" style="cursor:pointer; background-repeat: repeat-x;background-image:url('+sPath+'Images/Global/Button' + sColor + 'Background_03.gif);height:27px;min-width:50px;width:auto;float:left;padding: 6px 0px 0px 0px;overflow:hidden;line-height:0;"><img src="'+sPath+'Images/Global/ButtonWhiteBackground_07.gif" alt="" />&nbsp;&nbsp;' + sText + '</div>');
    document.write ('<div style="background-repeat:no-repeat;background-image:url('+sPath+'Images/Global/Button' + sColor + 'Background_05.gif);height:27px;width:10px;float:left"></div>');
    document.write ('</div>');
}; //browser.gui.addButton

browser.gui.addWarning = function(sText, sTitle)
{
    document.write ('<div class="PageWarning">');
    document.write ('<div class="WarningTitle">' + sTitle + '</div>');
    document.write (sText);
    document.write ('</div>');
}; //browser.gui.addWarning

browser.gui.addError = function(sText, sTitle)
{
    document.write ('<div class="PageError">');
    document.write ('<div class="ErrorTitle">' + sTitle + '</div>');
    document.write (sText);
    document.write ('</div>');
}; //browser.gui.addError



function getCloneString(sString)
{
    if (!(sString.substring(sString.length-5)=="clone"))
		{
			sString=sString+'clone';
		}
		
		return sString;	
}; //getCloneString

function getOriginalString(sString)
{
    if (sString.substring(sString.length-5)=="clone")
		{
			sString=sString.substring(0,sString.length-5);	
		}		
		
		return sString;	
}; //getOriginalString

function replaces(sValue, sSourceString, sReplaceBy) {
    var reValue = eval('/'+sValue+'/g');
    return sSourceString.replace(reValue, sReplaceBy)
}

function resizePic(oObject, iMaxWidth, iMaxHeight) {
	var nWidthRatio  = oObject.offsetWidth/iMaxWidth;
	var nHeightRatio = oObject.offsetHeight/iMaxHeight;

 if ( (nWidthRatio >= nHeightRatio) && (nWidthRatio > 1) ) {
		oObject.style.width = iMaxWidth;
		oObject.width = iMaxWidth;
		oObject.style.height = oObject.offsetHeight/nWidthRatio;
		oObject.Height = oObject.offsetHeight/nWidthRatio;
	}

	if ( (nHeightRatio > nWidthRatio) && (nHeightRatio > 1) ) {
		oObject.style.height = iMaxHeight;
		oObject.Height = iMaxHeight
		oObject.style.width = oObject.offsetWidth/nHeightRatio;
		oObject.width = oObject.offsetWidth/nHeightRatio;
	}
}

function trimAll(sString)
{
  sString = sString.replace(/\r/g, " ");
  sString = sString.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");
  sString = sString.replace(/'/g, "");
  sString = sString.replace(/ +/g, " ");
  sString = sString.replace(/^\s/g, "");
  sString = sString.replace(/\s$/g, ""); 

  if (sString == ' '){sString = ''};
  
  return sString;
}


function disableViewMenu()
{
    browser.dom.getElementById("viewtext").style.display = "none";
    browser.dom.getElementById("view").style.display = "none";
}

function disableAddMenu()
{
    browser.dom.getElementById("addtext").style.display = "none";
    browser.dom.getElementById("add").style.display = "none";
}

function disableTextSelection()
{
    if (browser.isIE) document.onkeydown = function() {if (window.event.keyCode == 65 && window.event.ctrlKey) return false; };
    browser.dom.getElementById("middlebottom").onselectstart = function() {return false;};            
}
