
function saudacao() {
    var d = new Date();
    if ((d.getHours() < 6) || (d.getHours() > 18)) {
        document.write("Boa noite");
    } else if (d.getHours() < 12) {
        document.write("Bom dia");
    } else {
        document.write("Boa tarde");
    }
}

function isEmail(email) {
    email = email.toLowerCase();
    tmpEmail = /^[\w-]+(\.[\w-]+)*@(([0-9a-z\d][0-9a-z\d-]{0,61}[0-9a-z\d]\.)+[0-9a-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
    eval("tmpEmail = tmpEmail");
    if (tmpEmail.test(email)) return true;
    else return false;
}

function openWindow(url,target,w,h) {
    return openWindowScroll(url,target,w,h,'yes');
}

function openWindowScroll(url,target,w,h,scrollbar) {
    l = parseInt((screen.width - w) / 2);
    t = parseInt((screen.height - h) / 2);
    var w = window.open(url,target,'width='+w+',height='+h+',left='+l+',top='+t+',scrollbars='+scrollbar);
    w.focus();
    return w;
}

function flash(ffile,w,h,transparent,params,id) {
    document.write('<object'+(((typeof id != 'undefined') && (navigator.appVersion.indexOf('MSIE') > -1))?' id="'+id+'"':'')+' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"' + ((typeof w == 'undefined')?'':' width="'+w+'"') + ((typeof h == 'undefined')?'':' height="'+h+'"') + '>');
    document.write('<param name="movie" value="'+ffile+'">');
    document.write('<param name=quality value=high>');
    document.write('<param name="menu" value="false">');
    if (typeof params != 'undefined') {
        var p = '';

        for (var i in params) {
            p += i + '="' + params[i] + '" ';
            document.write('<param name="'+i+'" value="'+params[i]+'">');
        }
    }
    if (transparent) {
        document.write('<param name="wmode" value="transparent">');
    }
    document.write('<embed'+(((typeof id != 'undefined') && (navigator.appVersion.indexOf('MSIE') < 0))?' id="'+id+'"':'')+' src="'+ffile+'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"' + ((typeof w == 'undefined')?'':' width="'+w+'"') + ((typeof h == 'undefined')?'':' height="'+h+'"') + ' ');
    if (transparent) {
        document.write('wmode="transparent" ');
    }
    document.write(p);
    document.write(' menu="false"></embed>');
    document.write('</object>');
}

function numbersOnly(s) {
    return s.replace(/[^0-9]+/g, '');
}

function isCNPJ(CNPJ) {
    CNPJ = numbersOnly(CNPJ);
    if (CNPJ.length != 14) {
        return false;
    }
    erro = new String;
    if(document.layers && parseInt(navigator.appVersion) == 4){
        x = CNPJ.substring(0,2);
        x += CNPJ. substring (2,5);
        x += CNPJ. substring (5,8);
        x += CNPJ. substring (8,12);
        x += CNPJ. substring (12,14);
        CNPJ = x;
    } else {
        CNPJ = CNPJ. replace (".","");
        CNPJ = CNPJ. replace (".","");
        CNPJ = CNPJ. replace ("-","");
        CNPJ = CNPJ. replace ("/","");
    }
    var a = [];
    var b = new Number;
    var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
    for (i=0; i<12; i++){
        a[i] = CNPJ.charAt(i);
        b += a[i] * c[i+1];
    }
    if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
    b = 0;
    for (y=0; y<13; y++) {
        b += (a[y] * c[y]);
    }
    if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
    return ((CNPJ.charAt(12) == a[12]) && (CNPJ.charAt(13) == a[13]));
}

function isCPF(cpf){
    cpf = numbersOnly(cpf);
    if (cpf == '11111111111') {
        return false;
    }
    if (cpf.length != 11) {
        return false;
    }
    s = cpf;
    var c = s.substr(0,9);
    var dv = s.substr(9,2);
    var d1 = 0;
    for (var i = 0; i < 9; i++){
        d1 += c.charAt(i)*(10-i);
    }
    if (d1 == 0){
        return false;
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(0) != d1){
        return false;
    }
    d1 *= 2;
    for (i = 0; i < 9; i++) {
        d1 += c.charAt(i)*(11-i);
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(1) != d1){
        return false;
    }
    return true;
}

function inputOnFocus(obj,padrao) {
    if (obj.value == padrao) {
        obj.value = '';
    }
}

function inputOnBlur(obj,padrao) {
    if (obj.value == '') {
        obj.value = padrao;
    }
}
