//Online Store Javascript - test
//Last updated by:
//REY 


// This function decodes the any string
// that's been encoded using URL encoding technique
function URLDecode(psEncodeString)
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}


	function getQueryVariable(variable) {
	  var query = window.location.search.substring(1);
	  var vars = query.split("&");
	  for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0].toLowerCase()== variable.toLowerCase()) {
		  return URLDecode(pair[1]);
		}
	  }
	 //alert('Query Variable ' + variable + ' not found');
	}

var product = getQueryVariable('prod');  // get the product ID variable



// if no query string in the url
if (product == undefined || product == ""){
	product = "CCH Books, Journals and Newsletters";
}else {	
product = product;
}



// function to update the values from xml data when the form loads

function changeValues() {
	
	//declare variables
	
	var imagesFolder;
	var headerImage;
	var confirmationPage;
	var pageTitle;
	var backgroundColor;
	var productName;
	var productCode;
	var defaultProductCode;
	var headerText;
	// var productCategory;
	var productNameNoHTML;
	var headerAltTag;
	var cpContent;
	
	

	// Load the default values for the productCategory if no query string defined in the URL
	var CurrentCFAProduct;	
	
	productCategory.toUpperCase();
	
	function loadTheDefault(){  // function to load the default xml data if no leadSource variable in url
		
		
		switch (productCategory){
						
			case "STORE":
			confirmationPage = "OLS-Store-HR_conf.aspx";
			imagesFolder = "http://hr.cch.com/cforms/images/";
			productName = "CCH Books, Journals and Newsletters";
			headerText = "Thank you for your interest in " + productName + ".  Please fill out the form and submit the information below.";
			headerImage = "http://hr.cch.com/images/WKLB_CCH-ASPEN-TAG.jpg";
			backgroundColor = "#e9e9e9";
			pageTitle = productName;
			break;
		
		}
	}

	
	
	if (product == undefined || product == ""){  // if query string leadSource undefined or null, load default values based on productCategory.  
		
		loadTheDefault();
	   
	   } else {
		loadTheDefault();
	   }

	
	if (productCategory == "STORE" ){ // testing for the Store form, set the hidden Product textfield value to the leadSource value, remove all html tags, and set the value of the textfield.
			productName = product;
			productNameNoHTML = productName.replace(/<\/?[^>]+(>|$)/g, "");
			document.getElementById('txtProductsTextbox').value = productNameNoHTML; // apply products textfield value
			pageTitle = productName;
			document.title = pageTitle; // apply pagetitle
			headerAltTag = pageTitle;
			headerText = "Thank you for your interest in " + productName + ".  Please fill out the form and submit the information below.";
			document.getElementById('lbvLabel3').innerHTML = headerText ;
	}
	

	
	// if no CONFIRMATIONPAGE in xml, use the default confirmation page.  If there is, load the value from xml.
		
		document.getElementById('redirectLink').value = confirmationPage + "?prod=" + product;
		document.getElementById('CFA-mainDiv').style.backgroundColor = backgroundColor; // load backgroundColor
			
	
	// if you want to add FooterText
		//document.getElementById('lbvLabelSep1').innerHTML = "";
		/*document.getElementById('headerContainer').innerHTML = "<IMG BORDER=\"0\" ALT=\"" + headerAltTag + "\" SRC=\"" + imagesFolder  + headerImage + "\">";*/

		
	
	
}



// function to change values in the confirmation page
function changeValuesConf() {

//declare variables
	var imagesFolder;
	var headerImage;
	var pageTitle;
	var backgroundColor;
	var productName;
	// var productCategory;
	var productNameNoHTML;
	var headerAltTag;
	var cpContent;
	
	
	// This function decodes the any string
	// that's been encoded using URL encoding technique
	function URLDecode(psEncodeString)
	{
	  // Create a regular expression to search all +s in the string
	  var lsRegExp = /\+/g;
	  // Return the decoded string
	  return unescape(String(psEncodeString).replace(lsRegExp, " "));
	}
	
	
		function getQueryVariable(variable) {
		  var query = window.location.search.substring(1);
		  var vars = query.split("&");
		  for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0].toLowerCase()== variable.toLowerCase()) {
			  return URLDecode(pair[1]);
			}
		  }
		 //alert('Query Variable ' + variable + ' not found');
		}
	
	var product = getQueryVariable('prod'); 
	
	if (product == undefined || product == ""){
		product = "CCH Books, Journals and Newsletters";
	}else {	
	product = product;
	}
		
	var CurrentCFAProduct;	
	
	productCategory.toUpperCase();
	
	function loadTheDefault(){
		switch (productCategory){
			
			
			case "STORE":
			confirmationPage = "OLS-Store-Default_conf.aspx";
			imagesFolder = "http://hr.cch.com/cforms/images/";
			productName = "CCH Books, Journals and Newsletters";
			headerText = "Thank you for your interest in " + productName + ".  Please fill out the form and submit the information below.";
			headerImage = "http://hr.cch.com/images/WKLB_CCH-ASPEN-TAG.jpg";
			backgroundColor = "#e9e9e9";
			pageTitle = productName;
			break;

		}
				
	}
	
	
	
	//if no query variable in the URL, load defaults.
	if (product == undefined || product == ""){
		
		loadTheDefault();
	   
	   } else {
		   
		   loadTheDefault();
	   }


	
	if (productCategory == "STORE"){
		productName = product;
		pageTitle = product;
		productNameNoHTML = pageTitle.replace(/<\/?[^>]+(>|$)/g, "");
		document.title = pageTitle;
		headerAltTag = pageTitle;
		cpContent = "Thank you for your interest in " + productName + ".<BR>  Your CCH Representative will contact you shortly.<BR><BR>If you need more information, please visit the <a href='http://hr.cch.com/products/'>HR Products Page</a>.<BR><BR>You can now close this browser window.<BR><BR><BR><BR>";
		document.getElementById('confirmationContent').innerHTML = cpContent; // apply Confirmation Page Content
	}
		
	/*document.getElementById('CFA-mainDiv').style.backgroundColor = backgroundColor;	
	document.getElementById('headerContainer').innerHTML = "<IMG BORDER=\"0\" ALT=\"" + productName + "\" SRC=\"" + imagesFolder  + headerImage + "\">";*/
	
	
	

}
