﻿var FRONT_COLORS = 1;
var BACK_COLORS = 0;

var keyPressTimeout = 800;
var typingHandler;
var enabled = true;
var image_brand_id = 1;

function ClickMainTab(id)
{
    var colorsBlock = document.getElementById("colorsTable");
    var typesBlock = document.getElementById("typesTable");

    switch(id)
    {
        case "types" :
            colorsBlock.style.display = "none";
            typesBlock.style.display = "block";
            SetTabUnselected("colors");
            SetTabSelected("types");
            break;
        case "colors" :
            typesBlock.style.display = "none";
            colorsBlock.style.display = "block";
            SetTabUnselected("types");
            SetTabSelected("colors");
            break;
    }
}

function SetTabSelected(id)
{
    var block1 = document.getElementById("tab_" + id + "_1");
    var block2 = document.getElementById("tab_" + id + "_2");
    var block3 = document.getElementById("tab_" + id + "_3");
    var block4 = document.getElementById("tab_" + id + "_4");
    var block5 = document.getElementById("tab_" + id + "_5");
    var block6 = document.getElementById("tab_" + id + "_6");
    
    if(block1 != null)
    {
        block1.src = "/img/pages/tab/selectedleft.gif";
    }
    
    if(block2 != null)
    {
        block2.style.backgroundImage = "url('/img/pages/tab/selectedmiddle.gif')";
    }
    
    if(block3 != null)
    {
        block3.src = "/img/pages/tab/selectedright.gif";
    }    
   
    if(block4 != null)
    {    
        block4.style.borderTopWidth = "0px";
    }
    
    if(block5 != null)
    {        
        block5.style.borderTopWidth = "0px";
    }
    
    if(block6 != null)
    {
        block6.style.borderTopWidth = "0px";
    }
}

function SetTabUnselected(id)
{
    var block1 = document.getElementById("tab_" + id + "_1");
    var block2 = document.getElementById("tab_" + id + "_2");
    var block3 = document.getElementById("tab_" + id + "_3");
    var block4 = document.getElementById("tab_" + id + "_4");
    var block5 = document.getElementById("tab_" + id + "_5");
    var block6 = document.getElementById("tab_" + id + "_6");
    
    if(block1 != null)
    {
        block1.src = "/img/pages/tab/unselectedleft.gif";
    }
    
    if(block2 != null)
    {
        block2.style.backgroundImage = "url('/img/pages/tab/unselectedmiddle.gif')";
    }
    
    if(block3 != null)
    {
        block3.src = "/img/pages/tab/unselectedright.gif";
    }
    
    
    
    if(block4 != null)
    {
        block4.style.borderTopWidth = "1px";
    }
    
    if(block5 != null)
    {
        block5.style.borderTopWidth = "1px";
    }
    
    if(block6 != null)
    {
        block6.style.borderTopWidth = "1px";
    }
}

// for table
function SelectColor(id)
{    
    var dropdown = document.getElementById(dropdownColors);
    dropdown.value = id;
    ProcessColor(id);
}

// for dropdown
function SelectColorDropDown(id)
{
    ProcessColor(id);   
}


function ProcessColor(id)
{
    HighlightColor(id);
    SetColorOnTabs(id);
    reloadBottomTable();
}

function SetSides(id)
{
    var frontOld = document.getElementById(dropdownFront).value;
    var backOld = document.getElementById(dropdownBack).value;
    
    var frontNew = frontOld;
    var backNew = backOld;
    
    //var frontPanel = document.getElementById("colors_front");
    //var backPanel = document.getElementById("colors_back");
    
    switch(id)
    {
        case "0":
            //frontPanel.style.display = "";
            //backPanel.style.display = "none";
            backNew = 0;
            if(frontNew == 0)
            {
                frontNew = FRONT_COLORS;
            }
            if(frontNew == 0)
            {
                frontNew = 1;
            }
            break;
        case "1":
            //frontPanel.style.display = "none";
            //backPanel.style.display = "";
            frontNew = 0;
            if(backNew == 0)
            {
                backNew = BACK_COLORS;
            }
            if(backNew == 0)
            {
                backNew = 1;
            }
            break;
        case "2":
            //frontPanel.style.display = "";
            //backPanel.style.display = "";
            if(frontNew == 0)
            {
                frontNew = FRONT_COLORS;
            }
            if(frontNew == 0)
            {
                frontNew = 1;
            }
            if(backNew == 0)
            {
                backNew = BACK_COLORS;
            }
            if(backNew == 0)
            {
                backNew = 1;
            }
            break;   
    }
    
    SetInkColors(frontNew, backNew);
    reloadBottomTable();
}

function SetFrontColors(number)
{    
    var backColors = document.getElementById(dropdownBack).value; 
    
    if((number == 0) && (backColors == 0))
    {
        number = 1;
    }
    
    SetInkColors(number, backColors);
    SetSidesDropdown(number, backColors);
    reloadBottomTable();
}


function SetBackColors(number)
{
    var frontColors = document.getElementById(dropdownFront).value; 
    
    if((number == 0) && (frontColors == 0))
    {
        number = 1;
    }
    
    SetInkColors(frontColors, number);
    SetSidesDropdown(frontColors, number);
    reloadBottomTable();
}

function SetSidesDropdown(frontColors, backColors)
{
    return;
    
    //var frontPanel = document.getElementById("colors_front");
    //var backPanel = document.getElementById("colors_back");
    //var dropdown = document.getElementById(dropdownSides);
    
    if((frontColors != "0") && (backColors != "0"))
    {
        //dropdown.value = "2";
        //frontPanel.style.display = "";
        //backPanel.style.display = "";
    }
    
    if((frontColors == "0") && (backColors != "0"))
    {
        //dropdown.value = "1";
        //frontPanel.style.display = "none";
        //backPanel.style.display = "";
    }
    
    if((frontColors != "0") && (backColors == "0"))
    {
        //dropdown.value = "0";
        //frontPanel.style.display = "";
        //backPanel.style.display = "none";
    }
}


function SetInkColors(frontColors, backColors)
{
    document.getElementById(dropdownFront).value = frontColors;
    document.getElementById(dropdownBack).value = backColors;
    
    document.getElementById("amountOfFrontColor").value = frontColors;
    document.getElementById("amountOfBackColor").value = backColors;
    
    if(frontColors != 0)
    {
        FRONT_COLORS = frontColors;
    }
    
    if(backColors != 0)
    {
        BACK_COLORS = backColors;
    }
}


function SelectTShirtType(id)
{
    var dropdown = document.getElementById(dropdownTypes);
    dropdown.value = id;
    ProcessTShirtType(id);
}

function SelectTShirtTypeDropdown(id)
{
    ProcessTShirtType(id);
}


function ProcessTShirtType(id)
{	
	TShirtType_ID = id;
	document.getElementById("tshirtTypeId").value = id;
    HighlightTShirtType(id);
    ShowBrandSet(id);
    ProcessQuantity();
    reloadBottomTable();
}

function SelectTShirtBrand(id)
{
    document.getElementById(dropdownBrands).value = id;
    ProcessTShirtBrand(id);
}


function SelectTShirtBrandDropdown(id)
{
    var radioElement = document.form1.tshirtBrand;
    SetRadioValue(radioElement, id);
    ProcessTShirtBrand(id);
}


function ProcessTShirtBrand(id)
{
	image_brand_id = id;
	ProcessQuantity();
    reloadBottomTable();
}

function SelectTurnaround(id)
{
    reloadBottomTable();
}

function SetColorOnTabs(id)
{
    var colorBlock = document.getElementById("sampleColor_" + id);
    var colorTab = document.getElementById("selectedColorTab");
    var colorTab1 = document.getElementById("selectedColorTab1");
    if((colorBlock != null) && (colorTab != null))
    {
        colorTab.style.backgroundColor = colorBlock.style.backgroundColor;
    }
    
    if((colorBlock != null) && (colorTab1 != null))
    {
        colorTab1.style.backgroundColor = colorBlock.style.backgroundColor;
    }
}


function HighlightColor(id)
{
    var colorsTable = document.getElementById("colorsTable");
    var tds = colorsTable.getElementsByTagName("td");
    for(var i = 0; i < tds.length; i++)
    {
        if(tds.item(i).id.indexOf("color_") == 0)
        {
            tds.item(i).style.backgroundColor = "#FFFFFF";
        }
    }
    
    var colorBlock = document.getElementById("color_" + id);
    if(colorBlock != null)
    {
        colorBlock.style.backgroundColor = "#D4EDF8";
    }
}

function HighlightTShirtType(id)
{
    // unhighlight all shirt types
    for(var key in typesBrands)
    {
        var typeBlock = document.getElementById("tshirttype_" + key);
        if(typeBlock != null)
        {
            typeBlock.style.backgroundColor = "#FFFFFF";
        }
    }
    
    // highlight right shirt type
    var typeBlock = document.getElementById("tshirttype_" + id);
    if(typeBlock != null)
    {
        typeBlock.style.backgroundColor = "#D4EDF8";
    }
}

function ShowBrandSet(id)
{   
    // make all brands sets invisible
    for(var i = 0; i < brands.length; i++)
    {
        var brandBlock = document.getElementById("brand_" + brands[i]);
        if(brandBlock != null)
        {
            brandBlock.style.display = "none";
        }
           
        var brandOption = document.getElementById("option_brand_" + brands[i]);
        if(brandOption != null)
        {
            brandOption.style.display = "none";                
        }        
    }
    
    // make right brand set visible
    var isSelectedBrandVisible = false;
    var selectedBrand = getIntRadio("tshirtBrand");
    for(var i = 0; i < typesBrands[id].length; i++)
    {   
        if(typesBrands[id][i] != 0)
        {
            var brandBlock = document.getElementById("brand_" + typesBrands[id][i]);
            if(brandBlock != null)
            {
                brandBlock.style.display = "";                
            }
            
            var brandOption = document.getElementById("option_brand_" + typesBrands[id][i]);
            if(brandOption != null)
            {
                brandOption.style.display = "";                
            }
        }
        
        if(typesBrands[id][i] == selectedBrand)
        {
            isSelectedBrandVisible = true;
        }
    }
    
    
    
    // if no visible brand is selected - then select it
    if(!isSelectedBrandVisible)
    {
        var radioElement = document.form1.tshirtBrand;
        
        for(var i = 0; i < radioElement.length; i++)
        {
            radioElement[i].checked = false;
        }
        
        for(var i = 0; i < radioElement.length; i++)
        {
            if(radioElement[i].value == typesBrands[id][0])
            {
                selectedBrand = typesBrands[id][0];
                radioElement[i].checked = true;
                //document.getElementById(dropdownBrands).value = typesBrands[id][0];
            }
        }
    }
    
    image_brand_id = selectedBrand;
    ProcessBrandsDropdown(id, selectedBrand);
}

function ProcessBrandsDropdown(typeId, brandId)
{
    var dropdown = document.getElementById(dropdownBrands);
    
    var startIndex = dropdown.options.length;
    for(var i = startIndex; i <= 0; i--)
    {
        dropdown.options[i] = null;
    }
    
    var counter = 0; 
    //dropdown.selectedIndex = 0;  
    for(var i = 0; i < typesBrands[typeId].length; i++)
    {
      var tmpId = typesBrands[typeId][i];
      if(tmpId > 0)
      {
          var brandName = document.getElementById("name_brand_" + tmpId).value;
          //var selected = (brandId == tmpId);
          dropdown.options[counter] = new Option(brandName, tmpId);
          counter++;
      }
    }

    dropdown.value = brandId;
    dropdown.options[counter] = null;    
    for(var i = counter; i < dropdown.options.length; i++)
    {
        if(dropdown.options[i] != null)
        {
            dropdown.options[i] = null;
        }
    }    
}

function SetRadioValue(radioElement, value)
{
    for(var i = 0; i < radioElement.length; i++)
    {
        radioElement[i].checked = false;
    }
    
    for(var i = 0; i < radioElement.length; i++)
    {
        if(radioElement[i].value == value)
        {
            radioElement[i].checked = true;
        }
    }
}

// ======================= Bottom table =======================

function CountInstantQuote()
{
    reloadBottomTable();
}

function reloadBottomTable()
{
	if(!enabled)
	{
	    //return;
	}
	
	var bTable = document.getElementById('bTable');
	//bTable.style.display = 'block';
	var shirtColorId = document.getElementById(dropdownColors).value;
	var argument =	getIntInput('quantitySmall') + '|' + 
					getIntInput('quantityMedium') + '|' + 
					getIntInput('quantityLarge') + '|' + 
					getIntInput('quantityXLarge') + '|' + 
					getIntInput('quantity2XLarge') + '|' + 
					getIntInput('quantity3XLarge') + '|' + 
					getIntInput('quantity4XLarge') + '|' + 
					TShirtType_ID + '|' +
					getIntRadio('tshirtBrand') + '|' + 
					shirtColorId + '|' + 
					getIntInput('amountOfFrontColor') + '|' + 
					getIntInput('amountOfBackColor') + '|' + 
					getIntRadio('turnaround') + '|' +
					COUPON_CODE; 	
					
	CallServer("reloadBottomTable|" + argument, "");
}

function ReceiveServerData(str)
{
	//prompt('',str);
	eval(str);
	//var image_brand_id = getIntRadio('tshirtBrand');
	var brandNameBottom = document.getElementById('brandNameBottom');
	brandNameBottom.innerHTML = document.getElementById("tshirttype_name_" + TShirtType_ID).value + ' (' + document.getElementById('image_brand_' + image_brand_id).alt + ')';
	
	

	
	var contetntTD = document.getElementById('contentTD');
	var contentValue = '<table style="width:100%;border: 1px solid #c0c0c0; TEXT-ALIGN: center; font-size: small; background-color: #FFFFFF;" cellPadding="3"><tr style="BACKGROUND-COLOR: #5995ca; COLOR: #ffffff; FONT-WEIGHT: 700"><td style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ECEBD6" noWrap colspan="3"><img alt="Gildan" src="' + document.getElementById('image_brand_' + image_brand_id).src + '" /></td></tr><tr style="BACKGROUND-COLOR: #5191CA; COLOR: #ffffff; FONT-WEIGHT: 700"><td style="TEXT-ALIGN: center; BACKGROUND-COLOR: #336FA4" noWrap>Quantity</td><td noWrap style="background-color: #336FA4">' + 
						'<table style="width:100%;" cellpadding="0" cellspacing="0"><tr><td>' + 
						'<font style="font-size: medium">' + getIntInput('amountOfFrontColor') + '</font> Color/Front<br />&nbsp;<font style="font-size: medium">' + getIntInput('amountOfBackColor') + '</font> Colors/Back</td>';
	
	if(defaultPercentage > 0)
	{
	    contentValue += '<td noWrap style="background-color: #EA4527" width="50%">With ' + defaultPercentage + '% <br />Discount</td>';
	}	
	contentValue += '</td></tr></table></td></tr>';
	
		
		
	var backgroundColor = '';				
	var backgroundColorTD = '';				
	var backgroundColorPriceTD = '';				
	var fontColorPriceTD = '';	
	var fontWeight = '';			
	for(var i = 0; i < ArrayOfTShirtsQuantityCostItem.length; i++)
	{
		if(i % 2 == 0)
		{
			backgroundColor = ' style="BACKGROUND-COLOR: #f0f0f0"';
			backgroundColorTD = '#81AED8';
			backgroundColorPriceTD = '#EAEAEA;';				
		}
		else
		{
			backgroundColor = '';
			backgroundColorTD = '#99bddf';
			backgroundColorPriceTD = '#FFFFFF;';		
		}
		
		if(ArrayOfTShirtsQuantityCostItem[i].IsMinPrice == 'True')
		{
			fontColorPriceTD = '#D12D2E';
			fontWeight = 'bold';
		}
		else
		{
			fontWeight = 'normal';
			if(ArrayOfTShirtsQuantityCostItem[i].QuantityId == 1)
			{
			    fontColorPriceTD = '#999999';
			}
			else
			{
			    fontColorPriceTD = '#000000';
			}
		}
		
		//alert('IsSelected = ' + ArrayOfTShirtsQuantityCostItem[i].IsSelected + ' = ' + (ArrayOfTShirtsQuantityCostItem[i].IsSelected == 'True'));
		
		if(ArrayOfTShirtsQuantityCostItem[i].IsSelected == 'True')
		{
			backgroundColorPriceTD = '#FCEA7E;';						
		}
		
	
		
		
		

		contentValue += '<tr ' + backgroundColor + '>' +
		'<td style="BACKGROUND-COLOR: ' + backgroundColorTD + '" noWrap>' +
						'<b style="COLOR: #ffffff">' + ArrayOfTShirtsQuantityCostItem[i].Text + '</b></td>';				
	    
	    if(defaultPercentage > 0)
	    {
	        contentValue += '<td style="COLOR: ' + fontColorPriceTD + '; background-color: ' + backgroundColorPriceTD + ';font-weight:' + fontWeight + '">$' + ArrayOfTShirtsQuantityCostItem[i].PricePerUnitWithDiscount + ' each</td>';
	    }  
	    else
	    {	         
			contentValue += '<td style="COLOR: ' + fontColorPriceTD + '; background-color: ' + backgroundColorPriceTD + ';font-weight:' + fontWeight + '">$' + ArrayOfTShirtsQuantityCostItem[i].PricePerUnit + ' each</td>';
	    }
	      	
	    contentValue += '</tr>';
	}		
	
	if(minimumQuantity == '12')
	{
	    contentValue += '<tr style="BACKGROUND-COLOR: #f0f0f0">' + 
						    '<td style="BACKGROUND-COLOR: #81AED8;COLOR: #ffffff" noWrap>' +
						    'For less than ' + minimumQuantity + '</td>' +
						    '<td style="COLOR: #999999; background-color: #EAEAEA;"><a href="/pages/contactus.html">Contact Us</a></td>';
    
		
	    //if(defaultPercentage > 0)
	    //{
	    //    contentValue += '<td style="COLOR: #999999; background-color: #EAEAEA;"><a href="/pages/contactus.html">Contact Us</a></td>';
	    //}
	    contentValue += '</tr>';
	}
	
				
	contentValue += '</table>';
	
	contetntTD.innerHTML = contentValue;
	
	// fill instant quote fields
	var tableRight = document.getElementById("subtotalRight");
    var tableWrong = document.getElementById("subtotalWrong");

    ProcessPrices(costSubtotal, costPerUnit, "0.0", 24);
    ProcessCoupon(COUPON_CODE, costDiscount, costDiscountPercentage, costFinalPrice, couponError, isCouponErrorCritical);

    if(parseFloat(costSubtotal) == 0)
    {
        tableRight.style.display = "block";
        tableWrong.style.display = "none"; 
        DisableAdding();
    }
    else
    {
        tableRight.style.display = "block";
        tableWrong.style.display = "none";
    
        EnableAdding();
        
    }
}

function getIntInput(id)
{
	var returnValue = 0;	
	
	var element = document.getElementById(id);
	if(element == null)
	{
		return returnValue;
	}
	
	if(element.value.length == 0)
	{
		return returnValue;
	}
	
	returnValue = parseInt(element.value, 10);
	
	return returnValue;
}

function getIntRadio(id)
{
    var value = "0";
    var elements = document.getElementsByName(id);
    for(var i = 0; i < elements.length; i++)
    {
        if(elements[i].checked)
        {
            value = elements[i].value;
        }
    }    
   
    return parseInt(value, 10);
}



function PrintQuantity(obj)
{
    var id = obj.id;
    if (typingHandler) clearTimeout(typingHandler);
    typingHandler = window.setTimeout("ProcessQuantity()", keyPressTimeout, "JavaScript");
}

function ProcessQuantity()
{
    var tshirtBrandId = getIntRadio('tshirtBrand');
    var index = TShirtType_ID + "," + tshirtBrandId;
    var minQuantity = typesBrandsMinimum[index];
    var maxQuantity = typesBrandsMaximum[index];
    
    var valueSmall = document.getElementById("quantitySmall").value;
    var valueMedium = document.getElementById("quantityMedium").value;
    var valueLarge = document.getElementById("quantityLarge").value;
    var valueXLarge = document.getElementById("quantityXLarge").value;
    var value2XLarge = document.getElementById("quantity2XLarge").value;
    var value3XLarge = document.getElementById("quantity3XLarge").value;
    var value4XLarge = document.getElementById("quantity4XLarge").value;
    
    var tableRight = document.getElementById("subtotalRight");
    var tableWrong = document.getElementById("subtotalWrong");
    
    if (CheckOnlyNumeric(valueSmall) &&
        CheckOnlyNumeric(valueMedium) &&
        CheckOnlyNumeric(valueLarge) &&
        CheckOnlyNumeric(valueXLarge) &&
        CheckOnlyNumeric(value2XLarge) &&
        CheckOnlyNumeric(value3XLarge) &&
        CheckOnlyNumeric(value4XLarge))
    {
        HideNumericError();
        // count total and check if it is good
        var totalCount = CountTotal();
        
        var fieldTotal = document.getElementById("total");
        if(fieldTotal.innerHTML)
        {
            fieldTotal.innerHTML = totalCount;
        }
        else
        {
            fieldTotal.textContent = totalCount;
        }
        
        if(totalCount < minQuantity)
        {
			
            //tableRight.style.display = "none";
            //tableWrong.style.display = "block";
            
            document.getElementById("less12").innerHTML = 'You need a minimum of ' + minQuantity + ' Shirts';          
            document.getElementById("minimum1").innerHTML = minQuantity;
            document.getElementById("minimum2").innerHTML = minQuantity;
            
            HideMaximumError();
            
            OutputMinimumError();
            return;
        }
        
        if(totalCount > maxQuantity)
        {
            //tableRight.style.display = "none";
            //tableWrong.style.display = "block";
            
            document.getElementById("less12").innerHTML = 'Get a custom quote for orders above ' + maxQuantity;
            document.getElementById("maximum1").innerHTML = maxQuantity;
            document.getElementById("maximum2").innerHTML = maxQuantity;
            
            HideMinimumError();
            OutputMaximumError();
            return;
        }   
        
        HideMinimumError();
        HideMaximumError();
        enabled = true;
        reloadBottomTable();
        
    }
    else
    {
        tableRight.style.display = "none";
        tableWrong.style.display = "block";
        
        HideMaximumError();
        HideMinimumError();
        OutputNumericError();
        return;
    }
        
    
}

function CheckOnlyNumeric(val)
{
    var reg = /[^0-9]/;

    if(reg.test(val))
    {        
        return false;
    }
    return true;
}

function HideMaximumError()
{
    document.getElementById("errorMaximumBottom").style.display = "none";
    document.getElementById("errorMaximumTop").style.display = "none";
}

function OutputMaximumError()
{
    document.getElementById("errorMaximumBottom").style.display = "block";
    document.getElementById("errorMaximumTop").style.display = "";
    DisableAdding();
}

function HideMinimumError()
{
    document.getElementById("errorMinimumBottom").style.display = "none";
    document.getElementById("errorMinimumTop").style.display = "none";
}

function OutputMinimumError()
{
    document.getElementById("errorMinimumBottom").style.display = "block";
    document.getElementById("errorMinimumTop").style.display = "";
    DisableAdding();
}

function HideNumericError()
{
    document.getElementById("errorNumericBottom").style.display = "none";
    document.getElementById("errorNumericTop").style.display = "none";
}

function OutputNumericError()
{
    document.getElementById("errorNumericBottom").style.display = "block";
    document.getElementById("errorNumericTop").style.display = "";
    DisableAdding();
}

function EnableAdding()
{
    var buttonAdd = document.getElementById("buttonAdd");
    buttonAdd.disabled = false;
    buttonAdd.src = "/img/add_to_cart.gif";
    enabled = true;
}

function DisableAdding()
{
    var buttonAdd = document.getElementById("buttonAdd");
    buttonAdd.disabled = true;
    buttonAdd.src = "/img/add_to_cart_disabled.gif";
    enabled = false;
}

function CountTotal()
{
    var valueSmall = document.getElementById("quantitySmall").value;
    if(valueSmall.length == 0)
    {
		valueSmall = 0;
    }
    
    var valueMedium = document.getElementById("quantityMedium").value;
    if(valueMedium.length == 0)
    {
		valueMedium = 0;
    }

    var valueLarge = document.getElementById("quantityLarge").value;
    if(valueLarge.length == 0)
    {
		valueLarge = 0;
    }
    
    var valueXLarge = document.getElementById("quantityXLarge").value;
    if(valueXLarge.length == 0)
    {
		valueXLarge = 0;
    }
    
    var value2XLarge = document.getElementById("quantity2XLarge").value;
    if(value2XLarge.length == 0)
    {
		value2XLarge = 0;
    }
    
    var value3XLarge = document.getElementById("quantity3XLarge").value;
    if(value3XLarge.length == 0)
    {
		value3XLarge = 0;
    }
    
    var value4XLarge = document.getElementById("quantity4XLarge").value;
    if(value4XLarge.length == 0)
    {
		value4XLarge = 0;
    }    
   
    var totalCount = parseInt(valueSmall, 10) + parseInt(valueMedium, 10) + parseInt(valueLarge, 10) +
            parseInt(valueXLarge, 10) + parseInt(value2XLarge, 10) + parseInt(value3XLarge, 10) + parseInt(value4XLarge, 10);
            
    
    return totalCount;
}
