				/*
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 doesn´t exist
 */
function loadFrameset(title)
{
	if(parent.frames.length == 0)
	{
		// 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/validateVpin.do', APP + '/register/gallery/related.do?XY=' + JSESSIONID);
		urlMatches[3] = new URLMatch('/register/validateEmailVpin.do', APP + '/register/gallery/related.do?XY=' + JSESSIONID);
		urlMatches[4] = new URLMatch('/register/sendConfirmationEmail.do', APP + '/register/gallery/related.do?XY=' + JSESSIONID);
		urlMatches[5] = new URLMatch('/register/short/step1/process.do', APP + '/register/short/step2/show.do?XY=' + JSESSIONID);
		urlMatches[6] = new URLMatch('/register/short_b_new/get_mobile_number.do', APP + '/register/short_b_new/select_func.do?XY=' + JSESSIONID);
		urlMatches[7] = new URLMatch('/login/login_chat.do', APP + '/login/test_abo.do?XY=' + JSESSIONID);

		var frameset = "";
//		var main_frame = window.location.href + window.location.search;

        // changed by Dirk Tornow
        var main_frame = window.location.href;
		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 makeSmall()
{
	if(navigator.appName == "Netscape")
	{
		breite = 265;
		hoehe = 50;
		x_pos = screen.width - breite;
		y_pos = screen.height - hoehe ;
		window.resizeTo(breite,hoehe);
		window.moveTo(x_pos,y_pos);
		document.getElementById("chat").rows="49,1";
	}
	else
	{
		breite = 265;
		hoehe = 50;
		x_pos = screen.width - breite;
		y_pos = screen.height-hoehe-80; //80 pixel Offset, sonst Fenster zu tief
		window.resizeTo(breite,hoehe);
		window.moveTo(x_pos,y_pos);
		document.getElementById("chat").rows="49,1";
	}
}

function makeBig()
{
	breite = 525;
	hoehe = 595;
	x_pos = 200;
	y_pos = 50;
	window.focus();
	window.resizeTo(breite,hoehe+20);
	window.moveTo(x_pos,y_pos);
	document.getElementById("chat").rows="405,170";
}

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 showUserProfileMsgBox(uid)
{
 	location.href = APP + "/profile/show.do?XY=" + JSESSIONID + "&uid=" + uid;
}

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)
{
	window.opener.parent.frames[0].location.href = APP + "/register/short_b/start.do?XY=" + JSESSIONID + "&func=chat&target_user=" + uid;
 	window.opener.parent.frames[0].focus();
}

function openChatWindow()
{
    window.open(APP + '/chat.do','ChatWindow','width=498,height=605,scrollbars=no');
}


// status of this windo
focusStatus = true;

if (navigator.appName != "Microsoft Internet Explorer"){
	window.captureEvents(Event.BLUR);
	window.onblur = looseFocus;
	function looseFocus(Ereignis) {
		focusStatus = false;
	}
	window.captureEvents(Event.FOCUS);
	window.onfocus = getFocus;
	function getFocus(Ereignis) {
		focusStatus = true;
	}
}

// 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 setCookie(nameValuePair, _expires, _path)
{
	document.cookie = nameValuePair.name + "=" + nameValuePair.value + "; expires=" + _expires + "; path=" + _path;
}

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];
		}
	}
}
