/*
 *
 * GoldenPEM - Pais / Estado / Município
 * Desenvolvedor: Fernando Arroyo
 * GoldenLight [ fernando.arroyo@goldenlight.biz ]
 * 06.08.2009
 *
 */

	var GoldenPEM=function(Parametros){
		
		/*
		 * Parametros - GoldenPEM
		 * 
		 * ObjPais
		 * ObjEstado
		 * ObjMunicípio
		 * Caminho
		 * 
		 */
		
		this.Alterar=function(Campo){
			switch(Campo){
				case "Pais":
					$.ajax({
		                type:"POST",
		                url:Parametros.Caminho+"/inc2/popups.php",
		                data:"pagina=GoldenPEM&Campo=Pais&Pais="+document.getElementById(Parametros.ObjPais).value,
						dataType:"script",
		                success:function(){
							while(document.getElementById(Parametros.ObjEstado).options.length>0){
								document.getElementById(Parametros.ObjEstado).remove(0);
							}
							while(document.getElementById(Parametros.ObjMunicipio).options.length>0){
								document.getElementById(Parametros.ObjMunicipio).remove(0);
							}
							xValSelect=0;
							while(document.getElementById(Parametros.ObjEstado).options.length<ValSelect.length){
								objValSelect=document.createElement("option");
								objValSelect.setAttribute("value",ValSelect[xValSelect][0]);
								objValSelect.text=ValSelect[xValSelect][1];
							    try {
									document.getElementById(Parametros.ObjEstado).add(objValSelect,document.getElementById(Parametros.ObjEstado).options[document.getElementById(Parametros.ObjEstado).options.length]);
							    }
							    catch(ex) {
									document.getElementById(Parametros.ObjEstado).add(objValSelect,document.getElementById(Parametros.ObjEstado).options.length);
							    }
								xValSelect++;
							}
						}
					});
				break;
				case "Estado":
					$.ajax({
		                type:"POST",
		                url:Parametros.Caminho+"/inc2/popups.php",
		                data:"pagina=GoldenPEM&Campo=Estado&Estado="+document.getElementById(Parametros.ObjEstado).value,
						dataType:"script",
		                success:function(){
							while(document.getElementById(Parametros.ObjMunicipio).options.length>0){
								document.getElementById(Parametros.ObjMunicipio).remove(0);
							}
							xValSelect=0;
							while(document.getElementById(Parametros.ObjMunicipio).options.length<ValSelect.length){
								objValSelect=document.createElement("option");
								objValSelect.setAttribute("value",ValSelect[xValSelect][0]);
								objValSelect.text=ValSelect[xValSelect][1];
							    try {
									document.getElementById(Parametros.ObjMunicipio).add(objValSelect,document.getElementById(Parametros.ObjMunicipio).options[document.getElementById(Parametros.ObjMunicipio).options.length]);
							    }
							    catch(ex) {
									document.getElementById(Parametros.ObjMunicipio).add(objValSelect,document.getElementById(Parametros.ObjMunicipio).options.length);
							    }
								xValSelect++;
							}
						}
					});
				break;
			}
		}
		
	}