﻿
function UpdateSelTotal()
{
    var spnTotal = document.getElementById("spnTotalSel");
    var value = 0;
    if(lsbSelected.length == 1 && lsbSelected.options[0].value == ''){ value = 0; }
    else {
        for (var z = 0; z < lsbSelected.length; z++) {
            if (lsbSelected[z].text == 'No Exposures currently selected.')
            { break; }
            value = value + 1;        
        }
    }
    spnTotal.innerText = value;
}

function CheckOut(){
    var lsbSelectedIndex;
    if(lsbSelected.options[0].value != 'No Exposures currently selected.' && hdnList.value != ''){         
            if (confirm('Preparing the quote will navigate away from this page.  Do you want to continue at this time?')){
                return true;
            }       
            else{ return false; }
        }
    else{
            alert('No exposures have been selected.');
            return false;
        } 
};


function RemoveFromCart(){
    
    var lsbSelectedIndex;
    var strList = hdnList.value; 
    while(lsbSelected.selectedIndex != -1){
        if(lsbSelected.options[lsbSelected.selectedIndex].value != ''){
            lsbSelectedIndex = lsbSelected.selectedIndex;
            strList = strList.replace(lsbSelected.options[lsbSelected.selectedIndex].value + '&', "");
            strList = strList.replace(lsbSelected.options[lsbSelected.selectedIndex].value + ',&', "");
            lsbSelected.remove(lsbSelected.selectedIndex); 
        }
    }
    hdnList.value = strList;

    if(map.GetZoomLevel() >= minExpLevel) { AJAXCallGetExposures(); }
    
    if(lsbSelected.length == 0){
        lsbSelected.length = 1;
        lsbSelected.options[0].text = 'No Exposures currently selected.';
        lsbSelected.options[0].value = '';
        ClearDrawings();
    }
    UpdateSelTotal();
    
};

function RemoveExpFromQuote(Shape, elementId){
    var Value = GetLBValueFromShape(Shape, elementId);
    var strList = hdnList.value; 
    for (var z = 0; z < lsbSelected.length; z++){
        if(lsbSelected.options[z].value == Value){
            lsbSelected.remove(z);
            //Remove value from hdnList as well.
            strList = strList.replace(Value + '&', "");
            strList = strList.replace(Value + ',&', "");
        }
    }
    hdnList.value = strList;
    
    if(map.GetZoomLevel() >= minExpLevel) { AJAXCallGetExposures(); }
    if(lsbSelected.length == 0){
        lsbSelected.length = 1;
        lsbSelected.options[0].text = 'No Exposures currently selected.';
        lsbSelected.options[0].value = '';
        ClearDrawings();
    }
    UpdateSelTotal();
};

function AddExpToQuote(Shape, elementId){
   var Value = GetLBValueFromShape(Shape, elementId);
   var Text = GetLBTextFromShape(Shape, elementId);
    var index = 0;
    var blnFound = false;
    var count = 0;
    
    if(lsbSelected.length == 1){ if(lsbSelected.options[0].value == '' || lsbSelected.options[0].value == 'No Exposures currently selected.'){ lsbSelected.length = 0; } }
        
    blnFound = false;
    for (count=0;count < lsbSelected.length;count++){
        if(lsbSelected.options[count].value ==  Value){
            blnFound = true; 
            break;
        }
    }
        
    if (blnFound == false){
        index = lsbSelected.length;
        lsbSelected.length = index + 1;
        lsbSelected.options[index].text = Text;
        lsbSelected.options[index].value = Value;
        hdnList.value = Value + '&' + hdnList.value;
    }
    UpdateSelTotal();
    AJAXCallGetExposures();
};

function ExpIsSelected(Title){
   var aryTitle = Title.split(",")
   var expId = aryTitle[0];
   var Selected = false;
   var strProjId = GetProjId();
  
   var optionCount = lsbSelected.options.length;
   var Value
    var aryValues = new Array();
    for (var z = 0; z < optionCount; z++){
       
        Value = lsbSelected.options[z].value;
        aryValues = Value.split(",");
        if(aryValues[0] == expId && aryValues[4] == strProjId){
            Selected = true;
            break;
        }
    }   
    return Selected;  
};

function LoadListBox()
{
   
   //var hdnList = document.getElementById('ctl00_Main_hdnList');
   var strList = hdnList.value;  
   var aryValues = new Array;
   var aryExposures = new Array;
   
   if(strList == '' || strList == '&+'){ return; }
   
   if(lsbSelected.length == 1){
      if(lsbSelected.options[0].text == 'No Exposures currently selected.'){ 
        lsbSelected.length = 0;
        aryValues = strList.split('&+');
        for (var z = 0; z < aryValues.length - 1; z++){
            aryExposures = aryValues[z].split(',');
            lsbSelected.length = z + 1;
           
            lsbSelected.options[z].text = 'Exposure ' + aryExposures[1];
            lsbSelected.options[z].value = aryValues[z];
            
} } } }

function SelectAll()
{
    for (var z = 0; z < lsbSelected.length; z++){
        lsbSelected.options[z].selected = true;   
    }   
}