﻿function abre(theURL, winName, features) {
    window.open(theURL, winName, features);
}
function abrePop(theURL) {
    window.open(theURL, '', 'width=800, height=700, resizable=1, menurbar=1, status=1, scrollbars=1');
}
/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
		
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
    var parentEl=what.offsetParent;
    while (parentEl!=null){
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl=parentEl.offsetParent;
    }
    return totaloffset;
}

function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
    var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
    if (whichedge=="rightedge"){
        var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
        dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
        if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
            edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
        }
        else{
            var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
            dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
        if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
        edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
    }
    return edgeoffset
}

function showhint(menucontents, obj, e, marginleft, pasta){
    var pastaimg = pasta
    if (pastaimg == null){
        pastaimg = '../img';
    }
    var marginleft2 = marginleft
    if (marginleft2 == 0){
        marginleft2 = "";
    }
    if ((ie||ns6) && document.getElementById("hintbox")){
        dropmenuobj=document.getElementById("hintbox")
        dropmenuobj.innerHTML='<img src='+ pastaimg +'/seta_explica.png border=0>&nbsp;' + menucontents        
        dropmenuobj.style.left=dropmenuobj.style.top=-500
        if (marginleft2!=""){
            dropmenuobj.widthobj=dropmenuobj.style
            dropmenuobj.widthobj.margin='0px 0px 0px '+ marginleft2 + 'px'
            //dropmenuobj.widthobj.width=tipwidth
        } else {
            dropmenuobj.widthobj=dropmenuobj.style
            dropmenuobj.widthobj.margin='0px 0px 0px -5px'
        }
        dropmenuobj.x=getposOffset(obj, "left")
        dropmenuobj.y=getposOffset(obj, "top")
        dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
        dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
        dropmenuobj.style.visibility="visible"
        //obj.onmouseout=hidetip
        obj.onblur=hidetip
    }
}
function hidetip(e){
    dropmenuobj.style.visibility="hidden"
    dropmenuobj.style.left="-500px"
}
function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox




/***********************************************
* Form Field Progress Bar- By Ron Jonk- http://www.euronet.nl/~jonkr/
* Modified by Dynamic Drive for minor changes
* Script featured/ available at Dynamic Drive- http://www.dynamicdrive.com
* Please keep this notice intact
***********************************************/

function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;    
	maxlimit = maxlimit -  document.getElementById("ctl00$cphPrincipal$UscEnviaSms1$txtDe").value.length;
	

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	//document.getElementById(counter).innerHTML="Limite: "+percentage+"% ("+ maxlimit - charcnt  +")";
	document.getElementById(counter).innerHTML=" <b>"+(maxlimit - charcnt)+"</b>"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){

	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}


// JScript File
        function handleEnter (field, event) {
            var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
            if (keyCode == 13) {
                var i;
                var z;
                for (i = 0; i < field.form.elements.length; i++)
                if (field == field.form.elements[i])
                break;
                z=i;
                while(field.form.elements[z+1].type=='hidden')
                    z++;
                i = (z + 1) % field.form.elements.length;
                field.form.elements[i].focus();
                return false;
            }
            return true;
        }

        function EstaCompleto(txtAtual,intTamanho,txtProximo)
        {    
            if(txtAtual.value.length==intTamanho)
            {
                txtProximo.focus();                                
            }
        }
        function rolar(x,y){
            window.scroll(x,y);
        }
        /*
        Live Date Script- 
        © Dynamic Drive (www.dynamicdrive.com)
        For full source code, installation instructions, 100's more DHTML scripts, and Terms Of Use,
        visit http://www.dynamicdrive.com
        */
        var dayarray=new Array("Domingo","Segunda-feira","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sábado")
        var montharray=new Array("Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro")
        
        function CallPrint(strid){            
        
            var mydate=new Date()
            var year=mydate.getYear()
            if (year < 1000)
            year+=1900
            var day=mydate.getDay()
            var month=mydate.getMonth()
            var daym=mydate.getDate()
            if (daym<10)
            daym="0"+daym
            var hours=mydate.getHours()
            var minutes=mydate.getMinutes()
            var seconds=mydate.getSeconds()
            var dn="AM"
            if (hours>=12)
            dn="PM"
            if (hours>12){
            hours=hours-12
            }
            if (hours==0)
            hours=12
            if (minutes<=9)
            minutes="0"+minutes
            if (seconds<=9)
            seconds="0"+seconds
            //change font size here
            var cdate="<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+daym+" de "+montharray[month]+" de "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
            +"</b></font></small>"
        
            var prtContent = document.getElementById(strid);
            //var WinPrint = window.open('','','left=1200,top=1000,width=100,height=100,menubar=1,mainbar=1,scrollbars=1,status=1');
            var WinPrint = window.open('','','left=0,top=0,width=800,height=600,menubar=1,mainbar=1,scrollbars=1,status=1,resizable=1,toolbar=1');
            
            //WinPrint.document.write('<link href="interface_web_impressao_pop.css" rel="stylesheet" type="text/css"><div align=left><img src="img/logo_imp.gif"><b>'+ cdate +'</b></div><br>' + prtContent.innerHTML + '<div class="rodape">&copy; 2007 ItCon.  Todos os direitos reservados.</div>');
            WinPrint.document.write('<HTML><HEAD><link href="interface_web_impressao_pop.css" rel="stylesheet" type="text/css"></HEAD><BODY>' + prtContent.innerHTML);
            WinPrint.document.write('	        <object id="factory" viewastext style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="smsx.cab#Version=6,1,431,2"></object> </BODY></HTML>');
            //WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            //WinPrint.close();
            //prtContent.innerHTML=strOldOne;
        } 
	    function abre(theURL,winName,features) {
		    window.open(theURL,winName,features);
	    }
	    //completa com zeros a esquerda até 13 dígitos
	    function completaZeros(src){	        
            var entrada = src.value;
            var saida;
            entrada = "0000000000000" + entrada;
            saida = entrada.substring(entrada.length-13,entrada.length);            
            src.value = saida;
        }
        function buscaProduto(src){
            var valor = src.value;   
            if (!isNaN(valor)){
                completaZeros(src);       
            } else {
                abre('frmCadProduto.aspx?busca=1&proDescricao=' + src.value,'produto','top=0, right=0, width=780px, scrollbars=1');    
            }
            if (valor.length == 0){
                //abre('frmCadProduto.aspx?busca=1','produto','top=0, right=0, width=780px, scrollbars=1');    
            }
        }
        
	    //mascara para o form
	    
	    function formatar(src, mask) 
	    {
	    var i = src.value.length;
	    var saida = mask.substring(0,1);
	    var texto = mask.substring(i)
	    if (texto.substring(0,1) != saida) 
	    {
		    src.value += texto.substring(0,1);
	    }
	    }
	    
	    // AUTO TAB - ao prencher o campo, automaticamente manda o foco para o próximo!
	    
	    var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	    function autoTab(input,len, e) {
		    var keyCode = (isNN) ? e.which : e.keyCode;
		    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		    if(input.value.length >= len && !containsElement(filter,keyCode)) {
			    input.value = input.value.slice(0, len);
			    input.form[(getIndex(input)+1) % input.form.length].focus();
	    }
	    function containsElement(arr, ele) {
		    var found = false, index = 0;
		    while(!found && index < arr.length)
		    if(arr[index] == ele)
			    found = true;
		    else
			    index++;
			    return found;
	    }
	    function getIndex(input) {
		    var index = -1, i = 0, found = false;
		    while (i < input.form.length && index == -1)
		    if (input.form[i] == input)index = i;
		    else i++;
			    return index;
		    }
		    return true;
	    }
	    //Fim da Função AutoTab
	    var cor;
	    function selecionaGrid( elemento ) {
		    cor=elemento.style.backgroundColor;
		    elemento.style.backgroundColor = "#DDDDDD";
	    }
	    // Função para mudar a linha ao de-selecionar
	    function deSelecionaGrid( elemento) {
		    elemento.style.backgroundColor = cor; 
	    }
		function FormataValor(campo,tammax,teclapres) {
				var tecla = teclapres.keyCode;
				vr = document.aspnetForm[campo].value;
				vr = vr.replace( "/", "" );
				vr = vr.replace( "/", "" );
				vr = vr.replace( ",", "" );
				vr = vr.replace( ".", "" );
				vr = vr.replace( ".", "" );
				vr = vr.replace( ".", "" );
				vr = vr.replace( ".", "" );
				tam = vr.length;
				if (tam < tammax && tecla != 8){ tam = vr.length + 1; }
				if (tecla == 8 ){ tam = tam - 1; }
				if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
				if ( tam <= 2 ){ 
					document.aspnetForm[campo].value = vr; }
				if ( (tam > 2) && (tam <= 5) ){
					document.aspnetForm[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
				if ( (tam >= 6) && (tam <= 8) ){
					document.aspnetForm[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
				if ( (tam >= 9) && (tam <= 11) ){
					document.aspnetForm[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
				if ( (tam >= 12) && (tam <= 14) ){
					document.aspnetForm[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
				if ( (tam >= 15) && (tam <= 17) ){
					document.aspnetForm[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
				}
			}
		function FormataValor9(campo,tammax,teclapres) {
				var tecla = teclapres.keyCode;
				vr = document.aspnetForm[campo].value;
				vr = vr.replace( "/", "" );
				vr = vr.replace( "/", "" );
				vr = vr.replace( ",", "" );
				vr = vr.replace( ".", "" );
				vr = vr.replace( ".", "" );
				vr = vr.replace( ".", "" );
				vr = vr.replace( ".", "" );
				tam = vr.length;
				if (tam < tammax && tecla != 8){ tam = vr.length + 1; }
				if (tecla == 8 ){ tam = tam - 1; }
				if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
				if ( tam > 9 ){ 
					//document.aspnetForm[campo].value = vr; }
				    document.aspnetForm[campo].value = vr.substr( 0, tam - 9 ) + ',' + vr.substr( tam - 9, tam );
				}
				}
			}   
	    function JsDelete()
	    {
		    if (confirm ("Você deseja confirmar essa ação?"))
		    {
			    return true;
		    }
		    else
		    {
			    return false;
		    }
	    }
	    function JsFecha()
	    {
		    if (confirm ("Você deseja fechar a janela e perder os dados não salvos?"))
		    {
		        window.opener.location.reload();
			    window.close();
		    }
		    else
		    {
			    return false;
		    }
	    }
	    function JsDelete2(msg)
	    {
		    if (confirm (msg))
		    {
			    return true;
		    }
		    else
		    {
			    return false;
		    }
	    }

//funçao para máscara de moeda
var backspaceKey = 8;
var deleteKey = 46;
var pasteKey = 86;
var cutKey = 88;
var k1 = 37;
var k2 = 38;
var k3 = 39;
var k4 = 40;
function isValidKey(keyCode) {
    if (keyCode == backspaceKey || keyCode == deleteKey || keyCode == k1 || keyCode == k2 || keyCode == k3 || keyCode == k4)
        return true;
    return false;
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e) {
    //alert(abobrinha);
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789\37';
    var aux = aux2 = '';
    if (!e) e = window.event;
    var whichCode = e.which || e.keyCode;
    if (isValidKey(whichCode)) 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;
}


