/*
 * funcions per bloquejar la funcionalitat del buto dret del ratoli
 */
var message="";

function clickIE()
{
	if (document.all)
	{
		(message);
		return false;
	}
}
function clickNS(e)
{
	if (document.layers||(document.getElementById&&!document.all))
	{
		if (e.which==2||e.which==3)
		{
			(message);
			return false;
		}
	}
}
if (document.layers)
{
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS;
} else {
	document.onmouseup=clickNS;
	document.oncontextmenu=clickIE;
}

document.oncontextmenu=new Function("return false");

/*
 * popup per les fotos (amb la imatge centrada)
 */
function popUpFoto(lloc)
{
	novawin = window.open('', '_blank', 'toolbar=no, status=no, scrollbars=no, resizable=no, menubar=no, location=no, height=600, width=800');
	novawin.document.write("<html><head><title>Ampliación de fotografia</title>" );
	novawin.document.write("<meta content='text/html; charset=ISO-8859-1' http-equiv='Content-Type'><!--tag meta--></meta>");
	novawin.document.write("<meta content='no-cache' http-equiv='Pragma'><!--Pragma content set to no-cache tells the browser not to cache the page This may or may not work in IE--></meta>");
	novawin.document.write("<meta content='0' http-equiv='expires'><!--Setting the page to expire at 0 means the page is immediately expired Any vales less then one will set the page to expire some time in past and not be cached. This may not work with Navigator--></meta>");

	novawin.document.write("</head><body>" );

	novawin.document.write("<table width='100%' height='600'>");
	novawin.document.write("<tr>");
	novawin.document.write("<td align='center' valign='middle' width='100%' height='100%'>");
	novawin.document.write("<img src='"+ lloc +"' width='100%' height='100%'>");
	novawin.document.write("</td>");
	novawin.document.write("</tr>");
	novawin.document.write("</table>");

	novawin.document.write("</body></html>" );
}
function popUp(lloc)
{
	novawin = window.open(lloc, '_blank', 'toolbar=no, status=no, scrollbars=no, resizable=no, menubar=no, location=no, height=600, width=800');
}

/*
 * funcio per ressaltar l'input seleccionat
 */
function TextOver( ElObjeto )
{
	ElObjeto.style.background = "#FFFFFF";
}
function TextOut( ElObjeto )
{
	ElObjeto.style.background = "#F6F6F6";
}

// comprova el formulari Apuntat
function comprova1(Objecte)
{
	Error="";
	NError=0;
	with(Objecte)
	{
		//Comprovacions
		if (nom.value || cognoms.value || email.value || nif.value || direccio.value || cp.value || poblacio.value) {
			if( !nom.value ) {
				Error += "   Falta el Nombre; \n";
			    	NError ++;
			}
			if( !cognoms.value ) {
				Error += "   Faltan los Apellidos; \n";
			    	NError ++;
			}
			if( !email.value ) {
				Error += "   Falta el email; \n";
			    	NError ++;
			} else {
				if( !V01_ValidaMail( email.value ) )
				{
					Error += "   Error en el email (Verificar); \n";
			    		NError ++;
				}
			}
			if( !nif.value ) {
				Error += "   Falta el NIF; \n";
			    	NError ++;
			}
			if( !tel.value ) {
				Error += "   Falta el Telèfon; \n";
			    	NError ++;
			} else {
				if( tel.value.length < 9 ) {
					Error += "   Error en el Telèfon (9 dígits); \n";
			    		NError ++;
				}
			}
			if( !direccio.value ) {
				Error += "   Falta la dirección; \n";
			    	NError ++;
			}
			if( !cp.value ) {
				Error += "   Falta el CP; \n";
			    	NError ++;
			} else {
				if( cp.value.length < 5 ) {
					Error += "   Error en el CP (5 dígitos); \n";
			    		NError ++;
				}
			}
			if( !poblacio.value ) {
				Error += "   Falta la Población; \n";
			    	NError ++;
			}
			/*
			if( !provincia.value ) {
				Error += "   Falta la Província; \n";
			    	NError ++;
			}
			if( !idpais.options[idpais.selectedIndex].value ) {
				Error += "   Falta el País; \n";
			    	NError ++;
			}
			*/
			if (Error==""){
				login.value = "000222";
				passwd.value = "eBotiga";
			}
		} else {
			if (!login.value) {
				Error+="   Falta el Nombre de Usuario \n";
				NError++;
			}
			if (!passwd.value) {
				Error+="   Falta la Clave \n";
				NError++;
			}
		}
	}
	if (Error!="") {
		if (NError==1) {
			alert("Hay " + NError + " error: \n" + Error);
		} else {
			alert("Hay " + NError + " errores: \n" + Error);
		}
		return false;
	}
	return true;
}

// Descripció: Valida que el Email introduït tingui
//             un format ******@***.***
//             amb un domini de dos o tres dígits

function V01_ValidaMail(T4_Mail)
{
	
//L'adreça ha de tenir una arroba
	if (T4_Mail.indexOf("@") == -1)
	{
		return (false);
	}
	
//L'adreça ha de tenir un punt
	if (T4_Mail.indexOf(".") == -1)
	{
		return (false);
	}
	
	var pos_arroba;
	var pos_punt;
	var vlong;
	pos_arroba = T4_Mail.indexOf("@");
	pos_punt = T4_Mail.indexOf(".");
	vlong = T4_Mail.length;
	
//L'adreça ha de tenir NOMÉS una arroba
	if (T4_Mail.indexOf("@", pos_arroba + 1) != -1)
	{
		return (false);
	}
	
	
//L'arroba no pot estar a l'inici de l'adreça ni el punt al final
	if (pos_arroba == 0 || pos_punt == vlong - 1)
	{
		return (false);
	}
	
//L'arroba i el punt no poden estar en posicions consecutives
	if (pos_arroba == pos_punt - 1)
	{
		return (false);
	}
	
//el domini ha de tenir minim 2 cars.
	if (vlong - pos_punt <= 2 )
	{
		return (false);
	}
	
	return (true);
}

/*
 * elimina galeta i tanca sessio
 */

function logout()
{

var c = "";
c += "usuari= "
var caducidad = new Date(1970, 1, 1, 0, 0, 0);
c += "; expires=" + caducidad.toGMTString();
document.cookie = c;


var d = "";
d += "clau= "
var caducidad = new Date(1970, 1, 1, 0, 0, 0);
d += "; expires=" + caducidad.toGMTString();
document.cookie = d;


var e = "";
e += "PHPSESSID= "
var caducidad = new Date(1970, 1, 1, 0, 0, 0);
e += "; expires=" + caducidad.toGMTString();
document.cookie = e;

}
