﻿//check current language
var thislang = "tc";
var thisURL = window.location.toString();

if(thisURL.indexOf("lang=") > -1)
	thislang = thisURL.substring(thisURL.indexOf("lang=")+5,thisURL.indexOf("lang=")+7)

// JScript File
var intRB = 0;

function bookingSystem(lang)
{
	if(lang == "en")
		swf = "http://www.ghticket.com/epayment/mini/epayment_hk_small_eng.swf";
	else
		swf = "http://www.ghticket.com/epayment/mini/epayment_hk_small_chi.swf";
	
	swfObj = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="380" id="epayment_hk_small_eng" align="middle">';
	swfObj += '<param name="allowScriptAccess" value="always" />';
	swfObj += '<param name="movie" value="'+ swf +'" /><param name="quality" value="high" /><param name="bgcolor" value="#cccccc" />';
	swfObj += '<embed src="'+swf+'" quality="high" bgcolor="#cccccc" width="380" name="epayment_hk_small_eng" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	swfObj += '</object>';
	
	document.getElementById("div_booking").innerHTML = swfObj;
}

function scroll()
{
	var div_board = document.getElementById("board");
	var div_rollboard = document.getElementById("rollboard");
	var nHeight = div_board.offsetHeight * -1;
	var oneStep = 1;
	//div_board.style.top = 0;
	//alert(div_board.offsetTop + "xx");
	//alert(div_board.offsetHeight + "|" + div_board.style.top);
	
	t = parseInt(div_board.offsetTop,10);
	
	if(isNaN(t))
		t = 0;
	
	if(t - oneStep <= nHeight)
	{
		//div_board.style.top  = (div_rollboard.offsetHeight - oneStep) + "px";
		div_board.style.top = "80px";	//reset position
	}
	else
	{
		div_board.style.top = (t - oneStep) + "px";
	}
	
	//var height = myDiv.style.height;
	//height = height.split("px")[0];
	/*
	if(parseInt(div_board.style.top) > -350)
	{
		div_board.style.top = parseInt(div_board.style.top) - 2
	}
	else
	{
		div_board.style.top = parseInt(div_board.style.top) + 670
	}
	*/
}

function getHttp()
{
	var xmlHttp;
	
	try
	{	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{	// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

/*
//----- NAV Cinema List (Start) ------//
var cinemaListOver = false;
var tobj;

function showCinemalist(lang)
{
	//alert("welcome");
	var html = '';
	if(lang == "en")
	{
		html += '<div class="cinemaMenuList1" style="width:120px; font-size: 12px;" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=grand_ocean&lang=en">GRAND OCEAN</a></div>';
		html += '<div class="cinemaMenuList2" style="width:120px; font-size: 12px;" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gateway&lang=en">GOLDEN GATEWAY</a></div>';
		html += '<div class="cinemaMenuList1" style="width:120px; font-size: 12px;" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gh_mk&lang=en">GH MONGKOK</a></div>';
		html += '<div class="cinemaMenuList2" style="width:120px; font-size: 12px;" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gh_hw&lang=en">GH HOLLYWOOD</a></div>';
		html += '<div class="cinemaMenuList1" style="width:120px; font-size: 12px;" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gh_ty&lang=en">GH TSING YI</a></div>';
		html += '<div class="cinemaMenuList2" style="width:120px; font-size: 12px;" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gh_citywalk&lang=en">GH Citywalk</a></div>';
		html += '<div class="cinemaMenuList1" style="width:120px; font-size: 12px;" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gh_whampoa&lang=en">GH Whampoa</a></div>';
	}
	else
	{
		html += '<div class="cinemaMenuList1" style="width:120px" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=grand_ocean&lang=tc">海運戲院</a></div>';
		html += '<div class="cinemaMenuList2" style="width:120px" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gateway&lang=tc">嘉禾港威電影城</a></div>';
		html += '<div class="cinemaMenuList1" style="width:120px" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gh_mk&lang=tc">嘉禾旺角電影城</a></div>';
		html += '<div class="cinemaMenuList2" style="width:120px" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gh_hw&lang=tc">嘉禾荷里活電影城</a></div>';
		html += '<div class="cinemaMenuList1" style="width:120px" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gh_ty&lang=tc">嘉禾青衣電影城</a></div>';
		html += '<div class="cinemaMenuList2" style="width:120px" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gh_citywalk&lang=tc">嘉禾荃新天地</a></div>';
		html += '<div class="cinemaMenuList1" style="width:120px" onmouseover="setMouseOver()" onmouseout="setMouseOut()"><a href="/booking/cinema.aspx?cinema=gh_whampoa&lang=tc">嘉禾黃埔</a></div>';
	}
	
	document.getElementById("cinemaMenu").innerHTML = html;
	document.getElementById("cinemaMenu").style.display = "block";
	clearTimeout(tobj);
}

function hidelist()
{
	if(!cinemaListOver)
		document.getElementById("cinemaMenu").style.display = "none";
}

function hideCinemalist()
{
	tobj = setTimeout('hidelist()',1000);
}

function setMouseOver()
{
	cinemaListOver = true;
	clearTimeout(tobj);
}

function setMouseOut()
{
	cinemaListOver = false;
	hideCinemalist();
}

//----- NAV Cinema List (End) ------//
*/

//----- Rotate Banner (Start) ---------//
var films = new Array();
var current_film = 0;

var jetSos = new Array();
var current_jetSo = 0;

var vBanners = new Array();
var currentBanner = 0;

var hBanners = new Array();
var currentTopBanner = 0;

function rotateFilm_add(img, id, desc)
{
	//films[films.length] = '<a href="coming.aspx?movie_id=' + id + '">' + '<img src="' + img + '" border=0 height="105" style="padding:3px;float:left" align="left" />' + '</a>' + desc + '';
	films[films.length] = '<a href="coming.aspx?movie_id=' + id + '&lang=' + thislang + '">' + '<img src="' + img + '" border=0 height="240" style="margin:10px 0 10px 0; padding:3px; border:1px solid #CCCCCC;" />' + '</a><br /><div style="text-align:left;">' + desc + '</div>';
	//alert(films[films.length]-1);
}

//Add rotateBanner list for rotate banner in right hand side
function rotateBanner_add(hstr)
{
	vBanners[vBanners.length] = hstr;
}

function rotateTopBanner_add(hstr)
{
	hBanners[hBanners.length] = hstr;
}

//Display a single , not rotate banner for header
function rotateBanner_show(hstr)
{
	document.writeln(hstr);
}

//Rotate action for banner in right hand side
function rotateBanner()
{
	var p = currentBanner + 1;
	
	if(p >= vBanners.length)
		p=0;
	
	if(document.getElementById('right_banner'))
		document.getElementById('right_banner').innerHTML = vBanners[p];
	
	currentBanner = p;
}

function rotateTopBanner()
{
	var q = currentTopBanner + 1;
	
	if(q >= hBanners.length)
		q=0;
	
	if(document.getElementById('top_banner'))
		document.getElementById('top_banner').innerHTML = hBanners[q];
	
	currentTopBanner = q;
}

function rotateFilm()
{
	var p = current_film + 1;
	
	if(p >= films.length)
		p=0;
	
	if(document.getElementById('div_filmlist'))
		document.getElementById('div_filmlist').innerHTML = films[p];
	
	current_film = p;
}

function addJetSo(url,target,name,photo)
{
	//jetSos[jetSos.length] = "<div style='padding:4px'><a href=\"" + url + "\" target=\""+ target +"\">" + "<img src=\"" +photo + "\" border=\"0\" height=\"70px\" align='left' style='padding:3px' /><span style='font-weight:bold'>" + name + "</span></a></div>";
	
	//add jetso to films's cell to rotate, <a> script detail copy from function rotateFilm_add()
	films[films.length] = '<a href="' + url + '" target="' + target + '">' + '<img src="' + photo + '" border="0" height="240" style="margin:10px 0 10px 0; padding:3px; border:1px solid #CCCCCC;" />' + '</a><br /><div style="font-weight:bold">' + name + '</div>';
}

function rotateJetSo()
{
	var p = current_jetSo + 1;
	
	if(p >= jetSos.length)
		p=0;
	
	document.getElementById('div_jetso').innerHTML = jetSos[p];
	
	current_jetSo = p;
}

function rotateStart()
{
	if(films.length > 0 && document.getElementById('div_filmlist'))
	{
		document.getElementById('div_filmlist').innerHTML = films[0];        
		setInterval("rotateFilm()",4000);
	}
	if(jetSos.length > 0 &&  document.getElementById('div_jetso'))
	{
		document.getElementById('div_jetso').innerHTML = jetSos[0];
		setInterval("rotateJetSo()",4000);
	}
	if(vBanners.length > 0 && document.getElementById('right_banner'))
	{
		document.getElementById('right_banner').innerHTML = vBanners[0];
		setRotateBanner(true);
	}
	if(hBanners.length > 0 && document.getElementById('top_banner'))
	{
		document.getElementById('top_banner').innerHTML = hBanners[0];
		setRotateBanner(true);
	}
}

function setRotateBanner(isStart)
{
	if(isStart)
	{
		if(intRB == 0)
		{
			if(vBanners.length > 1)
				intRB = setInterval("rotateBanner()",4000);
			else
				rotateBanner();
			
			if(hBanners.length > 1)
				intRB = setInterval("rotateTopBanner()",4000);
			else
				rotateTopBanner();
		}
	}
	else
	{
		clearInterval(intRB);
		intRB = 0;
	}
}

function trailerAdd(trailerURL, trailerType, location)
{
	var FLVclassid ='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
	var FLVcodebase = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
	var ASXclassid = 'CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6';
	var width = "280";
	var height = "240";
	var html = "";
	
	if(location == "inner")
		swf_file = "swf/trailer_innerpage.swf";
	else
		swf_file = "swf/trailer.swf";
	
	if(trailerType == 'flv')
	{
		html = '<object classid="' + FLVclassid + '" codebase="' + FLVcodebase +'" width="' + width + '" height="' + height + '" id="trailer" align="center">';
		html += '    <param name="allowScriptAccess" value="sameDomain" />';
		html += '    <param name="movie" value="' + swf_file + '" />';
		
		html += '    <param name="quality" value="high" />';
		html += '    <param name="bgcolor" value="#000000" />';
		html += '    <param name="FlashVars" VALUE="url=' + trailerURL + '">';
		html += '    <embed src="' + swf_file + '" flashVars="url=' + trailerURL + '" quality="high" bgcolor="#000000"'  +'" width="' + width + '" height="' + height + '" name="trailer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		html += '</object>';
	}
	else if(trailerType == 'asx')
	{
		html = '<OBJECT id="VIDEO" CLASSID="" type="application/x-oleobject" width="' + width + '" height="' + height + '" align="middle">';
		html += '   <PARAM NAME="URL" value="' + trailerURL + '" />';
		html += '   <PARAM NAME="AutoStart" VALUE="True">';
		html += '   <embed name="video" src="' + trailerURL + '" width="' + width + '" height="' + height + '"></embed>';
		html += '</OBJECT>';
	}
	document.getElementById('divTrailer').innerHTML = html;
}
//----- Rotate Banner (End) ---------//

//----- VIP (Start) ---------//
var numberOfFilm = 4;

function buyTicket(film_id,cinema,lang)
{
	var list = document.getElementById("select_" + film_id);
	//alert(list);
	if(list)
		window.location.href = list.options[list.selectedIndex].value;
		//document.write(list.options[list.selectedIndex].value);
} 
//----- VIP (End) ---------//

//----nowshowing
function showTrailer(url)
{
	if(url != "")
		window.open("trailer.aspx?trailer=" + url,"trailer","width=280,height=240");
}

//---- Cinema / Nowshowing
function getOptionList(film_id,cinema_id,lang)
{
	var wsURL = "WebService.asmx/GetFilmOptionList?film_id=" + film_id + "&cinema=" + cinema_id + "&lang=" + lang;
	var wsHttp = getHttp();        
	if(wsHttp)
	{
		wsHttp.onreadystatechange=function()
		{
			if(wsHttp.readyState==4)
			{
				var xmlDoc=wsHttp.responseXML.documentElement;
				document.getElementById("list_" + film_id + "_" + cinema_id).innerHTML = xmlDoc.childNodes[0].nodeValue;
			}
		}
		wsHttp.open("GET",wsURL,true);
		wsHttp.send(null);
	}
}

function buyTicket(film_id,cinema,lang)
{
	var list = document.getElementById("select_" + film_id + "_" + cinema); //NEW 
	//var list = document.getElementById("select_" + film_id);
	if(list)
	{
		var listvalue = list.options[list.selectedIndex].value;
		
		if(listvalue != "")
			window.location.href = listvalue;
	}
}

/* Banner System - JS: Stop all Error Alert */
function stopError()
{
	return true;
}
window.onerror = stopError;

/* Banner System : JS : Opening a new Window (Simple Version)
 * 
 * Example: 
 *      HREF="javascript:NewWin('pageurl','title', '640','480','no')"
 * 
 * Syntax:
 *      NewWin(windowtitle,pageurl,width,height,scrollbar,resizable)
 * --------------------------------------------------------------------	*/
var neWin = null;

function NewWin(mypage,myname,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
	neWin = window.open(mypage,myname,settings);
	
	if(neWin.window.focus)
		neWin.window.focus();
}


