/**
 * logprivatechat
 * freechat
*/

/* performer rate-hez */
actualRate = parseInt(actualRate);

/* free es private osszevonasahoz */ 
function isPrivate() {
	var headerBG = document.getElementById("header");
	var topMenu = document.getElementById("header_menu");
	var topMenu1 = document.getElementById("hm_NoFreeCredit");
	var table0 = document.getElementById("freechat_header");
	var table1 = document.getElementById("freechat_footer");
	var undert = document.getElementById("profil_windows_willingness");
	var freechats = document.getElementById("performersbox");
	var table2 = document.getElementById("texts");
	var threeMenu = document.getElementById("threeMenu");
	var lang = document.getElementById("flags_box");
	
	if (headerBG) {
		headerBG.style.height = "28px";
	}
	
	if (topMenu) {
		topMenu.parentNode.removeChild(topMenu);
	}
	else if (topMenu1) {
		topMenu1.parentNode.removeChild(topMenu1);
	}
	
	if (table0)	{
		table0.parentNode.removeChild(table0);
	}
	
	if(table1)
	{
		table1.parentNode.removeChild(table1);
	}
		
	if (undert)	{
		undert.parentNode.removeChild(undert);
	}
	
	if (freechats) {
		freechats.parentNode.removeChild(freechats);
	}
	
	if (table2)	{
		table2.parentNode.removeChild(table2);
	}
	
	if(threeMenu) {
		threeMenu.parentNode.removeChild(threeMenu);
	}
	
	if(lang) {
		lang.parentNode.removeChild(lang);
	}
};

function setFlashSize(newD)
{
	if ( getURLParam("isprivatestart") == 2 )
	{
		isprivatestart = 2;
	}
	
	var Opera = ((navigator.userAgent.indexOf("Opera/") > -1)) ? 1 : 0;
	var IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6")!=-1)) ? 1 : 0;
	actualSize = newD;
	
	var xwidth = new Array();
		xwidth[0] = 708;
		xwidth[1] = 708;
		xwidth[2] = 708;
		xwidth[3] = 708;
		
	var xheight = new Array();
		if (isprivatestart == 2) 
		{
			xheight[0] = 430;
		}
		else
		{
			xheight[0] = 285;
		}
		xheight[1] = 570;
		xheight[2] = 570;
		xheight[3] = 651;
		
	var minwidth = 320;
	var minheight = 285;
	
	/* full size */
	if (newD == 4)
	{
		if (document.documentElement && document.documentElement.clientWidth) {
			xwidth[newD] = document.documentElement.clientWidth;
			xheight[newD] = document.documentElement.clientHeight;
		}
		else if (self.innerWidth) {
			xwidth[newD] = self.innerWidth;
			xheight[newD] = self.innerHeight;
		}
		else if (document.body) {
			xwidth[newD] = document.body.clientWidth;
			xheight[newD] = document.body.clientHeight;
		}
		else {
			xwidth[newD] = xwidth[3];
			xheight[newD] = xheight[3];
		}
		
		if (xheight[newD] < xheight[2] || xwidth[newD] < xwidth[2])	{
			xwidth[newD] = xwidth[2];
			xheight[newD] = xheight[2];
		}

		var ar = xwidth[2]/xheight[2];	/* normal AR-t szamolunk Large alapjan */

		if (xwidth[newD]<(xheight[newD]*ar))
		{
			xheight[newD] = xwidth[newD]/ar;
		}
		else {
			xwidth[newD] = xheight[newD]*ar;
		}


	        if(isprivatestart == 2)
	        {
				if ($("#freechat_flashdiv_priv").attr("id") == "freechat_flashdiv_priv")
				{
					var flashdivTopPos = $("#freechat_flashdiv_priv").offset().top;
				}
				else
				{
					var flashdivTopPos = $("#freechat_flashdiv").offset().top;
				}
	        }
	        else
	        {
			    var flashdivTopPos = $("#freechat_flashdiv").offset().top;    
	        }        
	        var timeScroll = setTimeout("scroll(0,"+flashdivTopPos+")", 500);
				
		$(".auction_banners").css("display", "none");
        $(".alexa_banner").css("display", "none");
	}
	else  {
		if ($(".auction_banners").css("display") == "none" && isprivatestart != 2)	{
			$(".auction_banners").css("display", "block");
		}
        if ($(".alexa_banner").css("display") == "none" && isprivatestart != 2)	{
			$(".alexa_banner").css("display", "block");
		}
		scroll(0,0);
	}

	if (newD == 4 && document.layers) {
		w -= (parent.outerWidth-parent.innerWidth);
		h -= (parent.outerHeight-parent.innerHeight);
		if (xwidth[newD] < w || xheight[newD] < h) {
			self.resizeBy(((xwidth[newD] >= w)?0:w-xwidth[newD]),((xheight[newD] >= h)?0:h-xheight[newD]));
		}
	}
	
	setFlashWidth(xwidth[newD]);
	
	setFlashHeight(xheight[newD]);
};

/***** logprivatechat ****/
var price="5999";

function reloadLogPC()
{
	window.location="logprivatchat.php?performerid=<% $performer %>";
};

function reloadPage()
{
	window.location.reload();
};

function changeImage(key, index, cless){
	if (index >= snapshots[key].length)
		index = 0;
	
	if (cless == 1)
	{
		$('img.'+key+'_img').attr('src', snapshots[key][index].src);
	}
		
	else
	{
		$('#'+key+'_img').attr('src', snapshots[key][index].src);
	}
		
		
	t = setTimeout("changeImage('" + key + "', " + (index + 1) + ", " + cless + ")", 1000);
};

function resetImage(key, index, cless){
	if (cless == 1)
	{
		$('img.'+key+'_img').attr('src', snapshots[key][index].src);	
	}
	else
	{
		$('#'+key+'_img').attr('src', snapshots[key][index].src);
	}
		
	
	clearTimeout(t);
};

function getURLParam(strParamName) {
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ) {
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (	aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
};

function goLogPrivate( )
{
	$.ajax({
	   type: "GET",
	   url: logprivatechaturl,
	   success: function(msg){
		  if ( IE )
		  {
			document.getElementById("flash").logPrivate();
		  }
		  else
		  {
			document.getElementById("opera_elb").logPrivate();
			
		  }
			
		  $("#main_content").css("height", "1px");
		  $("#main_content").css("visibility", "hidden");
		  $("#logprivatchat").css("display", "block");
		  $("#logprivatchat").html(msg);
		  $(".livedealad").css("display", "none");
		  $(".alexa_banner").css("display", "none");
		  
		  var flags = document.getElementById("flags_box");
		  if ( flags )
		  {
		  	flags.style.display = "none";
		  }
	   },
	   error: function () {
		  location.href = logprivatechaturl;
	   }
	 });
}

function goPrivate( )
{
	$.ajax({
	   type: "GET",
	   url: "ajax/response.php?module=member&action=prePrivateActions&params[performerid]="+performerid,
	   success: function(msg){
			if (msg != "ERROR") 
			{
				var g = document.getElementById("form2").elements["twoway"];
				var e = document.getElementById("form2").elements;
				
				twoway = $("input[name=twoway]:checked").val() ? $("input[name=twoway]:checked").val() : 0;
				
				$("#main_content").css("visibility", "visible");
				$("#main_content").css("height", "auto");
				$("#logprivatchat").css("display", "none");
				
				if (msg == "BUYCREDIT_TRUE")
				{
					$('#freechat').append('<iframe name="check_trans" class="buycredit_frame" src="private_buycredit.php?livejasmin_session='+sid+'&amp;performerid='+performerid+'" scrolling="No" frameborder="0" width="720"></iframe>');
					$('.buycredit_frame').insertBefore($('#footer'));
				}
				
				privateinterval = setTimeout("goPrivateTimer()", 150);
			}
			else
			{
				location.href = logprivatechaturl;
			}
	   },
	   error: function () {
		  location.href = logprivatechaturl;
	   }
	 });
}

function goPrivateTimer( )
{
	isprivatestart=2;
	
	if ( IE )
	{
		document.getElementById("flash").startPrivate(twoway);
	}
	else
	{
		document.getElementById("opera_elb").startPrivate(twoway);
	}
}

var unloadedPage = false;

function setUnload( )
{
	unloadedPage = true;
}

window.onbeforeunload = function()
{
	if ( !unloadedPage )
	{
		if ( IE && document.getElementById("flash").closeChat )
		{
			document.getElementById("flash").closeChat();
		}
	}
		
	unloadedPage = true;
};
