﻿// JScript File
/*Trim function*/
function Trim(TRIM_VALUE)
{
	if (TRIM_VALUE.length < 1)
	{
		return "";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if (TRIM_VALUE == "")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if (v_length < 0)
	{
		return "";
	}
	var iTemp = v_length - 1;

	while (iTemp > -1)
	{
		if (VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0, iTemp + 1);
			break;
		}
		iTemp = iTemp - 1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if (v_length < 1)
	{
		return "";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while (iTemp < v_length)
	{
		if (VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp, v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

/// Types:
///	0 - Nothing, 
///	1 - PatriaPlus || InvestorPlus,
///	2 - PatriaPlus, 
///	3 - InvestorPlus,
function NoAccessMessage(lang, type, confirmUrl)
{
	switch (lang)
	{
		case "en":
			{
				switch (type)
				{
					case 1:
						var mess = "This service is only available to Patria Plus or Investor Plus subscribers.\n\nIf you are a Patria Plus/Investor Plus client and you would like to sign in, please click on the OK button.\n\nIf you are not interested in this service, please click on the Cancel/Storno button.";
						break;
					case 2:
						var mess = "This service is only available to Patria Plus subscribers.\n\nIf you are a Patria Plus client and you would like to sign in, please click on the OK button.\n\nIf you are not interested in this service, please click on the Cancel/Storno button.";
						break;
					case 3:
						var mess = "This service is only available to Investor Plus subscribers.\n\nIf you are a Investor Plus client and you would like to sign in, please click on the OK button.\n\nIf you are not interested in this service, please click on the Cancel/Storno button.";
						break;
					default:
						var mess = "This service is available only to registered users..\n\nTo register now?";
						break;
				}
				break;
			}
		case "sk":
			{
				switch (type) {
					case 1:
						var mess = "Táto služba je súčasťou plateného informačného zdroja Patria Plus alebo Investor Plus.\n\nPokiaľ  ste klientom Patria Plus alebo Investor Plus a chcete sa prihlásiť, kliknite na OK.\n\nPokiaľ nemáte o službu záujem, kliknite Storno.";
						break;
					case 2:
						var mess = "Táto služba je súčasťou plateného informačného zdroja Patria Plus.\n\nPokiaľ  ste klientom Patria Plus a chcete sa prihlásiť, kliknite na OK.\n\nPokiaľ nemáte o službu záujem, kliknite Storno.";
						break;
					case 3:
						var mess = "Táto služba je súčasťou plateného informačného zdroja Investor Plus.\n\nPokiaľ  ste klientom Investor Plus a chcete sa prihlásiť, kliknite na OK.\n\nPokiaľ nemáte o službu záujem, kliknite Storno.";
						break;
					default:
						var mess = "Táto služba je prístupná iba registrovaným uživateľom.\n\nChcete sa teraz zaregistrovať?";
						break;
				}
				break;
			}
		default:
			{
				switch (type) {
					case 1:
						var mess = "Tato služba je součástí placeného informačního zdroje Patria Plus nebo Investor Plus.\n\nPokud jste klienty Patria Plus nebo Investor Plus a chcete se přihlásit, klikněte na OK.\n\nPokud nemáte o službu zájem, klikněte Cancel/Storno.";
						break;
					case 2:
						var mess = "Tato služba je součástí placeného informačního zdroje Patria Plus.\n\nPokud jste klienty Patria Plus a chcete se přihlásit, klikněte na OK.\n\nPokud nemáte o službu zájem, klikněte Cancel/Storno.";
						break;
					case 3:
						var mess = "Tato služba je součástí placeného informačního zdroje Investor Plus.\n\nPokud jste klienty Investor Plus a chcete se přihlásit, klikněte na OK.\n\nPokud nemáte o službu zájem, klikněte Cancel/Storno.";
						break;
					default:
						var mess = "Tato služba je dostupná pouze registrovaným uživatelům.\n\nChcete se nyní zaregistrovat?";
						break;
				}
				break;
			}
	}

	res = confirm(mess);
	
	if (res)
		window.location = "https://" + location.host + (confirmUrl == "" ? "/Membership/UserLogin.aspx" : confirmUrl);
		
	return false;
}

function GetRoleRequiredNoDownloadMessage(role, lang)
{
	switch (role.toString().toLowerCase())
	{
		case "treasury.other":
			{
				var messageCS = "Tato služba je součástí placeného informačního zdroje Patria Plus.\n\nPokud jste klienty Patria Plus a chcete se přihlásit, klikněte na OK.\n\nPokud nemáte o službu zájem, klikněte Cancel/Storno.";
				var messageEN = "This service is only available to Patria Plus  subscribers.\n\nIf you are a Patria Plus client and you would like to sign in, please click on the OK button.\n\nIf you are not interested in this service, please click on the Cancel/Storno button.";
				var messageSK = "Táto služba je súčasťou plateného informačného zdroja Patria Plus .\n\nPokiaľ  ste klientom Patria Plus  a chcete sa prihlásiť, kliknite na OK.\n\nPokiaľ nemáte o službu záujem, kliknite Storno.";
				break;
			}
		default:
			{
				var messageCS = "Tato služba je součástí placeného informačního zdroje Patria Plus nebo Investor Plus.\n\nPokud jste klienty Patria Plus nebo Investor Plus a chcete se přihlásit, klikněte na OK.\n\nPokud nemáte o službu zájem, klikněte Cancel/Storno.";
				var messageEN = "This service is only available to Patria Plus or Investor Plus subscribers.\n\nIf you are a Patria Plus/Investor Plus client and you would like to sign in, please click on the OK button.\n\nIf you are not interested in this service, please click on the Cancel/Storno button.";
				var messageSK = "Táto služba je súčasťou plateného informačného zdroja Patria Plus alebo Investor Plus.\n\nPokiaľ  ste klientom Patria Plus alebo Investor Plus a chcete sa prihlásiť, kliknite na OK.\n\nPokiaľ nemáte o službu záujem, kliknite Storno.";

				break;
			}
	}


	if (lang.toString().toLowerCase() == "en")
	{
		res = confirm(messageEN);
	}
	else if (lang.toString().toLowerCase() == "sk")
	{
		res = confirm(messageSK);
	}
	else
	{
		res = confirm(messageCS);
	}

	if (res) window.location = "/membership/userlogin.aspx";
	return false;

}

function FXChartsDownload(lang)
{
	switch (lang)
	{
		case "cs":
			{
				var mess = "Graf je dostupný pouze po řádné registraci do volně přístupné verze stránek www.patria.cz.\n\nPokud jste již registrovaným uživatelem www.patria.cz, musíte se nejprve přihlásit.";
				break;
			}
		case "en":
			{
				var mess = "This chart is free only for registered users of www.patria.cz. Please sign in or register to view trading details.";
				break;
			}
		case "sk":
			{
				var mess = "Graf je dostupný pouze po řádné registraci do volně přístupné verze stránek www.patria.cz.\n\nPokud jste již registrovaným uživatelem www.patria.cz, musíte se nejprve přihlásit.";
				break;
			}
		default:
			{
				var mess = "Na tuto službu nemáte oprávnění!";
				break;
			}
	}

	res = confirm(mess);
	if (res) window.location = "/membership/userlogin.aspx";
	return false;
}


function NoDownloadPD(lang)
{
	switch (lang)
	{
		case "cs":
			{
				var mess = "Tato analýza je určená výhradně klientům Patria Direct.\n\nPokud máte zájem stát se klientem Patria Direct, klikněte na OK.\n\nPokud nemáte o analýzu zájem, klikněte  Cancel/Storno.";
				break;
			}
		case "en":
			{
				var mess = "This analysis is only available to Patria Direct clients.\n\nIf you are interested in becoming a Patria Direct client, click on the OK button.\n\nIf you are not interested in downloading the analysis, please click on the Cancel/Storno button.";
				break;
			}
		case "sk":
			{
				var mess = "Táto analýza je určená výhradne klientom Patria Direct.\n\nAk máte záujem stať sa klientom Patria Direct, kliknite na OK.\n\nPokiaľ nemáte o analýzu záujem, kliknite na Cancel/Storno.";
				break;
			}
		default:
			{
				var mess = "Tato služba je součástí placeného informačního zdroje Patria Plus nebo Investor Plus.\n\nPokud jste klienty Patria Plus nebo Investor Plus a chcete se přihlásit, klikněte na OK.\n\nPokud nemáte o službu zájem, klikněte Cancel/Storno.";
				break;
			}
	}
	res = confirm(mess);
	if (res) window.open("https://www.patria-direct.cz/HomeOtevreniUctu.aspx", "PD", "menubar=1,resizable=1,width=800,height=600");
	return false;
}

function OpenDiscussion(message, url)
{
	if (isauthorized)
	{
		//var wndw = parent.document.body.clientWidth;
		//var wndh = parent.document.body.clientHeight;
		//wndw =Math.round((wndw-500)/2);
		//wndh =Math.round((wndh-348)/2);
		//        window.open(url,'_blank','channelmode=no,left='+wndw+',top='+wndh+',toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no,copyhistory=no');
		window.open(url, '_blank', 'channelmode=no,width=500,top=420,toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no,copyhistory=no');
	}
	else
	{
		res = confirm(message);
		if (res) window.location = "/membership/UserLogin.aspx";
	}
	return false;
}

var HelpWin = 0;
function openNewInstanceWindow(src, name, w, h)
{
	var strParameters = "height=" + h + ",width=" + w + ",resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no,directories=no";
	window.open(src, name, strParameters);
	return false;
}
function openNewWindow(src, name, w, h)
{
	if (HelpWin != 0) HelpWin.close();
	var strParameters = "height=" + h + ",width=" + w + ",resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no,directories=no";
	HelpWin = window.open(src, name, strParameters);
	return false;
}
function openNewWindowScroll(src, name, w, h)
{
	if (HelpWin != 0) HelpWin.close();
	var strParameters = "height=" + h + ",width=" + w + ",resizable=no,scrollbars=yes,directories=no,status=no,toolbar=no,menubar=no,location=no";
	HelpWin = window.open(src, '', strParameters);
	HelpWin.focus();
	return false;
}

function openNewMenuAdvertisementWindow(src, name)
{
	if (HelpWin != 0) HelpWin.close();
	HelpWin = window.open(src, '', '');
	HelpWin.focus();
	return false;
}

function openNewMenuAdvertisementWindowAndAddHit(src, name)
{
	if (HelpWin != 0) HelpWin.close();
	HelpWin = window.open(src, '', '');
	//_gde_ocomoxqqai = new Image(1,1);
	//_gde_ocomoxqqai.src='http://gdecz.hit.gemius.pl/hitredir/id=B82a1uMAo63UKv_86dem6eTl71YRAJrQv.2SiOYM3If.A7/stparam=umehhkknye/url=';
	AdClicked(10000); //1.4.2008 5560
	HelpWin.focus();
	return false;
}
function openNewMenuAdvertisementWindowAndAddHit2(src, name)
{
	if (HelpWin != 0) HelpWin.close();
	HelpWin = window.open(src, '', '');
	//    _gde_ocomoxqqai = new Image(1,1);
	//    _gde_ocomoxqqai.src='http://gdecz.hit.gemius.pl/hitredir/id=ncpAsf7pc9CL4KNDKmOZnschLU_wIAO6gXGi7GO3qz3.O7/stparam=vgjpdvhurp/url=';
	AdClicked(10001); //MT 10.11.2008 - sodex;   1.4.2008 5560
	HelpWin.focus();
	return false;
}

function openNewMenuAdvertisementING(src, name)
{
	window.location = "http://gdecz.hit.gemius.pl/hitredir/id=0iJK5m__a5gu9LHNl1I2eae1HUyIS_NyNzXyD1Du59..n7/stparam=uhjtpnoiui/url=http://www.patria.cz/News/994887/News/detail.html"
}



function openNewGraphWindow(src, name)
{
	return openNewWindow(src, '', '550', '390');

}
function openNewSendPPlusQuestionWindow(src)
{
	return openNewWindow(src, '', '550', '370');

}

function OpenNewDistributeLicenceWindow()
{
	return openNewWindowScroll('/membership/DistributeLicence.aspx', '', 600, 400);
}

var printWindow = null;
var printContent = null;
function CallPrint(strid)
{
	try
	{
	    printContent = document.getElementById(strid);
	    printContent.innerHTML = printContent.innerHTML.replace(/<DIV class=links>[\s\S]*<\/DIV>/i, '');
	    printContent.innerHTML = printContent.innerHTML.replace(/<script.*>[\s\S]*<\/script>/i, '');	    
	    printWindow = window.open('', '', 'width=600,height=400,toolbar=0,scrollbars=1,status=0,top=-1000,left=-1000');
	    var code = '' +
        //'printWindow.resizeTo(+10,+10);printWindow.moveTo(+10000,+10000);' +
		'printWindow.document.write(\'<html><head><title>Okno pro tisk</title>\');' +
		'printWindow.document.write(\'<link rel="stylesheet" type="text/css" href="/css/styles.css" />\');' +
		'printWindow.document.write(\'<link rel="stylesheet" type="text/css" href="/css/panel.css" />\');' +
		'printWindow.document.write(\'<link rel="stylesheet" type="text/css" href="/css/table.css" />\');' +
		'printWindow.document.write(\'<link rel="stylesheet" type="text/css" href="/RadControls/Combobox/Skins/ClassicSmall/Styles.css" />\');' +
		'printWindow.document.write(\'<link rel="stylesheet" type="text/css" href="/RadControls/Input/Skins/Patria/styles.css" />\');' +
        'printWindow.document.write(\'<link rel="stylesheet" type="text/css" href="/css/stylesPrint.css?_ts20110926" />\');' +
		'printWindow.document.write(\'<link rel="stylesheet" media="print" type="text/css" href="/css/stylesPrint.css?_ts20110926" />\');' +
		'printWindow.document.write(\'</head><body>\');' +
		'printWindow.document.write(\'<div id="centerColumn">\');' +
		'var s = \'<\' + printContent.tagName;' +
		'for (var f = 0; f < printContent.attributes.length; f++)' +
		'{' +
		'	if (printContent.attributes[f].value != null && printContent.attributes[f].value != \'null\' && printContent.attributes[f].value != 0 && printContent.attributes[f].value != \'false\')' +
		'	{' +
		'		var attrquot = \'\\\'\';' +
		'		if ((\'\' + printContent.attributes[f].value + \'\').indexOf(attrquot) > -1) attrquot = \'"\';' +
		'		s = s + \' \' + printContent.attributes[f].name + \'=\' + attrquot + printContent.attributes[f].value + attrquot;' +
		'	}' +
		'}' +
        's = s + \'>\';' +
        'printWindow.document.write(s);' +
        'printWindow.document.write(printContent.innerHTML);' +
		'printWindow.document.write(\'</\' + printContent.tagName + \'>\');' +
		'printWindow.document.write(\'</div>\');' +
		'printWindow.document.write(\'</body></html>\');' +
		'printWindow.document.close();' +
		'printWindow.focus();try{window.setTimeout(\'try{/*if(confirm(\\\'Start print?\\\'))*/{printWindow.focus();printWindow.print();}window.setTimeout(\\\'printWindow.close();\\\', 1500);}catch(e){;}\',1000);}catch(ex){;}' + 
'';
        
		window.setTimeout(code, 100);
	}
	catch (e) {alert(e); }
	return false;
}

function SearchEquityWorld(strRicId, strNameId, strType)
{
	var worldRIC = document.getElementById(strRicId);
	var worldName = document.getElementById(strNameId);
	openNewWindowScroll('/patriaplus/searchequity.aspx?ric=' + worldRIC.value + '&name=' + worldName.value + '&smstype=' + strType, 'Search', 500, 150);
}

function RedirectToParent(parentContent)
{
	return RedirectToParent(parentContent, true);
}

function RedirectToParent(parentContent, close)
{
	if (window.opener != null && window.opener != 'undefined') window.opener.location.href = parentContent;
	if (close) window.close();
	return false;
}

function SetCookie(cookieName, cookieValue, nDays)
{
	var today = new Date();
	var expire = new Date();
	if (nDays == null || nDays == 0) nDays = 1;
	expire.setTime(today.getTime() + 3600000 * 24 * nDays);
	document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
}


function CourseValidateSelection(value, secondCombo)
{
	var secondC = secondCombo;
	if (value != 'CZK' && secondC.GetText() != 'CZK')
	{
		var comboItem = secondC.FindItemByText('CZK');
		if (comboItem != null) comboItem.Select();
	}
	if (value == 'CZK' && secondC.GetText() == 'CZK')
	{
		var comboItem = secondC.FindItemByText('EUR');
		if (comboItem != null) comboItem.Select();
	}

}

function SendCancel(text)
{
	res = confirm(text);
	//if(res) window.location="/patriaplus";
	if (res) window.location = "/membership/userlogin.aspx";
	return false;
}

function CancelSelection(combo, defaultValue, defaultText) {    
    //combo.SelectedItem.Selected = 0;
    combo.ClearSelection();    
	combo.SetValue(defaultValue);
	combo.SetText(defaultText);
	var item = combo.FindItemByValue(defaultValue);
	if((item!=null)&&(item!='undefined'))   
	    item.Select();
	return false;
}

function DenySelection(combo, text, defaultValue, defaultText)
{
	alert(text);
	combo.SetValue(defaultValue);
	combo.SetText(defaultText);
	return false;
}

function CompareYieldSwitch(graphId, graphUrl, currCompute, currPrice, currUnit, depo, bond, equity)
{
	var graph = document.getElementById(graphId);
	if (graph != null)
	{
		graphUrl = graphUrl.replace('{0}', currCompute.GetValue());
		graphUrl = graphUrl.replace('{1}', currPrice.GetValue() + '/' + currUnit.GetValue());
		graphUrl = graphUrl.replace('{2}', depo.GetValue());
		graphUrl = graphUrl.replace('{3}', bond.GetValue());
		graphUrl = graphUrl.replace('{4}', equity.GetValue());
		graph.src = graphUrl;
	}
}

function ChangeYiledCompareGraph(graphId, graphUrl, curr1, curr2)
{
	var graph = document.getElementById(graphId);
	if (graph != null)
	{
		graphUrl = graphUrl.replace('{0}', curr1.GetValue());
		graphUrl = graphUrl.replace('{1}', curr2.GetValue());
		graph.src = graphUrl;
	}
}

function ChangeYiledCompareGlobalGraph(graphId, graphUrl, curr1, curr2, date1, date2)
{
	var graph = document.getElementById(graphId);
	if (graph != null)
	{
		graphUrl = graphUrl.replace('{0}', curr1.GetValue());
		graphUrl = graphUrl.replace('{1}', curr2.GetValue());
		graphUrl = graphUrl.replace('{2}', date1);
		graphUrl = graphUrl.replace('{3}', date2);
		graph.src = graphUrl;
	}
}

function ChangeMoneyMarketGraph(graphId, graphUrl, curr1)
{
	var graph = document.getElementById(graphId);
	if (graph != null)
	{
		graphUrl = graphUrl.replace('{0}', curr1.GetValue());
		graph.src = graphUrl;
	}
}

var requestAd;
function AdClicked(id)
{
	try
	{
		var requestAd = GetXmlHttpRequest()
		if (requestAd == null)
		{
			return;
		}
		var soap = '<?xml version="1.0" encoding="utf-8"?>';
		soap += '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
		soap += '<soap12:Body><TipClicked xmlns="http://tempuri.org/"><id>' + id + '</id></TipClicked></soap12:Body></soap12:Envelope>';
		requestAd.open("POST", '/onlinedataprovider.asmx', true);
		requestAd.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
		requestAd.setRequestHeader("Content-Length", soap.length);
		requestAd.send(soap);
		return;
	}
	catch (ex)
	{
		alert(ex.message);
	}
}

var requestTip;
function TipClicked(id)
{
	try
	{
		var requestTip = GetXmlHttpRequest()
		if (requestTip == null)
		{
			return;
		}
		var soap = '<?xml version="1.0" encoding="utf-8"?>';
		soap += '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
		soap += '<soap12:Body><TipClicked xmlns="http://tempuri.org/"><id>' + id + '</id></TipClicked></soap12:Body></soap12:Envelope>';
		requestTip.open("POST", '/onlinedataprovider.asmx', true);
		requestTip.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
		requestTip.setRequestHeader("Content-Length", soap.length);
		requestTip.send(soap);
		return;
	}
	catch (ex)
	{
		alert(ex.message);
	}
}

var requestFavorites;
function AddRemoveFavorites(action, type, id)
{
	try
	{
		requestFavorites = GetXmlHttpRequest()
		if (requestFavorites == null)
		{
			return;
		}
		var soap = '<?xml version="1.0" encoding="utf-8"?>';
		soap += '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
		soap += '<soap12:Body><AddRemoveFavorites xmlns="http://tempuri.org/"><action>' + action + '</action><type>' + type + '</type><identification>' + id + '</identification></AddRemoveFavorites></soap12:Body></soap12:Envelope>';
		requestFavorites.open("POST", '/onlinedataprovider.asmx', true);
		requestFavorites.onreadystatechange = AddFavoritesSend;
		requestFavorites.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
		requestFavorites.setRequestHeader("Content-Length", soap.length);
		requestFavorites.send(soap);
		return false;
	}
	catch (ex)
	{
		alert(ex.message);
	}
}

function AddFavoritesSend()
{
	if (requestFavorites.readyState == 4)
	{
		if (requestFavorites.status == "200")
		{
			window.location.reload();
		}
	}
}

function GetXmlHttpRequest()
{
	var request = null;
	try
	{
		request = new ActiveXObject("Msxml2.XMLHttp");
	}
	catch (e)
	{
		try
		{
			var tp = '.' + typeof (ActiveXObject) + '.';
			if (tp != '.undefined.')
			{
				request = new ActiveXObject("Microsoft.XMLHttp");
			}
		}
		catch (e2)
		{
		}
	}
	if (request == undefined && (typeof XMLHttpRequest != 'undefined'))
	{
		request = new XMLHttpRequest();
	}
	return request;
}

function SearchInPatria()
{
	var cond = document.getElementById('searchBarCondition').value;
	var url = '/others/search.aspx';
	if (cond != '')
		// chybne escapovani unicode znaku >>> url = '/others/search.aspx?page=1&condition=' + escape(document.getElementById('searchBarCondition').value) + '&conditionRegion=All&conditionSection=All&conditionPart=All&conditionGroupBy=Date&conditionGroupDirection=DESC';
        url = '/others/search.aspx?page=1&condition=' + encodeURIComponent(cond) + '&conditionRegion=All&conditionSection=All&conditionPart=All&conditionGroupBy=Date&conditionGroupDirection=DESC';
	window.location = url
	return false;
}

function SearchInPatriatexBoxEnter()
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13)
	{
		return SearchInPatria();
	}
}

function SetEnableForChildFormElements(parentElementId, enabled)
{
	var parentElement = document.getElementById(parentElementId);
	SetEnableForChildFormElementsInternal(parentElement, enabled);
}

function SetEnableForChildFormElementsInternal(parentElement, enabled)
{
	if (parentElement != null && parentElement.childNodes.length > 0)
	{
		for (var i = 0; i < parentElement.childNodes.length; i++)
		{
			if (parentElement.childNodes[i].tagName == 'INPUT' || parentElement.childNodes[i].tagName == 'SELECT')
			{
				parentElement.childNodes[i].disabled = !enabled;
			}
			else if (parentElement.childNodes[i].childNodes.length > 0)
			{
				SetEnableForChildFormElementsInternal(parentElement.childNodes[i], enabled);
			}
		}
	}
}

function replaceInPackage(packg, index, value)
{
	var strs = packg.split('|');
	strs[index] = value;
	packg = strs.join('|');
	return packg;
}

function GetDate(value, format)
{
	if ((value == null) || (value == 'undefined')) return NaN;

	var item = "";
	var itemval = "";
	format = format.replace("31", "D").replace("12", "M").replace("1990", "Y");
	var y = 1990;
	var m = 12;
	var d = 31;

	for (var f = 0; f < format.length; f++)
	{
		var c = format.substring(f, f + 1);
		switch (c)
		{
			case "Y":
			case "D":
			case "M":
				{
					item = c; break;
				}
			default:
				{
					var index = value.indexOf(c);
					if (index < 0)
					{
						itemval = value;
						value = "0";
					} else
					{
						itemval = value.substring(0, index);
						value = value.substring(index + 1, value.length);
					}
					switch (item)
					{
						case "Y": { y = itemval; item = ""; break; }
						case "M": { m = itemval; item = ""; break; }
						case "D": { d = itemval; item = ""; break; }
					}
				}
		}
	}
	switch (item)
	{
		case "Y": { y = value; item = ""; break; }
		case "M": { m = value; item = ""; break; }
		case "D": { d = value; item = ""; break; }
	}
	if ((d > 31) || (m > 12)) return NaN;
	return new Date(y + '/' + m + '/' + d);
}


/*--------------------- Popup links - start--------------------*/
/*--------------------- Popup links - start--------------------*/
/*--------------------- Popup links - start--------------------*/
/*
//   ##############  SIMPLE  BROWSER SNIFFER
if (document.layers) {navigator.family = "nn4"}
if (document.all) {navigator.family = "ie4"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {navigator.family = "gecko"}

overdiv="0";
//  #########  CREATES POP UP BOXES 
function popLayer(a,b,c){
if (navigator.family == "gecko") {pad="0"; bord="bordercolor=black";}
else {pad="1"; bord="0";}


desc = 	  "<table cellspacing=0 cellpadding="+pad+" border="+bord+"  bgcolor=828282><tr><td>\n"
+"<table cellspacing=0 cellpadding=0 border=0 width=100%>"	
//	+"<tr ><td style='border-bottom: 1px solid #46A5CD;' bgcolor=#ecf6fa>\n" 
//	+"<span style='padding-left:4px;text-align:left;'>Název: " + b + "</span><br/><span style='padding-left:4px;text-align:left;'>Trh: " + c + "</span></td></tr>"
+"<tr><td bgcolor=#f6fafc><center><font size=-1><img src=/graph/imggen.aspx?type=linkPopupOnline&amp;bckcolor=0xf6fafc&amp;ric=" + a + ">"
+"</td></tr></table>"
+"</td></tr></table>";
if(navigator.family =="nn4") {
document.linkPopup.document.write(desc);
document.linkPopup.document.close();
document.linkPopup.left=x-15;
document.linkPopup.top=y+2;
}
else if(navigator.family =="ie4"){
linkPopup.innerHTML=desc;
linkPopup.style.pixelLeft=x-15;
linkPopup.style.pixelTop=y+2;
}
else if(navigator.family =="gecko"){
document.getElementById("linkPopup").innerHTML=desc;
document.getElementById("linkPopup").style.left=x-15+ 'px';
document.getElementById("linkPopup").style.top=y+2+ 'px';
}
}
function hideLayer(){
if (overdiv == "0") {
if(navigator.family =="nn4") {eval(document.linkPopup.top="-500");}
else if(navigator.family =="ie4"){linkPopup.innerHTML="";}
else if(navigator.family =="gecko") {document.getElementById("linkPopup").style.top="-500px";}
}
}

//  ########  TRACKS MOUSE POSITION FOR POPUP PLACEMENT
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
function handlerMM(e){
x = (isNav) ? e.pageX : event.clientX + document.body.scrollLeft;
y = (isNav) ? e.pageY : event.clientY + document.body.scrollTop;
}
//if (isNav){document.captureEvents(Event.MOUSEMOVE);}
document.onmousemove = handlerMM;
*/
/*--------------------- Popup links - end--------------------*/
/*--------------------- Popup links - end--------------------*/
/*--------------------- Popup links - end--------------------*/

function CheckNumeric()
{
	// Get ASCII value of key that user pressed
	var key = window.event.keyCode;

	// Was key that was pressed a numeric character (0-9)?
	if (key > 47 && key < 58)
		return; // if so, do nothing
	else
		window.event.returnValue = null; // otherwise, 
	// discard character
}

// Function to repair click function generated by asp.net runtime for firefox.
// For example: it can be use for repair default button on asp:Panel.
function addClickFunction(id)
{
	var b = document.getElementById(id);
	if (b && typeof (b.click) == 'undefined')
	{
		b.click = function()
		{
			var result = true;

			if (b.onclick)
				result = b.onclick();

			if (typeof (result) == 'undefined' || result)
			{
				eval(b.getAttribute('href'));
			}
		}
	}
};
var PatriaDirectExternalOrderAvailable = true;
var PatriaDirectExternalOrderUrl = "https://www.patria-direct.cz/TradeOrder.aspx";
var PatriaDirectPortalUrl = "https://www.patria-direct.cz";
var PatriaDirectExternalOrderWelcomeCode = "POL";

function PatriaDirectCallTradeOrder(action, ric, isin, currency, exchange) {
    if (!PatriaDirectExternalOrderAvailable) {
        window.open(PatriaDirectPortalUrl, 'PatriaDirectWindow');
    } else {
        var width = 640;
        var height = 480;
        var top = Math.floor((screen.height - height) / 2);
        var left = Math.floor((screen.width - width) / 2);
        var url = PatriaDirectExternalOrderUrl + "?heading=" + action + "&ric=" + ric + "&isin=" + isin + "&currency=" + currency + "&exchange=" + exchange + "&LeadingPage=" + PatriaDirectExternalOrderWelcomeCode;
        var wnd = window.open(url, 'BusinessOrder', 'status=yes,toolbar=no,menubar=no,location=no,status=no,titlebar=no,resizable=no' + ',width=' + width + ',height=' + height + ',top=' + top + ',left=' + left);
        try { wnd.moveTo((screen.width - width) / 2, (screen.height - height) / 2); } catch (ex) { ; }
    }
}
function ChangeChartMode(chartType,identification) 
{
    if (chartType == null) return false;
    
    if (identification == null) return false;

    if (identification.indexOf("/") >= 0) {
        identification = identification.replace('/', '~');   
    }

    var imgChart = document.getElementById('charIndexSmall');
    var newURL = '';
    if (imgChart != null) {
        imgChart.src = '/images/loadingminichart.gif';
        switch (chartType) {
            case "1D":
                newURL = '/grafy/index/online/maly/1D/' + identification + '.jpg';
                break;
            case "5D":
                newURL = '/grafy/index/online/maly/5D/' + identification + '.jpg';
                break;
            default:
                newURL = '/grafy/index/online/maly/3D/' + identification + '.jpg';
                break;
        }   
    }

    if (newURL != '')
        window.setTimeout('var imgChart = document.getElementById(\'charIndexSmall\');imgChart.src = \'' + newURL + '\';', 50);
    return false;
}

