
    // *******************************************************
    // * 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');
    }
    
    function MM_preloadImages() { //v3.0
        var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    
    // 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 b_version= new String(navigator.appVersion);
  	    var version= new String();
  	    
  	    if (b_version.search(/MSIE 7.0/) != -1)
  	        version = '7';
  	    else
  	        version = '6'; 
  	        
  	    // Create Window    
  	    var win = new Window({className: "dialog", title: "Dialog", 
                          top:70, left:100, width:600, height:500, 
                          url: url, showEffectOptions: {duration:0.2},
                          hideEffectOptions: {duration:0.2}})
        win.setDestroyOnClose();
        win.toFront();
        win.showCenter();   
        // Hack for IE 6 Content need to be refresh    
        if ((navigator.appName == 'Microsoft Internet Explorer') && (version == '6'))
  	    {  	        
  	        win.refresh();
  	    }
  	}
  	
  	// ****************************************************************
    // * Expand and Hide Category Offers Result
    // ****************************************************************
  	function showCategorySubTable(subCategory)
  	{
  	    //debugger;
        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 no data content then hide.       
            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);
        if (chkBox != null)
        {
            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');
    }
    // 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]);
        }
        document.getElementById('ctl00_Main_offer1_shoppingcart1___lblCartTotal').innerHTML=rows[rows.length-1];
        try{document.getElementById('ctl00_Main_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('ctl00_Main_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('ctl00_Main_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;
            
    }
    
    // ****************************************************************
    // * 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(window.opener.location.href);
                opener = (domain.indexOf('homes') >= 0) ? window.opener : this;
            } catch(err) {
                opener = this;
            }
        }
        
        //
//        Windows.closeAllModalWindows();
//        // show splash page
        var splashContent = new String('');
        // build content
        splashContent = '<div align="center">'
        splashContent = splashContent + '<img src="images/logo-tm.gif" width="150" height="65" />'
        splashContent = splashContent + '<br />'
        splashContent = splashContent + '<br />'
        splashContent = splashContent + '<img src="images/searching.gif" width="220" height="60" />'
        splashContent = splashContent + '</div>'
        //
        showSplash(splashContent)
        // change
        opener.location.replace(parentURL);     
        
    }
    
    function showSplash(content)
  	{
  	    Dialog.info(content, {className: "alphacube",  width:350, id: "splashPage1"})
  	}