﻿ /****************************************************/
//This code is to hide/display the gemEwizard drop down selections

var timerColor = null;
var timerTone = null;
var timerSat = null;
var gobj = null;	
var currentDropDown = null;
    
function displayDropDown(dropDownID) 
// Displays the drop down and clears its timer  
{
    //alert(dropDownID);						    
    var dropdownList = document.getElementById(dropDownID);	    
    var typeNumber = getGemEType(dropDownID);
    
    clearTimerByType(typeNumber);    
    dropdownList.style.display = 'block';
}


function clearTimerByType(typeNumber)
// Clears the specified timer
{
    switch(typeNumber)
    {
        case 0:
            clearTimeout(timerColor);
            break;
        case 1:
            clearTimeout(timerTone);
            break;
        case 2:
            clearTimeout(timerSat);
            break;
    }	
}

function startHideTimer(objname)
// Starts the timer which triggers the hide drop down function
{
    var typeNumber = getGemEType(objname);
    switch(typeNumber)
    {
        case 0:
            timerColor = setTimeout('hideDropDown(\'' + objname + '\')',10);
            break;
        case 1:
            timerTone = setTimeout('hideDropDown(\'' + objname + '\')',10);
            break;
        case 2:
            timerSat = setTimeout('hideDropDown(\'' + objname + '\')',10);
            break;
    }	 
}

function hideDropDown(objname)
// Hides the drop down and clears the timer
{   
    var typeNumber = getGemEType(objname);    
    var obj = document.getElementById(objname);
    clearTimerByType(typeNumber);
    obj.style.display = 'none';
}

function getGemEType(dropDownID)
// Parses the drop down id and returns an integer
// 0 = Color, 1 = Tone, 2 = Saturation
{        
    var colorRegEx = /Color+/;        
    var colorMatch = colorRegEx.exec(dropDownID);
    var toneRegEx = /Tone+/;        
    var toneMatch = toneRegEx.exec(dropDownID);        

    if(colorMatch != null)
        return 0;           
    else if(toneMatch != null)        
        return 1;
    else
        return 2;
}


function setTextBoxValue( dropDownobj, txtBoxId)
// Copies the currently selected value from the drop down to the txt box
{
    var txtBox = document.getElementById(txtBoxId);       
    txtBox.value = dropDownobj[dropDownobj.selectedIndex].value;
}

function selectedIndexChanged( txtBoxId, dropDownID)
// Writes the current value of the drop down into the text box
// and puts focus on text box.  Also caused so validation to occur
{       
    var dropdownList = document.getElementById(dropDownID);
    var txtBox = document.getElementById(txtBoxId);       
    txtBox.value = dropdownList[dropdownList.selectedIndex].value;
    txtBox.focus();             
    verifyGemEWizardValue(txtBoxId, dropDownID);            
}

function setGemEErrorMessages(typeNumber,displayFlag)
// Displays or hides validation failed messages
{
    var label = null;
    switch(typeNumber)
    {
            case 0:
                label = document.getElementById("gemEColorError");       
                break;
            case 1:
                label = document.getElementById("gemEToneError");       
                break;
            case 2:
                label = document.getElementById("gemESaturationError");       
                break;                        
    }   
    if(displayFlag)        
        label.style.display = 'block';    
    else
        label.style.display = 'none';    
}

function verifyGemEWizardValue(txtBoxId, dropDownID)
// Verfies that the value in the text box is valid by making sure
// it appears in the drop down list
{        
    var txtBox = document.getElementById(txtBoxId);       
    var dropdownList = document.getElementById(dropDownID); 
    var displayError = true;

    var txtValue =  txtBox.value;
    var numOfOptions = dropdownList.length;
    var i = 0;        

    for(i=0; i < numOfOptions; i++)
    {
       if( txtValue == dropdownList[i].value)
       {
          displayError = false;
          break;
       }
    }
    var typeNumber = getGemEType(dropDownID);
    setGemEErrorMessages(typeNumber,displayError);
}