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://mussol.cat/santquirze/openads/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>");

}


// Marca la hora 
function startTime()
{
    function checkTime(i)
    {
    if (i<10) 
      {i="0" + i}
      return i
    }

    var today=new Date()
    var h=today.getHours()
    var m=today.getMinutes()
    var s=today.getSeconds()
    // add a zero in front of numbers<10
    m=checkTime(m)
    s=checkTime(s)

    $('hours').update(h+":"+m+":"+s);
    t=setTimeout('startTime()',500)
}

function validaEnviar()
{
    var n=true;
    var e1=true;
    var e2=true;    
    
    n=validateField('name','errorName','Si us plau, indica el teu nom');
    e1=validateEmail('email1', 'errorEmail1','L\'adre\xE7a indicada no \xE9s correcta');
    e2=validateEmail('email2', 'errorEmail2','L\'adre\xE7a indicada no \xE9s correcta');
    
    if (n!=false) n=true;
    if (e1!=false) e1=true;
    if (e2!=false) e2=true;
    
    if (n && e1 && e2) 
    {
        $('contact-form').submit();
    }                 
}

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

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

function validateCheckbox(id,msgArea,alertText)
{
    field = $(id);
    
    if(field.checked!=true)
    {
        showMsg(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 validateField(id,msgArea,alertText)
{
    field = $(id);
    if(!check_field(field.value)){
        showMsg(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 validateTextarea(id,msgArea,alertText)
{
    field = $(id);
    if(!check_texta(field.value)){
    showMsg(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 validateEmail(id,msgArea,alertText)
{
    // check the first email address ( the exclamation means "not" )
    field =  $(id);
    if(!check_email(field.value)){
        showMsg (msgArea,alertText,true);
        // 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 check_field (f)
{
    var field = trim(f);
    if (field.length == 0) {
        return false;
    }
    else {
        return true;
    }
} 

function check_texta(f)
{
    if (f) {
        var field = trim(f);
        if (field.length == 0) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}
function trim(str)
{
    return str.replace(/^\s*|\s*$/g,"");
}

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

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

function deleteContentEmail ()
{   
    var contentEmail = $F('nlemail');
     if (contentEmail=='E-mail') $('nlemail').value='';
}
function validaNewsletter() {
    var e=true;
    e=validateEmail('nlemail', 'error-newsletter','L\'adre\xE7a indicada no \xE9s correcta'); 

    if (e!=false) e=true;
        
    if (e) $('newsletter').submit();
                     
} 


// Incrustar video  
function add_video2(url, root_video,width,height)
{
    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 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 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 printDate() 
{
    Fecha = new Date();
    $('date').update(Fecha.getDate()+" "+getMonth(Fecha.getMonth())+' de '+Fecha.getFullYear());   
}

function getMonth(id) 
{
    switch (id) {
        case 0 : mes="de gener"; break;
        case 1 : mes="de febrer"; break; 
        case 2 : mes="de mar\xe7"; break; 
        case 3 : mes="d'abril"; break; 
        case 4 : mes="de maig"; break; 
        case 5 : mes="de juny"; break; 
        case 6 : mes="de juliol"; break; 
        case 7 : mes="d'agost"; break; 
        case 8 : mes="de setembre"; break; 
        case 9 : mes="d'octubre"; break; 
        case 10 : mes="de novembre"; break;
        case 11 : mes="de desembre"; break; 
    }
    return mes;
}

function execute(element,index,size) {

        return (function() {
            completed = false;
            if (index >= size) {
                index = 0;
                completed = true;
            }
            var call = execute (element,index+1,size);
            if (index > 0) {
    //            Effect.Fade(element[index-1]);
              element[index-1].style.display='none';
            }
        //    Effect.Appear(element[index],{delay:1});
        element[index].style.display='block';
            if (completed) {
//                Effect.Fade(element[size-1]);
            element[size-1].style.display='none';
            }
            setTimeout(call,6000,size);
        });
    }


 function displayHeadlines() 
    {    
        var news = $$('#marquee a');
        var vilaweb = $$('#ticker_vila a');
        
        if (news.length>0)
        {
            var call = execute (news,0,news.length);
            setTimeout(call,100);    
        }
        
        if (vilaweb.length>0)
        {
            var call2 = execute (vilaweb,0,vilaweb.length);
            setTimeout(call2,100);    
        }
        
        
    }


 function startList(){
        if (document.all&&document.getElementById) {
            navRoot = document.getElementById("nav");
            for (i=0; i<navRoot.childNodes.length; i++) {
                node = navRoot.childNodes[i];
                if (node.nodeName=="LI") {
                    node.onmouseover=function() {
                        this.className+=" over";
                    }
                    node.onmouseout=function() {
                        this.className=this.className.replace(" over", "");
                    }
                }
            }
        }
    }

function load()
{

    addEvent(window, 'load', startTime);
    addEvent(window, 'load', printDate);
    addEvent(window, 'load', startList);
    addEvent(window, 'load', displayHeadlines);
   addEvent(window, 'load', loadVideos);
}
    
load()