<!-- 
//=============================================================================================//
// --> 	NAME			: 	Supplemental Survey (Asia Pacific)
// -->	VERSION			:	1.0
// -->	FILE NAME		:	kor_shop.js
// --> 	AUTHOR			: 	Jonathan Brumley (jonathan.brumley@hp.com)
// --> 	LAST MODIFIED	: 	3/12/2007 
// --> 	COPYRIGHT		: 	© 2006 Hewlett-Packard Development Company, L.P. All rights reserved.
//=============================================================================================//

/*	====================================================
	GLOBAL VARIABLES DECLARATION
	____________________________________________________
	WARNING: Please do not modify these variables
	because they are important for the script.
	____________________________________________________ */
	
	if(!s_prop1)var s_prop1="";
	if(!s_prop2)var s_prop2="";
	if(!s_prop3)var s_prop3="";
	if(!s_prop4)var s_prop4="";
	if(!s_prop7)var s_prop7="";
	if(!s_prop8)var s_prop8="";
	if(!s_prop13)var s_prop13="";
	if(!s_pageName)var s_pageName="";
	if(!s_hp_region)var s_hp_region="";

/*  ====================================================
	spVal - CONTAINS ALL ARGUMENTS
	____________________________________________________
	spVal is a variable that contains all the survey 
	arguments or values	including.
	____________________________________________________ */	

var spVal = {
	
	aquarius_exep :	new Array("cceaacspro01", "cceaacspro02"),// This is only for the error that is produced in Aquarius 
	
	exep :	new Array("https://","www.shopping.hp.com", "h30187.www3.hp.com", "h20139.www2.hp.com", "ipgweb.cce.hp.com", "dcart"),
/*	====================================================
	(spVal.inf) - SVVAL.INF NOTATION 
	____________________________________________________
	~ cname  	= country name, 
	~ ccode   	= country code or country
	~ pratio 	= popratio
	~ clicks 	= number of clicks 
	____________________________________________________ */
	inf	: 	[{ //Main Information Variables
				current : 0 //position 0 is reserved
			},{ //Default Country
				cname: "default", ccode: '64', pratio: 0.00, clicks: 4, flag: "n"
			}],
	
	inv : 	{ //Invitation Variables
				zIndex		: 1000,
				top			: "25px",
				left 		: "40px"				
		},
		
	gen : 	{ //General Variables
				svID			: "p272997502",
				sv_ebus_sitecode: "2",
				sv_ebus_jscript : "jp_desk.js",
				sv_ebus_tce 	: "n",
				sv_ebus_domain 	: ".hp.com",
				cdomain 		: "HP",
				ref 			: self.location.href,
				myurl 			: location.href,
				title 			: document.title,
				reg 			: new RegExp("(google.com)", "i"),
				use_ebus_clicks	: true,
				files_root		: "http://www.hp.com/cma/metrics/survey/"
		},

	js	: 	{
				dir : "lib/",
				files: new Array("svDrag1","apLang")
		},

	css	:	{	dir	:	"css/",
				files: new Array("invitation")
		},
		
	bwr : {
				ie4 : document.all, ns6 : document.getElementById && !document.all
		},
		
	td : { // Time and Date Variables
				sv_ebus_yr 					: new Date().getFullYear(),
				sv_ebus_clicks_expires 		: new Date(),
				sv_ebus_expires 			: new Date(),
				sv_ebus_cookielife 			: 180, //in days
				sv_ebusclicks_cookielife 	: 30, //in minutes
				sv_ebus_random 				: Math.random()
		},
					
	test : 	{ // Test Variables				
				svLaunched 		: 	"no",
				invLaunched 	: 	"no"
		},		
		
	varMap : { // Variable Maps for Scrape Meta Function
				target_country : "sv_ebus_country", segment : "sv_ebus_segment", hp_design_version : "sv_ebus_design_version", generator : "sv_ebus_generator", page_content : "sv_ebus_page_content", 
				lifecycle : "sv_ebus_lifecycle", product_service_name : "sv_ebus_product_service_name", web_section_id : "sv_ebus_web_section_id", ReversableHTMLId : "sv_ebus_reversablehtmlid"
		},
		
	allMetas : document.getElementsByTagName("META"), // Asigning HTML meta tags to allMetas
	
	prop : { // prop Variables
				n1 : s_prop1.replace(/(\s|\/)/g,"_").toLowerCase(),
				n2 : s_prop2.replace(/(\s|\/)/g,"_").toLowerCase(),
				n3 : s_prop3.replace(/(\s|\/)/g,"_").toLowerCase(),
				n4 : s_prop4.replace(/(\s|\/)/g,"_").toLowerCase(),
				n7 : "",
				n8 : "",
				n9 : "",
				n13: s_prop13.toLowerCase()
		}
}//End of spVal

/*  ====================================================
	hpSP - CONTAINS ALL FUNCTIONS
	____________________________________________________
	hpSP is a variable that start and contains all 
	functions this is the body of the script.
	____________________________________________________ */	

var hpSP = { 
// ==================== Function to initialize functions =============================
	init : function(){
		td = spVal.td; gen = spVal.gen; iv = spVal.inv; test = spVal.test;
		prop = spVal.prop; inf = spVal.inf; bwr = spVal.bwr; js = spVal.js; css = spVal.css;
		//Calling Function
		hpSP.sv_ebus_set_domain();
		hpSP.sv_ebus_init_vars();
		hpSP.sv_ebus_scrapeMeta();
		hpSP.sv_ebus_set_country();
		hpSP.sv_ebus_cookies_expire();
		hpSP.createtags();		
		hpSP.sv_ebus_run();
	}, 
// ==================== Function run (starts the script after init)=======================
	sv_ebus_run: function(){
		/***************Determine Language*******************/	
		if ((sv_ebus_lang == "")&&(s_prop8 != ""))sv_ebus_lang = s_prop8;
		var lp8=sv_ebus_lang;
		if (!window.l){	
			l = "9";
			//English
			if (lp8.toLowerCase().indexOf("en")>-1) {
				l = "9";
			}			
			else if (lp8.toLowerCase().indexOf("ko")>-1) {
				l = "18";
			}
			else if ((lp8.toLowerCase().indexOf("ja")>-1) || (lp8.toLowerCase().indexOf("jp")>-1)) {
				l = "17";
			}
			else if ((lp8.toLowerCase().indexOf("zh_pr")>-1) || (lp8.toLowerCase().indexOf("zh-pr")>-1) || (lp8.toLowerCase().indexOf("zh-hans")>-1)) {
				l = "2052";
			}
			else if ((lp8.toLowerCase().indexOf("zh_ta")>-1) || (lp8.toLowerCase().indexOf("zh-ta")>-1) || ((lp8.toLowerCase().indexOf("zh-hant")>-1) && (country == "59"))) {
				l = "1028";
			}
			else if ((lp8.toLowerCase().indexOf("zh_hk")>-1) || (lp8.toLowerCase().indexOf("zh-hk")>-1) || ((lp8.toLowerCase().indexOf("zh-hant")>-1) && (country == "24"))) {
				l = "3076";
			}
			else if (lp8.toLowerCase().indexOf("zh")>-1) {
				l = "2052";
			}
		}
		if ((!window.s_pageName) || (s_pageName.indexOf("gw:") == -1)){		
			if ((document.cookie.indexOf("HP_EBUS_"+gen.cdomain+"_CLICKS") != -1) || (gen.use_ebus_clicks == false)){		
				index = inf[0].current;// index is 0 to know the value of current country
				if(gen.use_ebus_clicks == true){
					clicks = hpSP.sv_ebus_getCookie('HP_EBUS_'+gen.cdomain+'_CLICKS').split("x");
					compare_clicks = clicks[1]*1;
				} 
				if (compare_clicks >= inf[index].clicks){				
					if ((document.cookie.indexOf("HP_EBUS=true")==-1) && (td.sv_ebus_random<inf[index].pratio) && (gen.reg.test(document.referrer) == false) && (this.checkdomains(spVal.exep)== false) || (location.search.indexOf("sv_launch_supplemental")>-1)){
						document.cookie = "HP_EBUS=true;path=/;Expires="+td.sv_ebus_expires.toGMTString()+";domain="+gen.sv_ebus_domain;											
						hpSP.trigOverlay();						
					}
				}
			}
		}		
	},
// ==================== Function Triger Overlay ===========================================
	trigOverlay: function(){		
		if (window.Drag){			
			hpSP.showOverlay();
		}else{
			window.setTimeout("hpSP.trigOverlay()", 100);
		}
	},
// ==================== Function initialize variables ======================================
	sv_ebus_init_vars: function(){
		sv_ebus_country="";
		sv_ebus_segment="";
		sv_ebus_design_version=""; 
		sv_ebus_generator="";
		sv_ebus_page_content=""; 
		sv_ebus_lifecycle="";
		sv_ebus_product_service_name="";
		sv_ebus_web_section_id="";
		sv_ebus_reversablehtmlid="";
		sv_ebus_stop_clicks = 0;
		clicks = new Array;	
		compare_clicks = 0;
		index = 0;
		sv_ebus_lang ="";
	},
// ==================== Function set domain for cookies =====================================	
	sv_ebus_set_domain: function(){
		if (location.host.indexOf("webmetrics1")!=-1){
			gen.sv_ebus_domain = ".hpqcorp.net";
			gen.cdomain = "HPQCORP";
		}//End if statement
	},
// ====================	Function createtags for overlay ====================================
	createtags: function(){
		var head = document.getElementsByTagName("HEAD")[0];
		for (i=0;i <= css.files.length-1;i++){
			var lk = document.createElement('link');
			lk.setAttribute("type", "text/css");
			lk.setAttribute("rel", "stylesheet");
			lk.setAttribute("href", gen.files_root+css.dir+css.files[i]+".css");
			head.appendChild(lk);
		}
		for (i=0;i <= js.files.length-1;i++){
			var element = document.createElement("script");
			element.setAttribute("type", "text/javascript");
			element.setAttribute("src", gen.files_root+js.dir+js.files[i]+".js");
			head.appendChild(element);
		}		
	},
// ==================== Function find country ===============================================
	sv_ebus_find_country: function(){
		if ((sv_ebus_country == "")&&(s_prop7 != ""))sv_ebus_country = s_prop7;	
		var ctry = sv_ebus_country.toLowerCase();	
		for (i=1; i<=(inf.length); i++){
			if(inf[i].cname == ctry){
				inf[i].flag = "y";
				inf[0].current = i;				
				return spVal.inf[i];
			}else{
				inf[1].flag = "y";
				inf[0].current = 1;						
				return inf[1];
			}
		}		
	},
// ==================== Function set country =================================================
	sv_ebus_set_country: function(){
		var fined = this.sv_ebus_find_country();
		country = fined.ccode;
	},
// ==================== Cookies Expire Time Set Up ===========================================
	sv_ebus_cookies_expire: function(){
		td.sv_ebus_clicks_expires.setTime(td.sv_ebus_clicks_expires.getTime()+(td.sv_ebusclicks_cookielife*60*1000));
		td.sv_ebus_expires.setTime(td.sv_ebus_expires.getTime()+(td.sv_ebus_cookielife*24*60*60*1000));		
	},
// ==================== Function check domains exeptions in URL ==============================
	checkdomains: function(exep_array){
		for (i=0; i < exep_array.length; i++) {				
			var result = spVal.gen.myurl.indexOf(exep_array[i]);		
			if ((result !=-1) && (exep_array[i] != "")){ return true; } 
		}		
		return false;
	},
// ==================== Function getcookie ===================================================
	sv_ebus_getCookie: function(name){
		var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);
		if (begin == -1) {
			begin = dc.indexOf(prefix);
			if (begin != 0) return null;
		}else{ begin += 2; }
		var end = document.cookie.indexOf(";", begin);
		if (end == -1) { end = dc.length; }
		return unescape(dc.substring(begin + prefix.length, end));
	},
// ==================== Function addLoadEvent =================================================
	 // This functions correcs the window.onload overwrite problem for other functions.
	 addLoadEvent: function(func){
		var oldonload = window.onload;
		if(typeof window.onload != 'function'){
			window.onload = func;
		}else{
			window.onload = function(){
				if(oldonload){
					oldonload();
				}
				func();
			}
		}
	},
// ==================== Function find Oject =====================================================
	findObj: function(theObj, theDoc){
	  var p, i, foundObj;  
	  if(!theDoc) theDoc = document;
	  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	  }
	  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
	  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
	  return foundObj;
	},
// ==================== Function generate global unique id ======================================
	genguid: function(){
		//generate global unique identifier
		var TempDate = new Date();
		var guid = (TempDate.getMonth()+1) + "-" + TempDate.getDate() + "-" + TempDate.getYear() + "_" + TempDate.getHours() + "-" + TempDate.getMinutes() + "-" + TempDate.getSeconds() + "-" + TempDate.getMilliseconds() + "_" + TempDate.getTimezoneOffset() + "_";
		for (var i = 1; i <= 32; i++){
			var n = Math.floor(Math.random() *16.0).toString(16);
			guid += n;
			if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) guid += "-";
		}
		return guid;
	},
// ==================== Function show overlay ===================================================
	showOverlay: function(){
		test.invLaunched = "yes";		
			if ((bwr.ns6) || (bwr.ie4)) {										
					//l = '17' //This variable is for testing only
					var LCOD = 'L'+l;
					var invitationtext = langLib[LCOD].text;
					var hp_ebus_answertext_yes = langLib[LCOD].yes;
					var hp_ebus_answertext_no = langLib[LCOD].no;
					var hp_ebus_buttontext = langLib[LCOD].button;				
				/*****************************Begin overlay HTML code****************************************/				
				var str='';
					str+='	<div id="sv_titlebar">';
					str+='		<a href=\'javascript:hpSP.toggleBox("sv_main",0)\'><img border="0"src="http://www.hp.com/cma/metrics/survey/img/close.gif" alt="close button"><\/a>';
					str+='		<span>HP Website Survey<\/span>';
					str+='	<\/div><!-- end sv_titlebar \/\/-->';
					str+='	<div id="sv_header"><img src="http://www.hp.com/cma/metrics/survey/img/sv_logo.gif" alt="hp logo"><span>HP Website Survey<\/span>';
					str+='	<\/div><!-- end sv_header \/\/-->';
					str+='	<div id="sv_body"> ';
					str+=	invitationtext;
					str+='		<form class=\'sv_form\' action=\'\' name=\'sv_ebus_form\'>';
					str+='			<input class=\'radio\' type=\'radio\' name=\'sv_ebus_invitation\' value=\'yes\' checked=\'true\'><span>' + hp_ebus_answertext_yes + '<\/span><br \/>';
					str+='			<input class=\'radio\' type=\'radio\' name=\'sv_ebus_invitation\' value=\'no\'>';
					str+='			<span>' + hp_ebus_answertext_no + '<\/span><br \/>';
					str+='			<input class=\'button\' type=\'button\' onClick=\'hpSP.sv_ebus_verify();\' value=\'Submit\' >';
					str+='		<\/form>';
					str+='	<\/div><!-- end sv_body \/\/-->';
					str+='	<div id="sv_footer"> © ' + td.sv_ebus_yr + ' Hewlett-Packard Development Company, L.P.';
					str+='	<\/div><!-- end sv_footer \/\/-->';
					str+='<!-- END FLOATING LAYER CODE \/\/--> ';				
				hpSP.dv = document.createElement('div'); 
				hpSP.dv.setAttribute('id','sv_main');	
				hpSP.dv.style.left = iv.left;
				hpSP.dv.style.top = iv.top;
				hpSP.dv.style.zIndex = iv.zIndex;
				hpSP.dv.innerHTML=str;
				hpSP.dv.onmousemove=function(){Drag.startDrag();}
				document.body.appendChild(hpSP.dv);		
				Drag.startDrag();		
				hpSP.toggleBox('sv_main',1);
			}
	}, 
// ==================== Function ebus verify ===========================================
	sv_ebus_verify: function(){
		if (document.sv_ebus_form.sv_ebus_invitation[1].checked == true){
			this.launchSurvey(2);
			td.sv_ebus_expires.setTime(td.sv_ebus_expires.getTime()+(td.sv_ebus_cookielife*24*60*60*1000));
			document.cookie = "HP_EBUS=true;path=/;Expires="+td.sv_ebus_expires.toGMTString()+";domain="+gen.sv_ebus_domain;
			this.toggleBox('sv_main',0);
		}else{      
			this.launchSurvey(1);
			this.toggleBox('sv_main',0);
		}
	},
// ==================== Function launch survey =========================================
	launchSurvey: function(invitation){		
		test.svLaunched = "yes";		
		var url1 = "http://survey.confirmit.com/wix/"+gen.svID+".aspx?l="+l+"&tce="+gen.sv_ebus_tce.toLowerCase()+"&svLaunched="+test.svLaunched+"&invLaunched="+test.invLaunched+"&stop_click="+clicks[0]+"&total_clicks="+clicks[1]+"&seconds_to_launch="+this.sv_ebus_getCookie('HP_EBUS_'+gen.cdomain+'_TIME')+"&jscript="+gen.sv_ebus_jscript+"&bus_prod_class="+sv_ebus_reversablehtmlid_arr[0]+"&bus_prod_type="+sv_ebus_reversablehtmlid_arr[1]+"&bus_prod_cat="+sv_ebus_reversablehtmlid_arr[2]+"&reference="+escape(gen.ref)+"&title="+escape(gen.title)+"&code="+gen.sv_ebus_sitecode+"&country="+country+"&prop7="+escape(sv_ebus_country.toLowerCase())+"&s_hp_region="+escape(s_hp_region.toLowerCase())+"&prop8="+escape(sv_ebus_lang.toLowerCase())+"&prop9="+escape(prop.n9)+"&prop13="+escape(prop.n13)+"&prop1="+escape(prop.n1)+"&prop2="+escape(prop.n2)+"&prop3="+escape(prop.n3.toLowerCase())+"&prop4="+escape(prop.n4)+"&hp_design_version="+escape(sv_ebus_design_version.toLowerCase())+"&generator="+escape(sv_ebus_generator.toLowerCase())+"&page_content="+escape(sv_ebus_page_content.toLowerCase())+"&lifecycle="+escape(sv_ebus_lifecycle.toLowerCase())+"&guid="+escape(this.genguid())+"&product_service_name="+escape(sv_ebus_product_service_name.toLowerCase())+"&web_section_id="+escape(sv_ebus_web_section_id.toLowerCase());
		url1 += "&invitation="+invitation;    
		window.open(url1, "","height=800,width=750,scrollbars=yes,resizable=yes");
	},	
// ==================== Function toggle box ============================================
	toggleBox: function(szDivID, iState){
	   var obj = document.layers ? document.layers[szDivID] :
	   document.getElementById ?  document.getElementById(szDivID).style :
	   document.all[szDivID].style;
	   obj.visibility = document.layers ? (iState ? "show" : "hide") :
	   (iState ? "visible" : "hidden");	   
	   if (bwr.ie4){			
			var fr = document.getElementById("dummyFRM");	
			fr.style.visibility = obj.visibility;
		}
	},
// ==================== Function scrape meta tags ======================================
	sv_ebus_scrapeMeta: function(){	
		if (document.getElementsByTagName){		
			var myMeta;	
			sv_ebus_lang = window.document.documentElement.lang;
			for (var i=0; i<spVal.allMetas.length; i++){						
				myMeta = spVal.allMetas[i];
				if (spVal.varMap[myMeta.name] != null){
					eval(spVal.varMap[myMeta.name]+ " ='"+ myMeta.content.toLowerCase().split("'").join("") +"'");				
				}
			}
		}
		prop.n9 = sv_ebus_segment.toLowerCase();
		sv_ebus_reversablehtmlid_arr=sv_ebus_reversablehtmlid.split("-");
	}	
}//End of hpSP

if(hpSP.checkdomains(spVal.aquarius_exep)== false) {
/* 
====================================================
hpSP.init() - Starts the entire script
____________________________________________________ */	
hpSP.addLoadEvent(hpSP.init);
//-->
}