
function fbs_click() {
            u='http://www.lluisaragones.cat/index.php?command=transform&style=homepage&idpublic=1';  
            t=document.title;  
            
            window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&amp;t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
            
            return false; 
            }
            
function banner(zone){
    if (!document.phpAds_used) document.phpAds_used = ',';
    phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
   
    document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
    document.write ("http://ads.grupclau.cat/adjs.php?n=" + phpAds_random);
    document.write ("&amp;what=zone:"+zone);
    document.write ("&amp;exclude=" + document.phpAds_used);
    if (document.referrer)
       document.write ("&amp;referer=" + escape(document.referrer));
    document.write ("'><" + "/script>");
} 

function validaContact(){
    var n=true;
    
    n=validateCheckbox('avis','msgerror','Has d\'acceptar l\'av\xEDs legal');
    
    if (n!=false) n=true; 

    if (n)
    {
        $('support-form').submit();
    }
}

function validateCheckbox(id,msgArea,alertText){ 
    field = $(id);
    
    if(field.checked!=true)
    {
        showMsgBox(msgArea, alertText);
        // change the color of text field
       field.addClassName('fieldError');
        field.focus();
        // make sure the form is not submitted
        return false;
    }
    else 
    {
        field.removeClassName('fieldError');
        $(msgArea).hide();
        return true;
    }
}

function showMsgBox (msgArea, msgText)
{
    $(msgArea).style.display='block';
    
    $(msgArea).update(msgText);
}

function trim(str)
{
    return str.replace(/^\s*|\s*$/g,"");
}


function validaNewsletter() { 
    var e=true;
        
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','L\'adre\xE7a indicada no \xE9s correcta', 'Si us plau, indica el teu e-mail');    
   
    if (e!=false) e=true;
        
    if (e) {
        document.getElementById('newsletter').submit();
    }                 
} 

function validateEmail(id,msgArea,msg,alertText)
{
    // check the first email address ( the exclamation means "not" )
    field = document.getElementById (id);
    if(!check_email(field.value)){
        showMsg (msgArea,msg,alertText,true);
        // change the color of text field
        field.style.borderColor = "#990000";
        field.focus(); 
        // make sure the form is not submitted
        return false;
    }
    else {
        return true;
    }
}


function showMsg (msgArea, msg, msgText,isError){
    displayArea = document.getElementById (msgArea);
    displayElement =  document.getElementById (msg);
    displayArea.style.display = "";
   /* if (isError) {
        displayArea.style.backgroundColor="#ffffff";
    }
    else {
        displayArea.style.backgroundColor="#ffffff";    
    }*/
    if (!isDOMCompliant) {
        alert (msgText);
    }
    else {
        
        changeElementText (displayElement,msgText);
        //document.location.href="#top";    
    }
}

function changeElementText (node,text) 
{
    while (node.hasChildNodes()) {
        node.removeChild(node.lastChild);
    }
    var textNode = document.createTextNode(text);
    node.appendChild(textNode );
}

function isDOMCompliant ()
{
        return (document.getElementsByTagName && document.createElement);
}

function check_email (emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress); 
}



//Timer

var mins,secs,TimerRunning,TimerID;
 TimerRunning=false;
 
 function Init() //call the Init function when u need to start the timer
 {
    mins=0;
    secs=30;  
    StopTimer(); 
    StartTimer();
 } 
 
 function StopTimer()
 {
    if(TimerRunning)
       clearTimeout(TimerID);
    TimerRunning=false;
 }
 
 function StartTimer()
 {
    TimerRunning=true;
    window.status="Time Remaining "+Pad(mins)+":"+Pad(secs);
    TimerID=self.setTimeout("StartTimer()",1000);
 
    Check();
    
    if(mins==0 && secs==0)
       StopTimer();
    
    if(secs==0)
    {
       mins--;
       secs=60;
    }
    secs--;
 
 }
 
 function Check()
 {
    if(mins==0 && secs==0)
    { 
    loadQuiosc();     
    }
 }
 
 function Pad(number) //pads the mins/secs with a 0 if its less than 10
 {
    if(number<10)
       number=0+""+number;
    return number;
 }
 
function setOpacity(){
       if (document.getElementById('layer')){
		var oe = document.getElementById('layer');
                // Set transparency to 50%
                oe.setAttribute("style", "opacity:0.5;")
		if (oe.style.setAttribute) //For IE
		oe.style.setAttribute("filter", "alpha(opacity=50);") 
	}
 }

function loadQuiosc (){   

    var aleatorio = Math.random()     

	new Ajax.Updater({ success: 'quiosc', failure: 'quiosc' }, 'http://www.lluisaragones.cat/index.php', { 
					 method: 'get',
					 evalScripts: true,
					 encoding: 'iso-8859-1', 
     				 parameters: {command:'transform', style:'quiosc', idpublic:'1', aleator: aleatorio},
     				 onCreate: showLoader,
                     onComplete: hideLoader	
                    });  
}


function showLoader(){
        $('layer').style.visibility="visible";
    }

function hideLoader(){
        $('layer').style.visibility='hidden';
        displayItems(); 
        Init(); 
    }
    
function displayItems(){    
    var rand_no = Math.ceil(4*Math.random());
    
    if (rand_no==1){
        $('item1').style.display='block';
        $('item2').style.display='block';
        $('item3').style.display='none';
        $('item4').style.display='none';
        $('item5').style.display='none';
        $('item6').style.display='none';
        $('item7').style.display='none';
        $('item8').style.display='none';
    }
    
    if (rand_no==2){
        $('item1').style.display='none';
        $('item2').style.display='none';
        $('item3').style.display='block';
        $('item4').style.display='block';
        $('item5').style.display='none';
        $('item6').style.display='none';
        $('item7').style.display='none';
        $('item8').style.display='none';
    }
    
    if (rand_no==3){
        $('item1').style.display='none';
        $('item2').style.display='none';
        $('item3').style.display='none';
        $('item4').style.display='none';
        $('item5').style.display='block';
        $('item6').style.display='block';
        $('item7').style.display='none';
        $('item8').style.display='none'; 
    }
    
     if (rand_no==4){
        $('item1').style.display='none';
        $('item2').style.display='none';
        $('item3').style.display='none';
        $('item4').style.display='none';
        $('item5').style.display='none';
        $('item6').style.display='none';
        $('item7').style.display='block';
        $('item8').style.display='block';
    }
}

//incrustar videos

function add_video(url,root_video,width,height)
{

 if(navigator.appName=="Microsoft Internet Explorer")
    {
        var text="<embed src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" autoplay=\"false\" wmode=\"transparent\">"
        +"<param name=\"cache\" value=\"true\">"
        +"<param name=\"type\" value=\"video/quicktime\">"
        +"<param name=\"bgcolor\" value=\"#FFFFFF\">"
        +"<param name=\"controller\" value=\"true\">"
        +"<param name=\"showcontrols\" value=\"1\"/>"
        +"<param name=\"enablejavascript\" value=\"TRUE\">"
        +"<param name=\"showdisplay\" value=\"1\">"
        +"<param name=\"wmode\" value=\"transparent\"/>"
        +"<param name=\"qtnext1\" value=\"javascript:GAMIndexAds.endMovie(GAMIndexAds.oCurrentMovie);\">"
        +"</embed>";
    
    } else {
        var text="<object width=\""+width+"\" height=\""+height+"\">"
            +"<param name=\"movie\" value=\""+url+"\"/>"
            +"<param name=\"wmode\" value=\"transparent\"/>"
            +"<embed src=\""+url+"\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\""+width+"\" height=\""+height+"\"/>"
            +"</object>";
    }
    $(root_video).update(text);
}


function loadVideos()
{

    var videos=$$('.urlvideo');
    if ($('video-width')!=null && $('video-height')!=null)
    {
        var width=$F('video-width');
        var height=$F('video-height');
    }

    for (i=0; i<videos.length;i++)
    {
        add_video(videos[i].value,'root_video_'+videos[i].id.substring(10),width,height);
    }
}

function loadAudio(){
    var strVar="";
    strVar += "<object width=\"300\" height=\"180\">";
    strVar += "<embed src=\"http:\/\/www.goear.com\/files\/externalpl.swf?file=ebeb579\" type=\"application\/x-shockwave-flash\" wmode=\"transparent\" quality=\"high\" width=\"300\" height=\"180\"><\/embed>";
    strVar += "<\/object>";
    
    $('root_audio').update(strVar);  
}

    
function addEvent(obj, evType, fn){  
    if (obj.addEventListener){ 
            obj.addEventListener(evType, fn, false); 
            return true; 
            } else if (obj.attachEvent){ 
            var r = obj.attachEvent("on"+evType, fn); 
            return r; 
            } else { 
            return false; 
        } 
}

function load(){ 
    addEvent(window, 'load', setOpacity);
    addEvent(window, 'load', loadQuiosc);
    addEvent(window, 'load', loadVideos);
    addEvent(window, 'load', loadAudio);
}
    
load()









