
// ################## switchChart  #########################
function switchChart(mID) {
	
	var mElementArray = new Array("1month_chart" , "3month_chart" , "12month_chart");
	if(mID == null || mID == "") return;
	
	 for(var i = 0; i < mElementArray.length; ++i){
        var mElementID = mElementArray[i];
        var mElement = document.getElementById(mElementID);
        
    	if (mElement != null){
    	  	if (mElementID == mID) { // ### display Chart ###
    	  		mElement.style.display = "block";
    	  		mElement.style.visibility = "visible";
    	  		mElement.style.position = "relative";
    	  		mElement.style.top = "-" + (i * 18 ) + "px";
    	  		mElement.style.margin = "0px";
    	  		mElement.style.padding = "0px";
    	  	} else {  // ### hide Chart ###
    	  		mElement.style.display = "none";
    	  		mElement.style.visibility = "hidden";
    	  		mElement.style.position = "relative";
    	  		mElement.style.top = "0px";
    	  		mElement.style.margin = "0px";
    	  		mElement.style.padding = "0px";
    	  	}
    	}
   	 }
}


// ################## internetExplorerPathCorrection  #########################
function internetExplorerPathCorrection(elementPath , activePagePath) {	
	if(elementPath.lastIndexOf("http:") > -1 || elementPath.lastIndexOf("https:") > -1){
		var pathArray = elementPath.split("/");
		if(pathArray.length > 2){
			var primaryDomain = pathArray[0] + "/" + pathArray[1] + "/" + pathArray[2] + "/";
								
			var rightPath = "";
			for(var t = 3; t < pathArray.length; ++t){
				var mPathElement = pathArray[t];
				rightPath += "/" + mPathElement ;	
			}
			//alert("rightPath: " + rightPath + "\n activePagePath: " + activePagePath);	
			var elementPath = rightPath;	
		}
	}
	
	
	
	var pathArray = activePagePath.split("/");

	for(var i = pathArray.length; i > 0; --i){
		var checkPath = "";
		for(var n = 0; n < i; ++n){	
        	var mPathElement = pathArray[n];
        	checkPath += mPathElement + "/";
        }
    	
  
    	if(checkPath.length > 1){
			var position = elementPath.lastIndexOf(checkPath);
			if(position > -1){
				var stopPosition = (position + checkPath.length);
				var elementPath = elementPath.substr(stopPosition);
				//alert("IE corrected elementPath: " + elementPath);
				return 	elementPath;
			}
		}	
    }
						
    
	return 	elementPath;			
}


// ################## sharingParagraphPathMapping  #########################
function sharingParagraphPathMapping(nodePath, magnoliaContextPath, activePagePath) {

	var searchPath = magnoliaContextPath + activePagePath;
		
	var sharedContentRoot = "/_shared_content/"; // ### defines the shared content root

	var documentHref = document.location.href;
	var serverType = "PUBLIC";
	if(documentHref.lastIndexOf("AuthorStage/") > 0) {var serverType = "AUTHOR";}
	if(documentHref.lastIndexOf("Author/") > 0) {var serverType = "AUTHOR";}
	
	//##### HACK for url correction on Magnolia Author Server only for relative hyperlink path ####
	var authorDocRoot = "";
	if(serverType == "AUTHOR") {
		var pathArray = documentHref.split("/");
		
		for(var i = 0; i <= 4; ++i){ // ### to level 2 domain
			var mPathElement = pathArray[i];
        	authorDocRoot += mPathElement + "/";
		}
		//alert("documentHref " + documentHref + " authorDocRoot: " + authorDocRoot);
	}
	
	
	var sharingDivElement = document.getElementById(nodePath);
   	if(sharingDivElement != null){
		//######## IMAGE HANDLING #########
		var mElementList = sharingDivElement.getElementsByTagName("img"); // ### get all images

		for(var i = 0; i < mElementList.length; ++i){
        	var mElement = mElementList[i];
        	if (mElement != null) {
				var elementPath = mElement.getAttribute("src");
				if (elementPath != null && elementPath != "") {	
					var elementPath = internetExplorerPathCorrection(elementPath , activePagePath); //### compose new path to avoid IE bug
					var newPath = sharedContentRoot + elementPath;
					var newPath = newPath.replace(/\/\//g, "/"); // ## replace // with single /
					
					mElement.setAttribute("src", newPath);
				}
			}		
    	}
    	
    	
    	//######## ANCHOR HANDLING #########
		var mElementList = sharingDivElement.getElementsByTagName("a"); // ### get all anchors
		
		for(var i = 0; i < mElementList.length; ++i){
        	var mElement = mElementList[i];
        	if (mElement != null) {
				var elementPath = mElement.getAttribute("href");
				
				var docType = "HTML"; // ## default docType HTML
				
				if(elementPath != null) {
					if(elementPath.lastIndexOf(".htm") > 0) {var docType = "HTML";}
					if(elementPath.lastIndexOf(".html") > 0) {var docType = "HTML";}
					if(elementPath.lastIndexOf(".pdf") > 0) {var docType = "PDF";}
					if(elementPath.lastIndexOf(".xls") > 0) {var docType = "XLS";}
					if(elementPath.lastIndexOf(".doc") > 0) {var docType = "DOC";}
					if(elementPath.lastIndexOf(".png") > 0) {var docType = "PNG";}
					if(elementPath.lastIndexOf(".jpg") > 0) {var docType = "JPEG";}
					if(elementPath.lastIndexOf(".gif") > 0) {var docType = "GIF";}
					if(elementPath.lastIndexOf(".swf") > 0) {var docType = "FLASH";}
					if(elementPath.lastIndexOf(".mov") > 0) {var docType = "QT";}

				
					var newPath = elementPath; // ## default
				
				
					if (elementPath != null && elementPath != "") {
						var elementPath = internetExplorerPathCorrection(elementPath , activePagePath); //### compose new path to avoid IE bug
					
						if(docType != "HTML"){
							//### HANDLING OF UPLOADED DOCS - TYPES like PDF, DOC, XSL  ####
							var newPath = sharedContentRoot + elementPath;
						}
						
						if(docType == "HTML"){
							//### HTML HANDLING  ####
							if(serverType == "AUTHOR"){
								//##### HACK for url correction on Magnolia Author Server only for relative hyperlink path ####
								if(elementPath.lastIndexOf("../") > 0){
									var elementPath = elementPath.replace(/\.\.\//g, "");
									var newPath = authorDocRoot + elementPath;
									//alert("\n authorDocRoot: " + authorDocRoot + "\n elementPath: " + elementPath + "\n newPath: " + newPath);
								}
							}
						}
					}
				
				
					if(elementPath.lastIndexOf("@") > 0) {var newPath = elementPath;} // ## no mapping for Mail links
					if(elementPath.lastIndexOf("#") > 0) {var newPath = elementPath;} // ## no mapping for # inline Anchor links
				
					// #### change path dynamically ####
					//alert("Anchor newPath: " + newPath);
					mElement.setAttribute("href", newPath);	
				}
				
			}		
    	}	
    
	}
}


// ################## sitemapLinkPrepare  #########################
function sitemapLinkPrepare() {

	if(gContextPath == null){gContextPath = "";}	
	var mAnchorList = document.getElementsByTagName("a"); // ### get all anchors from sitemap page
	
	 for(var i = 1; i < mAnchorList.length; ++i){
        var mAnchorElement = mAnchorList[i];
        
        if (mAnchorElement != null) {
			var ref = mAnchorElement.getAttribute("href");
			if (ref != null && ref != "") {
				//alert("Anchor i: " + i + " ref: " + ref);
				var ref = ref.replace(gContextPath, "");				
				var newHREF = "javascript:callOpenerPageNoClose('" + ref + "');";
				mAnchorElement.setAttribute("href", newHREF);		
			}
		}		
    }	
}


// ################## dmsLinkPrepare  #########################
function dmsLinkPrepare() {

	if(gContextPath == null){gContextPath = "";}	
	var mAnchorList = document.getElementsByTagName("a"); // ### get all anchors from sitemap page
	
	 for(var i = 1; i < mAnchorList.length; ++i){
        var mAnchorElement = mAnchorList[i];
        
        if (mAnchorElement != null) {
			var ref = mAnchorElement.getAttribute("href");
			if (ref != null && ref != "") {
				//alert("Anchor i: " + i + " ref: " + ref);
				//var ref = ref.replace(gContextPath, "");				
				
				if(ref.match("/dms/")!=null){
        			//alert("find");
	        		var relativPath = ref.substr(ref.indexOf("/dms"));
        			//alert("relativPath is : "+ relativPath);
        			var newRef = gContextPath+ relativPath;
        			//alert("newRef is : "+ newRef);
        			mAnchorElement.setAttribute("href", newRef);		
    			}
			}
		}		
    }	
}



// ################## callOpenerPage  #########################
function callOpenerPageNoClose(cmsPagePath) {
	if(gContextPath == null){gContextPath = "";}
	if(cmsPagePath != "") {
		if (window.opener && !window.opener.closed){
			var checkLocationTree = window.opener.location.href.lastIndexOf("trees"); // ## CMS path tree in author mode
			if(checkLocationTree == -1) {
				var mLoctionCMSPath =  gContextPath + cmsPagePath;
				//alert("mLoctionCMSPath: " + mLoctionCMSPath);
  				window.opener.document.location.href = mLoctionCMSPath;
  			}
  		}
	}
}


// ################## callOpenerPage  #########################
function callOpenerPage(cmsPagePath) {

	if(gContextPath == null){gContextPath = "";}
	if(cmsPagePath != "") {
		if (window.opener && !window.opener.closed){
			var checkLocationTree = window.opener.location.href.lastIndexOf("trees"); // ## CMS path tree in author mode
			if(checkLocationTree == -1) {
				var mLoctionCMSPath =  gContextPath + cmsPagePath;
				//alert("mLoctionCMSPath: " + mLoctionCMSPath);
  				window.opener.document.location.href = mLoctionCMSPath;
  				window.close();
  			}
  		}
	}
}



// ################## callCMSPage  #########################
function callCMSPage(contextPath, mTargetValue)
{

	if(mTargetValue != "") {
		var mLoactionCMSPath =  contextPath + mTargetValue + '.html';
		//alert("callCMSPage " + mLoactionCMSPath);
		document.location.href= mLoactionCMSPath;
	}
}



// ################## gotoCMSPage  #########################
function gotoCMSPage(contextPath, cmsPagePath) {
	if(cmsPagePath != "") {
		var mLoactionCMSPath =  contextPath + cmsPagePath ;
		//alert("gotoCMSPage: " + cmsPagePath );
		document.location.href= mLoactionCMSPath;
	}
}


// ################## QueryString  #########################
function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}

// ################## QueryString_Parse  #########################
function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}

}

// ################## popUp  #########################
function popUp(mUrl,mWname,mWidth,mHeight) {
	var mOptions = "toolbar=no,menubar=yes,locationbar=no,scrollbars=yes,resizable=yes,status=no";
        // ** Internet Explorer can't handle spaces in Window names **
        var name = mWname;
        var spaceIndex = name.indexOf(' ');
        while (spaceIndex > -1) {
            name = name.substring(0, spaceIndex) + name.substring(spaceIndex + 1, name.length); 
            spaceIndex = name.indexOf(' ');
        }
        // ** open the window **
	mWindow = window.open(mUrl,name,mOptions + ",width=" + mWidth + ",height=" + mHeight);
	mWindow.focus();
}


// ################## GetInputValue  #########################
// returns the numeric value of the form-field given in mObject
// if it contains a comma instead of a decimal point the function converts the "," to "."
 function GetInputValue(mObject) {
    
    // ### Get Value of Input Field ###//  
 	if(isNaN(mObject.value) == false){
	    var mValue = parseFloat(mObject.value); 
	    if(isNaN(mValue)){
	    	 var mValue = 0;
	    }
	     mObject.value = mValue;
  		return mValue;
	} else {
	 	// ### Convert , into . of Input Field ###//
	 	 var mZahlenString = "" + mObject.value;
		 var Zahlen = mZahlenString.split(",");
		 if (Zahlen.length > 0) {
		 	var mNewValue = Zahlen[0] + "." + Zahlen[1];
		 	var mNewValue = parseFloat(mNewValue);
		 	
		 		if (isNaN(mNewValue) == true) {
		 			var mValue = 0;
		 			mObject.value = mValue;
		 			return mValue;
		 		} 
		 	mObject.value = mNewValue;
		 	return mNewValue;
		} 
	}
 }
 
 // ** this variable can be overridden by the using JSP, e.g. to "," **
 var decimalSign = ".";
 /** ###############  KonvertFloatToString  ###############
  * receives a float value and converts it to a
  * formatted String with 2 digits after the decimal dot.
  * Uses the variable decimalSign to render a dot or a comma.
  */
 function KonvertFloatToString(mFloat) {
    var thousenderDot = ",";
    if (decimalSign == ",") {
       thousenderDot = ".";
    }
    var mNumber = Math.round(mFloat * 100);
    var mNumber =	mNumber / 100;
	var mString = "" + mNumber;
	
	var mZahlenArray = mString.split(".");
	
	if (mZahlenArray.length > 1) {
			var VorKomma = mZahlenArray[0];
			var NachKomma = mZahlenArray[1];
			
			if (NachKomma.length == 1) {var NachKomma = NachKomma + "0";}
			var mString = VorKomma + decimalSign + NachKomma;
	} else {
		var mString = mString + decimalSign + "00";
	}
	
	return mString;
}

//##### PRINT FUNCTION #######
function printit(){  
    if (window.print) {
        window.print();
    } else {
        var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    
        WebBrowser1.outerHTML = "";  
    }
}

/**
 * moves the selected item from one mutli-select-list to another. 
 * Use this method if you have 2 multi-select-lists, one with the 
 * possible values and one with the selected values.
 */
function MoveItem(fromObj,toObj)
{
   if (!eval(fromObj) || !eval(toObj))
       return;
   for (selIndex = fromObj.length-1; selIndex >=0 ; selIndex-- )
   {
      // Is this current option selected?
       if (fromObj.options[selIndex].selected)
       {
         // get the values from this option
         var newText = fromObj.options[selIndex].text;
         var newValue = fromObj.options[selIndex].value;
         // create the new element for other select box 
         var newOption = new Option(newText,newValue)
         // put the new option at the end of the current list 
         toObj[toObj.length] = newOption;
         // delete the old one.
         fromObj[selIndex] = null;
      }
   }
}

/**
 * auto-selects all entries in a multi-select-list. 
 * Use this method if you have 2 multi-select-lists, one with the 
 * possible values and one with the selected values. 
 * Example: 
 * <input type="submit" onclick="javascript:selectAllForSubmit(wishlist)">
 */
function selectAllForSubmit(selectBox)
{
    for(index = 0;index<selectBox.length;++index)
    {
        selectBox.options[index].selected = true;
    }
}

/**
 * compares the text of 2 options
 * @author Markus Leichter 
 */
function compareOptionsText (option1, option2) {
	return option1.text.toLowerCase() < option2.text.toLowerCase() ? -1 :
    	option1.text.toLowerCase() > option2.text.toLowerCase() ? 1 : 0;
}

/**
 * sorts items in mutli-select-list. 
 * @author Markus Leichter
 */
function SortMultiSelectList(select) 
{
//  if (!compareFunction)
	compareFunction = compareOptionsText;
	var options = new Array (select.options.length);
	for (var i = 0; i < options.length; i++)
	options[i] = 
		new Option (
			select.options[i].text,
			select.options[i].value,
			select.options[i].defaultSelected,
			select.options[i].selected
		);
	options.sort(compareFunction);
	select.options.length = 0;
	for (var i = 0; i < options.length; i++)
		select.options[i] = options[i];
}

/**
 * finds the index of an option by value
 */
function findOptionIndexByValue(optionListObject, mValue) {
    for (var i = 0; i < optionListObject.options.length; i++) {
        if (optionListObject.options[i].value == mValue)
            return i;
    }
    return 0;
} 

/**
 * this function sets the visibility of the dive with the given id to "visible" 
 * and positions it 
 * - horizontally centered
 * - with original top position, but relative to current scrolling position
 * It can be used for a hidden div, e.g. displaying a loading image and a 
 * "please wait" text. In the onclick azttribute of the button that leads to a 
 * time consuming controller action you can call this method. 
 * 
 * The div could be defined e.g. like this: 
 * <div style="position: absolute; top: 100px; left: 300px; width: 200px; height: 100px; z-index: 2; visibility: hidden; text-align: center; vertical-align: middle; background-color: #EFEFEF; border: 1px solid #FFA500; padding: 20px;" id="loadingDiv"><img src="<%= request.getContextPath() %>/images/loading.gif" width="35" height="35" border="0"><br><br><sf:message key="label.pleaseWait" bundle="UserInterfaceMessages"/></div>
 */
function showDivScrollingCentered(divId) {
    var myDiv = document.getElementById(divId);
    if (eval(myDiv)) {
        var mWidth,mHeight;
        if (self.innerHeight) // all except Explorer
        {
                mWidth = self.innerWidth;
                mHeight = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
                // Explorer 6 Strict Mode
        {
                mWidth = document.documentElement.clientWidth;
                mHeight = document.documentElement.clientHeight;
        }
        else if (document.body) // other Explorers
        {
                mWidth = document.body.clientWidth;
                mHeight = document.body.clientHeight;
        }
        var x = 0;
        var y = 0;
        if (self.pageYOffset) // all except Explorer
        {
                x = self.pageXOffset;
                y = self.pageYOffset;
        }
        else if (document.documentElement && document.documentElement.scrollTop)
                // Explorer 6 Strict
        {
                x = document.documentElement.scrollLeft;
                y = document.documentElement.scrollTop;
        }
        else if (document.body) // all other Explorers
        {
                x = document.body.scrollLeft;
                y = document.body.scrollTop;
        }  
        var posY = parseInt(myDiv.style.top) + y; // ** original top position, but relative to scrolling **
        var posX = (mWidth / 2) - (parseInt(myDiv.style.width) / 2) + x; // ** horizontally centered **
        myDiv.style.top = posY;
        myDiv.style.left = posX;
        myDiv.style.visibility = "visible";
    }
}

function showError(contextPath) {
    window.open(contextPath + '/errorPage.jsp', 'errorWindow');
}


// ### setInnerHtml  ###
function setInnerHtml(elementId, innerHtmlText) {
	var element = document.getElementById(elementId);
	if(element != null) {
		element.innerHTML = "" + innerHtmlText;
	}
}


// ###############   displayElement    ###############
function displayElement(id, status){
	if(status == null){var status = true;}
	
	var element = document.getElementById(id);
	if(element != null) {
		if(status == false){
			element.style.display = "none";
			element.style.visibility = "hidden";
		}
		
		if(status == true){
			element.style.display = "inline";
			element.style.visibility = "visible";
		}
	}
}


// ###########   attachEventListener #############
function attachEventListener(target, eventType, functionRef, capture){
		// ## cross browser compatible attachEventListener function -- function can be called with a pointer or a string representing a function name
	
      	if (typeof(functionRef)== 'string') {
            functionRef=eval(functionRef);
      	}

  		if (typeof target.addEventListener != "undefined"){
    		target.addEventListener(eventType, functionRef, capture);
		} else if (typeof target.attachEvent != "undefined"){
			target.attachEvent("on" + eventType, functionRef);
  		} else {
    		eventType = "on" + eventType;
		
    		if(typeof target[eventType] == "function"){
        		var oldListener = target[eventType];
        		target[eventType] = function(){
            		oldListener();
            		return functionRef();
        		};

    		} else {
        		target[eventType] = functionRef;
    		}

  		}

}

	
// ###############   createDOMElement    ###############
function createDOMElement(mElementType, mParentElement ,mTextString, mClassName , mElementID ){
		var mNewObject = document.createElement(mElementType);
		var mClassObject = document.createAttribute("class");
	
		if( mClassName  != ""){
			mClassObject.nodeValue = mClassName ;
			mNewObject.setAttributeNode(mClassObject);
		}

		if( mElementID  != "") {
			//alert("mElementID " + mElementID );
			var mIDObject = document.createAttribute("id");
			mIDObject.nodeValue = mElementID ;
			mNewObject.setAttributeNode(mIDObject);
		}
		
		if(mTextString != "") { 
            if (mElementType.toLowerCase() == "div") {
                mNewObject.innerHTML = mTextString;
            } else {
				var mTextNode = document.createTextNode("" + mTextString);
				mNewObject.appendChild(mTextNode);
            }
		}

		mParentElement.appendChild(mNewObject);

		return mNewObject;
}


// ############  Zahlen formatieren  ###########
// usage: format_zahl( number [, number]  [, bool]  )
function formatZahl(zahl, k, fix) {
    if(!k) k = 0;
    var neu = '';
    // Runden
    var f = Math.pow(10, k);
    zahl = '' + parseInt( zahl * f + (.5 * (zahl > 0 ? 1 : -1)) ) / f ;

    // Komma ermittlen
    var idx = zahl.indexOf('.');

    // fehlende Nullen einf?gen
    if(fix) {
         zahl += (idx == -1 ? '.' : '' )
         + f.toString().substring(1);
    }

    // Nachkommastellen ermittlen
    idx = zahl.indexOf('.');
    if( idx == -1) idx = zahl.length;
    else neu = ',' + zahl.substr(idx + 1, k);

    // Tausendertrennzeichen
    while(idx > 0)    {
        if(idx - 3 > 0)
        neu = '.' + zahl.substring( idx - 3, idx) + neu;
        else
        neu = zahl.substring(0, idx) + neu;
        idx -= 3;
    }

    return neu;
}

  
// ### ShowObjectProperties  ###
function ShowObjectProperties(mObject) {
    	var mWindow = window.open("", "DEBUG", "toolbar=0,location=0,directories=0,scrollbars=1,status=0,menubar=1,resizable=1,width=500,height=600");
    	mWindow.document.open();
    
    	for (var i in mObject) {
        	mWindow.document.write('<BR><B>' + i + '</B> = ' + mObject[i] );
    	}
    
    	mWindow.document.close();
    	mWindow.focus();
}

// ################  copyToClipboard    ##################
var gErrorMessageClipboardDiabled = "Die scriptgesteuerte Zwischenablage-Funktion Ihres Browsers ist aus Sicherheitsgründen deaktiviert. Bitte wenden Sie sich an Ihren Systemadministrator um diese zu aktivieren.";

function copyToClipboard(s) {
    if( window.clipboardData && clipboardData.setData ) {
        clipboardData.setData("Text", s);
    } else {
        // for mozilla and firefox browsers        
        try {
            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        }
        catch (e) {
            alert(gErrorMessageClipboardDiabled);
            return;
        }
        
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;
    
        // create a transferable
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;
    
        // specify the data we wish to handle. Plaintext in this case.
        trans.addDataFlavor('text/unicode');
    
        // To get the data from the transferable we need two new objects
        var str = new Object();
        var len = new Object();
    
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
    
        var copytext=s;
    
        str.data=copytext;
    
        trans.setTransferData("text/unicode",str,copytext.length*2);
    
        var clipid=Components.interfaces.nsIClipboard;
    
        if (!clip) return false;
    
        clip.setData(trans,null,clipid.kGlobalClipboard);      
    }
}

/**
 *  retrieves a cookie by name or <code>null</code>
 */
function getCookie ( cookieName )
{
  var results = document.cookie.match ( '(^|;) ?' + cookieName + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

/**
 * deletes a cookie by setting the timeout to a past date
 */
function deleteCookie ( cookieName )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookieName += "=; expires=" + cookie_date.toGMTString();
}

/**
 * sets a cookie
 * @param name name of the cookie
 * @param value value of the cookie
 * @param exp_y (optional) year to expire
 * @param exp_m (optional) month to expire
 * @param exp_d (optional) day to expire
 * @param path (optional)
 * @param domain (optional) 
 * @param secure (optional) 
 */
function setCookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}


//######################  findPos  ######################
function findPos(obj) {
	var curleft = 0, curtop = 0;
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
				return [curleft,curtop];
	}
}
