﻿var gs_ColorObjectId = null;

function OpenDialog(as_Url, as_Name, ai_Width, ai_Height)
{
	var ls_Top = "";
	var ls_Left = "";
	try
	{
		ls_Left = ",left=" + (screen.Width / 2 - ai_Width);
		ls_Top = ",top=" + (screen.Height / 2 - ai_Height);
	}
	catch (e)
	{}
	
	window.open(as_Url, as_Name, "directories=no,location=no,menubar=no,scrollbars=no,status=yes,toolbar=no,resizable=yes,width=" + ai_Width + ",height=" + ai_Height + ls_Left + ls_Top);
}

var gk_WindowObjectReference = null;

function OpenRequestedPopup(as_Url, as_Name, ai_Width, ai_Height)
{
	var ls_Top = "";
	var ls_Left = "";
	try
	{
		ls_Left = ",left=" + (screen.Width / 2 - ai_Width);
		ls_Top = ",top=" + (screen.Height / 2 - ai_Height);
	}
	catch (e)
	{}

	try
	{
		if(gk_WindowObjectReference == null || gk_WindowObjectReference.closed)
		{
			gk_WindowObjectReference = window.open(as_Url, as_Name,"directories=no,location=yes,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes,width=" + ai_Width + ",height=" + ai_Height + ls_Left + ls_Top);
		}
		else
		{
			gk_WindowObjectReference.focus();
		}
	}
	catch (e)
	{}
}


function ChangeColor(as_ObjectId, ab_Change)
{
	document.getElementById(as_ObjectId).className = ab_Change ? "ContentMenuItem1" : "ContentMenuItem";
}

function ChangeBackgroundColor(as_ObjectId, ab_Change, as_CssNormal, as_CssOver)
{
	document.getElementById(as_ObjectId).className = ab_Change ? as_CssOver : as_CssNormal;
}

function SendMail(as_Email) 
{
	location.href = DecodeMail(as_Email);
}

function DecodeMail(as_Email) 
{
	var li_Code = 0;
	var ls_Output = "";
	
	for(var i=0; i < as_Email.length; i++) 
	{
		li_Code = as_Email.charCodeAt(i);
		if (li_Code >= 8364) {li_Code = 128;}
		ls_Output += String.fromCharCode(li_Code-(2));
	}
	
	return ls_Output;
}

function DisplayCountry(ab_Visible)
{
	if (ab_Visible != null)
	{	
		document.getElementById("europe").style.visibility = ab_Visible ? "visible" : "hidden";
		document.getElementById("america").style.visibility = ab_Visible ? "hidden" : "visible";		
	}
	else
	{
		document.getElementById("europe").style.visibility = "hidden";
		document.getElementById("america").style.visibility= "hidden";		
	}
}

function FireOnClick(as_UniqueID)
{
  __doPostBack(as_UniqueID,"");
}

function ShowBlockPrice(as_PriceObjectId, as_DescriptionObjectId, as_ImageObjectId, as_ImageFootObjectId)
{
	$price = $('#' + as_PriceObjectId);
	$description = $('#' + as_DescriptionObjectId);

	if ($price.css('visibility') != 'hidden') {
		$price.css('visibility', 'hidden');
		$description.css('visibility', 'visible');
	}
	else {
		$price.width($description.width());
		$price.css('visibility', 'visible');
		$description.css('visibility', 'hidden');
	}
}

function SetItemHeight()
{
	if (document.getElementById) 
	{
		var lk_DivElement = document.body.getElementsByTagName("DIV");
	
		for (i=0; i< lk_DivElement.length; i++)
		{	
			if (lk_DivElement[i].id != "")
			{
				if (lk_DivElement[i].id.indexOf("PriceScaleDiv") != -1)
					IncreaseHeight(lk_DivElement[i].parentNode, lk_DivElement[i]);
			}
		}
	}
}

function SetHeight(objId, style, value)
{ 
    document.getElementById(objId).style[style] = value; 
} 

function IncreaseHeight(ak_AddToHeight, ak_WhichHeightTd)
{    
    var li_CurrHeight = parseInt(ak_WhichHeightTd.offsetHeight);
    var li_AddToOffsetHeight = parseInt(ak_AddToHeight.offsetHeight);
    
    var li_NewHeight = 0;
    var li_Count = 6;
    
    if (li_AddToOffsetHeight <= li_CurrHeight)
    {
		li_NewHeight = li_CurrHeight + li_Count;
		SetHeight(ak_AddToHeight.id, "height", li_NewHeight + "px"); 
	}
}

var gk_CurrentCachedImages = new Array();

function GetCachedImage(as_ImageUrl)
{
	if (gk_CurrentCachedImages[as_ImageUrl] == null)
	{
		gk_CurrentCachedImages[as_ImageUrl] = new Image();
		gk_CurrentCachedImages[as_ImageUrl].src = as_ImageUrl.replace(/url\(/g, "").replace(/\)/g, "");
	}
	return gk_CurrentCachedImages[as_ImageUrl].src;
}

function SetTextButtonOver(as_LeftCellId, as_MiddleCellId, as_RightCellId, as_ImgOverLeft, as_ImgOverMiddle, as_ImgOverRight)
{
	document.getElementById(as_LeftCellId).style.background = "url("+GetCachedImage(as_ImgOverLeft)+")";
	document.getElementById(as_MiddleCellId).style.background = "url("+GetCachedImage(as_ImgOverMiddle)+")";
	document.getElementById(as_RightCellId).style.background = "url("+GetCachedImage(as_ImgOverRight)+")";
}

function SetTextButtonNormal(as_LeftCellId, as_MiddleCellId, as_RightCellId, as_ImgLeft, as_ImgMiddle, as_ImgRight)
{
	document.getElementById(as_LeftCellId).style.background = "url("+GetCachedImage(as_ImgLeft)+")";
	document.getElementById(as_MiddleCellId).style.background = "url("+GetCachedImage(as_ImgMiddle)+")";
	document.getElementById(as_RightCellId).style.background = "url("+GetCachedImage(as_ImgRight)+")";
}

function ShowUpdateBlockPrice(as_PriceObjectId, as_DescriptionObjectId)
{
	try
	{
		if(document.getElementById(as_PriceObjectId).style.visibility == "visible")
		{
		
			document.getElementById(as_DescriptionObjectId).style.visibility = "visible";
			document.getElementById(as_PriceObjectId).style.visibility = "hidden";
		}
		else
		{
			document.getElementById(as_DescriptionObjectId).style.visibility = "hidden";
			document.getElementById(as_PriceObjectId).style.visibility = "visible";
		}
	}
	catch (e)
	{}
}

function openHelp(helpdisplayURL, ServerPath )
{
	CompleteURL = ServerPath + "Help/HelpFrame.aspx?displaypage=" + helpdisplayURL ; 
	Helpwindow = window.open(CompleteURL,'SK_help','resizable=yes,scrollbars=yes,toolbar=no,status=no,menubar=no,location=no,height=560,width=850');	
	Helpwindow.focus();
}

var gk_ScrollPos = new Array();
function ScreenshotScroll(as_ClientId, ai_Step, ai_ScrollStep)
{

	var lk_Nav = document.getElementById(as_ClientId + "ScreensNav");
	var lk_Nodes = lk_Nav.getElementsByTagName("img");
	var ai_Current = 0;
	for (var i = 0; i < lk_Nodes.length; i++)
	{
		if (lk_Nodes[i].src.indexOf("active") > 0)
			ai_Current = i;
	}
	if (ai_Current + ai_Step >= lk_Nodes.length || ai_Current + ai_Step < 0)
		return;
	ai_Current += ai_Step;
	for (var i = 0; i < lk_Nodes.length; i++)
	{
		if (i == ai_Current)
			lk_Nodes[i].src = lk_Nodes[i].src.replace("normal", "active");
		else
			lk_Nodes[i].src = lk_Nodes[i].src.replace("active", "normal");
	}
	document.getElementById(as_ClientId + "Screens").scrollLeft += ai_ScrollStep * ai_Step;
}
