﻿ie4 = (document.all) ? true : false;
itemname = "Item";
sl_count_cook = getCookie("ShoppingListCount")+"";
if ((sl_count_cook == "") || (sl_count_cook == "null")) {
    (sl_count_cook=0);
}
function getCookie(cook) {
    if (document.cookie.length>0) {
        begin = document.cookie.indexOf(cook+"=");
        if (begin != -1) {
            begin += cook.length+1;
            end = document.cookie.indexOf(";", begin);
            if (end == -1) {
                end = document.cookie.length;
            }
            return unescape(document.cookie.substring(begin, end));
        }
    }
    return null;
}
function setCookie(cook, value) {
    var ExpireDate = new Date(2030, 0, 1, 0, 0, 0, 00);
    document.cookie = cook+"="+value+";expires="+ExpireDate.toGMTString()+';path=/';
}
function shoppinglistadd(stid, lid, oid, cid) {
    //window.status = "stid::"+stid+"   lid::"+lid+"   oid::"+oid+"   cid::"+cid;
    sl_count_cook = getCookie("ShoppingListCount")+"";
    if ((sl_count_cook == "") || (sl_count_cook == "null")) {
        (sl_count_cook=0);
    }
    var sl_cook = (getCookie("ShoppingList")+"");
    var sl_n = "";
    var cook = document.cookie;
    if (cook.length>4000) {
        alert('Your shopping list is full. Please delete some items to add more.');
    } else {
        if (sl_cook == "null") {
            sl_cook = "";
        }
        if (oid == 0) {
            //add without a oid
            //see if it's in the cookie
            var sl_regex = lid+"(\\|[0-9]*)*,"+stid;
            add_regexp = new RegExp(sl_regex);
            if (add_regexp.test(sl_cook) != true) {
                //isn't already in cookie
                //add lid
                if (sl_cook != "") {
                    sl_cook += ","+lid;
                } else {
                    sl_cook += lid;
                }
                //add cid if applicable
                if (cid != 0) {
                    sl_cook += "|"+cid;
                }
                //add sid
                sl_cook += ","+stid;
                //increment count
                sl_count_cook++;
            }
        } else {
            //add with an oid
            //see if it's in the cookie
            var sl_regex = lid+"(\\|[0-9]*)*:"+oid+","+stid;
            add_regexp = new RegExp(sl_regex);
            if (add_regexp.test(sl_cook) != true) {
                //add lid
                if (sl_cook != "") {
                    sl_cook += ","+lid;
                } else {
                    sl_cook += lid;
                }
                //add cid if applicable
                if (cid != 0) {
                    sl_cook += "|"+cid;
                }
                //add sid
                sl_cook += ":"+oid+","+stid;
                //increment count
                sl_count_cook++;
            }
        }
        sl_cook = sl_cook.replace(",,", ",");
        setCookie("ShoppingListCount", sl_count_cook);
        setCookie("ShoppingList", sl_cook);
        SetFlashShoppingList(sl_cook, sl_count_cook);
        //window.status = sl_cook;
    }
}

 function shoppinglistremove(stid,lid,oid,cid) {                
    //window.status = "stid::"+stid+"   lid::"+lid+"   oid::"+oid+"   cid::"+cid;
        
        var sl_cook = getCookie("ShoppingList")+""; 
        var sl_count_cook = getCookie("ShoppingListCount")  
            
        //decrement the sl count 
        if (sl_count_cook==null) 
        { 
                sl_count=0; 
        } 
        else 
        { 
                sl_count_cook--; 
                setCookie("ShoppingListCount", sl_count_cook); 
        } 


        if ((oid==0) || (oid=="")) 
        { 
                //find the item 
                var sl_regex =  lid + "(\\|[0-9]*)*," + stid; 
                
        } 
        else 
        {    
                //find the item 
                var sl_regex =  lid  + "(\\|[0-9]*)*:" + oid  + "," + stid; 
        }     
        myregexp = new RegExp(sl_regex, "g"); 
            
        sl_cook = sl_cook.replace(myregexp,'');           
        sl_cook = sl_cook.replace(",,",","); 
            
        //set modified sl & count 
        setCookie("ShoppingList", sl_cook);  
        setCookie("ShoppingListCount", sl_count_cook);     
        SetFlashShoppingList(sl_cook, sl_count_cook);                 

    }  

function UpdateFlashShoppingList() {
        var sl_cook = getCookie("ShoppingList")+""; 
        var sl_count_cook = getCookie("ShoppingListCount")  
        SetFlashShoppingList(sl_cook, sl_count_cook);                 
}

function SetFlashShoppingList(val, val2) {
    var catalogObj = InternetExplorer ? catalog : document.catalog;
    catalogObj.SetVariable('shoppingList', val);
    catalogObj.SetVariable('shoppingListCount', val2);

    var emailAlert = getCookie("QuickHoundEmailAlerts");
    if (emailAlert == null) emailAlert = "none";
    catalogObj.SetVariable('quickhoundemailalerts', emailAlert);
}       
            var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
            // Handle all the the FSCommand messages in a Flash movie
            function catalog_DoFSCommand(command, args) {
            var catalogObj = InternetExplorer ? catalog : document.catalog;
            }

            // Hook for Internet Explorer 
            if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
                        navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
                        document.write('<SCRIPT LANGUAGE=VBScript\> \n');
                        document.write('on error resume next \n');
                        document.write('Sub catalog_FSCommand(ByVal command, ByVal args)\n');
                        document.write('  call catalog_DoFSCommand(command, args)\n');
                        document.write('end sub\n');
                        document.write('</SCRIPT\> \n');
            }

var d, dom, ie, ie4, ie5x, moz, mac, win, lin, old, ie5mac, ie5xwin, op;

d = document;
n = navigator;
na = n.appVersion;
nua = n.userAgent;
win = ( na.indexOf( 'Win' ) != -1 );
mac = ( na.indexOf( 'Mac' ) != -1 );
lin = ( na.indexOf( 'Linux' ) != -1 );

if ( !d.layers ){
    dom = ( d.getElementById );
    op = ( nua.indexOf( 'Opera' ) != -1 );
    konq = ( nua.indexOf( 'Konqueror' ) != -1 );
    saf = ( nua.indexOf( 'Safari' ) != -1 );
    moz = ( nua.indexOf( 'Gecko' ) != -1 );// will be true for safari as well
    ie = ( d.all && !op );
    ie4 = ( ie && !dom );

    /*
    ie5x tests only for functionality. ( dom||ie5x ) would be default settings. 
    Opera will register true in this test if set to identify as IE 5
    */

    ie5x = ( d.all && dom );
    ie5mac = ( mac && ie5x );
    ie5xwin = ( win && ie5x );
}

function catalog_DoFSCommand(command, args, pagenumber) {
    
    var catalogObj = InternetExplorer ? catalog : document.catalog;
  
    //LISTING
    if (command == "showdetail") {
        
        if(document.all && !mac)
            {
                
                //document.all.item("ifDetail").style.top = 154;
                
                pageResize();   
                ShowDetail();           
                document.all.item('ifDetail').src="/" + sVdirName + "/default.aspx?action=detailflash&listingid=" + args;
                document.all.item('ifDetail').style.visibility = "visible";
                window.top.name='opener';
            } 
            else
            {
                HideDetailInfo();
                var newWin = window.open("/" + sVdirName + "/default.aspx?action=detailflash&listingid=" + args,"moreinfo","width=500, height=350, location=no, menubar=no, status=no, toolbar=yes, scrollbars=yes, resizable=yes");
                window.top.name='opener';
            
                newWin.focus();
            }
            
        
        
        
    }
    if (command == "hidedetail") {

        if(document.all && !mac)
        {
            document.all.item("ifDetail").src = "blank.htm";
            document.all.item("ifDetail").style.visibility = "hidden";
        } 

    }
    
    //NLH
    if (command=="mapareadetail")
    {
            if(document.all && !mac)
            {
                
                //document.all.item("ifDetail").style.top = 154;
                
                pageResize();   
                ShowDetail();       
                document.all.item('ifDetail').src="/" + sVdirName + "/default.aspx?action=mapareadetailflash&mapareaid=" +  args + "&pagenumber=" + pagenumber
                document.all.item('ifDetail').style.visibility = "visible";
                window.top.name='opener';
            } 
            else
            {
                HideDetailInfo();
                var newWin = window.open("/" + sVdirName + "/default.aspx?action=mapareadetailflash&mapareaid=" + args + "&pagenumber=" + pagenumber,"moreinfo","width=500, height=350, location=no, menubar=no, status=no, toolbar=yes, scrollbars=yes, resizable=yes");
                window.top.name='opener';
            
                newWin.focus();
            }
    }
    

}
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
      navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
    document.write('<SCRIPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('Sub catalog_FSCommand(ByVal command, ByVal args)\n');
    document.write('  call catalog_DoFSCommand(command, args)\n');
    document.write('end sub\n');
    document.write('</SCRIPT\> \n');
}

function HideDetailInfo()
{
    var catalogObj = InternetExplorer ? catalog : document.catalog;
    if (!mac) catalogObj.SetVariable('movieState','hide');
}

function ShowDetail()
{
    var catalogObj = InternetExplorer ? catalog : document.catalog;
    if (!mac)
        catalogObj.SetVariable('movieState','show');
}

function pageResize()
{
    if (bolCenterIFRAME && document.all) {  
    
        if (parseInt(document.body.offsetWidth) > 770)
        {
            document.all.item("ifDetail").style.left = -8 + parseInt(document.body.offsetWidth)/2 - parseInt(document.all.item('ifDetail').style.width)/2;
            }
        else
        {
            document.all.item("ifDetail").style.left = 125;
        }
    }
}

window.onresize = pageResize;


// flash detection...no flash, redirect to HTML version 
var MM_PreviousVersion;
var MM_contentVersion = 6;
if (bolHybridMode)
{
    MM_contentVersion = 7;
}

var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
        var words = navigator.plugins["Shockwave Flash"].description.split(" ");
        for (var i = 0; i < words.length; ++i)
        {
        if (isNaN(parseInt(words[i])))
        continue;
        var MM_PluginVersion = words[i]; 
        }
    var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
    document.write('on error resume next \n');
    
    var ver = parseInt(MM_contentVersion);
    for(var i = 0; i < 3; i++){
        document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + (ver + i) + '" )))\n');
        document.write('MM_PreviousVersion = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion-1)))\n');         
    }
        
    document.write('</SCR' + 'IPT\> \n');
}

if (( !MM_FlashCanPlay ) ){

    if (FlashOnly==false) 
    {
        
        if ( (bolHybridMode) && ( (MM_contentVersion >=6) || (MM_PreviousVersion) ) )
        {
            //storing current URL in a cookie
            var date = new Date();
            date.setTime(date.getTime()+(1*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
            var currentURL = location.href;
            var MyCookie = "refUrl="+currentURL+"; "+expires+"; path=/";
            document.cookie = MyCookie;
            window.location.replace("default.aspx?action=installflash&reason=upgrade&htmllink=" + strHTMLPage + "&refUrl=" + escape(location.href));
        }
        else
        {   
            window.location.replace(strHTMLPage);
        }
    }
    else
    {
        window.location.replace("default.aspx?action=installflash");
    }
}
        

function DrawFlashCircularTags(id, url, width, height, flashvars, opaque)
{   
    // replace slhlogon with json version uid is a global js variable populated in PixelTracker.ascx
    try
    {        
        var qs = flashvars.split('&');
        var nvp;
        for(var i=0; i<qs.length; i++){
            nvp = qs[i].split('=');
            if(nvp[0].toLowerCase() == "slhlogon"){
                qs[i] = nvp[0] + "=" + uid;            
            }
            else{
                qs[i] = nvp[0] + "=" + nvp[1];
            }
        }
        flashvars = qs.join("&");        
    }
    catch(e){}  
       
    var opaqueAttribute = "";
    
    flashvars = flashvars + '%26firstname%3d' + cms_getQueryString("firstName", ""); 
    flashvars = flashvars + '%26lastname%3d' + cms_getQueryString("lastName", ""); 
    flashvars = flashvars + '%26giftlist%3d' + cms_getQueryString("giftlist", "");
    flashvars = flashvars + '%26listTitle%3d' + cms_getQueryString("listTitle", "");    
    
    document.write('<OBJECT style="border:0px solid Red" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="' + id + '" width="' + width + '" height="' + height + '" ALIGN="" VIEWASTEXT>');

    //it doesnt look like this attribute is being used consistently when it should - forcing opaque
    //if (opaque!=null && opaque.toUpperCase=="Y")
    //{
        document.write('<param name="wmode" value="opaque">');
        opaqueAttribute = 'wmode="opaque"';
    //}
    
    document.write('<param name="FlashVars" value="' + flashvars + '">');       
    document.write('<param name="movie" value="' + url + '" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="scale" value="exactfit" />');
    document.write('<param name="bgcolor" value="#ffffff" />');
    document.write('<EMBED onload="alert(45)" src="' + url + '" quality="high" scale="exactfit" bgcolor="#ffffff" width="' + width + '" height="' + height + '" swLiveConnect="true" ID="' + id + '" NAME="' + id + '" ALIGN="" ' + opaqueAttribute + ' FlashVars="' + flashvars + '" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
    document.write('</OBJECT>');    
    
    // go to pagenumber specified in the qs if the previous action is from the following below
    try{createJSFCommunicatorObject(thisMovie("catalog"));}catch(e){}     
            
    var page = cms_getQueryString("pagenumber", "-1");
    var ak_history = cms_getCookie("Prefs", "History", "");
    var ak_historyArr = ak_history.trim().split("|");       
    
    // back button functionality - going back to flash from the following actions	                
    if(page != "-1" && (ak_historyArr[0] == "detail" || ak_historyArr[0] == "browsecategoryl2" || ak_historyArr[0] == "detailbrowselarge")){     
        //GoToPage(page);
        GoToPage2(page);
    } 

    // deep link functionality
    if(page != "-1" && cms_getQueryString("flash", "N")=="y"){     
        //GoToPage(page);
        GoToPage2(page);
    } 
}

function ViewGiftList(giftListID)
{       
    var apiURL='http://grscat.target.com/giftReg/catserv/cat-service.jsp?catHost=SL&giftlist=' + giftListID + '&funct=edit&retnUrl=';
    var encodedURL =  escape(location.href);
    encodedURL = encodedURL.replace(/\//g,"%2f");             
    var sending = apiURL + encodedURL;
    window.location = sending;  
}

// ----------------------------------------------------------

function JSFCommunicator(flashMovie)
{	
	this.init(flashMovie);
}

JSFCommunicator.prototype.init = function(flashMovie) {

	if(flashMovie=="undefined") {
		var flashMovie = null;
	 }
	this.setMovie(flashMovie);
	this.functionToCall = null;
	this.functionLocationinFlash = null;
	this.functionArgs = null;
}

JSFCommunicator.prototype.setMovie = function(flashMovie)
{
	this.flashMovie = flashMovie;
}

JSFCommunicator.prototype.setVariable  = function(propName, propValue) {
	this.flashMovie.SetVariable(propName,propValue);
}

JSFCommunicator.prototype.getVariable  = function(propName) {

	var result = this.flashMovie.GetVariable(propName);
	return result;
}

JSFCommunicator.prototype.callFunction = function(fnLocation,fnName,fnArgs) {

	if(this.flashMovie==null) {	return false; }
	
	var flag = this.getVariable("/:triggerFn");
	var result = false;

	if(fnName=="") {return false; }
	if(fnLocation=="") {
		var fnLocation = "_level0";
	}

	this.setVariable("/:fnLocation",fnLocation);
	this.setVariable("/:fnName",fnName);	

	if(typeof(fnArgs)=="object") {
		this.setVariable("/:fnArgs",fnArgs.join("$@$$"));
	}else if(typeof(fnArgs)=="number" || typeof(fnArgs)=="string") {
		this.setVariable("/:fnArgs",fnArgs);
	}
	

	this.setVariable("/:triggerFn",!flag);
	result = this.getVariable("triggerFnStatus");	
	this.setVariable("/:triggerFnStatus",false);

	return result;	
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf ("Microsoft") !=-1) {
        return window[movieName]
    } else {
        return window.document[movieName]
    }
}

var jsf;
var flashActive = false;

function createJSFCommunicatorObject(playerObj){
    jsf = new JSFCommunicator(playerObj);
}

function flash_next(){
    jsf.callFunction("_root","TurnOnePage",[1]);
}

function flash_previous(){
    jsf.callFunction("_root","TurnOnePage",[-1]);    
}

var result = "-1";
function GoToPage(p){
     
    // poll the flash movie until it is ready            
    if(!flashActive){     
        try{            
            result = jsf.getVariable("cmHybridMenu.normalview_button.onRelease"); 
            flashActive = true;
        }catch(e){result = "error"}                         
	if(result == null || result == "error" || result == undefined){
        	try{
            		result = jsf.getVariable("_root.localized.cmHybridMenu2_mc.normalview_button.onRelease");
            		flashActive = true;
        	}catch(e){result = "error"}                 
        }
    }                
    if(result == null || result == "error" || result == undefined){
        setTimeout("GoToPage(" + p + ")",250);
	flashActive = false;
        return false;
    }
    
    // calculate page number                    
    if(p%2==0) p++;        
    var pageCount = -1;
    try{pageCount = jsf.getVariable("_root.pageCount");}catch(e){}
    if(p > pageCount) p = pageCount;
            
    // determine if flash is in single pagemode            
    var isSinglePageMode = false;
    try{isSinglePageMode = jsf.getVariable("_root.inSinglePageMode");}catch(e){}       
          
    // if flash is in single pagemode turn to spreadmode because this does not work in single pagemode
    if(isSinglePageMode == "true"){
        var result = "";
        try{
            result = jsf.getVariable("cmHybridMenu.normalview_button.onRelease");
            jsf.callFunction("cmHybridMenu.normalview_button", "onRelease");
        }catch(e){}
        
        if(result == ""){
            try{
                result = jsf.getVariable("_root.localized.cmHybridMenu2_mc.normalview_button.onRelease");
                jsf.callFunction("_root.localized.cmHybridMenu2_mc.normalview_button", "onRelease");        
            }
            catch(e){}        
        }
    }     

    //turn the page
    result = false;
    do{                    
    	jsf.setVariable("_root.currentPage", p);
    	result = jsf.callFunction("_root", "TurnPage", [0, true]);            
    }while(result != "true" && result != true)

}
    
// ----------------------------------------------------------

function GoToPage2(p){
    
	// poll the flash movie until it is ready            
    if(!flashActive)
	{     
		//alert("inside halfway");
        try
		{            
            result = jsf.getVariable("cmHybridMenu.normalview_button.onRelease"); 
            flashActive = true;
        }
		catch(e){result = "error"}
		
		if(result == null || result == "error" || result == undefined)
		{
        	try
			{
            		result = jsf.getVariable("_root.localized.cmHybridMenu2_mc.normalview_button.onRelease");
            		flashActive = true;
        	}
			catch(e){result = "error"}                 
        }
    }
	
	//alert("isNaN: " + isNaN(p));
	//alert("flashActive: " + flashActive);
	//alert("result: " + result);
    if(result == null || result == "error" || result == undefined)
	{
        setTimeout("GoToPage2(" + p + ")",250);
		flashActive = false;
        return false;
    }
	
	// calculate page number                    
    if(p%2==0) p++;        
    var pageCount = -1;
    try{pageCount = jsf.getVariable("_root.pageCount");}catch(e){}
	
    if(p > pageCount){p=pageCount;}
	
	//alert("outside halfway");
    // determine if flash is in single pagemode            
    var isSinglePageMode = false;
    try{isSinglePageMode = jsf.getVariable("_root.inSinglePageMode");}catch(e){}       
          
    // if flash is in single pagemode turn to spreadmode because this does not work in single pagemode
    /*	
	if(isSinglePageMode == true)
	{
		var result = "";		
		try
		{
            result = jsf.getVariable("cmHybridMenu.normalview_button.onRelease");
            jsf.callFunction("cmHybridMenu.normalview_button", "onRelease");
        }
		catch(e){}
        
        if(result == "")
		{
            try
			{
                result = jsf.getVariable("_root.localized.cmHybridMenu2_mc.normalview_button.onRelease");
                jsf.callFunction("_root.localized.cmHybridMenu2_mc.normalview_button", "onRelease");        
            }
            catch(e){}        
        }
    }     
	*/
	
    //turn the page
    result = false;
    do{                    
    	jsf.setVariable("_root.currentPage", p);
    	result = jsf.callFunction("_root", "TurnPage", [0, true]);            
    }while(result != "true" && result != true)

}
    
// ----------------------------------------------------------
