function moveFooter() {
    if(($(document).height() > $(window).height())) {
        $('footer').css('position','relative');
    }
    else {
        $('footer').css('position','absolute');
    }
}

function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(email);
}
function validateTel(tel) {
   var reg = /^[\+0-9\s\-\.]{6,10}$/;
   return reg.test(tel);
}
function submitform(url,elm,form) {
    $.post(url, $(form).serialize(), function(data) {$($__(elm)).html(data);});
}


function toUnicode(theString,html) {
  var unicodeString = '';
  for (var i=0; i < theString.length; i++) {
    var theUnicode = theString.charCodeAt(i).toString(16).toUpperCase();
    while (theUnicode.length < 4) {
      theUnicode = '0' + theUnicode;
    }
    theUnicode = (html?'&#x':'\\u') + theUnicode;
    unicodeString += theUnicode;
  }
  return unicodeString;
}

function wrmPrint(ac,dom,tld) {
    var em=toUnicode(ac+'\u0040'+dom+"\u002E"+tld,true);
    document.write(em);
}
function wrmReplace(ac,dom,tld,id,lnk) {
    if(document.all) var em=ac+'\u0040'+dom+'\u002E'+tld;
    else var em=toUnicode(ac+'\u0040'+dom+"\u002E"+tld,true);
    if(lnk) em='<a href="mailto:'+em+'">'+em+'</a>';
    $(id).html(em);
}

function forumPost(n) {
    $('#publicar'+n).toggleClass('oculto').load('/content/foro_add.php?n='+n);
}

function sendForm(f,t) {
    f=$(f);
    $.post(f.attr('action'), f.serialize(), function(data) { $(t).html(data); });
    return false;
}


function number_format(number, decimals, dec_point, thousands_sep, del_zero) { // http://kevin.vanzonneveld.net
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    
	s=s.join(dec);
	
	if(del_zero) s=s.replace(/(,[1-9]*)0+$/,"\$1");
    
	return s.replace(/,$/,"");
}

function precio(n) {
	return number_format(n,2,',','.',false);
}


$(function() {
   moveFooter();
   wrmReplace('info','amigosenruta','com','.wrm_01',true);
});

$(window).resize(function() {
  moveFooter();
});

