// JavaScript Document

function cambiarPosicionNoticia(id,pos1,pos2){
	//alert(id + " " + pos1 + " " + pos2);
	location.href="cambiarPosNoticia.asp?idNoticia=" + id + "&pos1=" + pos1 + "&pos2=" + pos2;
}

function cambiarPosicionNovia(id,pos1,pos2){
	//alert(id + " " + pos1 + " " + pos2);
	location.href="cambiarPosNovia.asp?idNoticia=" + id + "&pos1=" + pos1 + "&pos2=" + pos2;
}

function validarForm(form){
	
	if (!esFecha(form.txtFecha.value)) {
		alert("Fecha incorrecta! Formato correcto: dd/mm/aaaa");
		return false;
	}
	
	return true;	
}


function esFecha(Cadena){
	
	//Format correcte dd/mm/aaaa
	
	var Fecha= new String(Cadena)	// Crea un string
	var RealFecha= new Date()	// Para sacar la fecha de hoy
	
	
	// comprovar si té el format adecuat amb barres "/"
	
	if (Fecha.lastIndexOf("/")==-1) return false;	
	
	// Cadena Año
	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))
	// Cadena Mes
	var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))
	// Cadena Día
	var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))

	// Valido el año
	
	if (Ano.length<4)
		Ano="20"+Ano
		
	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900 || parseFloat(Ano)>3000 ){
        alert('Año inválido')
		return false
	}
	// Valido el Mes
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
		alert('Mes inválido')
		return false
	}
	// Valido el Dia
	if (isNaN(Dia) || parseFloat(Dia)<1 || parseFloat(Dia)>31){
		alert('Día inválido')
		return false
	}
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if (Mes==2 && Dia > 28 || Dia>30) {
			alert('Día inválido')
			return false
		}
	}
	
  return true;

}

function reescalaH(img,h){
	var w
	
	
	
	w = h * img.width / img.height;
	//alert (w + " x " + h );//+ "= "
	
	img.width = w;
	img.height = h;
	
}
