/* Validacion logueo de usuarios */
function validar_logueo()
{
	if(document.getElementById('usuario').value=="")		
	{
		alert("Debe ingresar el nombre de usuario");		
		return false;
	}
	
	if(document.getElementById('password').value=="")		
	{
		alert("Debe ingresar la contraseña");		
		return false;
	}
	return true;
}

/* Validacion recordar contraseña */
function validar_recordar()
{
	if(document.getElementById('cedula').value=="")		
	{
		alert("Debe ingresar el número de cédula o nit");		
		return false;
	}	
	return true;
}



function validar_banner()
{
	control=document.getElementsByName('seccion');
	if(document.getElementById('descripcion').value=='')	
	{
		alert("Debe ingresar la descripcion");
		document.getElementById('descripcion').focus();
		return false;
	}

	if(document.getElementById('orden').value=='')	
	{
		alert("Debe ingresar el orden en el que aparecerá el banner");
		document.getElementById('orden').focus();
		return false;
	}
	
/*	if(document.getElementById('enlace').value=='')	
	{
		alert("Debe ingresar el enlace(url) del banner");
		document.getElementById('enlace').focus();
		return false;
	}	*/
	
	return true;
}

function validar_nombre()
{
	if(document.getElementById('nombre').value=='')	
	{
		alert("Debe ingresar el nombre");
		return false;
	}
	return true;
}

function validar_busqueda()
{
	var campos=new Array(
		'Tipo inmueble,tipo,1,t'
		,'Ciudad,ciudad,1,t'		
	);
	/*	,'Area desde,area_desde,1,n'
	,'Area hasta,area_hasta,1,n'*/
	return validar_form(campos);
}

function validar_codigo_inm()
{
	var campos=new Array(
		'Codigo,codigo_,1,t'
	);
	
	return validar_form(campos);
}

function validar_encsec(prefijo)
{
	//alert("entro!");
	//return false;
	//{Descripcion campo}, 
	//{ nombre campo en formulario},  
	//{requerido: 1=si 0 no }, 
	//{tipo de campo: t=texto n=numerico c=correo}
	
	
	
	var campos=new Array(
		'Nombre,nombre'+prefijo+',1,t'
		,'Email,email'+prefijo+',0,c'
	);
	
	return validar_form(campos,prefijo);
}

function validar_propietario()
{
//	alert("entro!");
	//return false;
	//{Descripcion campo}, 
	//{ nombre campo en formulario},  
	//{requerido: 1=si 0 no }, 
	//{tipo de campo: t=texto n=numerico c=correo}
	
	try
	{
		control=document.getElementsByName('tipo');
		
		if(control[1].checked)
		{
			if(document.getElementById('razon_social').value=='')
			{
				alert("Razon social es un dato requerido");
				return false;
			}
			if(document.getElementById('nit').value=='')
			{
				alert("Nit es un dato requerido");
				return false;
			}
		}		
	}
	catch(e)
	{
	}
	
	var campos=new Array(
		"Nombre,nombre,1,t"
		,"Cédula o Nit,cedula,1,n"
		,"Telpro,cedula,1,n"
		,"Email,email,0,c"
	);	

	
	return validar_form(campos);
}

function validar_usuario()
{
//	alert("entro!");
	//return false;
	//{Descripcion campo}, 
	//{ nombre campo en formulario},  
	//{requerido: 1=si 0 no }, 
	//{tipo de campo: t=texto n=numerico c=correo}	
	var campos=new Array(
		"Nombre,nombre,1,t"
		,"Cédula o Nit,cedula,1,n"
		,"Telpro,cedula,1,n"
		,"Email,email,0,c"
	);
	
	return validar_form(campos);
}

function validar_areas()
{
	var campos=new Array(
		"Frente,frente,0,n"
		,"Fondo,fondo,0,n"
		,"Area del lote,area_lote,0,n"
		,"Area en oficinas,area_oficinas,0,n"
		,"Area en bodega,area_bodega,0,n"
		,"Area del local,area_local,0,n"
		,"Area Mezzanine,area_mezza,0,n"
		,"Area de Estacionamiento,area_estacionamiento,0,n"
		,"Area libre,area_libre,0,n"
		,"Area utilizable,area_utilizable,0,n"
		,"Frente area utilizable,uti_frente,0,n"
		,"Fondo area utilizable,uti_fondo,0,n"
		,"Area total,area_total,1,n"
	);
	
		return validar_form(campos);
}

function validar_valores()
{
	try
	{
		
	}
	catch(e)
	{
		
		
	}
	
}

function validar_inmueble()
{
	//{requerido: 1=si 0 no }, 
	//{tipo de campo: t=texto n=numerico c=correo s= select d=direccion}
	
	var campos=new Array(
		"Departamento,depto,1,s"
		,"Ciudad o municipio,ciudad,1,s"
		,"Sector,sector,1,s"
		,"Direccion,num1,1,d"
		,"Número inmueble,numero,0,n"
	);
	
	if((!document.getElementById('arrendar').checked)&&(!document.getElementById('vender').checked))
	{
		alert("Debe seleccionar el tipo de operación ");	
		return false;
	}
	
	try
	{
		if(document.getElementById('id_pro').value=="")	
		{
			alert("Debe seleccionar el propietario del inmueble");	
			return false;
		}
		
	}
	catch(e)
	{}
	
	return validar_form(campos);
}

function validar_form(campos)
{
	var fila,campo;
	num_campos=campos.length;	
	//alert(num_campos);
	for(j=0; j<num_campos; j++)
	{
		campo_cadena=campos[j];		
		campo=campo_cadena.split(',');
		//alert("campo"+campo);
		descripcion=campo[0];	
		campo_actual=campo[1];
		
		if(descripcion=='Direccion')
		{
			/*if(!validar_direccion())
				return false;*/
			mensaje_validacion=validar_direccion();
		}
		else
		if(descripcion=='Telpro')
		{
			/*if(!validar_direccion())
				return false;*/
			mensaje_validacion=validar_telefono();
		}
		else
		{
			valor=document.getElementById(campo_actual).value;	
				tipo=campo[3];
		//alert(valor+campo_actual);
		requerido=campo[2];
		//si el campo no tiene valor y es requerido hay problema 
		mensaje_validacion='';
		if(valor=='') 
		{
			//alert("entro");
			if(requerido=='1')	
				mensaje_validacion= '\''+descripcion+'\' es un dato requerido';			
		}
		else
		{ //si campo tiene valor, debe ser valido
			if( tipo=='n' && isNaN(valor) ) 
				mensaje_validacion= '\''+descripcion+'\' debe ser un dato numérico'; 
			if(tipo=='c') 
			{
				if(!validar_correo_e(valor))
				{	
					mensaje_validacion= '\''+descripcion+'\' debe ser correo electrónico válido'; 					
				}				
			}
			if(tipo=='s')
			{
				if(valor=="0")
				{
					mensaje_validacion= '\''+descripcion+'\' es un dato requerido'; 							
				}
			}
		}		
		}
		if(mensaje_validacion)
		{	
			alert(mensaje_validacion);
			document.getElementById(campo_actual).focus();
			return false;
		}	
	}
	return true;
}

function validar_telefono()
{
	if((document.getElementById('tel_casa').value=="")&&(document.getElementById('tel_oficina').value==""))	
	{
		return "Debe ingresar el teléfono de la casa o de la oficina";	
	}
	return '';
}


function validar_direccion()
{
	//direccion del inmueble
	num1 = document.getElementById('num1').value;			
	num2 = document.getElementById('num2').value;			
	num3 = document.getElementById('num3').value;	
		
	if(num1!="")
	{
		if(isNaN(num1.substr(0,1)))
		{
			//alert("Formato de Dirección Incorrecto");
			//document.form1.num1.focus();
			//return false;
			return "Formato de Dirección Incorrecto";
		}
	}
	else
	{
		//alert("Debe Ingresar la Dirección");
		return "Debe Ingresar la Dirección";
		//return false;
	}
		
	if(num2!="")
	{
		if(isNaN(num2.substr(0,1)))
		{
			//alert("Formato de Dirección Incorrecto");
			//document.form1.num2.focus();
			//return false;
			return "Formato de Dirección Incorrecto";
		}
	}
	else
	{
		//alert("Debe Ingresar la Dirección");
		//return false;
		return "Debe Ingresar la Dirección";
	}
		
	if(num3!="")
	{
		if(isNaN(num3))
		{
			/*alert("Formato de Dirección Incorrecto");
			document.form1.num3.focus();
			return false;*/
			return "Formato de Dirección Incorrecto";
		}
	}
	else
	{
		/*alert("Debe Ingresar la Dirección");
		return false;*/
		return "Debe Ingresar la Dirección";
	}	
	return '';	
}


function validar_afiliacion()
	{
		if(document.getElementById('nombre').value=="")	
		{
			alert("Debe ingresar el nombre");
			return false;				
		}	
		
		if(document.getElementById('cc').value=="")	
		{
			alert("Debe ingresar la cedula");
			return false;				
		}	
		
		if(document.getElementById('ciudad_cc').value=="")	
		{
			alert("Debe ingresar el lugar de expedición de la cedula");
			return false;					
		}
		
		if(document.getElementById('dir_casa').value=="")	
		{
			alert("Debe ingresar la dirección de residencia");
			return false;					
		}
		
		if(document.getElementById('ciudad').value=="")	
		{
			alert("Debe ingresar el nombre de la ciudad");
			return false;					
		}
		
		if(document.getElementById('depto').value=="")	
		{
			alert("Debe ingresar el nombre del departamento");
			return false;					
		}
		
		if(document.getElementById('tel_res').value=="")	
		{
			alert("Debe ingresar el telefóno de residencia");
			return false;					
		}
		
		if(document.getElementById('email').value!="")	
		{
			if(!validar_correo_e(document.getElementById('email').value))
			{	
				alert("Debe ingresar un correo electrónico válido");
				return false;		
			}
		}
		
		for(i=1; i<=6; i++)
		{
			if((eval("document.getElementById('beneficiario'+i).value") == "")&& (eval("document.getElementById('parentesco'+i).value") != ""))
			{
				alert("Debe ingresar el nombre y parentesco del beneficiario");
				return false;
			}
			
			if((eval("document.getElementById('beneficiario'+i).value") != "")&& (eval("document.getElementById('parentesco'+i).value") == ""))
			{
				alert("Debe ingresar el nombre y parentesco del beneficiario");
				return false;
			}
		}
		
		return true;
	}

		
	function validar_i(nombre, pais, correo)
	{
		if(nombre=="")	
		{
			alert("Input your name");
			return false;				
		}	
			
		if(pais=="")	
		{
			alert("Input your country");
			return false;				
		}	
			
		if(!validar_correo_e(correo))
		{	
			alert("Input your e-mail");
			return false;		
		}

		window.open('', 'enviar_correo', 'top=200px,width=350px,height=100px');
	}		
		
		
	function validar_contacto(nombre, empresa, email, telefono)
	{
		if(nombre=="")	
		{
			alert("Debe ingresar el nombre");
			return false;				
		}	
		
		if(empresa=="")	
		{
			alert("Debe ingresar la empresa");
			return false;				
		}	
		
		if(!validar_correo_e(email))
		{	
			alert("Debe ingresar un correo electrónico válido");
			return false;		
		}
		
		if(telefono=="")	
		{
			alert("Debe ingresar el telefono");
			return false;				
		}	
		return true;
		
	}
		


function validar_contra(c, c1)
{
	if(c==c1)
		return true;
	else
		alert("Las constraseñas ingresadas son diferentes");
	return false;	
}

function validar_correo_e(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1)   return false
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)	   return false
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)  return false
	if (str.indexOf(at,(lat+1))!=-1) return false
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)   return false
	if (str.indexOf(dot,(lat+2))==-1)   return false
	if (str.indexOf(" ")!=-1)   return false
	return true					
}


function createRequestObject() 
{
     var ro;
     var browser = navigator.appName;
     if(browser == "Microsoft Internet Explorer")
	 {
          ro = new ActiveXObject("Microsoft.XMLHTTP");
     }
	 else
	 {
          ro = new XMLHttpRequest();
     }
     return ro;
}

var http = createRequestObject();


function validar_codigo()
{	
	if(document.getElementById('textfield').value)
	{ 
		http.open('get', 'consultas_ajax.php?id='+cedula);
		http.onreadystatechange = handleResponse;
    	http.send(null);
		
		window.close(); 
		return true;
	} 
	else
	{ 
		alert('Por favor, ingrese el código del cliente'); 
		return  false; 
	}
}	


function tipo_av_cambio(objeto){
	tipo=objeto.value;
	http.open('get', 'admin/ciudades_ajax_av.php?tipo='+tipo);
	http.onreadystatechange = tipo_av_ret;
   	http.send(null);
}

function tipo_av_ret(){
	if(http.readyState == 4){
		var contenido = http.responseText;
		document.getElementById('ciudad_div').innerHTML=contenido;
		document.getElementById('sector_div').innerHTML='';
	}
}

function ciudad_av_cambio(objeto, tipo){
	ciudad=objeto.value;
	http.open('get', 'admin/sectores_ajax_av.php?ciudad='+ciudad+'&tipo='+tipo);
	http.onreadystatechange = ciudad_av_ret;
   	http.send(null);
}

function ciudad_av_ret(){
	if(http.readyState == 4){
		var contenido = http.responseText;
		document.getElementById('sector_div').innerHTML=contenido;
	}
}

function mostrar_ciudades(tipo, ciudad)
{
	//alert(tipo);	
	http.open('get', 'admin/ciudades_ajax.php?tipo='+tipo+'&ciudad='+ciudad);
	http.onreadystatechange = handleResponse;
   	http.send(null);
}

function mostrar_comprar_arrendar(tipo, ciudad)
{
	//alert(tipo);	
	http.open('get', 'admin/comprar_arrendar_ajax.php?tipo='+tipo+'&ciudad='+ciudad);
	http.onreadystatechange = mostrar_comprar_arrendar_response;
   	http.send(null);
}

function mostrar_comprar_arrendar_response(){
	if(http.readyState == 4){
          var contenido = http.responseText;
		  document.getElementById('comprar_arrendar_div').innerHTML=contenido;
	}
}

function mostrar_datos(cedula) 
{
	
}

function mostrar_telefonos(idp) 
{
	//alert(producto.length+"-"+orden+"-"+id_proceso);
	//prompt("",'consultas_ajax.php?id='+producto+'&orden='+orden+'&proceso='+id_proceso+'&ordenxproducto='+ordenxproducto);
	http.open('get', 'consultas_ajax.php?idp='+idp);
	http.onreadystatechange = handleResponse;
    http.send(null);
}

function mostrar_select(id,valor, sel) 
{
	//alert("llego: "+valor);
	/*return true;*/
	
	http.open('get', 'consultas_ajax.php?tipo='+id+'&valor='+valor+'&sel='+sel);
	http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() 
{
     if(http.readyState == 4)
	 {
          var response = http.responseText;
		  var update = new Array();

         //alert("va a poner sel"+response);
		 if(response.indexOf('@' != -1)) 
		  {
 			 //alert("va a poner sel"+response.split('@'));
			 update = response.split('@');
			//	alert(update[0]);
			//	alert(update[1]);

			  if(update[0]==1)
				{
				//alert("va a poner sel 1");
				document.getElementById('1').innerHTML = update[1];	
				try{
				document.getElementById('2').innerHTML = '';	
				document.getElementById('3').innerHTML = '';
				}catch(e){}
				z_ciudad=dhtmlXComboFromSelect("ciudad");
				var input_ciudad = document.getElementById('ciudad_al_cambiar');
				input_ciudad.value= "mostrar_select(2,z_ciudad.getSelectedValue())";
				}
				
				 if(update[0]==2)
				{
				//alert("va a poner sel");
				document.getElementById('2').innerHTML = update[1];	
				try{document.getElementById('3').innerHTML = '';	
				}catch(e) {}
				z_sector=dhtmlXComboFromSelect("sector");
				var input_sector = document.getElementById('sector_al_cambiar');
				input_sector.value= "mostrar_select(3,z_sector.getSelectedValue())";
				}
				
				if(update[0]==3)
				{
				//alert("va a poner sel");
				document.getElementById('3').innerHTML = update[1];	
				//alert('cc: '+document.getElementById('conjunto_cerrado').checked);
				if(!document.getElementById('conjunto_cerrado').checked)
					document.getElementById('3').style.display='none';	
				z_unidad=dhtmlXComboFromSelect("unidad");
				var input_unidad = document.getElementById('unidad_al_cambiar');
				input_unidad.value= "";
				}
				
				if(update[0]==4)
				{
					//alert("entro");
					document.getElementById('bus_ciudad').innerHTML = update[1];	
				}
          }
		
		
     }
}




function MM_swapImage() 
{ //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
   	if ((x=MM_findObj(a[i]))!=null)
	{
	   document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	}
}

function MM_swapImgRestore() 
{ //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) 
{ //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
    	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() 
{ //v3.0
	var d=document; 
	if(d.images)
	{ 
		if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0)
		{ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
		}
	}
}

var win = null;
function nueva_ventana(mypage,myname,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=yes'
	win = window.open(mypage,myname,settings)
}

function popup(theURL, winName,features)
{
	window.open(theURL, winName,features);
}


function validar_correo(nombre, email, mensaje)
{
	if(nombre=="")
	{
		alert("Debe ingresar el nombre");
		return false;
	}
	if(!validar_correo_e(email))
	{
		alert("Debe ingresar un correo electrónico válido");
		return false;
	}
	if(mensaje=="")
	{
		alert("Debe ingresar el mensaje");
		return false;
	}
	return true;
}

function validar_imagen(grafico)
{
	if(grafico=='')
	{
		alert("Debe seleccionar una imagen");
		return false;
	}
	return true;
}

function generar_inputs()
{
	var campos='';
	//alert(document.getElementById('num_niveles').value);
	if(document.getElementById('num_niveles').value>0)
	{
		for(ic=1; ic<=document.getElementById('num_niveles').value; ic++)
		{
			val=document.getElementById('nivel'+ic).value;	
			campos=campos+'<table class="formu"><td width="100">Nivel '+ic+' : </td><td><input type="text" name="nivel'+ic+'" id="nivel'+ic+'" value="'+val+'" onChange="calcular()"> mt</td></table>';
		}
	}
	
	document.getElementById('num_niveles').value = parseInt(document.getElementById('num_niveles').value)+1;
	campos=campos+'<table class="formu"><td width="100">Nivel '+document.getElementById('num_niveles').value+' : </td><td><input type="text" name="nivel'+document.getElementById('num_niveles').value+'" id="nivel'+document.getElementById('num_niveles').value+'" value="" onChange="calcular()"> mt</td></table>';
	//document.getElementById('niv').innerHTML = document.getElementById('niv').innerHTML+'<table class="formu"><td width="100">Nivel '+document.getElementById('num_niveles').value+' : </td><td><input type="text" name="nivel'+document.getElementById('num_niveles').value+'" id="nivel'+document.getElementById('num_niveles').value+'" value="" onChange="calcular()"> mt</td></table>';
	document.getElementById('niv').innerHTML = campos;
	//document.getElementById('niv').appendChild('<table class="formu"><td width="100">Nivel '+document.getElementById('num_niveles').value+' : </td><td><input type="text" name="nivel'+document.getElementById('num_niveles').value+'" id="nivel'+document.getElementById('num_niveles').value+'" value="" onChange="calcular()"> mt</td></table>');
	//var container = document.getElementById("niv"); 
	//container.appendChild('<div><table class="formu"><td width="100">Nivel '+document.getElementById('num_niveles').value+' : </td><td><input type="text" name="nivel'+document.getElementById('num_niveles').value+'" id="nivel'+document.getElementById('num_niveles').value+'" value="" onChange="calcular()"> mt</td></table></div>');

}

function calcular()
{
	//alert("entro"+document.getElementById('num_niveles').value);
	/*frente = document.getElemenById('frente').value;	fondo = document.getElemenById('fondo').value;
	area_lote = document.getElemenById('area_lote').value;  area_oficinas = document.getElemenById('area_lote').value;
	if(isNaN(frente))
	{
		alert("El valor debe ser númerico");	document.getElementById('valor'+i).value="";	return false;
	}*/
	
	suma=0;
	for(i=1; i<=document.getElementById('num_niveles').value; i++)
	{
		try
		{
			n=document.getElementById('nivel'+i).value;
			//alert("entro"+document.getElementById('nivel'+i).value);
			if(isNaN(n) || (n==''))
			{
				//alert("El área del nivel debe ser númerico");	
				document.getElementById('nivel'+i).value=0;
				return false;
			}
			suma=suma+parseFloat(n);
			document.getElementById('area_total').value=suma;	
		}
		catch(e)
		{
			//document.getElementById('area_total').value=suma;	
		}			
	}
}

//Mostrar u ocultar campos de texto
function accionar_car(id, num, accion)
{
	if(accion==1)
		dis='block';
	else
		dis='none';

	for(ci=1; ci<=num; ci++)	
		document.getElementById(id+ci).style.display=dis;				
}

function calcular_valores()
{
	try
	{
		precio_arriendo=document.getElementById('precio_arriendo').value;	
		if(isNaN(precio_arriendo) || (precio_arriendo==''))
		{
			alert("El precio de arriendo debe ser númerico.");	
			document.getElementById('precio_arriendo').focus();
			document.getElementById('precio_arriendo').value=0;
			return false;
		}
		
	}
	catch(e)
	{}
	
	try
	{
		var vmt=parseFloat(document.getElementById('precio_arriendo').value)/parseFloat(document.getElementById('area_total').value);
		//alert("entro1"+sprintf("%01.2f",vmt));
		document.getElementById('vmt').innerHTML = sprintf("%01.2f",vmt);
		document.getElementById('arriendo_mt').value = vmt;		
	}catch(e){}
	
	try
	{
		administracion=document.getElementById('administracion').value;	
		if(isNaN(administracion) || (administracion==''))
		{
			alert("El valor de la administración debe ser númerico");	
			document.getElementById('administracion').value=0;
			return false;
		}	
		var vmt_adm=parseFloat(document.getElementById('administracion').value)/parseFloat(document.getElementById('area_total').value);
		//alert("entro1"+sprintf("%01.2f",vmt));
		document.getElementById('vmt_adm').innerHTML = sprintf("%01.2f",vmt_adm);
		document.getElementById('valor_adm').value = vmt_adm;	
		
		precio_total_arriendo=parseFloat(document.getElementById('precio_arriendo').value)+parseFloat(document.getElementById('administracion').value);
		//alert(precio_total_arriendo);
		document.getElementById('ta').innerHTML = sprintf("%01.2f",precio_total_arriendo);
		document.getElementById('total_arriendo').value = precio_total_arriendo;	
		
		
		por_iva=document.getElementById('por_iva').value;	
		if(isNaN(por_iva) || (por_iva==''))
		{
			alert("El porcentaje debe ser númerico");	
			document.getElementById('por_iva').value=0;
			return false;
		}	
				
		var iva=document.getElementById('total_arriendo').value*(document.getElementById('por_iva').value/100);
		document.getElementById('arriendo_iva').innerHTML =sprintf("%01.2f",iva); //arriedno iva
		document.getElementById('pesos_iva').value=iva;
		
		if(document.getElementById('arr_incluida').checked)
		{
			document.getElementById('fin_arriendo').innerHTML=sprintf("%01.2f",parseFloat(document.getElementById('total_arriendo').value));
			document.getElementById('mt_fin_arriendo').innerHTML=sprintf("%01.2f",(parseFloat(document.getElementById('total_arriendo').value))/parseFloat(document.getElementById('area_total').value));
		}
		else
		{
			document.getElementById('fin_arriendo').innerHTML=sprintf("%01.2f",parseFloat(document.getElementById('total_arriendo').value)+iva);
			document.getElementById('mt_fin_arriendo').innerHTML=sprintf("%01.2f",(parseFloat(document.getElementById('total_arriendo').value)+iva)/parseFloat(document.getElementById('area_total').value));
			
		}
		//document.getElementById('mt_iva').innerHTML = document.getElementById('por_iva').value;
		//document.getElementById('mt_por_iva').value = document.getElementById('por_iva').value;	
		
	}
	catch(e)
	{}
	
	try
	{
		var vmt_adm=parseFloat(document.getElementById('precio_venta').value)/parseFloat(document.getElementById('area_total').value);
		//alert("entro1"+sprintf("%01.2f",vmt));
		document.getElementById('mt_venta').innerHTML = sprintf("%01.2f",vmt_adm);
		document.getElementById('venta_mt').value = vmt_adm;	
	}
	catch(e)
	{}
}

function sprintf()
		{
			if (!arguments || arguments.length < 1 || !RegExp)
			{
				return;
			}
			var str = arguments[0];
			var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
			var a = b = [], numSubstitutions = 0, numMatches = 0;
			while (a = re.exec(str))
			{
				var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
				var pPrecision = a[5], pType = a[6], rightPart = a[7];
				
				//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

				numMatches++;
				if (pType == '%')
				{
					subst = '%';
				}
				else
				{
					numSubstitutions++;
					if (numSubstitutions >= arguments.length)
					{
						alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
					}
					var param = arguments[numSubstitutions];
					var pad = '';
					       if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
					  else if (pPad) pad = pPad;
					var justifyRight = true;
					       if (pJustify && pJustify === "-") justifyRight = false;
					var minLength = -1;
					       if (pMinLength) minLength = parseInt(pMinLength);
					var precision = -1;
					       if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
					var subst = param;
					       if (pType == 'b') subst = parseInt(param).toString(2);
					  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
					  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
					  else if (pType == 'u') subst = Math.abs(param);
					  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
					  else if (pType == 'o') subst = parseInt(param).toString(8);
					  else if (pType == 's') subst = param;
					  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
					  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
				}
				str = leftpart + subst + rightPart;
			}
			return str;
		}
		
		
		
function ocultar(id, i)
{
	if(i>=1)
	{
		document.getElementById(id).style.display='none';	
	}
	if(i==1)
	{
		
	//document.getElementById(i).style.color='#58595B';	
	//document.getElementById(i).style.background='url(img/botong.jpg) no-repeat';	
	
	//si se quiere contar al inicio poner aqui guardar clic
	/*http.open('get', 'conteo.php?id='+id+'&tipo=A');
	http.onreadystatechange = handleResponse;
    http.send(null);*/

	}
}

function mostrar(id, arreglo, num, carpeta)
{
	var tam=arreglo.length;
	//alert(tam+"ss"+arreglo[1]);
	for(i=1; i<tam; i++)
	{
	document.getElementById(arreglo[i]).style.display='none';		
	document.getElementById(i).style.color='#F0EEFF';		
	document.getElementById(i).style.background='url('+carpeta+'img/botonb.jpg) no-repeat';
	//document.getElementById(i).style.background-repeat='no-repeat';
	}

	document.getElementById(id).style.display='block';	
	document.getElementById(num).style.color='#58595B';	
	document.getElementById(num).style.background='url('+carpeta+'img/botong.jpg) no-repeat';
	//document.getElementById(num).style.background-repeat='no-repeat';

	/*http.open('get', 'conteo.php?id='+id+'&tipo=A');
	http.onreadystatechange = handleResponse;
    http.send(null);*/
}


function mostrar_ficha(id, arreglo, num, carpeta)
{
	var tam=arreglo.length;
	//alert(tam+"ss"+arreglo[1]);
	for(i=1; i<tam; i++)
	{
	document.getElementById(arreglo[i]).style.display='none';		
	document.getElementById(i).style.color='#F0EEFF';		
	document.getElementById(i).style.background='url('+carpeta+'img/boton_azul.jpg) no-repeat';
	
	}

	document.getElementById(id).style.display='block';	
	document.getElementById(num).style.color='#58595B';	
	document.getElementById(num).style.background='url('+carpeta+'img/boton_gris.jpg) no-repeat';
	
}

function chequear(nombre)
{
	if(document.getElementById(nombre).checked)
		document.getElementById(nombre).click();	
}

function validar_mas_info(nom, em, tel, celular)
{
	//alert(tel);
	if(nom == "")
	{
		alert("Debe ingresar su nombre");
		return false;
	}
	
	if(tel=="")
	{
		alert("Debe ingresar su teléfono");
		return false;
	}
	
	if(celular=="")
	{
		alert("Debe ingresar su número de celular");
		return false;
	}
	
	if(!validar_correo_e(em))
	{
		alert("Debe ingresar un correo electrónico válido");
		return false;		
	}	
	
	return true;	
}

function validar_amigo(nombre, email, nombrea, emaila)
{
	if(nombre=="")
	{
		alert("Debe ingresar el nombre");
		return false;
	}
	if(!validar_correo_e(email))
	{
		alert("Debe ingresar un correo electrónico válido");
		return false;
	}
	if(nombrea=="")
	{
		alert("Debe ingresar el nombre de su amigo");
		return false;
	}
	if(!validar_correo_e(emaila))
	{
		alert("Debe ingresar un correo electrónico válido para su amigo");
		return false;
	}
	return true;
}

function preview(cad, texto, w, h, scroll)
{ 
    var windoew ;
    windoew = window.open(cad, texto, "location=no,height="+ h + ",width=" + w + ",scrollbars=" + scroll);
}

