var currSize = 1;

function swichStyleSheetSrc(size) {
    var styleName = 'size'+size;
    $('link[@rel*=STYLE][@title]').each(function() {
        this.disabled = true;
        if($(this).attr('title')==styleName) {
            this.disabled = false;
        }
    });
    $.cookie('styles',size,{expires:7,path:'/'});
}

function disableAll() {
    $('link[@rel*=STYLE]').each(function() {
        this.disabled = true;
    });
}


function setBookmark() {
    var bookmarkurl = location.href;
    var text = document.title;
    text = text.replace(/:/ ,"");
    text = text.replace(/\*/ ,"");
    text = text.replace(/\?/ ,"");
    text = text.replace(/\\/ ,"");
    text = text.replace(/"/ ,"");
    text = text.replace(/</ ,"");
    text = text.replace(/>/ ,"");
    text = text.replace(/|/ ,"");
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(text, bookmarkurl,"");
    } else if( window.external ) { // IE Favorite
        window.external.AddFavorite( bookmarkurl, text);
    } else if(window.opera && window.print) { // Opera Hotlist
        return true;
    }
}

$().ready(function() {
    if(document.all) {
        try {document.execCommand("BackgroundImageCache",false,true);} catch(e){}
    }
    $('#AddBookmark').click(function(){setBookmark(); return false;});
    $('#TextVersion').click(function(){disableAll(); return false;});

    if($.cookie('styles')) {
        currSize = parseInt($.cookie('styles'));
        var isActive = false;
        $('link[@rel*=STYLE][@title]').each(function() {
              if($(this).attr('rel').indexOf('ALTERNATE')==-1
                && $(this).attr('title')=='size'+currSize) {
                    isActive = true;
              }
        });
        $('#fs_size'+currSize).addClass('active');
        if(!isActive) {
            swichStyleSheetSrc(currSize);
        }
    }
    var maxSizes = $('#FontSizer .size').size();
    if(maxSizes > 0) {
        if(currSize==1) {
            $('#fs_minus').addClass('disabled');
        } else if(currSize==maxSizes) {
            $('#fs_plus').addClass('disabled');
        }
        $('#FontSizer .size').click(function() {
            currSize = parseInt(this.id.replace(/fs_size/g,''));
            $('#FontSizer .size').each(function(){$(this).removeClass('active');});
            $(this).addClass('active');
            if(currSize==1) { $('#fs_minus').addClass('disabled');}
            else {$('#fs_minus').removeClass('disabled');}
            if(currSize==maxSizes) { $('#fs_plus').addClass('disabled');}
            else {$('#fs_plus').removeClass('disabled');}
            swichStyleSheetSrc(currSize);
            return false;
        });
         $('#fs_minus').click(function(){
            if(currSize > 1) {
                currSize--;
                $('#FontSizer .size').each(function(){$(this).removeClass('active');});
                $('#fs_size'+currSize).addClass('active');
                if(currSize==1) { $('#fs_minus').addClass('disabled');}
                else {$('#fs_minus').removeClass('disabled');}
                $('#fs_plus').removeClass('disabled');
                swichStyleSheetSrc(currSize);
            }
            return false;
         });
         $('#fs_plus').click(function(){
                 if(currSize < maxSizes) {
                     currSize++;
                     $('#FontSizer .size').each(function(){$(this).removeClass('active');});
                     $('#fs_size'+currSize).addClass('active');
                     if(currSize==maxSizes) { $('#fs_plus').addClass('disabled');}
                     else {$('#fs_plus').removeClass('disabled');}
                     $('#fs_minus').removeClass('disabled');
                     swichStyleSheetSrc(currSize);
                 }
                 return false;
         });
     }
     $('#glossarTable a').open();
     $('a[@rel*=mail]').click(function() {
                 var url = this.href;
                 if (navigator.appName == "Netscape"){
                     url = url.replace(/index\.php/,'index_ns.php');
                 }
                 window.open(url,'Mail','width=468,height=565,scrollbars=yes');
                 return false;
     });
     $('.popup .print,.popup .close').css({'cursor':'pointer'});
     $('.popup .print').click(function(){
                    window.print();
                    return false;
              });
              $('.popup .close').click(function(){
                    self.close();
                    return false;
     });
});


var img_formula, img_ayuda, img_envase, img_tomar;
img_formula = new Image();
img_formula.src = "/html/images/upload/formula_big.jpg";
img_ayuda = new Image();
img_ayuda.src = "/html/images/upload/ayuda_big.jpg";
img_envase = new Image();
img_envase.src = "/html/images/upload/envases_big.jpg";
img_tomar= new Image();
img_tomar.src = "/html/images/upload/tomarlo_big.jpg";

function showHidden(elmt){
	var element = document.getElementById(elmt);
	var titulillo = document.getElementById(elmt+"Tit");
	//alert(elmt+"_big.gif");
	element.firstChild.src = "/html/images/upload/"+elmt+"_big.jpg";
	titulillo.style.visibility = "visible";
	
}


function hideShown(elmt){
	var element = document.getElementById(elmt);
	var titulillo = document.getElementById(elmt+"Tit");
	element.firstChild.src = "/html/images/upload/"+elmt+".jpg";
	titulillo.style.visibility = "hidden";
}

/***** validate email for contact form eBB Web 07-aug-2008 *******/

function validarEmail(valor) {
var errorEmail;
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
return ("ok")
} else {
return ("\nLa direcci&oacute;n de email es incorrecta.");
}
}


/***** validate contact form eBB Web 07-aug-2008 *******/
function Validate(formName){
var form = document.getElementById(formName);
//alert(validarEmail(form.email.value));
var message = "";
if(form.Nombre.value == "") message += "Inserte un Nombre de contacto";
if(validarEmail(form.email.value) != "ok") message += "\nInserte un Email valido";
if(form.texto.value == "") message += "\nInserte un Mensaje para Enviar a Bayer Health care";

if(message == "") form.submit();
 else alert(message);
 }

