// JavaScript Document

function popUpWin(theURL,winName,features) {
  var winName = window.open(theURL,winName,features);
}
function prodDetailWin(theURL,winName) {
  var winName = window.open(theURL,winName,'width=425,height=475');
}
var win = null;
function openCenteredWin(theURL,theName,w,h,scroll){
	// center the new window
	var winl = (screen.width - w)/2;
	var wint = (screen.height - h)/2;
	var settings ='height='+ h +',';
	settings +='width='+ w +',';
	settings +='top='+ wint +',';
	settings +='left='+ winl +',';
	settings +='scrollbars='+ scroll +',';
	settings +='resizable=yes';
	// open the window
	win = window.open(theURL,theName,settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
	// use this format:
	// <a href="javascript:openCenteredWin('http://wwww.url.com','name','400','400','yes');"></a>
}
// Rollover Functions
// ---------------------------------------------------------------- |
function swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// ------------------ 75th Anniversary ---------------------------- |
function lighterHistoryWin(){
	// center the window
	var winl = (screen.width-725)/2;
	var wint = (screen.height-585)/2;
	var settings ='height=585,';
	settings +='width=725,';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	// open the window
	var lighterHistory = window.open('/corporateInfo/history/lighterHistory.aspx','lighterHistory',settings);
}

function christmasMemoriesWin(){window.open('/corporateInfo/history/zippoChristmasGreetings.aspx','ChristmasCards','scrollbars=yes,resizable=yes,width=775,height=575');}

function holidayDisplaysWin(){
	window.open('/corporateInfo/history/zippoChristmasGreetings.aspx#displays','displays','scrollbars=yes,resizable=yes,width=775,height=575');
}

function holidayGreetingsWin(){
	window.open('/corporateInfo/history/zippoChristmasGreetings.aspx#cards','cards','scrollbars=yes,resizable=yes,width=775,height=575');
}

function anniversaryLightersWin(){
	window.open('/corporateInfo/history/zippoAnniversaryLighters.aspx','AnniversaryLighters','scrollbars=yes,resizable=yes,width=775,height=575');
}

function lighterHistoryWin(){
	window.open('/corporateInfo/history/lighterHistory.aspx','LighterHistory','scrollbars=yes,resizable=yes,width=700,height=580');
}

function privacyLink(){
	window.open('http://www.zippo.com/privacyPolicy.aspx','privacyPolicy','scrollbars=yes,width=575,height=500');
}

function legalLink(){
	window.open('http://www.zippo.com/legal.aspx','legal','scrollbars=yes,width=575,height=500');
}

function nascarTerms(){
	window.open('/Company/zippo-motorsports-terms.aspx','legal','scrollbars=yes,width=450,height=500');
}

function montageReflectionsWin(){
	window.open('/corporateInfo/advertising/montageAndReflections.aspx','MontageAndReflections','scrollbars=yes,resizable=yes,width=775,height=575');
}

function matchingGame(){
	window.open('/FunCenter/Games/zippo_matching_game.html','MatchinGame','width=650,height=505');
}

function DesignerZone(){
	window.open('/Designer_Zone/index.aspx?utm_source=Zippo_com&utm_medium=WebBanner_2&utm_campaign=DesignerZone_Apr08','DesignerZone','width=785,height=475');
}

function BLUvideos(){
	window.open('/FAQs/ZippoBLU_primer.aspx','ZippoBLUVideos','width=725,height=500');
}

function zippoLogosWin(){
	// center the window
	var winl = (screen.width-475)/2;
	var wint = (screen.height-625)/2;
	var settings ='height=625,';
	settings +='width=475,';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	// open the window
	window.open('/75years/logosAndSlogans.aspx','LogosAndSlogans',settings);
}

function datesInHistoryWin(){
	// center the window
	var winl = (screen.width-725)/2;
	var wint = (screen.height-540)/2;
	var settings ='height=540,';
	settings +='width=725,';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	// open the window
	window.open('/75years/datesInHistory.aspx','datesInHistory',settings);
}
function mailingList(){
	window.open('/joinMailingList.aspx','mailingList','width=615,height=390,scrollbars=yes');
}
// -- MEDIA CENTER LINKS  -- |
function imageLibraryWin(){
	// center the window
	var winl = (screen.width-625)/2;
	var wint = (screen.height-500)/2;
	var settings ='height=500,';
	settings +='width=625,';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	// open the window
	window.open('/75years/imageLibrary.aspx','ImageLibrary','scrollbars=yes,resizable=yes,width=625,height=500');
}
// -- ZippoBLU Teaser page resize function -- |
function getClientSize(targetElement) {
	var userWidth = 0;
	var userHeight = 0;
	// pad the height, width a bit so they don't bump the edges of the browsers, +/- 10 - 20px
	var minHeight = '700';
	var minWidth = '850';
	// set the sizes of the main content within the Flash site - NOT the stage size
	// sizes for the target must be defined as Strings (i.e. '700px')
	// -------------------------------------------------------------------------------
	//determine the browser window size for various browsers
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		userWidth = window.innerWidth;
		userHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		userWidth = document.documentElement.clientWidth;
		userHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		userWidth = document.body.clientWidth;
		userHeight = document.body.clientHeight;
	}
	
	//change the DIV width/height properties
	// set the div ID for the flash container
	var resizeElement = document.getElementById(targetElement);
	if (userHeight < minHeight){
		// you have to specify the 'px' here for the CSS to recognize the correct size
		resizeElement.style.height = minHeight + 'px';
	} else {
		resizeElement.style.height = '100%';
	}
	if (userWidth < minWidth){
		// you have to specify the 'px' here for the CSS to recognize the correct size
		resizeElement.style.width = minWidth + 'px';
	} else {
		resizeElement.style.width = '100%';
	}
	//var x = elm.offsetHeight;
	//elm.style.height = x + "px";
}

// this parses the querystring to see if the user failed to provide correct login credentials
// then opens a dialogue using thickbox to notify them of the problem, and with possible solutions.
var objURL = new Object();
function parseQueryString(){
	window.location.search.replace(
		new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),

		// For each matched query string pair, add that
		// pair to the URL struct using the pre-equals
		// value as the key.
		function( $0, $1, $2, $3 ){
			objURL[ $1 ] = $3;
		}
	);
	
	var videoJump = false;
	
	for (var strKey in objURL){			
		if (strKey == "Click_DZ"){
			//opens the Zippo Designer Zone
			if (objURL[ strKey ] == "true"){
				window.open('/Designer_Zone/index.aspx','DesignerZone','width=785,height=475');
			}
		} else if (strKey == "jump"){
			// opens the Zippo BLU FAQ video page.
			videoJump = objURL[ strKey ];
		} else if (strKey == "section"){
			if (videoJump){
				var sectionNumber = objURL[strKey];
				var windowPath = "/FAQs/ZippoBLU_primer.aspx?jump=true&section=";
				window.open(windowPath + sectionNumber,'ZippoBLUVideos','width=725,height=500');
			}
		}
	}
}

// capture the referring URL or the window location and populate the text field with it
var referringURL = document.referrer;

function setTheURL(){
	var urlField = document.getElementById('tryURL');
	if(referringURL != ''){
		urlField.value = referringURL;
	} else {
		urlField.value =  window.location.href;
	}
}

function tryThisURL(){
	// try the URL entered in the text box....
	document.location = document.getElementById('tryURL').value;
}

// for the Global sites menu pulldown in the header
function global_jumpMenu(targ,selObj,restore){ //v3.0
	var windowTarget = selObj.options[selObj.selectedIndex].value;
	if (windowTarget != 'USA'){
		window.open(windowTarget);
	}
  if (restore) selObj.selectedIndex=0;
}

function emailForm(emailAddress, region, businessName){
	var theURL = '/forms/distributorContactForm.aspx?emailAddress=' + emailAddress + '&region=' + region + '&businessName=' + businessName;
	window.open(theURL,'contactForm','width=625,height=585');
}