function MM_swapImgRestore()
{ //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages()
{ //v3.0
    var d = document; if (d.images)
    {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

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_swapImage()
{ //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

//Adiciona Favoritos
function addbookmark()
{
    var urlAddress = 'http://www.alternativaempregos.com.br/';
    var pageName = 'Alternativa Empregos';

    if (window.sidebar)
    {
        window.sidebar.addPanel(pageName, urlAddress, "");
    } else if (document.all)
    {
        window.external.AddFavorite(urlAddress, pageName);
    } else if (window.opera && window.print)
    {
        return true;
    }
}


function textCounter(field, countfield, maxlimit)
{
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
    else countfield.value = maxlimit - field.value.length;
}


function showRelease(_id)
{
    m = document.getElementById("tr_" + _id + "")
    if (m)
    {
        if (m.style.display == 'none')
        {
            m.style.display = '';
        } else
        {
            m.style.display = 'none';
        }
    }
}




var varIdJs;
function fcIsDate(obj)
{
    if (obj.value == "")
    {
        return false;
    }
    varIdJs = obj;
    var dtInv = false;

    var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
    if (!(obj.value.match(expReg)))
    {
        dtInv = true;
    }

    var data = obj.value;
    var dia = data.split("/")[0];
    var mes = data.split("/")[1];
    var ano = data.split("/")[2];

    if ((mes == 4 || mes == 6 || mes == 9 || mes == 11) && dia > 30)
    {
        dtInv = true;
    } else if ((ano % 4) != 0 && mes == 2 && dia > 28)
    {
        dtInv = true;
    } else if ((ano % 4) == 0 && mes == 2 && dia > 29)
    {
        dtInv = true;
    }

    if (dtInv == true)
    {
        alert("Data inválida.");
        setTimeout("varIdJs.focus()", 1);
    }

    var dgData = new Date();
    var dtAnt = new Date();
    var anoAnt = dtAnt.getFullYear();

    dgData.setFullYear(ano, parseInt(mes - 1), dia)
    dtAnt.setFullYear(parseInt(anoAnt - 100))

    if (dtAnt > dgData)
    {
        alert("A data não pode ser menor que \"" + dtAnt.toLocaleDateString() + "\"");
        setTimeout("varIdJs.focus()", 1);
    }
}



/*function showRelease(_id){			
var array = getElementsByClassName("name");
for (i = 0; i<array.length; i++)
{ 
array[i].style.display='none'; 
}
m = document.getElementById("tr_" + _id + "")
if (m){
if (m.style.display=='none'){
m.style.display='';
}else{
m.style.display='none';
}
}
}
		
function getElementsByClassName(needle) { 
var my_array = document.getElementsByTagName("*"); 
var retvalue = new Array(); 
var i; 
var j; 

for (i=0,j=0;i<my_array.length;i++) { 
var c = " " + my_array[i].className + " "; 
if (c.indexOf(" " + needle + " ") != -1) retvalue[j++] = my_array[i]; 
} 
return retvalue; 
} 
*/

///Adiciona Favoritos


function mascara(o, f)
{
    v_obj = o
    v_fun = f
    setTimeout("execmascara()", 1)
}

function execmascara()
{
    v_obj.value = v_fun(v_obj.value)
}

function MFone(v)
{
    v = v.replace(/\D/g, "")                 //Remove tudo o que nao é dígito
    v = v.replace(/^(\d\d)(\d)/g, "$1 $2") //Coloca parenteses em volta dos dois primeiros dígitos
    v = v.replace(/(\d{4})(\d)/, "$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function Mdata(v)
{
    v = v.replace(/\D/g, "")                 //Remove tudo o que nao é dígito
    v = v.replace(/^(\d\d)(\d)/g, "$1/$2") //Coloca parenteses em volta dos dois primeiros dígitos
    v = v.replace(/(\d{2})(\d)/, "$1/$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function MNumero(v)
{
    v = v.replace(/[^0123456789.,]/g, "")		//Remove tudo o que nao é dígito
    return v
}

function Mcpf(v)
{
    v = v.replace(/\D/g, "")
    v = v.replace(/(\d{3})(\d)/, "$1.$2") //000.000.000-00  
    v = v.replace(/(\d{3})(\d)/, "$1.$2")
    v = v.replace(/(\d{3})(\d)/, "$1-$2")
    return v
}


function Mrg(v)
{
    v = v.replace(/\D/g, "")
    v = v.replace(/(\d{7})(\d)/, "$1.$2")
    return v
}

function Mpis(v)
{
    v = v.replace(/\D/g, "")
    v = v.replace(/(\d{3})(\d)/, "$1.$2") //000.00000.00-0
    v = v.replace(/(\d{5})(\d)/, "$1.$2")

    if (v.length >= 10)
    {
        a = v.substring(10, v.length);
        a = a.replace(/(\d{2})(\d)/, "$1-$2")
        v = v.substring(0, 10) + a;
    }
    return v
}

function Mcnpj(v)
{
    v = v.replace(/\D/g, "")
    v = v.replace(/(\d{2})(\d)/, "$1.$2") //sd.fsd.fsd/fsdf-sd
    v = v.replace(/(\d{3})(\d)/, "$1.$2")
    v = v.replace(/(\d{3})(\d)/, "$1/$2")
    v = v.replace(/(\d{4})(\d)/, "$1-$2")
    return v
}

function Mcep(v)
{
    v = v.replace(/\D/g, "")
    v = v.replace(/(\d{5})(\d)/, "$1-$2")
    return v
}

function Mdinheiro(fld, milSep, decSep, e)
{

    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;  // Enter
    if (whichCode == 8)
    {
        fld.value = fld.value.slice(0, fld.value.length - 1);
    }
    key = String.fromCharCode(whichCode);  // recebe o valor da chave vinda da chave do código

    if (strCheck.indexOf(key) == -1) return false;  // Chave não válida   
    len = fld.value.length;
    for (i = 0; i < len; i++)
        if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
    aux = '';
    for (; i < len; i++)
        if (strCheck.indexOf(fld.value.charAt(i)) != -1) aux += fld.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) fld.value = '';
    if (len == 1) fld.value = '0' + decSep + '0' + aux;
    if (len == 2) fld.value = '0' + decSep + aux;
    if (len > 2)
    {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--)
        {
            if (j == 3)
            {
                aux2 += milSep;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        fld.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
            fld.value += aux2.charAt(i);
        fld.value += decSep + aux.substr(len - 2, len);
    }
    return false;
}

function startAjax()
{
    try
    {
        xmlhttp = new XMLHttpRequest();
    } catch (e)
    {
        try
        {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (ee)
        {
            try
            {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E)
            {
                xmlhttp = false;
            }
        }
    }
    return xmlhttp;
}

function MostrarCidades(_estado)
{
    var xhr = startAjax();
    var sel = document.getElementById("txtCidade");
    var url = "cidades.asp?est=" + _estado;
    xhr.open("GET", url, true)
    xhr.onreadystatechange = function()
    {
        if (xhr.readyState == 4)
        {
            if (xhr.status == 200)
            {
                var conteudo = xhr.responseText
                sel.options.length = 0
                cid = conteudo.split("#")
                for (i = 0; i < (cid.length - 1); i++)
                {
                    valor = cid[i].split("|")[0]
                    text = cid[i].split("|")[1]
                    sel.options[i] = new Option(text, valor)
                }
            }
        }
    }
    xhr.send(null);
}
//Janela Pop Up

function loadPopup(_w, _h, _url, _nome)
{

    var width = document.documentElement.offsetWidth / 2;
    var height = document.documentElement.offsetHeight / 2;



    window.open(_url, _nome, 'scrollbars=no,width=' + _w + ',height=' + _h + ',top=' + height / 2 + ',left=' + width / 2 + '');

}

//Funcao CallFlash
function callFlash(_path, _w, _h)
{
    var flash = "";
    flash = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + _w + "' height='" + _h + "'>";
    flash += "<param name='movie' value='" + _path + "' />";
    flash += "<param name='quality' value='high' />";
    flash += "<param name='wmode' value='transparent' />";
    flash += "<embed src='" + _path + "' quality='high' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + _w + "' height='" + _h + "'></embed>";
    flash += "</object>";
    document.write(flash);
}

function alteraValor(obj)
{
    var valorMax = document.getElementById("txtSalario2");
    var maxLen = obj.options.length;
    valorMax.options.length = 0;

    for (var i = obj.selectedIndex, j = 0; i < maxLen; i++, j++)
    {
        valorMax.options[j] = new Option(obj.options[i].text, obj.options[i].value);
    }

}


