﻿/********************************************************************************
UPDATE LOG
3/27/09		Added tracking information for the email campaign
4/3/09		Converted financing message to campaign tracking
4/22/09		Added Can PPC TFN
4/22/09		Updated loadme() to check for organic leads before the other variables
5/1/09 		Added 20% CAN-PPC Offer
5/29/09		Commented out form verification code, using vf.js now
*********************************************************************************/

/********************************************************************************
PURPOSE: JavaScript does not contain a String.trim() function that I know of.
This adds my own String.trim() to the String object.
Note: This must be physically located in the page above where it is first used.
*********************************************************************************/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

var m_sTimeStamp = '5/1/2009 12:30';
var src = ReadCookie('BudgetBlinds');

/********************************************************************************
PURPOSE: consolidates the old window.onload code with an orphan "if" statement
that I found on the page. This function checks to see if there's a query string.
If so, checks for "src" and "usrid". If it finds them sets cookies "BudgetBlinds"
with "src", and "usrid" with "usrid".
Note: window.onload needs to be called/assigned on the web page, not here. 
Same with window.unload
*********************************************************************************/
LoadMe();

function LoadMe()
{
	//Checks to see if src is present, if not set value to 'Organic'
	if (src == null){
		SetCookie('BudgetBlinds', "Organic", 30);
	}
	
	if (document.URL.indexOf("?") != -1)
	{
		//utm_campaign functions the same as 'src'
		//We are using this variable so that data is available to Google Analytics on a campaign level
		var source = GetQueryValue("utm_campaign");
		if (source)
		{
			SetCookie('BudgetBlinds', source, 30);
		}
		
		//if "src" is a querystring, put its value in a cookie called "BudgetBlinds"
		var source = GetQueryValue("src");
		if (source)
		{
			SetCookie('BudgetBlinds', source, 30);
		}
		
		var sUsrID = GetQueryValue("usrid");
		if (sUsrID)
		{
			SetCookie('usrid', sUsrID, 30);
		}
	}



	var sStyle = ReadCookie("style");
	if (sStyle == null) sStyle = "Green";  
	var oTitle = sStyle ? sStyle : getPreferredStyleSheet();
	
}//end LoadMe()

/********************************************************************************
PURPOSE: the unload function

Note: window.onload needs to be called/assigned on the web page, not here. 
Same with window.unload
*********************************************************************************/
function UnloadMe(evt) 
{
  //var title = getActiveStyleSheet();
  //SetCookie("style", title, 365);
}

//Zero out postal codes/repop//////////////////////////////
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName);
  if (obj.value == "" || newText == ""){
    if (obj)
         obj.value = newText;
  }
}
/////// Jump Menu ///////////////
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
/////// Image Swapper ///////////////
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/* Code is present in vf.js file
function validateForm() {
	var i,p,q,nm,prntNm,test,num,min,max,testr,errors='',args=validateForm.arguments;
	for (i=0; i < (args.length-2); i += 3) {	//	Loop through every third value in the args		:BP
		test = args[i+2];						//	Set a var = the third arg						:BP
		fld = findObj(args[i]);				//	Get the object with the arg name				:BP
		if (fld) {
			nm = fld.name;
			prntNm = args[i+1];					//	Set a var = the second arg name, I added this as the printable Name		:BP
			if (prntNm == "")	prntNm = nm;	//	Set printable name to arg Name if not provided
			if ((val = fld.value) != "") {
				if (test.indexOf('isEmail') != -1) {
					p = val.indexOf('@');
					if (p < 1 || p == (val.length - 1))
						errors += '- ' + prntNm + ' must contain an e-mail address.\n';
				} else if (test.indexOf('cPass') != -1) {
					p = test.indexOf(':');
					testr = test.substring(p+1);
					val2 = findObj(testr);
					if (val != val2.value)
						errors += '- Password fields do not match.\n';
				} else if (test == 'C') {
					if (fld.checked != true) errors += '- ' + prntNm + '\n';
				} else if (test != 'R') {
					num = parseFloat(val);
					if (isNaN(val)) errors += '- ' + prntNm + ' must contain a number.\n';
					if (test.indexOf('inRange') != -1) {
						p = test.indexOf(':');
						min = test.substring(8,p);
						max = test.substring(p+1);
						if (num < min || max < num)
							errors += '- ' + prntNm + ' must contain a number between ' + min + ' and ' + max + '.\n';
					}
				}
			} else if (test.charAt(0) == 'R') errors += '- ' + prntNm + ' is required.\n';
		}
	}
	if (errors)
		alert('The following information is required:\n' + errors);
	document.MM_returnValue = (errors == '');
}
*/

function popAnyHelp(strURL, strWinName, strParams) {
	var winRUHelp = window.open(strURL, strWinName, strParams);
	if(!winRUHelp) {
		alert("This HFC site has detected that you are using a popup blocker.\nPlease add this site to your trusted sites list or disable your popup blocker.\n\nThank you.");
	}
	winRUHelp.focus();
}

/********************************************************************************
PURPOSE: gets array of elements with tag name = "link". Iterates the array.
If the element also has an attribute "rel" with "style" in the string,
and it has an attribute called "title", then it toggles (disable/enable) the element
with "link" as its tagname.
*********************************************************************************/
function setActiveStyleSheet(title) 
{
	var a, main;
	var arLinkTags = document.getElementsByTagName("link");
	for (var i = 0; i < arLinkTags.length; i++)
	{
		var nStyleIndex = arLinkTags[i].getAttribute("rel").indexOf("style");
		var sTitle = arLinkTags[i].getAttribute("title");
		
		if (nStyleIndex != -1 && sTitle)
		{
			arLinkTags[i].disabled = (arLinkTags[i].getAttribute("title") == title) ? false : true;
		}
	}
	
}//end setActiveStyleSheet()

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

/**************************** not re-worked yet by Jim ***********************************/
/****************************    not touched by Jim    ***********************************/
/****************************     re-worked by Jim     ***********************************/

/********************************************************************************
PURPOSE: Campaign Tracking Code, switches out the content based on the campaign 
variable. Note: is case-sensitive
sTerr so far is either "US" or "CAN"
*********************************************************************************/

function campaignPhone(sTerr)
{
	//Refresh the stored src cookie
	var src = ReadCookie('BudgetBlinds');
	
	//Default Variables
	var sUSPhone = '(800) 800-9250';
	var sCAPhone = '(888) 982-8343';
	var sHeadline = 'Special Online Offer';
	var sOffer = 'Free In-Home Consultation';
	var sOffer2 = 'Financing Available';
	var sOffer3 = 'Get 25% Off';
	var sCall2Action ='Fill out the form below or call ' + sUSPhone + ' for your<br> FREE In-Home Consultation';
	var sDisclaimer = '*Participating franchises only. ©2008 Budget Blinds, Inc. ' +
		'All rights reserved. Each franchise is independently owned and operated.' +
		'Budget Blinds is a registered trademark of Budget Blinds, Inc. and a Home Franchise Concepts Brand. ' +
		'<a href="http://www.budget-blinds-franchise.com/">Franchise Opportunities Available</a>. ' +
		'Visit our website at <a href="http://www.budgetblinds.com/">www.budgetblinds.com</a>.';
	var sStyles ='styles';
	
	var sFinancingHeadline = "12 Months Zero Interest Financing Available";
	var sFinancingLegal = "*At participating franchises only.  Minimum monthly payments required. Valid on purchases made between April 1, 2009 through April 30, 2010 when you use your Signature Series by Budget Blinds® credit card. On promo purchase, monthly payments required, but no finance charges will be assessed if (1) promo purchase paid in full in 12 months, (2) any minimum monthly payments on account paid when due, and (3) account balance does not exceed credit limit. Otherwise, promo may be terminated & finance charges assessed from purchase date. On promotions requiring a minimum payment, payments over the minimum will usually be applied to those promo balances before non-promo and other balances. If you have a non-promo balance, this may reduce the benefit from the promo. If you want to change this allocation, please call Customer Service. Standard terms apply to non-promo purchases, optional charges & existing accounts. As of March 1, 2009, variable APR: 21.98% & on all accounts in default, 29.99%. Minimum Finance Charge $2.00. Subject to approval by GE Money";

	//Link phone numbers with campaign variables
	switch(src)
	{
		//Testing variable
		case 'cake':
			sUSPhone = '(800) EAT-CAKE';
			sFinancingHeadline = "This website has detected that your credit score is under 700. No financing for you.";
			sFinancingLegal = "*No Exceptions";
			document.write('<div style="position:absolute;left:0px;top:0px;padding:10px;background: #CCCCCC;"></div>');
		

			//setActiveStyleSheet('red');
			//Generates a timestamp on the page to check for server caching
			break;
		case 'BudgetInspStudio':
			sUSPhone = '(800) 481-8041';
			sCAPhone = '(800) 823-1248';
			break;
		case 'BudgetGiftCert':
			sUSPhone = '(800) 482-8114';
			sCAPhone = '(800) 788-7740';
			break;
		case 'MyPOV':
			sUSPhone = '(866) 925-5775';
			sCAPhone = '(800) 993-9087';
			break;
		case 'InspStudio':
			sUSPhone = '(866) 925-5778';
			sCAPhone = '(800) 993-9112';
			break;	
		case 'mm':
			sUSPhone = '(800) 715-9451';
			break;	
		case 'mm2':
			sUSPhone = '(800) 450-0814';
			break;
		case 'BrinksMailer':
			sUSPhone = '(800) 815-1349';
			break;
		case 'BDG':
			sUSPhone = '(866) 994-9657';
			sCAPhone = '(877) 333-5653';
			break;
		case 'BDG10':
			sUSPhone = '(866) 590-6563';
			sCAPhone = '(877) 745-3988';
			break;

//All these cases are for the BBDesignGuide PI effort - Delete all 30 when Renee clears them
		
		case 'BBDG1':
			sUSPhone = '(866) 331-7358';
			break;
		case 'BBDG2':
			sUSPhone = '(866) 590-6578';
			break;
		case 'BBDG3':
			sUSPhone = '(866) 590-7485';
			break;
		case 'BBDG4':
			sUSPhone = '(866) 590-7525';
			break;
		case 'BBDG5':
			sUSPhone = '(866) 590-7543';
			break;
		case 'BBDG6':
			sUSPhone = '(866) 590-7558';
			break;
		case 'BBDG7':
			sUSPhone = '(866) 590-7635';
			break;
		case 'BBDG8':
			sUSPhone = '(866) 646-3261';
			break;
		case 'BBDG9':
			sUSPhone = '(866) 646-3298';
			break;
		case 'BBDG10':
			sUSPhone = '(866) 669-8549';
			break;
		case 'BBDG11':
			sUSPhone = '(866) 669-9492';
			break;
		case 'BBDG12':
			sUSPhone = '(866) 675-8819';
			break;
		case 'BBDG13':
			sUSPhone = '(866) 702-1721';
			break;
		case 'BBDG14':
			sUSPhone = '(866) 857-9515';
			break;
		case 'BBDG15':
			sUSPhone = '(866) 869-0777';
			break;
		case 'BBDG16':
			sUSPhone = '(866) 890-3273';
			break;
		case 'BBDG17':
			sUSPhone = '(866) 890-3307';
			break;
		case 'BBDG18':
			sUSPhone = '(866) 905-0083';
			break;
		case 'BBDG19':
			sUSPhone = '(866) 913-0981';
			break;
		case 'BBDG20':
			sUSPhone = '(866) 925-0543';
			break;
		case 'BBDG21':
			sUSPhone = '(866) 925-3752';
			break;
		case 'BBDG22':
			sUSPhone = '(866) 925-4264';
			break;
		case 'BBDG23':
			sUSPhone = '(866) 925-4349';
			break;
		case 'BBDG24':
			sUSPhone = '(866) 946-3316';
			break;
		case 'BBDG25':
			sUSPhone = '(866) 991-3971';
			break;
		case 'BBDG26':
			sUSPhone = '(866) 991-3974';
			break;
		case 'BBDG27':
			sUSPhone = '(866) 991-6078';
			break;
		case 'BBDG28':
			sUSPhone = '(866) 991-6084';
			break;
		case 'BBDG29':
			sUSPhone = '(866) 994-7787';
			break;
		case 'BBDG30':
			sUSPhone = '(866) 994-7855';
			break;

//End the BBDesignGuide Garbage

		case 'BBRadio':
			sUSPhone = '(888) 288-4015';
			sHeadline = 'Special Offer For KFKF Listeners';
			sOffer = 'FREE $100 Budget Blinds <br>Gift Certificate* when you <br />' + 
				'schedule an In-Home Consultation <br /><br />'+ 
				'<img src="../../_images/gift-certificate.jpg" alt="Gift Certificate" />';
			sCall2Action = 'Fill out the form below or call ' + sUSPhone + 
				' for your FREE $100 Budget Blinds Gift Certificate';
			sDisclaimer = '*When you schedule an in-home consultation.  ' + 
				'At participating franchises only.  Valid on Selected Signature Series® products only.  ' + 
				'Only one gift certificate per household.  Gift certificate to be presented at ' + 
				'time of initial estimate only.  Not valid with any other offers.  Not redeemable for cash. ' + 
				'Budget Blinds is a registered trademark of Budget Blinds, Inc. and a ' + 
				'Home Franchise Concepts Brand. <a href="http://www.budget-blinds-franchise.com/">' + 
				'Franchise Opportunities Available</a>. ' + 
				'<a href="http://www.budgetblinds.com/">Visit our website at www.budgetblinds.com</a>.';
			break;
		case 'BBWolf':
			sUSPhone = '(888) 288-4013';
			sHeadline = 'Special Offer For KKWF Listeners';
			sOffer = '25% Off Selected<br /> Signature Series<span class="register">&reg;</span> Products*';
			sCall2Action = 'Fill out the form below or call ' + sUSPhone + 
				' for your<br /> FREE In-Home Consultation<br /> and Design Guide';
			break;
		case 'BBWarm':
			sUSPhone = '(888) 288-4017';
			sHeadline = 'Special Offer For KRWM Listeners';
			sOffer = '25% Off Selected<br /> Signature Series<span class="register">&reg;</span> Products*';
			sCall2Action = 'Fill out the form below or call ' + sUSPhone +
				' for your<br> FREE In-Home Consultation<br> and Design Guide';
			break;
		case 'BBWarmRadio':
			sUSPhone = '(888) 288-4014';
			sHeadline = 'Special Offer For KRWM Listeners';
			sOffer = '25% Off Selected<br /> Signature Series<span class="register">&reg;</span> Products*';
			break;
		case 'BBFM':
			sUSPhone = '(888) 288-4016';
			sHeadline = 'Special Offer For KCKC Listeners';
			sOffer = 'FREE $100 Budget Blinds <br>Gift Certificate* when you <br>schedule an In-Home Consultation <br><br><img src="../../_images/gift-certificate.jpg" alt="Gift Certificate" />';
			sCall2Action = 'Fill out the form below or call '  + sUSPhone + 
			' for your FREE $100 Budget Blinds Gift Certificate';
			sDisclaimer = '*When you schedule an in-home consultation.  At participating franchises only.  ' + 
			'Valid on Selected Signature Series® products only.  Only one gift certificate per household.  ' + 
			'Gift certificate to be presented at time of initial estimate only.  ' + 
			'Not valid with any other offers.  Not redeemable for cash. Budget Blinds is ' + 
			'a registered trademark of Budget Blinds, Inc. and a Home Franchise Concepts Brand. ' + 
			'<a href="http://www.budget-blinds-franchise.com/">Franchise Opportunities Available</a>. ' + 
			'<a href="http://www.budgetblinds.com/">Visit our website at www.budgetblinds.com</a>.';
			break;
		case 'bbt':
			sUSPhone = '(800) 214-9114';
			sHeadline = 'Special Entertainment Book Offer';
			sOffer = '25% Off Selected<br /> Signature Series<span class="register">&reg;</span> Products*';
			break;
		case 'YourHome':
			sUSPhone = '(888) 207-5577';
			sHeadline = 'Special offer for New Movers';
			sOffer = '25% Off Selected<br /> Signature Series<span class="register">&reg;</span> Products*';
			sCall2Action = 'Fill out the form below or call ' + sUSPhone + 
				' for your<br> FREE In-Home Consultation';
			break;
		case 'BBSky':
			sUSPhone = '(866) 413-2440';
			break;
		case 'BBAir':
			sUSPhone = '(866) 413-2527';
			break;
		case 'BBDex':
			sUSPhone = '(866) 638-9214';
			break;
		case 'BBDex10':
			sUSPhone = '(800) 498-7932';
			break;
		case 'BBIYP10':
			sUSPhone = '(800) 498-7972';
			break;
		case 'BBCAN':
			sUSPhone = '(800) 800-9250';
			sCAPhone = '(800) 991-9753';
			break;
		case 'BBCA':
			sCAPhone = '(877) 888-4158';
			break;
		case 'BBCASmartMoves':
			sCAPhone = '(877) 888-4208';
			break;
		default:
			sUSPhone = '(800) 800-9250';
			break;
	}//end large switch
	//If the src contains the variable anywhere in the string (not just a precise match like in the above case), it will set the phone number for the campaign
	//EXAMPLE: If the variable is set to 'NAF-PPC', then it will work with 'NAF-PPC-GOOGLE', 'NAF-PPC'GGL', etc etc
	if (src.indexOf("NAF-PPC") != -1){
			sUSPhone = '(866) 626-2911';
			sOffer3 = 'Get 25% Off';
	} 
	if (src.indexOf("CAN-PPC") != -1){
			sCAPhone = '(800) 991-9757';
			sOffer3 = 'Get 20% Off';
	} 
	if (src.indexOf("BB-Schedule-Email") != -1){
			sUSPhone = '(866) 401-6776';	
			sCAPhone = '(800) 664-6826';
	} 
	if (src.indexOf("BB-Overlay-Email") != -1){
			sUSPhone = '(866) 401-6776';	
			sCAPhone = '(800) 664-6826';
	}
	if (src.indexOf("BB-ENewsletter") != -1){
			sUSPhone = '(866) 401-6776';	
			sCAPhone = '(800) 664-6826';
	}
	
	//US Phone is the default
	var sReturn = sUSPhone; //'US'
	//sReturn only changes if sTerr is one of the following:
	switch(sTerr)
	{
		case 'CAN':
			sReturn = sCAPhone;
			break;
		case 'Offer':
			sReturn = (sOffer);
			break;
		case 'Offer2':
			sReturn = sOffer2;
			break;
		case 'Offer3':
			sReturn = sOffer3;
			break;
		case 'sCall2Action':
			sReturn = sCall2Action;
			break;
		case 'Headline':
			sReturn = sHeadline;
			break;
		case 'Disclaimer':
			sReturn = sDisclaimer;
			break;
		case 'sFinancingHeadline':
			sReturn = sFinancingHeadline;
			break;
		case 'sFinancingLegal':
			sReturn = sFinancingLegal;
			break;
	}//end switch
	
	return sReturn;
	
}//end campaignPhone()

/********************************************************************************
PURPOSE: Write out campaign variable as a hidden form field
JEB 3/16/09: per Bruce, add a cookie called "usrid", and put its value into 
a hidden field in the form, so it gets POSTed when the form posts.
*********************************************************************************/
function returnSource()
{
	var src = ReadCookie('BudgetBlinds');
	var usrid = ReadCookie('usrid');
	var sHiddenFields = "<input name='src' type='hidden' value='" + src + "' />" +
		"<input name='usrid' type='hidden' value='" + usrid + "' />";	
	document.write(sHiddenFields);
}//end returnSource()

/********************************************************************************
PURPOSE: only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.

JEB re-factored 3/13/09: per Jerrol, a cookie ought to have an expiration date, 
so if none is given, make the default 30 days.

Note: old name was createCookie()
*********************************************************************************/
function SetCookie(name, value, days, path, domain, secure) 
{
	//if no days are passed, make default 30 days
	var nNumDays = (days) ? days : 30;
	//convert to milliseconds
	nNumDays = nNumDays * 60 * 60 * 24 * 1000;
	//get today's date
	var dtExpires = new Date();
	//convert today's date to milliseconds and add number of days in milliseconds
	dtExpires.setTime(dtExpires.getTime() + nNumDays);
	//assign this mess to the new cookie
	document.cookie = name + "=" + escape(value) + 
	";expires=" + dtExpires.toUTCString() +
	((path)   ? ";path=" + path : ";path=/") + 
	((domain) ? ";domain=" + domain : "") +
	((secure) ? ";secure" : ""); 
	
}//end SetCookie()

/********************************************************************************
PURPOSE: receives name of cookie ("BudgetBlinds", "usrid", or "style" so far)
and returns value of that cookie, if exists, else null.
partly from http://techpatterns.com/downloads/javascript_cookies.php

Note: old name was readCookie()
*********************************************************************************/
function ReadCookie(sSearchName) 
{
	var sCookieValue = null;
	
	//split document.cookie into array of name/value pairs
	var AllCookiesArray = document.cookie.split( ';' );
	
	//iterate array
	for ( i = 0; i < AllCookiesArray.length; i++ )
	{
		//split each name=value pair
		var SingleCookieArray = AllCookiesArray[i].split( '=' );
		
		//see String.prototype.trim above
		var sCookieName = SingleCookieArray[0].trim();
	
		// if the extracted name matches passed sSearchName
		if ( sCookieName == sSearchName )
		{
			//check to see if this cookie actually has a value (2nd half of SingleCookieArray)
			if ( SingleCookieArray.length > 1 )
			{
				//this is the value of the cookie whose name we're searching for
				sCookieValue = unescape(SingleCookieArray[1].trim());
			}			
			break;
		}
	}
	// note that in cases where cookie is initialized but no value, null is returned
	return sCookieValue;
}//end ReadCookie()

/********************************************************************************
PURPOSE: iterates the query string, looking for a particular query string name; 
if it finds it, returns the value
*********************************************************************************/
function GetQueryValue(sName) 
{
	var sValue = "";
	//remove ? from beginning of string
	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] == sName) 
		{
			sValue = pair[1];
		}
	}
	return sValue;
}//end GetQueryValue()

/********************************************************************************
PURPOSE: deletes the given cookie, if found
Note: old name was eraseCookie()
*********************************************************************************/
function DeleteCookie(sCookieName) 
{
	if (ReadCookie(sCookieName))
	{
		SetCookie(sCookieName, "", -1);
	}
}//DeleteCookie()

/******************************** *Begin Test stuff ***********************************************/
function ShowCookies()
{
	var msg = "The cookies associated with this document are: " + document.cookie;
	//document.write(msg);
	alert(msg);
}

function SetThisCookie()
{
	var sName = document.getElementById("txtName").value;
	var sValue = document.getElementById("txtValue").value;
	var nDays = parseInt(document.getElementById("txtDays").value);
	SetCookie(sName, sValue, nDays);
	document.getElementById("txtName").value = '';
	document.getElementById("txtValue").value = '';
	document.getElementById("txtDays").value = "";
	ShowCookies();
}

function FindThisCookie()
{
	var sName = document.getElementById("txtSearchName").value;
	var sValue = ReadCookie(sName);
	document.getElementById("txtSearchValue").value = sValue;
}

function DeleteThisCookie()
{
	var sName = document.getElementById("txtDeleteName").value;
	alert(sName);
	DeleteCookie(sName);
	document.getElementById("txtDeleteName").value = "";
	ShowCookies();
}
/********************************* End Test stuff ***********************************************/
