// JavaScript Document
function abrir_ventana(url,l,t,w,h,s){
	window.open(url,'ventana','left=' + l +',top=' + t + ',width=' + w + ',height=' + h + ',scrollbars=' + s);
}
function login_f(){
	var f=document.frm_crear_usuario;
	if (f.login.value==''){
	   f.Submit.disabled="true";
       alert("Debes ingresar un login");	
	}else{
	   f.Submit.disabled="";		
	}
}
function pass_f(){
	var f=document.frm_crear_usuario;
	if (f.password.value==''){
	   f.Submit.disabled="true";
       alert("Debes ingresar un password");	
	}else{
	   f.Submit.disabled="";		
	}
}
function rety_f(){
	var f=document.frm_crear_usuario;
	if (f.conf_password.value==''){
	   f.Submit.disabled="true";
       alert("Debes repetir el password ingresado en el campo anterior");
	}else{
	  if(f.conf_password.value==f.password.value){
	     f.Submit.disabled="";
	  }else{
	   f.Submit.disabled="true";
       alert("Los passwords deben ser iguales");
      }
	}
}
function nom_f(){
	var f=document.frm_crear_usuario;
	if (f.nombre.value==''){
	   f.Submit.disabled="true";
       alert("Debes ingresar tu nombre");	
	}else{
	   f.Submit.disabled="";		
	}
}
function ape_f(){
	var f=document.frm_crear_usuario;
	if (f.apellidos.value==''){
	    f.Submit.disabled="true";
        alert("Debes ingresar tus apellidos");	
	}else{
	   f.Submit.disabled="";		
	}
}
function validateJoin(){
	var f=document.forms[0];
	
	if(f.username.value==""){
		alert("Please enter a User Name");
		f.username.focus();
		return;
	}
	if(f.username.value==""){
		alert("Please enter a User Name");
		f.username.focus();
		return;
	}
	if(f.username.value.length <4 || f.username.value.length >12){
		alert("The username Must be between (4-12 characters; no spaces)");
		f.username.focus();
		return;		
	}
	if(f.password.value==""){
		alert("Please enter a password");
		f.password.focus();
		return;
	}
	if(f.password.value!=f.password2.value){
		alert("Passwords does not match");
		f.password2.focus();
		return;
	}
	if(f.email.value==""){
		alert("Please enter an email");
		f.email.focus();
		return;
	}
	if(f.email.value!=f.email2.value){
		alert("Emails does not match");
		f.email2.focus();
		return;
	}
	if(f.year.value=="00"){
		alert("Please select a valid Year");
		f.year.focus();
		return;
	}
	if(f.month.value=="00"){
		alert("Please select a valid Month");
		f.month.focus();
		return;
	}
	if(f.day.value=="00"){
		alert("Please select a valid Day");
		f.day.focus();
		return;
	}
	if(f.zip.value==""){
		alert("Please enter a zip code");
		f.zip.focus();
		return;
	}
	if(f.occupation.value=="00"){
		alert("Please enter your Occupation");
		f.occupation.focus();
		return;
	}
	if(f.city.value==""){
		alert("Please enter your City");
		f.city.focus();
		return;
	}
	if(f.state.value=="00"){
		alert("Please enter your State");
		f.state.focus();
		return;
	}
	if(f.country.value=="00"){
		alert("Please enter your Country");
		f.country.focus();
		return;
	}
	if(!f.agree.checked){
		alert("Please check that you have read the members agreement");
		f.agree.focus();
		return;		
	}
	
	f.actioncode.value="join member";
	f.submit();
}

function validateLogin(){
	var f=document.form1;

	if(f.login_username.value==""){
		alert("Please enter a Username");
		f.login_username.focus();
		return;
	}
	if(f.login_username.value.length<4 || f.login_username.value.length>12){
		alert("The username Must be between (4-12 characters; no spaces)");
		f.login_username.focus();
		return;		
	}

	if(f.login_password.value==""){
		alert("Please enter a password");
		f.login_password.focus();
		return;
	}

	f.actioncode.value="login member";
	f.submit();
}

function validate_search(){
	var f=document.search_form;
	window.location="search.php?q="+f.buscar.value;
}

function validateInviteFriend(){
	var f=document.form1;

	if(f.email_referer.value==""){
		alert("Please enter your email address");
		f.email_referer.focus();
		return;
	}
	if(f.recipients.value==""){
		alert("Please enter your friend(s) email address(es)");
		f.recipients.focus();
		return;
	}
	f.actioncode.value="invite friend";
	f.submit();
	
}


function cb_link(url){
	var f=document.form1;
	open(url+"&name="+f.name.value+"&email="+f.email.value,'clickbank','widht=600,height=400,menubar=yes,resizable=yes,location=yes');
}

function validateContactUs(){
	var f=document.form1;

	if(f.email.value==""){
		alert("Please enter your email address");
		f.email.focus();
		return;
	}
	if(f.name.value==""){
		alert("Please enter your name");
		f.name.focus();
		return;
	}

	if(f.subject.value==""){
		alert("Please enter a subject for the message");
		f.subject.focus();
		return;
	}

	if(f.message.value==""){
		alert("Please enter a message");
		f.message.focus();
		return;
	}


	f.actioncode.value="contact us";
	f.submit();
}

function ventana_agregar_cotizacion(id_producto){
	window.open("agregar_cotizacion.php?id="+id_producto,"agregar_cotizacion","width=500,height=200,left=300,top=250,scrollbars=1");
}

function confirmar_borrar_puerto(id,puerto){
	if(confirm("Realmente desea borrar el puerto " + puerto + "?")){
		window.location="borrar_puerto.php?id="+id;
	}
}

function foto_siguiente(img){
	if((foto_actual+1)<cantidad_fotos){
		img.src=imagenes[++foto_actual].src;
	}
}

function foto_anterior(img){
	if((foto_actual+1)>1)
		img.src=imagenes[--foto_actual].src;
}

function preloadImages(){
  if(document.images)  {
    var i,j = imagenes.length;
	var args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++){
      if (args[i].indexOf("#")!=0){
        imagenes[j] = new Image;
        imagenes[j++].src = args[i];
      }
    }
  }
}


function findObj(theObj, theDoc){
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


function cambiar_contenido_div(div,contenido){
	var d = findObj(div);
	try{
		d.innerHTML=contenido;
	}catch(e){
		d.innerTEXT=contenido;
	}
}


function ancho_pantalla(){
	var screenW = 640, screenH = 480;
	if (parseInt(navigator.appVersion)>3) {
		screenW = screen.width;
		screenH = screen.height;
	}
	else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled()) {
		var jToolkit = java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize = jToolkit.getScreenSize();
		screenW = jScreenSize.width;
		screenH = jScreenSize.height;
	}
	return(screenW);
}
function alto_pantalla(){
	var screenW = 640, screenH = 480;
	if (parseInt(navigator.appVersion)>3) {
		screenW = screen.width;
		screenH = screen.height;
	}
	else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled()) {
		var jToolkit = java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize = jToolkit.getScreenSize();
		screenW = jScreenSize.width;
		screenH = jScreenSize.height;
	}
	return(screenH);
}


//Cambiar visibilidad

IE4 = (document.all) ? 1 : 0; // initialize browser.. 
NS4 = (document.layers) ? 1 : 0; // identification and... 
ver4 = (IE4 || NS4) ? 1 : 0; // DHTML variables 
var visibilidad_actual='invisible';

function mostrar_solo(i){
	var a=0;
	var t;
	for(a=1;a<=3;a++){
		t = document.getElementById('titulo_paso'+a);
		if(a==i){
			t.className='TituloPasoSeleccionado';
			cambiar_visibilidad_a(a,'visible')
		}else{
			t.className='TituloPasoNormal';
			cambiar_visibilidad_a(a,'invisible')
		}
	}
	window.location='#top';
}

function mostrar_solo1(element_id){
	var t;
	var i=0;
	var filas=document.getElementsByTagName('tr');
	for(i=0; i<filas.length; i++){
		if(filas[i].id.substr(0,11)=='comentarios'){
			//alert(filas[i].id);
			if(filas[i].id=='comentarios'+element_id){
				cambiar_visibilidad_a(filas[i].id,'visible');
			}else{
				cambiar_visibilidad_a(filas[i].id,'invisible');			
			}
		}
	}
}


function cambiar_visibilidad_a(i,vis){
	var e = document.getElementById(i);
	e.className=vis;
}


function cambiar_visibilidad(i){
	var e = document.getElementById('paso'+i);
	if (e.className=='visible'){
		e.className='invisible';
	}else{
		e.className='visible';	
	}
}

function cambiar_visibilidad_todos(){
	var i, e, img, img_todos;
	img_todos = document.getElementById('drill_todos');
	
	if (visibilidad_actual == 'invisible'){
		visibilidad_actual = 'visible';
		img_todos.src='/imagenes/drill_up.gif';
	}else{
		visibilidad_actual = 'invisible';
		img_todos.src='/imagenes/drill_down.gif';
	}
	
	
	for (i=1;i<=filas;i++){
		e = document.getElementById('gestiones' + i);
		img = document.getElementById('drill' + i);
		e.className=visibilidad_actual;
		if (visibilidad_actual=='invisible'){
			img.src='/imagenes/drill_down.gif';
		}else{
			img.src='/imagenes/drill_up.gif';	
		}
	}
}

function agregar_fila(objeto){
	num_fila=num_fila+1;
	document.frm_inmueble.cantidad_fotos.value=num_fila;
	var t=findObj(objeto);
	var a;
	var fila = document.createElement('tr');
	t.appendChild(fila);
	var celda1 = document.createElement("td");
	var celda2 = document.createElement("td");
	fila.appendChild(celda1);
	fila.appendChild(celda2);

	var input_file=document.createElement('input');
	input_file.setAttribute('TYPE','file');
	input_file.setAttribute('NAME','foto' + num_fila);
	input_file.setAttribute('ID','foto' + num_fila);
	celda1.appendChild(input_file);	
}

function confirmar_borrar(login){
	if(confirm('Desea borrar el usuario ' + login + '?.\nNo se puede deshacer esta operacion')){
			window.location='borrar_usuario.php?login='+login;
	}
}
function confirmar(mensaje,url){
	if(confirm(mensaje)==true){
		window.location=url;
	}
}

function verify_form(f){
	var i=0;
	for(i=0; i<f.elements.length; i++){
		switch(f.elements[i].type){
			case 'password':	if(f.elements[i].alt=='MANDATORY' && f.elements[i].value==""){
									alert('Por favor ingrese '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								if(f.elements[i].name=='password' && f.elements['confirmpassword'].value!=f.elements[i].value){
									alert('Password confirmation does not match');
									f.elements[i].focus();
									return(false);
								}								
								break;
			case 'text':		if(f.elements[i].alt=='MANDATORY' && f.elements[i].value==""){
									alert('Por favor ingrese '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;
			case 'checkbox':	if(f.elements[i].alt=='MANDATORY' && !f.elements[i].checked){
									alert('Por favor chequee '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;
		}
	}
	return(true);
}

///

function verify_form2(f){
	var i=0;
	for(i=0; i<f.elements.length; i++){
		switch(f.elements[i].type){
			case 'password':	if(f.elements[i].alt=='MANDATORY2' && f.elements[i].value==""){
									alert('Por favor ingrese '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								if(f.elements[i].name=='password' && f.elements['confirmpassword'].value!=f.elements[i].value){
									alert('Password confirmation does not match');
									f.elements[i].focus();
									return(false);
								}								
								break;
			case 'text':		if(f.elements[i].alt=='MANDATORY2' && f.elements[i].value==""){
									alert('Por favor ingrese '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;
			case 'checkbox':	if(f.elements[i].alt=='MANDATORY2' && !f.elements[i].checked){
									alert('Por favor chequee '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;
		}
	}
	return(true);
}

//
function verify_form3(f){
	var i=0;
	for(i=0; i<f.elements.length; i++){
		switch(f.elements[i].type){
			case 'password':	if(f.elements[i].alt=='MANDATORY3' && f.elements[i].value==""){
									alert('Por favor ingrese '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								if(f.elements[i].name=='password' && f.elements['confirmpassword'].value!=f.elements[i].value){
									alert('Password confirmation does not match');
									f.elements[i].focus();
									return(false);
								}								
								break;
			case 'text':		if(f.elements[i].alt=='MANDATORY3' && f.elements[i].value==""){
									alert('Por favor ingrese '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;
			case 'checkbox':	if(f.elements[i].alt=='MANDATORY3' && !f.elements[i].checked){
									alert('Por favor chequee '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;
		}
	}
	return(true);
}
//
function verify_form4(f){
	var i=0;
	for(i=0; i<f.elements.length; i++){
		switch(f.elements[i].type){
			case 'password':	if(f.elements[i].alt=='MANDATORY4' && f.elements[i].value==""){
									alert('Por favor ingrese '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								if(f.elements[i].name=='password' && f.elements['confirmpassword'].value!=f.elements[i].value){
									alert('Password confirmation does not match');
									f.elements[i].focus();
									return(false);
								}								
								break;
			case 'text':		if(f.elements[i].alt=='MANDATORY4' && f.elements[i].value==""){
									alert('Por favor ingrese '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;
			case 'checkbox':	if(f.elements[i].alt=='MANDATORY4' && !f.elements[i].checked){
									alert('Por favor chequee '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;
		}
	}
	return(true);
}

function EditarTD(td){
	cambiar_contenido_div(td.id,'<input type="text" value="'+td.innerHTML+'" style="width:100%" class="textosh" id="Edicion'+td.id+'">');
}