function validacion_formulario()
{
		var nombre=document.getElementById('texto').value;
		if(nombre=='dfd')
		{
			var msg_error="Faltan campos por completar: test, asdas,asd ,asd ,asd ,asd";
			
			alert(msg_error);
		}
		else
		document.form_reg_usuario.submit(); 
}
function check_formpublic1()
{
	$k = jQuery.noConflict();			
	var check;
	$k("#formulario fieldset .columns span input[type=radio][name=tipoUbica]:checked").each(function(){
		check = $k(this).val();
	});	
	msg="Los siguientes campos, son obligatorios:\n";
	p=0;
	if(document.getElementById('titulo').value=="")
	{
		p=1;
		msg = msg+"- Titulo\n";
	}
	if(document.getElementById('tipo_propiedad').value < 1)
	{
		p=1;
		msg = msg+"- Tipo Propiedad \n";
	}
	if(document.getElementById('region').value < 1)
	{
		p=1;
		msg = msg+"- Region \n";
	}
	if(document.getElementById('comuna').value < 1)
	{
		p=1;
		msg = msg+"- Comuna \n";
	}
	if(check == 'exacta'){	
		if(document.getElementById('direccion').value < 1)
		{
			p=1;
			msg = msg+"- Direccion \n";
		}	
		if(document.getElementById('numero').value =="0" || document.getElementById('numero').value=="Nº")
		{
			p=1;
			msg = msg+"- Numero \n";
		}
	}else{
		if(document.getElementById('ubicaProyecto').value < 1)
		{
			p=1;
			msg = msg+"- Ubicacion \n";
		}
	}
	if(document.getElementById('cod_p').value =="" || !/^([0-9])*$/.test(document.getElementById('cod_p').value))
	{
		p=1;
		msg = msg+"- Codigo Pais";
		if(!/^([0-9])*$/.test(document.getElementById('cod_p').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}
	if(document.getElementById('cod_c').value =="" || document.getElementById('cod_c').value=="02/09" || !/^([0-9])*$/.test(document.getElementById('cod_c').value))
	{
		p=1;
		msg = msg+"- Codigo Ciudad";
		if(!/^([0-9])*$/.test(document.getElementById('cod_c').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}
	if(document.getElementById('telef').value =="" || document.getElementById('telef').value =="5555555" || !/^([0-9])*$/.test(document.getElementById('telef').value))
	{
		p=1;
		msg = msg+"- Telefono Contacto";
		if(!/^([0-9])*$/.test(document.getElementById('telef').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}	
	if(p==1)
		alert(msg);	
	else
		document.form_public1.submit();	
}

function check_formpublic2()
{
	msg="Los siguientes campos, son obligatorios:\n";
	p=0;
	
	if(document.getElementById('met2c').value =="" || document.getElementById('met2c').value=="m²" || !/^([0-9])*$/.test(document.getElementById('met2c').value))
	{
		p=1;
		msg = msg+"- Metros Cuadrados";
		if(!/^([0-9])*$/.test(document.getElementById('met2c').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}
	
	if(document.getElementById('hvisit').value =="" || document.getElementById('hvisit').value=="Ejemplo: Lun-Vier 16 a 19 horas")
	{
		p=1;
		msg = msg+"- Horario de visita \n";
	}
	if(document.getElementById('precio').value =="" || !/^([0-9])*$/.test(document.getElementById('precio').value))
	{
		p=1;
		msg = msg+"- Precio";
		if(!/^([0-9])*$/.test(document.getElementById('precio').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}
	if(document.getElementById('descrip').value =="")
	{
		p=1;
		msg = msg+"- Descripcion de la Propiedad \n";		
	}
	
	if(p==1)
		alert(msg);	
	else
		document.form_publi2.submit();	
}
function check_formpublic2B()
{
	

		msg="Los siguientes campos, son obligatorios:\n";
	p=0;
		if(document.getElementById('met2c').value=="m²" || !/^([0-9])*$/.test(document.getElementById('met2c').value))
	{
		p=1;
		msg = msg+"- Metros cuadrados construidos";
		if(!/^([0-9])*$/.test(document.getElementById('met2c').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}
	
	if(document.getElementById('met2').value =="" || document.getElementById('met2').value=="m²" || !/^([0-9])*$/.test(document.getElementById('met2').value))
	{
		p=1;
		msg = msg+"- Metros cuadrados terreno";
		if(!/^([0-9])*$/.test(document.getElementById('met2').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}
	
	if(document.getElementById('hvisit').value =="" || document.getElementById('hvisit').value=="Ejemplo: Lun-Vier 16 a 19 horas")
	{
		p=1;
		msg = msg+"- Horario de visita \n";
	}
	if(document.getElementById('precio').value =="" || !/^([0-9])*$/.test(document.getElementById('precio').value))
	{
		p=1;
		msg = msg+"- Precio";
		if(!/^([0-9])*$/.test(document.getElementById('precio').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}
	if(document.getElementById('descrip').value =="")
	{
		p=1;
		msg = msg+"- Descripcion de la Propiedad \n";		
	}
	
	if(p==1)
		alert(msg);	
	else
		document.form_publi2.submit();
}	
function cargar_cajas()
{	
	num_cajas=document.getElementById('num2').value;
	cargaXML("subida_archivo/subir_arch.php?num_cajas="+num_cajas,"sub_img");
	//document.getElementById("ini").style.visibility="hidden";
}

function cargar_cajas2()
{	
	num_cajas=document.getElementById('num').value;
	//alert(num_cajas);
	document.getElementById('num').value=num_cajas+1;
	cargaXML("subida_archivo/agregar_caja.php?cont="+num_cajas,"div_"+num_cajas);
	//document.getElementById("ini").style.visibility="hidden";
}
function validaPass(){	
	var ok;
	ok = true;
	if(ok) ok = isAlphanumeric(document.getElementById("oldContrasena"),'Contrase\u00F1a Actual',"ok");	
	if(ok) ok = isAlphanumeric(document.getElementById("newContrasena"),'Contrase\u00F1a Nueva',"ok");
	if(ok) ok = isAlphanumeric(document.getElementById("repetirPass"),'Confirmar Contrase\u00F1a',"ok");
	
	if(ok){
		if(isAlphanumeric(document.getElementById("repetirPass"),'Confirmar Contrase\u00F1a',"ok")){			
			var ret = comparaPassword(document.getElementById("newContrasena"), document.getElementById("repetirPass"),'Contrase\u00F1a',10);
			ok = ret;
		}else{			
			ok = false;
		}
		
	}
	
	//if (ok) document.form_.submit();
	//if (ok) alert("enviar");
	if (ok) location.href="accion_pass.php?oldContrasena="+encode64(document.getElementById("oldContrasena").value)+"&newContrasena="+encode64(document.getElementById("newContrasena").value)+"&repetirPass="+encode64(document.getElementById("newContrasena").value);
}
/*
function alerta(obj,valor){
	if(valor == false){
		obj.css("background-color","red");
	}else{
		obj.css("background-color","white");
	}
}
*/

function alerta(texto,titulo,obj,valor){
	
}
function validaRegistro(accion){		
		
	    var ok;
        var flag = 0;
		var rutValida;
        ok = true;
		var mensaje;		
		if(ok){//valida RUT
			if(!$k(".columns span").is("[id='rut_inmo']")){
				if(accion == 'crear'){
					if($k("#rut").val() == ''){
						$k("#rut").focus();	
						$k("#rut").addClass('ui-state-error');
						tips = $k("#validateTips,#validateReg");
						updateTips("Debe ingresar 'R.U.T.'");					
						ok = false;				
					}else{
						var rutValida = Rut($k("#rut").val());									
						if(rutValida == false){
							ok = false;					
							$k("#rut").focus();
							$k("#rut").addClass('ui-state-error');		
							tips = $k("#validateTips,#validateReg");
							updateTips("El valor ingresado no corresponde a un 'R.U.T.' v\u00E1lido");	
						}else{
							ok = true;
							if(ok){
								$k.ajax({
									url: "validaRut.php",
									type: "GET",
									data: "rut="+$k("#rut").val(),
									async:false,										        		        		
									success: function(datos){				
										if(jQuery.trim(datos) != ''){
											tips = $k("#validateTips,#validateReg");							
											updateTips(datos);
											$k("#rut").addClass('ui-state-error');
											$k("#rut").focus();									
											ok=false;
										}else{
											ok=true;
											$k("#rut").removeClass("ui-state-error")
												.addClass("ui-state-active");			
										}										
									}
								});
							}
						}	
					}
				}else if(accion == 'editar'){
					var check="";
					$k(".columns span input[type=text][id=rut]").each(function(){
						check += "existe";
					});				
					if(check == 'existe'){
						if($k("#rut").val() == ''){				
							$k("#rut").focus();	
							$k("#rut").addClass('ui-state-error');
							tips = $k("#validateTips,#validateReg");
							updateTips("Debe ingresar 'R.U.T.'");					
							ok = false;				
						}else{
							var rutValida = Rut($k("#rut").val());				
							if(rutValida == false){					
								ok = false;					
								$k("#rut").focus();
								$k("#rut").addClass('ui-state-error');		
								tips = $k("#validateTips,#validateReg");
								updateTips("El valor ingresado no corresponde a un 'R.U.T.' v\u00E1lido");	
							}else{
								ok = true;
								if(ok){
									$k.ajax({
										url: "validaRut.php",
										type: "GET",
										data: "rut="+$k("#rut").val(),
										async:false,										        		        		
										success: function(datos){				
											if(datos != ''){
												tips = $k("#validateTips,#validateReg");							
												updateTips(datos);
												$k("#rut").addClass('ui-state-error');
												$k("#rut").focus();									
												ok=false;
											}else{
												ok=true;
												$k("#rut").removeClass("ui-state-error")
													.addClass("ui-state-active");			
											}										
										}
									});
								}
							}	
						}
					}
				}
			}			
		}
						
		if(ok){//valida Nombre
			ok = isAlphabeticv2($k("#nombrePri"),'Nombre',"ok");
			if(ok){
				$k("#nombrePri").removeClass("ui-state-error")
							.addClass("ui-state-active");
			}
		}
		if(ok){//valida Apellido
			ok = isAlphabeticv2($k("#paterno"),'Apellido',"ok");
			if(ok){
				$k("#paterno").removeClass("ui-state-error")
							.addClass("ui-state-active");
			}
		}
										        
        if (ok) {//valida Sexo
            for (i = 0; i < document.formReg.sexo.length; i++) {
                if (flag == 0) {
                    if (document.formReg.sexo[i].checked) {
                        flag = 1;
                    }
                    else {
                        flag = 0;
                    }
                }
            }
            if (flag == 0) {                
                document.formReg.sexo[0].focus();
                ok = false;
				tips = $k("#validateTips,#validateReg");
				updateTips("Debe seleccionar Sexo");				
            }			
        }
					 
		if($k("#Pchile").is(":checked")){       
		    if (ok) {//valida Region
		        if ($k("#region").val() == "0") {		            
		            ok = false;
					$k("#region").focus();
					tips = $k("#validateTips,#validateReg");
					updateTips("Debe seleccionar Regi\u00F3n");									
		        }
		    }		
		    if (ok) {//valida Ciudad
		        if ($k("#provinci").val() == "0") {		            
		            ok = false;
					$k("#provinci").focus();
					tips = $k("#validateTips,#validateReg");
					updateTips("Debe seleccionar Ciudad");					
		        }
		    }
				
		    if (ok) {//valida Comuna
		        if ($k("#comuna").val() == "0") {		            
		            ok = false;
					$k("#comuna").focus();
					tips = $k("#validateTips,#validateReg");
					updateTips("Debe seleccionar Comuna");					
		        }
		    }
			/*if (ok){//valida codigo telefono<<--inactivo
				ok = validaPhone(document.getElementById("codPais"),'C\u00F3digo de Pa\u00EDs',"ok");
			}*/								
			if(ok){//valida cod Ciudad telefono
				ok = validaPhonev2($k("#codCiudad"),'C\u00F3digo de Ciudad',"ok");			
				if(ok){
					$k("#codCiudad").removeClass("ui-state-error")
								.addClass("ui-state-active");
				}
			}				
			if (ok){//valida telefono			
				if($k("#telefono").val() == '5555555'){				
					//alert("Debe ingresar Tel\u00e9fono");
					ok = false;	
					$k("#telefono").focus();
					tips = $k("#validateTips,#validateReg");
					updateTips("Debe ingresar Tel\u00e9fono");
					//alerta("Debe ingresar Tel\u00e9fono",'Alerta',$k("#telefono"),ok);	
					//$k("#telefono").focus();
					//$k("#telefono").value="";
				}else{				
				 	ok = validaPhonev2($k("#telefono"),'Tel\u00e9fono',"ok");			 	
					if(ok){
						$k("#telefono").removeClass("ui-state-error")
								.addClass("ui-state-active");
					}	
				}
			}
			/*no obligatorio
			if (ok) ok = validaPhone(document.getElementById("prefijo"),'Prefijo Celular',"nok");
			if (ok) ok = validaPhone(document.getElementById("celular"),'N\u00FAmero Celular',"nok");
			*/			
		}
		if($k("#Potro").is(":checked")){
			if(ok){//valida OtroPais
				ok = isAlphabeticv2($k("#paisExt"),'Nombre de pa\u00EDs',"ok");
				if(ok){
					$k("#paisExt").removeClass("ui-state-error")
							.addClass("ui-state-active");
				}
			}
			if(ok){//valida OtroRegion
				ok = isAlphabeticv2($k("#otraRegion"),'Ciudad',"ok");
				if(ok){
					$k("#otraRegion").removeClass("ui-state-error")
								.addClass("ui-state-active");
				}
			}				
        }		
		
		
		if(accion == 'crear' || accion == 'crear_us'){//valida mail			
			if (ok) {
	            if ((validaRequeridov2($k("#email"), 'E-mail'))) {                
	                var mail = $k("#email").val();                
	                if (validaEmailStrv2(mail, "mail")) {
	                    ok = true;						
						$k("#email").removeClass("ui-state-error")
							.addClass("ui-state-active");
	                }
	                else {
	                    ok = false; 
						//alerta("'" + mail + "' debe ser de la forma usuario@host.dominio",'Alerta',$k("#email"),false);                   
						$k("#email").focus();	
						$k("#email").addClass('ui-state-error');
						tips = $k("#validateTips,#validateReg");
						updateTips("'" + mail + "' debe ser de la forma usuario@host.dominio");					
	                }
	            }
	            else {
	                ok = false;
					$k("#email").focus();	
					$k("#email").addClass('ui-state-error');
					tips = $k("#validateTips,#validateReg");
					updateTips("Debe ingresar E-mail");					
	            }
	        }
	    }
		   
		if(accion == 'crear'){	//valida usuario			
			if(ok){ 
				ok = isAlphanumericv2($k("#usuario"),'Nombre de Usuario',"ok");
				if(ok){
					$k("#usuario").removeClass("ui-state-error")
								.addClass("ui-state-active");
				}
			}			
			if(ok){
				ok = isAlphanumericv2($k("#contrasena"),'Contrase\u00F1a',"ok");	
				if(ok){
					$k("#contrasena").removeClass("ui-state-error")
								.addClass("ui-state-active");
				}
			}			
			if(ok){
				if(isAlphanumericv2($k("#repetir"),'Confirmar Contrase\u00F1a',"ok")){			
					var ret = comparaPasswordv2($k("#contrasena"), $k("#repetir"),'Contrase\u00F1a',10);
					ok = ret;
					if(ok){
						$k("#repetir").removeClass("ui-state-error")
								.addClass("ui-state-active");
					}
				}else{			
					ok = false;
				}
				
			}	
		}
		
		
	    if(accion == 'crear_us'){	//valida usuario
			if(ok) {
				ok = isAlphanumericv2($k("#usuario"),'Nombre de Usuario',"ok");	
				if(ok){
					$k("#usuario").removeClass("ui-state-error")
								.addClass("ui-state-active");
				}
			}
			if(ok){ 
				ok = isAlphanumericv2($k("#contrasena"),'Contrase\u00F1a',"ok");
				if(ok){
					$k("#contrasena").removeClass("ui-state-error")
								.addClass("ui-state-active");
				}
			}
			if(ok){
				if(isAlphanumericv2($k("#repetir"),'Confirmar Contrase\u00F1a',"ok")){			
					var ret = comparaPasswordv2($k("#contrasena"), $k("#repetir"),'Contrase\u00F1a',10);
					ok = ret;
					if(ok){
						$k("#repetir").removeClass("ui-state-error")
								.addClass("ui-state-active");
					}
				}else{			
					ok = false;
				}
			}	
		}		
		if (ok){ //valida codigo
			ok = validaRequeridov2($k("#codigo"),'C\u00F3digo Verificaci\u00F3n');
			if(ok){				
				//var respuesta = $k.load("validaCodigo.php?codigo="+$k("#codigo").val());				
				$k.ajax({
					url: "validaCodigo.php",
					type: "GET",
					data: "codigo="+$k("#codigo").val(),
					async:false,										        		        		
					success: function(datos){
						if(datos != ''){
							tips = $k("#validateTips,#validateReg");							
							updateTips(datos);
							$k("#codigo").addClass('ui-state-error');
							$k("#codigo").focus();							
							$k("#codigo").val("");
							ok=false;
						}else{
							ok=true;
							$k("#codigo").removeClass("ui-state-error")
								.addClass("ui-state-active");			
						}		
					}
				});
			}
		}		
		if(ok){//valida acepto
			if(!$k("#acepto").is(":checked")){				
				ok = false;
				$k("#acepto").focus();
				$k("#acepto").addClass('ui-state-error');		
				tips = $k("#validateTips,#validateReg");
				updateTips("Para continuar debe aceptar Condiciones");
			}
		}
				
	/*
	if (ok) document.formReg.submit();
	*/
	if (ok){
		//alert("enviar");
		$k("#validateTips").text("");
		$k("#validateReg").text("");		
		document.formReg.submit();
	}	
}
function validaNoticia(accion){						
	var ok;
    var flag = 0;
    ok = true;        
    if(ok) ok = validaRequerido(document.getElementById("titulo"),'Titulo');        
    //if(ok) ok = isAlphabetic(document.getElementById("fuente"),'Fuente',"ok");
    if(ok) ok = validaRequerido(document.getElementById("bajada"),'Bajada');    
	if (ok) document.formReg.submit();
	//if (ok) alert("enviar");
}
function validaInmo(accion){		
	    var ok;
        var flag = 0;
        ok = true;        
        
        if (ok) {
            if (document.getElementById("tipoUsuario").value == "0") {
                alert("Debe seleccionar un Tipo de Usuario");
                ok = false;
                document.getElementById("tipoUsuario").focus();
            }
        }
        if(ok) ok = isAlphabetic(document.getElementById("nombreCorre"),'Nombre',"ok");
        if (ok) {
            if (document.getElementById("region").value == "0") {
                alert("Debe seleccionar Regi\u00F3n");
                ok = false;
                document.getElementById("region").focus();
            }
        }
        if (ok) {
            if (document.getElementById("comuna").value == "0") {
                alert("Debe seleccionar Comuna");
                ok = false;
                document.getElementById("comuna").focus();
            }
        } 
        if (ok) {
            if (document.getElementById("comuna").value == "0") {
                alert("Debe seleccionar Comuna");
                ok = false;
                document.getElementById("comuna").focus();
            }
        }
        if (ok) {
            if (document.getElementById("direccion").value == "0") {
                alert("Debe seleccionar Direccion");
                ok = false;
                document.getElementById("direccion").focus();
            }
        }  	
        if (ok) {
            if (document.getElementById("numero").value == "0") {
                alert("Debe seleccionar Numero");
                ok = false;
                document.getElementById("numero").focus();
            }
        }
        if (ok) {
            if ((validaRequerido(document.getElementById("email"), 'E-mail'))) {                
                var mail = document.getElementById("email").value;                
                if (validaEmailStr(mail, "mail")) {
                    ok = true;
                }
                else {
                    ok = false;                    
                }
            }
            else {
                ok = false;
            }
        }
		if (ok) ok = validaPhone(document.getElementById("codPais"),'C\u00F3digo de Pa\u00EDs',"ok");
		if (ok) ok = validaPhone(document.getElementById("codCiudad"),'C\u00F3digo de Ciudad',"ok");
		if (ok) ok = validaPhone(document.getElementById("telefono"),'Telefono',"ok");	
		if (ok) document.form_.submit();
		//if (ok) alert("enviar");
}
function validaProyecto(accion){
	$k = jQuery.noConflict();			
	var check;
	$k("#formulario fieldset .columns span input[type=radio]:checked").each(function(){
			check = $k(this).val();
		});
	//console.log("check: "+check);		
	//var tipoUbica = $k("#formulario fieldset .columns span").html());
	var ok;
    var flag = 0;
    
    ok = true;        
    
    if (ok) {
    	if (document.getElementById("tipoUsuario").value == "0") {
        	alert("Debe seleccionar un Tipo de Usuario");
            ok = false;
            document.getElementById("tipoUsuario").focus();
		}
	}
	if (ok) {
    	if (document.getElementById("usuarioExt").value == "0") {
        	alert("Debe seleccionar un Usuario");
            ok = false;
            document.getElementById("usuarioExt").focus();
		}
	}
	if (ok) {
    	if (document.getElementById("usuarioInt").value == "0") {
        	alert("Debe seleccionar un Usuario");
            ok = false;
            document.getElementById("usuarioInt").focus();
		}
	}
    if(ok) ok = isAlphanumeric(document.getElementById("nombreProyecto"),'Nombre Proyecto',"ok");
    if(ok) ok = validaRequerido(document.getElementById("fecha_entrega"),'Fecha de Entrega',"ok");
    //if (ok) ok = validaPhone(document.getElementById("numTipoProp"),'Tipo de Propiedad',"ok");
	if(check == 'exacta'){	
		if (ok) {
			if (document.getElementById("region").value == "0") {
		    	alert("Debe seleccionar Regi\u00F3n");
		        ok = false;
		        document.getElementById("region").focus();
			}
		}
		if (ok) {
	 		if (document.getElementById("comuna").value == "0") {
		    	alert("Debe seleccionar Comuna");
		        ok = false;
		        document.getElementById("comuna").focus();
			}
		} 
		if (ok) {
			if (document.getElementById("comuna").value == "0") {
		    	alert("Debe seleccionar Comuna");
		        ok = false;
		        document.getElementById("comuna").focus();
			}
		}
		if (ok) {
			if (document.getElementById("direccion").value == "0") {
		    	alert("Debe seleccionar Direccion");
		        ok = false;
		        document.getElementById("direccion").focus();
		    }
		}  	
		if (ok) {
			if (document.getElementById("numero").value == "0") {
		    	alert("Debe seleccionar Numero");
		        ok = false;
		        document.getElementById("numero").focus();
		    }
		}
	}else if(check == 'aprox'){
		if(ok) ok = validaRequerido(document.getElementById("ubicaProyecto"),'Ubicaci\u00F3n',"ok");
	}    
	//alert(document.getElementById("hvisit").value);	    
	//alert(tinyMCE.get("hvisit").getContent()); 
	//alert(tinyMCE.get("descrip").getContent()); 
	if (ok) ok = validaPhone(document.getElementById("codPais"),'C\u00F3digo de Pa\u00EDs',"ok");
	if (ok) ok = validaPhone(document.getElementById("codCiudad"),'C\u00F3digo de Ciudad',"ok");
	if (ok) ok = validaPhone(document.getElementById("telefono"),'Telefono',"ok");
	//if(ok) ok = validaRequerido(document.getElementById("hvisit"),'Horario de Visita',"ok");	
	if(ok){ 
		if(tinyMCE.get("hvisit").getContent().length == 0){
			//focos
			tinyMCE.execCommand('mceFocus',false,'hvisit'); 
			alert("Debe ingresar 'Horario de visita'");
        	ok = false;
		}else{
			ok = true;
		}
	}
	if(ok){ 
		if(tinyMCE.get("descrip").getContent().length == 0){
			//focos
			tinyMCE.execCommand('mceFocus',false,'descrip'); 
			alert("Debe ingresar 'Descripci\u00F3n del Proyecto'");
        	ok = false;
		}else{
			ok = true;
		}
	}
	//if(ok) ok = validaRequerido(document.getElementById("descrip"),'Descripcion',"ok");	
	//if(ok) ok = validaRequerido(tinyMCE.get("descrip").getContent(),'Descripcion',"ok");	
	document.getElementById("enviara").value=accion;
	if (ok) {
		//alert("envia");
		document.formProyecto.submit();					
	}
}
function validaPropProyecto(tipoPropiedad,accion){		
	var ok;
    var flag = 0;
    ok = true;        
    if(ok) ok = isAlphanumeric(document.getElementById("nombrePropiedad"),'Nombre Propiedad',"ok");
    if (ok) {
    	if (document.getElementById("tipo_propiedad").value == "0") {
        	alert("Debe seleccionar un Tipo de Propiedad");
            ok = false;
            document.getElementById("tipo_propiedad").focus();
		}
	}
	/*
    if (ok) {
    	if (document.getElementById("hab").value == "0") {
        	alert("Debe seleccionar una Habitacion");
            ok = false;
            document.getElementById("hab").focus();
		}
	}
	if (ok) {
    	if (document.getElementById("ban").value == "0") {
        	alert("Debe seleccionar un Baño");
            ok = false;
            document.getElementById("ban").focus();
		}
	}
	*/	
	if(tipoPropiedad == 1){
		//if (ok) ok = validaPhone(document.getElementById("met2"),'Metros de Terreno',"ok");
		if (ok) ok = validaFloat(document.getElementById("met2"),'Metros de Terreno',"ok");		
	}
	//if (ok) ok = validaPhone(document.getElementById("met2c"),'Metros Construidos',"ok");
	if (ok) ok = validaFloat(document.getElementById("met2c"),'Metros Construidos',"ok");
	if (ok) ok = validaPhone(document.getElementById("numProp"),'Numero de Propiedades',"ok");
	if (ok) ok = validaFloat(document.getElementById("precioInicio"),'Precio de Inicio',"ok");
	//if (ok) ok = validaPhone(document.getElementById("precioTermino"),'Precio de Termino',"ok");
	//if (ok) ok = validaRequerido(document.getElementById("descrip"),'Descripcion',"ok");	
	if(ok){ 
		if(tinyMCE.get("descrip").getContent().length == 0){
			//focos
			tinyMCE.execCommand('mceFocus',false,'descrip'); 
			alert("Debe ingresar 'Descripci\u00F3n de la Propiedad'");
        	ok = false;
		}else{
			ok = true;
		}
	}	
	document.getElementById("enviara").value=accion;
	if (ok) document.formPropiedad.submit();
	//if (ok) alert("enviar");
}
function check_text(tot_carac)
{
	largo=document.getElementById('descrip').value.length;
	if(largo>tot_carac)
	{
		alert("Error: "+tot_carac+" Caracteres maximos");	
		//document.form_publi2.descrip.focus();		
	}
	
}
function EliminaPublic(ref,accion,mensaje){	
	if(accion == 'elimina'){
		var eliminar = confirm(mensaje);
		if(!eliminar){
			return false;		
		}else{
			location.href=ref;
			return true;	
		}
	}else{
		if(accion == 'predetermina'){
			window.open(ref,null,'height=200,width=400,status=yes,toolbar=no,menubar=no,location=no');
		}
	}
}
function volver()
{
	document.getElementById('formPubli').submit();
}
function reset1()
{
	document.getElementById('titulo').value="";
	document.getElementById('tipo_propiedad').selectedIndex =0;
	document.getElementById('region').value="";
	document.getElementById('comuna').value="";
	document.getElementById('direccion').value ="Avda./Calle/ Pje.";
	document.getElementById('numero').value ="Nº";
	document.getElementById('num_depto').value ="Nº Depto";
	document.getElementById('cod_p').value ="56";
	document.getElementById('cod_c').value ="02/09";
	document.getElementById('telef').value ="5555555";
	document.getElementById('region').selectedIndex =0;
	cargaXML("listar_comunas.php?id_region=0","comunas")
}
function reset2()
{
	document.getElementById('hab').selectedIndex =0;
	document.getElementById('ban').selectedIndex =0;
	document.getElementById('bod').selectedIndex =0;
	document.getElementById('est').selectedIndex =0;
	document.getElementById('met2c').value="m²";
	document.getElementById('hvisit').value="Ejemplo: Lun-Vier 16 a 19 horas";
	document.getElementById('precio').value="";
	document.getElementById('descrip').value="";
	
	
}
function reset3()
{
	document.getElementById('hab').selectedIndex =0;
	document.getElementById('ban').selectedIndex =0;
	document.getElementById('bod').selectedIndex =0;
	document.getElementById('est').selectedIndex =0;
	document.getElementById('met2').value="m²";
	document.getElementById('met2c').value="m²";
	document.getElementById('hvisit').value="Ejemplo: Lun-Vier 16 a 19 horas";
	document.getElementById('precio').value="";
	document.getElementById('descrip').value="";
	
	
}
function buscarH(nom_id,form_name,cont)
{
	habitaciones="";
	if(document.getElementById(nom_id).checked) //checkeo la opcion
	{		
		
		for(i=0;i<cont;i++)
		{
			id_com="hab_"+i;
			if(document.getElementById(id_com).checked)
			{		
				habitaciones=habitaciones+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[form_name].habit.value=habitaciones;
		document.forms[form_name].submit();
	}else
	{		
		for(i=0;i<cont;i++)
		{
			id_com="hab_"+i;
			if(document.getElementById(id_com).checked)
			{		
				habitaciones=habitaciones+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[form_name].habit.value=habitaciones;
		document.forms[form_name].submit();
	}
	//alert(document.forms["form_hab_1"].banos2.value);
}
function buscarH2(nom_id,form_name)
{
	habitacion="";
	if(document.getElementById(nom_id).checked) //checkeo la opcion
	{
		if(document.getElementById('hab_1').checked)
		{		
			habitacion=habitacion+"1|";
		}
		if(document.getElementById('hab_2').checked)
		{		
			habitacion=habitacion+"2|";
		}
		if(document.getElementById('hab_3').checked)
		{		
			habitacion=habitacion+"3|";
		}
		if(document.getElementById('hab_4').checked)
		{		
			habitacion=habitacion+"4|";
		}
		
		if(document.getElementById('hab_5').checked)
		{		
			habitacion=habitacion+"5|";
		}
		
		url_envio=""+url_envio+"&buscar="+consulta_rt+"&habit="+habitacion;
		document.forms[form_name].habit.value=habitacion;
		document.forms[form_name].submit();
		//location.href=url_envio;
	}else //deschekeo una opc.
	{
		habitacion="";
		if(document.getElementById('hab_1').checked)
		{		
			habitacion=habitacion+"1|";
		}
		if(document.getElementById('hab_2').checked)
		{		
			habitacion=habitacion+"2|";
		}
		if(document.getElementById('hab_3').checked)
		{		
			habitacion=habitacion+"3|";
		}
		if(document.getElementById('hab_4').checked)
		{		
			habitacion=habitacion+"4|";
		}
		
		if(document.getElementById('hab_5').checked)
		{		
			habitacion=habitacion+"5|";
		}
		
		url_envio=""+url_envio+"&buscar="+consulta_rt+"&habit="+habitacion;
		document.forms[form_name].habit.value=habitacion;
		document.forms[form_name].submit();
		//location.href=url_envio;
	}
}
function buscarB2(nom_id,form_name2)
{
	banos="";
	if(document.getElementById(nom_id).checked) //checkeo la opcion
	{
		if(document.getElementById('ban_1').checked)
		{		
			banos=banos+"1|";
		}
		if(document.getElementById('ban_2').checked)
		{		
			banos=banos+"2|";
		}
		if(document.getElementById('ban_3').checked)
		{		
			banos=banos+"3|";
		}
		if(document.getElementById('ban_4').checked)
		{		
			banos=banos+"4|";
		}
		
		
		url_envio=""+url_envio+"&buscar="+consulta_rt+"&habit="+banos;
		document.forms[form_name2].banos2.value=banos;
		document.forms[form_name2].submit();
		//location.href=url_envio;
	}else //deschekeo una opc.
	{
		banos="";
		if(document.getElementById('ban_1').checked)
		{		
			banos=banos+"1|";
		}
		if(document.getElementById('ban_2').checked)
		{		
			banos=banos+"2|";
		}
		if(document.getElementById('ban_3').checked)
		{		
			banos=banos+"3|";
		}
		if(document.getElementById('ban_4').checked)
		{		
			banos=banos+"4|";
		}
		
		
		url_envio=""+url_envio+"&buscar="+consulta_rt+"&habit="+banos;
		document.forms[form_name2].banos2.value=banos;
		document.forms[form_name2].submit();
		//location.href=url_envio;
	}
}
function buscarB(nom_id,form_name,cont)
{
	banos="";
	if(document.getElementById(nom_id).checked) //checkeo la opcion
	{		
		
		for(i=0;i<cont;i++)
		{
			id_com="ban_"+i;
			if(document.getElementById(id_com).checked)
			{		
				banos=banos+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[form_name].banos2.value=banos;
		document.forms[form_name].submit();
	}else
	{		
		for(i=0;i<cont;i++)
		{
			id_com="ban_"+i;
			if(document.getElementById(id_com).checked)
			{		
				banos=banos+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[form_name].banos2.value=banos;
		document.forms[form_name].submit();
	}
	//alert(document.forms["form_ban_1"].habit.value);
}


function buscarM(nom_id,form_name,cont)
{
	mt="";
	if(document.getElementById(nom_id).checked) //checkeo la opcion
	{		
		
		for(i=0;i<cont;i++)
		{
			id_com="mt_"+i;
			if(document.getElementById(id_com).checked)
			{		
				mt=mt+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[form_name].mt.value=mt;
		document.forms[form_name].submit();
	}else
	{		
		for(i=0;i<cont;i++)
		{
			id_com="mt_"+i;
			if(document.getElementById(id_com).checked)
			{		
				mt=mt+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[form_name].mt.value=mt;
		document.forms[form_name].submit();
	}
	//alert(document.forms["form_ban_1"].habit.value);
}
function check_comunas(nom_id,form_comuna,cont)
{
	comuna="";
	if(document.getElementById(nom_id).checked) //checkeo la opcion
	{		
		
		for(i=0;i<cont;i++)
		{
			id_com="comuna_"+i;
			if(document.getElementById(id_com).checked)
			{		
				comuna=comuna+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[form_comuna].ck_comunas.value=comuna;
		document.forms[form_comuna].submit();
	}else
	{		
		for(i=0;i<cont;i++)
		{
			id_com="comuna_"+i;
			if(document.getElementById(id_com).checked)
			{		
				comuna=comuna+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[form_comuna].ck_comunas.value=comuna;
		document.forms[form_comuna].submit();
	}
}
function check_pt(nom_id,name_form,cont)
{
	
	/*if(cont==4)
	{
		cont--;
	}*/
	pt="";
	if(document.getElementById(nom_id).checked) //checkeo la opcion
	{
		
		for(i=0;i<cont;i++)
		{
			id_com="pt_"+i;
			if(document.getElementById(id_com).checked)
			{		
				pt=pt+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[name_form].tp_prop.value=pt;
		document.forms[name_form].submit();
	}else
	{
		
		for(i=0;i<cont;i++)
		{
			id_com="pt_"+i;
			if(document.getElementById(id_com).checked)
			{		
				pt=pt+"|"+document.getElementById(id_com).value+"";
			}
		}
		
		document.forms[name_form].tp_prop.value=pt;
		document.forms[name_form].submit();
	}
	//alert(pt);
}
function createXMLHttpRequest() {   

    if (window.ActiveXObject) {     

        return new ActiveXObject("Microsoft.XMLHTTP");  

    } else if (window.XMLHttpRequest) {     

        return new XMLHttpRequest();    

    }   

}

var xmlHttp;
function Predetermina(multimedia,proyecto,detalle) {	
    var url = "multimediaPre.php?multimedia="+multimedia+"&proyecto="+proyecto+"&id_detalle="+detalle;           
    xmlHttp = createXMLHttpRequest();
    xmlHttp.open("GET", url);
    xmlHttp.onreadystatechange = onCompleteData;
    xmlHttp.send(null);
}

function onCompleteData() {
    if (xmlHttp.readyState == 4) {
		var idProyecto = document.getElementById("proyecto").value;		
		var detalleProy = document.getElementById("detalleProyecto").value;				
		cargaXML("imagenPredet1.php?id_proyecto="+idProyecto+"&id_detalle="+detalleProy,"img-inmobi");
		xmlHttp.responseText;
    }
}
function misFavoritos(id_tipo,usuario,propiedad,estado) {	
	var url = "masFavoritos.php?id_tipo="+id_tipo+"&idUsuario="+usuario+"&idPropiedad="+propiedad+"&estado="+estado;	
    xmlHttp = createXMLHttpRequest();
    xmlHttp.open("GET", url);
    xmlHttp.onreadystatechange = agregaFavorito;
    xmlHttp.send(null);
}
function agregaFavorito() {
    if (xmlHttp.readyState == 4) {		
        xmlHttp.responseText;
        alert(xmlHttp.responseText);        
    }
}

function validaCuenta(pass){		
        var ok;
        ok = true;
        if (ok) {
            if ((validaRequerido(document.getElementById("email2"), 'E-mail'))) {                
                var mail = document.getElementById("email2").value;                
                if (validaEmailStr(mail, "mail")) {
                    ok = true;
                }
                else {
                    ok = false;                    
                }
            }
            else {
                ok = false;
            }
        }
        if(pass == 'ok'){
        	if (ok) 
            	ok = validaRequerido(document.getElementById('contrasena2'), 'Contrase\u00F1a');
        }
        if (ok) 
            document.formRegistra.submit();
    }
 function validaContacto(){		
        var ok;
        ok = true;
        if (ok) {
            if ((validaRequerido(document.getElementById("email"), 'E-mail'))) {                
                var mail = document.getElementById("email").value;                
                if (validaEmailStr(mail, "mail")) {
                    ok = true;
                }
                else {
                    ok = false;                    
                }
            }
            else {
                ok = false;
            }
        }        
        if (ok) 
            document.formContacto.submit();
    }   
function x_filtros(filtros_activos3b,nom_id,navegador)
{
	//alert("entra");
	//alert(navegador);
	if(navegador!="MSIE")
	{
		
		document.getElementById('ult_consulta').value=filtros_activos3b;
		document.getElementById(nom_id).value="";
	
	}
	else
	{			
		//alert(filtros_activos3b);
		document.form_xfiltros.all['ult_consulta'].value=filtros_activos3b;				
		document.form_xfiltros.all[nom_id].value="";
	
	}
	document.form_xfiltros.submit();
}
function x_filtros4(dato,nom_id,navegador)
{
	if(navegador!="MSIE")
	{
		
		document.getElementById(nom_id).value=dato;
	}
	else
	{			
		document.form_xfiltros.all[nom_id].value=dato;
	}
	//document.all[nom_id].value=dato;
	
document.form_xfiltros.submit();
}
function x_filtrosEsp(listado,nom_id)
{
	
	document.getElementById(nom_id).value=listado;
	document.form_xfiltros.submit();
}

/*function x_filtros3(filtros_activos3b,nom_id)
{
	
	document.getElementById('ult_consulta').value=filtros_activos3b;
	//alert(document.getElementById(nom_id).value);
	document.getElementById(nom_id).value="";
	document.form_xfiltros.submit();
}*/
function x_filtros3(navegador)
{
	
	
	if(navegador!="MSIE")
	{
		document.getElementById('ult_consulta').value="estado:nueva| and region:metropolitana";	
		document.getElementById('buscar').value="estado:nueva and region:metropolitana";	
		document.getElementById('ck_comunas').value="";	
		document.getElementById('tp_prop').value="";	
		document.getElementById('habit').value="";	
		document.getElementById('banos2').value="";	
		document.getElementById('mt').value="";		
		document.getElementById('estad').value="nueva";	
	}
	else
	{			
		document.form_xfiltros.all['ult_consulta'].value="estado:nueva| and region:metropolitana";	
		document.form_xfiltros.all['buscar'].value="estado:nueva and region:metropolitana";	
		document.form_xfiltros.all['ck_comunas'].value="";	
		document.form_xfiltros.all['tp_prop'].value="";	
		document.form_xfiltros.all['habit'].value="";	
		document.form_xfiltros.all['banos2'].value="";	
		document.form_xfiltros.all['mt'].value="";		
		document.form_xfiltros.all['estad'].value="nueva";	
	}
	
	document.form_xfiltros.submit();
}

function x_filtros2(filtros_activos3b)
{
	document.getElementById('ult_consulta').value=filtros_activos3b;
	
	document.form_xfiltros.submit();
}
function CargaCalle(comuna,direccion){	//nueva
	cargaXML("callesXcomuna.php?id_comuna="+comuna+"&id_calle="+direccion,"calles");
	//cargaXMLSin("callesXcomuna.php?id_comuna="+comuna+"&id_calle="+direccion,"calles");
}
function CargaNumero(comuna,direccion,calle){	//nueva	
	cargaXML("numerosXcalle.php?id_calle="+direccion+"&id_comuna="+comuna+"&id_numero="+calle,"numeroCalle");	
	//cargaXMLSin("numerosXcalle.php?id_calle="+direccion+"&id_comuna="+comuna+"&id_numero="+calle,"numeroCalle");	
}

function carga_provincia(var_reg,var_provincia){	//nueva	
	cargaXML("listar_provincia.php?id_region="+var_reg+"&id_provincia="+var_provincia,"provincia");	
}

function carga_comuna(id_comuna,id_provincia,id_region){	//nueva	
	cargaXML("listar_comunas.php?id_region="+id_region+"&id_provincia="+id_provincia+"&id_comuna="+id_comuna,"comunas");	
	
	
}
function check_estado(nom_id,form_est,cont)
{
	comuna="";
	if(document.getElementById(nom_id).checked) //checkeo la opcion
	{		
		
		for(i=0;i<cont;i++)
		{
			id_com="est_"+i;
			if(document.getElementById(id_com).checked)
			{		
				comuna=comuna+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[form_est].estad.value=comuna;
		document.forms[form_est].submit();
		//location.href="index_propiedades.php?estad="+comuna;
	}else
	{		
		for(i=0;i<cont;i++)
		{
			id_com="est_"+i;
			if(document.getElementById(id_com).checked)
			{		
				comuna=comuna+"|"+document.getElementById(id_com).value+"";
			}
		}
		document.forms[form_est].estad.value=comuna;
		document.forms[form_est].submit();
		//location.href="index_propiedades.php?estad="+comuna;
	}
	
}
function check_regInmobi()
{
	msg="Los siguientes campos, son obligatorios:\n";
	msg2 = "Dirección url debe ser del tipo: \"http://www.pabellon.cl\"\n";
	p=0;
	if(document.getElementById('nombre').value=="")
	{
		p=1;
		msg = msg+"- Titulo\n";
	}
	if(document.getElementById('email').value=="")
	{
		p=1;
		msg = msg+"- Mail\n";
	}
	if(document.getElementById('tip_usuario').value < 1)
	{
		p=1;
		msg = msg+"- Tipo Propiedad \n";
	}
	if(document.getElementById('region').value < 1)
	{
		p=1;
		msg = msg+"- Region \n";
	}
	if(document.getElementById('comuna').value < 1)
	{
		p=1;
		msg = msg+"- Comuna \n";
	}
	if(document.getElementById('direccion').value < 1)
	{
		p=1;
		msg = msg+"- Direccion \n";
	}	
	if(document.getElementById('numero').value < 1)
	{
		p=1;
		msg = msg+"- Numero \n";
	}
	
	if(document.getElementById('cod_p').value =="" || !/^([0-9])*$/.test(document.getElementById('cod_p').value))
	{
		p=1;
		msg = msg+"- Codigo Pais";
		if(!/^([0-9])*$/.test(document.getElementById('cod_p').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}	
	if(document.getElementById('cod_c').value =="" || document.getElementById('cod_c').value=="02/09" || !/^([0-9])*$/.test(document.getElementById('cod_c').value))
	{
		p=1;
		msg = msg+"- Codigo Ciudad";
		if(!/^([0-9])*$/.test(document.getElementById('cod_c').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}
	if(document.getElementById('telef').value =="" || document.getElementById('telef').value =="5555555" || !/^([0-9])*$/.test(document.getElementById('telef').value))
	{
		p=1;
		msg = msg+"- Telefono Contacto";
		if(!/^([0-9])*$/.test(document.getElementById('telef').value))
			msg=msg+" (Campo Numerico)\n";
		else
			msg=msg+"\n";
	}
	if(document.getElementById('webPage').value != ""){		
		if(validaURLs(document.getElementById('webPage').value) == false){
			p=1;
			msg = msg+"- "+msg2;
		}
	}
	if(p==1)
	{
		alert(msg);	 
	}else		
	{
		document.form_.submit();			
	}
}


function imprime(){
 
     url="imprimir_propiver.php";
     window.open(url,'ventana','location=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes');  
  
}
function imprimeFav(){
 
     url="imprime_favorito.php";
     window.open(url,'ventana','location=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes');  
  
}

function abrir(direccion, pantallacompleta, herramientas, direcciones, estado, barramenu, barrascroll, cambiatamano, ancho, alto, izquierda, arriba, sustituir){ 
     var opciones = "fullscreen=" + pantallacompleta + 
                 ",toolbar=" + herramientas + 
                 ",location=" + direcciones + 
                 ",status=" + estado + 
                 ",menubar=" + barramenu + 
                 ",scrollbars=" + barrascroll + 
                 ",resizable=" + cambiatamano + 
                 ",width=" + ancho + 
                 ",height=" + alto + 
                 ",left=" + izquierda + 
                 ",top=" + arriba; 
	var navegador = navigator.appName;		
	if (navegador == "Microsoft Internet Explorer"){
		direccion = '../'+direccion;
	}
    var ventana = window.open(direccion,"venta",opciones,sustituir); 

}                     
function activaTerreno(valor,obj){	
	if(valor == 1){
		activa(obj);
	}else{
		inactiva(obj);
	}
}
function volverPublicaProy(){
	location.href="publicProyecto.php?accion=backToProy";
}
function cargaProvincia(region,provincia){
	cargaXML("listar_provincia.php?id_region="+region+"&id_provincia="+provincia,"provincia");
}
function cargaComuna(region,provincia,comuna){	
	cargaXML("listar_comunas.php?id_region="+region+"&id_provincia="+provincia+"&id_comuna="+comuna,"comunas");
	//cargaXMLSin("listar_comunas.php?id_region="+region+"&id_provincia="+provincia+"&id_comuna="+comuna,"comunas");
}
function cargaInternos(usuarioExt,usuarioInt){
	cargaXML("listar_internos.php?idUsuarioExt="+usuarioExt+"&id_usInt="+usuarioInt,"interno");	
}
function cargaResultado(proyecto,pagina,origen,inicio,termino,total){					
	//cargaXML("lista-resultado.php?id_pro="+proyecto+"&cuantos="+pagina+"&origen="+origen+"&inicio="+inicio+"&termino="+termino+"&total="+total,"resultado");	
	//alert("entra");
	FAjaxSin("lista-resultado.php","resultado","id_pro="+proyecto+"&cuantos="+pagina+"&origen="+origen+"&inicio="+inicio+"&termino="+termino+"&total="+total,"post");	
}
function resetProy(formulario){
	if(formulario == 'proyecto'){
		document.getElementById("tipoUsuario")[0].selected=true;
		document.getElementById("usuarioExt")[0].selected=true;	
		document.form_.usuarioExt.options.length = 1;
		document.getElementById("usuarioInt")[0].selected=true;	
		document.form_.usuarioInt.options.length = 1;
		document.getElementById("nombreProyecto").value="";
		//document.getElementById("numTipoProp").value="";
		document.getElementById("fecha_entrega").value="";
		document.getElementById("region")[0].selected=true;
		document.getElementById("provinci")[0].selected=true;
		document.form_.provinci.options.length = 1;
		document.getElementById("comuna")[0].selected=true;
		document.form_.comuna.options.length = 1;
		document.getElementById("direccion")[0].selected=true;
		document.form_.direccion.options.length = 1;
		document.getElementById("numero")[0].selected=true;
		document.form_.numero.options.length = 1;
		document.getElementById("codPais").value="";
		document.getElementById("codCiudad").value="";
		document.getElementById("telefono").value="";
		document.getElementById("hvisit").value="";
		document.getElementById("descrip").value="";	
	}else{
		if(formulario == 'propiedad'){
			document.getElementById("tipo_propiedad")[0].selected=true;		
			document.getElementById("nombrePropiedad").value="";
			document.getElementById("hab")[0].selected=true;
			document.getElementById("ban")[0].selected=true;
			document.getElementById("est")[0].selected=true;
			document.getElementById("bod")[0].selected=true;
			document.getElementById("met2").value="";
			document.getElementById("met2c").value="";
			document.getElementById("numProp").value="";
			document.getElementById("precioInicio").value="";
			document.getElementById("precioTermino").value="";
			document.getElementById("tipo_val").value="";
			document.getElementById("descrip").value="";
		}
	}
}

var map, Layer, markers,prop,nav,id_p,prop2;
function init(lon,lati,zoom,id_prop,id_region)
{
	map = new OpenLayers.Map('map',{controls: [],numZoomLevels:18});
  var layer = new OpenLayers.Layer.KaMap("MAPAS",
  "http://www.mapas.emol.com/tile.php?", {i:"png"},{'displayInLayerSwitcher':false});  
  map.addLayer(layer);  
  map.addControl(new OpenLayers.Control.Navigation({'zoomWheelEnabled': false}));
  map.addControl(new OpenLayers.Control.MousePosition(new OpenLayers.Control.PanZoom()));  
  map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':true}));
  //map.addControl(new OpenLayers.Control.MousePosition());  
  map.addControl(new OpenLayers.Control.OverviewMap({'size':new OpenLayers.Size(200,100)}));
  map.addControl(new OpenLayers.Control.KeyboardDefaults()); 
  zoom--;
  zoom++;
 
  map.setCenter(new OpenLayers.LonLat(lon,lati), zoom);
 	map.events.register("zoomend", null, displayZoom); 
 	map.events.register("moveend", null, movimiento); 
	
	//Servicios
	services('Carabineros','carabineros.png',id_region,'Carabineros');
	services('Bancos','banco.png',id_region,'Bancos');
	services2('Hospital','hospital.png',id_region,'Hospitales');
	services2('Supermercado','supermercado.png',id_region,'Supermercados');
	services('Colegio','colegio.png',id_region,'Colegios');
	propiedades2(id_p,0);	
	propiedades(id_p,1);	
	document.getElementById("test").value=map.getZoom();
	

}

function movimiento()
{	
	zoom=map.getZoom();
	getZoom(zoom);
	latlon=String(map.getCenter());
	//limpiarLatLon(latlon);
	arre=latlon.split(',');
  lon_m=arre[1];
  lat_m=arre[0];
  lat_m=lat_m.replace("lon=","");
  lon_m=lon_m.replace("lat=","");
	cargarVarMapas(lat_m,lon_m,zoom);
}
function limpiarLatLon(latlon)
{
	arre=latlon.split(',');
  lat_m=arre[1];
  lon_m=arre[0];
  lat_m=lat_m.replace("lat=","");
  lon_m=lon_m.replace("lon=","");
}
function displayZoom()
{
	
  zoom=map.getZoom();
  
 if(zoom>20)
 {
 	map.zoomTo(20);
 }
 if(zoom<6)
 {
 	map.setCenter(new OpenLayers.LonLat(-71.33539,-33.10113), 6);
 }
 getZoom(zoom);
 zoom_ant=document.getElementById("test").value;
 //alert(map.getZoom());			  
 if(zoom==14 && zoom_ant==13)
 {			 	
   map.zoomTo(15);
 }
 if(zoom==14 && zoom_ant==15)
 {			 	
   map.zoomTo(13);
 }
 
 document.getElementById("test").value=zoom;
			
}
function getZoom(zoom)
{
		latlon=String(map.getCenter());
		arre=latlon.split(',');
  	lon_m=arre[1];
  	lat_m=arre[0];
  	lat_m=lat_m.replace("lon=","");
  	lon_m=lon_m.replace("lat=","");
		cargarVarMapas(lat_m,lon_m,zoom);
		//limpiarLatLon(latlon);
	
		//cargarVarMapas(lat_m,lon_m,zoom_m);
		var url = "includes/acciones_var.php?accion=mapa&zoom="+zoom+"&latlon="+latlon+"";	
    xmlHttp = createXMLHttpRequest();
    xmlHttp.open("GET", url);
   //xmlHttp.onreadystatechange = agregaFavorito;
    xmlHttp.send(null);
}
function cargarMapa(lon,lat,zoom,id_prop2,id_region,lat_map,lon_map,ini,ter,tip_prop,var_html)
{
	//alert(ini);
	id_p=id_prop2;
	//cargaXML("mapa.php","container-mapa");
	FAjaxSin("mapa.php","container-mapa","ini="+ini+"&ter="+ter+"&id_prop="+id_prop2+"&tip_prop="+tip_prop+"&lat_map="+lat_map+"&lon_map="+lon_map+"","post");
	//alert("mapas");	
	setTimeout("init('"+lon+"','"+lat+"','"+zoom+"','"+id_prop2+"','"+id_region+"','"+lat_map+"','"+lon_map+"','"+ini+"','"+ter+"','"+tip_prop+"','"+var_html+"')",300);	
	//init(lon,lat,zoom,id_prop2,id_region);
}
function servicios()
{
	//Servicios ptos
	
	markers = new OpenLayers.Layer.Markers( "Servicios" );
	map.addLayer(markers);
  size = new OpenLayers.Size(10,15);
  calculateOffset = function(size) {
  return new OpenLayers.Pixel(-(size.w/2), -size.h); };
	icon = new OpenLayers.Icon(
		'http://boston.openguides.org/markers/AQUA.png',
		size, null, calculateOffset
	);
  markers.addMarker(
  new OpenLayers.Marker(new OpenLayers.LonLat(-70.68,-33.44), icon));
  markers.setVisibility(false);
}
function propiedades2(id_pro,tipo)
{
	//alert(id_pro);
	prop2 = new OpenLayers.Layer.Text( "Propiedades usadas", { location:"entrega_propiedades.php?id_pro="+id_pro+"&tipo="+tipo+"&"+url_get+""} );
  map.addLayer(prop2);
  prop2.setVisibility(true);						            
}
function propiedades(id_pro,tipo)
{
	//alert(id_pro);
	prop = new OpenLayers.Layer.Text( "Proyectos", { location:"entrega_propiedades.php?id_pro="+id_pro+"&tipo="+tipo+"&"+url_get+""} );
  map.addLayer(prop);
  prop.setVisibility(true);						            
}

function services(categoria,img,id_region,nom_cate)
{
	//alert(""+categoria+"-"+img+"-"+id_region+"");
	var newl = new OpenLayers.Layer.Text( nom_cate, { location:"entrega_servicios.php?categoria="+categoria+"&img="+img+"&id_region="+id_region+""} );
  map.addLayer(newl);
	newl.setVisibility(false);						            
}

function services2(categoria,img,id_region,nom_cate)
{
	//alert(""+categoria+"-"+img+"-"+id_region+"");
	var new2 = new OpenLayers.Layer.Text( nom_cate, { location:"entrega_servicios.php?categoria="+categoria+"&img="+img+"&id_region="+id_region+""} );
  map.addLayer(new2);
	new2.setVisibility(false);						            
}
function enviar_ciudad()
{
	val=document.getElementById('pro').value;
	document.forms[val].submit();
}
function cambia_clase_leguetas(id_del_objeto,nueva_clase){ //etapa2
//alert("entra");
var objeto = document.getElementById(id_del_objeto);
objeto.className = nueva_clase;

if(id_del_objeto=="1a")
{
	
	document.getElementById("3a").className = "";
}
if(id_del_objeto=="3a")
{
	
	document.getElementById("1a").className = "";
}

}
function confirmaPy(proyecto,propiedades,accion){
	location.href = "accion_publicProyecto.php?id_proyecto="+proyecto+"&id_propiedad="+propiedades+"&accion="+accion+"&ref=viewpy";	
}


   function enable(){  
    document.getElementById('prueba').style.display = "block";
   } 
   function disabled(){  
    document.getElementById('prueba').style.display = "none";
   }  
    function enable2(){  
    document.getElementById('desplieg2').style.display = "block";
   } 
   function disabled2(){
    if(document.getElementById('desplieg2')!=null)
    {
    	document.getElementById('desplieg2').style.display = "none";
  	}
   }  
function validaEmailStr(mail, nombre) {
    // Valida la sintaxis correcta del email
    // si el largo es 0 se considera que la sintaxis es correcta
    if (mail.length > 0 && (mail.indexOf('@') == -1 || mail.indexOf('.') == -1)) {
        alert("'" + nombre + "' debe ser de la forma usuario@host.dominio");
        return false;
    } else {
        return true;
    }
}
 
function olvido_contra()
{
	mail=document.getElementById('email2').value;
	if(mail=='')
	{
		msg="Debes ingresar tu correo.";
		alert(msg);
	}else
	{
		if(validaEmailStr(mail, "mail"))
		{
			location.href = "phpMailer/olvido.php?mail="+mail;	
		}
	}
}
function envio_amigo(paginaActual)
{
	
	mail=document.getElementById('email2').value;
	nombre=document.getElementById('nombre2').value;
	nombre2=document.getElementById('nombre3').value;
	if(mail=='')
	{
		msg="Debes ingresar un correo.";
		alert(msg);
	}else
	{
		if(validaEmailStr(mail, "mail"))
		{
			var navegador = navigator.appName;			
			if(navegador == "Microsoft Internet Explorer"){
				//location.href = "http://192.168.52.205/Pabellon-1.3/phpMailer/envio_amigo.php?mail="+mail+"&nombre="+nombre+"&nombre2="+nombre2+"&url="+paginaActual;
				location.href = "http://www.pabellon.cl/phpMailer/envio_amigo.php?mail="+mail+"&nombre="+nombre+"&nombre2="+nombre2+"&url="+paginaActual;
			}else{
				location.href = "phpMailer/envio_amigo.php?mail="+mail+"&nombre="+nombre+"&nombre2="+nombre2+"&url="+paginaActual;			
			}
		

		}
	}
}

function envio_amigo2(var_url) //etapa2
{
	
	mail=document.getElementById('email2').value;
	nombre=document.getElementById('nombre').value;
	nombre2=document.getElementById('nombre2').value;
	if(mail=='')
	{
		msg="Debes ingresar un correo.";
		alert(msg);
	}else
	{
		if(validaEmailStr(mail, "mail"))
		{
			location.href = "phpMailer/envio_amigo2.php?mail="+mail+"&nombre="+nombre+"&var_url="+var_url+"&nombre2="+nombre2;	
		}
	}
}
function validacionContacto(name_form)
{
	var paso=true;
	msg="Campos obligatorios: \n";
	if(document.getElementById('nombre_con').value=="")
	{
		paso=false;
		msg=""+msg+" Nombre\n";		
	}
	if(document.getElementById('email_con').value=="")
	{
		paso=false;
		msg=""+msg+" Email\n";		
	}else
	{
		if(!validaEmailStr(document.getElementById('email_con').value,'mail'))
		{
			paso=false;
		}
	}
	if(document.getElementById('texoMail').value=="")
	{
		paso=false;
		msg=""+msg+" Comentario\n";		
	}
	if(paso==false && msg!="Campos obligatorios: \n")
	{
		alert(msg);
	}else
	{
		document.formContacto.submit();
	}
	
}


function  cotizar(id_proyecto,tipo_cotizacion,id_propiedad,id_usuario,vieneDesde)
{
	var nombre_modal=document.getElementById('nombre_con').value;
	var mail=document.getElementById('email_con').value;
	var comen_modal=document.getElementById('textoMail').value;
	var cotizacion=document.getElementById('Ncotizacion').value;		
	if(mail=='')
	{
		msg="Debes ingresar un correo.";
		alert(msg);
	}else
	{
		if(validaEmailStr(mail, "mail"))
		{
			var navegador = navigator.appName;			
			if(navegador == "Microsoft Internet Explorer"){
				//location.href = "http://192.168.52.205/Pabellon-1.3/accion_cotizar.php?nombre_modal="+nombre_modal+"&mail_modal="+mail+"&comen_modal="+comen_modal+"&id_proyecto="+id_proyecto+"&tipo_cotizacion="+tipo_cotizacion+"&id_propiedad="+id_propiedad+"&id_usuario="+id_usuario+"&vieneDesde="+vieneDesde+"&cotizacion="+cotizacion;	
				location.href = "http://www.pabellon.cl/accion_cotizar.php?nombre_modal="+nombre_modal+"&mail_modal="+mail+"&comen_modal="+comen_modal+"&id_proyecto="+id_proyecto+"&tipo_cotizacion="+tipo_cotizacion+"&id_propiedad="+id_propiedad+"&id_usuario="+id_usuario+"&vieneDesde="+vieneDesde+"&cotizacion="+cotizacion;
			}else{
				location.href = "accion_cotizar.php?nombre_modal="+nombre_modal+"&mail_modal="+mail+"&comen_modal="+comen_modal+"&id_proyecto="+id_proyecto+"&tipo_cotizacion="+tipo_cotizacion+"&id_propiedad="+id_propiedad+"&id_usuario="+id_usuario+"&vieneDesde="+vieneDesde+"&cotizacion="+cotizacion;	
			}	
			//window.location=direccion; 
			
		}
	}
}
/*
function cotizar(id_proyecto,tipo_cotizacion,id_propiedad,id_usuario) {	
	
	
	var url = "accion_cotizar.php?id_proyecto="+id_proyecto+"&tipo_cotizacion="+tipo_cotizacion+"&id_propiedad="+id_propiedad+"&id_usuario="+id_usuario+"";	
    xmlHttp = createXMLHttpRequest();
    xmlHttp.open("GET", url);
    //xmlHttp.onreadystatechange = agregaFavorito;
    xmlHttp.send(null);
}
*/
function orden_precio()
{
	//alert(document.getElementById('orden').className);
	if(document.getElementById('orden').className=="alt")
	{
		document.getElementById('orden').className="";
		//document.getElementById('orden_bus2').value="mayor";
		document.form_orden.orden_bus.value="mayor";
	}
	else
	{
		document.getElementById('orden').className="alt";	
		//document.getElementById('orden_bus2').value="menor";
		document.form_orden.orden_bus.value="menor";
	}
	//alert(document.getElementById('orden_bus').value);
	
}
function cifraN(n)
{ 
	n=n+""; var i=n.length-3; 
	while(i>0)
	{ 
		n = n.substring(0,i)+ "." + n.substring(i,n.length); i=i-3; 
	} 
	return (n) ; 
} 
function cargarVarMapas(lat_m,lon_m,zoom_m)
{
	document.getElementById('lat_map').value=lat_m;
	//alert(document.getElementById('lat_map').value);
	document.getElementById('lon_map').value=lon_m;
	document.getElementById('zoom_map').value=zoom_m;
}
function getlatMap()
{
	lat_m=document.getElementById('lat_map').value;
	return lat_m;
}
function getlonMap()
{
	lon_m=document.getElementById('lon_map').value;
	return lon_m;
}
function getzoomMap()
{
	zoom_m=document.getElementById('zoom_map').value;
	return zoom_m;
}


function validar_destaca()
{
var f=document.adminis;
  if (f.inmobiliaria.selectedIndex==0)
   {
   alert("Debe ingresar inmobiliaria");
  return false;
   }
  if (f.proyec.selectedIndex==0)
   {
   alert("Debe ingresar proyecto");
   return false;
   }
      
document.adminis.action = "accion_destacados_admin.php";
document.adminis.submit();
return true;
}
function alt_flechaDespliege(nom_id)
{
	if(document.getElementById(nom_id).className == "submit_listado alt")
	{
		document.getElementById(nom_id).className = "submit_listado"
	}else
	{
		document.getElementById(nom_id).className = "submit_listado alt"
	}
}
function validacombo(id_encu) 
{
var id_encue=document.getElementById('id_encu').value; 
var f=document.form1;
 if(!confirm(" ¿Está seguro de activar esta encuesta? ")) 
  {
     return false;	 
    	}else if (f.id_encu.selectedIndex==0){ 
        alert("Debe ingresar elemento a activar");
   
      return false;
   	}else {
   		  		
       document.form1.action = "votar.php?accion=activar&id_encues="+id_encue;
       document.form1.submit();
        return true;
   }   
}

function validacombo2(id_encu) 
{
var id_encue=document.getElementById('id_encu').value; 
var f=document.form1;
 if(!confirm(" ¿Está seguro de Eliminar esta encuesta? ")) 
  {
     return false;	 
    	}else if (f.id_encu.selectedIndex==0){ 
        alert("Debe ingresar elemento a borrar");
   
      return false;
   	}else {
   		  		
       document.form1.action = "votar.php?accion=borrar&id_encues="+id_encue;
       document.form1.submit();
        return true;
   }   



} 

function encue_estadistica(id_encu) 
{
	var id_encue=document.getElementById('id_encu').value;
	 var data =document.getElementById('data').value;
	 var data2 =document.getElementById('data').value;
	 
   document.form1.action = "estadistica_encues.php?id_encu="+id_encue;
   document.form1.submit();
   return true;
 } 
