$(function(){
    if(typeof String.prototype.trim !== 'function') {
        String.prototype.trim = function() {
            return this.replace(/^\s+|\s+$/g, '');
        }
    }
});


function is_email(str)
{
    var filtro = /^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_.-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
    if (filtro.test(str)) return true;
    else return false;
}

function serialize(arr)
{
    var str = 'a:'+arr.length+':{';
    for(i=0; i<arr.length; i++)
    {
        str += 'i:'+i+';s:'+arr[i].length+':"'+arr[i]+'";';
    }
    str += '}';
    return str;
}

function stripslashes(str) {
    str=str.replace(/\\'/g,'\'');
    str=str.replace(/\\"/g,'"');
    str=str.replace(/\\0/g,'\0');
    str=str.replace(/\\\\/g,'\\');
    return str;
}

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

function is_array(input){
    return typeof(input)=='object'&&(input instanceof Array);
}

// Inicializar un input con un texto predeterminado
function _initInput(input_id, text_ini)
{
    input = $("#"+input_id);
    input.val(text_ini);
    input.attr("text_ini", text_ini);
    input.focus(function() {
        if ($(this).val() == $(this).attr("text_ini")) $(this).val("")
    });
    input.blur(function() {
        if ($(this).val() == "") $(this).val($(this).attr("text_ini"));
    });
    input.getTexto = function(){
        return $(this).val();
    };
}

//Adapta el alto de los IFRAME con class "googleiframe" según su contenido
//Esta función se auto-recarga 5 veces por si el contenido del IFRAME demora mucho en cargar
var countiframeresize=0;
function sizeIFrameGoogle(){
    $('.googleiframe').each(
        function() {
            var helpFrame = $(this);
            var innerDoc = (helpFrame.get(0).contentDocument) ? helpFrame.get(0).contentDocument : helpFrame.get(0).contentWindow.document;
            if (innerDoc.body)
                helpFrame.height(innerDoc.body.scrollHeight);
        });
    if (countiframeresize < 15){
        setTimeout("sizeIFrameGoogle()", 2500);
        countiframeresize++;
    }
}

/*
if (!console) {
	console = new Object();
	console.log = function(msg) {}
}
*/
