﻿// JScript File

function CheckAll(formulario, classe)
{
   	
   var formulario = document.getElementById(formulario);
   
   alert(formulario);
   
   for (var i=0; i<formulario.elements.length; i++)
   {		
		var x = formulario.elements[i];
		
		if(x.className == classe)
		{		
		    if (x.type == "checkbox")
		    {
			    x.checked = !x.checked;
		    }
	    }
    }
}



function exibePainel(painelid, campoid, value)
{
   painel = document.getElementById(painelid);
   campo = document.getElementById(campoid);  
     
   if(campo.value == value)
   {
      painel.className = "";
   }
   else
   {
      painel.className = "Oculto";
   }
}

function checkPainel(painelid, check)
{
   painel = document.getElementById(painelid);
   check = document.getElementById(check);  
     
   if(check.checked)
   {
      painel.className = "";
   }
   else
   {
      painel.className = "Oculto";
   }
}

// --------------------------------
// Popup
// Marcus Vinícius Siqueira
// Autor: Marcus Vinícius Siqueira
// Data: 24/01/2008
// --------------------------------
function popupall(Url,Name,ScrollBars,Resizable)
{
    newWindow = window.open(Url,Name,'toolbar==,location=0,directories=0,menubar=0,scrollbars=1,resizable='+Resizable+',top=0,left=0,width='+screen.availWidth+',height='+screen.availHeight+'');
    if(newWindow)
    {
        newWindow.focus();
        abriu = true
        return false
    }  
};

function openModalAll(pUrl)
{
   return openModal(pUrl, screen.availHeight, screen.availWidth); 
}

function openModal(pUrl, pWidth, pHeight)
{
	if (window.showModalDialog)
	{
		return window.showModalDialog(pUrl, window,
		  "dialogWidth:" + pWidth + "px;dialogHeight:" + pHeight + "px");
	} else
	{
		try {
			netscape.security.PrivilegeManager.enablePrivilege(
			  "UniversalBrowserWrite");
			window.open(pUrl, "wndModal", "width=" + pWidth
			  + ",height=" + pHeight + ",resizable=no,modal=yes");
			return true;
		}
		catch (e)
		{
			popup(pUrl,'');
			return false;
		}
	}
}

function popup(Url,Name, Width, Height)
{
   if(Width == null)
    {
       Width = screen.availWidth;
       Left = 0;
    }
    else
    {
        Left = ((screen.availWidth/2)-(Width/2));
    }

    if(Height == null)
    {
       Height = screen.availHeight;
       Top = 0; 
    }
    else
    {
        Top = ((screen.availHeight/2)-(Height/2));
    }
    
    if(Name == null)
    {
       Name = "PopUp";
    }   
    
    newWindow=window.open(Url,Name,'toolbar==,location=0,directories=0,menubar=0,scrollbars=1,resizable=0,left='+Left+',top='+Top+',width='+Width+',height='+Height+'');
    if(newWindow)
    {
        abriu = true
        return false
    }  
};
//---------------------------------
function Confirma(msg, pagina_sim, pagina_nao)
{
    if(confirm(msg))
    {
        location.href = pagina_sim;
    }
    else
    {
        location.href = pagina_nao;        
    }
}



function ConfirmaExclusao(link, PagCancel)
{
    if(! confirm('Deseja realmente excluir este registro?'))
    {
        link.href = PagCancel;
        return false;
    }
    return true;
}

function ConfirmaCancelamento(link, PagCancel)
{
    if(! confirm('Deseja realmente cancelar esta assinatura?'))
    {
        link.href = PagCancel;
        return false;
    }
    return true;
}
function ConfirmaReativacao(link, PagCancel)
{
    if(! confirm('Deseja realmente reativar esta assinatura?'))
    {
        link.href = PagCancel;
        return false;
    }
    return true;
}
function ConfirmaAssinatura(link, PagCancel, msg)
{
    if(!confirm(msg))
    {
        link.href = PagCancel;
        return false;
    }
    return true;
}
function MsgOk(msg, pagina)
{
    if (msg == "1")
        alert("Inclusão Efetuada com Sucesso");
    else
    if (msg == "2")
        alert("Alteração Efetuada com Sucesso");
    else
    if (msg == "4")
        alert("Exclusão Efetuada com Sucesso");
    else
    if (msg == "5")
        alert("Suspensão Efetuada com Sucesso");
    else
    if (msg == "6")
        alert("Reativação efetuada com Sucesso");
    else
    if (msg == "14")
        alert("Renovação Efetuada com Sucesso");
    location.href=pagina;    
}

function contador(field,ncaracteres,qtdcm,qtdcmtxb)
{
   var fieldSize =  document.getElementById(field).value.length;
  
  //pega label e faz contar os caracteres
   caracteres = document.getElementById(ncaracteres);	
   totalCaracter = fieldSize;
   caracteres.innerHTML = totalCaracter;
   
   totalcm = totalCaracter / 35;
   
  totalcm=parseInt(totalcm)
   resto = totalCaracter % 35;
   
   
   if(resto > 0)
      totalcm++;

   document.getElementById(qtdcm).value = totalcm;
   document.getElementById(qtdcmtxb).value = totalcm;
 
}

function calculopa(field,ncaracteres,qtdcm,qtdcmtxb,ddlqtdcolid,vltipoid,txbtotal,txbtotalacres,hdftotal)
{
//ncaracteres=label que recebera valores
//qtdcm=hidden que recebe o numero de cm
//qtdcmtxb=text box que recebe o numero cm
//ddlqtdcolid=dropdownlist que passa o valor para efetuar o calculo
//vltipoid=valor do hidden que que e passado para o calculo
//txbtotal=textbox que recebera o valor total.
//txbtotalacres=textbox que recebera o valor total.
//hdftotal=hidden que recebera o valor total.

   var fieldSize =  document.getElementById(field).value.length;
  
  //pega label e faz contar os caracteres
   caracteres = document.getElementById(ncaracteres);	
   totalCaracter = fieldSize;
   caracteres.innerHTML = totalCaracter;
   
   //Pega o valor da dropdownlist colunas
   ddlqtdcol = document.getElementById(ddlqtdcolid);	
   colunas=ddlqtdcol.value;
     alert("Colunas= "+colunas)
   //pega o valor do tipo
    vltipo = document.getElementById(vltipoid);	
    
   valor=vltipoid.value;
     alert("Valor= "+valor)
     
   totalcm = totalCaracter / 35;
   
  totalcm=parseInt(totalcm)
   resto = totalCaracter % 35;
   
   
   if(resto > 0)
      totalcm++;
      
      calccmcol=totalcm*colunas;
      total=calccmcol*valor;
    
   
   document.getElementById(qtdcm).value = totalcm;
   document.getElementById(qtdcmtxb).value = totalcm;

   document.getElementById(txbtotal).value = total;
   document.getElementById(txbtotalacres).value = total;
  document.getElementById(hdftotal).value = total;
}

function CalculaPreco(field1, field2, field3)
{
    var prCompra = parseFloat(document.getElementById(field1).value);
    var percentVenda = parseFloat(document.getElementById(field2).value);
    
    var precoVenda = (prCompra + (prCompra * (percentVenda/100)));
    
    document.getElementById(field3).value = precoVenda;
}
