   	var comboid;
	var	sectionid;
	var sections;
   
	function cleanAndHide(secs) {
   		// oculto las secciones que no corresponden
		for (i=0; i<secs.length; i++) {
			if (document.getElementById(secs[i]+"div") != null){
				document.getElementById(secs[i]+"div").style.display='none';
			}
		}
		// borro las options de los combos que se ocultaron
		for (i=0; i<secs.length; i++) {
				if (document.getElementById(secs[i]+"div") != null){
					for (j = document.getElementById(secs[i]).options.length - 1; j>=1; j--) {
						document.getElementById(secs[i]).remove(j);
					}
				}
			}
   	}
   
  	function mostrar(sResult, oParam) {
		eval(sResult);
		cleanAndHide(sections);	
		sel = document.getElementById(comboid);
		if (childs.length>0) {
			document.getElementById(sectionid).style.display='';
		  	for (i=0; i<childs.length; i++) {
				sel.options[i+1] = childs[i];
			}
		} 
	}
   
    function findChild(parent, target, sectionsToHide) {
	    comboid = target; 
	    sectionid = target+"div";
	    sections = sectionsToHide;
  	    parentid = document.getElementById(parent).value;
  	    if (parentid!="") {
            jQuery.ajax({
                type: "GET",
                url:locationURL,
                data: 'parent='+parentid,
                async:false,
                success: function(datos){
                    mostrar(datos,null);
                }
		    });
 	    }
    }
   	
   	function findChildParameters(parent, target, sectionsToHide) {
   		comboid = target; 
   		sectionid = target+"div";
   		sections = sectionsToHide;
   	  	parentid = document.getElementById(parent).value;
   	  	if (parentid!="") {
            var sURL = locationURL + '&parent='+parentid;
            sData = sURL.split('?');
            jQuery.ajax({
                type: "GET",
                url: sData[0],
                data: sData[1],
                async:false,
                success: function(datos){
                    mostrar(datos,null);
                }
            });
        }
   	}   	
   	function setState() {
		provincia = document.getElementById('provincia');
		if (provincia.selectedIndex>0) 
			document.getElementById('state').value = provincia.options[provincia.selectedIndex].text;
		else
			document.getElementById('state').value = '';
	}
   	
   	function filterByCountry(val, secciones) {
		country = this.document.getElementById('country');
		if (country.options[country.options.selectedIndex].value != val) 
			cleanAndHide(secciones);
		else // si es Argentina
			findChildParameters('location1', 'location2', new Array('location2','location3'));
	}
	
	function setChildLabel(objName, objLabel, targetLabel, textPartido) {
		p1 = document.getElementById(objName);
		if (document.getElementById(targetLabel)!= null){
			document.getElementById(targetLabel).innerHTML ='';
			var newDiv=document.createElement('div');
			if (parseLocationID(p1.options[p1.options.selectedIndex].value)){
					newDiv.innerHTML=textPartido;
			}else{
					newDiv.innerHTML=objLabel;
			}
			document.getElementById(targetLabel).appendChild(newDiv.childNodes[0]);
		}
	}
   	function otroVisibility(obj1, obj2){
   	    obj1 = document.getElementById(obj1);
   	    obj2 = document.getElementById(obj2);
	    if ((obj1.selectedIndex == (obj1.length -1))){
	        obj2.style.display='';
	        return false;
	    }
	    obj2.style.display='none';
	    return true;
	}
    function cleanAndHideLocation(secs) {
        obj = null;
		for (i=0; i<secs.length; i++) {
		    obj = document.getElementById(secs[i]+'div');
			if( obj != null){
			        resetCombo(secs[i]);
				    obj.style.display ='none';
			}
		}
    }
    function resetCombo(id){
        document.getElementById(id).value = '';
    }
    function hideDependingParentLocation(parent, child){
        if (document.getElementById(parent).selectedIndex == 0){
            document.getElementById(child).style.display ='none';
        }
    }
    function selectionDependingParentLocation(accion){
        var location1 = document.getElementById('location1').options[document.getElementById('location1').selectedIndex].value;
	    var location2 = document.getElementById('location2');
	    
	    if(parseLocationID(location1)){
	        if(accion){
	            findChildParameters('location2', 'location3', new Array('location3','localidad2'));
	        }else{
	            if(document.getElementById('location2').selectedIndex>0){
	                document.getElementById('location3div').style.display='';
	            }
	        }
	        if(document.getElementById('validateLocationPair')){
	            document.getElementById('validateLocationPair').value='location3';
	        }
	        otroVisibility('location3', 'citydiv');
	    }else{
	        if (!otroVisibility('location2', 'citydiv')){
	            cleanAndHideLocation(new Array('location3'));
	        }
	        if(document.getElementById('validateLocationPair')){
	            document.getElementById('validateLocationPair').value='location2';
	        }
	    }
    }
    function checkLocations(countrySystem){
	    var item = '';
	    country = document.getElementById('country').value;
	    location1 = document.getElementById('location1').value;
	    location2 = document.getElementById('location2').value;
	    location3 = document.getElementById('location3').value;
	    city = document.getElementById('city').value.toLowerCase();
	    
	    if (country == ''){
	        item = '  País \n';
	    }else{
            if(country ==countrySystem){
			    if (location1 == ''){
				    item = '  Provincia \n';
			    }else{
                    if(parseLocationID(location1)){
	                    valueValidate = location3 + city;
	                }else{
	                    valueValidate = location2 + city;
	                }
                    if(valueValidate.replace(/^\s*|\s*$/g,"") == ''){
                        item = '  Ciudad \n';
                    }
                }
	        }
	    }
	    return item;
	}
	
	function parseLocationID(selectLocationID){
	    var arrLocationID = sReturnsListLocationID.split(",");
	    var bCheck = false;
	    	    
	    for(var index in arrLocationID){
	        if (arrLocationID[index] == selectLocationID){
	            bCheck = true;
	        }
	    }
	    return bCheck;
	}
