/*# IFRAME VIRTUAL #*/
function iframe_virtual(vc_url) {
	if (document.all.iframe_virtual)	{
		document.all.iframe_virtual.removeNode(true);
	}
	
	var tempIFrame					= document.createElement('iframe');
		tempIFrame.style.border		='0px';
		tempIFrame.style.width		='0px';
		tempIFrame.style.height		='0px';
		
		tempIFrame.setAttribute('id','iframe_virtual');
		tempIFrame.setAttribute('name','iframe_virtual');
		tempIFrame.setAttribute('src',vc_url);
	
	IFrameObj						= document.body.appendChild(tempIFrame);
}

/*# IMAGE CHANGER #*/
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_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];}
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

/*# MASCARA */
function mascarar(src,msk) {
	var i		= src.value.length;
	var x		= msk.substring(0,1);
	var y		= msk.substring(i);
	
	if (y.substring(0,1) != x) {
		src.value += y.substring(0,1);
	}
}

/*# POP-UP SELECT #*/
function pop_select_limpar(vc_campo,vc_termo){
	var vc_campo	= eval('document.all.'+vc_campo)

	if(vc_termo == 'clique aqui e tecle ENTER'){
		vc_campo.value	= '';
	}	
}

function pop_select(vc_campo,vc_termo){
	var vc_campo	= vc_campo.replace('vc','select');
	
	if(event.keyCode==13){
		var W			= 330; 	
		var H			= 430;
		var X			= 50;
		var Y			= Math.ceil( (window.screen.width - W) / 2 );
		window.open('../relatorios/'+vc_campo+'.asp?vc_termo='+vc_termo,'ap_select','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no,toolbar=no');
	}	
}

function pop_select_preenche(id_campo,vc_campo,tx_campo){
	var id_item 										= String('id_'+tx_campo);
	var vc_item 										= String('vc_'+tx_campo);

	window.opener.eval('document.all.'+id_item).value	= id_campo;
	window.opener.eval('document.all.'+vc_item).value	= vc_campo;
	window.close();	
}

/*# MOEDA #*/
function moeda(valor,cx)	{
	if (valor)	{
		var doc = eval('document.all.'+cx);
		if (window.event.keyCode == 190 || window.event.keyCode == 194 || window.event.keyCode == 110 || window.event.keyCode == 188)	{
			doc.value = valor.substr(0, (valor.length-1));
		}	else	{
			valor = centavo(valor);
			if (centavo(valor).length > 2)	{
				str = valor.replace(".", "");
				doc.value = str.substr(0, (str.length-2))+"."+str.substr((str.length-2), str.length);
			}	else	{
				valor = centavo(valor);
				if (valor.length == 1)	{
					doc.value = "0.0"+valor;
				}	else	{
					doc.value = "0."+valor;
				}
			}
		}
	}
}

function centavo(valor)	{
	if (valor.indexOf("0")  == 0)	{
		valor = valor.replace("0.", "");
		valor = valor.replace("0.0", "");
	}
	valor = valor.replace(".", "");
	return valor;
}

/*# FORMATAR MOEDA #*/
function formataMoeda(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ((mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}
/* NUMEROS*/
function numeros() {
	var tecla	= event.keyCode;
	
	if (tecla > 47 && tecla < 58) { 
		return true;
		} else {
			if (tecla != 8) {
				event.keyCode = 0;
				alert('Digite apenas números');
			} else {
				return true;
		}
	}
}
//Abre pop_up

/*function abre_pop(theURL,winName,W,H,arquivo_VC) {
	var X = Math.ceil( (window.screen.height - H) / 2 );
	var Y = Math.ceil( (window.screen.width - W) / 2 );
	window.open('includes/'+theURL+'.asp?arquivo_VC='+arquivo_VC,winName,'width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=no,menubar=no,scrollbars=auto,resizable=no,directories=no,toolbar=no');
}*/

function abre_pop(theURL,winName,arquivo_VC) {
	window.open('includes/'+theURL+'.asp?arquivo_VC='+arquivo_VC,winName,'width=600,height=600,top=40,left=40,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,toolbar=no');
}

function abre_pop2(theURL,winName,arquivo_VC,it_width,it_height) {
	window.open('includes/'+theURL+'.asp?arquivo_VC='+arquivo_VC,winName,'width='+it_width+',height='+it_height+',top=40,left=40,location=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,toolbar=no');
}

function teste() {
	if (verifica() == false) {
	}
}

function verifica() {
	vc_erro		= '';
	
	if ((document.all.it_transporte.value == 1 || document.all.it_transporte.value == 2) && (document.all.vc_transportadora.value.length == 0)){
	 	vc_erro	= vc_erro + '- Digite o nome da TRANSPORTADORA.\n';
	}

	if (vc_erro.length == 0) {
		document.form.submit();
	} else {
		alert('ATENÇÃO!\n\n' + vc_erro);
		return false;
	}
}

function enviar_p() {
	document.frm_p.submit();
}