
function validaNewsletter(lang) {  
    var n=true; 
    var e=true;
    
    if (lang=='ca') {
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','Si us plau, inseriu un e-mail v\xE0lid', 'Si us plau, inseriu un e-mail v\xE0lid');
        n=validateField('nlname','error-newsletter','msg-newsletter','Si us plau, inseriu un nom', 'Si us plau, inseriu un nom');       
    }
    else if (lang=='es') { 
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','Por favor, inserte un e-mail v\xE1lido', 'Por favor, inserte un e-mail v\xE1lido');
        n=validateField('nlname','error-newsletter','msg-newsletter','Por favor, escriba un nombre', 'Por favor, escriba un nombre');
    }
    else if (lang=='en') {
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','Please insert a valid e-mail', 'Please insert a valid e-mail');
        n=validateField('nlname','error-newsletter','msg-newsletter','Please insert your name', 'Please insert your name');
    }
    else if (lang=='de') {
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','Bitte schreiben Sie eine g\xFCltige E-Mail', 'Bitte schreiben Sie eine g\xFCltige E-Mail'); 
        n=validateField('nlname','error-newsletter','msg-newsletter','Bitte schreiben Sie Ihren Namen', 'Bitte schreiben Sie Ihren Namen');
    }
    else if (lang=='ru') {
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','Пожалуйста, введите адреcс электронной почты', 'Пожалуйста, введите адреcс электронной почты');
        n=validateField('nlname','error-newsletter','msg-newsletter','Пожалуйста, введите ваше имя', 'Пожалуйста, введите ваше имя'); 
    }
    else if (lang=='fr') { 
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','S\'il vous pla\xEEt ins\xE9rez un e-mail valide', 'S\'il vous pla\xEEt ins\xE9rez un e-mail valide'); 
        n=validateField('nlname','error-newsletter','msg-newsletter','S\'il vous pla\xEEt ins\xE9rez votre nom', 'S\'il vous pla\xEEt ins\xE9rez votre nom');
    }
   
    if (n!=false) n=true;
    if (e!=false) e=true;
        
    if (n && e) { 
        document.getElementById('newsletter').submit(); 
    }                  
} 

function validateField(id,msgArea,msg,alertText,isError){

    field = document.getElementById(id); 
     
    if(!check_field(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 validateEmail(id,msgArea,msg,alertText){
    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 (!isDOMCompliant) { 
        alert (msgText);
    }
    else {
        changeElementText (displayElement,msgText);    
    }
}

function check_field (f)
{
    var field = trim(f);
    if (field.length == 0) {
        return false;
    }
    else {
        return true;
    }
} 

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

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 displayNewsletter(){   
    var namee =  $('nlname').value;
    var emaile = $('nlemail').value;
    var groupe = $('nl_group_id').value;  
    
    var news = $('select-newslet').checked;
    var aleatorio = Math.random(); 
    
    if (news==true) {   
    	
	new Ajax.Request('http://www.tarracoiuris-abogados.com/lib/proxy.php?proxy_url=http://invicem.editiosoftware.com/customers/tarracoiuris-abogados.com/index.php?command=subscribe_user', {
					 method: 'post',
					 evalScripts: true,
					 encoding: 'utf-8',  
     				 parameters: {name: namee, email: emaile, nl_group_id: groupe, aleator: aleatorio},
     				 onSuccess: sendContact()
                    });                                                        
     }
     else{
     sendContact();
     }                      
}

function sendContact(){  
    document.getElementById('contact-form').submit();  
}


//incrustar mapes 

function add_map(url,root_map,width,height){

 if(navigator.appName=="Microsoft Internet Explorer")
    {
       var text="<iframe src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" >"+"</iframe>";    
    
    } else { 
       var text="<object data=\""+url+"\" width=\""+width+"\" height=\""+height+"\">"+"</object>"; 
    }
    $(root_map).update(text);  
}


function loadMaps(){

    var maps=$$('.urlmap');   
    
    if ($('map-width')!=null && $('map-height')!=null)
    {
        var width=$F('map-width');
        var height=$F('map-height'); 
    }

    for (i=0; i<maps.length;i++)
    {
        add_map(maps[i].value,'root_map_'+maps[i].id.substring(8),width,height);    
    }
}

//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 add_ivideo(url,root_video,width,height){ 

    var text="<iframe src=\""+url+"\" width=\""+width+"\" height=\""+height+"\"  frameborder=\"0\" scrolling=\"no\" style=\"border:0;outline:0\" >"+"</iframe>";    
    
    $(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 loadiVideos(){    

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

    for (i=0; i<videos.length;i++)
    {
        add_ivideo(videos[i].value,'root_ivideo_'+videos[i].id.substring(11),width,height);  
    }
}

window.onload=function() {
    fontsize(cookieGrab('fontSize'));   
 }
 
 function fontsize(v) { 
    if(v) {
        if (document.getElementById('content-mobile')){
            $('content-mobile').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 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);
    addEvent(window, 'load', loadiVideos); 
    addEvent(window, 'load', loadMaps);
}
    
load() 

