/* jQuery No Conflict */
jQuery.noConflict();
/* Global Vars */

var root = "";


/* Functions */

function initialize(newRoot)
{
	root = newRoot;
	
}

/**********************************************************************************
Load Yeti Wildcards
**********************************************************************************/
jQuery(document).ready(function()
{
    if(jQuery('body').attr('class') == "yeti")
    {
        jQuery('#yetiWildcards').show();
    }
    else
    {
       jQuery('#yetiWildcards').hide();
    }
});

/**********************************************************************************
Deals Callout Menu Page
**********************************************************************************/
jQuery(document).ready(function()
{
    jQuery('.loginDeals').click(function(){
          if (getCookie("_qouid"))
          {
            window.location = baseQuickOrderURL + PageMoreDeals + dealsTracking;
          }
          else
          {
            window.location = rootURL + 'deals.aspx' + dealsTracking;
          }
    });
});


/**********************************************************************************
View More Deal Information
**********************************************************************************/
jQuery(document).ready(function()
{
    //Clear Title
    jQuery('#orderNowBtn').click(function(){
        jQuery('#itemTitle, #addToOrderText').html('');
    });
});


/***********************************************************************************
Send/View Deals
***********************************************************************************/
function sendDeals()
{
    var userEnteredEmail = jQuery('input#getDealEmail').val();
    CreateOverlay();
    Center(jQuery('#dealsLightbox'));
    jQuery(window).resize(AdjustOverlay);
    jQuery(window).resize(Center(jQuery('#dealsLightbox')));
    jQuery(window).scroll(Center(jQuery('#dealsLightbox')));
    jQuery('#modalBackground').fadeIn(500, function(){
       jQuery('#dealsLightbox').slideDown(500);
       jQuery('.emailSD').val(userEnteredEmail);
    });
    
}

jQuery(function(){
    jQuery('input').keypress(function(e)
    {
        if(e.which==13)
        {
            var enterSendDeals = jQuery(this).parent().attr('class');

            switch (enterSendDeals){
                case "formInputs":
                return sendOptInInformation();
                break;
              
                default :
                break; 
            }
        }
    });
});

function viewYetiDeals()
{
      if (getCookie("_qouid"))
      {
        window.location = baseQuickOrderURL + PageMoreDeals + '?WT.mc_id=060809Yeti_View_All_Deals';
      }
      else
      {
        window.location = rootURL + 'deals.aspx?WT.mc_id=060809Yeti_View_All_Deals';
      }
}

function viewSlinkyDeals()
{
      if (getCookie("_qouid"))
      {
        window.location = baseQuickOrderURL + PageDeals + '?WT.mc_id=060809Slinky_Cookied_View_All_Deals';
      }
      {
        window.location = rootURL + 'deals.aspx?WT.mc_id=060809Slinky_Non-Cookied_View_All_Deals';
      }
}

/************************************************************************************
Add Item to Cart
************************************************************************************/

//Insert text in lightbox headline when we add an item to the cart
jQuery(document).ready(function() {
    jQuery('.addItem').click(function() {
        var itemTitle = jQuery(this).attr('type');
        jQuery('#itemTitle').html(itemTitle);
        jQuery('#addToOrderText').html(' will be added to your order. ');
    });
    
    jQuery('.buildPizza').click(function(){
        var buildPizzaTitle = jQuery(this).attr('type');
        jQuery('#itemTitle').html(buildPizzaTitle);
        jQuery('#addToOrderText').html('');
    });
});

/************************************************************************************
Form Field Clear
************************************************************************************/

jQuery(document).ready(function() {
      var address = "Enter a Street Address";
      var zip = "Enter a ZIP Code";
      var city = "Enter Your City";
      
      jQuery('#orderNowMid select, .dealsLogin select, #dealsLogin select, .loginBox select, #locations select').change(function(){
            jQuery('#orderNowMid select option:selected, .dealsLogin select option:selected, #dealsLogin select option:selected, .loginBox select option:selected, #locations select option:selected').each(function () {
                if(jQuery(this).text() != "Please Select a State")
                {
                    jQuery('#stateLL, #stateMH, #stateDE').slideUp();   
                }
              });
      });
      
      jQuery('#orderNowMid :input[type="text"], .dealsLogin :input[type="text"], #dealsLogin :input[type="text"], .loginBox :input[type="text"], #locations :input[type="text"], #orderNowMid :input[type="password"], .dealsLogin :input[type="password"], #dealsLogin :input[type="password"], .loginBox :input[type="password"]').focus(function(){

            //Clear out error messages on focus of form field
            if(jQuery(this).attr('type') == "text")
            {
                jQuery(this).prev().slideUp();
            }

            if(jQuery(this).prev().prev().prev().hasClass('cityState'))
            {
                jQuery('#cityLL, #cityMH, #cityDE').slideUp();
            }

            //Value is blank on focus
            if(this.value == "" || this.value == address || this.value == zip || this.value == city) //Do not need to clear password value because it is two different input boxes
            {
                this.value = "";
            }
            
            //On blur, if the value is left blank or is the original text, leave as original text
            jQuery(this).blur(function(){
                if(this.value == "" && jQuery(this).hasClass('streetAddressText'))
                {
                    this.value = address;
                }
                else if(this.value == "" && jQuery(this).hasClass('zipCodeText'))
                {
                    this.value = zip;
                }
                else if(this.value == "" && jQuery(this).hasClass('cityText'))
                {
                    this.value = city;
                }
            });
            
            jQuery('.passwordTextLL').blur(function(){
                if(this.value == "")
                {
                    jQuery('.passwordTextLL').hide();
                    jQuery('.switchTextBoxLL').show();
                }
            });

      });

      //On Enter, submit Forms for sign in
      jQuery('input').keypress(function(e)
      {
            if(e.which==13)
            {
                var grandParent = jQuery(this).parent().parent().attr('id');
                var zipCityGrandParent = jQuery(this).parent().parent().parent().attr('id');
                grandParent = grandParent + zipCityGrandParent;
                
                switch (grandParent){

                case "newCustomerLL":
                return getCookieInformationLightbox('NewLL');
                break;
                
                case "newCustomerMH":
                return getCookieInformation();
                break;
                
                case "newCustomerMHorderOnlineNow":
                return getCookieInformation();
                break;
                
                case "newCustomerDE":
                return getCookieInformation();
                break;

                case "newCustomerDEdealsGuestUser":
                return getCookieInformation();
                break;
                
                case "newCustomerDEcenter":
                return getCookieInformation();
                break;
                
                default :
                break; 
                }
                return false;
            }            
      });


});

/***********************************************************************************
    Clear out Get More Deals Form
*************************************************************************************/


jQuery(document).ready(function() {
    //var clearMePrevious = "";
    
    jQuery('.emailAddress, .emailSD').focus(function()
    {       
        if(jQuery(this).val() == "Enter Your Email Address")
        {
            jQuery(this).attr('value', '');
        }
        /*if(jQuery(this).val() == jQuery(this).attr('value'))
        {   
           //setting the var clearMePrevious to whatever the value is; then clearing out the value.
            //clearMePrevious = jQuery(this).val();
            //jQuery(this).val("");
        }*/
    });

    // if field is empty afterward, add text again
    jQuery('.emailAddress, .emailSD').blur(function()
    {
        if(jQuery(this).val() == '')
        {
            jQuery(this).attr('value', "Enter Your Email Address");
        }
        
    });
    
   //start sendDeals on key press 
    jQuery('#getDealEmail').keypress(function(e)
       {
            if(e.which==13)
            {               
                sendDeals();
            }
        });
    
 });  
 
  




/************************************************************************************
Yeti Wildcard Hover
************************************************************************************/

jQuery(document).ready(function(){
    var obj = jQuery('#yetiWildcards .wildcardWrapper');    
    var imgContainer = jQuery('#wildcardTooltip2');
    var displayTimeout, displayDuration= 0, hoverTimeout, hoverDuration = 0;
    //On mouse over
    jQuery(obj).bind('mouseover', function(event){
    
        //Get top of hover object    
        var imageTop = jQuery(this).offset().top;
        //Get width of object
        var imageWidth = jQuery(this).offset().left;
        
        //Adjust the top position of where the hover is on the object hovered 
        imageTop = imageTop -72;
        //Adjust the left position of where the hover is on the object hovered 
        imageWidth = imageWidth - 45;
        
        //Get Image of object hovered on
        var toolImage = jQuery('div', this).children()[3];
        
        //Get Image src of object hovered on
        var toolImageSrc = toolImage.src;
        
        var toolImageClass = jQuery(toolImage).attr('class');
       
        //Get width of image of object hovered on
        var toolImageWidth = jQuery(toolImage).width();
        
        //Get height of image of object hovered on
        var toolImageHeight = jQuery(toolImage).height();
        
        //Get alternate text of image of object hovered on
        var toolImageAlt = jQuery(this).find('img').attr('alt');
       
        //Get headline of image of object hovered on
        var wcHeadline = jQuery(this).find('h3').html();
           
        //Get copy of image of object hovered on
        var wcCopy = jQuery(this).find('p').attr('title');
        
        //Get Link text of image of object hovered on
        var wcLinkText = jQuery(this).find('a').text();
        
        //Get href of link of image of object hovered on
        var wcLink = jQuery(this).find('a').attr('href');
        
        var wcTarget = jQuery(this).find('a').attr('targetType');
        
        //Create Wildcard wrapper and innerHTML the attributes listed above
        jQuery(imgContainer).html('<div style="position:relative;"><div class="wildcardWrapperTT"><div style="width:75px;position:absolute;bottom:-4px;*bottom:-14px;_bottom:-4px; left:8px;"><div class="wcImage ' + toolImageClass + '" style="background:url(' + toolImageSrc + ') no-repeat; _background-image:none; _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'scale\', src=\'' + toolImageSrc + '\'); width:' + toolImageWidth + 'px; height:' + toolImageHeight + 'px; _margin-top: 2px;"></div></div><div style="_margin-top: 2px; margin-left:85px; width:140px;"><h2>' + wcHeadline + '</h2><p>' + wcCopy + '</p></div> <a href=\''  + wcLink + '\' class="link">' + wcLinkText +' </a></div></div>');
        jQuery('.wildcardTooltipLink').css({'top':imageTop + 'px', 'left':imageWidth + 'px', 'display':'block'});
        jQuery('.wildcardTooltipLink').attr('href', wcLink);
        if(wcTarget == 0)
        {
            jQuery('.wildcardTooltipLink').attr('target', '_self');
        }
        else
        {
            jQuery('.wildcardTooltipLink').attr('target', '_blank');
        }
        
        
        //Position where wildcard goes
        clearTimeout(displayTimeout);
        hoverTimeout = setTimeout(function(){
            jQuery(imgContainer).css({'position':'absolute', 'display':'block', 'top':imageTop + 'px', 'left':imageWidth + 'px', 'z-index':'30'});
        }, hoverDuration);

     });        
     
    jQuery('#wildcardTooltip2, .wildcardTooltipLink').hover(function(){
        clearTimeout(displayTimeout);
        }, function(){
        displayTimeout = setTimeout(function(){ jQuery(imgContainer).hide();jQuery('.wildcardTooltipLink').css('display','none'); jQuery(imgContainer).html('');}, 0);
    });

});


/**********************************************************************************
Wildcard Window Opener
**********************************************************************************/
jQuery(document).ready(function(){
    jQuery('.wildcardMiddle a').click(function(){
         var link = jQuery(this).attr('href');
         var target = jQuery(this).attr('targetType');
         if (IsCookied == 'Y')
         {
            var cookiedLink = link.replace(/Non/, '');
            if(target == 0)
            {
                window.location = cookiedLink;
                return false;
            }
            else
            {
                window.open(cookiedLink, '_blank');
                return false;
            }
         }
         else
         {
            if(target == 0)
            {
                window.location = link;
                return false;
            }
            else
            {
                window.open(link, '_blank');
                return false;
            }
         }
    });        
});    


/************************************************************************************
Help TooltipHovers
************************************************************************************/

//Help tooltip hovers for help bubbles
jQuery(document).ready(function(){
    var obj = jQuery('.helpHover');    
    var imgContainer = jQuery('#helpTooltip');
    
    //on mouse over of obj('.helpHover') show tooltip
    jQuery(obj).hover(function(){
        //Get Height of object
        var imageTop = jQuery(this).offset().top;
        //Get width of object
        var imageWidth = jQuery(this).offset().left;
        
        imageTop = imageTop - 133;
        imageWidth = imageWidth - 130;
        
        //on item hovered, get the title attribute
        var tooltipHelp = jQuery(this).attr('title');
        
        //innerHTML info from title attribute into help tooltip
        jQuery(imgContainer).html('<p>' + tooltipHelp + '</p>');
        
        //Show help tooltip
        jQuery(imgContainer).show();
        
        //Style help tooltip
        jQuery(imgContainer).css({'position':'absolute', 'top':imageTop + 'px', 'left':imageWidth + 'px', 'z-index':'1000'});
    }, function(){
        //Hide help tooltip
        jQuery(imgContainer).hide();
    });
});

/************************************************************************************
Navigation
************************************************************************************/

jQuery(document).ready(function(){
    var navDuration = 200; //time in miliseconds
    var navJumpHeight = "7px"; //Variable set for how much to animate tab
      
      //On hover of navigation animate the tabs
      jQuery('ul#primaryNavigation li').hover(function() {
          
          //Get img of object hovered over
          imgs = jQuery('img', this); 
          
          //hide image
          imgs.css('display', 'none');
          
          //animate background-image by navJumpHeight variable
          jQuery(this).animate({ top : "-="+navJumpHeight }, navDuration);            
      }, function() {
      
          //on mouse off, show image
          imgs = jQuery('img', this);
          imgs.css({'display': 'block'});
          
          //animate background-image back to starting point
          jQuery(this).animate({ top : "0px" }, 20);
      });
});

/************************************************************************************
ZIP Code/CityState Change
************************************************************************************/

jQuery(document).ready(function(){

    //On click of object ('a.noZip') hide zip fields and show city and state fields
    jQuery('a.noZip').click(function()
    {
        //Hide Zip Code Fields
        jQuery('.zipCodeWrapper').hide();
        
        //Show city and state fields
        jQuery('.cityStateWrapper').show();
    
        //hide previous city/state errors
        jQuery('#cityMH, #cityLL, #cityDL, #cityDE, #stateMH, #stateLL, #stateDL, #stateDE').hide(); //Hide Errors
        return false;
    });

    //on click of object('a.noCityState') hide city and state fields and show zip fields
    jQuery('.noCityState').click(function()
    {
        //Show Zip code fields
        jQuery('.zipCodeWrapper').show();
        
        //Hide city and state fields
        jQuery('.cityStateWrapper').hide();
        
        //Hide all previous zip errors
        jQuery('#zipMH, #zipLL, #zipDL, #zipDE').hide(); //Hide Errors
        return false;
    });
});

/************************************************************************************
Button Hover
************************************************************************************/
jQuery(document).ready(function(){
    
    //Get button hovered
    var button = jQuery('img.button');
   
    //on mouseover of button, get image src and replace .gif with _on.gif
    button.bind('mouseover', function buttonOver(event){
        jQuery(this).attr("src", jQuery(this).attr("src").split(".gif").join("_on.gif")); 
    });
    
    //on mouseout of button, get image src and replace _on.gif with .gif
    button.bind('mouseout', function buttonOut(event){
        jQuery(this).attr("src", jQuery(this).attr("src").split("_on.gif").join(".gif"));
    });


    // Do the same as we did for the button links above
    var inputBtn = jQuery('input.button');

    
    inputBtn.bind('mouseover', function(event){
        jQuery(this).attr('src', function(){
            jQuery(this).attr("src", jQuery(this).attr("src").split(".gif").join("_on.gif")); 
        });
    });
    
    inputBtn.bind('mouseout', function(event){
        jQuery(this).attr('src', function(){
            jQuery(this).attr("src", jQuery(this).attr("src").split("_on.gif").join(".gif"));
        });
    });
        
    
});

/*************************************************************************************
FAQ Tabs
*************************************************************************************/

jQuery(document).ready(function() {
    var tabContainers = jQuery('div.faqTabs > div');
    
    //on Click of tabs, add and remove class of active to show active tab clicked and deactivate 
    //tabs that were not clicked
    jQuery('div.faqTabs ul.tabs a').click(function () {
        tabContainers.hide().filter(this.hash).show();
        
        jQuery('div.faqTabs ul.tabs a').removeClass('active');
        jQuery(this).addClass('active');
        
        return false;
    }).filter(':first').click();

    jQuery('div#eGiftCardsTab').show();
});



//ALL CODE BELOW IS FROM THE CURRENT PIZZA HUT SITE


/*********************************************************************************************
	limitText - limits amount of text in textbox
*********************************************************************************************/

function limitText(limitField, limitNum) 
{
	if (limitField.value.length > limitNum) 
	{
		limitField.value = limitField.value.substring(0, limitNum);
	} 
}

function limitWords(limitField, limitNum)
{
	var delimeter = " ";
	
	var arr = limitField.value.split(delimeter);
	if(arr.length > limitNum)
	{
		var lastWord = arr[limitNum];
		var idx = limitField.value.lastIndexOf(lastWord);
		limitField.value = limitField.value.substring(0, idx);
	}
}

/*********************************************************************************************
	toggleEmailDiv
*********************************************************************************************/

function toggleEmailDiv(divid) 
{
	var nextButton = "btnNext";
	
	if (document.getElementById(divid).style.display == "none")
	{
		// Show Layer
		document.getElementById(divid).style.display="block";
		// Hide Next Button
		document.getElementById(nextButton).style.display="none";
	}
	else
	{
		// Hide Layer
		document.getElementById(divid).style.display="none";
		// Show Next Button
		document.getElementById(nextButton).style.display="block";
	}
}

/*********************************************************************************************
	popUpImage
*********************************************************************************************/
var newwindow;

function popUpImage(url, title, w, h) 
{
	if (w == null)
	{
		w = 400;
	}
	if (h == null)
	{
		h = 400;
	}
	if (title == null)
	{
		title = "";
	}
	if (newwindow && !newwindow.closed)
	{ 
		newwindow.focus(); 
		newwindow.document.clear() 
	}
	else
	{ 
		newwindow=window.open('','','width=' + w + ',height=' + h + ',resizable=1,resizable=no') 
	}
	
	newwindow.document.writeln('<head> <title>' + title + '<\/title><style>body{margin:0;}</style> <\/head> <body bgcolor=\"white\"> <center>');
	newwindow.document.writeln('<img src=' + url + ' title=\"' + title + '\" alt=\"' + title + '\" >');
	newwindow.document.writeln('<\/center> <\/body> <\/html>');
	newwindow.document.close();
}

/*********************************************************************************************
	gowindow - Used by Inherited Interactive International Map
*********************************************************************************************/

function gowindow(newURL,winname,wd,ht,rsz,scr) {
	newURL = root + "/International/" + newURL;
	
	if (navigator.appName == "Netscape") {
		sswindow = window.open(newURL,winname,"menubar=no,height="+ht+",width="+wd+",toolbar=no,location=no,resizable="+rsz+",scrollbars="+scr+",status=yes")
		sswindow.location.href=newURL;
                sswindow.focus();
	} else {
		sswindow = window.open(newURL,winname,"height="+(ht-30)+",width="+wd+",resizable="+rsz+",scrollbars="+scr)
		sswindow.location.href=newURL;
                sswindow.focus();
	}
}

/*********************************************************************************************
	Cookies - Pulls cookie information for Favorites
*********************************************************************************************/

function getFavorites() 
{	
  var vCookie = unescape(readCookie('QOsorders'));
  var y = 1
  var vCookieArray = new Array;
  var curData = new Array;
  //filter out first two items
  vCookie = (vCookie.substring(vCookie.indexOf('~')+1, vCookie.length));
  vCookie = (vCookie.substring(vCookie.indexOf('~')+1, vCookie.length));
  vCookie = vCookie.replace(/\+/g, " ");
  vCookieArray = vCookie.split("~");
  
  //no cookies so return null so the flash will show America's Favorites
  if(vCookieArray.length <= 1) return false;
  
  //loop through each order
  for(var x = 0; x < vCookieArray.length; x++)
  {
    var vExternalTitle;
    var vExternalDetail;
    switch(y)
    {
      case 1: //Index or Code
        vExternalIndex =  vCookieArray[x];
        y++;
        break
      case 2: //order name
        vExternalTitle =  vCookieArray[x];
        y++;
        break
      case 3: //delivery type
        y++;
        break
      case 4: //order detail
        vExternalDetail = getOrderDetail(vCookieArray[x]);
        var curObj = new Object();
        curObj.title = vExternalTitle;
		curObj.detail = vExternalDetail;
		curObj.href = "http://quikorder.pizzahut.com/phorders2/login.php?templateIndex=" + vExternalIndex; //production
		//curObj.href = "http://qotest.pizzahut.com/pizzahutnew/login.php?templateIndex=" + vExternalIndex; //development
		curObj.target = "_self";
        curData.push(curObj);
        y=1;
        break
    }
  }
   return curData;    	
}

function getOrderDetail(vDetail)
{
  var vOrderDetailArray = new Array;
  var getOrderDetail = "";
  var n = false;
  vDetail = (vDetail.substring(vDetail.indexOf('---')+3, vDetail.length));
  vOrderDetailArray = vDetail.split("---");
        
  for(var z = 0; z < vOrderDetailArray.length; z++)
  {
    if(n == true)
    {
      getOrderDetail = getOrderDetail + " " + vOrderDetailArray[z] + "<br>";
      n = false;
    }
    else
    { 
      getOrderDetail = getOrderDetail + vOrderDetailArray[z];
      n = true;
    }
  }
  return getOrderDetail;
}

function readCookie(name) 
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  
  for(var i=0;i < ca.length;i++) 
  {
  	var c = ca[i];
  	while (c.charAt(0)==' ') c = c.substring(1,c.length);
  	if (c.indexOf(nameEQ) == 0)
  	if (c.indexOf(nameEQ) == 0) 
  	return c.substring(nameEQ.length,c.length);
   }
  return null;
}

function findMovie(movieName) 
{
    if (navigator.appName.indexOf("Microsoft") != -1) 
    {
        return window[movieName]
    }
    else 
    {
        return document[movieName]
    }
} 


/**********BDA Popup************/
function bdaPopup(){
    window.open('http://quikorder.pizzahut.com/phorders2/bda/bdainstall.html','bdainstall','width=240, height=180, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=0'); 
}

/*******Go to Country Locator******/
function switchLanguage() {
    urls=new Array();
    oh=new Array();tsd=new Array();
    tsh='quikorderespanol.pizzahut.com';
    oh[0]='quikorder.pizzahut.com';tsd[0]='/enes/sdquikorder/';
    oh[1]='qotest.quikorder.com';tsd[1]='/enes/sdqotest/sdquikorder/';
    urls[0]=new URLData(tsh, oh, tsd);

    oh=new Array();tsd=new Array();
    tsh='espanol.pizzahut.com';
    oh[0]='www.wingstreet.com';tsd[0]='/enes/dwingstreet/';
    oh[1]='pizzahutcard.pizzahut.com';tsd[1]='/enes/sdpizzahutcard/';
    oh[2]='coupons.eurorscgretail.com';tsd[2]='/enes/sdcoupons/deurorscgretail/';
    oh[3]='a248.e.akamai.net';tsd[3]='/enes/sda248/dakamai/';
    oh[4]='<%=PHLink%>';tsd[4]='<%=PHSpanishLink %>';
    urls[1]=new URLData(tsh, oh, tsd);

    var found=false;
    for (i=0;i<urls.length;i++)
    { 
        idx=location.href.indexOf(urls[i].tsh);
        if(idx==-1)
        {
            for (j=0;j<urls[i].oh.length;j++)
            { 
                idx=location.href.indexOf(urls[i].oh[j]);
                if(idx>-1)
                {
                    idx=idx+urls[i].oh[j].length;hname=urls[i].tsh+urls[i].tsd[j];
                    found=true;
                    break;
                }
            }
        }
        else
        {
            for (j=0;j<urls[i].tsd.length;j++)
            { 
                idx=location.href.indexOf(urls[i].tsd[j]);
                if(idx>-1)
                {
                    idx=idx+urls[i].tsd[j].length;hname=urls[i].oh[j];
                    found=true;
                    break;
                }
            }
        }
        if (found) break;
    }

    path=location.href.substring(idx);
    hend=hname.charAt(hname.length-1); pstart=path.charAt(0);
    if(hend=='/' && pstart=='/') path=path.substring(path.indexOf('/')+1);
    if(hend!='/' && pstart!='/') path='/'+path;
    location.href=location.protocol+'//'+hname+path;
    return false;
}

function URLData(tsh, oh, tsd) {
    this.tsh = tsh;
    this.oh = oh;
    this.tsd = tsd;
}	

////////////////////
function goToCountry(elem)
{
    var selectedIndex = elem.selectedIndex;
    var URL = elem.options[selectedIndex].value;
    window.location = "http://" + URL;
}


/*********************************************************************************************
	Access Query String Parameters - Usage : if(queryString('animation')=='start')
*********************************************************************************************/

function PageQuery(pageQuery) {
    if(pageQuery.length > 1) this.pageQuery = pageQuery.substring(1, pageQuery.length);
    else this.pageQuery = null;
    this.keyValuePairs = new Array();
    if(pageQuery) 
    {
        for(var i=0; i < this.pageQuery.split("&").length; i++) {
            this.keyValuePairs[i] = this.pageQuery.split("&")[i];
        }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) {
        for(var j=0; j < this.keyValuePairs.length; j++) {
            if(this.keyValuePairs[j].split("=")[0] == s)
                return this.keyValuePairs[j].split("=")[1];
        }
    return false;
    }
    this.getParameters = function() {
        var a = new Array(this.getLength());
        for(var j=0; j < this.keyValuePairs.length; j++) {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; }
}

function queryString(key){
    var page = new PageQuery(window.location.search);
    return unescape(page.getValue(key));
}


/*************************************************************************
Add Deal Info 
*************************************************************************/
function ShowDealInfo(dealInfo, itemType, itemCode, tracking) {
    //Get Coupon Code        
    var hiddenCouponCode = $get("hiddenCouponCode");
    var hiddenCouponCode_text = "";
	// supress error if hiddenCouponCode is null
	if(hiddenCouponCode != null)
	{
	    //if(hiddenCouponCode.firstChild != null)
		hiddenCouponCode_text = hiddenCouponCode.firstChild.data;
	}
    
    var itemCodePass = itemCode.split("|"); // Added to check for banner variable set for banner page only
                                            // Banner page is itemCodePass[1]
    
    //If it is the deals wildcard, redirect to deals page
    if(itemCodePass[0] == "moreDeals")
    {
        
        addItemToCart('', '', '', 'moreDeals', tracking);
    }
    else //if it is a cpn, redirect to proper coupon page
    {
        addItemToCart(itemType, itemCodePass[0], 'deals', 'deals', tracking);
    }
     
     
    if (IsCookied == 'Y') {
        window.location = getQuickOrderRedirectURL();
    }
    else {
    
        if (dealInfo != null) {
            
            CreateOverlay();
            Center(jQuery('#loginLightboxWrapper'));
            jQuery('#modalBackground').fadeIn(100, function() { jQuery('#loginLightboxWrapper').show(); });
            
            var dealTitle = dealInfo.split("|");

//            dealTitle = dealTitle.replace(/<br>/g, ' ');
//            dealTitle = dealTitle.replace('||', ' ');
//            dealTitle = dealTitle.replace('|', '<br/>');
//            dealTitle = dealTitle.replace('.|', '. ');
            if(dealTitle[1] != undefined)
            {
                //This is for the deals coming from the MM/QO webservice
                jQuery('#itemTitle').html(dealTitle[0] + '<br/>' + dealTitle[1] +  '<br/> ' + dealTitle[2] + ' ' + dealTitle[3]);
                jQuery('#addToOrderText').html("");
            }
            else if(dealTitle[0] == "")
            {
                //This is for the deals wildcards
                jQuery('#itemTitle').html("");
                jQuery('#addToOrderText').html("");
            }
            else
            {
                //This is for the flash deals and deals not on the homepage
                jQuery('#itemTitle').html(dealTitle[0]);
                jQuery('#addToOrderText').html(" will be added to your order.");
            }
            
        }
    }

    jQuery(window).resize(Center(jQuery('#loginLightboxWrapper')));
    jQuery(window).scroll(Center(jQuery('#loginLightboxWrapper')));
}   


function addDealBanner(dealInfo, itemType, itemCode, tracking) {
    //Get Coupon Code    
    var hiddenCouponCode = $get("hiddenCouponCode");
    var hiddenCouponCode_text = "";
	// supress error if hiddenCouponCode is null
	
	if(hiddenCouponCode.firstChild != null)
	{
		hiddenCouponCode_text = hiddenCouponCode.firstChild.data;
	}
	addItemToCart(itemType, itemCode, 'deals', 'deals', tracking);
}  

/*****************************************************************************
DayPart
******************************************************************************/
var currentDay;
function getCurrentDateTime()
{
    var currentDate = new Date();
    currentDay = currentDate.getDay(); 
}
jQuery(document).ready(function(){
    getCurrentDateTime();
    if(currentDay == 2)
    {
        jQuery('#tuesdayDeal, #wednesdayCurrentDeal').show();
        jQuery('#wednesdayDeal, #tuesdayCurrentDeal').hide();
    }
    else if(currentDay == 3)
    {
        jQuery('#tuesdayDeal, #wednesdayCurrentDeal').hide();
        jQuery('#wednesdayDeal, #tuesdayCurrentDeal').show();
    }
    else
    {
        jQuery('#tuesdayDeal, #wednesdayDeal').hide();
        jQuery('#tuesdayCurrentDeal, #wednesdayCurrentDeal').show();
    }
});
