// JavaScript Document

/***********************************************
* Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var delayb4scroll0=6000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed0=1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseit0=1 //Pause marquee onMousever (0=no. 1=yes)?

////NO NEED TO EDIT BELOW THIS LINE////////////

var copyspeed0=marqueespeed0
var pausespeed0=(pauseit0==0)? copyspeed0: 0
var actualheight0=''

function scrollmarquee0(){
	if (parseInt(cross_marquee0.style.top)>(actualheight0*(-1)+8))
		cross_marquee0.style.top=parseInt(cross_marquee0.style.top)-copyspeed0+"px"
	else
		cross_marquee0.style.top=parseInt(marqueeheight0)+8+"px"
}

function initializemarquee0(){
	cross_marquee0=document.getElementById("vmarquee0")
	cross_marquee0.style.top=0
	marqueeheight0=document.getElementById("marqueecontainer0").offsetHeight
	actualheight0=cross_marquee0.offsetHeight
	if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
		cross_marquee0.style.height=marqueeheight0+"px"
		cross_marquee0.style.overflow="scroll"
		return
	}
	setTimeout('lefttime=setInterval("scrollmarquee0()",30)', delayb4scroll0)
}

if (window.addEventListener)
	window.addEventListener("load", initializemarquee0, false)
else if (window.attachEvent)
	window.attachEvent("onload", initializemarquee0)
else if (document.getElementById)
	window.onload=initializemarquee0

	


	
 function obrir_finestra(url){
    window.open(url, "", "toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,width=550,height=500,top=0,left=0");
}
function large(url){ //Load an image and open window;
	img = new Image();
	img.src = url;
	var w = window.open('large.htm','large','status=no');
}
function display(mi_img) {
	img = new Image();
	img.src = mi_img;
	/*var width = img.width + 10;
	var height = img.height + 10;
	alert(width+","+height);
	width += width - document.body.clientWidth;
	height += height - document.body.clientHeight;
	alert(document.body.clientWidth+","+document.body.clientHeight);
	alert(width+","+height);*/
	
	if(img.width > document.body.clientWidth) wwidth = document.body.clientWidth;
	else wwidth = img.width;
	
	html = "<HTML><HEAD><TITLE>Mi imagen</TITLE>" +
	"</HEAD><BODY LEFTMARGIN=0 " +
	"MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER>" +
	"<IMG SRC='" + mi_img + "' width='"+wwidth+"' BORDER=0 NAME=image";
	if(img.width > document.body.clientWidth) html += " onclick='if("+img.width+" == image.width) image.width = "+document.body.clientWidth+"; else image.width = "+img.width+";'";
	html += "></CENTER></BODY></HTML>";
	
	popup=window.open('','image','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,width='+img.width+',height='+img.height);
	popup.document.open();
	popup.document.write(html);
	//popup.document.focus();
	popup.document.close();
};

function dir_algu(){
	alert('ALGU!!!');
}

/*VALIDACIONS*/
function validar_mail(theElement){
	var s = theElement.value;
	var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if (s.length == 0) {
		alert('Falta el correu.');
		return false;
	}
	if (filter.test(s))
		return true;
		
	theElement.focus();
	alert('El correu és incorrecte.');
	return false;
} 
function espais_en_buit(q) {  
	for ( i = 0; i < q.length; i++ ) {  
		if ( q.charAt(i) != " " ) {  
			return true;
		}  
	}
	return false;  
}
function validar_contingut(F) {
	if( espais_en_buit(F.value) == false ) return false;
	else return true;
}
function validar_cp(F) {  
	var er_cp = /(^([0-9]{5,5})|^)$/

	if(!er_cp.test(F.value)) {   
		return false;
	}
	return true;
}
function validar_num(F) {  
	var er_num = /(^([0-9]{1,5})|^)$/

	if(!er_num.test(F.value)) {   
		return false;
	}
	return true;
}
function validar_telf_sp(F) {  
	var er_telf_sp = /(^([0-9]{9,9})|^)$/

	if(!er_telf_sp.test(F.value)) {   
		return false;
	}
	return true;
}
function validar_dni(F) {
	var value = F.value; 
	if (value.length<9 || value.length>10){
		return false;
	}else{
		return true;
	}
	
	/*
var er_dni = /(^([0-9]{8,8}\-[A-Z])|^)$/

	if(!er_dni.test(F.value)) {
		return false;  
	} 
	return true;
*/
}
function validar_form_pressupost(F){
	var val;
	var msg='';
	var comp=true;
	
	for (var i = 0; i < F.elements.length; i++) {
		//alert(F.elements[i].name+': '+F.elements[i].value);
		switch (F.elements[i].name) {
			case 'EMPRESA_CLIENT':
				if (!validar_contingut(F.elements[i])) {
					msg = msg + "Introdueix el camp Empresa client.\n";
					comp = false;
				}
				break;
			case 'PERSONA_CONTACTE':
				if (!validar_contingut(F.elements[i])) {
					msg = msg + "Introdueix el camp Persona contacte.\n";
					comp = false;
				}
				break;
			case 'TELEFON':
				if (!validar_contingut(F.elements[i])) {
					msg = msg + "Introdueix el Telèfon.\n";
					comp = false;
				}
				break;
			case 'DESCRIPCIO':
				if (!validar_contingut(F.elements[i])) {
					msg = msg + "Introdueix la descripció.\n";
					comp = false;
				}
				break;
			case 'EMAIL2':
				if (!validar_mail(F.elements[i])) {
					comp = false;
				}
				break;
		}
	}
	if (comp) 
		return true;
	else {
		alert(msg);
		return false;
	}
}
