
var GB_ROOT_DIR = "http://www.lavozdepinares.com/js/greybox/"; 

function searchNews(query) {
    window.location.href = "index.php?command=search_news&match="+query;
}

function mobile(){
   if(screen.width <= 800){
      location.replace('http://www.lavozdepinares.com/index.php?command=transform&style=error-mobile') 
       }          
    }

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(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://www.lavozdepinares.com/adserver/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 displayComments (newsId)
{
    var aleatorio = Math.random() 
	new Ajax.Updater({ success: 'comments', failure: 'comments' }, 'index.php', {
					 method: 'get',
					 encoding: 'iso-8859-1',
     				 parameters: {command: 'view_comments', news_id: newsId, aleator: aleatorio}	 
                    });
}

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) {
            element[index-1].style.display='none';
        }
        element[index].style.display='block';
        if (completed) {
            element[size-1].style.display='none';
        }
        setTimeout(call,3000,size);
    });
}

/*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 ("<" + "script language='JavaScript' type='text/javascript' src='");
         document.write (url+"/adserver/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>");
   
}*/


function validaNewsletterEs() {
    var e=true;
    
    e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','El correo introducido es incorrecto', 'Indicar el e-mail');
   
    if (e!=false) e=true;
        
    if (e) {
        document.getElementById('subscribe').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="#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 isDOMCompliant ()
{
        return (document.getElementsByTagName && document.createElement);
}


function validaEnviarEs()
{
    var n=true;
    var e2=true;    
    var m=true;
    
    n=validateField('name','msgerror','message','Por favor, indique su nombre', 'Por favor, indique su nombre');
    e2=validateEmail('email2', 'msgerror','message','La direcci\363n de correo indicada no es v\xE1lida', 'Por favor, indique su direcci\363n de correo');
    m=validateTextarea('comment', 'msgerror','message','Por favor, escriba un mensaje', 'Por favor, escriba un mensaje');    
    
    if (n!=false) n=true;
    if (e2!=false) e2=true;
    if (m!=false) m=true;
 
    
    if (n && e2 && m) 
    {
        document.getElementById('formsend').submit();
    }                 
}

function validaComentarioEs()
{
    var n=true;
    var t=true;    
    var c=true;
    
    n=validateField('name','msgerror','message','Por favor, indique su nombre', 'Por favor, indique su nombre');
    t=validateField('title', 'msgerror','message','Por favor, indique el título del comentario', 'Por favor, indique  el título del comentario');
    c=validateTextarea('comment', 'msgerror','message','Por favor, escriba un comentario', 'Por favor, escriba un comentario');    
    
    if (n!=false) n=true;
    if (t!=false) e2=true;
    if (c!=false) m=true;
 
    
    if (n && t && c) 
    {
        document.getElementById('formsend').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 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_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 view_issues(){

    var id_issue=$('anios').value+"-"+$('meses').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';
        }
    } 
     if (counter==0) {
        $('no_issues').style.display='block';
        $('issues_found').style.display='none';
    } else
    {
        $('no_issues').style.display='none';
        $('issues_found').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 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) {
    $('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 load(){
    addEvent(window, 'load', loadVideos);
}
    
load()

