
    /**
     * Update the "Current Qty" of a package group and also the total price of package
     */
    function refreshPkgContentsBox(pkgID)
	{
         var elem = document.forms[0].elements; //Lawrence 9/11/2007: removed the ".all" as it is invalid in FireFox and is just plain unneccessary
         var intTotalQty = 0 ;
         var dblTotalPrice = 0.00 ;

         //---------------------------
         var pkgContentsPics = new Array()
         var tempImgPath;
         var pkgGroupHeadings = new Array()
         var tempGroupIndex = 0;
         //---------------------------
         var z=0;
         var tempGroup;
         var tempDisplayTypeId;
         
         
         for(var i=0; i < elem.length; i++)
         {
            //this if-statement only chooses that particular group
            //Lawrence (9/11/2007) commented it out b/c I want ALL groups
            //if( Left(elem[i].id , intIndex-1 ) == strTmp )
            {
                if ((elem[i].id.indexOf('hiddenGroupHeading')) != -1)
                {
                    
                    if ((elem[i].id.indexOf(pkgID)) != -1)
                    {
                        pkgGroupHeadings[tempGroupIndex] = elem[i].value.split("|"); //0=heading,1=min,2=max,3=pkgID
                    
                        tempGroupIndex++;
                    }
                }
                
                if ((elem[i].id.indexOf('DDR_Item_Number')) != -1)
                {
                    if ((elem[i].id.indexOf(pkgID)) != -1)
                    {
                        //Lawrence 9/11/2007: Only update intTotalQty if the element is part of the current pkg group
                        intTotalQty = parseInt(intTotalQty) + parseInt(elem[i].value);
                        
                        //---------------------------
                        tempGroup = elem[i].id.toString();
                        tempGroup = tempGroup.substring(0, tempGroup.indexOf('_PackageCustomizeItemDetails1_DDR_Item_Number')-1)
                    
                        if ((pkgContentsPics[tempGroup] == null) || (pkgContentsPics[tempGroup] == undefined)) {
                            pkgContentsPics[tempGroup] = new Array();
                        }
                        //alert(elem[i].value);
                        var tempArray = elem[i].value.split("|");
//                        tempImgPath = getThumbImg(elem[i].value.substring(elem[i].value.indexOf("|") + 1, elem[i].value.lastIndexOf("|")));
//                        tempDisplayTypeId = elem[i].value.substring(elem[i].value.lastIndexOf("|") + 1, elem[i].value.length);
                        tempImgPath = getThumbImg(tempArray[1]);
                        tempDisplayTypeId = tempArray[2];
                        tempPrice = tempArray[3];
                        tempSku = tempArray[4];
                        pkgContentsPics[tempGroup][z] = new Array(3);
                        pkgContentsPics[tempGroup][z][0] = parseInt(elem[i].value); //pic qty
                        pkgContentsPics[tempGroup][z][1] = tempImgPath; //pic path
                        pkgContentsPics[tempGroup][z][2] = tempDisplayTypeId;//display type id
                        pkgContentsPics[tempGroup][z][3] = tempPrice;//price
                        pkgContentsPics[tempGroup][z][4] = tempSku;//SKU
                    
                        z++;
                        //---------------------------
                    }
                }
            }
            
            // add up all items to reach package total of entire package
            if ((elem[i].id.indexOf('DDR_Item_Number')) != -1)
            {
                if ((elem[i].id.indexOf(pkgID)) != -1)
                {
                    var intIndex1 =  elem[i].id.indexOf('DDR_Item_Number');
                    var strTemp1 = Left(elem[i].id,intIndex1);
                    strPrice = document.getElementById(strTemp1 + 'LBL_Package_Price').innerHTML  ;   
                    dblTotalPrice = dblTotalPrice + (parseFloat(Right(strPrice,(strPrice.length - 1 ))) * parseInt(elem[i].value))
                }
            }
        }
       //alert(print_r(pkgGroupHeadings));
        //---------------------------
        var html = ''
        var j=0;
        var tempQty;
        var tempUrl;
        var tempDisplay;
        var tempCss;
        var pkgGroups = pkgContentsPics;
        var groupItems;
        var itemSettings;
        var tempCol;
        var tempGroupHeading;
        var tempMin;
        var tempMax;
        var tempItemTotal;
        var tempSelectionIsGood;
        var tempNumItemsSelected;
        var tempHtmlBoxes;
        j = 0;
        tempGroupIndex = 0; //reused from above
        displayPKG = 0;
        html += '<table class="pkg_contents_table" border="0" cellpadding="0" cellspacing="0">';
        for (id in pkgGroups) {//loop through package groups

            tempGroupHeading = pkgGroupHeadings[tempGroupIndex][0];
            tempMin = pkgGroupHeadings[tempGroupIndex][1];
            tempMax = pkgGroupHeadings[tempGroupIndex][2];
            tempGroupIndex++;
            
            groupItems = pkgGroups[id];
            
            //html += '<tr><td colspan="2" class="pkg_contents_group_heading">' + tempGroupHeading + '</td></tr>';
            
            if((tempGroupHeading == "Telephone Base") || (tempGroupHeading == "Primary Base") || (tempGroupHeading == "Primary Handset") || (tempGroupHeading == "Primary Headset"))
            {      
                base_added = 1;      
                j=0;
            }
        

            
            tempItemTotal = 0;
            for (m=0; m < groupItems.length; m++) {
                itemSettings = groupItems[m];
                if ((itemSettings != null) && (itemSettings != undefined))
                {
                    tempItemTotal += itemSettings[0];
                }
            }
            if ((tempItemTotal < tempMin) || (tempItemTotal > tempMax)) {
                tempSelectionIsGood = false;
            } else {
                tempSelectionIsGood = true;
            }
            
            var pkgContents = document.getElementById("ctl06_PackageCustomizeList_" + pkgID + "_pkg_contents_box");
            
            
            //if((tempGroupHeading != "Telephone Base") && (tempItemTotal > 0))
            if(((tempGroupHeading != "Telephone Base") && (tempGroupHeading != "Primary Base") && (tempGroupHeading != "Primary Handset") && (tempGroupHeading != "Primary Headset")) && (tempItemTotal > 0))
            {   
                displayPKG = 1;
                if(pkgContents)
                {
                        pkgContents.style.display = 'block';
                }
            } else {
                if(displayPKG != 1)
                {
                    if(pkgContents)
                    {
                            pkgContents.style.display = 'none';
                    }
                }
            }
            
            tempHtmlBoxes = "";
            tempNumItemsSelected = 0; // Lawrence 10/17/2007: Reset to 0 for next package group's items
            
            for (m=0; m < groupItems.length; m++) { //loop through items for each package group
                itemSettings = groupItems[m];
                
                
                if ((itemSettings != null) && (itemSettings != undefined))
                {
                    // count the number of items selected
                    // to figure out what instructions to
                    // output to customer for adjustments
                    // to the package selections so that
                    // every group fits within the min/max
                    // ranges specified.
                    tempNumItemsSelected += itemSettings[0]; // Lawrence 10/17/2007
                    
                    for (i=0; i < itemSettings[0]; i++) {//loop through settings for each item
                        if (j % 6 == 0) {
                            tempHtmlBoxes += '<tr>';
                            tempCol = 'pkg_contents_col1';
                        } else {
                            tempCol = 'pkg_contents_col2';
                        }
                        
                        tempQty = itemSettings[0];
                        if((tempGroupHeading == "Telephone Base") || (tempGroupHeading == "Primary Base") || (tempGroupHeading == "Primary Handset") || (tempGroupHeading == "Primary Headset"))
                        {
                            tempUrl = itemSettings[1].replace("thumb1","thumb6");
                            tempCol = 'base_item';
                            
                        } else {
                            tempUrl = itemSettings[1].replace("thumb1","thumb4");                        
                        }
                        
                        tempDisplay = itemSettings[2];
                        
                        
                        if (tempDisplay == '2') {
                            if (tempSelectionIsGood) {
                                tempCss = 'pkg_item_double_box_good';
                            } else {
                                tempCss = 'pkg_item_double_box_bad';
                            }
                            tempHtmlBoxes += '<td colspan="2" class="pkg_contents_col_double">';
                            tempHtmlBoxes += '<table class="' + tempCss + '" border="0" cellpadding="0" cellspacing="0"><tr>';
                            tempHtmlBoxes += '<td><img src="' + tempUrl + '" /></td>';
                            tempHtmlBoxes += '<td class="pkg_double_box_qty">x' + tempQty + '</td>'
                            tempHtmlBoxes += '</tr></table>';
                            tempHtmlBoxes += '</td></tr>';
                            j++;
                            break;
                        } else {
                            if (tempSelectionIsGood) {
                                if((tempGroupHeading == "Telephone Base") || (tempGroupHeading == "Primary Base") || (tempGroupHeading == "Primary Handset") || (tempGroupHeading == "Primary Headset"))
                                {
                                    tempCss = 'pkg_selection_good_base';
                                } else {
                                    tempCss = 'pkg_selection_good';
                                }
                            } else {
                                if((tempGroupHeading == "Telephone Base") || (tempGroupHeading == "Primary Base") || (tempGroupHeading == "Primary Handset") || (tempGroupHeading == "Primary Headset"))
                                {
                                    tempCss = 'pkg_selection_bad_base';
                                } else {
                                    tempCss = 'pkg_selection_bad';
                                } 
                            }
                            
                            if((tempGroupHeading == "Telephone Base") || (tempGroupHeading == "Primary Base") || (tempGroupHeading == "Primary Handset") || (tempGroupHeading == "Primary Headset"))
                            {
                                tempHtmlBoxes += '<td class="' + tempCol + '" colspan="4">';
                            } else {
                                 tempHtmlBoxes += '<td class="' + tempCol + '">';
                            }
                            tempHtmlBoxes += '<table class="' + tempCss + '" border="0" cellpadding="0" cellspacing="0">';
                            tempHtmlBoxes += '<tr><td><img src="' + tempUrl + '" /></td></tr>';
                            tempHtmlBoxes += '</table>';
                            tempHtmlBoxes += '</td>';
                        }
                        if (j % 6 == 5) {
                            tempHtmlBoxes += '</td></tr>';
                        }
                        
                        if((tempGroupHeading == "Telephone Base") || (tempGroupHeading == "Primary Base") || (tempGroupHeading == "Primary Handset") || (tempGroupHeading == "Primary Headset"))
                                {
                                    tempHtmlBoxes += '</td></tr>';
                                }
                        if((tempGroupHeading == "Telephone Base") || (tempGroupHeading == "Primary Base") || (tempGroupHeading == "Primary Handset") || (tempGroupHeading == "Primary Headset"))
                        {
                            j = 0;
                        } else { j++; }
                    }
                }
            }
                        
            // Lawrence 10/17/2007: Output instructional message per package group
            // to explain to customer how many more or less items are needed for
            // the current package group.
//            if ((tempMin == 0) && (tempNumItemsSelected <= tempMax) && (tempNumItemsSelected >= tempMin)) {
//                html += '<tr><td colspan="2" class="pkg_contents_no_adjust">Optional: No selections required for package.</td></tr>';
//            } else if (tempNumItemsSelected > tempMax) {
//                if (tempNumItemsSelected - tempMax == 1) {
//                    alert('Too Many '+ tempGroupHeading + ': Please remove ' + (tempNumItemsSelected - tempMax) + ' item.');
//                    html += '<tr><td colspan="2" class="pkg_contents_adjust_remove">Too Many Items: Please remove ' + (tempNumItemsSelected - tempMax) + ' item.</td></tr>';
//                } else {
//                    alert('Too Many '+ tempGroupHeading + ': Please remove ' + (tempNumItemsSelected - tempMax) + ' items.');
//                    html += '<tr><td colspan="2" class="pkg_contents_adjust_remove">Too Many Items: Please remove ' + (tempNumItemsSelected - tempMax) + ' items.</td></tr>';
//                }
//            } else if (tempNumItemsSelected < tempMin) {
//                if (tempMin - tempNumItemsSelected == 1) {
//                    alert('Not Enough '+ tempGroupHeading + ': Please select ' + (tempMin - tempNumItemsSelected) + ' more item.');
//                    html += '<tr><td colspan="2" class="pkg_contents_adjust_add">Not Enough Items: Please select ' + (tempMin - tempNumItemsSelected) + ' more item.</td></tr>';
//                } else {
//                    alert('Not Enough '+ tempGroupHeading + ': Please select ' + (tempMin - tempNumItemsSelected) + ' more items.');
//                    html += '<tr><td colspan="2" class="pkg_contents_adjust_add">Not Enough Items: Please select ' + (tempMin - tempNumItemsSelected) + ' more items.</td></tr>';
//                }
//            } else {
//                html += '<tr><td colspan="2" class="pkg_contents_no_adjust">Enough items selected.</td></tr>';
//            }
            html += tempHtmlBoxes;
            
        }
html += '</table>';
        var CurrPkgContents = document.getElementById("ctl06_PackageCustomizeList_" + pkgID + "_current_pkg_contents");
        
        if(CurrPkgContents)
        {
            CurrPkgContents.innerHTML = html;
        }
        //---------------------------

        //Lawrence: Set total price of package contents
        //document.getElementById("PackageCustomizeList1_TR_Total_Amount").value = '$' + dblTotalPrice.toFixed(2);
        //document.getElementById("PackageCustomizeList1_TR_Total_Amount_contents").value = '$' + dblTotalPrice.toFixed(2);
        
        var PkgCustomizeListTotal = document.getElementById("ctl06_PackageCustomizeList_" + pkgID + "_TR_Total_Amount_contents")
        
        if(PkgCustomizeListTotal)
        {
            PkgCustomizeListTotal.value = '$' + dblTotalPrice.toFixed(2);
        }
        
        
        // new akil stuff
        
        html = "";
        tempGroupIndex = 0;
        
for (id in pkgGroups) {
    
	tempGroupHeading = pkgGroupHeadings[tempGroupIndex][0];
	tempMin = pkgGroupHeadings[tempGroupIndex][1];
	tempMax = pkgGroupHeadings[tempGroupIndex][2];

	tempGroupIndex++;

	groupItems = pkgGroups[id];
            
	html += '<div class="yur_pkg_grp">';
	html += '<div class="yur_pkg_grp_hdr_req">';
	html += '<p class="yur_pkg_grp_hdr">' + tempGroupHeading + '</p>';
	
	j=0;

	tempItemTotal = 0;
	
	for (m=0; m < groupItems.length; m++) 
	{
		itemSettings = groupItems[m];
		if ((itemSettings != null) && (itemSettings != undefined))
		{
		    //alert(itemSettings[0] + " - " + itemSettings[4] + " - " + tempMax + " - " + tempMin );
		    tempItemTotal += itemSettings[0];
		}
		
	}
	tempNumItemsSelected = tempItemTotal;
	
	if ((tempItemTotal < tempMin) || (tempItemTotal > tempMax)) 
	{
		tempSelectionIsGood = false;
	} else {
		tempSelectionIsGood = true;
	}
            
	
	var req;
	
	if ((tempMin == 0) && (tempNumItemsSelected <= tempMax) && (tempNumItemsSelected >= tempMin)) {
		req = '<span class="pkg_contents_no_adjust">Optional: No selections required for package.</span>';
	} else if (tempNumItemsSelected > tempMax) {
		if (tempNumItemsSelected - tempMax == 1) {
			alert('Too Many '+ tempGroupHeading + ': Please remove ' + (tempNumItemsSelected - tempMax) + ' item.');
			req = '<span class="pkg_contents_adjust_remove">Too Many Items: Please remove ' + (tempNumItemsSelected - tempMax) + ' item.</span>';
		} else {
			alert('Too Many '+ tempGroupHeading + ': Please remove ' + (tempNumItemsSelected - tempMax) + ' items.');
			req = '<span class="pkg_contents_adjust_remove">Too Many Items: Please remove ' + (tempNumItemsSelected - tempMax) + ' items.</span>';
		}
	} else if (tempNumItemsSelected < tempMin) {
		if (tempMin - tempNumItemsSelected == 1) {
			alert('Not Enough '+ tempGroupHeading + ': Please select ' + (tempMin - tempNumItemsSelected) + ' more item.');
			req = '<span class="pkg_contents_adjust_add">Not Enough Items: Please select ' + (tempMin - tempNumItemsSelected) + ' more item.</span>';
		} else {
			alert('Not Enough '+ tempGroupHeading + ': Please select ' + (tempMin - tempNumItemsSelected) + ' more items.');
			req = '<span class="pkg_contents_adjust_add">Not Enough Items: Please select ' + (tempMin - tempNumItemsSelected) + ' more items.</span>';
		}
	} else {
		req = '<span class="pkg_contents_no_adjust">Enough items selected.</span>';
	}
            
	html += '<p class="yur_pkg_grp_req">' + req + '</p>';
	html += '</div>';

	html += '<table class="yur_pkg_item">';
	
	tempRow = "";
	tempNumItemsSelected = 0; // Lawrence 10/17/2007: Reset to 0 for next package group's items

	for (m=0; m < groupItems.length; m++) { //loop through items for each package group
		itemSettings = groupItems[m];

		if ((itemSettings != null) && (itemSettings != undefined))
		{
		if (itemSettings[0] > 0) {
			tempQty = itemSettings[0];
		    tempUrl = itemSettings[1].replace("thumb1","thumb4");
		    tempPrice = itemSettings[3].replace("$","");
            tempSku = itemSettings[4];
            tempSubtotal = tempQty * tempPrice;
            tempSubtotal = tempSubtotal.toFixed(2);
                        
	        
			tempRow += '<tr>';
			tempRow += '<td class="yur_pkg_item_image"><img src="' + tempUrl + '" /></td>';
			tempRow += '<td class="yur_pkg_item_qty">QTY: <strong>' + tempQty + '</strong> <br>' + tempSku + '</td>';
			tempRow += '<td class="yur_pkg_item_price">$' + tempSubtotal + '</td>';
			tempRow += '</tr>';
			}
		}
		
	}
	html += tempRow;
	html += '</table>';
	html +='</div>';
	
}


        var pkgContentsDetails = document.getElementById("ctl06_PackageCustomizeList_" + pkgID + "_current_pkg_contents_details");
        
        if(pkgContentsDetails)
        {
        
            pkgContentsDetails.innerHTML = html;
        }




        
        return false ;
    }


function print_r(theObj){	  if(theObj.constructor == Array ||	     theObj.constructor == Object){	    document.write("<ul>");	    for(var p in theObj){	      if(theObj[p].constructor == Array||	         theObj[p].constructor == Object){	document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");	        document.write("<ul>");	        print_r(theObj[p]);	        document.write("</ul>");	      } else {	document.write("<li>["+p+"] => "+theObj[p]+"</li>");	      }	    }	    document.write("</ul>");	  }	}


    function OpenMoreInfoU(url)
    {
        window.open(url,"newADD","left=" + ((screen.width-500)/2) + ",top=" + ((screen.height-250)/2) + ",width=500,height=250,scrollbars=yes,toolbars=no,resizable=yes" )
	    
        return false;
    }
    
    /**
     * Update the "Current Qty" of a package group and also the total price of package
     */
    function Change_QTY_Price(maxQTY , minQTY , objQTYCombo , objPackagePriceLabel,  objQTYLabel , objTotalPrice, pkgID)
	{
	    refreshPkgContentsBox(pkgID);
	    
	    var intIndex = objQTYCombo.id.indexOf('_PackageCustomizeItemDetails1_DDR_Item_Number');
        var strTmp = Left(objQTYCombo.id , intIndex-1) ;

	    var elem = document.forms[0].elements; //Lawrence 9/11/2007: removed the ".all" as it is invalid inFireFox and just plain unneccessary
        var intTotalQty = 0;
        var dblTotalPrice = 0.00 ;
        
        for(var i=0; i < elem.length; i++)
        {
            //this if-statement only chooses the current package group
            if (Left(elem[i].id , intIndex-1 ) == strTmp)
            {
                if ((elem[i].id.indexOf('DDR_Item_Number')) != -1)
                {
                    //Lawrence 9/11/2007: Only update intTotalQty if the element is part of the current pkg group
                    if( Left(elem[i].id , intIndex-1 ) == strTmp )
                    {
                        intTotalQty = intTotalQty + parseInt(elem[i].value);
                    }
                }
            }
        }
        objQTYLabel.innerHTML = intTotalQty;
//        var button = document.getElementById("ctl05_PackageCustomizeList_" & pkgID &  "_BTN_Submit_Contents");
//        if ((parseInt(intTotalQty) > parseInt(maxQTY)) || (parseInt(intTotalQty) < parseInt(minQTY))) {
//            // Function Check_QTY() uses these CSS class names to
//            // determine if the current quantity of a package group
//            // is good or bad. These CSS rules are set in this function
//            // and also on initial load in the PackageCustomizeItems.ascx.vb 
//            // code file. Don't change these CSS rule names!
//            objQTYLabel.className = 'pkg_group_count_bad';
//            button.style.visibility = "hidden";
//        } else {
//            objQTYLabel.className = 'pkg_group_count_good';
//            button.style.visibility = "visible";
//        }
	    return false;
    }
    
    function getThumbImg(imagePath)
    {
        var newImagePath;
        newImagePath = imagePath.replace(".jpg", "_thumb1.jpg");
        newImagePath.replace(".gif", "_thumb1.gif");
        newImagePath.replace(".png", "_thumb1.png");
        return newImagePath;
    }
    
    function Check_QTY()
    {
        var elem = document.forms[0].elements;
        for(var i=0;i<elem.length;i++)
        {
            if (elem[i].id.indexOf('lblTotal') != -1)
            {
                // Function Check_QTY() uses these CSS class names to
                // determine if the current quantity of a package group
                // is good or bad. These CSS rules are set in function Change_QTY_Price()
                // and also on initial load in the PackageCustomizeItems.ascx.vb 
                // code file. Don't change these CSS rule names!
                if (elem[i].className == 'pkg_group_count_bad')
                {
                    alert('Invalid quantities selected for package deal.\nSee red instructions on \"My Package\" section for details.');
                    return false ;
                }
            }
         }
         
         return true ;
    }


function swapPKG(pkgID)
    {
    
    
        if(pkgID == "")
        {
            return false;
        }
        var div;
        if (pkgID.indexOf('noPKGFlyDesc') != -1)
        {

           div = document.getElementById(pkgID);
           if (div){div.style.display = 'block';}
        
        } else {
        
            div = document.getElementById("ctl06_noPKGFlyDesc");
            if(div){div.style.display = 'none';}
        
        }
        
        pkgID = pkgID + "_package_wrapper";
        //alert(pkgID);
        
        var divs = document.getElementsByTagName("div");
        
        for(var i = 0; i < divs.length; i++)
        {
            if((divs[i]["id"].indexOf('package_wrapper')) != -1)
            {
                if(divs[i]["id"] == pkgID)
                {
                    divs[i].style.display = "block";
                }
                else
                {
                    divs[i].style.display = "none";
                }
                
                //alert(divs[i]["id"]);
            }
        }
    }