// funcions de Validacio i canvis dinamics en JavaScript

function VeureOrfe(pagina) {
   if(self.top==self) location.href='http://www.mamv.net/index.html';
}

function Menu(opcio,ruta) {
	switch(opcio) {
	case 1: // index
		window.top.location.href=ruta+'index.html';
		break;
	case 2: // Nosaltres
		window.top.location.href=ruta+'nosaltres.html';
		break;
	case 3: // cataleg
		window.top.location.href=ruta+'cataleg/fnsInicial.php?accio=0&f=0';
		break;
	case 4: // on comprar
		window.top.location.href=ruta+'serveis/fnsOnComprar.html';
		break;
	case 5: // competició
		break;
	case 6: // Noticies
		window.top.location.href=ruta+'noticies/fnsNoticia.php?accio=0';
		break;
	case 7: // Contacte
		window.top.location.href=ruta+'contacte.html';
		break;
	case 8: // validacio d'usuari
		open(ruta+'funcions/frmAcces.html','_blank','top=100, left=200, height=240, width=500');
		break;
	}
}

function ValidaData(strData)
{
	var separador=strData.substr(2,1);
	if(separador!='-' && separador!='/' && separador!='.') return false;
	if(strData.length!=10) return false;
	if(strData.charAt(5)!=separador) return false;
	part=strData.substr(0,2);
	if(isNaN(part)) return false;
	if(part<1 || part>31) return false;
	part=strData.substr(3,2);
	if(isNaN(part)) return false;
	if(part<1 || part>12) return false;
	part=strData.substr(6);
	if(isNaN(part)) return false;
	return true;
}

function ValidaMail(strMail) {
  var patro=/^[a-z]([\w\.]*)(-*)([\w\.]*)@[a-z]([\w\.]*)(-*)([\w\.]*)\.[a-z]{2,4}$/;
  resultat=patro.test(strMail);
  return resultat;
}

function ValidaCompte(strCompte) {
	var patro=/^[0-9]{4}[\-][0-9]{4}[\-][0-9]{2}[\-][0-9]{10}/;
	resultat=patro.test(strCompte);
	return resultat;
}

function ValidaNombre(strValor)
{
	var esValid=true;
	n=strValor.indexOf(".");
	if(n>-1) {
		part=strValor.substr(n+1);
		if(part.indexOf(".")>-1) return false; // tenim dos punts decimals
		if(isNaN(part)) return false;	
		strValor=strValor.substr(0,n); // ens quedem sense la part decimal si la n'hi havia
	}
	if(!isNaN(strValor)) return true;
	llarg=strValor.length;
	if(llarg<4 && isNaN(strValor)) return false;
	while(llarg>3 && esValid) {
		part=strValor.substr(llarg-4);
		if(part.charAt(0)!=",") esValid=false; 
		else {
			part=part.substr(1);
			if(isNaN(part)) esValid=false;
			else {
				strValor=strValor.substr(0,llarg-4);
				llarg=strValor.length;
			}
		}
	}
	return esValid;
}

String.prototype.trim=trim;
function trim() {
	var temporal=this;
	while(temporal.charAt(0) == " ") temporal=temporal.substring(1);
	return temporal;
}
