function imprimir_quadern() {
	var zoom = window.open('quadern_i.html',"quadern","width=568,height=700,left=0,top=0,status=no,resizable=no,scrollbars=no"); 
}


function validaRegistre() {
	var ok=0;
	var campo_actual="";

	var ff=window.document.Registre;
	validacion = /[^a-z-.@0-9A-Z]/g;

	if (ff.nickname.value.length < 3){
		ok=1;
		alert("S\'ha detectat un error a la validaciķ del formulari de dades:\nOmpli correctament el camp \'Ālias o Nickname\'.");
	} else {
		if (validacion.test(ff.nickname.value)) {
			ok=1;
			alert("S\'ha detectat un error a la validaciķ del formulari de dades:\nOmpli correctament el camp \'Ālias o Nickname\'.");
		}
	}


	if (ff.login.value.length < 3){
		ok=1;
		alert("S\'ha detectat un error a la validaciķ del formulari de dades:\nOmpli correctament el camp \'Identificador d'usuari desitjat (login)\'.");
	} else {
		if (validacion.test(ff.login.value)) {
			ok=1;
			alert("S\'ha detectat un error a la validaciķ del formulari de dades:\nOmpli correctament el camp \'Identificador d'usuari desitjat (login)\'.");
		}
	}

	if (checkEmail(ff.email.value)) {
		ok=1;
		alert("S\'ha detectat un error a la validaciķ del formulari de dades:\nOmpli correctament el camp \'eMail\'.");
	}

	if (checkEmail(ff.email_2.value)) {
		ok=1;
		alert("S\'ha detectat un error a la validaciķ del formulari de dades:\nOmpli correctament el camp \'eMail (repetiu-lo)\'.");
	}

	if (ff.email.value != ff.email_2.value){
		ok=1;
		alert("S\'ha detectat un error a la validaciķ del formulari de dades:\nEls eMails omplerts no coincideixen.");
	}


	if (ok==0){
		ff.submit();
	} else {
		event.returnValue=false;
	}


}


function esborraRegistre() {
	var ff=window.document.Registre;
	ff.nickname.value="";
	ff.login.value="";
	ff.email.value="";
	ff.email_2.value="";
}

function zoomFotos(n,lg) {
	var zoom = window.open("recurso_foto_zoom.html?Id="+n+"&lg="+lg,"","width=50,height=50,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}


function paginadoFiltro(pagina) {
	var ff=window.document.bava;
	ff.pagina.value = pagina;
	ff.submit();
}

function esborraCerca() {
	var ff=window.document.Busqueda;
	ff.Ambit.value="";
	ff.i_Ambit.value="";
	ff.Destinataris.value="";
	ff.i_Destinataris.value="";
	ff.Area_Tematica.value="";
	ff.i_Area_Tematica.value="";
	ff.Paraules_Clau.value="";
	ff.i_Paraules_Clau.value="";
}
	

function validaCerca() {
	var ff=window.document.Busqueda;
	ff.submit();
}

function selector(n,lg) {
	var zoom = window.open("selector.html?tbl="+n+"&lg="+lg,"Selector","width=250,height=500,left=0,top=0,status=no,resizable=yes,scrollbars=yes"); 
}


function checkEmail(emailStr) {
   if (emailStr.length == 0)
     return true;
   var emailPat=/^(.+)@(.+)$/;
   var specialChars="()<>@,;:\".[]";
   var validChars="[^s" + specialChars + "]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^(d{1,3})[.](d{1,3})[.](d{1,3})[.](d{1,3})$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(." + atom + ")*$");
   var matchArray=emailStr.match(emailPat);

   if (matchArray == null)
      return false;

   var user=matchArray[1];
   var domain=matchArray[2];

   if (user.match(userPat) == null)
      return false;

   var IPArray = domain.match(ipDomainPat);
   if (IPArray != null) {
      for (var i = 1; i <= 4; i++) {
         if (IPArray[i] > 255)
         	return false;
   		}

   return true;
	 }

   var domainArray=domain.match(domainPat);
   if (domainArray == null)
      return false;

   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;

   if (domArr[domArr.length-1].length < 2 || domArr[domArr.length-1].length > 3)
      return false;

   if (len < 2)
      return false;

   return true;
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

 function MM_showHideLayers() { //v2.0
   var i, visStr, args, theObj;
   args = MM_showHideLayers.arguments;
   for (i=0; i<(args.length-2); i+=3) { //with arg triples (objNS,objIE,visStr)
     visStr   = args[i+2];
     if (navigator.appName == 'Netscape' && document.layers != null) {
       theObj = eval(args[i]);
       if (theObj) theObj.visibility = visStr;
     } else if (document.all != null) { //IE
       if (visStr == 'show') visStr = 'visible'; //convert vals
       if (visStr == 'hide') visStr = 'hidden';
       theObj = eval(args[i+1]);
       if (theObj){
		pageWidth=(ie)?document.body.offsetWidth:innerWidth;
		theObj.style.left=(pageWidth - 780)/2;
		theObj.style.visibility = visStr;
		}
  } }
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function



/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function misetPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    seleccionarId(theRowNum);
    return true;
} // end of the 'setPointer()' function


function seleccionarId(imagen) {
	if ((document.images['img_'+imagen].src.indexOf("images/not_selected.gif")) > -1) {
		MM_swapImage('img_'+imagen,'','images/selected.gif',1);
	} else {
		MM_swapImage('img_'+imagen,'','images/not_selected.gif',1);
	}
}

function ilumina(imagen,base_imagen) {
	if ((document.images[imagen].src.indexOf("_i.gif")) > -1) {
		MM_swapImage(imagen,'',base_imagen+'.gif',1);
	} else {
		MM_swapImage(imagen,'',base_imagen+'_i.gif',1);
	}
}

function recoge_ids () {

	var ff=window.document.seleccionados;
	ff.seleccionados.value="";
	ff.tseleccionados.value="";

	for (var i = 1; i <ff.max_filas.value; i++)
	{
		if ((document.images['img_'+i].src.indexOf("images/selected.gif")) > -1) {
			ff.seleccionados.value = ff.seleccionados.value + ","+eval("ff.cam_"+i+".value");
			ff.tseleccionados.value = ff.tseleccionados.value + ","+eval("ff.tit_"+i+".value");
		}
	}
	ff.tseleccionados.value=ff.tseleccionados.value.substring(1);

	eval("window.opener.document.Busqueda." +ff.tbl.value+ ".value = '" +ff.tseleccionados.value+ "';");
	eval("window.opener.document.Busqueda.i_" +ff.tbl.value+ ".value = '" +ff.seleccionados.value+ "';");
	window.close();


}



//Pilla navegador
function checkBrowser(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.opera=this.agent.indexOf("Opera")>-1

	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5)
	return this
}


//Acopla ventana
function res() {

	bw = new checkBrowser()

	//desabilita el drag
	document.onselectstart=function(){return false}
	document.ondragstart=function(){return false}

	if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)==4) { 
		document.onmousedown=NSclick;
		document.captureEvents(Event.MOUSEDOWN);
	}
	if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)>=5) { 
		document.onmouseup=NSclick;
	}
	if (navigator.appName=="Microsoft Internet Explorer") { 
		document.oncontextmenu = new Function("return false;")
	}

	if( bw.opera ){
		var width = 13
		var height = 33
	}
	else if ( bw.ns6 == 1 ){
		var width = 8
		var height = 28
	}
	else {
		var width = 9
		var height = 29
	}

	var Pwidth = document.getElementById('picture').width
	var Pheight = document.getElementById('picture').height
	var Aheight = screen.availHeight
	var Awidth = screen.availWidth

	if ( (Awidth <= Pwidth) && (Aheight <= Pheight) ) window.resizeTo(Awidth, Aheight)
	else if ( (Awidth <= Pwidth) && (Aheight >= Pheight) ) window.resizeTo(Awidth, Pheight + height + 31)
	else if ( (Awidth >= Pwidth) && (Aheight <= Pheight) ) window.resizeTo(Pwidth+width, Aheight)
	else if ( (Pwidth <= 250)) window.resizeTo(267, Pheight+ height + 31)
	else window.resizeTo(Pwidth + width, Pheight + height + 31)
}


// deshabilita boton derecho
function NSclick(e) {
	if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)==4) { 
		if (e.which == 3) {
			window.close();
		}
	}
	if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)>=5) { 
    		if (e.button == 2 || e.button == 3) {
      			e.preventDefault();
			window.close();
  		}
	}
}

