/*
 * Copyright Sentido Virtual - http://www.sentidovirtual.com.br
 * contato@sentidovirtual.com.br
 */
 
window.defaultStatus = ".:..:: PET COMPRE - www.petcompre.com.br ::..:."


function OpenUp(resenha, w, h)
{
	l = (screen.availWidth-w) / 3;
	t = (screen.availHeight-h) / 3;
	remote = window.open(resenha,'comentario','left='+l+',top='+t+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,menubar=no,width='+ w + ',height='+ h + '')
}

// ********************************************************************************

function ver_busca()
{
	if(isFieldBlank(document.formbusca.bc))
	{
		alert("Você deve digitar pelo menos uma palavra para realizar a busca.");
		document.formbusca.bc.focus();
		return false;
	}
	if(document.formbusca.bc.value.length < 3)
	{
		alert("Sua palavra deve conter no mínimo 3 caracteres.");
		document.formbusca.bc.focus();
		return false;
	}	
}

// ********************************************************************************

function tabRoll(srv,vale)
{
srv.className=vale; 
}

// ********************************************************************************

// checa campo vazio
function isFieldBlank(theField)
{
	inStr = theField.value;
	inLen = inStr.length;
	for(var i = 0; i < inLen; i++)
	{
		var ch = inStr.substring(i, i+1)
		if (ch != " ")
		return false;   
	}
	theField.Value = "";
	return true;
}

// ********************************************************************************

// checa se é número
function isNumber(theNumber)
  {
  inStr = theNumber.value;
  inLen = inStr.length;
  for(var i = 0; i < inLen; i++)
    {
      var ch = inStr.substring(i, i+1)
      if ((ch < "0") || (ch > "9"))
        return false;
    }
  return true;
  }

// ********************************************************************************

function Verifica()
{
	var caract = new RegExp(/^[a-z 0-9 ç ã á ê é í ó ü ú]+$/i); 
	var caract = caract.test(String.fromCharCode(event.keyCode));

	if(!caract){
		//alert("Caracter inválido.\n" +String.fromCharCode(event.keyCode));
		event.keyCode=0;
		return;
	}
}

// ********************************************************************************

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// ********************************************************************************

// validação para entrada somente Números
function key()
{
	theKey = event.keyCode;
	if ((theKey < 48) ||
	(theKey > 57))
	event.returnValue = false;
}

// ********************************************************************************

function go(pag)
{
	top.opener.top.location.href=pag;
	window.self.close();
}

// ********************************************************************************

// Função utilizada para 'saltar' os campos quando o maxlength é atingido
function DFchangeField(o,e) {
	if(window.event)key=window.event.keyCode;
	else if(e)key=e.which;
	else return true;
	if (key==9||key==2||key==16) return false;
	// Vai
	if(o.value.length==o.maxLength){
  		for(var i=0;i<o.form.length;i++){
			if(o.form[i]==o && o.form[i+1]){
	    		if (!o.form[i+1].disabled && o.form[i+1].type != "hidden" && o.form[i+1].style.display != "none") {
					o.form[i+1].focus();
					return true;
				}else{
					return false;
				}
	    	}
		}
	}
	// Volta
	if(o.value.length == 0 && key == 8){
  		for(var i=0;i<o.form.length;i++){
    		if(o.form[i]==o && o.form[i-1]){
				if (!o.form[i-1].disabled && o.form[i-1].type != "hidden" && o.form[i+1].style.display != "none") {
					setTimeout("document." + o.form.name + "[" + (i-1) +"].focus()",10);
    				o.form[i-1].value = o.form[i-1].value;
    				return;
    			}else{
					return;
				}
			}
		}
	}
}

// ********************************************************************************

// função utilizada em formulário para aceitar somente entrada de números.
function soNumero(event)
{
	iKey = KeyStroke( event );
	if (!( ( iKey>47 && iKey<58 ) || iKey == 13 || iKey == 0 || iKey == 8 ) )
	{
		return false;
	}
	return true;
}

function KeyStroke( event )
{
	ikey = 0;
	if( event.which == undefined )
	{
		ikey = window.event.keyCode;
	}
	else
	{
		ikey = event.which;
	}
	return ikey;
}

// ********************************************************************************

// funçoes utilizadas no formulário de cadastro, para deixar os campos 'destacados' quando não preenchido.
function destacField(field, destac)
{
	if(destac)
	{
		field.style.borderColor = "#EB151A";
		field.style.backgroundColor = "#F9B8BA";
	}
	else
	{
		field.style.borderColor = "";
		field.style.backgroundColor = "#FFFFFF";
	}
}

function destacLabel(labelId, destac)
{
	if(destac)
	{
		document.getElementById(labelId).style.color = "#EB151A";
	}
	else
	{
		document.getElementById(labelId).style.color = "";
	}
}

// ********************************************************************************

// validação para qtd de caracters no campo
function minLen(txtField, minVal)
{
	strExp = txtField.value;
	l = strExp.length;
	if (l < minVal)
		return(true);
	else
		return(false);
}

// ********************************************************************************
// ********************************************************************************
// ********************************************************************************

// funções do carrinho

function valida_cep()
{
	Form = document.carrinho;
	if (Form.cep1.value.length==0||Form.cep1.value.length < 5)
	{
		alert("Informe o CEP corretamente.");
		Form.cep1.focus();
		return false;
	}
     
	if (Form.cep2.value.length==0||Form.cep2.value.length < 3)
	{
		alert("Informe o CEP corretamente.");
		Form.cep2.focus();
		return false;
	}
}

// ********************************************************************************

function valida_frete() {
  Form = document.carrinho;
  marcado = -1;
  if ( !Form.tipo_frete.length ) Form.tipo_frete.checked = true;
  else {
    for ( i = 0; i < Form.tipo_frete.length; i++ ) if ( Form.tipo_frete[i].checked ) marcado = i;
    if ( marcado == -1 ) {
      alert("Selecione uma opção de Entrega.");
      return false;
    }
  }
}

function valida_frete2()
{
	Form = document.carrinho;
	if (Form.tipo_frete.checked==false)
	{
		alert("Selecione uma opção de Entrega.");
		return false;
	}
}

// ********************************************************************************

function envia_frete() {
  if ( document.forms("pagamento") ) Form = document.pagamento;
  else Form = carrinho.pagamento;
  if ( Form ) {
    Form.Finalizar.value = "Aguarde...";
    Form.Finalizar.disabled = true;
  }
  document.carrinho.submit();
}

// ********************************************************************************
// ********************************************************************************
// ********************************************************************************

