// 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' 
		});
}

*/

/* 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';
}


/* FI -- Funcions lightbox */

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;
}
}


jQuery(document).ready(function() {
	jQuery("ul.menuRoot ul").css("display","none");
	
	jQuery(".impar").mouseover(function () {
    	jQuery(this).addClass('detalleActivitats');
    });
	jQuery(".impar").mouseout(function () {
    	jQuery(this).removeClass('detalleActivitats');
    });
	jQuery(".par").mouseover(function () {
    	jQuery(this).addClass('detalleActivitats2');
    });
	jQuery(".par").mouseout(function () {
    	jQuery(this).removeClass('detalleActivitats2');
    });
	jQuery(".banerRedessa").mouseover(function () {
    	jQuery(this).addClass('banerRedessa2');
    });
	jQuery(".banerRedessa").mouseout(function () {
    	jQuery(this).removeClass('banerRedessa2');
    });
	jQuery(".banerGeneralitat").mouseover(function () {
    	jQuery(this).addClass('banerGeneralitat2');
    });
	jQuery(".banerGeneralitat").mouseout(function () {
    	jQuery(this).removeClass('banerGeneralitat2');
    });
	jQuery(".banerDiputacio").mouseover(function () {
    	jQuery(this).addClass('banerDiputacio2');
    });
	jQuery(".banerDiputacio").mouseout(function () {
    	jQuery(this).removeClass('banerDiputacio2');
    });
	jQuery(".banerAjuntamentReus").mouseover(function () {
    	jQuery(this).addClass('banerAjuntamentReus2');
    });
	jQuery(".banerAjuntamentReus").mouseout(function () {
    	jQuery(this).removeClass('banerAjuntamentReus2');
    });
	jQuery(".banerCambraReus").mouseover(function () {
    	jQuery(this).addClass('banerCambraReus2');
    });
	jQuery(".banerCambraReus").mouseout(function () {
    	jQuery(this).removeClass('banerCambraReus2');
    });
});

function enviarform()
{
//alert ("Hello World");
	if (document.form.direccion.value==''){
		alert("Ompli la direcció");return false;
	}else if (document.form.mensaje.value==''){
		alert("Ompli el MIssatge");return false;
	}else if (document.form.mail.value==''){
		alert("Ompli el Email");return false;
	}else if (document.form.apellidos.value==''){
		alert("Ompli els cognoms");return false;
	}else if (document.form.nombre.value==''){
		alert("Omli en nom");return false;
	}else {

	//document.formulario.action = "form/"+archivo+".php";
	//alert ("submit");
	//document.form.action = "enviar.php";
	//document.form.submit();
		return true;
	}
}

function menuDeSalto(urla) {
	var destino=document.formFires.menu.value
	document.location.href=urla+'/'+destino;
} 

function getTicket() {
	
	if (jQuery('#enviar')) {
		jQuery('#enviar').attr('disabled', true);
		if (jQuery('#carregant')) {
			jQuery('#carregant').show();
		}
	}
	
	var strform = jQuery("#formulari").serialize();
	var objform = document.formulari;
	var actform = objform.action;
	
	var strerror = '';
	
	var enableButton = function () {
		if (jQuery('#enviar')) {
			jQuery('#enviar').attr('disabled', false);
			if (jQuery('#carregant')) {
				jQuery('#carregant').hide();
			}
		}
	}
	
	if ((objform.nom.value=='')||
		 (objform.cognoms.value=='')||
		 (objform.email.value=='')||
		 ((objform.telefon1.value=='')&&(objform.telefon2.value==''))||
		 (objform.exposvisit.value=='')) 
			strerror = 'Per tal de realitzar el registre correctament, cal que els camps nom, cognoms, e-mail, telèfon i si s\'és visitant o expositor siguin correctes. Gràcies.';
			
		
	if (strerror!='') {
		alert(strerror);
		enableButton();
	} else {	
		document.formulari.reset();
		jQuery('#enviar').attr('disabled', true);
		/*lightwindowInit();
		myLightWindow.activateWindow({
			, 
			title: 'Emissió d\'acreditacions', 
			author: 'firareus.com', 
			caption: 'Emissió d\'acreditacions',
			width: '600',
			height: '480'
		});*/
		jQuery.ajax({
			url: actform,
			data: strform,
			type:'POST',
			success: function (msg) {
				jQuery.colorbox({
					title: 'Emissió d\'acreditacions', 
					innerWidth:625, 
					innerHeight:550,
					html: msg, 
					onClosed: function() { 
						enableButton();
					}
				});
			}
		});
	}
	return false;
}


// Create a jquery plugin that prints the given element.
jQuery.fn.print = function() {
	
	// NOTE: We are trimming the jQuery collection down to the
	// first element in the collection.
	if (this.size() > 1){
		this.eq( 0 ).print();
		return;
	} else if (!this.size()){
		return;
	}
	
	// ASSERT: At this point, we know that the current jQuery
	// collection (as defined by THIS), contains only one
	// printable element.
	
	// Create a random name for the print frame.
	var strFrameName = ("printer-" + (new Date()).getTime());
	
	// Create an iFrame with the new name.
	var jFrame = jQuery( "<iframe name='" + strFrameName + "'>" );
	
	// Hide the frame (sort of) and attach to the body.
	jFrame
	.css( "width", "1px" )
	.css( "height", "1px" )
	.css( "position", "absolute" )
	.css( "left", "-9999px" )
	.appendTo( jQuery( "body:first" ) )
	;
	
	// Get a FRAMES reference to the new frame.
	var objFrame = window.frames[ strFrameName ];
	
	// Get a reference to the DOM in the new frame.
	var objDoc = objFrame.document;
	
	// Grab all the style tags and copy to the new
	// document so that we capture look and feel of
	// the current document.
	
	// Create a temp document DIV to hold the style tags.
	// This is the only way I could find to get the style
	// tags into IE.
	var jStyleDiv = jQuery( "<div>" ).append(
		jQuery( "style" ).clone()
	);
	
	// Write the HTML for the document. In this, we will
	// write out the HTML of the current element.
	objDoc.open();
	objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
	objDoc.write( "<html>" );
	objDoc.write( "<body>" );
	objDoc.write( "<head>" );
	objDoc.write( "<title>" );
	objDoc.write( document.title );
	objDoc.write( "</title>" );
	objDoc.write( jStyleDiv.html() );
	objDoc.write( "</head>" );
	objDoc.write( this.html() );
	objDoc.write( "</body>" );
	objDoc.write( "</html>" );
	objDoc.close();
	
	// Print the document.
	objFrame.focus();
	objFrame.print();
	
	// Have the frame remove itself in about a minute so that
	// we don't build up too many of these frames.
	setTimeout(
		function(){
			jFrame.remove();
		},
		(60 * 1000)
	);
}

function openDiv(codi) {
	//alert(codi);
	jQuery("#"+codi).each(function () {
			if (jQuery(this).css("display")=="none") {
				jQuery(this).slideDown("slow");
			} else {
				jQuery(this).slideUp("slow");
			}
	});
}

function divsMapaEpocauto(codi) {
	//alert(codi);
	jQuery("#"+codi).each(function () {
		if (jQuery(this).css("display")=="none") {
			jQuery(".divsMapa").css("display","none");
			jQuery(this).show("slow");
		}
	});
}
function divsMapaClose(codi) {
	//alert(codi);
			jQuery("#"+codi).css("display","none");
}

