/**
 * @author florian.auer
 */

var is_ie = false;

// Browserhack - damn IE... THX to http://design-noir.de/webdev/JS/XMLHttpRequest-IE/
/*@cc_on
is_ie = true;
@if (@_win32 && @_jscript_version >= 5) {
    if (!window.XMLHttpRequest) {
        function XMLHttpRequest() {
            return new ActiveXObject('Microsoft.XMLHTTP')
        }
    }
}
@end
@*/

function changeCountrySelectBox( selectBoxObj )
{
    currentIndex	= selectBoxObj.selectedIndex;
    currentValue	= selectBoxObj.options[currentIndex].value;
    url				= '/index.php?pageID=mapping&land:output=xml&land:c=' + currentValue;

    request						= new XMLHttpRequest();
    request.onreadystatechange 	= setCountrySelectBox;

    request.open( 'GET', url, true );
    request.send( null );
}

function setCountrySelectBox()
{
    if ( request.readyState == 4 && request.status == 200 ) {
        var XMLdata				= request.responseXML;
        var continent			= XMLdata.getElementsByTagName('continent')[0];
        var countrySelectBox	= document.getElementById('countrySelectBox');

        deleteSelectBoxOptions( countrySelectBox, 1);

        for ( var i = 0; i < continent.childNodes.length; i++ ) {
            country 			= continent.childNodes[i];
            name				= country.getElementsByTagName('name').item(0).firstChild.data;
            id					= country.getElementsByTagName('id').item(0).firstChild.data;
            position			= i + 1;
            // Neues OPTION-Objekt generieren und anf?gen
            newOption							= new Option( name, id );
            countrySelectBox.options[position]	= newOption;
        }
    }
}

function deleteSelectBoxOptions( selectBox, start)
{
    if (!start) start = 0;
    for ( var i = selectBox.options.length-1; i > 0; i-- ) {
        selectBox.options[i] = null;
    }
}
