
//************ funcions de validació de formularis *************

function validForm(){
	var result = true;

	if (formmail.ValidForm.value != ""){
		result = false;
	}	

	return result;
}

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validRequired(formField,fieldLabel)
{
	var result = true;

	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}	

	return result;
}

function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}

function seleccionaCheckbox(theForm, fieldName, fieldLabel) {

	var temp = 0;
	var result = true;
	
	for(var i=0; i<theForm.elements.length && temp==0; i++) {
		var element = theForm.elements[i];

		if (element.name==fieldName && element.type=="checkbox" && element.checked) {
			temp=temp+1;
		}
	}
	
	if (temp==0){
		alert('');
		result = false;	
	}

	return result;
}

function seleccionaRadioButton(formField,fieldLabel){

	var temp = 0;
	var result = true;
	
	for(var i=0; i<formField.length && temp==0; i++) {
		if(formField[i].checked){
			temp=temp+1;
		}
	}
	
	if (temp==0){
		alert('');
		result = false;	
	}

	return result;
}

function validRequiredSelect(formField,fieldLabel,valorNull) {
	var result = true;

	if (formField.value == valorNull)
	{
		alert('Please choose a value for the "' + fieldLabel + '" field.');
		formField.focus();
		result = false;
	}	

	return result;
}

function selectText(formField) {
	var index = formField.selectedIndex;
	var text = formField.options[index].text;

	return text;
}

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
   
  return result;

}

function validNum(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allDigits(formField.value))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function validInt(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var num = parseInt(formField.value,10);
 		if (isNaN(num))
 		{
 			alert('Please enter a integer number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function validDate(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var elems = formField.value.split("/");
 		
 		result = (elems.length == 3); // should be three components
 		
 		if (result)
 		{
 			var month = parseInt(elems[0],10);
  			var day = parseInt(elems[1],10);
 			var year = parseInt(elems[2],10);
			result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
					 allDigits(elems[1]) && (day > 0) && (day < 32) &&
					 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
 		}
 		
  		if (!result)
 		{
 			alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
			formField.focus();		
		}
	} 
	
	return result;
}

//************ funcions per les capes *************

var nav="";
var j=1;

function navegador(){
if (navigator.appName == "Microsoft Internet Explorer") nav="ie4"
else if(document.layers){//NS4
	nav="ns4";}
else if(document.getElementById){//IE 5 i posteriors i NS6
		nav="ie5ns6"}
	
if (j<6) {
	eval("amagar('menu"+j+"')");
	//if (pagina!=0) eval("amagar_menu(9"+j+")");	
	j++;
	setTimeout("navegador()",10);
}
}

function carregar(){
MM_preloadImages('/cidem/catalonia/binaris/foto1_tcm51-1619.jpg');
surtfoto1();
}

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 (i==(a.length-1)){ 
	//	if (screen.width<810) lanz("home.jsp",790,530,'home',0,0);
	//	else document.location="home.jsp";
	  }
   	if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image; d.MM_p[j++].src=a[i]; }}
	}
}

// fade 

var f1;
var f2;
var f3;
var f4;

function surtfoto1()
{
if (navigator.appName != "Microsoft Internet Explorer") veure("foto1");
	else {
	f1 = new Fade("f1","foto1",0);
	f1.Appear(1);
	}
setTimeout("surtfoto2()",6000);	
}

function surtfoto2()
{
if (navigator.appName != "Microsoft Internet Explorer") {amagar("foto1");veure("foto2");}
	else  {
	f2 = new Fade("f2","foto2",0);
	f1.Disappear(2);
	f2.Appear(1);
	}

setTimeout("surtfoto3()",6000);	

}

function surtfoto3()
{
if (navigator.appName != "Microsoft Internet Explorer")  {amagar("foto2"); veure("foto3");}
	else {
	f3 = new Fade("f3","foto3",0);
	f2.Disappear(2);
	f3.Appear(1);
	}

setTimeout("surtfoto4()",6000);	
}

function surtfoto4()
{
if (navigator.appName != "Microsoft Internet Explorer")  {amagar("foto3"); veure("foto4");}
	else {
	f4 = new Fade("f4","foto4",0);
	f3.Disappear(2);
	f4.Appear(1);
	}

setTimeout("surtfoto5()",6000);	
}
function surtfoto5()
{
if (navigator.appName != "Microsoft Internet Explorer")  {amagar("foto4"); veure("foto1");}
	else {
	f4.Disappear(2);
	f1.Appear(1);
	}
setTimeout("surtfoto2()",6000);	
}
// fi fade

function ref(nom_capa){
    if (nav == "ie5ns6") return "document.getElementById('" + nom_capa + "').style.";
 	else if (nav == "ie4") return "document.all['" + nom_capa + "'].style.";
	else return "document." + nom_capa + ".";
} 

function ref2(nom_capa,capa_mare){
    if (nav == "ie5ns6") return "document.getElementById('" + nom_capa + "').style."
	else  	if (nav == "ie4") return "document.all['" + nom_capa + "'].style."
			else return "document." + capa_mare + ".document." + nom_capa + "."

  } 
  
function refObj(nom_capa){
	if (nav == "ie5ns6") return "document.getElementById('" + nom_capa + "')";
	else if (nav == "ie4") return "document.all['" + nom_capa + "']";
	else return "document." + nom_capa + "";
}

function veure(nom_capa){
	if(eval(refObj(nom_capa))!=null)
	eval(ref(nom_capa) + "visibility = 'visible'");

}

function amagar(nom_capa){
	if(eval(refObj(nom_capa))!=null)
	eval(ref(nom_capa) + "visibility = 'hidden'");
}

function mourecapa(capa,posx,posy){
   	if (nav=="ns4" || nav=="ie5ns6") {
        eval(ref(capa) + "left=posx;");
        eval(ref(capa) + "top=posy;");
  	}
    else {
    	eval(ref(capa) + "pixelLeft=posx;");
        eval(ref(capa) + "pixelTop=posy;");
    }
}

function clipcapa(capa,arr,der,aba,izq){
  	if (nav=="ns4") {
    	eval(ref(capa) + "clip.top=arr;");
        eval(ref(capa) + "clip.right=der;");
        eval(ref(capa) + "clip.bottom=aba;");
        eval(ref(capa) + "clip.left=izq;");
   	}
    else {
        eval(ref(capa) + "clip='rect("+arr+"px "+der+"px "+aba+"px "+izq+"px)'");
    }
}

function obre(desti,am,al,nom){
  var ampla = am;
  var altura = al;
  strURL = desti;
  poshoritz = (screen.width) ? (screen.width-ampla)/2 : 0;
  posvert = (screen.height) ? (screen.height-altura)/2 : 0;
  strW = 'toolbar=0,directories=0,location=0,status=no,menubar=0,resizable=false,copyhistory=yes,scrollbars=yes,width='+ ampla + ',height='+ altura + ',top='+ posvert + ',left='+ poshoritz;
  eval("window.open('" + strURL + "',nom,'" + strW + "')");
}


function agafaCookie(adreca) 
 { 
    //window.open(adreca,"docs","dependent,height=280,width=360"); 
    open_window_2(adreca,"docs",400) 
 } 
 
function open_window_2(pag,nom,h){ 
    w = 400;  
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0; 
TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
win = window.open(pag,nom,'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=0,resizable=0') 
}

//************ funcions per les noticies rotatives *************

function ref3(nom_capa){
    if (nav == "ie5ns6") return "document.getElementById('" + nom_capa + "').style."
	else  	if (nav == "ie4") return "document.all['" + nom_capa + "'].style."
			else return "document.finestra.document." + nom_capa + "."

} 

var guardo_posy=0; 

function mourescroll(capa,posx,posy){
   	if (nav=="ns4" || nav=="ie5ns6") {
	        eval(ref3(capa) + "left=posx;");
	        eval(ref3(capa) + "top=posy;");
  	}
/*	if (nav=="ns4") {
	        eval(ref3(capa) + "left=posx;");
	        eval(ref3(capa) + "top=posy-20;");
  	}  */
	else {
		eval(ref3(capa) + "pixelLeft=posx;");
		eval(ref3(capa) + "pixelTop=posy;");
	}
	guardo_posy=posy;
}


var m=0;
var baixat=false;

function avall(){
	if ((guardo_posy+m)>-560){
		if (nav=="ns4") {
			mourescroll("noticies",0,guardo_posy-150);baixat=true;
		}
		/* if (nav=="ns4") {
			if (m<18) {
				mourescroll("noticies",0,guardo_posy-m);
				m=m+1;
				setTimeout("avall()",10);
			}
			else {
				m=0;
				baixat=true;
			}
		}
		*/
		else { 
			if (m<40) {
				mourescroll("noticies",0,guardo_posy-m);
				m=m+5;
				setTimeout("avall()",10);
			}
			else {
				m=0;
				baixat=true;
			}
		}	

	}
}

function amunt(){
	if (baixat) {
		if (nav=="ns4") {mourescroll("noticies",0,guardo_posy+150); if (guardo_posy==0) baixat=false;}
		/* if (nav=="ns4") {
			if (m<28) {
				mourescroll("noticies",0,guardo_posy+m);
				m=m+2;
				setTimeout("amunt()",10);
				}
			else{
				m=0;
				if (guardo_posy+m==0) baixat=false;
				}
		 }
		*/
		 else { 
			if (m<40) {
				mourescroll("noticies",0,guardo_posy+m);
				m=m+5;
				setTimeout("amunt()",10);
				}
			else{
				m=0;
				if (guardo_posy+m==0) baixat=false;
				}
		}
	} 
}


//************ funcio per al banner de cubo (pla d'innovacio) *************

function newWindow(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}
