function ColocaFocoEm(NomeBtn, e) 
{ 
	try
	{
		var key;  
			
		if (window.event) 
		{    
			key = event.keyCode;   
		}
		else
		{     
			key = e.which; 
		}

		if (key == 13)
		{
			document.getElementById(NomeBtn).focus();
			key = 13;
		}
	}     
	catch(err)
	{
		alert(err);
	}
}

function Preenchido(obj)
{
    return document.getElementById(obj).value != '';        
}

function FocoSubmit(btn)
{
	if (event.keyCode == 13)
	{
		document.getElementById(btn).focus();
		event.keyCode = 13;
	}
}

function Confirmar()
{
    return confirm('Este registro sera excluido. Deseja continuar?');
}

function SomenteNumeroFirefox(e) 
{ 
  var key //= (window.event) ? event.keyCode : e.which;   
  
  if (window.event)     
    key = event.keyCode   
  else     
    key = e.which   // Was key that was pressed a numeric character (0-9) or backspace (8)?   
    
  if ( key > 47 && key < 58 || key == 8 )     
    return; // if so, do nothing   
  else // otherwise, discard character     
    if (window.event) //IE       
        window.event.returnValue = null;     
    else //Firefox       
        e.preventDefault();
}



function SomenteLetras(e) 
{ 
  var key //= (window.event) ? event.keyCode : e.which;   
  
  if (window.event)     
    key = event.keyCode   
  else     
    key = e.which   // Was key that was pressed a numeric character (0-9) or backspace (8)?   
    
  if ( key > 47 && key < 58 || key == 8 )     
    if (window.event) //IE       
        window.event.returnValue = null;     
    else //Firefox       
        e.preventDefault();
  else // otherwise, discard character     
    return; // if so, do nothing   
}



function Mascara(textBox, mask) 
{
     var i      = textBox.value.length;
     var saida  = mask.substring(0,1);
     var texto  = mask.substring(i);
     
     if (texto.substring(0,1) != saida) 
     {
          textBox.value += texto.substring(0,1);
     }
}

function LoginAlternar()
{

    if(document.getElementById('login_rdnSenha').checked)
    {
        document.getElementById('login_txtCep1').value = '';
        document.getElementById('login_txtCep2').value = '';
        document.getElementById('login_txtCep1').disabled 	= true;
        document.getElementById('login_txtCep2').disabled 	= true;
        
        document.getElementById('login_txtSenha').disabled	= false;
    }
    else
    {
        document.getElementById('login_txtSenha').value = '';
        document.getElementById('login_txtSenha').disabled	= true;
        
        document.getElementById('login_txtCep1').disabled 	= false;
        document.getElementById('login_txtCep2').disabled 	= false;        
    }
}

function ColocaFocoEm(NomeBtn, e) 
{ 
    try
    {
        var key;  

        if(window.event) 
        {    
            key = event.keyCode;   
        }
        else
        {     
            key = e.which; 
        }
      
        if(key == 13)
        {
		    document.getElementById(NomeBtn).focus();
		    key = 13;
        }
	}     
	catch(err)
	{
	    alert(err);
	}
	
}  

function PopUp(u, w, h){
   // t = (screen.width - w) / 2;
    t = 100;
    l = (screen.height - h) / 2;
    window.open(u, 'wpopup', 'top=' + t + ', left=' + l + ', width=' + w + ', height=' + h + ', scrollbars=yes, resizable=no, menubar=no, location=no, status=no, toolbar=no');
}


	var correctos = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","z","y","w","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","X","Z","Y","W","1","2","3","4","5","6","7","8","9","0"," ");

	function NoSpecialCharacter(e) 
     {

         estado=false;

         if(document.all)
         {
             codigoTecla = event.keyCode
             cadenaTecla = (String.fromCharCode(event.keyCode));
         }
         else if(document.layers)
         {
             codigoTecla = e.which
             cadenaTecla = String.fromCharCode(e.which);
         }
         else if(document.getElementById)
         {
             codigoTecla = (window.Event) ? e.which : e.keyCode;
             cadenaTecla=(String.fromCharCode(codigoTecla));
         }

         for(i=0;i<correctos.length;i++)
         {
             if(cadenaTecla==correctos[i])
                 estado=true;
         }

         if(estado==false)
         {
             if(document.all)
             {
              event.returnValue = false;
				alert('Ao digitar, não faça uso de acentos gráficos ou caracteres especias!');
             }   
             else
                 return false;
			
         }
     }


function isValidCreditCardNumber(cardNumber, cardType){
    var isValid = false;
    var ccCheckRegExp = /[^\d ]/;
    isValid = !ccCheckRegExp.test(cardNumber);
    if (isValid){
        var cardNumbersOnly = cardNumber.replace(/ /g,"");
        var cardNumberLength = cardNumbersOnly.length;
        var lengthIsValid = false;
        var prefixIsValid = false;
        var prefixRegExp;
    switch(cardType){
        case "mastercard":
            lengthIsValid = (cardNumberLength == 16);
            prefixRegExp = /^5[1-5]/;
        break;
        case "visa":
            lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
            prefixRegExp = /^4/;
        break;
        case "amex":
            lengthIsValid = (cardNumberLength == 15);
            prefixRegExp = /^3(4|7)/;
        break;
        default:
            prefixRegExp = /^$/;
            alert("Card type not found");
    }

    prefixIsValid = prefixRegExp.test(cardNumbersOnly);
    isValid = prefixIsValid && lengthIsValid;
    }
    if (isValid){
        var numberProduct;
        var numberProductDigitIndex;
        var checkSumTotal = 0;
        for (digitCounter = cardNumberLength - 1; digitCounter >= 0; digitCounter--){
            checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
            digitCounter--;
            numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
            for (var productDigitCounter = 0; productDigitCounter < numberProduct.length; productDigitCounter++){
                checkSumTotal += parseInt(numberProduct.charAt(productDigitCounter));
            }
        }
        isValid = (checkSumTotal % 10 == 0);
    }

    return isValid;
}


/*************************/

	function SendId(x){
		document.Form1.txtValor.value = x;			
    }

	function Toggle(item, abaName) 
	{
		Collapse();
		
		var aba2 = abaName.replace("a","");
		
		obj=document.getElementById(item);
		aba=document.getElementById(abaName);
		objaba2=document.getElementById(aba2);

		var sp = document.getElementById('txtQry').value;

		if(sp.indexOf('1') >=0)
		{
			b_1.style.display="block";
			b_1a.style.display="none";
		}

		if(sp.indexOf('2') >=0)
		{
			b_2.style.display="block";
			b_2a.style.display="none";
		}
		
		if(sp.indexOf('3') >=0)
		{
			b_3.style.display="block";
			b_3a.style.display="none";
		}
		
		if(sp.indexOf('4') >=0)
		{
			b_4.style.display="block";
			b_4a.style.display="none";
		}
		
		if(sp.indexOf('5') >=0)
		{
			b_5.style.display="block";
			b_5a.style.display="none";
		}
		
		visible=(obj.style.display!="none")
		
		cel=document.getElementById("c" + item);
		
		obj.style.display="block";
		
		aba.style.display="block";		
		objaba2.style.display="none";		
		
		
		
		
		if(item != 'panSaibaMais')
		{
			panSaibaMais.style.display="none";
		}

		if(item != 'panTarifas')
		{
			panTarifas.style.display="none";
		}
		
		if(item != 'panVantagens')
		{
			panVantagens.style.display="none";
		}

		if(item != 'panOpinioes')
		{
			panOpinioes.style.display="none";
		}
		
		if(item != 'panAvalie')
		{
			panAvalie.style.display="none";
		}
	}



	function Collapse()
	{
		divs=document.getElementsByTagName("div");
		
		for (i=0;i<divs.length;i++) 
		{
			celCol=document.getElementById("c" + divs[i].id);
			if (celCol)
			{
				divs[i].style.display="none";

				try
				{
					celCol.style.background='#7ba56b';
				}
				catch(err)
				{
				}
			}
		}
	}


function ShowPlan(nameDiv)
	{
		QtdeDivs=document.getElementById("txtQtdePlanos");
		for (i=0;i<QtdeDivs.value;i++)
		{
			eval("c"+i+".style.display = 'none'")
		}
		eval("c"+nameDiv+".style.display = 'block'")
	}


	function Collapse2(nameDiv)
	{
		divs=document.getElementsByTagName("div");

		for (i=0;i<divs.length;i++) 
		{
			var hidden = document.getElementById('c'+i);
			
			hidden.style.display = 'none';
			
		}
	}



	function CollapsePlanos()
	{
		divs_=document.getElementsByTagName("div");

		for (i=0;i<divs_.length;i++) 
		{
			var hidden = document.getElementById(i);
			
			hidden.style.display = 'none';
			
		}
	}


	function ValidaInsereOpiniao()
	{
		var Nome = document.getElementById('txtNome');
		var Opiniao = document.getElementById('txtOpiniao');
		var Avaliacao = document.getElementById('ddlAvaliacao');
		var codigo = document.getElementById('txtProCodigo').value;
		detalhes.InsereOpinioes("teste1","teste2","5","teste3");
		detalhes.InsereOpinioes(Nome.value, Opiniao.value, Avaliacao.value,codigo, Mensagem_CallBack);
	}

	function Mensagem_CallBack(resp)
	{
		var lblConsisteAvaliacao = document.getElementById('lblConsisteAvaliacao');
		lblConsisteAvaliacao.innerHTML = resp.value;
		var Nome = document.getElementById('txtNome');
		var Opiniao = document.getElementById('txtOpiniao');
		var Avaliacao = document.getElementById('ddlAvaliacao');
		Nome.value = "";
		Opiniao.value = "";
		Avaliacao.value = " ";
	}	

	function Janela(Link)	
	{
		alert(Link)
	}
	
	function AbreVideo(endereco)
	{
		window.open (endereco, "mywindow","status=0,toolbar=0,<code>scrollbars=1,width=425,height=445");
	}
	
	
	function ConsisteValor()
	{
		var ChoicePlan = document.getElementById('txtValor');

		if(ChoicePlan.value =="")
		{
			alert('Selecione o plano desejado!');
			return false;
		}else
		{
		return true;
		}
	}

/*************************************************************/

function AtendimentoOnLine()
{
	window.open ("http://azzu.com.br:9090/webchat/start.jsp?workgroup=lojavirtual@workgroup.azzu.com.br", "mywindow","status=0,toolbar=0,<code>scrollbars=1,width=499,height=400");
//	window.open ("http://sa.ctbc.com.br:9090/webchat/userinfo.jsp?chatID=&workgroup=lojavirtual@workgroup.tudomais.com.br", "mywindow","status=0,toolbar=0,<code>scrollbars=1,width=499,height=400");
}

/*************************************************************/

function PopUpRegulamento()
{
	window.open ('http://www.lojaCTBC.com.br/regulamento.htm', 'janela','status=0,toolbar=0,scrollbars=yes,width=800,height=700');
}

function Msg()
{
	ddrivetip('Valores sujeitos a alteração no fechamento do pedido de acordo com o plano do cliente e última compra de aparelho celular realizada na CTBC com subsídio.');
}

function AlternSearch(aux)
{
	obj=document.getElementById('Painelcarac');
	
	if(aux.value == 13)
	{
		obj.style.display = 'block';
	}else
	{	
		obj.style.display = 'none';
	}
}


function LoadFlash(caminho,largura,altura)
{
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+largura+'" height="'+altura+'">');
    document.write('<param name="movie" value="'+caminho+'">');
    document.write('<param name="quality" value="high">'); 
    document.write('<param name="wmode" value="transparent">');
    document.write('<param name="menu" value="false">');
    document.write('<embed src="'+caminho+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'"></embed>');
    document.write('</object>');

}


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];}
}

function hideTime(item){
//document.getElementById('136997').style.display='none';
document.getElementById(item).style.display='none';
}
