﻿/////////////////////////////////////////////////////////////////
//
//  Consumer.products.js JScript File
//  This file contains functions specific to products.aspx.
//
//---------------------------------------------------------------
//  (C) 2008 Copyright JVC Canada 
//--------------------------------------------------------------- 



// Handle clicks to product browser paging //
function PagingClick(iPage, Hier_ID)
{
    
    if (Hier_ID != null && Hier_ID != undefined)
    {
        document.getElementById("ctl00_txtLookFor").value = "";
        document.getElementById("ctl00_PH01_txtLookFor").value = "";
    }
    
    StyleStick("Op" + Hier_ID);
    
    //alert(Hier_ID + "\n\n" + Hier_ID.substring(0,2) +"\n\n" + (Hier_ID.substring(0,2)=="E1"));
    
    if (Hier_ID != undefined)
    {
        // Hide/Display ACCESSORY STORE menu
        if (Hier_ID.substring(0,2)=="E1")
        {
            $get("ctl00_PH01_PanelAccStore").style.display = "";
            $get("ctl00_PH01_PromoProd").style.display = "none";  // hide promo        
        }
        else
        {
            $get("ctl00_PH01_PanelAccStore").style.display = "none";
            $get("ctl00_PH01_PromoProd").style.display = "";  // show promo    
            
            var pix1 = $get('ctl00_PH01_Promo1Pix');
            var pix2 = $get('ctl00_PH01_Promo2Pix');
            
            if (Hier_ID.substring(0,2)=="A1") 
            {   // A U D I O 
                pix1.src="../Img/Promo/PromoAud01.jpg";
                pix2.src="../Img/Promo/PromoAud02.jpg";
            }
            if (Hier_ID.substring(0,2)=="B1") 
            {   // V I D E O  
                pix1.src="../Img/Promo/PromoVid01.jpg";
                pix2.src="../Img/Promo/PromoVid02.jpg";
            }
            if (Hier_ID.substring(0,2)=="C1") 
            {   // T E L E V I S I O N S
                pix1.src="../Img/Promo/PromoTV01.jpg";
                pix2.src="../Img/Promo/PromoTV02.jpg";
            }
            if (Hier_ID.substring(0,2)=="D1") 
            {   // M O B I L E   
                pix1.src="../Img/Promo/PromoMob01.jpg";
                pix2.src="../Img/Promo/PromoMob02.jpg";
            }            
 
        }
    }
    
    var args = iPage + (Hier_ID == undefined ? "" : "|" + Hier_ID);    
    //WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00_PH01_UpdatePanelResults",args,true,"","",false,true));
    __doPostBack("ctl00_PH01_UpdatePanelResults", args);  
    
}

var flyVisible = "";
var mnuOn;

function NavFlyMenu(objHovered, menuName)
{
    if (objHovered!=null || typeof(objHovered)!="undefined")
    {
        if (objHovered.tagName.toLowerCase()=="li")
        {
            FocusOff();
            if (objHovered.id.length==8)
                objFocus = objHovered;
        
            BubbleOn(menuName,objHovered.id, 0, 172, 0, objHovered,"NavMenuON","");    
        }
        else
        {
            FocusOff();
            
            if (objHovered.id.length==8)
                objFocus = objHovered;

            BubbleOn(menuName,objHovered.id, 25, -1, 0, objHovered,"url(../Img/Button/AccMHot.gif)","url(../Img/Button/AccM.gif)");    
        }
    }
    else
    {
        BubbleOn(menuName,objHovered.id, 36, 0, 0, null,null,null);
    }
}
function NavFlyMenuOff(objOff, menuName)
{
    //var isFocusOn = false;    
    //try    {
    //document.getElementById("ctl00_PH01_lblAccStoreTitle").innerHTML="objOff: " + objOff.id + "  -  objStick: " + objStick.id;}catch(e){}

    //if (objOff != null)
    //{
        // Restore className //
        //if (objStick!=undefined && objStick!=null)
        //{ 
            //alert(objOff.id + "\n" + objStick.id);
            //if (objOff.id==objStick.id 
            //    || objOff.id.indexOf(objStick.id)>=0 
            //    || objStick.id.indexOf(objOff.id)>=0
            //    ) 
            //    isFocusOn = true
            //if (objOff.id.length > objStick.id.length)
            //    if (objOff.id.indexOf(objStick.id)>=0) isFocusOn = true;
            //else
            //    if (objStick.id.indexOf(objOff.id)>=0) isFocusOn = true;
        //}

        // do not turn off focus for menu header
        //if (objOff.id.length == 8) isFocusOn = true;

        //if (!isFocusOn)
        //{   // turn off focus
        //    if (objOff.tagName.toLowerCase()=="li")
        //        objOff.className = "";
        //    else
        //        objOff.style.backgroundImage = 'url(../Img/Button/AccM.gif)';
        //}    
        
    //}  // if (objOff != null)
    
    BubbleOff(menuName, false)
}

function Recalc()
{
	var inp = document.getElementsByTagName("INPUT");
	var qty = inp[0];
	var items = "";
	try
	{
	    for (var i=0;i<inp.length;i++)
	    {
		    var e=inp[i];
		    if ((e.id.indexOf("Cart")==0) && (e.type=='text'))
		    {
                items += "&" + e.id.substring(4) + "=" + e.value;        
		    }
	    }
	    $get("ctl00_PH01_txtCV").value = items.substring(1);
	}
	catch(e){}
	WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$PH01$cmdRecalc","",true,"","",false,true));
}

// Handle clicks to product results //
function ProdDetail(model,evt)
{   
    var isPop = false;
    
    if (!evt) var evt = window.event;

    var elem = ((evt.target) ? evt.target : evt.srcElement);
    
    switch(elem.tagName)
    {
        case "INPUT":
            break;
        case "SPAN":
            var chk = MM_findObj("chkModel" + model);
            if (chk!=undefined) chk.checked = !(chk.checked);
            break;
        case "IMG":
            if (elem.className=="addToCart") // && (isIE() ? (56 - evt.offsetX < evt.offsetY) : true) 
            {   // Add to cart //
                __doPostBack("ctl00_PH01_UpdatePanelCart","add:" + model);
            }
            else {isPop = true};      
            break;            
        default:
            isPop = true;
            break;
    }
    
    if (isPop) MPEOpen("overview.aspx?m=" + model, 782, 500,"auto", model )

}

// Remove from Cart
function RemoveFromCart(model)
{
    $get("Cart"+ model).value = 0;
    Recalc();
}

//////////////////////////////////////////////////////
///
///  A J A X   I N    P R O G R E S S    E F F E C T 
///  

// Update message on the progress bar //
//MM_findObj("ProgressMessage").innerHTML = lblWait;

//var ctlupdatepanel = "ctl00_PH01_UpdatePanelLegend";
//var ctlprogresspanel = "ctl00_PH01_UpdateProgressLegend";

Sys.Application.add_init(Init);
var intervalID = null;

var ctlprg = null;
var ctlupd = null;

function Init(sender)
{
  var prm = Sys.WebForms.PageRequestManager.getInstance();
  if (prm)
  {
      if (!prm.get_isInAsyncPostBack())
      {
            prm.add_beginRequest(BeginRequest);
            prm.add_endRequest(EndRequest);
      }
  }
}

var elemReq;
 
function BeginRequest(sender,args)
{
   
    switch(args.get_postBackElement().id)
    {
    case "ctl00_PH01_UpdatePanelResults":
      ctlupd=$get("ctl00_PH01_UpdatePanelResults"); 
      ctlprg=$get("ctl00_PH01_UpdateProgressResults");
      break;    
    default:
      ctlupd=$get("ctl00_PH01_UpdatePanelCart"); 
      ctlprg=$get("ctl00_PH01_UpdateProgressCart");      
      ctlprg.style.display = "block";  
      break;
    }        
    
    if (ctlprg!=null)
    {
        ctlprg.className = "ProgressPanel";
        ctlprg.style.width = "220px";

        ctlupd.className = "UpdatePanelAlpha";

        // get the bounds of both: the updatepanel and the progresspanel
        var UpdBounds = Sys.UI.DomElement.getBounds(ctlupd);
        var PrgBounds = Sys.UI.DomElement.getBounds(ctlprg);
        
        //	do the math to figure out where to position the element (the center of the updatepanel)
        var x = UpdBounds.x + Math.round(UpdBounds.width / 2) - 75; //Math.round(PrgBounds.width / 2);
        var y = UpdBounds.y + Math.round(UpdBounds.height / 2) - 50; //Math.round(PrgBounds.height / 2);

        //	set the progress panel to this position
        Sys.UI.DomElement.setLocation (ctlprg, x, y);        
    }   
}

function EndRequest(sender,args)
{
    if (ctlupd!=null) ctlupd.className = "UpdatePanelNormal";
    if (ctlprg!=null) ctlprg.style.display = "none";        
}

if(typeof(Sys) != "undefined") Sys.Application.notifyScriptLoaded(); 


