/*------------------------------------------------
	Project:		Papa Murphy's Re-design
	File:			my-functions.js
	
	INDEX //
	+ Browser Detection
	+ Nav RollOvers
		++ Old
		++ New
	+ Main Content
		++ Content Swapping
		++ Nav Animations
			+++ eClub
			+++ Our Menu
			+++ Store Locator
			+++ Special Promotions
	+ FAQ Page
	+ Start Process & Events
----------*/

/*--------------------------
	+ Browser Detection
----------------------------*/
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }

  return rv;
}


var isIE;
var ext;
if (navigator.userAgent.indexOf("MSIE")!=-1) {
	var rev = getInternetExplorerVersion();
	if(rev == 6){	
		isIE = true;
		isFirefox = false;
		isSafari = false;
		ext = ".gif";
	}else{
		isIE = false;
		isFirefox = true;
		isSafari = false;
		ext = ".png"
	}
}else{
	isIE = false;	
	if(navigator.userAgent.indexOf("Firefox") != -1){
		isFirefox = true;
		isSafari = false;
	}else{
		isFirefox = false;
		isSafari = true;
	}
	ext = ".png";
}


/* COOKIE FUNCTIONS */
//////////////////////
function set_menu(Name){
	document.cookie="menu="+Name;
}
function set_eClub(state){
	document.cookie="eClub="+state;
}
function set_storeLoc(state){
	document.cookie="storeLoc="+state;
}
function set_promo(state){
	document.cookie="promo="+state;	
}
function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		// if cookie exists
	if (offset != -1) {
		offset += search.length
		// set index of beginning of value
		end = document.cookie.indexOf(";", offset);
		// set index of end of cookie value
	if (end == -1) end = document.cookie.length;
		returnvalue=unescape(document.cookie.substring(offset, end))
	}
	}
	return returnvalue;
}

/*--------------------------
	+ Nav RollOvers
----------------------------*/

// ++ Old //
function rollOver(id) {
	if(id == 'nav1') { document.getElementById('navImg1').src="images/nav/but_witnbRO"+ext; };
	if(id == 'nav2') { document.getElementById('navImg2').src="images/nav/but_storeRO"+ext; };
	if(id == 'nav3') { document.getElementById('navImg3').src="images/nav/but_menuRO"+ext; };
	if(id == 'nav4') { document.getElementById('navImg4').src="images/nav/but_aboutRO"+ext; };
	if(id == 'nav5') { document.getElementById('navImg5').src="images/nav/but_franchRO"+ext; };
	if(id == 'nav6') { document.getElementById('navImg6').src="images/nav/but_eclubRO"+ext; };
}
function rollOut(id) {
	if(id == 'nav1') { document.getElementById('navImg1').src="images/nav/but_witnbNR"+ext; };
	if(id == 'nav2') { document.getElementById('navImg2').src="images/nav/but_storeNR"+ext; };
	if(id == "nav3") { document.getElementById('navImg3').src="images/nav/but_menuNR"+ext; }
	if(id == 'nav4') { document.getElementById('navImg4').src="images/nav/but_aboutNR"+ext; };
	if(id == 'nav5') { document.getElementById('navImg5').src="images/nav/but_franchNR"+ext; };
	if(id == 'nav6') { document.getElementById('navImg6').src="images/nav/but_eclubNR"+ext; };
}

// ++ Old //
var currentNav;

function newrollOver(id) {
	document.getElementById(id).src='images/nav/but_' + id + 'RO'+ext;
}
function newrollOut(id) {
	if(id != currentNav){
		document.getElementById(id).src='images/nav/but_' + id + 'NR'+ext;
	}
}

/*--------------------------
	+ Main Content
----------------------------*/

// ++ Content Swapping //
var mainContent = "main";
function resetMain(){
	openItem("home-content");
	document.getElementById("witnb").src = "images/nav/but_witnbNR"+ext;
	currentNav = "none";
	
}

function reDirect(id) {
	var hashed;
	// for hashing
	var strippedID = id.replace('#','');
	if(strippedID == 'eClub') {
		$(window).load(function(){
			openItem(strippedID);
			eClubRollOver();
			eClubDropDown();
		});
		
		hashed = "eClub";
		
	} else if(strippedID.substr(0,8) == 'our_menu') {
		set_menu(strippedID);
		$(window).load(function(){
			var deepLink = strippedID.split("/");
			menuRollOver();
			menuDropDown(false);
			if(deepLink.length > 1){
				cascadeMenu(deepLink, true);
			}else{
				openMenuItem(deepLink);
			}
		});
		
		hashed = "menu";
	} else if(strippedID == 'storeLocator' || strippedID == 'store-locator') {
		$(window).load(function(){
			storeRollOver();
			storeDropDown();
		});
		
		hashed = "storeLoc";
	} else if(strippedID == 'take-n-bake') {
		$(window).load(function() {
			newrollOver("witnb");
			openItem(strippedID);
		});
		
		hashed = "take-n-bake";
	} else if(strippedID == 'promo1'){
		promoRollOver();
		promoDropDown(false);
		swapContent(1);
		
		hashed = "promo";
		
	} else if(strippedID == 'promo2'){
		promoRollOver();
		promoDropDown(false);
		swapContent(2);
		
		hashed = "promo";
		
	} else {
		$(window).load(function(){
			pickPromo();
		});
		
		hashed = "none";
	}
	
	// for cookies
	if(get_cookie("eClub") == 'open' && hashed != "eClub"){
		$(window).load(function(){
			eClubRollOver();
			eClubDropDown(false);
			//alert("opening eClub");
		});
	}
	if(get_cookie("storeLoc") == 'open' && hashed != "storeLoc"){
		$(window).load(function(){
			storeRollOver();
			storeDropDown(false);
			//alert("opeining store locator");
		});
	}
	if(get_cookie("menu") != '' && hashed != "menu"){
		var splitUp = get_cookie("menu").split("/");
		$(window).load(function(){
			menuRollOver();
			menuDropDown(false);
			cascadeMenu(splitUp, false);
			//alert("opening menu");
		});
	}
	if(get_cookie("promo") == 'open' && hashed != 'promo'){
		$(window).load(function(){
			promoRollOver();
			promoDropDown(false);
			//alert("opening promos");
		});
	}
	
}

function cascadeMenu(id, deepLink){
	var topNavs = ["pizza", "side_items", "gift_certificates", "baking_instructions", "nutrition_info"];
	var pizzaSubs = ["signature_items", "custom", "stuffed", "gourmet", "deLite"];
	var sideSubs = ["apps", "desserts", "salads", "soft_drinks"];
	
	if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}
	
	var topLevel = topNavs.indexOf(id[1])+1;
	
	if(id.length == 2){
		if(deepLink){
			expandList(topLevel,'.hidden'+topLevel, 'top',id[1],"expandBtn"+topLevel,"");
		}else{
			expandList(topLevel,'.hidden'+topLevel, 'top',"","expandBtn"+topLevel,"");
		}
		
	}else if(id.length ==3){
		
		expandList(topLevel,'.hidden'+topLevel, 'top',"","","");
		
		var subGroup;
		if(pizzaSubs.indexOf(id[2]) == -1){
			subGroup = sideSubs;
		}else{
			subGroup = pizzaSubs;
		}
		var midLevel = (subGroup.indexOf(id[2])+1);
		
		window.setTimeout('expandList(0,".hidden'+topLevel+'-'+midLevel+'", "","","","")', 500);
		if(deepLink){
			window.setTimeout('openMenuItem("'+id[2]+'", "", "expandBtn'+topLevel+'-'+midLevel+'")', 500);
		}
		
	}else if(id.length ==4){
		
		expandList(topLevel,'.hidden'+topLevel, 'top',"","","");
		
		var subGroup;
		if(pizzaSubs.indexOf(id[2]) == -1){
			subGroup = sideSubs;
		}else{
			subGroup = pizzaSubs;
		}
		var midLevel = (subGroup.indexOf(id[2])+1);
		
		window.setTimeout('expandList(0,".hidden'+topLevel+'-'+midLevel+'", "","","","")', 500);
		if(deepLink){
			window.setTimeout('openMenuItem("'+id[3]+'")', 500);
		}
		
	}
}

var lastItem = "null";
function highlight(id){
	//alert(id);
	if(lastItem == "null" || lastItem == undefined){
		
	}else{
		document.getElementById(lastItem).style.textDecoration = "none";
	}
	document.getElementById(id).style.textDecoration = "underline";
	//alert(lastItem);
	lastItem = id;
	
}
function trackThis(id){
	try {
		var pageTracker = _gat._getTracker("UA-3860108-1");
		pageTracker._trackPageview(id);
	} catch(err) {}
}
function openMenuItem(id, newHash, hot) {
	//alert(id);
	xmlHttp.onreadystatechange = openedMenuItem;
	xmlHttp.open('GET', 'content/menu/' + id + '.asp', true);
	xmlHttp.send(null);
	
	if(id == "our_menu"){
		location.hash = "our_menu";
	}else{
		if(hot != undefined){
			window.setTimeout('highlight("'+hot+'")', 200);
		}else{
			window.setTimeout('highlight("'+id+'")', 200);	
		}
		
	}
	if(newHash == undefined || newHash == ''){
		location.hash = "our_menu";
		trackThis("our_menu");
	}else{
		set_menu("our_menu/"+newHash);
		location.hash = 'our_menu/'+newHash;
		trackThis(newHash);
	}
	
}
function openedMenuItem() {
	//alert(xmlHttp.readyState);
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			document.getElementById('main-content').innerHTML = xmlHttp.responseText;
			//alert(xmlHttp.responseText);
		}
	}
}

function openItem(id, setHash) {
	//alert(id);
	if(setHash != false){
		setHash = true;
	}else{
		setHash = false;	
	}
	xmlHttp.onreadystatechange = openedItem;
	xmlHttp.open('GET', 'content/' + id + '.asp', true);
	xmlHttp.send(null);
	if(setHash){
		location.hash = id;
	}
	if(id == "take-n-bake"){
		currentNav = "witnb";	
	}else if(id == "main"){
		currentNav = "none";
		document.getElementById("witnb").src = "images/nav/but_witnbNR"+ext;
	}
	//mainContent = newContent;
	trackThis(id);
}
function openedItem() {
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			document.getElementById('main-content').innerHTML = xmlHttp.responseText;
			//alert(xmlHttp.responseText);
		}
	}
}


// ++ Nav Animations //
// +++ coupons //
function couponsRollOver() {
	document.getElementById('couponTop').style.background='url(images/nav/coupons/couponTop'+ext+')';
	document.getElementById('couponMid').style.background='url(images/nav/coupons/couponMid'+ext+')';
	document.getElementById('couponBtm').style.background='url(images/nav/coupons/couponBtm'+ext+')';
	document.getElementById('couponTtl').style.background='url(images/nav/coupons/couponTtl'+ext+')';
}
function couponsRollOut() {
	document.getElementById('couponTop').style.background='url(images/nav/eClubOpen/eClubTop-Off'+ext+')';
	document.getElementById('couponMid').style.background='url(images/nav/eClubOpen/eClubMid-Off'+ext+')';
	document.getElementById('couponBtm').style.background='url(images/nav/eClubOpen/eClubBtm-Off'+ext+')';
	document.getElementById('couponTtl').style.background='url(images/nav/coupons/couponTtl-Off'+ext+')';
}
function couponsDropDown(setHash){
	if(setHash != false){
		setHash = true;	
	}
	
	$('#coupons').unbind('mouseout', couponsRollOut);
	$('.couponTtl').animate( { 
			left:'14px',
			top:'4px'
		}, 
		200, 'swing', cleanUpCoupons);
	$('.closeCoupon').fadeIn('fast');
	/*if(setHash){
		window.setTimeout('openItem("eClub")', 500);
	}
	
	$('#eclubTtl').bind('click', function(){openItem("eClub")});
	
	set_eClub("open");*/
}
function cleanUpCoupons() {
	$('#openCoupon').show('fast');
	$('#coupons').unbind('click', couponsDropDown);
}
function closeCoupon() {
	$('#coupons').bind('mouseout', couponsRollOut);
	$('#openCoupon').hide('fast');
	$('.couponTtl').animate( {
			left:'69px',
			top:'10px'
	},
	200, 'linear', startOverCoupons);
	$('.closeCoupons').fadeOut('fast');
}
function startOverCoupons(){
	$('#coupons').bind('click', couponsDropDown);
	$('#coupons').bind('mouseover', couponsRollOver);
}
function searchCoupons(){
	var zip = document.getElementById("couponZip").value;
	if(zip.length < 5){
		alert("Please enter a valid zip code.");
	}else{
		xmlHttp.onreadystatechange = gotCoupon;
		xmlHttp.open('GET', 'includes/getCoupon.asp?zip=' + zip, true);
		xmlHttp.send(null);
	}
}
var couponURL;
function gotCoupon(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			var tmp = xmlHttp.responseText.split(":");
			if(tmp[0] == "SUCCESS"){
				document.getElementById("couponPixels").innerHTML = getPixels();
				document.getElementById("couponError").style.display = "none";
				couponURL = tmp[1];
				pageTracker._trackPageview("/downloadCoupon/"+document.getElementById("couponZip").value);	
				setTimeout('document.location.href = couponURL;', 1000);
			}else{
				document.getElementById("couponError").style.display = "block";
			}
		}
	}
}
	$(document).ready(function() { $('#coupons').bind('click',  couponsDropDown); });
	$(document).ready(function() { $('#coupons').bind('mouseover', couponsRollOver); });
	$(document).ready(function() { $('#coupons').bind('mouseout', couponsRollOut); });

function getPixels(){
	var google1 = "http://www.googleadservices.com/pagead/conversion/1063457234/?random=1256675856233&cv=6&fst=1256675856233&num=1&fmt=1&value=0&label=AiLiCOqXRRDSo4z7Aw&bg=ffffff&hl=en&gl=US&guid=ON&u_h=1600&u_w=2560&u_ah=1511&u_aw=2560&u_cd=24&u_his=2&u_tz=-300&u_java=true&u_nplug=7&u_nmime=94&url="+document.location.href;
	var google2 = "http://googleads.g.doubleclick.net/pagead/viewthroughconversion/1063457234/?random=1256675856233&cv=6&fst=1256675856233&num=1&fmt=1&value=0&label=AiLiCOqXRRDSo4z7Aw&bg=ffffff&hl=en&gl=US&guid=ON&u_h=1600&u_w=2560&u_ah=1511&u_aw=2560&u_cd=24&u_his=2&u_tz=-300&u_java=true&u_nplug=7&u_nmime=94&url="+document.location.href+"&ctc_id=CAIVAgAAAB0CAAAA&ct_cookie_present=false";
	var yahoo="http://srv1.wa.marketingsolutions.yahoo.com/script/ScriptServlet?aid=13R9CA9BL9AVG1OOS1RULSTT6F8";
	return "<img src='"+google1+"' /><img src='"+google2+"' /><img src='"+yahoo+"' />";
}



// +++ eClub //
function eClubRollOver() {
	document.getElementById('eclubTop').style.background='url(images/nav/eClubOpen/eClubTop'+ext+')';
	document.getElementById('eclubMid').style.background='url(images/nav/eClubOpen/eClubMid'+ext+')';
	document.getElementById('eclubBtm').style.background='url(images/nav/eClubOpen/eClubBtm'+ext+')';
	document.getElementById('eclubTtl').style.background='url(images/nav/eClubOpen/eClubTtl'+ext+')';
}
function eClubRollOut() {
	document.getElementById('eclubTop').style.background='url(images/nav/eClubOpen/eClubTop-Off'+ext+')';
	document.getElementById('eclubMid').style.background='url(images/nav/eClubOpen/eClubMid-Off'+ext+')';
	document.getElementById('eclubBtm').style.background='url(images/nav/eClubOpen/eClubBtm-Off'+ext+')';
	document.getElementById('eclubTtl').style.background='url(images/nav/eClubOpen/eClubTtl-Off'+ext+')';

}
if(location.hash != '#eClub') {
	$(document).ready(function() { $('#eClub').bind('click',  eClubDropDown); });
	$(document).ready(function() { $('#eClub').bind('mouseover', eClubRollOver); });
	$(document).ready(function() { $('#eClub').bind('mouseout', eClubRollOut); });
}

function eClubDropDown(setHash) {
	if(setHash != false){
		setHash = true;	
	}
	
	$('#eClub').unbind('mouseout', eClubRollOut);
	$('.eclubTtl').animate( { 
			left:'-6px',
			top:'-1px'
		}, 
		200, 'swing', cleanUpClub);
	$('.closeEClub').fadeIn('fast');
	if(setHash){
		window.setTimeout('openItem("eClub")', 500);
	}
	
	$('#eclubTtl').bind('click', function(){openItem("eClub")});
	
	set_eClub("open");
}
function cleanUpClub() {
	$('#openEClub').show('fast');
	$('#eClub').unbind('click', eClubDropDown);
}

function closeEClub() {
	$('#eClub').bind('mouseout', eClubRollOut);
	$('#openEClub').hide('fast');
	$('.eclubTtl').animate( {
			left:'69px',
			top:'10px'
	},
	200, 'linear', startOverClub);
	$('.closeEClub').fadeOut('fast');
	openItem('main-content');
	
	set_eClub("closed");
}
function startOverClub() {
	$('#eClub').bind('click', eClubDropDown);
	$('#eClub').bind('mouseover', eClubRollOver);
}
function ajaxEclub(){
	var frm = document.getElementById("eclubForm");
	var errors = "";
	if(frm.First_Name.value == ""){
		errors += "First Name\r\n";
	}
	if(frm.Last_Name.value == ""){
		errors += "Last Name\r\n";	
	}
	if(frm["Email Address"].value == ""){
		errors += "Email Address\r\n";	
	}
	if(frm["Postal Code"].value == ""){
		errors += "Postal Code\r\n";
	}
	if(frm.Birthday_Month.value == "" || frm.Birthday_Day.value == "" || frm.Birthday_Year.value == ""){
		errors += "Birthday";	
	}
	if(errors != ""){
		alert("The following fields are required:\r\n"+errors);
	}else{
		frm.submit();
	}
}
function gotEClub(){
	//alert(window.frames['eclubResponse'].location.href);
	var responseURL = window.frames['eclubResponse'].location.href;
	if(responseURL != "about:blank"){		
		if(responseURL.indexOf("?") == -1){
			document.getElementById('eClubContents').innerHTML = "Thank you for signing up for our EClub!<br><br>Check your inbox to complete your membership.";
		}else{
			var tmp = responseURL.split("?");
			var params = tmp[1].split("&");
			var errorCode = params[0].substr(params[0].indexOf("=")+1, params[0].length);
			var errorControl = params[1].substr(params[1].indexOf("=")+1, params[1].length);
			if(errorCode == 8){
				eclubError("Thanks for your interest, but you are already a member of our eClub.");
			}else if(errorCode == 4){
				var msg = "The value of ";
				if(errorControl == "DataProfileValues.Birthday_Month"){
					msg += "birthday month";
				}else if(errorControl == "DataProfileValues.Birthday_Day"){
					msg += "birthday day";
				}else if(errorControl == "DataProfileValues.Birthday_Year"){
					msg += "birthday year";
				}else if(errorControl == "Email%20Address"){
					msg += "email address";
				}
				msg += " is invalid. Please correct this and try again.";
				eclubError(msg, true);
			}else{
				eclubError("Sorry, there was a problem with your request.", true);
			}
		}
	}
}
function eclubError(msg, retry){
	if(retry){
		document.getElementById('eClubError').innerHTML = msg;
	}else{
		document.getElementById('eClubContents').innerHTML = msg;
	}
}
function eclubListen() {
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
		//var win=window.open(document.getElementById("eclubForm").action+"?"+xmlHttp.responseText);
		//win.focus();
		window.location.href = document.getElementById("eclubForm").action+"?"+xmlHttp.responseText;
	}
}
// +++ Our Menu //
function menuRollOver() {
	document.getElementById('menuTop').style.background='url(images/nav/ourMenuOpen/ourMenuTop'+ext+')';
	document.getElementById('menuMid').style.background='url(images/nav/ourMenuOpen/ourMenuMid'+ext+')';
	document.getElementById('menuBtm').style.background='url(images/nav/ourMenuOpen/ourMenuBtm'+ext+')';
	document.getElementById('menuTtl').style.background='url(images/nav/ourMenuOpen/ourMenuTtl'+ext+')';
}
function menuRollOut() {
	document.getElementById('menuTop').style.background='url(images/nav/ourMenuOpen/ourMenuTop-Off'+ext+')';
	document.getElementById('menuMid').style.background='url(images/nav/ourMenuOpen/ourMenuMid-Off'+ext+')';
	document.getElementById('menuBtm').style.background='url(images/nav/ourMenuOpen/ourMenuBtm-Off'+ext+')';
	document.getElementById('menuTtl').style.background='url(images/nav/ourMenuOpen/ourMenuTtl-Off'+ext+')';
}
if(location.hash != '#our_menu') {
	$(document).ready(function() { $('#ourMenu').bind('click',  menuDropDown); });
	$(document).ready(function() { $('#ourMenu').bind('mouseover', menuRollOver); });
	$(document).ready(function() { $('#ourMenu').bind('mouseout', menuRollOut); });
}
function menuDropDown(setHash) {
	if(setHash != false){
		setHash = true;	
	}else{
		setHash = false;
	}
	$('.navBlock').css('cursor:normal;');
	$('#ourMenu').unbind('mouseout', menuRollOut);
	$('.menuTtl').animate( { 
			left:'11px',
			top:'-5px'
		}, 
		200, 'swing', cleanUp);
	$('.closeMenu').fadeIn('fast');
	if(setHash){
		openMenuItem('our_menu');
	}
	set_menu("open");
}
function cleanUp() {
	$('#openMenu').show('fast');
	$('#ourMenu').unbind('click', menuDropDown);
}

function closeMenu() {
	$('#ourMenu').bind('mouseout', menuRollOut);
	$('#openMenu').hide('fast');
	$('.menuTtl').animate( {
			left:'69px',
			top:'4px'
	},
	200, 'linear', startOver);
	$('.closeMenu').fadeOut('fast');
	openItem('main-content');
	
	set_menu("");
}
function startOver() {
	$('#ourMenu').bind('click', menuDropDown);
	$('#ourMenu').bind('mouseover', menuRollOver);
}
function expandList(i, ul, level, id, makeHot, newHash) {
	if(level == 'top') {
		//$('.plusMinus' + i).toggle();
	}
	$(ul).toggle('fast');
	if(id == undefined || id == '') {
		
	} else {
		openMenuItem(id, newHash, makeHot);
	}
}
// +++ Store Locator //
if(location.hash != '#storeLocator') {
	$(document).ready(function() { $('#storeLocator').bind('click',  storeDropDown); });
	$(document).ready(function() { $('#storeLocator').bind('mouseover', storeRollOver); });
	$(document).ready(function() { $('#storeLocator').bind('mouseout', storeRollOut); });
}
function storeRollOver() {
	document.getElementById('locTop').style.background='url(images/nav/locator/locTop'+ext+')';
	document.getElementById('locMid').style.background='url(images/nav/locator/locMid'+ext+')';
	document.getElementById('locBtm').style.background='url(images/nav/locator/locBtm'+ext+')';
	document.getElementById('locTtl').style.background='url(images/nav/locator/storeLocTtl'+ext+')';
}
function storeRollOut() {
	document.getElementById('locTop').style.background='url(images/nav/locator/locTop-Off'+ext+')';
	document.getElementById('locMid').style.background='url(images/nav/locator/locMid-Off'+ext+')';
	document.getElementById('locBtm').style.background='url(images/nav/locator/locBtm-Off'+ext+')';
	document.getElementById('locTtl').style.background='url(images/nav/locator/storeLocTtl-Off'+ext+')';
}
function setStoreOpen() {
	storeRollOver();
	storeDropDown('#storeLocator');
}
function storeDropDown(setHash) {
	if(setHash != false){
		setHash = true;	
	}else{
		setHash = false;
	}
	
	$('#storeLocator').unbind('mouseout', storeRollOut);
	$('#locTtl').animate( { 
			left:'17px',
			top:'-7px'
		}, 
		200, 'linear', cleanUpStore);
	$('.closeBtn').fadeIn('fast');
	if(setHash){
		//location.hash = '#storeLocator';
	}
	
	set_storeLoc("open");
	trackThis("store locator");
}
function cleanUpStore() {
	$('#locator_content').show('fast');
	$('#storeLocator').unbind('click', storeDropDown);
}

function closeStore() {
	$('#storeLocator').bind('mouseout', storeRollOut);
	$('#locator_content').hide('fast');
	$('#locTtl').animate( {
			left:'60px',
			top:'0px'
	},
	200, 'linear', startOverStore);
	$('.closeBtn').fadeOut('fast');
	
	set_storeLoc("closed");
}
function startOverStore() {
	$('#storeLocator').bind('click', storeDropDown);
	$('#storeLocator').bind('mouseover', storeRollOver);
	document.getElementById("zip").style.display = "none";
	document.getElementById("edit").style.display = "block";
}
function enterZip(){
	$('#zip').show('fast', hideEnter);
}
function hideEnter(){
	$('#edit').hide('fast');	
}
function autoStoreSearch(){
	xmlHttp.onreadystatechange = getStoreResults;
	xmlHttp.open('GET', 'includes/storeResults.asp', true);
	xmlHttp.send(null);
}
function searchStores(){
	var frm = document.getElementById("storeSearch");
	if(frm.zip.value != "" || (frm.city.value != "" && frm.state.value != "")){
		if(frm.zip.value != ""){
			var params = "zip="+frm.zip.value;	
		}else{
			var params = "city="+frm.city.value+"&state="+frm.state.value;
		}
		xmlHttp.onreadystatechange = getStoreResults;
		xmlHttp.open('GET', 'includes/storeResults.asp?search_param=N3&' + params, true);
		xmlHttp.send(null);
	}else{
		alert("Please enter a zip code or a city and state.");	
	}
}
function getStoreResults(){
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if(xmlHttp.responseText.substring(0, 5) == "ERROR"){
			var tmp = xmlHttp.responseText.split(":");
			document.getElementById("storeContent").innerHTML = tmp[1]+"<br><br><div class='skinny'></div>";
		}else{
			document.getElementById("storeContent").innerHTML = "<b>Your Closest Stores:</b><br>"+xmlHttp.responseText;
			document.getElementById("edit").style.display="inline";
			document.getElementById("zip").style.display="none";
		}
		
	}
}

// +++ Special Promotions //
function promoRollOver() {
	document.getElementById('promoTop').style.background='url(images/nav/promoOpen/promoTop'+ext+')';
	document.getElementById('promoMid').style.background='url(images/nav/promoOpen/promoMid'+ext+')';
	document.getElementById('promoBtm').style.background='url(images/nav/promoOpen/promoBtm'+ext+')';
	document.getElementById('promoTtl').style.background='url(images/nav/promoOpen/promoTtl'+ext+')';
}
function promoRollOut() {
	document.getElementById('promoTop').style.background='url(images/nav/promoOpen/promoTop-Off'+ext+')';
	document.getElementById('promoMid').style.background='url(images/nav/promoOpen/promoMid-Off'+ext+')';
	document.getElementById('promoBtm').style.background='url(images/nav/promoOpen/promoBtm-Off'+ext+')';
	document.getElementById('promoTtl').style.background='url(images/nav/promoOpen/promoTtl-Off'+ext+')';
}
$(document).ready(function() { $('#promo').bind('click',  promoDropDown); });
$(document).ready(function() { $('#promo').bind('mouseover', promoRollOver); });
$(document).ready(function() { $('#promo').bind('mouseout', promoRollOut); });
function promoDropDown(setHash) {
	if(setHash != false){
		setHash = true;	
	}else{
		setHash = false;
	}
	$('#promo').unbind('mouseout', promoRollOut);
	$('.promoTtl').animate( { 
			left:'8px',
			top:'-1px'
		},
		200, 'swing', cleanUpPromo);
	$('.closePromo').fadeIn('fast');
	if(setHash){
		//openItem('promo');
	}
	set_promo("open");
}
function cleanUpPromo() {
	$('#openPromo').show('fast');
	$('#promo').unbind('mouseout', promoRollOut);
	$('#promo').unbind('click', promoDropDown);
}

function closePromo() {
	$('#promo').bind('mouseout', promoRollOut);
	$('#openPromo').hide('fast');
	$('.promoTtl').animate( {
			left:'112px',
			top:'10px'
	},
	200, 'linear', startOverPromo);
	$('.closePromo').fadeOut('fast');
	//openItem('promo');
	set_promo("closed");
}
function startOverPromo() {
	$('#promo').bind('click', promoDropDown);
}
var promos = Array('set1', 'set2', 'set3');
var currentPos = Array();
function promoInit() {
	currentPos = [1, 2];
}
promoInit();
function prev() {
	newFirstPos = currentPos[0] - 1;
	newSecondPos = currentPos[1] - 1;
	if(newFirstPos == 0) {
		newFirstPos = promos.length;
	}
	if(newSecondPos == 0) {
		newSecondPos = promos.length;
	}
	currentPos = [newFirstPos, newSecondPos];
	run(currentPos);
}
function next() {
	newFirstPos = currentPos[0] + 1;
	newSecondPos = currentPos[1] + 1;
	if(newFirstPos == promos.length + 1) {
		newFirstPos = 1;
	}
	if(newSecondPos == promos.length + 1) {
		newSecondPos = 1;
	}
	currentPos = [newFirstPos, newSecondPos];
	run(currentPos);
}
function run(pos) {
	for(i = 1; i <= promos.length; i++) {
		if(i == pos[0]) {
			document.getElementById('set' + pos[0]).style.display = 'block';
			document.getElementById('set' + pos[0]).style.left = '30px';
		} else if(i == pos[1]) {
			document.getElementById('set' + pos[1]).style.display = 'block';
			document.getElementById('set' + pos[1]).style.left = '185px';
		} else {
			document.getElementById('set' + i).style.display = 'none';
			document.getElementById('set' + i).style.left = '-520px';
		}
	}
}
function swapContent(id) {
	document.getElementById('home').style.backgroundImage = 'url(images/1600x1350_promo0' + id + '.jpg)';
	openItem('promo' + id);
}
function pickPromo() {
	var randomNumber = randomToN(2, 0);
	var randCheck = checkRandomNumber(randomNumber);
	openItem('promo' + randCheck);
}

function randomToN(maxVal,floatVal) {
   var randVal = Math.random()*maxVal;
   return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}
function checkRandomNumber(num) {
	if(num == 0) {
		return randomToN(2, 0);
	} else {
		return num;
	}
}

/*--------------------------
	+ FAQ Page
----------------------------*/
function switchAnswer(id){
	coldAll();
	makeHot("q"+id);
	
	hideallAnswers();
	showAnswer("a"+id);
}

function hideallAnswers(){
	var i = 1;
	while(document.getElementById("a"+i)){
		hideAnswer("a"+i);
		i++;
	}
}
function coldAll(){
	var i = 1;
	while(document.getElementById("a"+i)){
		makeCold("q"+i);
		i++;
	}
}
function hideAnswer(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
function makeCold(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.color = '#000';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.color = '#000';
		}
		else { // IE 4
			document.all.id.style.color = '#000';
		}
	}
}

function showAnswer(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
function makeHot(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.color = '#bf2e1a';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.color = '#bf2e1a';
		}
		else { // IE 4
			document.all.id.style.color = '#bf2e1a';
		}
	}
}

/*--------------------------
	+ Start Process & Events
----------------------------*/
function friendlyCheck(){
	var adds = '';
	var errors = 'false';
		if ($F('first_name') == ''){
			adds += 'First Name\n';
			var errors = 'true';
		}
		if ($F('last_name')==''){
			adds += 'Last Name\n';
			var errors = 'true';
		}
		if ($F('street')==''){
			adds += 'Street\n';
			var errors = 'true';
		}
		if ($F('city')==''){
			adds += 'City\n';
			var errors = 'true';
		}
		if ($F('state')==''){
			adds += 'State or Province\n';
			var errors = 'true';
		}
		if ($F('zip')==''){
			adds += 'Zip\n';
			var errors = 'true';
		}
		if ($F('email')==''){
			adds += 'Email\n';
			var errors = 'true';
		}
		if ($F('email')!=$F('email2')){
			adds += 'Confirm Email\n';
			var errors = 'true';
		}
		if ($F('phone')==''){
			adds += 'Phone\n';
			var errors = 'true';
		}
		if ($F('lead_source')=='--None--'){
			adds += 'How did you hear about us?\n';
			var errors = 'true';
		}
		
		if ($F('00N30000001Guzk')=='select'){
			adds += 'Requested State\n';
			var errors = 'true';
		}
		if ($F('00N30000001Gs7v')=='--Select--'){
			adds += 'Cash Available\n';
			var errors = 'true';
		}
		if ($F('00N30000001Gs8K')=='--Select--'){
			adds += 'Net Worth\n';
			var errors = 'true';
		}
		if (document.getElementsByName("00N30000001Gs7N")==''){
			adds += 'Requested City\n';
			var errors = 'true';
		}
	if (errors == 'true'){
		var goalert = alert('The following fields are required:\n' + adds);
		return false;
	}else{
	return true;
	}
}
function check(frm) {
valid = true;
		var curvis=findObj('staterequested').value;
	if ((frm.staterequested.selectedIndex == "") || (frm.staterequested.options[frm.staterequested.selectedIndex].value == "") || (frm[curvis].selectedIndex == "") || (frm[curvis].options[frm[curvis].selectedIndex].value == "")) {
		valid = false;
	}
	if (valid) {
		frm.submit();
	}
	else { alert("You must select a state AND city.");
	}
	return valid;
}
function findObj(n, d) { //v3.0
	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=findObj(n,d.layers[i].document); return x;
}
function hideObj(objName) {
	var obj=findObj(objName); if(obj!=null) {obj.disabled = true; if(obj.style) {obj.style.display = 'none';}}
}
function showObj(objName) {
	var obj=findObj(objName); if(obj!=null) {obj.disabled = false; if(obj.style) {obj.style.display = 'block';}}
}
function switchstates() {
	var curvis=findObj('00N30000001Guzk').value;
	hideObj(lastvis); showObj(curvis); lastvis=curvis;
}

$F = document.getElementById("franchiseForm");