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];}}
}

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_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_jumpMenu(targ,selObj,restore){ //v3.0
  alert("Entre");  
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}*/

function validarForm() {
	if(document.formIndex.moto1.value == 0 || document.formIndex.moto2.value == 0) {
		alert("Debe seleccionar dos motos para comparar");
		return false;
	}
	document.formIndex.action = "http://motos.motos.es/comparador_motos.php";
	document.formIndex.submit();
}

function check_date(dia, mes, anio){
	arrMeses = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
	
	if (((anio % 4 == 0) && (anio % 100 != 0)) || (anio % 400 == 0)) {
		arrMeses[2] = 29;
	}	
	
	if (dia > arrMeses[mes]){
		alert("fecha incorrecta");
		return false;
	}
	return true;
}


function check_email(email){
var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/; 
if (!re_mail.test(email.value)) { 

alert("Email inválido!");	
return false; 
}

return true; 

}

function allowOnly(r)
{
    reg = new RegExp(r)
    return reg.test(String.fromCharCode(window.event.keyCode));
}

function hasInvalidCharacters(str) {
	for(i=0; i<str.length; i++) {
		if(str.charAt(i) == ' ' || str.charAt(i) == '"' || str.charAt(i) == "'") {
			return true;
		}
	}
	
	return false;
}

function validar(){
	if (document.registerForm.userName.value==""){ alert("Debe ingresar un nombre de usuario"); return false;}
	if (document.registerForm.password.value==""){ alert("Debe ingresar un password"); return false;}
	if (document.registerForm.email.value==""){ alert("Debe ingresar un email"); return false;}
	if (document.registerForm.password.value != document.registerForm.passwordVal.value) {
		alert("El password y la confirmación no coinciden");
		return false;
	}
	if(hasInvalidCharacters(document.registerForm.userName.value)) {
		alert("El nombre de usuario no es válido");
		return false;
	}
	if(hasInvalidCharacters(document.registerForm.password.value)) {
		alert("El password no es válido");
		return false;
	}
	if(hasInvalidCharacters(document.registerForm.email.value)) {
		alert("El email no es válido");
		return false;
	}
	if(!document.registerForm.terminosDelRegistro.checked) {
		alert("Debe de aceptar los términos del registro");
		return false;
	}
	
	return check_email(document.registerForm.email);
}

function popup() {
	//window.open("terminosYCondiciones.php", "", "height=450,width=566,status=yes,toolbar=no,menubar=no,scrollbars=yes,location=no,top=450,left=300");
	window.open('http://usuarios.motos.es/terminosYCondicionesRegistro.php', "", "height=450,width=566,status=yes,toolbar=no,menubar=no,scrollbars=yes,location=no,top=450,left=300");
	
	return false;
}
function mostrarImagen(imagen) {	
	document.getElementById('fotoGrande').src = imagen;
	document.getElementById('fotoGrande').width = 350;
	document.getElementById('fotoGrande').height = 280;
}
function validarFormS1() {
		
		if(document.buscadorPForm.frase.value == "") {
			alert("Debe ingresar un texto");
			return false;
		}else if((!document.buscadorPForm.motos.checked) && (!document.buscadorPForm.compraVenta.checked) && (!document.buscadorPForm.foros.checked)){
			alert("Selecciona un seccion");
			return false;
		}
	}
function validarFormContacto(){
	if(document.frmContacto.nombre.value==""){alert("Ingrese un nombre por favor!");return false;}
	if(document.frmContacto.email.value==""){alert("Ingrese un email por favor!");return false;}
	if (!check_email(document.frmContacto.email)){return false;}
	//if(document.getElementById("mensaje").innerText==""){
	if(document.frmContacto.mensaje.value==""){
		alert("Por favor, ingrese un mensaje");
		return false;
	}
	return true;
}
function openPopup(idNoticia, idImagen) {
	mywindow=window.open("imagenes_noticias_popup.php?idNoticia="+idNoticia+"&idImagen="+idImagen, "ImagenesdelaNoticia", "height=450,width=570,status=yes,toolbar=no,menubar=no,scrollbars=yes,location=no,top=450,left=300");
}

function emoticon(text) {
	var txtarea = document.comentarios.comentario;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}
function validarFormComparar() {
	if(document.formIndex.moto1.value == 0 || document.formIndex.moto2.value == 0) {
		alert("Debe seleccionar dos motos para comparar");
		return false;
	}
	document.formIndex.action = "http://motos.motos.es/comparador_motos.php";
	document.formIndex.submit();
}