// Copyright: infoAsset AG, 2000-2002. All rights reserved.
// www.infoasset.de
// Date: 31-MAY-2005
// Author: FM

var normalImage =  "/skin/images/icons/ic_portfolio_p.gif";
var selectedImage = "/skin/images/icons/ic_portfolio.gif";

var portfolioControls = new Array();
var portfolioControlCounter = 0;

// Display inverse symbol on entry:
function over(id) {
  var p = getPortfolioControl(id);
  if(!p.on) {
    var cid=cleanId(id);//erase the . and /
    document.images[cid].src = selectedImage;
  }
  // else do not change the image
}

// Display original symbol on exit:
function out(id) {
  var p = getPortfolioControl(id);
  if(!p.on) {
    var cid=cleanId(id);
    document.images[cid].src = normalImage;
  }
}

function toggle(id) {
  var p = getPortfolioControl(id);
  p.on = !p.on;
  var cid=cleanId(id);
  if(p.on) {
    document.images[cid].src = selectedImage;
  }
  else {
    document.images[cid].src = normalImage;
  }
}

function change(id) {
    loadXMLDoc('/portfolios/changeState?id=' + id, changeImage);
}

function changeImage() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status != 200) {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
        else {
          var id = req.responseText;
          toggle(id);          
        }
    }
}

// this function will erase / and .
// needed for proper handling of ids containing those characters
// e.g. document/123.htm is converted to document123
// javascript would otherwise have difficulties
function cleanId(id) {
	var posSlash=id.indexOf("/");
	var cleanId1=id.substring(0,posSlash);
	var cleanId2=id.substring(posSlash+1,id.length);
	return cleanId1+cleanId2;
}

function removeExtension(id) {
	var posDot=id.indexOf(".");
	if(posDot > 0) {
		id=id.substring(0,posDot);
	}
	return id;
}

function PortfolioControl(fullId) {
  this.id = removeExtension(fullId);
  this.on = d.currentPortfolioItems.indexOf(this.id) > -1;
}

function getPortfolioControl(id) {
	for (var i = 0; i < portfolioControls.length; i++) {
		var p = portfolioControls[i];
		if(p.id == id) {
			return p;
		}
	}
	return null;
}

function portfolioControl(fullId) {
	//alert(d.hasCurrentPortfolio);
  	if(d.hasCurrentPortfolio == "true") {
  		var p = new PortfolioControl(fullId);
	  	portfolioControls[portfolioControlCounter++] = p;
	  	var cid=cleanId(p.id);
	  	document.write("<a href='javascript:change(\"");
  		document.write(p.id);
  		document.write("\")' onMouseOver='over(\"");
  		document.write(p.id);
  		document.write("\")' onMouseOut='out(\"");
 	 	document.write(p.id);
  		document.write("\")' ><img name=\"")
  		document.write(cid);
  		document.write("\" src=\"");
  		if (p.on) {
   		 	document.write(selectedImage);
		} else {
     		//if it is not in this portfolio...
			document.write(normalImage);
		}
		document.write("\" border=0 width=\"17\" height=\"11\"></a>");
 	}
}

function setCurrentPortfolio(id) {
    loadXMLDoc('/portfolios/setCurrent?id=' + id, setCurrentPortfolioInDocument);
}

function setCurrentPortfolioInDocument() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status != 200) {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
        else {
          var currentPortfolioItems = req.responseText;
          d.currentPortfolioItems = currentPortfolioItems;
          for (var i = 0; i < portfolioControls.length; i++) {
            var p = portfolioControls[i];
            p.on = d.currentPortfolioItems.indexOf(p.id) > -1;
  			var cid=cleanId(p.id);
            if(p.on) {
    			document.images[cid].src = selectedImage;
            }
            else {
    			document.images[cid].src = normalImage;
            }
          }
        }
    }
}

var ratings = new Ratings();

function Ratings() {
  this.text = new Array();
  this.none = 256;
  this.best = 3;
  this.worst = -3;
  this.text[3]  = "+++";
  this.text[2]  = "++";
  this.text[1]  = "+";
  this.text[0]  = "+/-";
  this.text[-1] = "-";
  this.text[-2] = "--";
  this.text[-3] = "---";
  this.text[this.none] = "";
  return this;
}


//Display a rating for an asset at the current position.
//String id  the asset this rating refers to
//int rating the rating assigned to this asset
//String status one of
// "invisible" => neither input nor output are possible
// "readonly" => visible output but no input is possible
// othervise  => visible output and a control to create an input
function ratingControl(id, rating) {
	document.write("<select name\"_\" title=\"Geben Sie hier an, wie nützlich diese Information für Sie persönlich ist\" onChange=\"javascript:changeRating('" + id + "', this.value);\">");
	for (var i=ratings.none; i>=ratings.worst; i = (i==ratings.none) ? ratings.best : i-1) {
		document.write("<option value=\"" + i + "\""); 
		if (i==rating) {
			document.write(" selected");
		} 
		document.write(">" + ratings.text[i] + "</option>");
	}
	document.write("</select>");
}

function changeRating(id, value) {
    loadXMLDoc('/ratings/change?id=' + id + '&value=' + value, changeRatingAction);
}

function changeRatingAction() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status != 200) {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}

/*	##############################################################
		Author:		Gina Mako, 
		Date:			01.02.2004
		Purpose:	extending of rankingControl function
							because of the underlined table headers
		##############################################################
*/
	function sortControl(self, ranking, direction, description, href) 
	{
		var imagePath = "";
		if (self==ranking) 
		{
			if (direction == "desc") 
			{ 
				//0=ascending
				imagePath = "ic_arrow_top.gif";
			} 
			else //if ("false"==direction) 
			{
				imagePath = "ic_arrow_down.gif";
			} //if ("false"==direction) 

			document.write(
												"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"
											+		"<tr>"
											+			"<td>"	
											+				"<b><a href=\"" + href +  "\" class=\"ranking\">" + description + "</A></b>"
											+			"</td>"
											+			"<td>"
											+				"<img src=\"/skin/images/icons/" + imagePath + "\" width=\"14\" height=\"14\" hspace=\"3\">"
											+			"</td>"
											+		"</tr>"
											+	"</table>"
										);
		} // if (self==ranking) 
		else // if (self==ranking)
		{
			document.write("<b><a href=\"" + href +  "\" class=\"header\">" + description + "</A></b>");
		} // if (self==ranking)

	} //function sortControl(self, ranking, direction, description, href) 
//	##############################################################

function checkCharacters(elem){
  var allowedChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for (var i = 0; i < elem.value.length; i++) {
  	if (allowedChars.indexOf(elem.value.charAt(i)) == -1) {
	 elem.value = "";
  	alert ("Die Weblog-Adresse darf nur Buchstaben und Ziffern enthalten.");
  	return false;
  	}
  }
}

function checkFloat(v) {
  if (isNaN(v)) {
	  return "Bitte hier eine Zahl (evtl. mit Dezimalpunkt) eingeben"
  }
  return null
}
function checkMonth(v) {
  if (isNaN(v) ||
     (parseInt(v) > 12) ||
     (parseInt(v) < 1)) {
	  return "Bitte hier einen Monat als Zahl zwischen 1 und 12 eingeben"
	}
	return null;
}

function checkYear(v) {
  if (isNaN(v) ||
	   (parseInt(v) < 1900) ||
	   (parseInt(v) > 2300)) {
		return "Bitte hier ein Jahr als Zahl zwischen 1900 und 2300 eingeben"
   }
   return null
}

function checkDate(v) {  //#RM: modified because parseInt does not work properly for numbers starting with 0, e.g. 08
   if ((v.length != 10) ||
		   (v.charAt(4)!='-') ||
			 (v.charAt(7)!='-') ||
       isNaN(v.substring(0,4)) ||
			 isNaN(v.substring(5,7)) ||
			 isNaN(v.substring(8,10)))
	   return "Bitte hier ein Datum exakt im Format JJJJ-MM-TT eingeben"
	 if(v.substring(5,6) == "0")
		 month =  v.substring(6,7)
	 else
		 month =  v.substring(5,7)
	 if(v.substring(8,9) == "0")
		 day =  v.substring(9,10)
	 else
		 day =  v.substring(8,10)
	 if ((parseInt(month)  > 12) ||
	     (parseInt(month) < 1) ||
	     (parseInt(day)> 31) ||
	     (parseInt(day)< 1) ) {
		 return "Bitte hier ein Datum exakt im Format JJJJ-MM-TT eingeben"
   }
   return null
}
function checkEuropeanDate(v) { 
    if(v.length == 0) return null;
	  if ((v.length != 10) ||
		   (v.charAt(2)!='-') ||
			 (v.charAt(5)!='-') ||
       isNaN(v.substring(0,2)) ||
			 isNaN(v.substring(3,5)) ||
			 isNaN(v.substring(6,10)))
	   return "Bitte hier ein Datum exakt im Format TT-MM-JJJJ eingeben"
	 if(v.substring(3,4) == "0") 
		 month =  v.substring(4,5)
	 else		
		 month =  v.substring(3,5)
	 if(v.substring(0,1) == "0") 
		 day =  v.substring(1,2)
	 else		
		 day =  v.substring(0,2)
	 if ((parseInt(month)  > 12) || 
	     (parseInt(month) < 1) || 
	     (parseInt(day)> 31) ||
	     (parseInt(day)< 1) ) {
		 return "Bitte hier ein Datum exakt im Format TT-MM-JJJJ eingeben"
   }
   return null
}

function checkEuropeanDate2(v,expiry) {  //#RM: modified because parseInt does not work properly for numbers starting with 0, e.g. 08
    if(v.length == 0) return null;
	  if ((v.length != 10) ||
		   (v.charAt(2)!='.') ||
			 (v.charAt(5)!='.') ||
       isNaN(v.substring(0,2)) ||
			 isNaN(v.substring(3,5)) ||
			 isNaN(v.substring(6,10)))
	   return "Bitte hier ein Datum exakt im Format TT.MM.JJJJ eingeben"
	 if(v.substring(3,4) == "0") 
		 month =  v.substring(4,5)
	 else		
		 month =  v.substring(3,5)
	 if(v.substring(0,1) == "0") 
		 day =  v.substring(1,2)
	 else		
		 day =  v.substring(0,2)
	 if ((parseInt(month)  > 12) || 
	     (parseInt(month) < 1) || 
	     (parseInt(day)> 31) ||
	     (parseInt(day)< 1) ) {
		 return "Bitte hier ein Datum exakt im Format TT.MM.JJJJ eingeben"
   }
		else {
			if(expiry !=null){
		if(expiry.value==null || expiry.value.length<10)
			expiry.value = v ;	
			}
   }
   return null
}

function checkNumber(v) {
 if(isNaN(v))
	return "Bitte eine ganze Zahl eingeben";
return null;
}

//Constraint is a string of the following syntax:
//[optional](float|month|year|date)
function changeValue(t, constraint,expiry){
  var error = null
	if ((constraint!=null) &&
	   (constraint.indexOf("optional")==0) &&
      ((t.value==null)||t.value=="")) {
	  // dont check empty optional fields
	} else {
	  if(constraint != null){ //only if there is constraint
	    if (constraint.indexOf("num")!=-1) error = checkNumber(t.value)
	    if (constraint.indexOf("float")!=-1) error = checkFloat(t.value)
	    if (constraint.indexOf("month")!=-1) error = checkMonth(t.value)
  	  if (constraint.indexOf("year")!=-1) error = checkYear(t.value)
  	  if (constraint.indexOf("date")!=-1) error = checkDate(t.value)
  	  if (constraint.indexOf("edate")!=-1) error = checkEuropeanDate(t.value)
  	  if (constraint.indexOf("edate2")!=-1) error = checkEuropeanDate2(t.value,expiry)
		}
	}
	if (error) {
    alert(error)
		t.value=t.defaultValue
    t.focus()
    return false
 }
 if ((t.form.changes.value.indexOf(t.name) < 0) && (t.value != t.defaultValue)) {
   t.form.changes.value += t.name;
 }
 return true
}

// back to last visited page
function returnBack() {
  var name = navigator.appName
  if (name == "Microsoft Internet Explorer")
    location.href = "javascript:history.back()";
   else
    location.href = "javascript:window.back()";
}

function encodeURL(url){
  var newUrl = "";
   for (var i=0 ; i<url.length; i++){
 c=url.charAt(i);
 newUrl += this.encodetab[c];
   }
  return newUrl;
}

function URLEncoder(){
  this.encodetab = new Array(256)
  this.encodetab["\x00"] ="%00"
  this.encodetab["\x01"] ="%01"
  this.encodetab["\x02"] ="%02"
  this.encodetab["\x03"] ="%03"
  this.encodetab["\x04"] ="%04"
  this.encodetab["\x05"] ="%05"
  this.encodetab["\x06"] ="%06"
  this.encodetab["\x07"] ="%07"
  this.encodetab["\x08"] ="%08"
  this.encodetab["\x09"] ="%09"
  this.encodetab["\x0A"] ="%0A"
  this.encodetab["\x0B"] ="%0B"
  this.encodetab["\x0C"] ="%0C"
  this.encodetab["\x0D"] ="%0D"
  this.encodetab["\x0E"] ="%0E"
  this.encodetab["\x0F"] ="%0F"
  this.encodetab["\x10"] ="%10"
  this.encodetab["\x11"] ="%11"
  this.encodetab["\x12"] ="%12"
  this.encodetab["\x13"] ="%13"
  this.encodetab["\x14"] ="%14"
  this.encodetab["\x15"] ="%15"
  this.encodetab["\x16"] ="%16"
  this.encodetab["\x17"] ="%17"
  this.encodetab["\x18"] ="%18"
  this.encodetab["\x19"] ="%19"
  this.encodetab["\x1A"] ="%1A"
  this.encodetab["\x1B"] ="%1B"
  this.encodetab["\x1C"] ="%1C"
  this.encodetab["\x1D"] ="%1D"
  this.encodetab["\x1E"] ="%1E"
  this.encodetab["\x1F"] ="%1F"
  this.encodetab["\x20"] ="+"
  this.encodetab["\x21"] ="%21"
  this.encodetab["\x22"] ="%22"
  this.encodetab["\x23"] ="%23"
  this.encodetab["\x24"] ="%24"
  this.encodetab["\x25"] ="%25"
  this.encodetab["\x26"] ="%26"
  this.encodetab["\x27"] ="%27"
  this.encodetab["\x28"] ="%28"
  this.encodetab["\x29"] ="%29"
  this.encodetab["\x2A"] ="*"
  this.encodetab["\x2B"] ="%2B"
  this.encodetab["\x2C"] ="%2C"
  this.encodetab["\x2D"] ="-"
  this.encodetab["\x2E"] ="."
  this.encodetab["\x2F"] ="%2F"
  this.encodetab["\x30"] ="0"
  this.encodetab["\x31"] ="1"
  this.encodetab["\x32"] ="2"
  this.encodetab["\x33"] ="3"
  this.encodetab["\x34"] ="4"
  this.encodetab["\x35"] ="5"
  this.encodetab["\x36"] ="6"
  this.encodetab["\x37"] ="7"
  this.encodetab["\x38"] ="8"
  this.encodetab["\x39"] ="9"
  this.encodetab["\x3A"] ="%3A"
  this.encodetab["\x3B"] ="%3B"
  this.encodetab["\x3C"] ="%3C"
  this.encodetab["\x3D"] ="%3D"
  this.encodetab["\x3E"] ="%3E"
  this.encodetab["\x3F"] ="%3F"
  this.encodetab["\x40"] ="%40"
  this.encodetab["\x41"] ="A"
  this.encodetab["\x42"] ="B"
  this.encodetab["\x43"] ="C"
  this.encodetab["\x44"] ="D"
  this.encodetab["\x45"] ="E"
  this.encodetab["\x46"] ="F"
  this.encodetab["\x47"] ="G"
  this.encodetab["\x48"] ="H"
  this.encodetab["\x49"] ="I"
  this.encodetab["\x4A"] ="J"
  this.encodetab["\x4B"] ="K"
  this.encodetab["\x4C"] ="L"
  this.encodetab["\x4D"] ="M"
  this.encodetab["\x4E"] ="N"
  this.encodetab["\x4F"] ="O"
  this.encodetab["\x50"] ="P"
  this.encodetab["\x51"] ="Q"
  this.encodetab["\x52"] ="R"
  this.encodetab["\x53"] ="S"
  this.encodetab["\x54"] ="T"
  this.encodetab["\x55"] ="U"
  this.encodetab["\x56"] ="V"
  this.encodetab["\x57"] ="W"
  this.encodetab["\x58"] ="X"
  this.encodetab["\x59"] ="Y"
  this.encodetab["\x5A"] ="Z"
  this.encodetab["\x5B"] ="%5B"
  this.encodetab["\x5C"] ="%5C"
  this.encodetab["\x5D"] ="%5D"
  this.encodetab["\x5E"] ="%5E"
  this.encodetab["\x5F"] ="_"
  this.encodetab["\x60"] ="%60"
  this.encodetab["\x61"] ="a"
  this.encodetab["\x62"] ="b"
  this.encodetab["\x63"] ="c"
  this.encodetab["\x64"] ="d"
  this.encodetab["\x65"] ="e"
  this.encodetab["\x66"] ="f"
  this.encodetab["\x67"] ="g"
  this.encodetab["\x68"] ="h"
  this.encodetab["\x69"] ="i"
  this.encodetab["\x6A"] ="j"
  this.encodetab["\x6B"] ="k"
  this.encodetab["\x6C"] ="l"
  this.encodetab["\x6D"] ="m"
  this.encodetab["\x6E"] ="n"
  this.encodetab["\x6F"] ="o"
  this.encodetab["\x70"] ="p"
  this.encodetab["\x71"] ="q"
  this.encodetab["\x72"] ="r"
  this.encodetab["\x73"] ="s"
  this.encodetab["\x74"] ="t"
  this.encodetab["\x75"] ="u"
  this.encodetab["\x76"] ="v"
  this.encodetab["\x77"] ="w"
  this.encodetab["\x78"] ="x"
  this.encodetab["\x79"] ="y"
  this.encodetab["\x7A"] ="z"
  this.encodetab["\x7B"] ="%7B"
  this.encodetab["\x7C"] ="%7C"
  this.encodetab["\x7D"] ="%7D"
  this.encodetab["\x7E"] ="%7E"
  this.encodetab["\x7F"] ="%7F"
  this.encodetab["\x80"] ="%80"
  this.encodetab["\x81"] ="%81"
  this.encodetab["\x82"] ="%82"
  this.encodetab["\x83"] ="%83"
  this.encodetab["\x84"] ="%84"
  this.encodetab["\x85"] ="%85"
  this.encodetab["\x86"] ="%86"
  this.encodetab["\x87"] ="%87"
  this.encodetab["\x88"] ="%88"
  this.encodetab["\x89"] ="%89"
  this.encodetab["\x8A"] ="%8A"
  this.encodetab["\x8B"] ="%8B"
  this.encodetab["\x8C"] ="%8C"
  this.encodetab["\x8D"] ="%8D"
  this.encodetab["\x8E"] ="%8E"
  this.encodetab["\x8F"] ="%8F"
  this.encodetab["\x90"] ="%90"
  this.encodetab["\x91"] ="%91"
  this.encodetab["\x92"] ="%92"
  this.encodetab["\x93"] ="%93"
  this.encodetab["\x94"] ="%94"
  this.encodetab["\x95"] ="%95"

  this.encodetab["\x96"] ="%96"
  this.encodetab["\x97"] ="%97"
  this.encodetab["\x98"] ="%98"
  this.encodetab["\x99"] ="%99"
  this.encodetab["\x9A"] ="%9A"
  this.encodetab["\x9B"] ="%9B"
  this.encodetab["\x9C"] ="%9C"
  this.encodetab["\x9D"] ="%9D"
  this.encodetab["\x9E"] ="%9E"
  this.encodetab["\x9F"] ="%9F"
  this.encodetab["\xA0"] ="%A0"
  this.encodetab["\xA1"] ="%A1"
  this.encodetab["\xA2"] ="%A2"
  this.encodetab["\xA3"] ="%A3"
  this.encodetab["\xA4"] ="%A4"
  this.encodetab["\xA5"] ="%A5"
  this.encodetab["\xA6"] ="%A6"
  this.encodetab["\xA7"] ="%A7"
  this.encodetab["\xA8"] ="%A8"
  this.encodetab["\xA9"] ="%A9"
  this.encodetab["\xAA"] ="%AA"
  this.encodetab["\xAB"] ="%AB"
  this.encodetab["\xAC"] ="%AC"
  this.encodetab["\xAD"] ="%AD"
  this.encodetab["\xAE"] ="%AE"
  this.encodetab["\xAF"] ="%AF"
  this.encodetab["\xB0"] ="%B0"
  this.encodetab["\xB1"] ="%B1"
  this.encodetab["\xB2"] ="%B2"
  this.encodetab["\xB3"] ="%B3"
  this.encodetab["\xB4"] ="%B4"
  this.encodetab["\xB5"] ="%B5"
  this.encodetab["\xB6"] ="%B6"
  this.encodetab["\xB7"] ="%B7"
  this.encodetab["\xB8"] ="%B8"
  this.encodetab["\xB9"] ="%B9"
  this.encodetab["\xBA"] ="%BA"
  this.encodetab["\xBB"] ="%BB"
  this.encodetab["\xBC"] ="%BC"
  this.encodetab["\xBD"] ="%BD"
  this.encodetab["\xBE"] ="%BE"
  this.encodetab["\xBF"] ="%BF"
  this.encodetab["\xC0"] ="%C0"
  this.encodetab["\xC1"] ="%C1"
  this.encodetab["\xC2"] ="%C2"
  this.encodetab["\xC3"] ="%C3"
  this.encodetab["\xC4"] ="%C4"
  this.encodetab["\xC5"] ="%C5"
  this.encodetab["\xC6"] ="%C6"
  this.encodetab["\xC7"] ="%C7"
  this.encodetab["\xC8"] ="%C8"
  this.encodetab["\xC9"] ="%C9"
  this.encodetab["\xCA"] ="%CA"
  this.encodetab["\xCB"] ="%CB"
  this.encodetab["\xCC"] ="%CC"
  this.encodetab["\xCD"] ="%CD"
  this.encodetab["\xCE"] ="%CE"
  this.encodetab["\xCF"] ="%CF"
  this.encodetab["\xD0"] ="%D0"
  this.encodetab["\xD1"] ="%D1"
  this.encodetab["\xD2"] ="%D2"
  this.encodetab["\xD3"] ="%D3"
  this.encodetab["\xD4"] ="%D4"
  this.encodetab["\xD5"] ="%D5"
  this.encodetab["\xD6"] ="%D6"
  this.encodetab["\xD7"] ="%D7"
  this.encodetab["\xD8"] ="%D8"
  this.encodetab["\xD9"] ="%D9"
  this.encodetab["\xDA"] ="%DA"
  this.encodetab["\xDB"] ="%DB"
  this.encodetab["\xDC"] ="%DC"
  this.encodetab["\xDD"] ="%DD"
  this.encodetab["\xDE"] ="%DE"
  this.encodetab["\xDF"] ="%DF"
  this.encodetab["\xE0"] ="%E0"
  this.encodetab["\xE1"] ="%E1"
  this.encodetab["\xE2"] ="%E2"
  this.encodetab["\xE3"] ="%E3"
  this.encodetab["\xE4"] ="%E4"
  this.encodetab["\xE5"] ="%E5"
  this.encodetab["\xE6"] ="%E6"
  this.encodetab["\xE7"] ="%E7"
  this.encodetab["\xE8"] ="%E8"
  this.encodetab["\xE9"] ="%E9"
  this.encodetab["\xEA"] ="%EA"
  this.encodetab["\xEB"] ="%EB"
  this.encodetab["\xEC"] ="%EC"
  this.encodetab["\xED"] ="%ED"
  this.encodetab["\xEE"] ="%EE"
  this.encodetab["\xEF"] ="%EF"
  this.encodetab["\xF0"] ="%F0"
  this.encodetab["\xF1"] ="%F1"
  this.encodetab["\xF2"] ="%F2"
  this.encodetab["\xF3"] ="%F3"
  this.encodetab["\xF4"] ="%F4"
  this.encodetab["\xF5"] ="%F5"
  this.encodetab["\xF6"] ="%F6"
  this.encodetab["\xF7"] ="%F7"
  this.encodetab["\xF8"] ="%F8"
  this.encodetab["\xF9"] ="%F9"
  this.encodetab["\xFA"] ="%FA"
  this.encodetab["\xFB"] ="%FB"
  this.encodetab["\xFC"] ="%FC"
  this.encodetab["\xFD"] ="%FD"
  this.encodetab["\xFE"] ="%FE"
  this.encodetab["\xFF"] ="%FF"
  this.encode=encodeURL
  return this
}

/* POPUP */
//function winopen (url,ext_x,ext_y) {
function popUp (url) {
	/*ext_x = (screen.width/5)*4;
	ext_y = (screen.height/5)*3;*/

	ext_x = 500; //530
	ext_y = 420;
	if (ext_y >= screen.height) {
		ext_y = (screen.height/5)*2;
	}
	if (ext_x >= screen.width) {
		ext_x = (screen.width/5)*3;
	}
	win=window.open(url,"Preview","toolbar=no,location=no,explorer=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,left=50,top=50,width="+ext_x+",height="+ext_y);

	if ((navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 3) ||
    	(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4)) { 
  		win.moveTo((screen.width/2)-(ext_x/2),(screen.height/3)-(ext_y/3));
  		win.focus();
  	} 
}

// Method for Images Popup's
function image_popup(pfad, width, height, title) {
 fenster = window.open("", "fenster", "width="+width+", height="+height);
 with(fenster.document) {
   write('<html>');
   write('<head><title>' + title + '</title></head>');
   write('<body style="margin:0" oncontextmenu="return false;">');
   write('<img src="'+pfad+'" />');
   write('</body></html>');
 }
 fenster.focus();
}

function popupImageEditor(imageIds, title, finalDestination, next) {
	var imageIdParameters = "";
	for(var i=0; i<imageIds.length;++i) {
		imageIdParameters += "&imageId="+imageIds[i];
	}
	window.open("/imageClips/showEditImage?finalDestination="+finalDestination+"&titleMessage=" + title+"&next=" + next + imageIdParameters, "uploadExtraWin", "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=560,height=450,left=262,top=184");
}

function liste_unterknoten (knoten) {
    var ausgabe;
    ausgabe = '<li>';
    switch (knoten.nodeType) {
        case 1 :
            ausgabe += '<strong>' + knoten.nodeName + '<\/strong>-Element';
            if (knoten.hasChildNodes()) {
                ausgabe += ', ' + knoten.childNodes.length + ' Unterknoten';
            }
            break;
        case 3 :
            var knotenwert = knoten.nodeValue.replace(/</g, '&lt;').replace(/\n/g, '\\n');
            ausgabe += 'Textknoten: [<strong>' + knotenwert + '<\/strong>]';
            break;
        case 8 :
            var knotenwert = knoten.nodeValue.replace(/</g, '&lt;').replace(/\n/g, '\\n');
            ausgabe += 'Kommentarknoten: [' + knotenwert + ']';
            break;
        default :
            ausgabe += 'Knoten des Typs ' + knoten.nodeType +
                ', Wert: [' + knoten.nodeValue + ']';
    }
    if (knoten.hasChildNodes()) {
        ausgabe += '\n<ol>\n';
        for (var i = 0; i < knoten.childNodes.length; i++) {
            knotenneu = knoten.childNodes[i];
            ausgabe += liste_unterknoten(knotenneu); // Rekursion
        }
        ausgabe += '</ol>\n';
    }
    ausgabe += '</li>\n';
    return ausgabe;
}



function leaveForm(formName) {
	//alert("leaveForm");
	var changes = "";
	var encoder = new URLEncoder();
	if(formName == null) {
		alert("formName cannot be null");
		return;
	}
	var form = document.forms[formName];
	if(form == null) {
		alert("there is no form with name " + formName);
		return;
	}
	var isGet = form.method == "get";
	if(isGet) {
		alert("error: form " + formName + " has to be a POST form");
		return;
	}
	for (var j=0; j<form.elements.length; ++j) {
		if(form.elements[j].value != null) {
			var child = form.elements[j];
			if(child.type == "select-multiple") {
				var length = child.options.length;
				for(var i=0; i<length; i++) {
					var name = child.options[i].text;
   	    			changes += "&" + child.name + "_" + i + "_name=" + encoder.encode(name);
					var id = child.options[i].value;
   	    			changes += "&" + child.name + "_" + i + "_id=" + encoder.encode(id);
				}
			}
		}
   	}
	if(changes != null) {
		var value;
		if(form.selectMultiples != null) {
			value = "";
			form.selectMultiples.value = changes;
		}
		else {
			value = form.action;		
		}
		if((value.indexOf("?")==-1) && (changes.length > 0)) {
			changes = changes.substring(1);
			changes = "?" + changes;
		}
		value += changes;
		if(form.selectMultiples != null) {
			form.selectMultiples.value = value;
			//alert("selectMultiples: " + form.selectMultiples.value);
		}
		else {
			form.action = value;
			//alert("action: " + form.action);
		}
	}
	form.submit();
}

function show(href) {
	document.location.href = href;
}

function requestLogin(login, passwd, nonce) {
	//alert(login + " " + passwd + " " + nonce);
	var digest = MD5(login + passwd + nonce);
    document.location.href = '/myPortal/login?digest=' + digest + "&loginFormemail1=" + login+"&loginFormpassword="+passwd;
}

function logoff() {
    document.location.href = '/myPortal/logoff';
}

function currentPortfolio() {
    document.location.href = "/portfolios/current";
}

var req;

function loadXMLDoc(url, processReqChange) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

//-- MD5 Algorithm

/*
 *  md5.jvs 1.0b 27/06/96
 *
 * Javascript implementation of the RSA Data Security, Inc. MD5
 * Message-Digest Algorithm.
 *
 * Copyright (c) 1996 Henri Torgemane. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for any purposes and without
 * fee is hereby granted provided that this copyright notice
 * appears in all copies.
 *
 * Of course, this soft is provided "as is" without express or implied
 * warranty of any kind.
 *
 * $Id: md5.js,v 1.1.1.1 2000/04/17 16:40:07 kk Exp $
 *
 */



function array(n) {
  for(i=0;i<n;i++) this[i]=0;
  this.length=n;
}

/* Some basic logical functions had to be rewritten because of a bug in
 * Javascript.. Just try to compute 0xffffffff >> 4 with it..
 * Of course, these functions are slower than the original would be, but
 * at least, they work!
 */

function integer(n) { return n%(0xffffffff+1); }

function shr(a,b) {
  a=integer(a);
  b=integer(b);
  if (a-0x80000000>=0) {
    a=a%0x80000000;
    a>>=b;
    a+=0x40000000>>(b-1);
  } else
    a>>=b;
  return a;
}

function shl1(a) {
  a=a%0x80000000;
  if (a&0x40000000==0x40000000)
  {
    a-=0x40000000;
    a*=2;
    a+=0x80000000;
  } else
    a*=2;
  return a;
}

function shl(a,b) {
  a=integer(a);
  b=integer(b);
  for (var i=0;i<b;i++) a=shl1(a);
  return a;
}

function and(a,b) {
  a=integer(a);
  b=integer(b);
  var t1=(a-0x80000000);
  var t2=(b-0x80000000);
  if (t1>=0)
    if (t2>=0)
      return ((t1&t2)+0x80000000);
    else
      return (t1&b);
  else
    if (t2>=0)
      return (a&t2);
    else
      return (a&b);
}

function or(a,b) {
  a=integer(a);
  b=integer(b);
  var t1=(a-0x80000000);
  var t2=(b-0x80000000);
  if (t1>=0)
    if (t2>=0)
      return ((t1|t2)+0x80000000);
    else
      return ((t1|b)+0x80000000);
  else
    if (t2>=0)
      return ((a|t2)+0x80000000);
    else
      return (a|b);
}

function xor(a,b) {
  a=integer(a);
  b=integer(b);
  var t1=(a-0x80000000);
  var t2=(b-0x80000000);
  if (t1>=0)
    if (t2>=0)
      return (t1^t2);
    else
      return ((t1^b)+0x80000000);
  else
    if (t2>=0)
      return ((a^t2)+0x80000000);
    else
      return (a^b);
}

function not(a) {
  a=integer(a);
  return (0xffffffff-a);
}

// Here begin the real algorithm

    var state = new array(4);
    var count = new array(2);
    var buffer = new array(64);
    var transformBuffer = new array(16);
    var digestBits = new array(16);

    var S11 = 7;
    var S12 = 12;
    var S13 = 17;
    var S14 = 22;
    var S21 = 5;
    var S22 = 9;
    var S23 = 14;
    var S24 = 20;
    var S31 = 4;
    var S32 = 11;
    var S33 = 16;
    var S34 = 23;
    var S41 = 6;
    var S42 = 10;
    var S43 = 15;
    var S44 = 21;

    function F(x,y,z) {
	return or(and(x,y),and(not(x),z));
    }

    function G(x,y,z) {
	return or(and(x,z),and(y,not(z)));
    }

    function H(x,y,z) {
	return xor(xor(x,y),z);
    }

    function I(x,y,z) {
	return xor(y ,or(x , not(z)));
    }

    function rotateLeft(a,n) {
	return or(shl(a, n),(shr(a,(32 - n))));
    }

    function FF(a,b,c,d,x,s,ac) {
        a = a+F(b, c, d) + x + ac;
	a = rotateLeft(a, s);
	a = a+b;
	return a;
    }

    function GG(a,b,c,d,x,s,ac) {
	a = a+G(b, c, d) +x + ac;
	a = rotateLeft(a, s);
	a = a+b;
	return a;
    }

    function HH(a,b,c,d,x,s,ac) {
	a = a+H(b, c, d) + x + ac;
	a = rotateLeft(a, s);
	a = a+b;
	return a;
    }

    function II(a,b,c,d,x,s,ac) {
	a = a+I(b, c, d) + x + ac;
	a = rotateLeft(a, s);
	a = a+b;
	return a;
    }

    function transform(buf,offset) {
	var a=0, b=0, c=0, d=0;
	var x = transformBuffer;

	a = state[0];
	b = state[1];
	c = state[2];
	d = state[3];

	for (i = 0; i < 16; i++) {
	    x[i] = and(buf[i*4+offset],0xff);
	    for (j = 1; j < 4; j++) {
		x[i]+=shl(and(buf[i*4+j+offset] ,0xff), j * 8);
	    }
	}

	// Round 1
	a = FF ( a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
	d = FF ( d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
	c = FF ( c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
	b = FF ( b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
	a = FF ( a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
	d = FF ( d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
	c = FF ( c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
	b = FF ( b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
	a = FF ( a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
	d = FF ( d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
	c = FF ( c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
	b = FF ( b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
	a = FF ( a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
	d = FF ( d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
	c = FF ( c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
	b = FF ( b, c, d, a, x[15], S14, 0x49b40821); /* 16 */

	// Round 2
	a = GG ( a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
	d = GG ( d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
	c = GG ( c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
	b = GG ( b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
	a = GG ( a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
	d = GG ( d, a, b, c, x[10], S22,  0x2441453); /* 22 */
	c = GG ( c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
	b = GG ( b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
	a = GG ( a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
	d = GG ( d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
	c = GG ( c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
	b = GG ( b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
	a = GG ( a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
	d = GG ( d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
	c = GG ( c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
	b = GG ( b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */

	// Round 3
	a = HH ( a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
	d = HH ( d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
	c = HH ( c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
	b = HH ( b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
	a = HH ( a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
	d = HH ( d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
	c = HH ( c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
	b = HH ( b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
	a = HH ( a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
	d = HH ( d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
	c = HH ( c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
	b = HH ( b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
	a = HH ( a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
	d = HH ( d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
	c = HH ( c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
	b = HH ( b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */

	// Round 4
	a = II ( a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
	d = II ( d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
	c = II ( c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
	b = II ( b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
	a = II ( a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
	d = II ( d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
	c = II ( c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
	b = II ( b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
	a = II ( a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
	d = II ( d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
	c = II ( c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
	b = II ( b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
	a = II ( a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
	d = II ( d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
	c = II ( c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
	b = II ( b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */

	state[0] +=a;
	state[1] +=b;
	state[2] +=c;
	state[3] +=d;

    }

    function init() {
	count[0]=count[1] = 0;
	state[0] = 0x67452301;
	state[1] = 0xefcdab89;
	state[2] = 0x98badcfe;
	state[3] = 0x10325476;
	for (i = 0; i < digestBits.length; i++)
	    digestBits[i] = 0;
    }

    function update(b) {
	var index,i;

	index = and(shr(count[0],3) , 0x3f);
	if (count[0]<0xffffffff-7)
	  count[0] += 8;
        else {
	  count[1]++;
	  count[0]-=0xffffffff+1;
          count[0]+=8;
        }
	buffer[index] = and(b,0xff);
	if (index  >= 63) {
	    transform(buffer, 0);
	}
    }

    function finish() {
	var bits = new array(8);
	var	padding;
	var	i=0, index=0, padLen=0;

	for (i = 0; i < 4; i++) {
	    bits[i] = and(shr(count[0],(i * 8)), 0xff);
	}
        for (i = 0; i < 4; i++) {
	    bits[i+4]=and(shr(count[1],(i * 8)), 0xff);
	}
	index = and(shr(count[0], 3) ,0x3f);
	padLen = (index < 56) ? (56 - index) : (120 - index);
	padding = new array(64);
	padding[0] = 0x80;
        for (i=0;i<padLen;i++)
	  update(padding[i]);
        for (i=0;i<8;i++)
	  update(bits[i]);

	for (i = 0; i < 4; i++) {
	    for (j = 0; j < 4; j++) {
		digestBits[i*4+j] = and(shr(state[i], (j * 8)) , 0xff);
	    }
	}
    }

function hexa(n) {
 var hexa_h = "0123456789abcdef";
 var hexa_c="";
 var hexa_m=n;
 for (hexa_i=0;hexa_i<8;hexa_i++) {
   hexa_c=hexa_h.charAt(Math.abs(hexa_m)%16)+hexa_c;
   hexa_m=Math.floor(hexa_m/16);
 }
 return hexa_c;
}


var ascii="01234567890123456789012345678901" +
          " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
          "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

function MD5(entree)
{
 var l,s,k,ka,kb,kc,kd;

 init();
 for (k=0;k<entree.length;k++) {
   l=entree.charAt(k);
   update(ascii.lastIndexOf(l));
 }
 finish();
 ka=kb=kc=kd=0;
 for (i=0;i<4;i++) ka+=shl(digestBits[15-i], (i*8));
 for (i=4;i<8;i++) kb+=shl(digestBits[15-i], ((i-4)*8));
 for (i=8;i<12;i++) kc+=shl(digestBits[15-i], ((i-8)*8));
 for (i=12;i<16;i++) kd+=shl(digestBits[15-i], ((i-12)*8));
 s=hexa(kd)+hexa(kc)+hexa(kb)+hexa(ka);
 return s;
}

// End of the MD5 algorithm

//##replace images by text

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var d = new Document();

// executeLoaded should is called in a frame-based design to make sure that
// the necessary frames are already there.
function executeLoaded(){
  	if (parent==null) {
  		var location = document.URL;
  		var lastIndex = location.lastIndexOf('/');
  		//alert("lastIndex: " + lastIndex);
  		var id = location.substr(lastIndex + 1, location.length);
  		//alert("id: " + id);
  		var locationWithoutId = location.substr(0, lastIndex);
  		var preLastIndex = locationWithoutId.lastIndexOf('/');
  		var area = locationWithoutId.substr(preLastIndex + 1, locationWithoutId.length);
	  	var brokerHost = locationWithoutId.substr(0, preLastIndex);
  		//alert("area: " + area);
  		var brokerUrl = area + "/" + id;
  		if(area == 'home') {
	  		alert("Beim Aufruf über Favoriten und nach dem Aktualisieren ist eine Neuanmeldung erforderlich");
  		    parent.location = parent.location;
  		}
  		else if(!(area == 'myPortal')) {
  			//alert("brokerHost: " + brokerHost);
	  		var redirectUrl = brokerHost + '/main.htm?t=' + brokerUrl;
	  		//alert("redirect to " + redirectUrl);
  			document.location = redirectUrl;
  		}
	}
}
