
    // *******************************************************
    // * Vader Show Offer Result Control
    // *******************************************************

    // -- Compare Boxes Functions
    function UncheckCompareCells(name)
    {
         var capCell = document.getElementsByName(name);
         for (var index = 0; index < capCell.length; index++)
         {
            if (navigator.appName == 'Microsoft Internet Explorer')
                capCell[index].children[0].firstChild.checked=false;
            else
                capCell[index].childNodes[3].checked=false;
         }
    }

    // Determine with Boxes are selected in a category
    function Compare(category)
    {        
        var compare = new String('Compare;');
        var counter = 0;
        var name = new String(category + 'CompareAndProdIdCell');
       
        // Get Sub Items Products
        var capCell = document.getElementsByName(name);
        for (var index = 0;index < capCell.length;index++)
        {
            if (capCell[index].childNodes.length > 0)
            {
                var str = new String();
                // Preferred Product 
                if (navigator.appName == 'Microsoft Internet Explorer')
                {
                    str = capCell[index].childNodes[0].id;
                    if (str.search(/productValue/) != -1)
                    {
                        counter++;
                        compare += capCell[index].childNodes[0].attributes['value'].value + ',' + index + '|';
                    }
                    else
                    {
                        if (capCell[index].childNodes[0].firstChild.checked)
                        {
                            counter++;
                            compare += capCell[index].childNodes[2].attributes['value'].value + ',' + index + '|';
                        }
                    }
                }
                else
                {
                    str = capCell[index].childNodes[1].id;
                    if (str.search(/productValue/) != -1)
                    {
                        counter++;
                        compare += capCell[index].childNodes[1].attributes['value'].value + ',' + index + '|';
                    }
                    else
                    {
                        if (capCell[index].childNodes[1].firstChild.checked)
                        {
                            counter++;
                            compare += capCell[index].childNodes[3].attributes['value'].value + ',' + index + '|';
                        }
                    }
                }
            }
        }
        
        compare += category;
        // Make sure right amount of item are selected
        if ((counter<2) || (counter>4))
        {
            alert('Please select between 2 and 4 products for comparison');
            return false;
        }
        // Make a call to the server
        CallServer(compare, 'prodComparison');
    }
    
    // select top four items in category
    function SelectAll(ctrl, category)
    {
        try
        {
            var name = new String(category + 'CompareAndProdIdCell');
            // make sure all item are unselected
            UncheckCompareCells(name);
            
            var checkAll = ctrl.checked;
            if (checkAll == true)
            {
                var capCell = document.getElementsByName(name); 
                for (var index = 0;index < capCell.length;index++)
                {
                    if (index == 4)
                        break;
                    if (navigator.appName == 'Microsoft Internet Explorer')
                        capCell[index].children[0].firstChild.checked=true;
                    else
                        compare += capCell[index].childNodes[2].attributes['value'].value + ',' + index + '|';
                }
            }
        }
        catch (exception){}
    }
    // ****************************************************************


    // ****************************************************************
    // * Server Call Back Procedure
    // ****************************************************************
    function ReceiveServerData(rValue, context)
    {
        switch (context)
        {
            case 'addToCart':
                AddItemToCart(rValue);
                break;
            case 'prodComparison':
                showDetailURL(rValue);
                break;
        }
    }
    
    // ****************************************************************
    // * Show PopUp Windows
    // ****************************************************************
    function showDetailURL(url)
  	{
  	    var win = new Window({className: "dialog", title: "", 
                      top:70, left:100, width:600, height:500, 
                      url: url, showEffectOptions: {duration:0.5}})
        win.showCenter();     
  	}
  	function showPopUp(url)
  	{
  	    var win = new Window({className: "dialog", title: "", 
                      top:70, left:100, width:425, height:315, 
                      url: url, zIndex:10000, showEffectOptions: {duration:0.5}})
        win.setDestroyOnClose();                       
        win.showCenter();     
  	}
  	// ****************************************************************
    // * Expand and Hide Category Offers Result
    // ****************************************************************
  	function showCategorySubTable(subCategory)
  	{
        var table = document.getElementById(subCategory);
        if (table != null)
        {
            var LabelValue = new String();
            var LabelID = new String(subCategory).replace('Subtable','ShowHide');
            var Label = document.getElementById(LabelID);
            var ImageID = new String(subCategory).replace('Subtable','ShowHideImage');
            var Image = document.getElementById(ImageID);
            
            if (table.style.display == 'block')
            {
                table.style.display='none';
                if (Label != null)
                {
                    LabelValue = Label.innerHTML;
                    LabelValue = LabelValue.replace('Hide', 'Show');                    
                    Label.innerHTML = LabelValue;
                }
                if (Image != null)
                    Image.src = 'images/arrowoff.gif'
            }
            else
            {
                table.style.display='block';
                if (Label != null)
                {
                    LabelValue = Label.innerHTML;
                    LabelValue = LabelValue.replace('Show', 'Hide');                    
                    Label.innerHTML = LabelValue;
                }
                if (Image != null)
                    Image.src = 'images/arrowon.gif'
            }
        }
  	}
  	
  	function EnableAnchors(anchors)
  	{
  	 
  	    for (var index=0;index<anchors.length;index++)
  	    {
              	            
            var dataContainer = GetSubTableContainer(anchors[index])
  	                                     
            //if data content then show.
                    
            if (HasContent(dataContainer))
            {
                
                anchors[index].style.display='block';
                
                //if is Tripple play then expand
                                    
                if (GetTableFromElement(anchors[index]).id=='Triple_Play_Bundletable')
                    showCategorySubTable('Triple_Play_BundleSubtable');
                                                                                    
            }
          
  	    }
  	      	    
  	}
  	
  	function HasContent(dataContainer)
  	{
  	    
  	    if (dataContainer==null) return false;
  	    
  	    try
  	    {
  	        
  	        var rowIndex = 0;              	        
  	        var temp = new String(dataContainer.id);
  	        
  	        if (temp.indexOf('Double') >-1)
                rowIndex = 1;
  	        
  	        if (navigator.appName == 'Microsoft Internet Explorer')
            {
                   
                if (dataContainer.childNodes[0].childNodes[0].rows[rowIndex].cells[0].childNodes[0].tagName=='TABLE')
  	                return true;
  	              else
  	                return false;
                  	                
            } 
            else
            {
                    
                if (dataContainer.childNodes[1].childNodes[1].rows[rowIndex].cells[0].childNodes[1].tagName=='TABLE')
  	                return true;
  	              else
  	                return false;
                      	                
            }
            
  	    }
  	    catch (exception){return false;}   
  	}
  	
  	function GetSubTableContainer(element)
  	{
  	    
  	    var eventHandler = new String(element.onclick);
  	    var temp = new String('showCategorySubTable(');
  	    var start = eventHandler.indexOf(temp,0);
  	    eventHandler = eventHandler.substring(start + temp.length + 1 ,eventHandler.length-2);
  	    var containerName = eventHandler.replace('\n','');
  	    containerName = containerName.replace(')','');
  	    containerName = containerName.replace(';','');
  	    containerName = containerName.replace('"','');
  	    containerName = containerName.replace("'",'');
  	      
  	    return document.getElementById(containerName);
  	    
  	}
  	
  	function GetTableFromElement(element)
  	{
  	    
  	    while (element.tagName != 'TABLE')
  	    {element = element.parentNode;}
  	    
  	    return element;
  	    
  	}
  	
  	// ****************************************************************
    // * Expand and Hide Category Offers Result
    // ****************************************************************
    function showHiddenCategory(expandOffers, categoryGroup)
    {
        var chkBox = document.getElementById(expandOffers);
        chkBox.checked = true;
        showHideCategory(chkBox, categoryGroup);
    }
  	function showHideCategory(expandOffers, categoryGroup)
  	{   
  	    var cloneCheckString = new String(expandOffers.id);
  	    if (cloneCheckString.search(/OfferChooserHeaderBar/i) > -1 )
  	        cloneCheckString = cloneCheckString.replace('OfferChooserHeaderBar','OfferChooserListBar');
  	    else
  	        cloneCheckString = cloneCheckString.replace('OfferChooserListBar','OfferChooserHeaderBar');
        var cloneCheck = document.getElementById(cloneCheckString)
        if (cloneCheck != null)
            cloneCheck.checked = expandOffers.checked;
  	    
  	    var defaultGroup = null;
  	    var groups = document.getElementsByName(categoryGroup);
  	    if (groups.length > 0)
  	    {
  	        defaultGroup = groups[0];
  	        for (var index = 0;index < groups.length;index++)
            {
  	            if (expandOffers.checked == true)
  	                Expand(groups[index]);
  	            else
  	                Collapse(groups[index]);
  	        }
  	    }
  	    else
  	    {
  	        defaultGroup = categoryGroup;
  	        if (expandOffers.checked == true)
                Expand(defaultGroup);
            else
                Collapse(defaultGroup);
  	    }
  	    
  	    if (defaultGroup != null)
  	    {
  	        var viewOffer = new String(defaultGroup.id);
  	        viewOffer = viewOffer.replace('table','viewOffers');
  	        var offerViewDIV = document.getElementsByName(viewOffer);
      	    
  	        if (expandOffers.checked == true)
            {
                if (offerViewDIV != null && offerViewDIV.length > 0)
                    offerViewDIV[0].style.display='none';
            }
  	        else
  	        {
                if (offerViewDIV != null && offerViewDIV.length > 0)
                    offerViewDIV[0].style.display='block';
  	        }   
  	    }
  	}
  	
  	function Expand (group)
  	{
  	    group.style.display='block';
  	}
  	
  	function Collapse(group)
  	{
  	    group.style.display='none';
  	}
  	
  	// ****************************************************************
    // * Client Side Shopping Cart 
    // ****************************************************************
    function LoadCart(prodId)
    {
        CallServer(prodId, 'addToCart');
    }
    
    var masterPageId = 'ctl00_Main_';
    
    // Write Item in Cart 
    function AddItemToCart(rValue)
    {
        var delimitedDataRows = new String(rValue);
        var rows = delimitedDataRows.split('%');
        // Clear Current Rows
        ClearCart();
        for (var index = 0;index < rows.length-1;index++)
        {
            var data = rows[index].split(';');
            // Write Row in Shopping Cart
            UpdateCart(data[0], data[1], data[2]);
        }
                                                //offer1___shoppingcart1___lblCartTotal
        document.getElementById(masterPageId + 'offer1___shoppingcart1___lblCartTotal').innerHTML=rows[rows.length-1];
        try{document.getElementById(masterPageId + 'offer1_shoppingcart1___divCartIsEmpty').style.display='none';}catch(exception){}
        alert('Your cart has been updated.');
    }
    
    function RemoveItemFromCart(prodId)
    {
        if (prodId != null)
            CallServer('removeFromCart:' + prodId, 'addToCart');
    }
    // Update the cart
    function UpdateCart(name, price, key)
    {
        try
        {                
            var grid = document.getElementById(masterPageId + 'offer1_shoppingcart1___grdCart');
            if (grid != null)
            {
                var newRow = grid.insertRow(-1);
                
                var newCell = newRow.insertCell(0);
                newCell.className = 'style11'
                newCell.innerHTML=name;
                
                newCell = newRow.insertCell(1);
                var priceColumn = new String();
                priceColumn = price + '<br />'
                priceColumn += '<a href="javascript:void(0);" onclick="RemoveItemFromCart(\'' + key + '\');">'
                priceColumn += '<img src="images/vadcalc/remove.jpg" style="border:0" width="51" height="13" /></a>'
                
                newCell.innerHTML=priceColumn;
                
                // Add Sep Line
                newRow = grid.insertRow(-1);
                // Add a new Cell
                newCell = newRow.insertCell(0);
                newCell.colSpan = 2;
                var Spr = new String();
                Spr += '<table width="100%" border="0" style="text-align:center" cellpadding="2" cellspacing="2">'
                Spr += '<tr>'
                Spr += '<td align="center">'
                Spr += '<img src="images/vadcalc/sep_line.jpg" style="border:0" width="151px" height="5px" />'
                Spr += '</tr>'
                Spr += '</table>'
                newCell.innerHTML=Spr;
            }
        }
        catch(exception){}
    }
    // Clear all items in the cart
    function ClearCart()
    {
        try
        {
            var grid = document.getElementById(masterPageId + 'offer1_shoppingcart1___grdCart');
            if (grid != null)
            {
                while (grid.rows.length >= 0)
                {
                     grid.deleteRow(0);
                }
            }
        }
        catch(exception){}
    }
    
    // *******************************************************
    // * Vader Service Extended Search Control
    // *******************************************************
    function ActiveCheckBoxes(stateControl)
    {
        var ckTv = document.getElementById('extendedSearch1___ckTelevision');
        var ckPhone = document.getElementById('extendedSearch1___ckPhone');
        var ckHighSpeed = document.getElementById('extendedSearch1___ckHighSpeed');
        var otherControl = null;
       
        // reset individual check items
        ckTv.checked = false;
        ckPhone.checked = false;
        ckHighSpeed.checked = false;
            
        if (stateControl.id == 'extendedSearch1___showBundles')
        {
            otherControl = document.getElementById('extendedSearch1___showAllOffers');
        }
        else
        {
            otherControl = document.getElementById('extendedSearch1___showBundles');            
        }
        
         // unselected othe radio button
         if (otherControl != null)
            otherControl.checked = false;
    }
    function SearchSelectionCheckBoxes(stateControl)
    {
        var showAllControl = null;
        var showBundleControl = null;
             
        showAllControl = document.getElementById('extendedSearch1___showAllOffers');
        showBundleControl = document.getElementById('extendedSearch1___showBundles');
        
        // unselected othe radio button
        if (showAllControl != null)
            showAllControl.checked = false;
        if (showBundleControl != null)
            showBundleControl.checked = false;
            
    }
    
    function AddToCart(controlArray, buttonIndex)
    {
      
        var tableButtons = document.getElementsByName(controlArray);
        if (tableButtons.length > 0)
        { 
            var addToCartLink = tableButtons[buttonIndex];
            if (navigator.appName == 'Microsoft Internet Explorer')
            { 
                addToCartLink.children[0].click();
            }
            else
            { 
                var attr = new String(addToCartLink.attributes["onclick"].value);
                addToCartLink.focus();
                addToCartLink.onclick();
                
            }
            return true;
        }
        return false;
    } 
    
    // ****************************************************************
    // * Search Process
    // ****************************************************************
    function SubmitSearchProcess(rValue, context)
    {   
        switch (context)
        {
            case 'dispatch':
                if (rValue != null)
                {
                    // Status:Failure;Message:
                    var Result = new String(rValue);
                    var values = Result.split(';');
                    var status =  values[0].split(':')[1];
                    if (status == 'Failure')
                    {
                        var Message = new String(values[1].split(':')[1]);
                        if (Message.length > 0 )
                            alert(Message);
                    }
                    else
                    {
                        var url = new String(values[1].split(':')[1]);
                        postToParent(url)
                    }
                }
                break;
        }
    }
    
    function ParseDomainFromUrl(pUrl) {
        var lUrl = unescape(pUrl);
        var lPieces = lUrl.split('/');
        var lDomain = (lPieces.length >= 3) ? lPieces[2] : '';
        var lPortPos = lDomain.indexOf(':');
        if (lPortPos >= 0) lDomain = lDomain.substr(0, lPortPos);
        return lDomain;
    }
    
    function postToParent(parentURL)
    {
        var opener = null;
        if (window.opener == null)
            opener = this.parent;
        else
        {
            try 
            {
                var domain = ParseDomainFromUrl(this.opener.location.href);
                opener = ((domain.indexOf('verizon') >= 0) || (domain.indexOf('localhost') >= 0)) ? this.opener : this;
            } catch(err) {
                opener = this;
            }
        }            
        
        displaySplash();
       try{
            // change
            opener.location.replace(parentURL);  
        }
         catch(err) {}    
        
    }
    
    function displaySplash(){
        // show splash page
        var splashContent = new String('');
       
        // build content      
        splashContent = '<div id="splashDiv" style="display: block" align="center">'
        splashContent = splashContent + '<img src="images/logo-splash.gif" width="280" height="155" />'
        splashContent = splashContent + '<br />'
        splashContent = splashContent + '<br />'
        splashContent = splashContent + '<img src="images/searching.gif" width="220" height="60" />'
        splashContent = splashContent + '</div>'
        
        showSplash(splashContent);
    }
    
    // ****************************************************************
    // * Show PopUp Div
    // ****************************************************************
  	
  	function changeAddress(url)
  	{
  	    var win = new Window({className: "dialog", title: "New Search", 
                      top:70, left:100, width:460, height:238, 
                      url: url, showEffectOptions: {duration:0.5}})
        win.setDestroyOnClose();                      
        win.showCenter();     
  	}
  	function showSplash(content)
  	{
  	    showSplash(content, 'splashPage1');
  	}
  	function showSplash(content, id)
  	{
  	    var splashPage = document.getElementById(id);
  	    if (splashPage != null)
  	        id = id + '1';
  	    Dialog.info(content, {className: "alphacube",  width:350, id: id, showProgress: "true"}); 
  	    
  	}
  	
  	