var imageWin;
function imgWin(imgSrc,pwidth,pheight,title) {
	var winw = (screen.width - pwidth) / 2;
	var winh = (screen.height - pheight) / 2;
	if (imageWin && imageWin.closed==false) {
		imageWin.close();
	}
		imageWin = open("/gfx/index.html", "pilt", "toolbar=no,directories=no,status=no,location=no,resizable=no,scrollbars=no,menubar=no,height="+pheight+",width="+pwidth+",top="+winh+",left="+winw+"");
		imageWin.document.open();
		imageWin.document.write("<html><head><title>" + title);
		imageWin.document.write("</title></head><body bgcolor=black scrolling=no marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>");
		imageWin.document.write("<table width=100% height=100% cellpadding=0 border=0 cellspacing=0><tr><td valign=middle align=center><a href='javascript:window.close()'><img src="+imgSrc+" width="+pwidth+" height="+pheight+" border=0></a></td></tr></table>");
		imageWin.document.write("</body></html>");
		imageWin.document.close();
	return false;
}
var banWin;
function bannerWin(imgSrc,url,pwidth,pheight,title) {
	var winw = (screen.width - pwidth) / 2;
	var winh = (screen.height - pheight) / 2;
	if (banWin) banWin.close();
	banWin = open("/gfx/index.html", "banWin", "toolbar=no,directories=no,status=no,location=no,resizable=no,scrollbars=no,menubar=no,height="+pheight+",width="+pwidth+",top="+winh+",left="+winw+"");
	banWin.document.open();
	banWin.document.write("<html><head><title>" + title);
	banWin.document.write("</title></head><body bgcolor=black scrolling=no marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>");
	banWin.document.write("<table width=100% height=100% cellpadding=0 border=0 cellspacing=0><tr><td valign=middle align=center><a href='javascript:parent.window.opener.location.href=\""+url+"\";window.close();'><img src="+imgSrc+" width="+pwidth+" height="+pheight+" border=0></a></td></tr></table>");
	banWin.document.write("</body></html>");
	banWin.document.close();
	return false;
}
var prWin;
function printWin() {
	var pwidth=650;
	var pheight=600;
	var winw = (screen.width - pwidth) / 2;
	var winh = (screen.height - pheight) / 2;
	var url = window.location.href+"?printable=true";
	if (prWin) prWin.close();
	prWin = window.open( url, "print", "toolbar=no,directories=no,status=no,location=no,resizable=yes,scrollbars=yes,menubar=yes,height="+pheight+",width="+pwidth+",top="+winh+",left="+winw+"");
	return false;
}
var camWindow;
function camWin() {
	var pwidth=320;
	var pheight=508;
	var winw = (screen.width - pwidth) / 2;
	var winh = (screen.height - pheight) / 2;
	if (camWindow && camWindow.closed==false) camWindow.close();
	camWindow = window.open( "/webcam/", "webcam", "toolbar=no,directories=no,status=no,location=no,resizable=no,scrollbars=no,menubar=no,height="+pheight+",width="+pwidth+",top="+winh+",left="+winw+"");
	//return false;
}
function newwindow(url) {
	window.open(url,"","");
}
	function getElement(formname,id) {
		var element;
		if (document.getElementById) {
			element = document.getElementById(id);
		} else if (document.all) {
			element = document.all[id];
		} else if (document.layers) {
			element = document.all[id];
		}
		return element;
	}

	function GetElement(id) {
		var element;
		if (document.getElementById) {
			element = document.getElementById(id);
		} else if (document.all) {
			element = document.all[id];
		} else if (document.layers) {
			element = document.all[id];
		}
		return element;
	}

	function hideLayer(id) {
		if (document.getElementById) {
			document.getElementById(id).style.visibility = 'hidden';
			document.getElementById(id).style.display = 'none';
		} else if (document.all) {
			document.all[id].style.visibility = 'hidden';
			document.all[id].style.display = 'none';
		} else if (document.layers) {
			document.layers[id].visibility = 'hidden';
			document.layers[id].display = 'none';
		}
	}
	function showLayer(id) {
		//var hh = 19 + 14*cnt;
		//captureMousePosition;
		if (document.getElementById) {
			document.getElementById(id).style.visibility = 'visible';
			document.getElementById(id).style.display = 'block';
			//if (yMousePos>0 && (yMousePos+hh)>yMousePosMax)
				//document.getElementById(id).style.marginTop = '-' + hh;
		} else if (document.all) {
			document.all[id].style.visibility = 'visible';
			document.all[id].style.display = 'block';
			//if (yMousePos>0 && (yMousePos+hh)>yMousePosMax)
				//document.all[id].style.marginTop = '-' + hh;
		} else if (document.layers) {
			document.layers[id].visibility = 'visible';
			document.layers[id].display = 'block';
			//if (yMousePos>0 && (yMousePos+hh)>yMousePosMax)
				//document.layers[id].marginTop = '-' + hh;
		}
	}
//**********************************************************
	function selectbox(id) {
		this.id = id;
		this.visible = false;
		this.selectItems = new Array();
		this.itemcount = 0;
		this.show = showSelect;
		this.hide = hideSelect;
		this.showhide = showhideSelect;
		this.makeSelect = makeNewSelect;
		this.addItem = addSelectItem;
		this.Delay = 300;
		this.timerID = null;
		this.stop = stopTimer;
		this.restart = restartTimer;
	}
	function addSelectItem(newid) {
		var i = this.itemcount;
		this.selectItems[i] = newid;
		this.itemcount++;
	}
	function showhideSelect() {
		if (this.visible)
			this.hide();
		else
			this.show();
	}
	function showSelect() {
		this.visible = true;
		showLayer(this.id,this.itemcount);
	}
	function hideSelect() {
		this.visible = false;
		hideLayer(this.id);
	}
	function makeNewSelect(sid) {
		for (var i=0; i<this.itemcount; i++) {
			hideLayer(this.selectItems[i]);
		}
		showLayer(sid);
	}
	function selectItem(ids) {
		this.ids = ids;
		alert(this);
	}
	function restartTimer(ref) {
		clearTimeout(this.timerID);
		this.timerID = setTimeout(ref+".hide()", this.Delay);
	}
	function stopTimer() {
		clearTimeout(this.timerID);
	}
//**********************************************************
		function showlistclass() {
			this.shows = new Array();
			this.movies = new Array();
			this.itemscount = 0;
			this.addShowItem = addShowItemF;
			this.selectShow = selectShowF;
			this.cbg = changeLayerBG;
		}
		function addShowItemF(ss,mm) {
			var i = this.itemscount;
			this.shows[i] = ss;
			this.movies[i] = mm;
			this.itemscount++;
		}
		function selectShowF(movieID,bg1,bg2) {
				for (var i=0; i<this.itemscount; i++) {
					if (this.movies[i]!=movieID) {
						this.cbg("show"+this.shows[i], bg1);
					} else {
						this.cbg("show"+this.shows[i], bg2);
					}
				}
		}
		function changeLayerBG (id,color) {
			if (document.getElementById) {
				document.getElementById(id).style.background = color;
			} else if (document.all) {
				document.all[id].style.background = color;
			} else if (document.layers) {
				document.layers[id].background = color;
			}
		}
	function formChangeLocation(formName,changeObj,automatic) {
		var cntrselect = getElement(formName, "countryselect");
		var selectedCountry = cntrselect.value;
		var regselect = getElement(formName, "regionselect");
		var selectedRegion = regselect.value;
		var citselect = getElement(formName, "cityselect");
		var selectedCity = citselect.value;
		var regions = new Array();
		var regionsID = new Array();
		regions.length = 0;
		regionsID.length = 0;
		regions = arrRegionName[selectedCountry];
		regionsID = arrRegionID[selectedCountry];
		if (changeObj=='country') {
			if (regselect)
			regselect.options.length=0;
		}
		citselect.options.length=0;
		if (regions && changeObj=='country') {
			var len = regions.length;
			var length=0;
			for (var i=0; i<len; i++) {
				if (regionsID[i] == selectedRegion) {
					regselect.options[length++]=new Option(regions[i], regionsID[i], false, true);
				} else {
					regselect.options[length++]=new Option(regions[i], regionsID[i], false);
				}
			}
			regselect.style.width = '150';
		}
		if (automatic==1) {
			regselect.value = selectedRegion;
		} else {
			selectedRegion = regselect.value;
		}
		var cities = new Array();
		var citiesID = new Array();
		cities.length = 0;
		citiesID.length = 0;
		cities = arrCityName[selectedRegion];
		citiesID = arrCityID[selectedRegion];
		citselect.options.length=0;
		if (cities) {
			var len = cities.length;
			var length=0;
			var isCity = 0;
			for (var i=0; i<len; i++) {
				if (citiesID[i] == selectedCity) {
					isCity = 1;
					citselect.options[length++]=new Option(cities[i], citiesID[i], false, true);
				} else {
					citselect.options[length++]=new Option(cities[i], citiesID[i], false);
				}
			}
			citselect.style.width = '150';
			if (isCity==1) citselect.value = selectedCity;
		}
	}
var tsWin;
function MCS_ticketSaleWindow(baseurl, showID,sessID, PriceClasses, AmountSmallMsg, AmountBigMsg) {
        pwidth=750;
        pheight=600;
        var screenwidth = 800;
        var screenheight = 600;
        if (parseInt(screen.width,10)>0) screenwidth = screen.width;
        if (parseInt(screen.height,10)>0) screenheight = (screen.height-100);
        var winw = (screenwidth - pwidth) / 2;
        var winh = 0;
        if (pheight<screenheight) pheight=(screenheight-10);
	var totalAmount = 0;
	var $priceArr = new Array();
	var prices = '';
	if (PriceClasses) {
		$priceArr = PriceClasses;
		var c = $priceArr.length;
		var i = 0;
		var u = 0;
		while (i<c) {
			var priceClass = $priceArr[i];
			var priceField = getElement( 'showbookingform', 'price' + priceClass );
			if (priceField) {
				var amount = parseInt(priceField.value,10);
				if (amount>0) {
					totalAmount = parseInt(totalAmount+amount,10);
					if (u>0) prices = prices + '&';
					prices = prices + 'price' + priceClass + '=' + amount;
					u++;
				}
			}
			i++;
		}
	}
	var url = baseurl+'/'+showID+'/sell/'+sessID+'/?'+prices;
	if (tsWin && tsWin.closed==false) tsWin.close();
	if (parseInt(totalAmount,10)==0) {
		alert(AmountSmallMsg);
	} else if (parseInt(totalAmount,10)>0 && parseInt(totalAmount,10)>6) {
		alert(AmountBigMsg);
	} else {
		tsWin = window.open( url, "tsWindow"+sessID+"", "toolbar=no,directories=no,status=yes,location=no,resizable=yes,scrollbars=yes,menubar=no,height="+pheight+",width="+pwidth+",top="+winh+",left="+winw+"");
	}
	return false;
}
function MCS_ticketBronWindow(baseurl, showID,sessID, PriceClasses, AmountSmallMsg, AmountBigMsg) {
        pwidth=750;
        pheight=600;
        var screenwidth = 800;
        var screenheight = 600;
        if (parseInt(screen.width,10)>0) screenwidth = screen.width;
        if (parseInt(screen.height,10)>0) screenheight = (screen.height-100);
        var winw = (screenwidth - pwidth) / 2;
        var winh = 0;
        if (pheight<screenheight) pheight=(screenheight-10);
	var totalAmount = 0;
	var $priceArr = new Array();
	var prices = '';
	if (PriceClasses) {
		$priceArr = PriceClasses;
		var c = $priceArr.length;
		var i = 0;
		var u = 0;
		while (i<c) {
			var priceClass = $priceArr[i];
			var priceField = getElement( 'showbookingform', 'price' + priceClass );
			if (priceField) {
				var amount = parseInt(priceField.value,10);
				if (amount>0) {
					totalAmount = parseInt(totalAmount+amount,10);
					if (u>0) prices = prices + '&';
					prices = prices + 'price' + priceClass + '=' + amount;
					u++;
				}
			}
			i++;
		}
	}
	var url = baseurl+'/'+showID+'/bron/'+sessID+'/?'+prices;
	if (tsWin && tsWin.closed==false) tsWin.close();
	if (parseInt(totalAmount,10)==0) {
		alert(AmountSmallMsg);
	} else if (parseInt(totalAmount,10)>0 && parseInt(totalAmount,10)>6) {
		alert(AmountBigMsg);
	} else {
		tsWin = window.open( url, "tsWindow"+sessID+"", "toolbar=no,directories=no,status=yes,location=no,resizable=yes,scrollbars=yes,menubar=no,height="+pheight+",width="+pwidth+",top="+winh+",left="+winw+"");
	}
	return false;
}
var brWin;
function MCS_ticketBronView(baseurl,num) {
        pwidth=750;
        pheight=600;
        var screenwidth = 800;
        var screenheight = 600;
        if (parseInt(screen.width,10)>0) screenwidth = screen.width;
        if (parseInt(screen.height,10)>0) screenheight = (screen.height-100);
        var winw = (screenwidth - pwidth) / 2;
        var winh = 0;
        if (pheight<screenheight) pheight=(screenheight-10);
	var url = baseurl+'/'+num+'/';
	if (brWin && brWin.closed==false) brWin.close();
		brWin = window.open( url, "brWindow", "toolbar=no,directories=no,status=yes,location=no,resizable=yes,scrollbars=yes,menubar=no,height="+pheight+",width="+pwidth+",top="+winh+",left="+winw+"");
	return false;
}
function doFocus() {
	if (tsWin && tsWin.closed==false) {
		//tsWin.focus();
	}
}
function HtmlDecode(s) {
      var out = "";
      if (s==null) return out;
      var l = s.length;
      for (var i=0; i<l; i++) {
            var ch = s.charAt(i);
            if (ch == '&') {
                  var semicolonIndex = s.indexOf(';', i+1);
            	    if (semicolonIndex > 0) {
                        var entity = s.substring(i + 1, semicolonIndex);
                        if (entity.length > 1 && entity.charAt(0) == '#') {
                              if (entity.charAt(1) == 'x' || entity.charAt(1) == 'X')
                                    ch = String.fromCharCode(eval('0'+entity.substring(1)));
                              else
                                    ch = String.fromCharCode(eval(entity.substring(1)));
                        }
                        i = semicolonIndex;
                  }
         	}
         	out += ch;
      }
      return out;
}



var idWin;
function idCardLogin(url) {
        pwidth=400;
        pheight=200;
        var screenwidth = 800;
        var screenheight = 600;
        if (parseInt(screen.width,10)>0) screenwidth = screen.width;
        if (parseInt(screen.height,10)>0) screenheight = (screen.height-100);
        var winw = (screenwidth - pwidth) / 2;
        var winh = (screenheight - pheight) / 2;

	if (idWin && idWin.closed==false) idWin.close();
		idWin = window.open( url, "idWindow", "toolbar=no,directories=no,status=yes,location=no,resizable=yes,scrollbars=yes,menubar=no,height="+pheight+",width="+pwidth+",top="+winh+",left="+winw+"");
	return false;
}


function mcsTicketsalesWindowFormSubmit(formPrices,PriceClasses,AmountSmallMsg,AmountBigMsg,maxAmount) {
	if (!maxAmount) maxAmount = 6;
	if (formPrices) {

		var totalAmount = 0;
		var $priceArr = new Array();
		if (PriceClasses) {
			$priceArr = PriceClasses;
			var c = $priceArr.length;
			var i = 0;
			var u = 0;
			while (i<c) {
				var priceClass = $priceArr[i];
				var priceField = GetElement( 'price' + priceClass );
				if (priceField) {
					var amount = parseInt(priceField.value,10);
					if (amount>0) {
						totalAmount = parseInt(totalAmount+amount,10);
						u++;
					}
				}
				i++;
			}
		}

		if (parseInt(totalAmount,10)==0) {
			alert(HtmlDecode(AmountSmallMsg));
		} else if (parseInt(totalAmount,10)>0 && parseInt(totalAmount,10)>maxAmount) {
			alert(HtmlDecode(AmountBigMsg));
		} else {
   	        pwidth=750;
	        pheight=600;
	        var screenwidth = 800;
	        var screenheight = 600;
	        if (parseInt(screen.width,10)>0) screenwidth = screen.width;
	        if (parseInt(screen.height,10)>0) screenheight = (screen.height-100);
	        var winw = (screenwidth - pwidth) / 2;
	        var winh = 0;
	        if (pheight<screenheight) pheight=(screenheight-10);

			try {
				window.open('', "mcsTicketsalesWindow", "toolbar=no,directories=no,status=yes,location=no,resizable=yes,scrollbars=yes,menubar=no,height="+pheight+",width="+pwidth+",top="+winh+",left="+winw+"");
			} catch(e) {}
			formPrices.target = "mcsTicketsalesWindow";
	  		formPrices.submit();
		}
	}
	return false;
}


function toggleElementVisible(elementID, isVisible)
{
	el = GetElement(elementID);
	if (el)
	{
		if (isVisible)
		{
			el.style.visibility = 'visible';
			el.style.display = '';
		}
		else
		{
			el.style.visibility = 'hidden';
			el.style.display = 'none';
		}
	}
}

function toggleBirthdayAndGenderFields()
{
	
	var elIDCodeShow = GetElement('profileForm_personalCodeShow');
	var elIDCode = GetElement('profileForm_personalCode');
	
	if (elIDCodeShow && elIDCode)
	{
		if (elIDCodeShow.checked)
		{
			//elIDCode.oldValue = elIDCode.value; 
			//elIDCode.value = '';
			elIDCode.disabled = true;
			
			toggleElementVisible('profileForm_birthday_row', true);
			toggleElementVisible('profileForm_birthday_error_row', true);
			toggleElementVisible('profileForm_gender_row', true);
			toggleElementVisible('profileForm_gender_error_row', true);
			
			toggleElementVisible('profileForm_personalCodeShowComment_row', true);
			
			toggleElementVisible('profileForm_personalCode_error_row', false);
		}
		else
		{
			//if (elIDCode.oldValue) elIDCode.value = elIDCode.oldValue; 
			elIDCode.disabled = false;
			
			toggleElementVisible('profileForm_birthday_row', false);
			toggleElementVisible('profileForm_birthday_error_row', false);
			toggleElementVisible('profileForm_gender_row', false);
			toggleElementVisible('profileForm_gender_error_row', false);
			
			toggleElementVisible('profileForm_personalCodeShowComment_row', false);
			
			toggleElementVisible('profileForm_personalCode_error_row', true);
		}
	}
}

var countDownTimer;
function timeCountDown(id,secondsRemaining,tmTimeout)
{
	if (secondsRemaining < 0)
	{
    	updateCountDownLabel(id,0);
    }
    else
    {
		if (countDownTimer) clearTimeout(countDownTimer);
		
   		var dt;
   		var tm;

   		if (!tmTimeout || tmTimeout==0)
   		{
	   		dt=new Date();
	   		tm=dt.getTime();
   			tmTimeout = (tm + (secondsRemaining * 1000));
   		}	
    	

		if (!dt) 
		{
		   	dt=new Date();
		   	tm=dt.getTime();
		}
		secondsRemaining = Math.floor((tmTimeout - tm) / 1000);
				 
    	updateCountDownLabel(id,secondsRemaining);

    	countDownTimer = setTimeout('timeCountDown(\''+id+'\','+secondsRemaining+','+tmTimeout+');',1000);
    }
}

function updateCountDownLabel(id,seconds)
{
	var elLabel = document.getElementById(id);
	if (elLabel)
	{ 

		elLabel.innerHTML = formatCountDown(seconds);

		if (seconds <= 0)
		{
			elLabel.style.color = 'red';
			if (window.paymentWindow && !window.paymentWindow.closed)
			{
				window.paymentWindow.close();
			}
		}		
	}
}

function formatCountDown(sec)
{
	var s = '00:00:00';
	if (sec > 0)
	{
		var minutes = '00';
		var hours = '00';
		var seconds = '00';
		
		hours = ((Math.floor(sec/3600))%60).toString();
		minutes = ((Math.floor(sec/60))%60).toString();
		seconds = ((Math.floor(sec))%60).toString();
		
		if (hours.length < 2) hours = '0'+hours;
		if (minutes.length < 2) minutes = '0'+minutes;
		if (seconds.length < 2) seconds = '0'+seconds;
		
		s = hours + ':' + minutes + ':' + seconds; 
	}
	return s;
}

function openPaymentWindow(url,windowName,width,height)
{
	var windowHeight = height;
	var windowWidth = width;
	var windowTop = 0;
	var windowLeft = 0;
	
	var screenWidth = 800;
	var screenHeight = 600;
    if (window.screen && parseInt(window.screen.width,10)>0) screenWidth = window.screen.width;
	if (window.screen && parseInt(window.screen.height,10)>0) screenHeight = (window.screen.height-100);
	

	windowLeft = (screenWidth - windowWidth) / 2;
	windowTop = (screenHeight - windowHeight) / 2;

	if (windowHeight>(screenHeight-30)) windowHeight=(screenHeight-30);

	try
	{
		if (window.name=='') window.name = "mainWindow";
		if (window.paymentWindow && !window.paymentWindow.closed)
		{
			window.paymentWindow.close();
		}

		window.paymentWindow = window.open(url,windowName,'toolbar=no,directories=no,status=yes,location=yes,resizable=yes,scrollbars=yes,menubar=yes,height='+windowHeight+',width='+windowWidth+',top='+windowTop+',left='+windowLeft+',screenX='+windowLeft+',screenY='+windowTop+'');
		//window.paymentWindow = window.open(url,windowName,'toolbar=yes,directories=yes,status=yes,location=yes,resizable=yes,scrollbars=yes,menubar=yes,height='+windowHeight+',width='+windowWidth+',top='+windowTop+',left='+windowLeft+',screenX='+windowLeft+',screenY='+windowTop+'');
		window.paymentWindow.focus();
		
		return true;

		
	} catch(e) {}
	return false;		
}






function checkShoppingCartStatus(url,intervalSeconds,isExecute)
{
	if (isExecute)
	{
   		var dt=new Date();
   		var tm=dt.getTime();
   		var urlGet = url + '&_t=' + tm;
   		
   		if (xmlhttp)
   		{
		 xmlhttp.open("GET", urlGet, true);
		 xmlhttp.onreadystatechange=function() {
		  if (xmlhttp.readyState==4) {
		  	responseText = xmlhttp.responseText;
		  	
		  	if (responseText.length>1)
		  	{
			  	var response = responseText.split(' ');
			  	if (response[0] && response[0]=='OK')
			  	{
				  	if (response[1] && response[1].length>0)
				  	{
				  		var urlNew = response[1];
				  		document.location.href=urlNew;
				  	}
			  	}
			}
			setTimeout('checkShoppingCartStatus(\''+url+'\','+intervalSeconds+',true);',intervalSeconds*1000);
		  }
		 }
		 xmlhttp.send(null);
		 }
	}
	else
	{
		setTimeout('checkShoppingCartStatus(\''+url+'\','+intervalSeconds+',true);',intervalSeconds*1000);
	} 
}

