function confirmDelSituacao(id,idPai)
{
    if(idPai == 0){
        if (confirm("ATENÇÃO: Esta ação irá excluir todos os substatus deste status principal! Deseja continuar?"))
        {
            location.href = "index.php?modulo=Cliente&action=excluirSituacao&key=" + id;
        }
    }else{
        if (confirm("Excluir definitivamente este item?")){
            location.href = "index.php?modulo=Cliente&action=excluirSituacao&key=" + id;
        }
    }
}

function form_action(form, msg, url) {
    if (msg != "" && window.confirm(msg)){
        form.action = url;
        form.submit();
    }
    return false;
}

function replaceAll(string, token, newtoken) {
    var minha_er = new RegExp("/"+token+"/g");
    var string_retorno = string.replace( minha_er, newtoken )
    return string_retorno;
}

function IsNumeric(strString){

    var strValidChars = "0123456789.-";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++)
    {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
        {
            blnResult = false;
        }
    }
    return blnResult;
}

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ 
            return true;
        }else{
            return false;
        }
    }else{
        if(typeof(mail) == "object"){
            if(er.test(mail.value)){
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }
}

function validaTecla(campo, event)
{
    var BACKSPACE =  8;
    var key;
    var tecla;

    CheckTAB = true;
    if (navigator.appName.indexOf("Netscape") != -1)
        tecla = event.which;
    else
        tecla = event.keyCode;

    key = String.fromCharCode( tecla);

    if ( tecla == 13 ) return false;
    if ( tecla == BACKSPACE ) return true;
    if ( tecla == 44 ) return true;
    if ( tecla == 46 ) return false;
    return ( isNum(key));
}

function openWin(URL, largura, altura) {
    aWindow=window.open(URL,"Stort_bilde","toolbar=no,width=" + largura + ",height=" + altura + ",status=no,scrollbars=no,menubars=no");
}

function openWinScroll(URL, largura, altura) {
	LeftPosition = (screen.width) ? (screen.width - largura)/2 : 0;
	TopPosition = (screen.height) ? (screen.height - altura)/2 : 0;
    settings = 'height='+altura+',width='+largura+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable';
    aWindow = window.open(URL,"",settings);
    //aWindow=window.open(URL,"Stort_bilde","toolbar=no,width=" + largura + ",height=" + altura + ",status=no,scrollbars=yes,menubars=no");
}

function openWinScrolTemp(URL, largura, altura, aux) {
    //Esta função é usada quando precisa ser passado variaveis auxiliares
    aWindow=window.open(URL + "&iniCalend=" + aux,"Stort_bilde","toolbar=no,width=" + largura + ",height=" + altura + ",status=0,scrollbars=yes,menubars=0");
}

function startUpload(){
    document.getElementById('f1_upload_process').style.visibility = 'visible';
    document.getElementById('f1_upload_form').style.visibility = 'hidden';
    return true;
}

function stopUpload(success){
    var result = '';
    if (success == 1){
        result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
        self.close();
    }
    else {
        result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
    }
    document.getElementById('f1_upload_process').style.visibility = 'hidden';
    document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
    document.getElementById('f1_upload_form').style.visibility = 'visible';
    return true;
}

function trocaImagem(img){
    document.getElementById( 'img' ).src = "images/quadras/thumbs/"+img;
    document.getElementById( 'fotoAlterada' ).value = img;
    return;
}

function trocaImagemDefault(){
    document.getElementById( 'img' ).src = "images/quadras/thumbs/default.gif";
    document.getElementById( 'fotoAlterada' ).value = "default.gif";
    return;
}

/*Função Pai de Mascaras*/
function Mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

/*Função que Executa os objetos*/
function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

/*Função que Determina as expressões regulares dos objetos*/
function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

/*Função que permite apenas numeros*/
function Integer(v){
    return v.replace(/\D/g,"")
}

/*Função que padroniza  telefone 11 4184-1241*/
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
}

/*Função que padroniza telefone (11) 41841241*/
function TelefoneCall(v){
    v=v.replace(/\D/g,"")
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2")
    return v
}

/*Função que padroniza CPF*/
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
}

/*Função que padroniza CEP*/
function Cep(v){
    v=v.replace(/D/g,"")
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")
    v=v.replace(/(\d{3})(\d)$/,"$1-$2")
    return v
}

/*Função que padroniza CNPJ*/
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
}

/*Função que permite apenas numeros Romanos*/
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
}

/*Função que padroniza o 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
}

/*Função que padroniza DATA*/
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
}

/*Função que padroniza hora*/
function Hora(v){
    v=v.replace(/\D/g,"")
    v=v.replace(/(\d{2})(\d)/,"$1:$2")
    return v
}

/*Função que padroniza valor monétario*/
function Valor(v){
    v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
    v=v.replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/,"$1.$2");
    //v=v.replace(/(\d{3})(\d)/g,"$1,$2")
    v=v.replace(/(\d)(\d{2})$/,"$1.$2") //Coloca ponto antes dos 2 últimos digitos
    return v
}

/*Função que padroniza Area*/
function Area(v){
    v=v.replace(/\D/g,"")
    v=v.replace(/(\d)(\d{2})$/,"$1.$2")
    return v

}

function currencyFormat(objTextBox, SeparadorMilesimo, SeparadorDecimal, 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;
    // 13=enter, 8=backspace as demais retornam 0(zero)
    // whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc

    if (navigator.appName.indexOf("Netscape") != -1)
        tecla = e.which;
    else
        tecla = e.keyCode;

    key = String.fromCharCode( tecla);

    if (objTextBox.value.length >= 13) key = -1;

    if ((tecla == 13) || (tecla == 0) || (tecla == 8))
    	return true;
    //key = String.fromCharCode(whichCode); // Valor para o código da Chave

    if (strCheck.indexOf(key) == -1)
    	return false; // Chave inválida

    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal))
        	break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1)
        	aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0)
    	objTextBox.value = '';
    if (len == 1)
    	objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2)
    	objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        	objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function img_sombra() {

    var gradientshadow={}
    gradientshadow.depth=6 //Depth of shadow in pixels
    gradientshadow.containers=[]

    gradientshadow.create=function(){
    var a = document.all ? document.all : document.getElementsByTagName('*')
    for (var i = 0;i < a.length;i++) {
        if (a[i].className == "shadow") {
            for (var x=0; x<gradientshadow.depth; x++){
                var newSd = document.createElement("DIV")
                newSd.className = "shadow_inner"
                newSd.id="shadow"+gradientshadow.containers.length+"_"+x //Each shadow DIV has an id of "shadowL_X" (L=index of target element, X=index of shadow (depth)
                if (a[i].getAttribute("rel"))
                    newSd.style.background = a[i].getAttribute("rel")
                else
                    newSd.style.background = "black" //default shadow color if none specified
                document.body.appendChild(newSd)
            }
        gradientshadow.containers[gradientshadow.containers.length]=a[i]
        }
    }
    gradientshadow.position()
    window.onresize=function(){
        gradientshadow.position()
    }
    }

    gradientshadow.position=function(){
    if (gradientshadow.containers.length>0){
        for (var i=0; i<gradientshadow.containers.length; i++){
            for (var x=0; x<gradientshadow.depth; x++){
            var shadowdiv=document.getElementById("shadow"+i+"_"+x)
                shadowdiv.style.width = gradientshadow.containers[i].offsetWidth + "px"
                shadowdiv.style.height = gradientshadow.containers[i].offsetHeight + "px"
                shadowdiv.style.left = gradientshadow.containers[i].offsetLeft + x + "px"
                shadowdiv.style.top = gradientshadow.containers[i].offsetTop + x + "px"
            }
        }
    }
    }

    if (window.addEventListener)
    window.addEventListener("load", gradientshadow.create, false)
    else if (window.attachEvent)
    window.attachEvent("onload", gradientshadow.create)
    else if (document.getElementById)
    window.onload=gradientshadow.create
}

function startTime()
{
    var today=new Date()
    var h=today.getHours()
    var m=today.getMinutes()
    var s=today.getSeconds()
    // add a zero in front of numbers<10
    m=checkTime(m)
    s=checkTime(s)
    document.getElementById('txt').innerHTML=h+":"+m+":"+s
    t=setTimeout('startTime()',500)
}

function checkTime(i)
{
if (i<10)
  {i="0" + i}
  return i
}

function redireciona(url,parm, elementId){
    window.location.href = url + parm + document.getElementById(elementId).value;
}
