/**
 * Chama a mascara correspondente.
 */
function mascara(o,f)
{
    v_obj = o;
    v_fun = f;
    setTimeout("execMascara()",1);
}

/**
 * Executa a mascara.
 */
function execMascara()
{
    v_obj.value = v_fun(v_obj.value);
}

/**
 * Remove tudo o que nao e digito.
 */
function numeros(v)
{
    return v.replace(/\D/g,"");
}

/**
 * Formata um telefone no formato (11) 1111-1111.
 */
function telefone(v)
{
    v = v.replace(/\D/g,"");
    v = v.replace(/^(\d\d)(\d)/g,"($1) $2");
    v = v.replace(/(\d{4})(\d)/,"$1-$2");
    return v;
}

/**
 * Formata uma data no formato 11/11/1111.
 */
function data(v)
{
    v = v.replace(/\D/g,"");
    v = v.replace(/(\d{2})(\d)/,"$1/$2");
    v = v.replace(/(\d{2})(\d)/,"$1/$2");
    return v;
}

/**
 * Formata um cpf no formato 111.111.111-11.
 */
function cpf(v)
{
    v = v.replace(/\D/g,"");
    v = v.replace(/(\d{3})(\d)/,"$1.$2");
    v = v.replace(/(\d{3})(\d)/,"$1.$2");
    v = v.replace(/(\d{3})(\d{1,2})$/,"$1-$2");
    return v;
}

/**
 * Formata um cep no formato 11111-111.
 */
function cep(v)
{
    v = v.replace(/D/g,"");
    v = v.replace(/^(\d{5})(\d)/,"$1-$2");
    return v;
}

/**
 * Formata um cnpj no formato 11.111.111/1111-11.
 */
function cnpj(v)
{
    v = v.replace(/\D/g,"");
    v = v.replace(/^(\d{2})(\d)/,"$1.$2");
    v = v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3");
    v = v.replace(/\.(\d{3})(\d)/,".$1/$2");
    v = v.replace(/(\d{4})(\d)/,"$1-$2");
    return v
}

/**
 * Remove tudo o que não for I, V, X, L, C, D ou M.
 */
function romanos(v)
{
    v = v.toUpperCase();
    v = v.replace(/[^IVXLCDM]/g,"");
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"") != "")
    {
        v = v.replace(/.$/,"");
    }
    return v;
}

/**
 * Adiciona o http:// em todo endereco de site.
 */
function site(v)
{
    v = v.replace(/^http:\/\/?/,"");
    dominio = v;
    caminho = "";
    if(v.indexOf("/") > -1)
    {
    	dominio = v.split("/")[0];
    }
    caminho = v.replace(/[^\/]*/,"");
    dominio = dominio.replace(/[^\w\.\+-:@]/g,"");
    caminho = caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"");
    caminho = caminho.replace(/([\?&])=/,"$1");
    if(caminho != "")
    {
    	dominio = dominio.replace(/\.+$/,"");
    }
    v = "http://" + dominio + caminho;
    return v;;
}
