
var _currentOpenedComboDiv;
var _useOnClick;

document.onclick = comboHideOpenComboOnDocumentClick;

function comboHideOpenComboOnDocumentClick(name)
{
      if(_useOnClick == true)
      {
          if(_currentOpenedComboDiv != null)
          {
            _currentOpenedComboDiv.style.visibility="hidden";
            _currentOpenedComboDiv = null;
          }
      }
      _useOnClick = true;
} 


function cancelOnClick(element)
{
	if(window.event) 
	{
	    window.event.cancelBubble= true;
	}
	else
	{
	    if (element.stopPropagation) element.stopPropagation();
	}
}

function getPxValue(value)
{
    var     string = new String(value); 
            string = string.replace("px","");
    var     number = parseInt(string);
    return  number;
}

function comboPopup(e,name)
{   
    _useOnClick = false;
    var _comboDiv = document.getElementById("comboDiv"   + name);
    if(_comboDiv ==_currentOpenedComboDiv)
    {
        comboHide(name);
    }
    else
    {
        if (IsIE(7))
        {
            comboPopupIE6(e,name);
        }
        else
        {
            comboPopupIE7(e,name);
        }
    }
} 



// IE7 & Opera & FF & Safari
function comboPopupIE7(element,name) 
{
    var base_o;
    var x;
    var y;
    var comboDiv    = document.getElementById("comboDiv"   + name);
    var comboInput  = document.getElementById("comboInput" + name); 
    var comboList   = document.getElementById("comboList"  + name);       

    if(_currentOpenedComboDiv != comboDiv) 
    {
      if(_currentOpenedComboDiv != null)
      {
        _currentOpenedComboDiv.style.visibility="hidden";
      }
      _currentOpenedComboDiv = null;
    }
    
    y = comboInput.offsetHeight;
    x = 0;           
    

    var e = comboInput;
    while (e)
    {
        x += e.offsetLeft;
        y += e.offsetTop;
        e = e.offsetParent;
    } 

    var p1 = getPxValue(comboList.offsetWidth);
    var p2 = getPxValue(comboInput.offsetWidth); 
    
    comboDiv.style.visibility = "visible"; 
    comboDiv.style.top        = y  + 1 + "px";
    comboDiv.style.left       = x + "px";

    if (p1 <= p2)
    {
        comboDiv.style.width = (p2 + 14) + "px";
    }
    _currentOpenedComboDiv = comboDiv; 
}




// IE6 Only
function comboPopupIE6(element,name) 
{
    var base_o;
    var x;
    var y;
    var comboDiv    = document.getElementById("comboDiv"   + name);
    var comboInput  = document.getElementById("comboInput" + name); 
    var comboList   = document.getElementById("comboList"  + name);       


    if(comboDiv.style.visibility=="visible")
    {
      return;
    }

    if(_currentOpenedComboDiv != comboDiv) 
    {
      if(_currentOpenedComboDiv != null)
      {
        _currentOpenedComboDiv.style.visibility="hidden";
      }
      _currentOpenedComboDiv = null;
    }
    


    
    y = comboInput.offsetHeight;
    x = 0;           

    var e = comboInput;
    while (e)
    {
        x += e.offsetLeft;
        y += e.offsetTop;
        e = e.offsetParent;
    } 
    comboDiv.style.visibility = "visible";
    
    var p1 = getPxValue(comboList.clientWidth);
    var p2 = getPxValue(comboInput.clientWidth); 
    var p3 = getPxValue(comboList.offsetHeight);
 
    //comboDiv.style.visibility = "visible";
    comboDiv.style.top        = y  + 1 + "px";
    comboDiv.style.left       = x + "px";

    
    if (p1 <= p2)
    {
        comboDiv.style.width = (p2 + 14) + "px";
    }
    else
    {
        comboDiv.style.width = p1 + "px";     
    }

    if(p3 >= 250)
    {
      comboDiv.style.height = 250 + "px"; 
    }
     _currentOpenedComboDiv = comboDiv;
}

function comboHide(name)
{
      var comboDiv = document.getElementById("comboDiv"   + name); 
      comboDiv.style.visibility="hidden";
      _currentOpenedComboDiv = null;
}

function comboShow(name)
{

    var comboDiv = document.getElementById("comboDiv"   + name); 
     if(comboDiv.style.visibility=="visible")
     {

       return;
     }
      comboDiv.style.visibility="visible";
      _currentOpenedComboDiv = comboDiv;      
} 

function comboSetValue(element,name) 
{
    var comboDiv    = document.getElementById("comboDiv"   + name);
    var comboInupt  = document.getElementById("comboInput" + name);
    var comboHidden = document.getElementById(name);

    comboInupt.value  = element.getAttribute("valueName");
    comboHidden.value = element.getAttribute("valueID");
    comboHidden.onchange();
    comboDiv.style.visibility="hidden";
}

function elementOnMouseOver(e)
{
    e.className="comboover";
}
function elementOnMouseOut(e)
{
    e.className="comboout";
}