				/*
global js functions
*/

function postForm(FormName)
{
  for(var i=0;i<document.forms.length;i++)
  {
    if (document.forms[i].name == FormName)
    {
      document.forms[i].submit();
    }
  }
  return false;
}

function jsRedirect(url,param,value)
{
  var redirectUrl = url;
  var session = "";
  if (location.href.indexOf("?") != -1)
  {
    session = location.href.substring(location.href.lastIndexOf('?')+1,location.href.length+1);
  }
  if (session != "")
  {
    redirectUrl = redirectUrl + ";" + session;
  }
  redirectUrl = redirectUrl + "?" + param + "=" + value;
  document.location.replace(redirectUrl);
}

function destroyFrames()
{
  if(top.frames.length > 0)
  {
	  top.location.href=self.location;
  }
}

//-----------------------------------------------
// Chat / Frameset Handling functions
//-----------------------------------------------


/**
 * Object used in loadFrameset()
 */
function URLMatch(_toReplace, _replaceWith)
{
	this.toReplace = _toReplace;
	this.replaceWith = _replaceWith;
}

/**
 * Loads a frameset if one does not exist
 */
function loadFrameset(title) {

/*
	if(location.href == "/" || location.href.indexOf("/home.do") != -1)
		return;
*/	
	
	if(location.href == "/")
		return;		

	if(parent.frames.length == 0) {
    var main_frame = window.location.href;
		var ignoreList = Array();		
		ignoreList[0] = '/info/ilove-de-de/katalog/';
		ignoreList[1] = '/profile/mydata/processEmailVpin.do';
		ignoreList[2] = '/fill_profile/validate_vpin.do';
		ignoreList[3] = '/login/logout.do';
		/*ignoreList[4] = '/home.do';*/
		for(i=0; i < ignoreList.length; i++) {
			if(main_frame.indexOf(ignoreList[i]) != -1) {
				return;
			}
		}
		
		// stop certain urls from being called twice
		var urlMatches = Array();
		urlMatches[0] = new URLMatch('/login/login.do', APP + '/login_forward.jsp?XY=' + JSESSIONID);
		urlMatches[1] = new URLMatch('/cancel/login.do', APP + '/cancel/choice.do?XY=' + JSESSIONID);
		urlMatches[2] = new URLMatch('/register/short/step1/process.do', APP + '/register/short/step2/show.do?XY=' + JSESSIONID);
		urlMatches[3] = new URLMatch('/login/login_chat.do', APP + '/login/test_abo.do?XY=' + JSESSIONID);

		var frameset = "";

        // changed by Dirk Tornow
		for(i=0; i < urlMatches.length; i++) {
			if(main_frame.indexOf(urlMatches[i].toReplace) != -1) {
				main_frame = urlMatches[i].replaceWith;
				break;
			}
		}
		
		frameset += "<html>";
		frameset += "  <head>";
		frameset += "  <title>" + title + "</title>";
		frameset += "  </head>";
		frameset += "  <frameset rows=\"*,0\">";
		frameset += "    <frame src=\"" + main_frame + (main_frame.indexOf("?") == -1 ? "?" : "&") + "inframe=1\" name=\"frame_main\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" noresize>";
		frameset += "    <frame src=\"" + APP + "/chat/connector.do?XY=" + JSESSIONID + "\" name=\"frame_connector\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" noresize>";
		frameset += "    <noframes>";
		frameset += "      Ihr Browser kann diese Seite leider nicht anzeigen!";
		frameset += "    </noframes>";
		frameset += "  </frameset>";
		frameset += "</html>";

		document.writeln(frameset);
	}
}

function showUserProfile(uid)
{
 	parent.opener.parent.frames[0].location.href = APP + "/profile/show.do?XY=" + JSESSIONID + "&uid=" + uid;
	parent.opener.parent.frames[0].focus();
}

function addFavorite(uid)
{
	//window.open('http://www.ilove.de/dtf/user/bookmarks/add.do?ptyp=1&uid='+uid+'&profileSelectFlag=0&profileSendFlag=4&url=1&backTo=profile','iLove');
	parent.opener.parent.frames[0].location.href = APP + "/user/bookmarks/add.do?XY=" + JSESSIONID + "&ptyp=1&uid=" + uid + "&profileSelectFlag=0&profileSendFlag=4&url=1&backTo=profile";
	parent.opener.parent.frames[0].focus();
}

function addFriend(uid)
{
	//window.open('http://www.ilove.de/dtf/profile/show/navigated.do?profileSendFlag=3&uid='+uid+'&ptyp=1&profileSelectFlag=0&index=0&profileIndex=0','iLove');

	parent.opener.parent.frames[0].location.href = APP + "/friends/invite/start.do?XY=" + JSESSIONID + "&ptyp=1&uid=" + uid + "&profileSelectFlag=0&profileSendFlag=3&url=1";
	//parent.opener.parent.frames[0].location.href = APP + "/profile/show/navigated.do?XY=" + JSESSIONID + "&profileSendFlag=3&uid=" + uid + "&ptyp=1&profileSelectFlag=0&index=0&profileIndex=0";
	parent.opener.parent.frames[0].focus();
}

function showUserProfileMsgBox(uid)
{
 	var targeturl = APP + "/profile/show.do?XY=" + JSESSIONID + "&uid=" + uid;
 	if (isMagazin != null && isMagazin == true) {
		top.location.href = targeturl;
 	} else {		
 		location.href = targeturl;
 	}
}

function goToMailBox()
{
	location.href = APP + "/mail/start.do?XY=" + JSESSIONID;
	//window.open('http://www.ilove.de/dtf/mail/start.do','_blank');
}

function showOnlineUser()
{
 	parent.opener.parent.frames[0].location.href = APP + "/search/currently_online.do?XY=" + JSESSIONID + "&search=online";
 	parent.opener.parent.frames[0].focus();
}

function open_reg(uid, upsell)
{
	window.opener.parent.frames[0].location.href = APP + "/order/start.do?XY=" + JSESSIONID + "&func=chat&target_user=" + uid;
 	window.opener.parent.frames[0].focus();
}

function blockUser(uid)
{
	parent.opener.parent.frames[0].location.href = APP + "/mail/blocklist/add.do?XY=" + JSESSIONID + "&toUid=" + uid;
 	parent.opener.parent.frames[0].focus();
	//window.open('http://www.ilove.de/dtf/mail/blocklist/add.do?toUid='+uid ,'_blank');
}

function openChatWindow()
{
    window.open(APP + '/chat.do?XY=' + JSESSIONID,'ChatWindow','width=498,height=605,scrollbars=no');
}


// status of this windo
focusStatus = true;

if (navigator.appName != "Microsoft Internet Explorer"){
	window.captureEvents(Event.BLUR);
	function looseFocus(Ereignis) {
		focusStatus = false;
	}
	window.onblur = looseFocus;
	
	
	window.captureEvents(Event.FOCUS);
	function getFocus(Ereignis) {
		focusStatus = true;
	}
	window.onfocus = getFocus;
}

/* FocusStatus wieder nach Einspielung von RU und PL aktivieren. F???r die Einspielung ist es zwingend erforderlich,
dass es ausgeschaltet ist, da es sonst zu Fehlern kommt */


// called from chat_client.swf to brinf window in front
function focusWindow(){

	//window.focus();
	//alert("YO");

	if (navigator.appName == "Microsoft Internet Explorer"){
		self.focus();
	}
	else {
		if (!focusStatus) { 
			self.focus();
		} 
	}

}



//-----------------------------------------------
// Cookie / Affiliate Handling functions
//-----------------------------------------------

var nameValuePair;

function NameValuePair(_name, _value)
{
	this.name = _name;
	this.value = _value;
}

function getCookieTimeout(_time)
{
	var _date = new Date();
	var _timeout = _date.getTime() + _time;
	_date.setTime(_timeout);
	return _date.toGMTString();
}

function setAffiliateCookie(nameValuePair, _expires, _path, _host)
{	
	// workaround for IE security violation through third party partner sites; see jira DADMIN-1885
	if (document.cookie.indexOf('D_A_') == -1 || window.location.href.indexOf("came_from_partner_site") == -1) {
		if(_host != null && _host != '') {
			document.cookie = nameValuePair.name + "=" + nameValuePair.value + "; expires=" + _expires + "; path=" + _path + "; domain=" + getHostToSet(_host);
		}
		else {
			document.cookie = nameValuePair.name + "=" + nameValuePair.value + "; expires=" + _expires + "; path=" + _path;
		}
	}
}

function getHostToSet(_host)
{
	var _domain = 'ilove.de';
	var _index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;

	_domain = 'ilove.co.uk';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;

	_domain = 'ilove.ch';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;

	_domain = 'ilove.at';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;

	_domain = 'ilove.pl';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;

	_domain = 'ilove.se';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;

	_domain = 'ilove.it';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;

	_domain = 'ilove.nl';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;

	_domain = 'ilove.ru';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;

  _domain = 'ru.ilove.com';
  _index = _host.indexOf(_domain);
  if(_index != -1)
  	return _domain;

  _domain = 'ilove.com';
  _index = _host.indexOf(_domain);
  if(_index != -1)
  	return _domain;

	_domain = 'i-love.pl';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;

	_domain = 'intern.dev.de';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = 'intern.dev.co.uk';
	 _index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = 'intern.dev.se';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = '10.35.30.19';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = '127.0.0.1';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;		
		
	_domain = 'prerelease01.ilove.de';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = 'prerelease01.ilove.ch';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = 'prerelease01.ilove.at';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = 'prerelease02.ilove.pl';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = 'prerelease02.ilove.ru';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;				
		
	_domain = 'localhost.de';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = 'localhost.ch';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = 'localhost.at';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = 'localhost.pl';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;
		
	_domain = 'localhost.ru';
	_index = _host.indexOf(_domain);
	if(_index != -1)
		return _domain;				
}

function getCookie()
{
	return document.cookie;
}

function getValueFromCookie(name)
{
	var _cookie = getCookie();
	var _attributes = _cookie.split(";");
	for(i=0; i<_attributes.length;i++)
	{
		if(_attributes[i].indexOf(name))
		{
			var pair = _attributes[i].split("=");
			return pair[1];
		}
	}
}

function agbcheck(theForm)
{
	if ((!theForm.elements.termsaccepted.checked))
	{
 		alert ("Bitte den AGBs zustimmen!");
 		return false;
	}
	return true;
}

 /**
  * method for limiting text fields for a certain size.
  * @param obj: text field to limit
  * @param maxLength: allowed max length of field
  * @param $fieldLengthName: name of textfield which shows how many characters are left
  * @param form: name of the form
  */
 function probeComment($obj, $maxLength, $fieldLengthName, $form) {
    var $len = $maxLength - $obj.value.length;

    if ($len < 0) {
      $obj.value = $obj.value.substring(0, $maxLength);
      $len = 0;
    }

    $fieldLengthName.value = $len;
    // $form.elements[$fieldLengthName].value = $len;
  }
  
function writeFlash(_width,_height,_movieclip,_flashvars,_divname){
  var swfObj = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\""+_width+"\" height=\""+_height+"\">";
  swfObj += "<param name=\"movie\" value=\"" + _movieclip + "\">";
  swfObj += "<param name=\"quality\" value=\"high\">";
  swfObj += "<PARAM NAME=FlashVars VALUE=\"" + _flashvars + "\">";
  swfObj += "<embed src=\"" + _movieclip + "\" width=\""+_width+"\" height=\""+_height+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" FlashVars=\"" + _flashvars + "\"></embed>";
  swfObj += "</object>";
  
  document.getElementById(_divname).innerHTML = swfObj;
} 

/* ajax function */
function fetchContent(destinationDiv, url) {
	try {
		$('big-image').hide();
		$('loading-image').show();
	}
	catch (e) {}
	new Ajax.Updater(destinationDiv, url, {
		evalScripts:true, 
		onComplete:function() { $('loading-image').hide(); },
		asynchronous:true
	});
}