// Isaac Roca - iroca at pragmapublicitat dot cat

/*
EXEMPLE DE SECCIÓ AMB CALENDARI 

FnLoad.push({ 
	sec:'admInmuebles',
	fn: function () {
			if (!calendariIncluded) {
				csslink('/lib/calendari/calendar-blue.css');
				include('/lib/calendari/calendar_stripped.js');
				include('/lib/calendari/lang/calendar-es.js');
				include('/lib/calendari/calendar-setup_stripped-inm.js');
				calendariIncluded=true;
			} else {
				setupcalendar();
			}
	}
});


function setupcalendar() {
		Calendar._C = null;
		window._dynarch_popupCalendar = null;
		calendari=Calendar.setup({ 
				inputField:'flimit',
				ifFormat:'%Y-%d-%m', 
				button:'lanzador' 
		});
}

*/

function seleccionar(txt)	{
	if(txt.value.length>0) {
		//txt.focus();
		txt.select();
	}
}


function estiloOn(which, estilo){
//alert (estilo);
	if (document.all||document.getElementById){
	which.className= estilo;
	}
}

function estiloOff(which, estilo){
	if (document.all||document.getElementById){
	which.className= estilo;
	}
}

/* Funcions lightbox */

function showBox(){
    $('overlay').show();
    center('box');
    return false;
}

function hideBox(){
    $('box').hide();
    $('overlay').hide();
    return false;
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && 
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    element.style.display  = 'block';
}


FnLoad.push({
 sec:'documentacio',
 fn: function () {
	//Definición de clases para cada tipo de archivo.
	
	//alert('cacona');
	
	jQuery("ul.llistaDocs li a[@href$=pdf]").addClass("pdf");
	
	jQuery("ul.llistaDocs li a[@href$=doc]").addClass("doc");
 }
});

FnLoad.push({
 sec:'noticies',
 fn: function () {
	//Definición de clases para cada tipo de archivo.
	
	jQuery("#noticiaAmpliada a[@href$=jpg]").addClass("jpg");
	jQuery("#noticiaAmpliada a[@href$=doc]").addClass("doc");
	jQuery("#noticiaAmpliada a[@href$=pdf]").addClass("pdf");
 }
});


function showDiv(codi) {
	
	/*jQuery('.pmoures').animate({ 
        opacity: 0
      }, {speed:500, complete:function (){jQuery('#logoTarragona, #logoReus, #logoValls').css({display: 'none', zIndex: 1});}} );
	
	if (codi !== "") {
		alert ("#"+codi);
		
	}*/

	jQuery('.pmoures').each(function (){
		if (this.id==codi) {
			jQuery('#'+codi).css({display: 'block', zIndex: 3 });
			jQuery('#'+codi+" a").css({display: 'block', zIndex: 3 });
			jQuery('#'+codi).animate({ 
				opacity: 1
			  }, 500 );
		} else {
			jQuery('#'+this.id).animate({ 
				opacity: 0
			 } , {
				 speed:500 , complete: function () { 
			  		jQuery('#'+this.id).css({display: 'none', zIndex: 1});  
					jQuery('#'+this.id+" a").css({display: 'none', zIndex: 1});
				}
			 });
		}
	});
}