//=========================================
// I-Box parameters that can be overriden
//=========================================
 
// Speed for 'sliding effect'
var ibox_slide_timervalue = 35;

// Path to ibox images
var ibox_images_path = '/pics';

// Link/eProfile parameters
var ibox_link_parameters = new Array();
ibox_link_parameters["eProfile"] = "";
ibox_link_parameters["eProfileSecure"] = "";
ibox_link_parameters["PPID"] = "VW01";
ibox_link_parameters["RURL"] = document.location;
ibox_link_parameters["Template"] = "";



//=========================================
// I-Box public functions
//=========================================

/**
 * Returns the version number of the ibox implementation.
 */
function ibox_getversion() {
  return "1.1.11";
}

/**
 * Initialized the ibox and places it on the positoin where this function is executed (but invisble).
 * @param pMode I-Box mode ('default' or 'home').
 * @param pData JavaScript object containing all link data for the ibox.
 * @param pPageID PageID of the current page (optional).
 */
function ibox_init(pMode, pData, pPageID) {
	 
  ibox_internal_mode = pMode;
  ibox_internal_PageID = pPageID;
  
  if (pMode=="home") {
    ibox_internal_closetabheight_initialvalue = 183;
    ibox_internal_renderibox_home(pData);
  }
  else if(pMode=="default"){
    ibox_internal_closetabheight_initialvalue = 183;
    ibox_internal_renderibox_default(pData);
  } 
  else if(pMode=="reduced"){
    ibox_internal_closetabheight_initialvalue = 183;
	  ibox_internal_renderibox_reduced(pData);
  }
  

  
}

/**
 * Displays the I-Box.
 * @param pTabID Name of the Tab to open initially (optional, the first is opened if none specified).
 *   Avaiable tab names: 'login', 'konfigurator', 'dialogcenter', 'news_events', 'myvolkswagen'.
 */
function ibox_display(pTabID) {
  if (!pTabID || pTabID=="") {
    pTabID = ibox_internal_getCookie("vwcms_ibox_selectedtab");
    if (!pTabID || pTabID=="") {
			pTabID = ibox_internal_InitialTabID;
		}
  }
  ibox_internal_InitialTabID = pTabID;

  ibox_internal_initDisplayIBox("ibox_div_" + pTabID);

  document.getElementById("ibox_main").style.visibility = "visible";
	document.getElementById("ibox_main").style.display = "block";
}

/**
 * Sets the user information of a logged in eProfile user.
 * @param pEProfileUserInfo A valid ibox_eprofile_userinfo object or null if no user is logged in.
 */
function ibox_seteprofile_userinfo(pEProfileUserInfo) {
  ibox_internal_eprofile_userinfo = pEProfileUserInfo;
  ibox_internal_refresh_eprofile_userinfo();
}

/**
 * Returns the user information previously set by ibox_seteprofile_userinfo.
 */
function ibox_geteprofile_userinfo() {
  return ibox_internal_eprofile_userinfo;
}

/**
 * Sets a javascript callback method that should be called in every
 * case when the eprofile login information is changed.
 */
function ibox_seteprofile_userinfo_refresh_callback(pCallbackMethod) {
  ibox_internal_eprofile_userinfo_refresh_callback = pCallbackMethod;
}



//=========================================
// I-Box tab rendering - default mode
//=========================================

var ibox_internal_mode = null;
var ibox_internal_PageID = null;
var ibox_internal_InitialTabID = "login";
var ibox_internal_eprofile_userinfo = null;
var ibox_internal_eprofile_userinfo_refresh_callback = null;

function ibox_internal_renderibox_default(pData) {

  document.write('<div id="ibox_main" class="ibox" style="display:none;visibility:hidden;">');
	document.write('<div class="ibox_head"><img name="ibox_headline_image" id="ibox_headline_image" src="' + ibox_images_path + '/ibox_headline.gif" width="163" height="19" alt="Handelsbetreuung Schnellnavigation"></div>');
	
	
	// ----- Tab 'login' START -----
	ibox_internal_countTab('ibox_div_login');
	var tab_login = ibox_internal_gettab(pData, 'login');
	
	document.write('<div id="ibox_div_login" class="ibox_inactive"><a href="javaScript:ibox_internal_switchBox(\'ibox_div_login\')"><img onload="ibox_internal_createHiliteObj(this,\'' + ibox_images_path + '/ibox_login_over.gif\',this.src)" onmouseover="ibox_internal_showTabHigh(this)" onmouseout="ibox_internal_resetTabHigh(this)" src="' + ibox_images_path + '/ibox_login_off.gif" width="163" height="19" alt="Login"></a></div>');
	
	document.write('<div id="ibox_div_login_a" class="ibox_active" style="height:183px">');
	
	document.write('<img src="' + ibox_images_path + '/ibox_login_on.gif" width="163" height="19" alt="Login"><br>');
	
		
	// -- User not logged in --
	document.write('<div id="ibox_div_login_a_notloggedin" style="display:block;visibility:visible;">');
	ibox_internal_renderitem_form(tab_login, 'form_login_posturl', 'ibox_form_login');
	document.write('<input type="text" id="ibox_userid" name="userid" value="Benutzername" class="ibox_input_login" onfocus="select()" tabindex="8001"><br>');
	document.write('<table cellpadding="0" cellspacing="0" border="0" style="WIDTH: 100%;">');
	document.write('<tr style="VERTICAL-ALIGN: top;" valign="top">');
	document.write('<td><input type="password" id="ibox_passwd" name="passwd" class="ibox_input_pwd" onfocus="select()" onkeydown="ibox_internal_login_pwd_onkeydown()" tabindex="8002"></td>');
	document.write('<td><input type="image" src="' + ibox_images_path + '/but_login.gif" width="54" height="15" alt="Login" class="ibox_but_login" onclick="document.ibox_form_login.submit();" tabindex="8003"></td>');
	document.write('</tr>');
	document.write('</table>');
		
	document.write('</form>');
	
	document.write('<div class="ibox_line_inarea"></div>');
	
	document.write('<div class="ibox_txt_link">');
	ibox_internal_renderitem_link(tab_login, 'link_register');
	ibox_internal_renderitem_link(tab_login, 'link_passwordforgotten');
	ibox_internal_renderitem_link(tab_login, 'link_advantages');
	document.write('</div>');
	
	document.write('</div>');

	// -- User logged in --
	document.write('<div id="ibox_div_login_a_loggedin" style="display:none;visibility:hidden;">');
	
	document.write('<div id="ibox_div_login_username" class="ibox_name_log"></div>');
	
	document.write('<div class="ibox_line_inarea_log"></div>');

	document.write('<div class="ibox_txt_link">');
	ibox_internal_renderitem_link(tab_login, 'link_admin');
	document.write('</div>');	
	document.write('<div class="ibox_line_inarea_log"></div>');	
	document.write('<div class="ibox_txt"><strong>Hinweis</strong><br>Bitte melden Sie sich beim verlassen der Anwendung ordnungsgemäß ab.</div>');
	document.write('<div class="ibox_line_inarea_log"></div>');	
	document.write('<div class="ibox_txt_link">');	
	ibox_internal_renderitem_link(tab_login, 'link_logout');	document.write('</div>');
	document.write('</div>');
	// --
	

	document.write('</div>');
	// ----- Tab 'login' END -----

	document.write('<div class="ibox_line"></div>');
	
	
	// ----- Tab 'Suche' START -----
	ibox_internal_countTab('ibox_div_search');
	var tab_search = ibox_internal_gettab(pData, 'search');
	
	document.write('<div id="ibox_div_search" class="ibox_inactive"><a href="javaScript:ibox_internal_switchBox(\'ibox_div_search\')"><img  onload="ibox_internal_createHiliteObj(this,\'' + ibox_images_path + '/ibox_search_over.gif\',this.src)" onmouseover="ibox_internal_showTabHigh(this)" onmouseout="ibox_internal_resetTabHigh(this)" src="' + ibox_images_path + '/ibox_search_off.gif" width="163" height="19" alt="Beratung &amp; Kauf"></a></div>');
	
	document.write('<div id="ibox_div_search_a" class="ibox_active">');
	document.write('<img src="' + ibox_images_path + '/ibox_search_on.gif" width="163" height="19" alt="Beratung &amp; Kauf"><br>');
	
	document.write('<form name="ibox_form_search" action="search.php" method="get">');
	ibox_internal_renderitem_combobox(tab_search, 'links_searchbox', 'select_search', 'ibox_select_konfigurator', 'Bitte w&auml;hlen', '8010');
	document.write('<table cellpadding="0" cellspacing="0" border="0" style="WIDTH: 100%;">');
	document.write('<tr style="VERTICAL-ALIGN: top;" valign="top">');
	document.write('<td><input type="text" id="ibox_search" name="suchwort" value="Suchwort(e)" class="ibox_input_pwd" onfocus="select()" tabindex="8001" style="width:100px;"></td>');
	document.write('<td><input type="image" src="' + ibox_images_path + '/but_go.gif" width="36" height="15" alt="Go" class="ibox_but_go" onclick="ibox_internal_openComboboxLink(document.ibox_form_search.select_search)" tabindex="8012"></td>');
	document.write('</tr>');
	document.write('</table>');	
	document.write('</form>');

	document.write('<div class="ibox_line_inarea"></div>');
	
	document.write('<div class="ibox_txt">');
	document.write('<strong>Information</strong><br>');
	document.write('mehrere Suchbegriffe ');
	document.write('werden durch ein ');
	document.write('Leerzeichen getrennt.</div>');

	//document.write('<div class="ibox_line_inarea"></div>');
	
	//document.write('<div class="ibox_txt_link">');
	//ibox_internal_renderitem_link(tab_search, 'link_search');
	//document.write('</div>');

	document.write('</div>');
	// ----- Tab 'Suche' ENDE -----

	document.write('<div class="ibox_line"></div>');
	
	
	// ----- Tab 'Applikationen' START -----
	ibox_internal_countTab('ibox_div_applications');
	var tab_applications = ibox_internal_gettab(pData, 'applications');
	
	document.write('<div id="ibox_div_applications" class="ibox_inactive"><a href="javaScript:ibox_internal_switchBox(\'ibox_div_applications\')"><img onload="ibox_internal_createHiliteObj(this,\'' + ibox_images_path + '/ibox_warenkorb_over.gif\',this.src)" onmouseover="ibox_internal_showTabHigh(this)" onmouseout="ibox_internal_resetTabHigh(this)" src="' + ibox_images_path + '/ibox_warenkorb_off.gif" width="163" height="19" alt="Warenkorb"></a></div>');
	document.write('<div id="ibox_div_applications_a" class="ibox_active">');
	document.write('<img src="' + ibox_images_path + '/ibox_warenkorb_on.gif" width="163" height="19" alt="Dialog Center">');

	// -------eingefügt von Pascal Collins-----------
	document.write('<div class="ibox_txt">Ihr Warenkorb enth&auml;lt:<br>4 Artikel<br>360&euro; gesamt<br></div>');
	// ---------Ende eingefügt von Pascal Collins-------

	document.write('<div class="ibox_txt_link">');
	ibox_internal_renderitem_link(tab_login, 'link_ebz_aw');	
	ibox_internal_renderitem_link(tab_applications, 'eigene_angebote');	
	ibox_internal_renderitem_link(tab_applications, 'eigene_vorlagen');	
	document.write('<div class="ibox_line_inarea_log"></div>');
	ibox_internal_renderitem_link(tab_applications, 'link_favorites');
	ibox_internal_renderitem_link(tab_applications, 'link_saved_search');
	ibox_internal_renderitem_link(tab_applications, 'link_basket');
	document.write('</div>');
	document.write('</div>');
// ----- Tab 'Applikationen' ENDE -----

	document.write('<div class="ibox_line"></div>');


	// ----- Tab 'DialogCenter' START -----
	ibox_internal_countTab('ibox_div_dialogcenter');
	var tab_applications = ibox_internal_gettab(pData, 'dialogcenter');
	
	document.write('<div id="ibox_div_dialogcenter" class="ibox_inactive"><a href="javaScript:ibox_internal_switchBox(\'ibox_div_dialogcenter\')"><img onload="ibox_internal_createHiliteObj(this,\'' + ibox_images_path + '/ibox_helpdesk_over.gif\',this.src)" onmouseover="ibox_internal_showTabHigh(this)" onmouseout="ibox_internal_resetTabHigh(this)" src="' + ibox_images_path + '/ibox_helpdesk_off.gif" width="163" height="19" alt="HelpDesk"></a></div>');
	document.write('<div id="ibox_div_dialogcenter_a" class="ibox_active">');
	document.write('<img src="' + ibox_images_path + '/ibox_helpdesk_on.gif" width="163" height="19" alt="HelpDesk">');
	document.write('<div class="ibox_txt_link">');
	ibox_internal_renderitem_link(tab_applications, 'link_fragensieuns');	
	ibox_internal_renderitem_link(tab_applications, 'link_hilfe');
	ibox_internal_renderitem_link(tab_applications, 'link_newsletter');	
	ibox_internal_renderitem_link(tab_applications, 'link_forum');
	ibox_internal_renderitem_link(tab_applications, 'link_faqs');
	ibox_internal_renderitem_link(tab_applications, 'link_anregungenkritik');
	ibox_internal_renderitem_link(tab_applications, 'link_infomaterial');	
	document.write('</div>');

	// ----- Tab 'DialogCenter' START -----	

	document.write('<div class="ibox_line"></div>');
	document.write('</div>');
	document.write('</div>');	

}


//=========================================
// Internal functions for I-Box graphical effects
//=========================================


//var ibox_internal_avaiabletabs = new Array("search", "applications", "login", "konfigurator", "dialogcenter");
var ibox_internal_avaiabletabs = new Array("warenkorb", "applications", "login", "konfigurator", "dialogcenter", "myvwa", "suche", "merkliste");
var ibox_internal_inactiveEntry = '';
var ibox_internal_activeEntry = '';
var ibox_internal_oldibox_inactiveEntry = '';
var ibox_internal_oldibox_internal_activeEntry = '';
var ibox_internal_closetabheight = 0;
var ibox_internal_slidecount = 0;
var ibox_internal_tabArray = new Array();
var ibox_internal_tabheight = 0;

// Value depends on total height of I-Box
var ibox_internal_closetabheight_initialvalue = 153;


//click on tab
function ibox_internal_switchBox(whichBox) {
  // validate box name
  whichBox = ibox_internal_valiadateboxname(whichBox);
	
	var myEntry = whichBox + "_a";
	ibox_internal_oldibox_internal_activeEntry = ibox_internal_activeEntry;
	ibox_internal_oldibox_inactiveEntry = ibox_internal_inactiveEntry;
	ibox_internal_activeEntry = myEntry;
	ibox_internal_inactiveEntry = whichBox;
	if(navigator.appVersion.indexOf("MSIE") == -1){
		document.getElementById(whichBox).style.height = 0 + "px";
		document.getElementById(whichBox).style.border = 0 + "px";
		document.getElementById(whichBox).style.padding = 0 + "px";
	}
	else{
		document.getElementById(whichBox).style.visibility = "hidden";
		document.getElementById(whichBox).style.display = "none";	
	}	
	document.getElementById(ibox_internal_activeEntry).style.visibility = "visible";
	document.getElementById(ibox_internal_activeEntry).style.display = "block";
	
	document.getElementById(ibox_internal_activeEntry).style.height = 0 + "px";
	ibox_internal_tabheight = 19;
	if(navigator.appVersion.indexOf("MSIE") == -1){
			ibox_internal_tabheight = 19;
	}
	ibox_internal_closetabheight = ibox_internal_closetabheight_initialvalue;
	ibox_internal_slidecount = 1;
	ibox_internal_slidetab();
	
	// save last selected tab in cookie
	if (navigator.cookieEnabled) {
	  var selectedTab = whichBox;
	  if (selectedTab.indexOf("ibox_div_")==0) {
	    selectedTab = whichBox.substring("ibox_div_".length);
	  }
	  ibox_internal_setCookie("vwcms_ibox_selectedtab", selectedTab, null, "/");
	}
}

//slide function
function ibox_internal_slidetab() {
	ibox_internal_slidecount = ibox_internal_slidecount*2;
	ibox_internal_tabheight = ibox_internal_tabheight + ibox_internal_slidecount;
	ibox_internal_closetabheight = ibox_internal_closetabheight - ibox_internal_slidecount;
	document.getElementById(ibox_internal_activeEntry).style.height = ibox_internal_tabheight + "px";
	document.getElementById(ibox_internal_oldibox_internal_activeEntry).style.height = ibox_internal_closetabheight + "px";
	if (ibox_internal_closetabheight<=60){
		document.getElementById(ibox_internal_activeEntry).style.height = ibox_internal_closetabheight_initialvalue + "px";
		document.getElementById(ibox_internal_oldibox_internal_activeEntry).style.height = 19 + "px";
		document.getElementById(ibox_internal_oldibox_internal_activeEntry).style.display = "none";
		document.getElementById(ibox_internal_oldibox_internal_activeEntry).style.visibility = "hidden";
		document.getElementById(ibox_internal_oldibox_inactiveEntry).style.visibility = "visible";
		document.getElementById(ibox_internal_oldibox_inactiveEntry).style.display = "block";
		if(navigator.appVersion.indexOf("MSIE") == -1){
			document.getElementById(ibox_internal_oldibox_inactiveEntry).style.height = 19 + "px";			
		}
		window.clearTimeout(slidetimer);slidetimer=0;
		}
	else{
		slidetimer = window.setTimeout("ibox_internal_slidetab()",ibox_slide_timervalue);
		}
}

//default ibox display on page load
function ibox_internal_initDisplayIBox(whichCB) {
	whichCB = ibox_internal_valiadateboxname(whichCB);

	var CBnum = ibox_internal_tabArray.length;
	for(i=0;i<CBnum;i++){
		var myEntry = ibox_internal_tabArray[i] + "_a";
		document.getElementById(myEntry).style.visibility = "hidden";
		document.getElementById(myEntry).style.display = "none";	
		if(document.getElementById(ibox_internal_tabArray[i])){
			document.getElementById(ibox_internal_tabArray[i]).style.visibility = "visible";
			document.getElementById(ibox_internal_tabArray[i]).style.display = "block";			
		}
	}

	var myEntry = whichCB + "_a";
	ibox_internal_activeEntry = myEntry;
	ibox_internal_inactiveEntry = whichCB;
	document.getElementById(whichCB).style.visibility = "hidden";
	document.getElementById(whichCB).style.display = "none";
	document.getElementById(ibox_internal_activeEntry).style.visibility = "visible";
	document.getElementById(ibox_internal_activeEntry).style.display = "block";	
}

//counting tabs for default ibox display
function ibox_internal_countTab(whichTab){
	ibox_internal_tabArray[ibox_internal_tabArray.length] = whichTab;	
}


//image hiliting on mouseover
function ibox_internal_createHiliteObj(imgobj,onsrc,offsrc) {
if(imgobj.loadCount != true){		
	imgobj.imgname = new Object();
	imgobj.imgname.offimg = new Image();
    imgobj.imgname.offimg.src = offsrc;
	imgobj.imgname.onimg = new Image();
	imgobj.imgname.onimg.src = onsrc;
	imgobj.loadCount = 1;
	}
}

function ibox_internal_showTabHigh(whichImg) {
	whichImg.src = whichImg.imgname.onimg.src;		
}

function ibox_internal_resetTabHigh(whichImg) {	
	whichImg.src = whichImg.imgname.offimg.src;
}

//returns the given tab from ibox_data
function ibox_internal_gettab(pData, pTabName) {
  var tab = null;
  if (pData && pData!=null && pData.tabs) {
    tab = pData.tabs[pTabName];
  }
  if (tab==null) {
    tab = new function() {
			this.items = new Array();
		}
	}
	return tab;
}

function ibox_internal_renderitem_form(pTab, pItemName, pFormName) {
  document.write('<form name="' + pFormName + '" method="POST"');

  var item = pTab.items[pItemName];
  if (item!=null) {
		if (item.href!=null && item.href!='') {
			document.write(' action="' + ibox_internal_replace_linkparams(item.href) + '"');
			if (item.target!=null && item.target!='') {
				document.write(' target="' + item.target + '"');
			}
		}
	}

	document.write('>');
}

// renders a item as link (with arror and enclosing <div> tag)
function ibox_internal_renderitem_link(pTab, pItemName) {
  var item = pTab.items[pItemName];
  if (item==null) {
    return "";
  }
  document.write('<div class="link">');
  if (item.href!=null && item.href!='') {
    if (item.width!=null || item.height!=null) {
			document.write('<a href="javascript://" onclick="ibox_internal_openWindow(\'' + ibox_internal_replace_linkparams(item.href) + '\', \'' + item.target + '\', ' + (item.width!=null ? item.width : "0") + ', ' + (item.height!=null ? item.height : "0") + ', true);">');
    }
    else {
			document.write('<a href="' + ibox_internal_replace_linkparams(item.href) + '"');
			if (item.target!=null && item.target!='') {
				document.write(' target="' + item.target + '"');
			}
			document.write('>');
    }
  }
  document.write('<img src="' + ibox_images_path + '/arrow_orange.gif" width="10" height="8" border="0" alt="&gt;" class="arrow">');
  if (item.title!=null && item.title!='') {
		document.write(item.title);
  }
  if (item.href!=null && item.href!='') {
		document.write('</a>');
	}
  document.write('</div>');
}

// renders a item as label
function ibox_internal_renderitem_label(pTab, pItemName) {
  var item = pTab.items[pItemName];
  if (item==null) {
    return "";
  }
  if (item.title!=null && item.title!='') {
		document.write(item.title);
  }
}

// renders a item and containing links as combobox
function ibox_internal_renderitem_combobox(pTab, pItemName,	pComboName, pComboClass, pNullItem, pTabIndex) {
	document.write('<select name="' + pComboName + '" class="' + pComboClass + '"' + (pTabIndex!=null ? ' tabindex="' + pTabIndex + '"' : '') + '>');
	document.write('<option value="" selected>' + pNullItem + '</option>');

  var item = pTab.items[pItemName];
	if (item!=null && item.links!=null) {
	  for (var i=0; i<item.links.length; i++) {
	    var link = item.links[i];
	    if (link.title!=null && link.href!=null) {
	      var value = ibox_internal_replace_linkparams(link.href);
	      value += "|";
	      if (link.target!=null) {
	        value += link.target;
	      }
	      value += "|";
	      if (link.width!=null) {
	        value += link.width;
	      }
	      value += "|";
	      if (link.height!=null) {
	        value += link.height;
	      }
				document.write('<option value="' + value + '">' + link.title + '</option>');
			}
	  }
	}

	document.write('</select>');
}

// replaces all link parameters enclosed in { ... } with their values from ibox_link_parameters
function ibox_internal_replace_linkparams(pURL) {
  var url = pURL;

  for (var param in ibox_link_parameters) {
    
    // 1st: replace all params escacped in { }
    var toReplace = "{" + param + "}";
    var replacePos = url.indexOf(toReplace);
    while (replacePos>=0) {
      var parameterBeginPos = url.indexOf("?");
      if (parameterBeginPos>=0 && replacePos>parameterBeginPos) {
				// escape url parameters
				url = url.replace(toReplace, escape(ibox_link_parameters[param]));
      }
      else {
				url = url.replace(toReplace, ibox_link_parameters[param]);
			}
			replacePos = url.indexOf(toReplace);
    }

    // 2nd: do the same, but with urlencoded { }
    var toReplace = "%7B" + param + "%7D";
    var replacePos = url.indexOf(toReplace);
    while (replacePos>=0) {
			// double escape url parameters
			url = url.replace(toReplace, escape(ibox_link_parameters[param]));
			replacePos = url.indexOf(toReplace);
    }

  }

  return url;
}

// opens a new window with the given ur, target and parameters.
function ibox_internal_openWindow (pUrl, pTarget, pWidth, pHeight, pCentered) {
  if (pCentered == true && (navigator.appName.indexOf("Netscape") > -1 && parseInt(navigator.appVersion.substring(0,1)) >=4 )
			|| (navigator.appName.indexOf("Microsoft Internet Explorer") > -1 && parseInt(navigator.appVersion.substring(0,1)) >=4 )) {
    var w = (screen.width/2)-(pWidth/2); 
    var h = (screen.height/2)-(pHeight/2); 
    var parameter = "scrollbars=0,resizable=0";
	var parameter2 = "";
    
    if (pWidth != 0) {
      parameter2 += ',width=' + pWidth + ', screenX=' + w + ',left=' + w;
    }
    if (pHeight != 0) {
      parameter2 += ',height=' + pHeight + ', screenY=' + h + ',top=' + h;
    }
  }
  else {
    var parameter = "scrollbars=0,resizable=0";
	var parameter2 = "";
    if (pWidth != 0) {
      parameter2 += ',width=' + pWidth;
    }
    if (pHeight != 0) {
      parameter2 += ',height=' + pHeight;
    }
  }


	// Patch:
	if (pUrl.indexOf("cc5.volkswagen.de") > 0) {
		parameter = "scrollbars=yes,resizable=1";
		pTarget = "CC5";
	}

  var win = window.open(pUrl, pTarget, parameter + parameter2);
  if (win) {
    win.focus();
  }
  return false;
}

// opens a url from a combobox
function ibox_internal_openComboboxLink(pCombobox) {
  var value = pCombobox.options[pCombobox.selectedIndex].value;
  if (value.length==0) {
    return;
  }
  var parts = value.split("|");
  var url = parts[0];
  if (url!=null && url.length!=0) {
		var target = parts[1];
		var width = parts[2];
		var height = parts[3];

		if (target!=null && target.length!=0) {
			if ((width!=null && width.length!=0) || (height!=null && height.length!=0)) {
				if (width==null || width.length==0) {
					width = 0;
				}
				if (height==null || height.length==0) {
					height = 0;
				}
				ibox_internal_openWindow(url, target, width, height);
			}
			else {
			  window.open(url, target);
			}
		}
		else {
			document.location = url;
		}
	}
}

// refreshes ibox display when eprofiler userinfo changed
function ibox_internal_refresh_eprofile_userinfo() {
  // Switch headline
  var headline_image = null;
  if (ibox_internal_mode=="home") {
		if (ibox_internal_eprofile_userinfo!=null) {
			headline_image = ibox_images_path + "/ibox_headline_hp_loggedin.gif";
		}
		else {
			headline_image = ibox_images_path + "/ibox_headline_hp.gif";
		}
  }
  else {
		if (ibox_internal_eprofile_userinfo!=null) {
			headline_image = ibox_images_path + "/ibox_headline.gif";
		}
		else {
			headline_image = ibox_images_path + "/ibox_headline.gif";
		}
	}
	if(document.getElementById("ibox_headline_image")){
		document.images["ibox_headline_image"].src = headline_image;
	}
  
  // Switch login tab
	if (ibox_internal_eprofile_userinfo!=null) {
		// Clear existing user information
		var userNameDiv = document.getElementById("ibox_div_login_username");
		while (userNameDiv.childNodes.length!=0) {
		  userNameDiv.removeChild(userNameDiv.childNodes[0]);
		}
		// display user information
		if (ibox_internal_eprofile_userinfo.persaddr2
		    && ibox_internal_eprofile_userinfo.persaddr2!=null
		    && ibox_internal_eprofile_userinfo.persaddr2!="") {
			document.getElementById("ibox_div_login_username").className = "ibox_name_log_2rows";
			document.getElementById("ibox_div_login_username").appendChild(document.createTextNode(ibox_internal_eprofile_userinfo.persaddr1));
			document.getElementById("ibox_div_login_username").appendChild(document.createElement("br"));
			document.getElementById("ibox_div_login_username").appendChild(document.createTextNode(ibox_internal_eprofile_userinfo.persaddr2));
		}
		else {
			document.getElementById("ibox_div_login_username").className = "ibox_name_log";
			document.getElementById("ibox_div_login_username").appendChild(document.createTextNode(ibox_internal_eprofile_userinfo.persaddr1));
		}
		// display login tab with user information
		document.getElementById("ibox_div_login_a_notloggedin").style.visibility = "hidden";
		document.getElementById("ibox_div_login_a_notloggedin").style.display = "none";
		document.getElementById("ibox_div_login_a_loggedin").style.visibility = "visible";
		document.getElementById("ibox_div_login_a_loggedin").style.display = "block";
		document.getElementById("ibox_div_login_a_loggedin").style.height="183px";
	}
	else {
	  // clear user information
		var userNameDiv = document.getElementById("ibox_div_login_username");
		while (userNameDiv.childNodes.length!=0) {
		  userNameDiv.removeChild(userNameDiv.childNodes[0]);
		}
		document.getElementById("ibox_div_login_username").className = "ibox_name_log";
	  // display login tab without user information
		document.getElementById("ibox_div_login_a_notloggedin").style.visibility = "visible";
		document.getElementById("ibox_div_login_a_notloggedin").style.display = "block";
		document.getElementById("ibox_div_login_a_loggedin").style.visibility = "hidden";
		document.getElementById("ibox_div_login_a_loggedin").style.display = "none";		
	}
	
	if (ibox_internal_eprofile_userinfo_refresh_callback!=null) {
	  eval(ibox_internal_eprofile_userinfo_refresh_callback);
	}
}

function ibox_internal_login_pwd_onkeydown(pArgs) {
  // Special handling for IE in login fields: submit form on return
  try {
    if (event.keyCode==13) {
      document.ibox_form_login.submit();
    }
	}
	catch (e) {
	  // ignore
	}
}

// checks if the given ibox div/box name is valid and returns a valid one if not
function ibox_internal_valiadateboxname(pWhichBox) {
  for (var i=0; i<ibox_internal_avaiabletabs.length; i++) {
    var box = "ibox_div_" + ibox_internal_avaiabletabs[i];
    if (box==pWhichBox) {
      return box;
    }
  }
  // not found: return default tab
  return "ibox_div_login";
}


//=========================================
// I-Box Cookie helper functions
//=========================================

/**
 * Sets a Cookie with the given name and value.
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a secure transmission
 */
function ibox_internal_setCookie(name, value, expires, path, domain, secure) {
  ibox_internal_deleteCookie(name, path, domain);
	document.cookie= name + "=" + escape(value)
		+ ((expires) ? "; expires=" + expires.toGMTString() : "")
		+ ((path) ? "; path=" + path : "")
		+ ((domain) ? "; domain=" + domain : "")
		+ ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 * name  Name of the desired cookie.
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function ibox_internal_getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function ibox_internal_deleteCookie(name, path, domain) {
	if (ibox_internal_getCookie(name)) {
		document.cookie = name + "="
			+ ((path) ? "; path=" + path : "")
			+ ((domain) ? "; domain=" + domain : "")
			+ "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}



//=========================================
// I-Box common objects
//=========================================

/**
 * Defines a link reference.
 * @param pTitle Link title.
 * @param pHRef HRef for link. Can be URL or javascript: call (optional).
 * @param pTarget If HRef is URL: target for link (optional).
 * @param pWindowTarget Window properties.
 * @param pWindowWidth Window width.
 * @param pWindowHeight Window height.
 */
var ibox_object_link = function(pTitle, pHRef, pWindowTarget, pWindowWidth, pWindowHeight) {
  this.title = pTitle;
  this.href = pHRef;
  this.target = pWindowTarget;
  this.width = pWindowWidth;
  this.height = pWindowHeight;
}

/**
 * Defines user information for a logged in eProfile User.
 * @param pGUID eProfile User GUID.
 * @param pSID eProfile Session ID.
 * @param pRole eProfle role.
 * @param pPersAddr1 User display name, line 1.
 * @param pPersAddr2 User display name, line 2 (optional).
 */
var ibox_eprofile_userinfo = function(pGUID, pSID, pRole, pPersAddr1, pPersAddr2) {
  this.guid = pGUID;
  this.sid = pSID;
  this.role = pRole;
  this.persaddr1 = pPersAddr1;
  this.persaddr2 = pPersAddr2;
}

