/**
* Leaving HP notifications
*/
function leavingHPCanadafr(newLocation) {
  if(confirm("Veuillez noter que ce lien vous mènera à l’extérieur du site hp.ca et que vous allez accéder à un site universel HP.")) {
    window.open(newLocation);
  }
}

function leavingHPCanada(newLocation) {
  if(confirm("Please be aware that you are leaving hp.ca and entering a global HP site")) {
    window.open(newLocation);
  }
}

function resellerFr2Eng(newLocation) {
  if(confirm("Veuillez noter que ce lien vous mènera à l’extérieur du site hp.ca et que vous allez accéder à un site revendeur en ligne anglais.")) {
    window.open(newLocation);
  }
}

function leavingHPCanadafr2en(newLocation) {
  if(confirm("Veuillez noter que ce lien vous mènera à l’extérieur du site hp.ca et que vous allez accéder à un site universel anglais HP.")) {
    window.open(newLocation);
  }
}

// Function: leavingHP
// Purpose : allow HP to display message before user leaves HP domain

function leavingHP(newLocation) {
  if(confirm("This link will take you outside the Hewlett-Packard web-site. HP does not control and is not responsible for information outside the HP website.")) {
    window.location = newLocation;
  }
}


// Function: Fr2EngPage
// Purpose : Displays disclaimer stating a french user is leaving the HP Canada site to view an english one.
function Fr2EngPage(newLocation) {
  if(confirm("Veuillez noter que vous allez accéder à un site universel anglais HP.")) {
    window.location = newLocation;
  }
}
// Function: leavingHP
// Purpose : allow HP to display message before user leaves HP domain

function frenchHP(newLocation) {
  if(confirm("Ce lien vous mènera à l’extérieur du site Web de Hewlett-Packard. HP n’assume aucune responsabilité sur l’information qui n’est pas comprise dans son site Web et sur laquelle elle n’exerce aucun contrôle.")) {
    window.location = newLocation;
  }
}


// Function: currentDate
// Purpose : write current date to document
function currentDate() {

   var now = new Date();
   var month = now.getMonth();
   var date = now.getDate();
   var browserName = navigator.appName;
   var browserVer = parseInt( navigator.appVersion );
   var version = "";
   var monthname;

   if (month == 0) monthname = "January";
   if (month == 1) monthname = "February";
   if (month == 2) monthname = "March";
   if (month == 3) monthname = "April";
   if (month == 4) monthname = "May";
   if (month == 5) monthname = "June";
   if (month == 6) monthname = "July";
   if (month == 7) monthname = "August";
   if (month == 8) monthname = "September";
   if (month == 9) monthname = "October";
   if (month == 10) monthname = "November";
   if (month == 11) monthname = "December";

   if (browserName == "Netscape" && browserVer >= 4)
         version = "n4";
   else if (browserName == "Microsoft Internet Explorer" && browserVer >= 4 )
         version = "e4";
   else
         version = "other";
   if (version == "n4" || version == "e4") {
      var year = now.getFullYear();
   } else {
      var year = now.getYear();
      if (year < 100) {
      // Entered value is two digits, which we allow for 1930-2029.
         if (year >= 30) {
            year += 1900
         } else {
            year += 2000
         }
      }
   }
   document.write(monthname + "&nbsp; "+ date + "," + "&nbsp;" + year);
}


// function to display message that the visitor is leaving HP site for a 3rd party site
function leavingHPCanada3rdparty(newLocation) {
  if(confirm("Please be aware that you are leaving hp.ca and entering a third-party site.")) {
    window.open(newLocation);
  }
}

// function to display message that the visitor is leaving HP site for a 3rd party site - en francois
function leavingHPCanada3rdparty_fr(newLocation) {
  if(confirm("Veuillez noter que vous allez quitter le site hp.ca pour accéder à un site de tiers en anglais.")) {
    window.open(newLocation);
  }
}




/**
* DOM & Cookie functions
*/

// get cookie by name
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";",c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}


// set cookie that expires at the end of a browsing session
function setTemporaryCookie(NameOfCookie, value, domain, path) {
        document.cookie = NameOfCookie + "=" + escape(value) + ((domain) ? "; domain=" + domain : "") + ((path) ? "; path=" + path : "");
}


// get value of a meta tag
function getMetaTagByName(name) {
	name = name.toLowerCase();
	
	var tags = document.getElementsByTagName("META");	
	for (var x=0; x<tags.length; x++) {
		if (tags[x].name.toLowerCase() == name) return tags[x].content;
	}
}




/**
* Init page settings
*/
// get language code from html tag
var html_lang = document.documentElement.lang.toLowerCase();




/**
* Buy buttons & pricing
*/

// get CI integration cookie
var ci_buy_button_stier = getCookie('hp_shp_tname');


// call CI pricing+buttons - do not call directly
function ci_price(sku, language, no_price, no_button) {
	if (!language) language = html_lang;
	
	sku = escape(sku);
	stier = escape(ci_buy_button_stier);
	
	var rule_group_id = '732';
	if (language == 'fr' || language == 'fr-ca') rule_group_id = '795';

	var sd_price = 'low';
	if (no_price) sd_price = 'false';

	var button_str = '&sDBM=true&bDReseller=true&bPrefix=true';
	if (no_button) button_str = '&sDBM=false&bDReseller=false&bPrefix=false';

	var url = 'http://h30218.www3.hp.com/oemsites/7240393/cii_pricing_service_api_ca.asp?nRGID=' + rule_group_id + button_str + '&sDPrice=' + sd_price + '&sSKU=' + sku + '&stier=' + stier + '&sJumpID=JumpID_value&HP_CrossSell=Y';
	document.write('<script type="text/javascript" src="' + url + '"><\/script>');
}


// buy button with pricing
function show_buy_button(sku, language) {
	ci_price(sku, language);
}


// buy button without pricing
function show_buy_button_no_price(sku, language) {
	ci_price(sku, language, true);
}


// price without button
function show_price(sku, language) {
	ci_price(sku, language, false, true);
}




/**
* JS Cart
*/

var CanCart = {
    load: function(lang) {
        if (!lang) lang = html_lang;
        
        // fast path - don't load cart if it is empty
        if (this.getItemCount() < 1) return;

        var url = "http://hpce.can.hp.com/wigo/getcart/cart.php?language=" + lang + "&t=" + new Date().getTime();
        document.write('<script src="' + url + '" type="text/javascript"></s' + 'cript>');
    },

    getItemCount: function() {
        var count = parseInt(getCookie('ca_store').split('|')[1]);
        if (window.console) console.log("ca_store=", getCookie('ca_store'));
        if (isNaN(count)) count = 0;

        return count;
    }
};


