/* $Revision: 6977 $ */
/* Function to get the RefUrl parameter for the link to HTML gateway
 */
function getRefUrl() {
	var refUrl = '/NoFlash/Gatewaypage.htm?RefUrl=http%3a%2f%2f';
	var constructedDomain = '';
	var domain = document.domain;
	var domainParts = domain.split('.');
	var root = domainParts[0];
	switch (root) {
		case 'testinggw':
			domainParts[0] = 'testing3';
			break;
		case 'staginggw':
			domainParts[0] = 'staging3';
			break;
		case 'landingpage2':
			domainParts[0] = 'www3';
			break;
	}
	for (var i=0; i<domainParts.length; i++) {
		constructedDomain += domainParts[i];
		if (i != (domainParts.length-1)) {
			constructedDomain += '.';
		}
	}
	refUrl += constructedDomain;
	refUrl += '%2fen-row%2fhome%2fhtmlhome';
	return refUrl;
}
/** Function intended to open a popup window based on language and country
   * popupName - name of the popup window to be opened
   * countryCode - language and country information
   * userId - identifies the user for the opening a manage account page
   **/
function smirnoffPopupCc(popupName, countryCode, userId) {
  smirnoffPopup(popupName,userId);
}
/** Function intended to open a popup window based on language and country
   * popupName - name of the popup window to be opened
   * countryCode - language and country information
   * userId - identifies the user for the opening a manage account page
   **/
function smirnoffPopupCcNoBlock(popupName, countryCode, userId) {
  smirnoffPopupNoBlock(popupName,userId);
}
/** Helper function to call smirnoffPopupOver with the popup blocker check toggled
  * on
  * popupName - name of the popup window
  * userId - identifies the user for the opening a manage account page
  **/
function smirnoffPopup(popupName,userId) {
  smirnoffPopupOver(popupName,'1',userId);
}
/** Helper function to call smirnoffPopupOver with the popup blocker check toggled
  * off
  * popupName - name of the popup window
  * userId - identifies the user for the opening a manage account page
  **/
function smirnoffPopupNoBlock(popupName,userId) {
  smirnoffPopupOver(popupName,'0',userId);
}
/** Opens a popup window with the appropriate attributes and positioning based on name
   * After telling the popup to open it waits two seconds and calls the function to test if the
   * popup was blocked
   * popupName - name of the popup window
   * check - toggles whether or not to check for a blocked popup
   * userId - identifies the user for the opening a manage account page
   **/
function smirnoffPopupOver(popupName,check,userId) {
	var url;
  var swidth = screen.width;
  var sheight = screen.height;
  var width; var height; var popupWindow;
  var checkBlocked;
  if (check == '1') { checkBlocked = true; }
  else { checkBlocked = false; }
  switch(popupName)
  {
    case 'terms_of_use':
      width = 508; height = 500;
			url = '/en-row/terms.html';
			if (localize && localize.terms && localize.terms.getTermsUrl) {
				url = localize.terms.getTermsUrl();
			}
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
	case 'terms_black':
      width = 508; height = 500;
			url = '/it-it/terms_black.htm';

	  popupWindow = window.open(url,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
	break;
   case 'privacy_statement':
      width = 508; height = 500;
			url = '/en-row/privacy.html';
			if (localize && localize.privacy && localize.privacy.getPrivacyUrl) {
				url = localize.privacy.getPrivacyUrl();
			}
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
    case 'accessibility_statement':
      width = 508; height = 500;
			url = '/en-row/accessibility.html';
			if (localize && localize.accessibility && localize.accessibility.getAccessibilityUrl) {
				url = localize.accessibility.getAccessibilityUrl();
			}
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
    case 'contactus':
      width = 336; height = 460;
			url = '/en-row/Utilities/ContactUs.htm';
			if (localize && localize.contact && localize.contact.getContactUrl) {
				url = localize.contact.getContactUrl();
			}
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=no,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
		case 'sxregistration':
			width = 330; height = 625;
			url = '/en-row/Secure/experience/ExperienceRegistration.htm';
			popupWindow = window.open(url,popupName,'resizable=no,scrollbars=no,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
			break;
		case 'sxregistrationTerms':
			width = 330; height = 625;
			url = '/en-row/Secure/experience/terms.htm';
			window.open(url,popupName,'resizable=yes,scrollbars=no,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
			break;
		case 'exp_terms_of_use':
			width = 640; height = 625;
			url = '/en-row/Secure/experience/termsView.htm';
			popupWindow = window.open(url,popupName,'resizable=yes,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
			break;
    case 'registration_1':
      width = 660; height = 572;
			url = '/en-row/Secure/Registration';
			if (localize && localize.registration && localize.registration.getRegistrationUrl) {
				url = localize.registration.getRegistrationUrl();
			}
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
    case 'registration_2':
      width = 640; height = 572;
      popupWindow = window.open('/en-row/Secure/Registration/registration_2.htm',popupName,'resizable=no,scrollbars=no,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
    case 'registration_3':
      width = 640; height = 572;
      popupWindow = window.open('/en-row/Secure/Registration/registration_thanks2.htm',popupName,'resizable=no,scrollbars=no,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
		case 'electric_cabaret':
			width = 565; height = 600;
			popupWindow = window.open('/en-row/CabaretForm.htm',popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
			break;
    case 'login':
      width = 420; height = 210;
      url = '/en-row/Secure/Login/Login.htm';
      if (localize && localize.login && localize.login.getLoginUrl) {
        url = localize.login.getLoginUrl();
      }
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=no,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
    case 'forgot_password':
      width = 420; height = 200;
			url = '/en-row/Secure/ForgotPW/forgot_password.htm';
			if (localize && localize.forgotPassword && localize.forgotPassword.getForgotUrl) {
				url = localize.forgotPassword.getForgotUrl();
			}
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=no,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
    case 'sent_password':
      width = 420; height = 200;
      popupWindow = window.open('/en-row/Utilities/Secure/ForgotPW/sent_password.htm',popupName,'resizable=no,scrollbars=no,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
    case 'unsubscribe':
      width = 336; height = 355;
      popupWindow = window.open('/en-row/Utilities/Unsubscribe/Unsubscribe.htm',popupName,'resizable=no,scrollbars=no,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
    case 'manage_account':
      width = 660; height = 572;
			url = '/en-row/Secure/ManageAccount/manage_account.htm';
			if (localize && localize.manageAccount && localize.manageAccount.getManageAccountUrl) {
				url = localize.manageAccount.getManageAccountUrl();
			}
      popupWindow = window.open(url+'?userid='+userId,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
		case 'signature_wallpaper':
			width = 790; height = 600;
			url = '/en-row/Signature/sig_download.htm?imgPath=' + userId;
			popupWindow = window.open(url,popupName,'resizable=no,scrollbars=no,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
			break;	  
		case 'experience_terms_en_AU':
			width = 508; height = 500;
			url = '/en-au/experience/terms.html';
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
		case 'experience_terms_en_CA':
			width = 508; height = 500;
			url = '/en-ca/experience/terms.html';
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
		case 'experience_terms_en_GB':
			width = 508; height = 500;
			url = '/en-gb/experience/terms.html';
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
		case 'experience_terms_en_IE':
			width = 508; height = 500;
			url = '/en-ie/experience/terms.html';
      popupWindow = window.open(url,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
      break;
		case 'experience_widget':
			width = 793; height = 380;
			url = '/en-row/experience_widget3.html';
			popupWindow = window.open(url,popupName,'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + calcTop(sheight,height) + ',left=' + calcLeft(swidth,width));
			break;
    case 'smirnoff.com':
      window.open('http://www.smirnoff.com');
      checkBlocked = false;
      break;
    case 'drink_responsibly':
      window.open('http://www.diageo.com/en-row/CorporateCitizenship/PromotingResponsibledrinking/',popupName,'resizable=yes');
      checkBlocked = false;
      break;
    case 'know_your_drink':
      window.open('http://www.drinkiq.com',popupName,'resizable=yes');
      checkBlocked = false;
      break;
		case 'about_cookies':
			window.open('http://www.aboutcookies.org',popupName,'resizable=yes');
      checkBlocked = false;
			break;
		case 'diageo_brands':
			window.open('http://www.diageobrands.com/',popupName,'resizable=yes');
      checkBlocked = false;
			break;
    case 'html_site':
      checkBlocked = false;
			window.location = 'http://'+document.domain+'/en-row/Home/HTMLHome.htm';
      break;
		case 'flash_site':
			checkBlocked = false;
			window.location = 'http://'+document.domain+'/en-row/Home/home.htm';
			break;
		case 'html_site_pop':
			checkBlocked = false;
			window.opener.location='http://'+document.domain+'/en-row/Home/HTMLHome.htm';
			break;
		case 'flash_site_pop':
			checkBlocked = false;
			window.opener.location='http://'+document.domain+'/en-row/Home/home.htm';
			break;
		case 'html_gate':
			checkBlocked = false;
			var sOpLoc = new String(window.location);
			var refUrlLoc = sOpLoc.indexOf('RefUrl');
			var refUrlAmp = sOpLoc.indexOf('%26',refUrlLoc);
			var refUrl = sOpLoc.substring(refUrlLoc,refUrlAmp);
			window.location = 'http://'+document.domain+'/noflash?'+refUrl;
			break;
		case 'flash_gate':
			checkBlocked = false;
			var sOpLoc = new String(window.location);
			var refUrlLoc = sOpLoc.indexOf('RefUrl');
			var refUrlAmp = sOpLoc.indexOf('%26',refUrlLoc);
			var refUrl = sOpLoc.substring(refUrlLoc,refUrlAmp);
			window.location = 'http://'+document.domain+'/flash?'+refUrl;
			break;
		case 'html_gate_pop':
			checkBlocked = false;
			var sOpLoc = new String(window.opener.location);
			var refUrlLoc = sOpLoc.indexOf('RefUrl');
			var refUrlAmp = sOpLoc.indexOf('%26',refUrlLoc);
			var refUrl = sOpLoc.substring(refUrlLoc,refUrlAmp);
			window.opener.location = 'http://'+window.opener.document.domain+'/noflash?'+refUrl;
			break;
		case 'flash_gate_pop':
			checkBlocked = false;
			var sOpLoc = new String(window.opener.location);
			var refUrlLoc = sOpLoc.indexOf('RefUrl');
			var refUrlAmp = sOpLoc.indexOf('%26',refUrlLoc);
			var refUrl = sOpLoc.substring(refUrlLoc,refUrlAmp);
			window.opener.location = 'http://'+window.opener.document.domain+'/flash?'+refUrl;
			break;
    case 'logout':
      //session.invalidate();
      checkBlocked = false;
      break;
  }
  if (checkBlocked && popupWindow == null) { setTimeout(function(){smirnoffPopupBlocked(popupName);},2000); }
	return popupWindow;
}
/** Helper function to calculate where to position a popup so it is centered vertically
   * sheight - height of the screen display
   * height - height of the popup window
   **/
function calcTop(sheight, height) {
  return sheight/2 - height/2;
}
/** Helper function to calculate where to position a popup so it is centered horizontally
   * swidth - width of the screen display
   * width - width of the popup window
   **/
function calcLeft(swidth, width) {
  return swidth/2 - width/2;
}

// -- Popup blocker detection

/** Function to set a value in a hidden field on the parent document of the popup window
   * parentDoc - document of the parent windo
   * popupName - name of the window to open
   **/
function smirnoffPopupOnLoad(win) {
  var popupName = win.name;
	/*
  if (win.opener) {
    var parentDoc = win.opener.document;
    if (parentDoc) {
      var popupBlockDetect = parentDoc.getElementById('popupBlockDetect');
      if (popupBlockDetect) { popupBlockDetect.value = popupName; }
    }
  }
	*/
}
/** Function to check if the popup has been blocked and if it has to alert the user
   * of the need for them to allow popups
   * doc - document of popup parent window
   * popupName - name of the popup window which may have been blocked
   **/
function smirnoffPopupBlocked(popupName) {
  // should be called after a couple second delay from the browser
  var swf = document.getElementById('home');
  if (swf) { swf.popupBlockerEnabled(); }
  else { // no swf found so it is an html page
    // get the div with the popup has been blocked copy and make it visible
    var popupBlocked = document.getElementById('popupBlocked');
    popupBlocked.style['display'] = 'block';
  }
}
/**
 * Function to open a url in a popup window that is the full size of the screen
 * @param {String} url - the url to open
 */
function fullScreenPopup(url) {
	var swidth = screen.width;
  var sheight = screen.height;
	/*var encUrl = url;
	var i, base, params, key, val, keyValPairs, pair, newUrl;-
	var newPairs = [];
	if (encUrl.indexOf('?') != -1) {
		base = encUrl.split('?')[0];
		params = encUrl.split('?')[1];
		while (params.indexOf(':') != -1) { params = params.replace(':','%3a'); }
		while (params.indexOf('/') != -1) { params = params.replace('/','%2f'); }
		if (params.indexOf('&') != -1) {
			keyValPairs = params.split('&');
		} else {
			keyValPairs = [params];
		}
		for (i=0;i<keyValPairs.length;i++) {
			key = keyValPairs[i].split('=')[0];
			val = keyValPairs[i].split('=')[1];
		}
	}*/
	window.open(url,'new','resizable=yes,width='+swidth+',height='+sheight+',top=0,left=0');
}
// -- end popup blocker detection

