// CafeCrift JavaScripts
// Función para modificar tamaño de fuentes tipográficas

var newsfont = 10;

function changeFont(id) {

if (document.getElementById) {
        document.getElementById(id).style.fontSize = newsfont+"px";
    } else {
        if (document.layers) {
            document.layers[id].fontSize = newsfont+"px";
        } else {
            if (document.all) {
                eval("document.all." + id + ".style.fontSize = \"" + newsfont + "px \"");
            }
        }
    }
	
        setCookie();
}

function larger() {
    if (newsfont < 20) {
        newsfont= newsfont +2;
        changeFont('content');
    }
}

function smaller() {
    if (newsfont > 5) {
    newsfont= newsfont -2;
    changeFont('content');
    }
}

// Función para chequear validez de emails en suscripciones

function checksub()
{
 var str = sub.email.value;
 var re = /^[A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)*[@][A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)+$/;
 if (!re.test(str))
 {
   window.alert('Tienes que ingresar un e-mail válido!');
   sub.email.focus();
   return false;
 }
 return true;
}

// funciones para almacenar tamaño de texto en cookie

cookie_name = "fontsize";

function setCookie() {

    if(document.cookie != document.cookie) { 
    index = document.cookie.indexOf(cookie_name);
    }
    else { 
    index = -1;
    }

    if (index == -1) {
    document.cookie=cookie_name+"="+newsfont+"; expires=thuesday, 01-Apr-2008 05:00:00 GMT";
    }

}

function getCookie() {
    if(document.cookie) {
    index = document.cookie.indexOf(cookie_name);
    if (index != -1) {
        namestart = (document.cookie.indexOf("=", index) + 1);
        nameend = document.cookie.indexOf(";", index);
        if (nameend == -1) nameend = document.cookie.length;
        val = document.cookie.substring(namestart, nameend);
        return parseInt(val);
    }
    }
}

// Aqui comenzamos el seteo de cookies para comentarios.

var HOST = '<$MTBlogHost$>';

// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    setCookie('mtcmtauth', f.author.value, now, '', HOST, '');
    setCookie('mtcmtmail', f.email.value, now, '', HOST, '');
    setCookie('mtcmthome', f.url.value, now, '', HOST, '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '', HOST);
    deleteCookie('mtcmthome', '', HOST);
    deleteCookie('mtcmtauth', '', HOST);
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}

// Funciones para validar formulario de contacto

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe ser un e-mail válido.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' debe contener un número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' debe ser un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es requerido.\n'; }
  } if (errors) alert('Por favor corrija el siguiente error:\n'+errors);
  document.MM_returnValue = (errors == '');
}