

// RequestData(): primary function for performing the AJAX data request
// tabId: ID of the currect active tab
// parentKey: Collection key for the parent product category
// subKey: Collection key for the selected product category's support content type
// collectIds: All of the collection Ids that will be required to iterate to the last collection
function requestData(tabId, modelNum, returnType, collectIds)
{ 
   // alert(modelNum + " " + returnType + " Parent:" + parentKey + " Cat:" + colKey + " SubCat:" + subKey);
    var url;
    xmlHttp = getXmlHttpObject();
    
    if (xmlHttp == null)
    {
      return;
    }
    // NOTE: set AJAX request values
    url = "/business/provideo/support/includes/scripts/getXMLData.asp";
    url = url + "?mn=" + modelNum;
    url = url + "&type=" + returnType;
    url = url + "&sid=" + Math.random();
    url = url + "&cIds=" + tabId + "~" + collectIds; 
    //alert(url);
 
    switch(returnType)
    {
        case "comma-delim":
           // xmlHttp.onreadystatechange = loadModels(tabId);
           xmlHttp.onreadystatechange = function(){
            if (xmlHttp.readyState == 4)
                loadModels(tabId);
           }
            break;
        default: 
           // xmlHttp.onreadystatechange = loadMedia(tabId);
           xmlHttp.onreadystatechange = function(){
            if (xmlHttp.readyState == 4)
                loadMedia(tabId);
           }
            break;
    }
     //alert(url);
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null); 
}

// LoadModels(): loads all available models into the "ModelSelect" drop down list
function loadModels(tabId) 
{ 
   var returnVal;
   var firstSplit, secondSplit;
   var styleObject1 = document.getElementById('ModelDisplay' + tabId);
   var styleObject2 = document.getElementById('ResultDisplay'+ tabId);
   var tempModelSelect = 'ModelSelect' + tabId;

        returnVal = xmlHttp.responseText;
       // alert(returnVal);
        // NOTE: Remove drop down options, except "Select Model" 
        if(returnVal != "")
        {
           firstSplit = returnVal.split("^");
           
           document.form1[tempModelSelect].options.length = 1;

            for(i=0; i < firstSplit.length; i++)
            {     
              secondSplit = firstSplit[i].split("~"); // secondSplit[0]: KEY - secondSplit[1]: Title
              document.form1[tempModelSelect].options[i+1] = new Option(secondSplit[1],secondSplit[0])
            }  
            styleObject1.style.visibility = 'visible';
            styleObject2.style.visibility = 'visible';  
        }
        else // nothing was returned in the result set
        {
            styleObject1.style.visibility = 'hidden';
            styleObject2.style.visibility = 'visible';
            styleObject2.innerHTML = "No information is available for this particular category";
        }
}

// LoadMedia(): loads all of the result values into the "ResultDisplay" <div> area
function loadMedia(tabId) 
{ 
   return document.getElementById('ResultDisplay' + tabId).innerHTML = xmlHttp.responseText;
}

// GetSelectedValue(name): Helper function returning the selected value of the "CategorySelect" drop down
function getSelectedValue(name)
{
    var sel = document.getElementsByName(name)[0];
    var i = sel.options.selectedIndex;
    return i == -1? "": sel.options[i].value;
}

function getXmlHttpObject()
{
    var xmlHttp= null;
    
    try
      {
        // NOTE: Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
      }
    catch (e)
      {
      // NOTE: Internet Explorer
      try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    return xmlHttp;
}


