// JavaScript Document

var currentBoxInt = 1;
var currentBox = 1;
var parentSelName = [];



parentSelName[1] = 'Greece';

// select box
function GetXmlHttpObject(handler)
{
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}

function clearSelect(selectName){
	var theSel = document.getElementById(selectName);
	if (theSel){
		for(i=theSel.length-1; i>=0; i--)
			theSel.options[i] = null;
	}
}

 
function stateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {	
		var optcode = xmlHttp.responseText;
		var optcurr	= '';
		var disabledText = '';
		disabledText = lngArea.replace('{parent}',parentSelName[currentBox]);
		// Clear away the boxes that we don't use
		

		for (var i=currentBox;i<=maxLevels;i++){
			var selectName = selectId+''+i+'';
			clearSelect(selectName);
			document.getElementById(selectName).style.display = 'none';
		}

		

		document.getElementById(selectId+currentBox).options[document.getElementById(selectId+currentBox).length] = new Option(disabledText,0,1);
		//document.getElementById(selectId+currentBox).options[document.getElementById(selectId+currentBox).length-1].selected = true;
		

		while (optcode.indexOf('|')!=-1){
			optcurr = optcode.substr(0,optcode.indexOf('|'));
			optcode = optcode.substr(optcode.indexOf('|')+1);
			
			optId	= optcurr.substr(0,optcurr.indexOf('::'));
			optcurr = optcurr.substr(optcurr.indexOf('::')+2);
			optSel	= optcurr.substr(0,optcurr.indexOf('::'));
			optcurr = optcurr.substr(optcurr.indexOf('::')+2);
			optName = optcurr;
			document.getElementById(selectId+currentBox).options[document.getElementById(selectId+currentBox).length] = new Option(optName,optId);
			//alert(optName+', '+optId+', '+optSel);
		}	
		/*document.getElementById(selectId+currentBox).selectIndex =  0;	*/
		document.getElementById(selectId+currentBox).style.display = "";
    }
    else {
            //alert(xmlHttp.status);
    }
}
 
function sendHtmlRequest(url){
	xmlHttp		=	GetXmlHttpObject()
    if (xmlHttp==null){
        alert ("Browser does not support HTTP Request");
        return;
    }	
	xmlHttp.onreadystatechange=stateChanged;

    xmlHttp.open("GET",url,true) ;
    xmlHttp.send(null);

}

function openSubmenu(level){
	var parentId 	= document.getElementById(selectId+level).value;

	if (parentId == '0') return 0;
	var requestUrl 	= rootUrl + '?parentId='+parentId+'&lang='+lang+'&trash='+Math.random();
	
	currentBox		= level + 1;
	parentSelName[currentBox] = document.getElementById(selectId+level).options[document.getElementById(selectId+level).selectedIndex].text;
	sendHtmlRequest(requestUrl);
} 
 

