window.onunload = metrics_end;

// Metrics tracking for pathing, dwell time and drop off
//failing in IE, we need to pause execution before end
function metrics_end() {
	if(document.images['metrics']) {
		var endMetrics = new Image();
		endMetrics.src = document.images['metrics'].src.replace(/(page_id=)([^&]*)/, '$1$2&action=end');  ;
	}
	metrics_end_delay(endMetrics);
}
function metrics_end_delay(endMetrics) {
	return endMetrics.src;
}
// Rules Pop-Up
function rules() {
	window.open("index.tbapp?page=rules","rules","menu=no,toolbar=no,width=450,height=400,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124");
}

// New Window

function openWindow(link) {
  window.open(link, '_blank', 'width=800,height=600,toolbar=yes,status=yes,location=yes,menubar=yes,directories=yes,resizable=yes,scrollbars=yes');
}

// Instant Win Rules Pop-Up
function rules_iw(siteurl) {
	    window.open(siteurl + "index.tbapp?page=rules","rules","menu=no,toolbar=no,width=450,height=400,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124");
}

// FAQ Pop-Up
function faq(email) {
  self.name = "Parent_Window";
  
  var faq_window = "scrollbars,resizable,width=465,height=400,left=100,top=100";
  OpenWindow = window.open("index.tbapp?page=faq&email="+email+"&lid=general/faq_pop", "faq", faq_window);
}

// Contact Us Pop-Up
function contactus(email) {
	self.name = "Parent_Window";
	
	var contactus_window = "scrollbars,resizable,width=450,height=400,left=120,top=120";
	OpenWindow = window.open("index.tbapp?page=contact_form&nav=form&email="+email+"&lid=top+nav_how+it+works_FAQ","faq", contactus_window);
}

// Cookies FAQ

function cookies_faq() {
	window.open("index.tbapp?page=cookies_faq","cookies_faq","menu=no,toolbar=no,width=450,height=400,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124"); 
}

//Forgot password
function forgot() {
  window.opener.location="https://register.go.com/bvhe/disneymovierewards/sendPassword";
  window.close(); 
}	

// Image Security Information Pop-Up
function img_security() {
	window.open("index.tbapp?page=img_security_info","imgsec","menu=no,toolbar=no,width=450,height=400,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=132,left=196");
}

// Image Security Information Pop-Up Donate Points
function img_security_donate() {
	window.open("index.tbapp?page=img_security_info_donate","imgsec","menu=no,toolbar=no,width=450,height=370px,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=132,left=196");
}

function changeImage(source,graphic) {
	    source.src = "images/global/"+graphic;
}

// Generic Pop-Up
// ex: <a href="javascript:openThis('http://www.eprize.com');">Click here</a>
function openThis(link) {
  window.open(link, '_blank', 'width=990,height=600,toolbar=yes,location=yes,menubar=yes,directories=yes,resizable=yes,scrollbars=yes');
}

// Cancel Order
function cancelOrder() {
	    document.cancel_order_form.submit();
}

// Why do we ask for this information pop-up
function whyWeAsk() {
	    window.open("index.tbapp?page=_why_we_ask","popup","menu=no,toolbar=no,width=400,height=250,scrollbars=1,resizable=yes,directories=no,location=no,screenX=0,screenY=0,top=0,left=0");
}

function shipShow(objTarget) {

	if (document.all) {
	    targetBlock1 = document.all("profileAddress");
	    targetBlock2 = document.all("differentAddress");
	    targetCheckbox = document.all("update_address");
	} else {
	    targetBlock1 = document.getElementById("profileAddress");
	    targetBlock2 = document.getElementById("differentAddress");
	    targetCheckbox = document.getElementById("update_address");
	}

	if (objTarget.id == "differentRadio" && objTarget.checked) {
        targetBlock1.style.display = "none";
        targetBlock2.style.display = "block";
						    }

	if (objTarget.id == "profileRadio" && objTarget.checked) {
        targetBlock2.style.display = "none";
        targetBlock1.style.display = "block";
        targetCheckbox.checked = false;
    }

}


	if (document.images)
	{
		// back btn
		backBtnon = new Image(96,19);
		backBtnon.src="images/global/btn_back_home_on.gif";
		backBtnoff = new Image(96,19);
		backBtnoff.src="images/global/btn_back_home.gif";
		
		// main navs
		pic1on= new Image(140,25);
		pic1on.src="images/global/btn_entercode_on.gif";  
		pic2on= new Image(120,25);
		pic2on.src="images/global/btn_my_account_on.gif";
		pic3on= new Image(142,25);
		pic3on.src="images/global/btn_how_it_works_on.gif"; 
		pic4on= new Image(152,25);
		pic4on.src="images/global/btn_eligible_movies_on.gif"; 
		pic5on= new Image(150,25);
		pic5on.src="images/global/btn_view_rewards_on.gif"; 
		pic6on= new Image(120,25);
		pic6on.src="images/global/btn_join_now_on.gif";
		
		pic1off= new Image(140,25);
		pic1off.src="images/global/btn_entercode.gif";
		pic2off= new Image(120,25);
		pic2off.src="images/global/btn_my_account.gif";
		pic3off= new Image(142,25);
		pic3off.src="images/global/btn_how_it_works.gif"; 
		pic4off= new Image(152,25);
		pic4off.src="images/global/btn_eligible_movies.gif"; 
		pic5off= new Image(150,25);
		pic5off.src="images/global/btn_view_rewards.gif"; 
		pic6off= new Image(120,25);
		pic6off.src="images/global/btn_join_now.gif";
		
		// seat navs
		seat1on = new Image();
		seat1on.src = "images/global/btn_feature_promo2_on.gif";
		seat2on = new Image();
		seat2on.src = "images/global/btn_member_benefits2_on.gif";
		seat3on = new Image();
		seat3on.src = "images/global/btn_earn_bonus_points2_on.gif";
		seat4on = new Image();
		seat4on.src = "images/global/btn_refer_a_friend2_on.gif";
		seat5on = new Image();
		seat5on.src = "images/global/btn_faq_on.gif";
		seat6off = new Image();
		seat6off.src = "images/global/btn_contactus_on.gif";
		
		seat1off = new Image();
		seat1off.src = "images/global/btn_feature_promo2.gif";
		seat2off = new Image();
		seat2off.src = "images/global/btn_member_benefits2.gif";
		seat3off = new Image();
		seat3off.src = "images/global/btn_earn_bonus_points2.gif";
		seat4off = new Image();
		seat4off.src = "images/global/btn_refer_a_friend2.gif";
		seat5off = new Image();
		seat5off.src = "images/global/btn_faq.gif";
		seat6off = new Image();
		seat6off.src = "images/global/btn_contactus.gif";
	}
	
	// handle btn over state
	function lightup(imgName)
	{
		if (document.images)
		{
			imgOn=eval(imgName + "on.src");
			document[imgName].src= imgOn;
		}
	}
	
	// handle btn out state
	function turnoff(imgName)
	{
		if (document.images)
		{
			imgOff=eval(imgName + "off.src");
			document[imgName].src= imgOff;
		}
	}
	
function dosubmit() {
    if (document.all) {
        buttonID = document.all["orderbutton"];
        button2ID = document.all["processbutton"];
    } else {
        buttonID = document.getElementById("orderbutton");
        button2ID = document.getElementById("processbutton");
    }
    buttonID.style.display = "none";
    button2ID.style.display = "block";
}

function delayCloseDiv(dropDownName) {
	setTimeout("closeDiv('" + dropDownName + "')",100);
}

function closeDiv(dropDownName) {
	var divName = dropDownName + '_div';
	var dropDownDiv = document.getElementById(divName);
	dropDownDiv.style.visibility = "hidden";
}

function openDiv(dropDownName) {
	var divName = dropDownName + '_div';
	var dropDownDiv = document.getElementById(divName);
	dropDownDiv.style.visibility = "visible";
	dropDownDiv.focus();
}

function operateDropDown(dropDownName) {
	var divName = dropDownName + '_div';
	var dropDownDiv = document.getElementById(divName);
	if (dropDownDiv.style.visibility != "visible") {
		openDiv(dropDownName);
	} else {
		closeDiv(dropDownName);
	}
}

function populateFormValue(elementName, formValue, displayValue) {
	var hiddenField = document.getElementById(elementName);
	var textDiv = document.getElementById(elementName + "_text");
	hiddenField.value = formValue;
	textDiv.innerHTML = displayValue;
	closeDiv(elementName);
}

// No Cookies Popups

function cookies_faq() { 
	window.open("index.tbapp?page=cookies_faq","cookies_faq","menu=no,toolbar=no,width=450,height=400,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=88,left=124");
}



$(document).ready(function() {

	$("ul.product").hide();
	$("h5.product_header a").click(function(){
		if($(this).parent().next().css("display")== "block") {
			$("ul.product:visible").slideUp("slow");
		} else{
			$("ul.product:visible").slideUp("slow");
			$(this).parent().next().slideDown("slow");
		}
		return false;
	});
	
	$("#preview").hide();
	$('#show_preview').click(function(){
		var fName = $("input[@name=first_name_1]").val();
		var fEmail = $("input[@name=email_1]").val();
		$('span#friend_name').html(fName);
		$('span#friend_email').html(fEmail);
		$('#preview').show("slow");
	});
	
	$("#change_bid_form").hide();
	$("#change_bid_txt").hide();
	$("#change_bid_form_btn").click(function(){
		if($("#change_bid_form").css("display")== "none") {
		$('#change_bid_form').show("slow");
		$('#change_bid_txt').show("slow");
		} 
		return false;
	});
	
	$(".add_info").hide();
	$(".add_info_header").click(function(){
		if($(this).next().css("display")== "block") {
			$(".add_info:visible").slideUp("slow");
		} else{
			$(".add_info:visible").slideUp("slow");
			$(this).next().slideDown("slow");
		}
		return false;
	});
	
	//winners map
	
	$(".winner_nav").hover(function(){
		$(this).addClass('winner_nav_hover');
		},function(){
		$(this).removeClass('winner_nav_hover');
	});
	
	$("#alaska_pan").click(function(){
		map.setZoom(3); 
		map.panTo(new GLatLng(64.32087157990324, -150.908203125));
		return false;
	});
	
	$("#hawaii_pan").click(function(){
		map.setZoom(6);
		map.panTo(new GLatLng(20.77665905187883, -157.08251953125));
		return false;
	});
	
	$("#continent_pan").click(function(){
		map.setZoom(3);
		map.panTo(new GLatLng(39.50404070558415, -98.26171875));
		return false;
	});
	
	
	// Rewards Catalog Awesomeness
	$(".reward").click(function() {
		$(".reward_details").hide();
								
		reward_id = $(this).attr("reward_id");
		$(this).next(".reward_details").show("default");
		return false;
	});
	
	$(".reward_details .close_popup").click(function() {
		$(this).parent().hide("default");
	});
	
	
});