/* -------------------------------------------------- */
/* SOURCE CODE                                        */
/* -------------------------------------------------- */
/**
*
* @copyright Copyright (c) 2007, NETCRIATIVA
*
*/

function abrirFoto(file, name, width, height, scrollbars)
{
   // Certifica-se de que uma dimensão de tela existe
   screen_width = 800;
   screen_height = 600;

   if (scrollbars) if (scrollbars !== '') scrollbars = ',' + scrollbars;

   // Dimensões da tela do usuário
   if (screen) if (screen.width) screen_width = screen.width;
   if (screen) if (screen.height) screen_height = screen.height;

   // Calcula a posição da janela no centro
   window_left = (screen_width / 2) - (width / 2);
   window_top = (screen_height / 2) - (height / 2);

   // Abre janela
   if (window)
   {
      if (window.open)
      {
         w = window.open(file,name,'width='+width+',height='+height+',left='+window_left+',top='+ window_top+',screenX='+window_left+',screenY='+ window_top+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollbars+',resizable=no,menubar=no,copyhistory=no');
         if (w.moveTo)
            w.moveTo(window_left, window_top);
         if (w.focus)
            w.focus();

         w.document.write("<html>");
         w.document.write("<head>");
         w.document.write("<title>Yasui Shopping</title>");
         w.document.write("</head>");
         w.document.write("<body topmargin='0' leftmargin='0'>");
         w.document.write("<table width='100%' height='" + height + "' border='0' cellpadding='0' cellspacing='0'>");
         w.document.write("  <tr>");
         w.document.write("    <td width='" + width + "' class='foto'>");
         w.document.write("<p><img src='" + file + "' alt='' /></p>");
         w.document.write("    </td>");
         w.document.write("  </tr>");
         w.document.write("</table>");
         w.document.write("</body>");
         w.document.write("</html>");
         w.document.close();
      }
   }
}

function moeda(moeda, url, qs)
{
   if (qs != '')
   {
      pos = qs.indexOf("moeda=");

      if (pos > 0)
      {
         pos = pos + 7;
         tam = qs.length;
         qs  = '?' + qs.slice(0, pos) + moeda;
      }
      else
      {
         qs = '?' + qs + '&moeda=' + moeda;
      }
   }
   else
   {
      qs = '?moeda=' + moeda;
   }

   document.location.href = url + qs;
}


function addCart()
{

   if (document.getElementById('f_Combinacao'))
   {
	   if (document.getElementById('f_Combinacao').value == "")
      {
	      alert("É necessário selecionar uma opção!");
         document.getElementById('f_Combinacao').focus();

	      return false;
		}
	}

   return true;
}


/* -------------------------------------------------- */
/* CARRINHO                                           */
/* -------------------------------------------------- */
function remover(form, codigo)
{
   // Página para qual os dados do formulário serão enviados.
   form.action = "carrinho.php";

   // Seta o valor 'atualizar' no campo para que a página possa processar os dados.
   form.f_Action.value = "remover";

   form.f_Codigo.value = codigo;

   // Envia os dados do formulário.
   form.submit();
}

function atualizarValores(form)
{
   // Página para qual os dados do formulário serão enviados.
   form.action = "carrinho.php";

   // Seta o valor 'atualizar' no campo para que a página possa processar os dados.
   document.getElementById('f_Action').value = "atualizar";

   // Envia os dados do formulário.
   form.submit();
}

function fecharPedido(form, action)
{
   if (form.name == 'frmPedido')
   {
      document.location.href = "identificacao.php?" + action;

      return true;
   }
}
/* -------------------------------------------------- */


function cadastrado(valor)
{
   if (valor == 'S')
   {
      document.getElementById('senha').style.display = 'block';
      document.getElementById('f_jpSenha').disabled = false;
      document.getElementById('f_jpSenha').focus();
	}
   else
   {
      document.getElementById('senha').style.display = 'none';
      document.getElementById('f_jpSenha').disabled = true;
	}
}


function continuarEndereco(form)
{
   if ((form.f_Cadastrado_S.checked == false) && (form.f_Cadastrado_N.checked == false))
   {
      alert("Preencha os dados corretamente!");
      form.f_jpEmail.focus();

      return false;
   }

   // Cliente ja cadastrado
   if (form.f_Cadastrado_S.checked == true)
   {
      if (!form.f_jpEmail.value)
      {
         alert("É necessário que você preencha seu e-mail!");
         form.f_jpEmail.focus();
         return false;
      }
      else
      {
         if (form.f_jpEmail.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
         {
            alert("Digite um e-mail válido!");
            form.f_jpEmail.focus();
            return false;
         }
      }

      if (!form.f_jpSenha.value)
      {
         alert("É necessário que você preencha sua senha!");
         form.f_jpSenha.focus();
         return false;
      }

//      form.action = "identificacao.php?status=cadastrado";
      form.submit();
      return true;
   }

   // Cliente nao cadastrado
   if (form.f_Cadastrado_N.checked == true)
   {
      if (!form.f_jpEmail.value)
      {
         alert("É necessário que você preencha seu e-mail!");
         form.f_jpEmail.focus();
         return false;
      }
      else
      {
         if (form.f_jpEmail.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
         {
            alert("Digite um e-mail válido!");
            form.f_jpEmail.focus();
            return false;
         }
      }

      form.f_Carrinho.value = "S";

      form.submit();
      return true;
   }
}

function tpdoc(valor)
{
   switch (valor)
   {
      case 'EN' :
         document.getElementById('transferencia_bancaria').style.display = 'none';
         document.getElementById('cartao_de_credito').style.display      = 'none';

         document.getElementById('f_Bandeira').disabled          = true;
         document.getElementById('f_NomeDoTitular').disabled     = true;
         document.getElementById('f_NumeroDoCartao').disabled    = true;
         document.getElementById('f_CodigoDeSeguranca').disabled = true;
         document.getElementById('f_Mes').disabled               = true;
         document.getElementById('f_Ano').disabled               = true;

         fpgto(valor);

         break;
      case 'TB' :
         document.getElementById('transferencia_bancaria').style.display = 'block';
         document.getElementById('cartao_de_credito').style.display      = 'none';

         document.getElementById('f_Bandeira').disabled          = true;
         document.getElementById('f_NomeDoTitular').disabled     = true;
         document.getElementById('f_NumeroDoCartao').disabled    = true;
         document.getElementById('f_CodigoDeSeguranca').disabled = true;
         document.getElementById('f_Mes').disabled               = true;
         document.getElementById('f_Ano').disabled               = true;

         fpgto(valor);

         break;
      case 'CC' :
         document.getElementById('transferencia_bancaria').style.display = 'none';
         document.getElementById('cartao_de_credito').style.display      = 'block';

         document.getElementById('f_Bandeira').disabled          = false;
         document.getElementById('f_NomeDoTitular').disabled     = false;
         document.getElementById('f_NumeroDoCartao').disabled    = false;
         document.getElementById('f_CodigoDeSeguranca').disabled = false;
         document.getElementById('f_Mes').disabled               = false;
         document.getElementById('f_Ano').disabled               = false;

         document.getElementById('f_Bandeira').focus();

         fpgto(valor);

         break;
	}

   if (valor == 'S')
   {
      document.getElementById('senha').style.display = 'block';
      document.getElementById('f_jpSenha').disabled = false;
      document.getElementById('f_jpSenha').focus();
	}
   else
   {
      document.getElementById('senha').style.display = 'none';
      document.getElementById('f_jpSenha').disabled = true;
	}
}

function cellMouseOver(obj)
{
   obj.className = "cellMouseOver";
}
function cellMouseOut(obj)
{
   obj.className = "cellMouseOut";
}

function cellLatMouseOver(obj)
{
   obj.className = "cellLatMouseOver";
}

function cellLatMouseOut(obj)
{
   obj.className = "cellLatMouseOut";
}

function trocaClassForms()
{
   for (f = 0; f < document.forms.length; f++)
   {
      form = document.forms[f];

      for (i = 0; i < form.length; i++)
      {
         // text | textarea | password
         if ((form[i].type == 'text') || (form[i].type == 'textarea') || (form[i].type == 'password'))
         {
            // onfocus
            form[i].onfocus = function()
            {
               this.className = "textF";
            }

            // onblur
            form[i].onblur = function()
            {
               this.className = "text";
            }
         }
         // select-one | select-multiple
         if ((form[i].type == 'select-one') || (form[i].type == 'select-multiple'))
         {
            // onfocus
            form[i].onfocus = function()
            {
               this.className = "selectF";
            }

            // onblur
            form[i].onblur = function()
            {
               this.className = "select";
            }
         }
      }
   }
}

window.onload = function()
{
	trocaClassForms();
}

function abrirJanela(file, name, width, height, scrollbars)
{
   // Certifica-se de que uma dimensão de tela existe
   screen_width  = 800;
   screen_height = 600;

   // Dimensões da tela do usuário
   if (screen) if (screen.width) screen_width = screen.width;
   if (screen) if (screen.height) screen_height = screen.height;

   // Calcula a posição da janela no centro
   window_left = (screen_width / 2) - (width / 2);
   window_top  = (screen_height / 2) - (height / 2);

   // Abre janela
   if (window)
   {
      if (window.open)
      {
         w = window.open(file, name, 'width=' + width + ', height=' + height + ', left=' + window_left + ', top=' + window_top + ', screenX=' + window_left + ', screenY=' +  window_top + ', toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=' + scrollbars + ', resizable=no, menubar=no');

         if (w.moveTo)
            w.moveTo(window_left, window_top);

         if (w.focus)
            w.focus();

         return w;
      }
   }
}

/* -------------------------------------------------- */