var counter = 0;

function displayPoll ()
{
	new Ajax.Updater({ success: 'poll', failure: 'poll' },'display-poll.php', {
					 method: 'get',
					 evalScripts: false					 
                    });
}

function displayPollResults (pollId)
{
	new Ajax.Updater({ success: 'poll-results', failure: 'poll-results' },'display-poll.php', {
					 method: 'get',
		             parameters: {action: 'results', poll_ident: pollId}	
					 });
}

function displayPollList ()
{
	new Ajax.Updater({ success: 'poll-results', failure: 'poll-results' },'http://www.cori.cat/pollphp/db/other_polls.php', {
					 method: 'get',
		             parameters: {action: 'results'}	
					 });
}

function fbs_click() {
            u=location.href;
            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(id, url) {

         if (!document.phpAds_used) document.phpAds_used = ',';
         phpAds_random = new String (Math.random()); 
         phpAds_random = phpAds_random.substring(2,11);
         document.write ("<div class=\"banner\">");
         document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
         document.write (url+"/phpadsnew/adjs.php?n=" + phpAds_random);
         
         document.write ("&amp;what=zone:"+id);
         
         
         document.write ("&amp;exclude=" + document.phpAds_used);
         if (document.referrer)
         document.write ("&amp;referer=" + escape(document.referrer));
         
         document.write ("'><" + "/script>");
         
         document.write("</div>");
}

function validaEnviar()
{

    var e2=true;    
    
    e2=validateEmail('email2', 'msgerror','message','L\'e-mail introdu\357t no \351s v\340lid', 'Si us plau, introdueix l\'e-mail del teu amic');
    
    
    if (e2!=false) e2=true;
    
    if (e2) 
    {
        document.getElementById('formsend').submit();
    }                 

}

function validaNewsletter() {
    var e=true;
    var n=true;
    e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','E-mail inv\340lid', 'Indiqueu l\'e-mail');
    n=validateField('nlname','error-newsletter','msg-newsletter','Indiqueu el nom', 'Indiqueu el nom');
    if (e!=false) e=true;
    if (n!=false) n=true;
    
    if (e && n) {
        document.getElementById('subscribe').submit();
    }                 
}


function validateField(id,msgArea,msg,alertText,isError)
{
    field = document.getElementById(id);
    if(!check_field(field.value)){
        showMsg(msgArea, msg, alertText,isError);
        // change the color of text field
        field.style.borderColor = "red";
        field.focus();
        // make sure the form is not submitted
        return false;
    }
    else {
        return true;
    }
}

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 = "red";
        field.focus(); 
        // make sure the form is not submitted
        return false;
    }
    else {
        return true;
    }
}

function validateTextarea(id,msgArea,msg,alertText,isError)
{
    field = document.getElementById(id);
    if(!check_texta(field.value)){
    showMsg(msgArea, msg, alertText,isError);
    // change the color of text field
    field.style.borderColor = "red";
    field.focus();
    // make sure the form is not submitted
    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 showMsg (msgArea, msg, msgText,isError)
{
    displayArea = document.getElementById (msgArea);
    displayElement =  document.getElementById (msg);
    displayArea.style.display = "";
    if (isError) {
        displayArea.style.backgroundColor="#FF6666";
    }
    else {
        displayArea.style.backgroundColor="#FFFF99";    
    }
    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 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 check_field (f)
{
    var field = trim(f);
    if (field.length == 0) {
        return false;
    }
    else {
        return true;
    }
} 

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

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


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 load()
{
    addEvent(window, 'load', loadVideos);
}
    
load()
