// JavaScript Document

<!--
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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->

var ns6=document.getElementById&&!document.all;
var ie=document.all;

function show_text(thetext, whichdiv){
    if (ie) eval("document.all."+whichdiv).innerHTML=thetext;
    else if (ns6) document.getElementById(whichdiv).innerHTML=thetext;
}

function resetit(whichdiv){
    if (ie) eval("document.all."+whichdiv).innerHTML='&nbsp;';
    else if (ns6) document.getElementById(whichdiv).innerHTML='&nbsp;';
}

/*
 * Floating photos
 */

floatingPhoto = {
    intervalId : null,

    view : function (url, text) {
        var imgLoader = new Image();
        imgLoader.src = url;

        floatingPhoto.intervalId = window.setInterval(function () {
            if (imgLoader.complete) {
                document.getElementById('floatingPhotoText').innerHTML = text;
                document.getElementById('floatingPhotoImg').src = url;

                var offset = window.scrollY
                    || document.documentElement.scrollTop
                    || document.body.scrollTop || 0;

                var viewportHeigth = window.innerHeight
                        || document.documentElement.clientHeight
                        || document.body.clientHeight;

                if (viewportHeigth) {
                    offset += viewportHeigth / 2;
                }

                var table = document.getElementById('floatingPhoto');
                table.style.marginLeft = '-' + imgLoader.width / 2 + 'px';
                table.style.marginTop = '-' + imgLoader.height / 2 + 'px';
                if (offset) {
                    table.style.top = offset + 'px';
                }
                table.style.display = 'block';

                window.clearInterval(floatingPhoto.intervalId);
            }
        }, 200);
    },

    close : function () {
        document.getElementById('floatingPhoto').style.display = 'none';
    }
}

function openClose(id) {
	var t = document.getElementById(id);
	if (t.style.display == 'none') {
		t.style.display = 'block';
	}
	else {
		t.style.display = 'none';
	}
}

function setViewAlertIE(checked)
{
	var value;
	if (checked)
		value = 0;
	else
		value = 1;
	var caducitat = 30;
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate()+caducitat);
	document.cookie = "viewAlertIE=" + escape(value) + "; expires=" + expireDate.toGMTString() + "; path=/";
	//document.cookie = "viewAlertIE=" + escape(value) + ";";
}

function loadAlertIE(id)
{
	var view = true;
	var nomCookie = "viewAlertIE";
	var start,end;

	if(document.cookie.length>0)
	{
		/*
		 * indexOf(caracter,desde) Devuelve la primera posicion que el caracter aparece
		 * devuelve -1 si no encuentra el caracter
		 */
		start=document.cookie.indexOf(nomCookie+"=");
		if (start!=-1)
		{
			//El inicio de la cookie, el nombre de la cookie mas les simbolo '='
			start=start + nomCookie.length+1; 
			//Buscamos el final de la cookie (es el simbolo ';')
			end=document.cookie.indexOf(";",start);
			//Si no encontramos el simbolo del final ';', el final sera el final de la cookie.
			if (end==-1)
				end=document.cookie.length;
			//Devolvemos el contenido de la cookie.
			//substring(start,end) devuelve la cadena entre el valor mas bajo y
			//el mas alto, indiferentemente de la posicion.
			view = unescape(document.cookie.substring(start,end));
		}
		else
			view = true;
	}
	else
		view = true;

	if (view == 1)
	{
		document.getElementById(id).style.display = "block";
	}
	else
	{
		document.getElementById(id).style.display = "none";
	}
}

function openDialog(id,vtitle,vwidth,vheight)
{
	$("#"+id).dialog("destroy");

	if (!vtitle)
		vtitle = "";
	if (!vwidth)
		vwidth = "auto";
	if (!vheight)
		vheight = "auto";
			
	$('#'+id).dialog({
		title: vtitle,
		width: vwidth,
		height: vheight
	});
	$('#'+id).dialog('open');
}
	
function closeDialog(id)
{
	$('#'+id).dialog('close');
}
