
var GB_ROOT_DIR = "http://www.delcamp.cat/js/greybox/"; 

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.delcamp.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 displayPoll ()
{
	new Ajax.Updater({ success: 'poll', failure: 'poll' },'http://www.delcamp.cat/php/display-poll.php', {
					 method: 'get',
					 evalScripts: false					 
                    });
}

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

function displayPollList (){
	new Ajax.Updater({ success: 'poll-results', failure: 'poll-results' },'http://www.delcamp.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 viewsect(sel){
    if (sel.sections.selectedIndex != 0){
    document.location=sel.sections.options[sel.sections.selectedIndex].value
    }
}

function mobile(){
   if(screen.width <= 800){
      location.replace('http://www.delcamp.cat/index.php?command=transform&style=error-mobile') 
       }          
    }
    
function deleteSearch ()
{   
    var search = document.getElementById('match').value;
    
     if (search=='Cercar not\xEDcies') {
     document.getElementById('match').value='';
    }		
}

function displayComments (newsId){   
    var aleatorio = Math.random() 
    

	new Ajax.Updater({ success: 'comments', failure: 'comments' }, 'http://www.delcamp.cat/index.php', {
					 method: 'get',
					 evalScripts: false,
					 encoding: 'iso-8859-1',
     				 parameters: {command: 'view_comments', news_id: newsId, aleator: aleatorio}	 
                    }); 
}

function viewRules(){ 

 if ($('rules').style.display=='block') {
        $('rules').style.display='none';    
        }
        else{
        $('rules').style.display='block';    
        }    
   }
   
function viewMobile(block){

 $('first-content').style.display='none';
 $('second-content').style.display='none';
 $('third-content').style.display='none';

 $(block).style.display='block'; 
   }
   
function viewShare(block){

 $('first-content').style.display='none';
 $('second-content').style.display='none';

 $(block).style.display='block'; 
   }
   
function view_issues(){

    var id_issue=$('anios').value;      
    var fechas=document.getElementsByClassName('date_issue');    
    var counter=0;
    
    for (var index = 0; index < fechas.length; ++index) {
      var item = fechas[index];
      
       if (id_issue==item.value)
        {
        
          item.parentNode.style.display='block';
          counter++;
        }
        else 
        {
         item.parentNode.style.display='none';
        }
    }   
} 

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

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

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

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

function validaRecomanar()
{
    var n=true;
    var e2=true;
    
    var emissor = document.getElementById('email1').value; 
    
     if (emissor==''){
     document.getElementById('email1').value=":";
     }
    
    
    n=validateField('name','msgerror','message','Si us plau, indiqueu el vostre nom', 'Si us plau, indiqueu el vostre nom');
    e2=validateEmail('email2', 'msgerror','message','L\'adre\xE7a indicada no \xE9s correcta', 'Si us plau, indiqueu el vostre e-mail');  
    
    if (n!=false) n=true;
    if (e2!=false) e2=true;
 
    
    if (n && e2) 
    {
        document.getElementById('contact-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 validaNewsletter() { 
    var e=true;
        
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','L\'adre\xE7a indicada no \xE9s correcta', 'Si us plau, indiqui el seu 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 = "red";
        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 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 deleteNewsletEmail (){   
    var contentEmail = document.getElementById('nlemail').value;
    
     if (contentEmail=='e-mail') {
     document.getElementById('nlemail').value='';
    }		
	}
	
function validaComentari()
{   
    var n=true;
    var e=true;
    var t=true; 
    
       
    n=validateField('name','msgerror','message','Si us plau, indiqueu el vostre nom', 'Si us plau, indiqueu el vostre nom');       
    e=validateEmail('email-com','msgerror','message','L\'adre\xE7a indicada no \xE9s correcta', 'L\'adre\xE7a indicada no \xE9s correcta'); 
    t=validateField('title','msgerror','message','Si us plau, indiqueu un t\xEDtol', 'Si us plau, indiqueu un t\xEDtol');
    
    if (t!=false) t=true;
    if (n!=false) n=true;
    if (e!=false) e=true;
 
    
    if (t && n && e) 
    {
        stripHTML(document.getElementById('comment'));
        document.getElementById('comment-form').submit();
    }                 
}

function validaComentariMobile()
{   
    var n=true;
    var e=true;
    var t=true; 
    
       
    n=validateField('name','msgerror','message','Si us plau, indiqueu el vostre nom', 'Si us plau, indiqueu el vostre nom');       
    e=validateEmail('email-com','msgerror','message','L\'adre\xE7a indicada no \xE9s correcta', 'L\'adre\xE7a indicada no \xE9s correcta'); 
    t=validateField('title','msgerror','message','Si us plau, indiqueu un t\xEDtol', 'Si us plau, indiqueu un t\xEDtol');
    
    if (t!=false) t=true;
    if (n!=false) n=true;
    if (e!=false) e=true;
 
    
    if (t && n && e) 
    {
        stripHTML(document.getElementById('comment'));
        document.getElementById('formsend').submit();  
    }                 
}

function stripHTML(){
    var re = /(<([^>]+)>)/gi;
    for (i=0; i<arguments.length; i++)
    arguments[i].value=arguments[i].value.replace(re, "");
}


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 check_field (f)
{
    var field = trim(f);
    if (field.length == 0) {
        return false;
    }
    else {
        return true;
    }
} 
	
//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 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; 
        } 
}

window.onload=function() {
    fontsize(cookieGrab('fontSize'));   
 }
 
 function fontsize(v) { 
    if(v) {
        if (document.getElementById('block-1')){
            $('block-1').style.fontSize=v+'px';
            cookieStab('fontSize',v);
        }
    }
   
}

function cookieGrab(f) {
    var c=document.cookie.split(';'); 
    f=f+"=";
    
for (var i = 0;i<c.length;i++) {
  var v=trim2(c[i]);  
  
  if(v.indexOf(f)==0) {       
        return(v.substr(f.length,v.length)); 
   } 
}

}

function trim2(v) { 
    return(v.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,""));
     }

function cookieStab(f,v) {
    miliseconds=parseInt(365*24*60*60*1000);
    var date = new Date();  
    
    time=date.getTime();
    total=date.setTime(parseInt(time+miliseconds));
      
    document.cookie=f+'='+v+'; path=/'+'; expires=' + date.toGMTString();
 }
 
function printDate() {
    Fecha = new Date();
    
    if ($('date')!=null){
        $('date').update(Fecha.getDate()+" "+getMonth(Fecha.getMonth())+' de '+Fecha.getFullYear()); 
    }
        
    if (document.getElementById('date-weather')){
     switch (Fecha.getDate()) {
        case 1, 11 : 
        $('date-weather').update("l' "+Fecha.getDate()+" "+getMonth(Fecha.getMonth())+" de "+Fecha.getFullYear());  
        break; 
        
        default:
        $('date-weather').update("el "+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;
}

//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)
    { 
    loadLastGame(); 
    loadNewsGame();    
    }
 }
 
 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 loadLastGame (){   
    var aleatorio = Math.random()     

	new Ajax.Updater({ success: 'last_game', failure: 'last_game' }, 'http://www.delcamp.cat/php/last-game.php', {
					 method: 'get',
					 evalScripts: true,
					 encoding: 'iso-8859-1',
     				 parameters: {aleator: aleatorio}, 
                     onCreate: showLoader,
                     onComplete: hideLoader	 
                    }); 
}

function loadNewsGame (){   
    var aleatorio = Math.random()     

	new Ajax.Updater({ success: 'news_game', failure: 'news_game' }, 'http://www.delcamp.cat/php/last-game.php', {
					 method: 'get',
					 evalScripts: true,
					 encoding: 'iso-8859-1',
     				 parameters: {aleator: aleatorio, page_ident: 'news'},
                     onCreate: showLoader,
                     onComplete: hideLoader	 
                    }); 
}



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

function hideLoader(){
        $('layer').style.visibility='hidden';
        Init();
    }
    
function displayBanner (){
	new Ajax.Updater({ success: 'gameban', failure: 'gameban' },'http://www.delcamp.cat/php/display-banner.php', {
					 method: 'get',
					 evalScripts: true		     				 
                    });
}

function loadBanner(){
	
	var d = new Date();
	var ran = d.getTime();
 
  
 var text="<iframe id=\'a0b2cba1\' name=\'a0b2cba1\' src=\'http:\/\/ads.delcamp.cat\/www\/delivery\/afr.php?n=a0b2cba1&amp;zoneid=3&amp;cb="+ran+"\' framespacing=\'0\' frameborder=\'no\' scrolling=\'no\' width=\'234\' height=\'90\'><a href=\'http:\/\/ads.delcamp.cat\/www\/delivery\/ck.php?n=aecd64af&amp;cb="+ran+"\' target=\'_parent\'><img src=\'http:\/\/ads.delcamp.cat\/www\/delivery\/avw.php?zoneid=3&amp;cb="+ran+"&amp;n=aecd64af\' border=\'0\' alt=\'\' \/><\/a><\/iframe>\n"  
   			
	 if (document.getElementById('gameban')){		  
        $('gameban').update(text);    
    }
   
}

function load(){
    addEvent(window, 'load', printDate);
    addEvent(window, 'load', loadVideos);  
    addEvent(window, 'load', setOpacity);
    addEvent(window, 'load', loadLastGame);
    addEvent(window, 'load', loadNewsGame);
}
    
load()


