var xmlns = 'http://www.w3.org/1999/xhtml';

/* Internet Explorer... */
if(!document.createElementNS)
{
	document.createElementNS = function(ns, el)
	{
		return document.createElement(el);
	};
}

/*if(!window.DOMInitialised)
  {
  Event.onDOMReady(init);
  }
  else
  {
  window.setTimeout(init, 1);
  }
 */
function init()
{
	$A(document.getElementsByClassName('popup')).each(function(obj) { Event.observe(obj, 'click', popup, false); });
	if($('page_content'))
	{
		var links = $('page_content').getElementsByTagName('a');
		if(document.getElementsByTagName('base').length > 0)
		{
			var linkRe = new RegExp("^" + document.getElementsByTagName('base')[0].href + "(?!\/?external)");
		}
		else
		{
			var linkRe = new RegExp("^(https?\:\/\/|external)");
		}

		for(var i = links.length - 1; i >= 0; i--)
		{
			if(links[i].href && !linkRe.test(links[i].href))
			{
				Event.observe(links[i], 'click', popup, false);
			}
		}
	}

	if($('signup_email'))
	{
		$('signup_email').observe('blur', checkSignupBgImage, false);

		checkSignupBgImage('signup_email');
	}
};

/**
 * Pop up a link in a new window.
 * @param evt Event
 */
function popup(evt)
{
	var el = Event.element(evt);

	do
	{
		if(/a/i.test(el.tagName))
		{
			window.open(el.href, null);
			Event.stop(evt);
			break;
		}
	}
	while(el = el.up());
};

/**
 * Ensure that there is no background image when there is text in the field.
 * @param evt Event|String
 */
function checkSignupBgImage(evt)
{
	if(typeof evt == 'string')
	{
		var tgt = $('signup_email');
	}
	else
	{
		var tgt = Event.element(evt);
	}

	if(tgt.value == '')
	{
		tgt.style.backgroundImage = '';
	}
	else
	{
		tgt.style.backgroundImage = 'none';
	}
};

function hide(id){
	var close = document.getElementById(id);
	close.style.visibility='hidden';
	close.style.display = "none";


};


function hide_menu(num){
	var close = document.getElementById('subnav_'+num);
	close.style.visibility='hidden';


};

function show_menu(num){
	var show = document.getElementById('subnav_'+num);
	show.style.visibility='visible';

};

var IE = document.all?true:false
var offsetx = 0
	var offsety = 0
function partner_hover(id, event)
{
	var show = document.getElementById('partner_hover_'+id);
	show.style.visibility='visible';
	show.style.display = "block";
	if (IE) { // grab the x-y pos.s if browser is IE
		//	offsetx = event.clientX; 
		//	offsety = event.clientY; 

		offsetx=event.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft; 
		offsety=event.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop; 
		show.style.top=offsety-140+'px';
		show.style.left=offsetx+15+'px';
	} else {  // grab the x-y pos.s if browser is NS
		offsetx = event.pageX
			offsety = event.pageY
			show.style.top=offsety-140+'px';
		show.style.left=offsetx+10+'px';
	}  

}



function partner_hide_hover(id){
	var close = document.getElementById('partner_hover_'+id);
	close.style.visibility='hidden';
	close.style.display = "none";
	return false;
};
var IE = document.all?true:false
var offsetx = 0
var offsety = 0

function showHover(millis, id, e)
{

	// This will work better in IE when all offers are chanted to links
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while(curDate-date < millis);
	var show = document.getElementById('hover_'+id);

	show.style.visibility='visible';
	show.style.display = "block";

	if (IE) { // grab the x-y pos.s if browser is IE
		show.style.top=show.style.top-50+'px';
	} else {  // grab the x-y pos.s if browser is NS
		offsety = e.pageY;
		show.style.top = offsety - 280 + 'px';
	}





}

function hideHover(id){
	var close = document.getElementById('hover_'+id);
	close.style.visibility='hidden';
	close.style.display = "none";
	return false;
};


function mypopup_content(url){
	newwin=window.open(url,'popcontent','left=100,top=100,width=900,height=800,status=1,address=1,scrollbars=1');
	/*
	   var content=document.getElementById(id);
	   content.style.display = 'block';
	   str = content.innerHTML;
	//alert(str);
	newwin.document.write('<HTML>\n<HEAD>\n');
	newwin.document.write('<TITLE>FunSource - Fandango2<TITLE>\n');
	newwin.document.write('<link rel="stylesheet" type="text/css" href="/scripts/master.css" />\n');
	newwin.document.write('<script language="Javascript" type="text/javascript" src="http://images.fandango.com/scripts/global.js"></script>\n');
	newwin.document.write('<script type="text/javascript" src="/scripts/master.js"></script>\n');
	newwin.document.write('</HEAD>\n');
	newwin.document.write('<BODY>\n');
	newwin.document.write(str);
	newwin.document.write('</BODY>\n');
	newwin.document.write('</HTML>\n');
	newwin.document.close();
	 */
}

function printContent(id){
	str=document.getElementById(id).innerHTML
		newwin=window.open('','printwin','left=100,top=100,width=600,height=800')
		newwin.document.write('<HTML>\n<HEAD>\n')
		newwin.document.write('<TITLE>Print Page</TITLE>\n')
		newwin.document.write('<script>\n')
		newwin.document.write('function chkstate(){\n')
			newwin.document.write('if(document.readyState=="complete"){\n')
				newwin.document.write('window.close()\n')
					newwin.document.write('}\n')
					newwin.document.write('else{\n')
						newwin.document.write('setTimeout("chkstate()",2000)\n')
							newwin.document.write('}\n')
							newwin.document.write('}\n')
							newwin.document.write('function print_win(){\n')
								newwin.document.write('window.print();\n')
									newwin.document.write('chkstate();\n')
									newwin.document.write('}\n')
									newwin.document.write('<\/script>\n')
									newwin.document.write('<link rel="stylesheet" type="text/css" href="scripts/master.css" />\n')
									newwin.document.write('</HEAD>\n')
									newwin.document.write('<BODY onload="print_win()">\n')
									newwin.document.write('<div id="content">')
									newwin.document.write(str)
									newwin.document.write('</div>')
									newwin.document.write('</BODY>\n')
									newwin.document.write('</HTML>\n')
									newwin.document.close()
}

function dontShowPop(id){
	newwin=window.open('','dontshowwin','left=400,top=300,width=425,height=100')
		newwin.document.write('<HTML>\n<HEAD>\n')
		newwin.document.write('<TITLE>Don\'t show message again.</TITLE>\n')
		newwin.document.write('<link rel="stylesheet" type="text/css" href="scripts/master.css" />\n')
		newwin.document.write('</HEAD>\n')
		newwin.document.write('<BODY>\n')
		newwin.document.write('<div style="padding:10px;" class="textlrg">\n')
		newwin.document.write('<FORM method="post" action="">\n')
		newwin.document.write('Are you sure you want to hide the Get Started message from now on? <br><br> \n')
		newwin.document.write('<input type="submit" name="yes_hide" CLASS="subheading" value="Yes" onclick="window.opener.hideDivTransPOP();"/> <input type="button" name="no" CLASS="subheading" value="No" onclick="window.close(); "/>\n')
		newwin.document.write('</FORM>\n')
		newwin.document.write('</div>\n')
		newwin.document.write('</BODY>\n')
		newwin.document.write('</HTML>\n')
		newwin.document.close()
}


function disabler(){
	button = document.getElementById("submitCover");
	button.style.visibility='visible';
	button.style.display = "block";
	return true;
}

function getDocHeight() {
	var D = document;
	return Math.max(
			Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
			Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
			Math.max(D.body.clientHeight, D.documentElement.clientHeight)
			);
}


function showProfileForm(id,trans){
	//    div = document.getElementById(id);
	//  transparent = document.getElementById(trans);
	//div.style.visibility='visible';
	//    div.style.display = "block";
	//  transparent.style.visibility='visible';
	//transparent.style.display = "block";

	div = document.getElementById(id);
	transparent = document.getElementById(trans);

	posx = document.documentElement.scrollLeft + 300;
	posy = document.documentElement.scrollTop + 100;

	div.style.top=posy+'px';
	div.style.left=posx+'px';

	div.style.visibility='visible';
	div.style.display = "block";
	transparent.style.height = getDocHeight()+'px';
	transparent.style.visibility='visible';
	transparent.style.display = "block";


	return true;
}

function showPForm(){
		div = document.getElementById('profile_form');
		div2 = document.getElementById('bb_congrats');

    posx = document.documentElement.scrollLeft + 300;
    posy = document.documentElement.scrollTop + 100;

    div.style.top=posy+'px';
    div.style.left=posx+'px';

    div.style.visibility='visible';
    div.style.display = "block";
    div2.style.display = "block";
}

function showGetStartedForm(id,trans,where,event){
	div = document.getElementById(id);
	transparent = document.getElementById(trans);

	posx = document.documentElement.scrollLeft + 200;
	posy = document.documentElement.scrollTop + 100;

	div.style.top=posy+'px';
	div.style.left=posx+'px';

	div.style.visibility='visible';
	div.style.display = "block";
	transparent.style.visibility='visible';
	transparent.style.display = "block";
	transparent.style.height = getDocHeight()+'px';

	return true;
}

function showPollResults(id){
	div = document.getElementById(id);
	div.style.visibility='visible';
	div.style.display = "block";
	return true;
}

function show(id){
	div = document.getElementById(id);
	div.style.visibility='visible';
	div.style.display = "block";
	return true;
}


function showratecoupon(id){
	div = document.getElementById(id);
	div.style.visibility='visible';
	div.style.display = "block";
	return true;
}

function hideDivTransPOP(){
	newwin.window.close();
	div = document.getElementById('profile_information');
	transparent = document.getElementById('transparent_layer');
	div.style.visibility='hidden';
	div.style.display = "none";
	transparent.style.visibility='hidden';
	transparent.style.display = "none";
}

function hideDivTrans(id, trans){
	div = document.getElementById(id);
	transparent = document.getElementById(trans);
	div.style.visibility='hidden';
	div.style.display = "none";
	transparent.style.visibility='hidden';
	transparent.style.display = "none";
	return false;
}

function stopRKey(evt) {
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text")) { return false; }
}

function searchKeyPress(e)  
{  
	if (e.keycode == 13)  
	{  
		document.searchForm.submit.submit();  
	}  
}  



function mypopup(url)
{
	mywindow = window.open (url,  "mywindow","resizable=1,scrollbars=1,  left=100,width=785,height=750");
}

function mouseOver(id, num){

	var img = document.getElementById(id).src="/image_server.php?image_id="+num;
}

function mouseOut(id, num){
	var img = document.getElementById(id).src="/image_server.php?image_id="+num;
}

function hoverImage(id){
	var show = document.getElementById(id);
	show.style.visibility='visible';
	show.style.display = "block";
}

//delete all below////////////////////////////////////////////////////////////
function load_campaign(url) {
	var show = document.getElementById('campaign');
	show.style.visibility='visible';
	show.style.display = "block";

	try {
		// Moz supports XMLHttpRequest. IE uses ActiveX.
		// browser detction is bad. object detection works for any browser
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
		// browser doesn't support ajax. handle however you want
	}

	xmlhttp.onreadystatechange = placecode;
	xmlhttp.open("GET", url);

	// Moz is fine with just send(); but
	// IE expects a value here, hence we do send(null);
	xmlhttp.send(null);
}

function placecode() {
	if (xmlhttp.readyState == 4) {
		document.getElementById("campaign").innerHTML = xmlhttp.responseText;
	}
}

function curtian_call(){
	var left_curtian = document.getElementById('left_curtain');
	var right_curtian = document.getElementById('right_curtain');

}

function checkLocation() {
	if (document.location_form.location.value == "Enter ZIP or City") {
		document.location_form.action = "http://www.fandango.com/"; }
	else {
		document.location_form.action = "http://www.fandango.com/redirect.aspx?" }
}

function checkKeyword() {
	if (document.keyword_form.q.value == "Enter Movie or Actor") {
		document.keyword_form.q.value = "";
		document.location_form.action = "http://www.fandango.com/GlobalSearch.aspx?"; }
}



var Timer;
var TotalSeconds;

function CreateTimer(Time,game_page) {
	TotalSeconds = Time;
	if (game_page == 'yes'){
		UpdateTimer()
			window.setTimeout("Tick('yes')", 1000);
	}else{
		UpdateTimer()
			window.setTimeout("Tick('no')", 1000);
	}
}

function Tick(game_page) {
	if (TotalSeconds <= 1 && TotalSeconds >= -1 && game_page == 'yes') {
		alert("Time's up! The tournament is now over. Thanks for playing Banana Blast!")
		//return;
		setTimeout("window.location = '/banana_blast'", 1000);
	}
	var gp = game_page
		TotalSeconds = TotalSeconds - 1;
	UpdateTimer()
		if (game_page == 'yes'){
			UpdateTimer()
				window.setTimeout("Tick('yes')", 1000);
		}else{
			UpdateTimer()
				window.setTimeout("Tick('no')", 1000);
		}
}



function UpdateTimer(){

	var Seconds = TotalSeconds;

	var Days = Math.floor(Seconds / 86400);
	Seconds -= Days * 86400;

	var Hours = Math.floor(Seconds / 3600);
	Seconds -= Hours * (3600);

	var Minutes = Math.floor(Seconds / 60);
	Seconds -= Minutes * (60);


	var TimeDayStr = ((Days > 0) ? Days + " " : "0");
	TimeDayStr = LeadingZero(TimeDayStr);
	var TimeHourStr =  LeadingZero(Hours);
	var TimeMinStr = LeadingZero(Minutes) ;
	var TimeSecStr = LeadingZero(Seconds);
	//var TimeStr = ((Days > 0) ? Days + " " : " ") + LeadingZero(Hours) + " " + LeadingZero(Minutes) + " " + LeadingZero(Seconds)

	var TimerDay = document.getElementById("timer_day");
	var TimerHour = document.getElementById("timer_hour");
	var TimerMin = document.getElementById("timer_min");
	var TimerSec = document.getElementById("timer_sec");
	//Timer.innerHTML = TimeStr;
	TimerDay.innerHTML = TimeDayStr;
	TimerHour.innerHTML = TimeHourStr;
	TimerMin.innerHTML = TimeMinStr;
	TimerSec.innerHTML = TimeSecStr;
}


function LeadingZero(Time) {

	return (Time < 10) ? "0" + Time : + Time;

}

function HideSecMenu(){
	var no_sec = document.getElementById('page_content_no_sec_menu');
	if (no_sec) {
		var sec = document.getElementById('page_content_right');
		var pc = document.getElementById('page_content');
		sec.style.display = 'none';
		pc.style.width = '100%';
	}
}

