﻿function email(theElement,idioma)
{

var s = theElement.value;
var filter=/^[A-Za-z][A-Za-z0-9_\-\.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
if (s.length == 0 ) return true;
if (filter.test(s))
return true;
else{
   if (idioma==1) alert('E-mail incorrecto'); else alert('Incorrect E-mail');
   theElement.focus();
   return false;
}
}

function isEmpty(s)	{
	return ((s == null) || (s.length == 0))
}

function isDigit(c) {   
	return ((c >= "0") && (c <= "9"))
}
function isChar(c) {   
	return ((c >= "A") && (c <= "z"))
}
function isInteger(s) {
	var i;
    for (i = 0; i < s.length; i++) 
        if (!isDigit(s.charAt(i))) return false;
    return true;
}
function isValidYear(y) {
	if (y.length>0){
 if ((y.length==4)&&(isDigit(y)))
    return true;
 else
    return false;} 
 else return true;
}
function decimal(objName, long)   
 {                                      
if (!/^([0-9])*[.]?([0-9])*$/.test(objName.value)) 
return false;
else
return true;
}

function ValidateForm(f,idioma) {
 	var correo = f.correo.value;
	var errors = 0;
	var comentario = f.coment.value;
	
	if (isEmpty(correo)) {
		if (idioma==1) alert('Escriba el E-mail'); else alert('Write your E-mail address');
		  errors = 1;
	}else{
		if (isEmpty(comentario)) {
			     if (idioma==1) alert('Escriba su comentario'); else alert('Write your comment');
				errors = 1;	
				}			     
		}	
 	return (errors==0);
}

function ValidateForm2(f,idioma) {
 	var correo = f.correo.value;
	var comentario = f.coment.value;
	var errors = 0;
	var terminos = f.terminos.checked;
	
	if (isEmpty(correo)) {
		if (idioma==1) alert('Escriba el E-mail'); else alert('Write your E-mail address');
		  errors = 1;
	}else{
		if (isEmpty(comentario)) {
			if (idioma==1) alert('Escriba su comentario'); else alert('Write your comment');
		  errors = 1;
		}else{
			if (!(terminos)) {
			     if (idioma==1) alert('Debe aceptar los Términos de Uso'); else alert('You must accept the Terms');
				errors = 1;	
				}
		      }
		}	
 	return (errors==0);
}

function ValidateForm3(f,idioma) {
 	var tit = f.titulo.value;
	var cp=f.codigopostal.value;
	var precio=f.precio.value;
	var cuartos=f.cuartos.value;
	var bannos=f.bannos.value;
	var correo = f.correo.value;
	var correo2 = f.correo2.value;
	var ciudad = f.ciudad.value;
	var tipo = f.oper.value;
	var subcat = f.subcateg.value;
	var estado = f.estado.value;
	
	
	
	var errors = 0;
	var terminos = f.terminos.checked;
	
	if ((isEmpty(tit))||(isEmpty(estado))||(isEmpty(ciudad))||(isEmpty(tipo))||(isEmpty(subcat))||(isEmpty(cp))||(isEmpty(precio))|| (isEmpty(cuartos))||(isEmpty(bannos))||(isEmpty(correo))||(isEmpty(correo2))){
		if (idioma==1) alert('Faltan datos obligatorios por especificar'); else alert('Complete the obligatories fields');
		  errors = 1;
	}else{
		if (!(correo==correo2)) {
			if (idioma==1) alert('El E-mail y su confirmación no coinciden'); else alert('The E-mail and its confirmation are differents');
			errors = 1;	
			} 
			else {
				if (!(terminos)) {
			     if (idioma==1) alert('Debe aceptar los Términos de Uso'); else alert('You must accept the Terms');
				errors = 1;	
				}
		       }	
	     }
 	return (errors==0);
}

function ValidateForm4(f,idioma) {
 	
	var correo = f.correo.value;
	var nombre = f.nombre.value;
	var pass = f.passw.value;
	var pass2 = f.passw2.value;	
	var terminos = f.terminos.checked;
	
	var errors = 0;	
	
	if ((isEmpty(pass))||(isEmpty(pass2))||(isEmpty(nombre))||(isEmpty(correo))){
		if (idioma==1) alert('Faltan datos obligatorios por especificar'); else alert('Complete the obligatories fields');
		  errors = 1;
	}else{
		if (!(pass==pass2)) {
			if (idioma==1) alert('La Clave y su confirmación no coinciden'); else alert('The password and its confirmation are differents');
			errors = 1;	
			} 
			else {
				if (!(terminos)) {
			     if (idioma==1) alert('Debe aceptar los Términos de Uso'); else alert('You must accept the Terms');
				errors = 1;	
				}
		       }	
	     }
 	return (errors==0);
}

function ValidateForm5(f,idioma) {
 	
	var correo = f.correo.value;
	var errors = 0;	
	
	if (isEmpty(correo)){
		if (idioma==1) alert('Escriba el E-mail'); else alert('Write your E-mail address');
		  errors = 1;
	}
 	return (errors==0);
}


function ValidateForm6(f,idioma) {
 	
	var nombrefoto = f.foto1.value;
	var opc=f.opcion.value;
	var tam=nombrefoto.length;
	var pos=tam-4;
	var errors = 0;	
	
	if (opc=="ins"){
	
	if (isEmpty(nombrefoto)){
		if (idioma==1) alert('Seleccione la foto'); else alert('Select the picture');
		  errors = 1;
	}
	else{
		var ext=nombrefoto.substr(pos);		
		if ((!(ext==".GIF"))&&(!(ext==".JPG"))&&(!(ext==".gif"))&&(!(ext==".jpg"))){
			if (idioma==1) alert('Solo ficheros .GIF o .JPG son permitidos'); else alert('Only files .GIF or .JPG are permitted');
			errors = 1;
			}			
		}
	}
 	return (errors==0);
}


function ValidateForm7(f,idioma) {
 	
	var nombrevideo = f.video.value;
	var opc=f.opcion.value;
	var tam=nombrevideo.length;
	var pos=tam-4;
	var errors = 0;	
	
	if (opc=="ins"){
	
	if (isEmpty(nombrevideo)){
		if (idioma==1) alert('Seleccione el video'); else alert('Select the video');
		  errors = 1;
	}
	else{
		var ext=nombrevideo.substr(pos);		
		if ((!(ext==".flv"))&&(!(ext==".FLV"))){
			if (idioma==1) alert('El video debe estar en formato FLV (Flash Video)'); else alert('The video must be FLV format (Flash Video)');
			errors = 1;
			}			
		}
	}
 	return (errors==0);
}

function ValidateForm8(f,idioma) {
var correo = f.correo.value;
var correo2 = f.correo2.value;
var comentario=f.coment.value;
	var errors = 0;	
	
	if (isEmpty(correo)){
		if (idioma==1) alert('Escriba el E-mail del remitente'); else alert('Write the source E-mail address');
		  errors = 1;
	}
	else{
		if (isEmpty(correo2)){
		  if (idioma==1) alert('Escriba el E-mail del destinatario'); else alert('Write the target E-mail address');
		  errors = 1;
		}
		else {
			 if (comentario.length>150) {
			  if (idioma==1) alert('Solo se permiten 150 caracteres'); else alert('Only 150 characters are permitted');
		      errors = 1;}
			}
	}
	
 	return (errors==0);
}


function cambiaimg(cod, fichero, titulo){
	var fichero="../fotos/"+cod+"/"+fichero;
	document.big.src=fichero;
	var key=document.getElementById("piefoto");
	key.innerHTML=titulo;
}

function cambiaimg2(cod, ficheroorig, titulo){
	var fichero="../fotos/"+cod+"/"+ficheroorig;
	document.big.src=fichero;
	var key=document.getElementById("piefoto");
	key.innerHTML=titulo;
	var key2=document.getElementById("nombrefoto");
	key2.innerHTML="("+ficheroorig+")";
}

function cursor(t){
	t.style.cursor="hand";
	}
	
	
function stopvideo(){
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;
var nn = document.layers ? true:false;
var ie = document.all ? true:false;
document.pelicula.src="../images/videostop.jpg";
if(ie4){
document.all.parar.style.display = "none";
document.all.play.style.display = "";
document.pelicula.dynsrc="";
}
else{
if(nn4){
document.parar.visibility = "hidden";
document.play.visibility = "visible";
document.pelicula.dynsrc="";
} else if(dom){
	document.getElementById("parar").style.display = "none";
	document.getElementById("play").style.display = "";
	document.getElementById("pelicula").dynsrc="";
	}	
} 
}

function playvideo(file1){
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;
var nn = document.layers ? true:false;
var ie = document.all ? true:false;

if(ie4){
document.all.parar.style.display = "";
document.all.play.style.display = "none";
document.pelicula.dynsrc=file1;
}
else{
if(nn4){
document.parar.visibility = "visible";
document.play.visibility = "hidden";
document.pelicula.dynsrc=file1;
} else if(dom){	
	document.getElementById("parar").style.display = "";
	document.getElementById("play").style.display = "none";
	document.getElementById("pelicula").dynsrc=file1;
	}	
} 
}




