
siteID = 41;
 
function goToPage(newURL)
{
  if (newURL == "") {
    // alert("Preview: Nothing selected in text");
  } else {
    trackURL(newURL);
    document.location = newURL;
    // alert("Preview: Would go to site: " + newURL);
  }
  
    return false;
}

function leaving(toURL,leaving){
  // alert("going to: " + toURL);
  from = document.location;
  
  trackURL(toURL);
  
  // alert("from: " + from);
  if (leaving == 1) {
      
      redir = "/hsbcusa/leaving.html?toURL=" + escape(toURL) + "&" + "fromURL=" + escape(document.location);

  } else {
     redir = "/c/b.jsp?s=" + siteID + "&p=0" + "&d=" + escape(toURL) + "&" + "m=" + escape(document.location);
     //alert("redir " +  redir);
  
     //alert("leaving " +  redir);
     //redir = toURL;
  }
  
  document.location = redir;  

  return false;
}

function RU_Leaving(toURL,leaving,ru4code){
  // alert("going to: " + toURL);
  from = document.location;
  
  //leaving(toURL,leaving)
  //return false;
  
  placement_parm= 'placement='+escape(ru4code);
  
  /* This is relative from root URL */
  first_slash = toURL.indexOf('/');
    if (first_slash == 0) { toURL = document.location.protocol + '//' + document.location.hostname + toURL; }
    else { if (toURL.indexOf('http')==0) { 
    		trackURL(toURL); 
    	   };
         };

  target_parm = 'target='+escape(toURL); 
       
  redir = 'http://' + RU_Host() + '/smartserve/textlink?'+placement_parm+'&'+target_parm;
  
  // alert("from: " + from);
  //if (leaving == 1) {
  //   redir = "/hsbcusa/leaving.html?toURL=" + escape(toURL) + "&" + "fromURL=" + escape(document.location);
  //  } else {
  //  redir = "/c/b.jsp?s=" + siteID + "&p=0" + "&d=" + escape(toURL) + "&" + "m=" + escape(document.location);
  //   //alert("redir " +  redir);
  
  //   //alert("leaving " +  redir);
  //   //redir = toURL;
  // }
  
  document.location = redir;  

  return false;
}


function RU_Leaving_Offers(toURL,leaving,zone1_track) {
  // alert("going to: " + toURL);
  from = document.location;
    
  /* This is relative from root URL */
  first_slash = toURL.indexOf('/');
    if (first_slash == 0) { toURL = document.location.protocol + '//' + document.location.hostname + toURL; }
    else { if (toURL.indexOf('http')==0) { 
    		trackURL(toURL); 
    	   };
         };

  target_parm = 'target='+escape(toURL); 
       
  redir = zone1_track + escape(toURL);
  document.location = redir;  

  return false;
}

function RU_Leaving_OffersDebug(toURL,leaving,zone1_track) {
  alert("going to: " + toURL);
  from = document.location;
  /* This is relative from root URL */
  first_slash = toURL.indexOf('/');
    if (first_slash == 0) { toURL = document.location.protocol + '//' + document.location.hostname + toURL; }
    else { if (toURL.indexOf('http')==0) { 
    		trackURL(toURL); 
    	   };
         };

  target_parm = 'target='+escape(toURL); 
       
  redir = zone1_track + escape(toURL);
  alert("redir: " + redir); 
  document.location = redir;  

  return false;
}

// new code for topFeature rotation.
curFeature = 0;
rotateFeatures = false;
var event_Array = new Array();
function nextEvent() {
    
    if (rotateFeatures==true) {
   	 lastevent = curFeature;
          curFeature = curFeature + 1;
          if (curFeature >= event_Array.length) {
            curFeature = 0;
          }
          hideID(event_Array[lastevent])
          showID(event_Array[curFeature]);
    }
}
   
   
   
    

function page_init() {
   trackPage = new Image();
   if (pagePath) {
     trackTag = "/c/c.jsp?s=" + siteID + "&a=1&t=1&p=0" + "&d=" + escape(pagePath);
     trackPage.src = trackTag;      
   }
   
   
   try {
      var flashVersion = deconcept.SWFObjectUtil.getPlayerVersion();
      if (document.getElementById && (flashVersion['major'] > 5)) {
   			traverse_display_flash(document.body);
      }
   } catch(err)
   {
      //Handle errors here
   }
   
   
   // right now - only need to worry about 2 features...   
   featureTest1 = document.getElementById("topFeature1");
   if (featureTest1) {
   	showID("topFeature1");
   	event_Array.push("topFeature1");
   	featureTest2 = document.getElementById("topFeature2");
   	if (featureTest2) {
   	        event_Array.push("topFeature2");
   	        rotateFeatures = true;
   		myInterval = setInterval(nextEvent,5000);
   	}
   }
   
   add_spanish_disclaimer();   
  
   var careerTest = new RegExp("logicalMessageName=careerInformation");
   if (careerTest.test(document.location)) 
   try {
     subs = document.getElementsByName("subject");
     if (subs != null) {
  	    var subjects = subs[0];
	    if ((subjects[2].value == 'Benefits')&&(subjects[3].value == 'Diversity Recruiting')) {
           for(j=4;j<subjects.length;j++) {
		     k = j - 2;
		     subjects[k].text = subjects[j].text;
		     subjects[k].value = subjects[j].value;
	       } 
	       subjects.length = subjects.length - 2;
	    }
    }
    } catch (err) {
    }
   
     lead_pages = new Array('/',
   			'/personal',
   			'/security',
   			'/hsbcusa/abouthsbc');
   			
     conversion_pages = new Array('/credit_cards', '3.00',
     				'/personal/loans_mortgages.html', '2.00',
     				'/personal/insurance.html', '2.00',
     				'/personal/less_than_perfect_credit.html', '1.00',
     				'/security', '0.00',
     				'/security/how_safe_are_you.html', '1.00',
     				'/security/protect_yourself.html', '1.00',
     				'/security/protect_your_small_business.html', '3.00',
     				'/security/how_we_protect_you.html', '2.00',
     				'/careers', '1.00',
     				'/corporateresponsibility', '1.00',
     				'/investorrelations', '3.00',
     				'/ourcompany', '2.00',
     				'/diversity', '1.00',
     				'/hsbcusa/abouthsbc/contacthsbc.html', '2.00');  
     
     var sr_page_path = document.location.pathname.toLowerCase();
     
     default_replace = new RegExp(/[//]default.html/i);
     sr_page_path = sr_page_path.replace(default_replace, '');
     
     var is_lead_page = false;
     for (sry = 0; sry < lead_pages.length;sry++) {
     	if (lead_pages[sry] == sr_page_path) {
     		is_lead_page=true;
     		break;
     	}
     }
     
     var is_conversion_page = false;
     for (sry = 0; sry < conversion_pages.length;sry = sry + 2) {
       	if (conversion_pages[sry] == sr_page_path) {
       		is_conversion_page=true;
       		_sr_amount = "0";
       		_sr_amount = conversion_pages[sry + 1];
       		break;
       	}
     }
      
     var cb=Math.floor(Math.random()*999999);
     if (is_lead_page) {
   	  sr_tagtype="LEAD";
   	  fpc=1;
   	  sr_tag(533,205);  
     }
     
     if (is_conversion_page) {  

   	  sr_tagtype="CONVERSION";
   	  fpc=1;
   	  sr_tag(534);
  }    
   

  
}

function add_spanish_disclaimer() {
    try {
		var langTogg = document.getElementById('language_toggle');
		if (langTogg) {
	   
			var langToggAlist = langTogg.getElementsByTagName("A");

			if (langToggAlist.length > 0) {
				var testLink = langToggAlist[0];
				var teststring = testLink.innerText;
				if (typeof(teststring) != "undefined") 
				{
					try {
						if (teststring.substring(0,3).toLowerCase().indexOf("esp") > -1) {

							var es_disclaimer = 'Por favor tenga en cuenta que aunque esta p\u00e1gina est\u00e1 disponible en espa\u00f1ol, esto no significa necesariamente que las p\u00e1ginas subsiguientes, informaci\u00f3n de productos, solicitudes y documentos est\u00e9n tambi\u00e9n disponibles en espa\u00f1ol. Esta p\u00e1gina no constituye una negociaci\u00f3n de ning\u00fan tipo.';

							testLink.title = es_disclaimer; 
						}
					} catch (err) {
					}
				}

			}

		}
	} catch(e) {
	}
}

function preparePrint() {
   var newURL = location.href;
   if (newURL.indexOf("printFormat=yes")>0) {
      first= newURL.indexOf("&printFormat=yes");
      if (newURL.indexOf("?printFormat=yes")>0) {
      	      first= newURL.indexOf("?printFormat=yes");
      }
      if (first > 0) {
        newURL = newURL.substring(0,first);
      }
   } 
   if (newURL.indexOf('?')<1) {
      newURL = newURL + "?printFormat=yes";
   } else {
      newURL = newURL + "&printFormat=yes";
   }
   options = 'location=no,menubar=yes,resizable=yes,scrollbars=yes,toolbar=no,width=600,height=400';
   window.open(newURL,'printable',options);
}

function do_print()
{
	window.print();
        setActiveStyleSheet('default');
}

function disclaimer(newURL) {
 fullURL = '/hsbcusa/disclaimer.html?toURL=' + escape(newURL) + '&fromURL=' + escape(document.location);
 options = 'location=no,menubar=yes,resizable=yes,scrollbars=yes,toolbar=no,width=760,height=400';
 window.open(fullURL,'printable',options);
 return false;
}

function notrackURL(targetURL) {}

function trackURL(targetURL){
var re = new RegExp("^(.*?)://([^/]+)(.*)");
  var m = re.exec(targetURL);
  if (m == null) {
    //alert("No match");
  } else {
    //var s = "Match at position " + m.index + ":\n";
    //for (i = 0; i < m.length; i++) {
    //  s = s + m[i] + "\n";
    //}
    //alert(s);
    targetServer = m[2];
    targetURI    = m[3];
    trackURL     = targetServer + targetURI
    if (dcsIsOnsite && dcsIsOnsite(targetServer)) {
    	trackURL = "Offsite:" + trackURL;
    }
    
    dcsMultiTrack('DCS.dcssip',targetServer,'DCS.dcsuri',targetURI,'WT.ti',trackURL,"DCS.dcsref",location.href,"DCSext.HSBCexit","1");
    
  }
}

function go_home() {
  document.location = default_host;
}

function go_default() {
  document.location = default_host + pagePath;
}

function openABSList() {

  newWin = window.open("/hsbc_finance/abs", "abslist","location=yes,toolbar=yes,resizable=yes,scrollbars=yes,width=600,height=600");

  newWin.focus();


}

function openVideo(openURL) {
	  msgVidWin=window.open(openURL,"VideoWindow","width=640,height=550,scrollbars=no");
	  msgVidWin.focus();
	  return false;
}

// code to integrate flash-comment blocks into the actual code
        var numFlash = 0;
        function traverse_display_flash(currNode) {
 			var flashsrc = '';
			if (currNode.nodeType == 8) {  // we found a comment node.
				//*alert("Found comment node" + currNode.nodeValue);
				// FLASH-COMMENT;target_div;flashsrc;flash_width;flash_height;flash_code;flash_bgcolor;
				var flash_AA = currNode.nodeValue.split(";");
				if (flash_AA[0] == "FLASH-COMMENT") {
				   //*alert("Displaying flash");
				   var so = new SWFObject(flash_AA[1], "flash" + (++numFlash) ,flash_AA[3], flash_AA[4], flash_AA[5], flash_AA[6]);
				   so.write(flash_AA[2]);
				}
			}

 			if( currNode.hasChildNodes() ) {
				for(var node = currNode.firstChild; node != null; node = node.nextSibling){
					traverse_display_flash(node);

				}
			}
      }

	function page_flash_init() {
	  page_init();

   	  var flashVersion = deconcept.SWFObjectUtil.getPlayerVersion();

   	  if (document.getElementById && (flashVersion['major'] > 5)) {
			traverse_display_flash(document.body);
	    }
	}
	
	function showID(sid) {
	 var tempElm = document.getElementById(sid);
	 if (tempElm) {
	      if (tempElm.tagName == "TR") {
	      try {
		   tempElm.style.display='table-row';
		 } catch(e) {
		   tempElm.style.display='block';
		 }
	  } else {

	       if (sid.indexOf("_TABLE")>-1) {
	     	      try {
	     		   tempElm.style.display='table';
	     	      } catch(e) {
	     		tempElm.style.display='block';
		      }
	       } else {
	     		tempElm.style.display = 'block';
	       }

	  }
	  		tempElm.style.visibility = "visible";
		   }
		}

		function hideID(sid) {
		   var tempElm = document.getElementById(sid);
		   if (tempElm) {
		      tempElm.style.visibility = "hidden";
		      tempElm.style.display    = "none";
		   }
		}


		function writeID(sid, newHTML) {
		  var tempElm = document.getElementById(sid);
		  if (tempElm) {
		     tempElm.innerHTML = newHTML;
		  }
	}
	
	
	
	
	function increaseFontSize(path) {
	   if (path.length > 0) {
	      document.location = "/increase_fontsize?cd_doc_path=" + path;
	   } 
	}
	
	function decreaseFontSize(path) {
	   if (path.length > 0) {
	      document.location = "/decrease_fontsize?cd_doc_path=" + path;
	   } 
	}
	
        function togglePage(otherhost) {
          if (otherhost.length > 0) {
              path = location.pathname;
              query_string = location.search;
              newURL = otherhost + substring(location.pathname,1);
              if (query_string.length > 0) newURL += "?" + location.search;
              //alert(newURL);
              document.location = newURL;

          }
	}
	
	function includeJS(jsPath){var js = document.createElement("script");js.setAttribute("type", "text/javascript");js.setAttribute("src", jsPath); document.getElementsByTagName("head")[0].appendChild(js);};
	
	function RU_Host() {var ru_sd = 'cia';if (document.location.host.toLowerCase().indexOf('btctest')<0) ru_sd = 'http300';	ru_sd = ru_sd+'.edge.ru4.com'; return ru_sd;}

	function confirm_leaving() {
	  var answer = confirm("You are leaving HSBCusa.com and will enter another third party's website. Though the companies we choose to do business with are selected because of their high level of quality, we assume no liability for any other third party's website content, products, privacy policies, security, external links, nor for any third party content residing on HSBCusa.com. We recommend you read the terms & conditions, security and privacy policy of the linked website."); 
	  return answer;
	}


	function add_delicious_bookmark() {
		if (confirm_leaving()) {
			trackURL('http://delicious.com/save');
			window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent(location.href)+'&amp;title=HSBC - '+encodeURIComponent(document.getElementById('header').innerHTML), 'delicious','toolbar=no,width=550,height=550');
		}
		return false;
	}
	
	function add_yahoo_bookmark() {
		if (confirm_leaving()) {
			trackURL('http://myweb.yahoo.com/myresults/bookmarklet');
			window.open('http://myweb.yahoo.com/myresults/bookmarklet?t=HSBC - '+encodeURIComponent(document.getElementById('header').innerHTML)+'&u='+encodeURIComponent(location.href)+'&ei=UTF'); 
		}
		return false; 
	}
	
	function add_google_bookmark(){
		if (confirm_leaving()) {
			trackURL('http://www.google.com/bookmarks/mark');
			window.open('http://www.google.com/bookmarks/mark?op=add&amp;bkmk='+encodeURIComponent(location.href)+'&amp;annotation=&amp;labels=&amp;title=HSBC - '+encodeURIComponent(document.getElementById('header').innerHTML));
		}
		return false;
	}						
	
	function add_stumbleupon_bookmark() {
		if (confirm_leaving()) {
			trackURL('http://www.stumbleupon.com/submit');
			window.open('http://www.stumbleupon.com/submit?url='+encodeURIComponent(location.href)+'&amp;title=HSBC - '+encodeURIComponent(document.getElementById('header').innerHTML));
		}
		return false; 
	}
	
        function downloadPDF() {
	if (pagePath) {
	
		var urlParse = pagePath.split("/");
		
		var lastOne = urlParse.length-1;
		
		var htmlParse = urlParse[lastOne].split('.');
		
		var docName = htmlParse[0];
			
		var pdfURL = htmlParse[0];
		
		if (pdfURL.match("report_fraud")) {
			pdfURL = "incident_reporting";
		}
			
		options = 'location=no,menubar=yes,resizable=yes,scrollbars=yes,toolbar=no';
		/* width=600,height=400 */
		
		var downloadURL = "/security/pdf/" + pdfURL + ".pdf";
		trackURL("Download: " + downloadURL);
        	window.open(downloadURL,'printable',options);
	
		return false;
	
	}
}
