
var Lista_Region=new Array();

function MM_swapImgRestore() { //v2.0
  if (document.MM_swapImgData != null)
    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
}

function MM_preloadImages() { //v2.0
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}

function MM_swapImage() { //v2.0
  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  } }
  document.MM_swapImgData = swapArray; //used for restore
}

function MM_goToURL() { //v2.0
  for (var i=0; i< (MM_goToURL.arguments.length - 1); i+=2) //with arg pairs
    eval(MM_goToURL.arguments[i]+".location='"+MM_goToURL.arguments[i+1]+"'");
  document.MM_returnValue = false;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//************************************
function borra(SelectObj)
{
	var temp = SelectObj.options.length;
	for (var x=0;x <= temp ;x++)
	{
		SelectObj.options[temp-x]=null;
	};
}
//************************************
function getSelected(opt)
		{
           	var selected = new Array();      

            for (var intLoop = 0; intLoop < opt.length; intLoop++)
			{
               if ((opt[intLoop].selected) ||
                   (opt[intLoop].checked))
					{
                  index = selected.length;
                  selected[index] = new Object;
                  selected[index].value = opt[intLoop].value;
                  selected[index].index = intLoop;
               	}
            }
            return selected;
         }
//***********************************
function outputSelected(opt)
			{
            var sel = getSelected(opt);
            var strSel = "";
				for (var item in sel)
					strSel += sel[item].value;
					//alert(strSel);
			return strSel;
         	}

//***********************************
function outputSelected2(opt)
			{
            var sel = getSelected(opt);
            var strSel = "";
				for (var item in sel)
					strSel += sel[item].index;
			return strSel;
         	}


//************************************
function addNew(text, value,i,j)
{
	// Add a new option.
	var el = new Option(text,value);

	if (j == 1 )
           document.principal.ciudad.options[i] = el;
	else
           document.principal.comuna.options[i] = el;

}

//************************************
function addNew2(text, value,i,j)
{
	// Add a new option.
	var el = new Option(text,value);

	if (j == 1 )
           document.principal.region.options[i] = el;
	else
           document.principal.comuna.options[i] = el;

}

function replace(originalString,searchText,replaceText)
{ 
	var strLength = originalString.length; 
	var txtLength = searchText.length; 

	if ((strLength == 0) || (txtLength == 0)){
		return originalString; 
	}

	var i = originalString.indexOf(searchText);

	if ((!i) && (searchText != originalString.substring(0,txtLength))){
		return originalString; 
	} 

	if (i == -1){
		return originalString; 
	}

	var newstr = originalString.substring(0,i) + replaceText; 

	if (i+txtLength < strLength){
		newstr += replace(originalString.substring(i+txtLength,strLength),searchText,replaceText); 
	}

	return newstr;
} 


//*************************************
function mensaje(opt1,ver,idioma)
{
	var Lista_Nombres=new Array();
	var Lista_Nombres=new Array();

	var seleccion = outputSelected(opt1.options);


	//alert(idioma);

	document.principal.nueva_region.value = '0';
	//----------------------------------
	borra(document.principal.ciudad);
	//----------------------------------

	//----------------------------------
	if (seleccion == "0"){
			Lista_Nombres = Lista_Ciudad_Nom_0;
			Lista_Codigos = Lista_Ciudad_Nom_0;
        }
	//----------------------------------
	if (seleccion == "1"){
			Lista_Nombres = Lista_Ciudad_Nom_1;
			Lista_Codigos = Lista_Ciudad_Nom_1;
        }
	//----------------------------------
	if (seleccion == "2"){
			Lista_Nombres = Lista_Ciudad_Nom_2;
			Lista_Codigos = Lista_Ciudad_Nom_2;
        }
	//----------------------------------
	if (seleccion == "3"){
			Lista_Nombres = Lista_Ciudad_Nom_3;
			Lista_Codigos = Lista_Ciudad_Nom_3;
	}
	//----------------------------------
	if (seleccion == "4"){
			Lista_Nombres = Lista_Ciudad_Nom_4;
			Lista_Codigos = Lista_Ciudad_Nom_4;
	}
	//----------------------------------
	if (seleccion == "5"){
			Lista_Nombres = Lista_Ciudad_Nom_5;
			Lista_Codigos = Lista_Ciudad_Nom_5;
	}
	//----------------------------------
	if (seleccion == "6"){
			Lista_Nombres = Lista_Ciudad_Nom_6;
			Lista_Codigos = Lista_Ciudad_Nom_6;
	}
	//----------------------------------
	if (seleccion == "7"){
			Lista_Nombres = Lista_Ciudad_Nom_7;
			Lista_Codigos = Lista_Ciudad_Nom_7;
	}
	//----------------------------------
	if (seleccion == "8"){
			Lista_Nombres = Lista_Ciudad_Nom_8;
			Lista_Codigos = Lista_Ciudad_Nom_8;
	}
	//----------------------------------
	if (seleccion == "9"){
			Lista_Nombres = Lista_Ciudad_Nom_9;
			Lista_Codigos = Lista_Ciudad_Nom_9;
	}
	//----------------------------------
	if (seleccion == "10"){
			Lista_Nombres = Lista_Ciudad_Nom_10;
			Lista_Codigos = Lista_Ciudad_Nom_10;
	}
	//----------------------------------
	if (seleccion == "11"){
			Lista_Nombres = Lista_Ciudad_Nom_11;
			Lista_Codigos = Lista_Ciudad_Nom_11;
	}
	//----------------------------------
	if (seleccion == "12"){
			Lista_Nombres = Lista_Ciudad_Nom_12;
			Lista_Codigos = Lista_Ciudad_Nom_12;
	}
	//----------------------------------
	if (seleccion == "-1"){

			document.principal.nueva_region.value = '-1';
			Lista_Codigos[0] = "-1";
			Lista_Region[0]  = "-1";

			Lista_Nombres = Lista_Ciudad_Nom_Todas;
			Lista_Codigos = Lista_Ciudad_Nom_Todas;
			Lista_Region  = Lista_Region_Nom_Todas;

			var TAM=i, temp; 			
			for (i=2; i<TAM; i++)
				for (j=1 ; j<TAM-1; j++)
					if (Lista_Nombres[j] > Lista_Nombres[j+1]){
						temp = Lista_Nombres[j];
						Lista_Nombres[j] = Lista_Nombres[j+1];
						Lista_Nombres[j+1] = temp;
					
						temp = Lista_Codigos[j];
						Lista_Codigos[j] = Lista_Codigos[j+1];
						Lista_Codigos[j+1] = temp;
						
						temp = Lista_Region[j];
						Lista_Region[j] = Lista_Region[j+1];
						Lista_Region[j+1] = temp;
					}

	}
	//----------------------------------
	if (idioma != 1)
		Lista_Nombres[0] = "Todas";
	else
		Lista_Nombres[0] = "All";

	for (var x=0 ; x< Lista_Nombres.length ; x++)
		addNew(replace(Lista_Nombres[x],'Nz','Ñ'),Lista_Codigos[x],x,1); 
	document.principal.ciudad.options[0].selected = true;
}

function entrega_region(p)
{
	var region=0;		
	inc=0;
	p++;
	inc=inc+Lista_Ciudad_Nom_0.length; 
	if (p>=inc && p<inc+Lista_Ciudad_Nom_1.length) region=1; inc=inc+Lista_Ciudad_Nom_1.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_2.length) region=2; inc=inc+Lista_Ciudad_Nom_2.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_3.length) region=3; inc=inc+Lista_Ciudad_Nom_3.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_4.length) region=4; inc=inc+Lista_Ciudad_Nom_4.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_5.length) region=5; inc=inc+Lista_Ciudad_Nom_5.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_6.length) region=6; inc=inc+Lista_Ciudad_Nom_6.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_7.length) region=7; inc=inc+Lista_Ciudad_Nom_7.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_8.length) region=8; inc=inc+Lista_Ciudad_Nom_8.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_9.length) region=9; inc=inc+Lista_Ciudad_Nom_9.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_10.length) region=10; inc=inc+Lista_Ciudad_Nom_10.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_11.length) region=11; inc=inc+Lista_Ciudad_Nom_11.length-1; 	
	if (p>=inc && p<inc+Lista_Ciudad_Nom_12.length) region=12; inc=inc+Lista_Ciudad_Nom_12.length-1; 	
	return(region);
}

function mensaje2(opt1, ver, idioma)
{
	var seleccion = outputSelected(opt1.options);//trae valor
	var seleccion2 = outputSelected2(opt1.options);//trae indice

	nregion= Lista_Region[seleccion2];

	//alert(idioma);

	//----------------------------------
	borra(document.principal.region);
	//----------------------------------

	if (idioma != 1) { 
		var Lista_Nombres = new Array('Metropolitana               ','Primera','Segunda','Tercera','Cuarta','Quinta','Sexta','Séptima','Octava','Novena','Décima','Undécima','Duodécima','Todas');
		var Lista_Codigos = new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,-1);
	}
	else {
		var Lista_Nombres = new Array('Metropolitan               ','First','Second','Third','Fourth','Fifth','Sixth','Seventh','Eighth','Ninhth','Tenth','Eleventh','Twelfth','All');
		var Lista_Codigos = new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,-1);
	}
	
	for (var x=0 ; x< Lista_Nombres.length ; x++)
		addNew2(Lista_Nombres[x],Lista_Codigos[x],x,1); 

	if (document.principal.nueva_region.value != '-1') 
		document.principal.region.options[ver].selected = true;
	else 
		document.principal.region.options[nregion].selected = true;
}

//*************************************
function Actualiza_Comuna(Region, Ciudad, idioma)
{
	var Lista_Nombres=new Array();
	var Lista_Codigos=new Array();
	var Lista_CodCiud=new Array();
	var RegSel = outputSelected(Region.options);
	var CiudSel = outputSelected(Ciudad.options);

	var TodasArray = new Array();
	var CodigosArray = new Array;
	var CodiCiuArray = new Array;
	var ii=0;

	//----------------------------------
	borra(document.principal.comuna);
	//----------------------------------
/*
	if (RegSel == "0" && CiudSel == "1"){
			Lista_Nombres = Lista_Comuna_Nom;
			Lista_Codigos = Lista_Comuna_Nom;
        } else{
	   Lista_Nombres = TodasArray;
	   Lista_Codigos = CodigosArray;
	   Lista_CodCiud = CodiCiuArray;
	}
*/
	//----------------------------------
	switch(RegSel)
	{ 
		case "0":
			Lista_Nombres = Lista_Comuna_Nom_0;
			Lista_Codigos = Lista_Comuna_Nom_0;
		    Lista_CodCiud = Lista_ComCiu_Nom_0;
			break;
		case "1":
			Lista_Nombres = Lista_Comuna_Nom_1;
			Lista_Codigos = Lista_Comuna_Nom_1;
		    Lista_CodCiud = Lista_ComCiu_Nom_1;
			break;
		case "2":
			Lista_Nombres = Lista_Comuna_Nom_2;
			Lista_Codigos = Lista_Comuna_Nom_2;
		    Lista_CodCiud = Lista_ComCiu_Nom_2;
			break;
		case "3":
			Lista_Nombres = Lista_Comuna_Nom_3;
			Lista_Codigos = Lista_Comuna_Nom_3;
		    Lista_CodCiud = Lista_ComCiu_Nom_3;
			break;
		case "4":
			Lista_Nombres = Lista_Comuna_Nom_4;
			Lista_Codigos = Lista_Comuna_Nom_4;
		    Lista_CodCiud = Lista_ComCiu_Nom_4;
			break;
		case "5":
			Lista_Nombres = Lista_Comuna_Nom_5;
			Lista_Codigos = Lista_Comuna_Nom_5;
		    Lista_CodCiud = Lista_ComCiu_Nom_5;
			break;
		case "6":
			Lista_Nombres = Lista_Comuna_Nom_6;
			Lista_Codigos = Lista_Comuna_Nom_6;
		    Lista_CodCiud = Lista_ComCiu_Nom_6;
			break;
		case "7":
			Lista_Nombres = Lista_Comuna_Nom_7;
			Lista_Codigos = Lista_Comuna_Nom_7;
		    Lista_CodCiud = Lista_ComCiu_Nom_7;
			break;
		case "8":
			Lista_Nombres = Lista_Comuna_Nom_8;
			Lista_Codigos = Lista_Comuna_Nom_8;
		    Lista_CodCiud = Lista_ComCiu_Nom_8;
			break;
		case "9":
			Lista_Nombres = Lista_Comuna_Nom_9;
			Lista_Codigos = Lista_Comuna_Nom_9;
		    Lista_CodCiud = Lista_ComCiu_Nom_9;
			break;
		case "10":
			Lista_Nombres = Lista_Comuna_Nom_10;
			Lista_Codigos = Lista_Comuna_Nom_10;
		    Lista_CodCiud = Lista_ComCiu_Nom_10;
			break;
		case "11":
			Lista_Nombres = Lista_Comuna_Nom_11;
			Lista_Codigos = Lista_Comuna_Nom_11;
		    Lista_CodCiud = Lista_ComCiu_Nom_11;
			break;
		case "12":
			Lista_Nombres = Lista_Comuna_Nom_12;
			Lista_Codigos = Lista_Comuna_Nom_12;
		    Lista_CodCiud = Lista_ComCiu_Nom_12;
			break;
		case "-1":
			Lista_Nombres = TodasArray;
			Lista_Codigos = CodigosArray;
		    Lista_CodCiud = CodiCiuArray;
			break;
		default: 
			Lista_Nombres = TodasArray;
			Lista_Codigos = CodigosArray;
		    Lista_CodCiud = CodiCiuArray;
			break;
	}
	//----------------------------------
	if (idioma != 1) {
		Lista_Nombres[0] = "Todas";
		Lista_Codigos[0] = "-1";
	}	
	else {
		Lista_Nombres[0] = "All";
		Lista_Codigos[0] = "-1";
	} 
	Lista_CodCiud[0] = CiudSel;

	for (var x=0 ; x< Lista_Nombres.length ; x++)
	{
		if (CiudSel==Lista_CodCiud[x])
		{
			//addNew(replace(Lista_Nombres[x],'Nz','Ñ'),Lista_Codigos[x],x,0); 
			addNew(replace(Lista_Nombres[x],'Nz','Ñ'),Lista_Codigos[x],ii,0); 
			ii++;
		}
	}
	
	document.principal.comuna.options[0].selected = true;
}

