var domain = document.domain;

if( domain == '192.168.0.200' )
	domain += '/dev/imprimafacil';
else if( domain == 'www.magicwebdesign.com.br' )
	domain += '/dev/imprimafacil';

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 validaemail(email) {
  var objRegExp  = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/i;
  return objRegExp.test(email);
}

function envia(param) {
  if (param == 1) {
    if (document.f1.nome.value.length < 3) {
      alert("Preencha o campo NOME!");
      document.f1.nome.focus();
    }
    else {
      if (!validaemail(document.f1.emai.value)) {
        alert("Preencha o campo E-MAIL!");
              document.f1.emai.focus();
      }
      else {
        document.f1.submit();
      }
    }
  }
  else if (param == 2) {
    if (!validaemail(document.f2.emai.value)) {
      alert("Preencha o campo E-MAIL!");
      document.f2.emai.focus();
    }
    else {
      document.f2.submit();
    }
  }
  else if ( param == 3 ) {
    if (document.f1.nome.value.length < 3) {
      alert("Preencha o campo NOME!");
      document.f1.nome.focus();
    }
    else {
      if (!validaemail(document.f1.email.value)) {
        alert("Preencha o campo E-MAIL!");
              document.f1.email.focus();
      }
      else {
        if ( document.f1.comentario.value.length < 3 )
        {
            alert("Preencha o campo MENSAGEM!");
        } else {
            document.f1.submit();
        }
      }
    }
  } else {
    if (document.f1.nome.value.length < 3) {
      alert("Preencha o campo NOME!");
      document.f1.nome.focus();
    }
    else {
      if (!validaemail(document.f1.email.value)) {
        alert("Preencha o campo E-MAIL!");
              document.f1.email.focus();
      }
      else {
        document.f1.submit();
      }
    }
  }
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_showHideLayers2() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers2.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_showHideLayers3() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers3.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_showHideLayers4() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers4.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function abre_popup(foto)
{
  window.open( 'http://'+domain+'/dev/imprimafacil/foto.htm?'+foto,'imagem','width=100, height=100, status=no');
}

function tour()
{
  window.open('tour.htm','tour','width=600, height=400, status=no');
}

var res = screen.height;
	if (res <= 600)
	{
		document.write('<style type="text/css">#geral{min-height:93%;_height:93%;}<\/style>')
	}
	else if ( res == 768 )
	{
		document.write('<style type="text/css">#geral{min-height:94%;_height:94%;}<\/style>')
	}
	else if ( res == 864 )
	{
		document.write('<style type="text/css">#geral{min-height:95%;_height:95%;}<\/style>')
	}
	else if ( res == 1024 )
	{
		document.write('<style type="text/css">#geral{min-height:96%;_height:96%;}<\/style>')
	}
	else if ( res == 1200 )
	{
		document.write('<style type="text/css">#geral{min-height:97%;_height:97%;}<\/style>')
	}
	else
	{
		document.write('<style type="text/css">#geral{min-height:98%;_height:98%;}<\/style>')
	}

/*
    COMO USAR
    EX: onkeypress="return Mascaras ( event, 'FONE', 'nome_id' );"
*/
function Mascaras ( e, formato, objeto )
{
    var key;

    if ( window.event ) keyPressed = window.event.keyCode; // IE hack
    else keyPressed = e.which; // <B>standard method</B>

    if ( keyPressed >= 48 && keyPressed <= 57 )
    {
        var campo = document.getElementById(objeto);
        
        /*
            DATA
            FORMATO: 00/00/0000
        */
        if ( formato == 'DATA' )
        {
            separador = '/'; 
            conjunto1 = 2;
            conjunto2 = 5;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador;
            
            if ( campo.value.length == conjunto2 )
                campo.value = campo.value + separador;
            
            return true;
        }
        
        /*
            HORA
            FORMATO: 00:00
        */
        if (formato == 'HORA')
        {
            separador = ':';
            conjunto1 = 2;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador;
            
            return true;
        }
        
        /*
            CEP
            FORMATO: 00000-000
        */
        if (formato == 'CEP')
        {
            separador = '-';
            conjunto1 = 5;
            if (    campo.value.length == conjunto1 )
                campo.value = campo.value + separador;
            
            return true;
        } 
        
        /*
            CPF
            FORMATO: 000.000.000-00
        */
        if (formato == 'CPF')
        {
            separador = '.';
            separador1 = '-';
            conjunto1 = 3;
            conjunto2 = 7;
            conjunto3 = 11;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador;

            if ( campo.value.length == conjunto2 )
                campo.value = campo.value + separador;

            if ( campo.value.length == conjunto3 )
                campo.value = campo.value + separador1;
            
            return true;
        }
        
        /*
            CNPJ
            FORMATO: 00.000.000/0000-00
        */
        if (formato == 'CNPJ')
        {
            separador1 = '.';
            separador2 = '/';
            separador3 = '-';
            conjunto1 = 2;
            conjunto2 = 6;
            conjunto3 = 10;
            conjunto4 = 15;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador1;
            
            if ( campo.value.length == conjunto2 )
                campo.value = campo.value + separador1;
            
            if ( campo.value.length == conjunto3 )
                campo.value = campo.value + separador2;
            
            if ( campo.value.length == conjunto4 )
                campo.value = campo.value + separador3;
            
            return true;
        }
        
        /*
            FONE
            FORMATO: (00) 0000-0000
        */
        if ( formato == 'FONE' )
        {
            separador1 = '(';
            separador2 = ') ';
            separador3 = '-';
            conjunto1 = 0;
            conjunto2 = 3;
            conjunto3 = 9;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador1;
            
            if ( campo.value.length == conjunto2 )
                campo.value = campo.value + separador2;
            
            if ( campo.value.length == conjunto3 )
                campo.value = campo.value + separador3;
            
            return true;
        }
        
        /*
            FONE2
            FORMATO: 0000-0000
        */
        if ( formato == 'FONESIMPLES' )
        {
            separador1 = '-';
            conjunto1 = 4;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador1;
            
            return true;
        }
    }
    else if ( keyPressed == 8 || keyPressed == 13 || keyPressed == 0 )
        return true;
    else
        return false;
}

/*
    COMO USAR
    EX: onkeypress="return TextoSimples ( event );"
*/
function TextoSimples ( e )
{
    if ( window.event ) keyPressed = window.event.keyCode; // IE hack
    else keyPressed = e.which; // <B>standard method</B>

    if ( keyPressed == 8 || keyPressed == 95  || keyPressed == 13  || keyPressed == 0 ) return true;
    else if ( ( keyPressed >= 48 && keyPressed <= 57 ) || (keyPressed > 96 && keyPressed < 123) || keyPressed == 95 ) return true;
    else if ( ( keyPressed > 191 && keyPressed < 221 ) || ( keyPressed > 223 && keyPressed < 253 ) ) return true;
    
    return false;
}

/*
    COMO USAR
    EX: onkeypress="return Numeros ( event );"
*/
function Numeros ( e )
{
    if ( window.event ) keyPressed = window.event.keyCode; // IE hack
    else keyPressed = e.which; // <B>standard method</B>
    
    if ( keyPressed == 8 || keyPressed == 13 || keyPressed == 0 ) return true;
    else if ( keyPressed >= 48 && keyPressed <= 57 ) return true;
              
    return false;
}


/*
    MOSTRAIMG
    MOSTRA A IMAGEM THUMB E TROCA O LINK PARA ABRIR A GRANDE
*/
function mostraImg ( id_ampli, src_ampli, id_link, src_alta )
{
    document.getElementById( id_ampli ).src = src_ampli;
    document.getElementById( id_link ).href = "javascript:abre_popup('"+src_alta+"')";
}

function myLoadXml_img ( arq, div_apaga, div_id, valor )
{
    divId = div_id ;
    divApaga = div_apaga ;
    loadXMLDoc_img ( arq, valor );
}

function alteraResul( div_resul, div_altera )
{
	document.getElementById( div_resul ).style.display = 'none';
	document.getElementById( div_altera ).style.display = '';
}

function aceitaResul( div_resul, val_altera, div_altera )
{
	document.getElementById( div_resul ).innerHTML = document.getElementById( val_altera ).value;
	document.getElementById( div_resul ).parentNode.style.display = '';
	document.getElementById( div_altera ).style.display = 'none';
}

function persoImage( status, campo, produ_nome_url, diretorio )
{
	if ( !status )
	{
		document.f1.target = "ifrPerso";
		document.f1.action = "http://"+domain+"/loja/xmlPersoImage.php?"+campo;
		
		document.getElementById( "altera_"+campo ).style.display = 'none';
		document.getElementById( "resul_"+campo ).style.display = 'none';
		document.getElementById( "carre_"+campo ).style.display = '';
		
		document.f1.submit();
	}
	else if ( status && campo && produ_nome_url && diretorio )
	{
		numRand = Math.random();
		
		parent.document.f1.target = "_self";
		parent.document.f1.action = "http://"+domain+"/loja/carrinho/"+produ_nome_url;
		parent.document.getElementById( "img_"+campo ).src = "http://"+domain+"/imagens/temp/"+diretorio+"/"+campo+"_thumb.jpg?"+numRand;
		
		parent.document.getElementById( "carre_"+campo ).style.display = 'none';
		parent.document.getElementById( "altera_"+campo ).style.display = 'none';
		parent.document.getElementById( "resul_"+campo ).style.display = '';
	}
}

/*
    ABRE_PAGINA
    ABRE UMA PÁGINA DE ACORDO COM O CAMINHO E AS DIMENSÕES PASSADAS.
*/
function abre_pagina ( caminho, width, height )
{
	posY = ( screen.height / 2 ) - ( height / 2 );
	posX = ( screen.width / 2 ) - ( width / 2 );
	window.open( caminho, "", "height="+height+", width="+width+", scrollbars=yes, tollbar=no, status=no, menubar=no, location=no, top="+posY+", left="+posX );
	return false;
}



function addImage ( diretorio, produ_nome_url, status, num_foto )
{
	if ( !status )
	{
        if ( ! document.f1.input_add_imagem.value )
        {
            alert ( 'Por favor, selecione uma imagem.' );
            return false;
        }
        
		document.f1.target = "ifrAddImg";
		document.f1.action = "http://"+domain+"/loja/xmlAddImage.php";
		
		document.f1.submit();
	}
	else if ( status == 'carregado' )
	{
        // recarrega a página para corrigir os DRAGs e imagens
        parent.location.href = parent.location.href;
        return false;
        
        /** daqui pra baixo não está rodando por enquanto **/
        
        parent.total_fotos ++;
		parent.document.f1.target = "_self";
		parent.document.f1.action = "http://"+domain+"/loja/carrinho/"+produ_nome_url;
        
        var li = document.createElement ( 'li' );
        li.id  = 'fot' + parent.total_fotos;
        
        var div = document.createElement ( 'div' );
        div.id  = 'botao' + parent.total_fotos;
        div.style.display = 'block';
        div.className = 'bot';
        div.setAttribute ( 'class', 'bot' );
        
        var a1     = document.createElement ( 'a' );
        a1.href    = "javascript: alert ('oi');";
        a1.onclick = function () {
            alert ( "iu" );
            return false;
            open ( 'http://' + parent.domain + '/imagens/temp/' + diretorio + '/' + num_foto + '.jpg', '_blank' );
            return false;
        }
        a1.className = 'link_galer';
        a1.setAttribute ( 'class', 'link_galer' );
        a1.innerHTML = 'ampliar';
        
        var a2     = document.createElement ( 'a' );
        a2.onclick = function () {
            if ( confirm ( 'Tem certeza que deseja remover esta foto do álbum?' ) )
                parent.myLoadXml_img_POST ( 'http://' + parent.domain + '/loja/ajax_remove_img.php', this.parentNode.parentNode.id, '', 'dir=' + diretorio + '&foto=t_' + num_foto + '.jpg' );
            return false;
        }
        a2.href    = "#";
        a2.className = 'link_galer';
        a2.setAttribute ( 'class', 'link_galer' );
        a2.innerHTML = 'excluir';
        
        var div2 = document.createElement ( 'div' );
        div2.id  = 'foto' + parent.total_fotos;
        
        img     = document.createElement ( 'img' );
        img.src = 'http://' + parent.domain + '/imagens/temp/' + diretorio + '/' + 't_' + num_foto + '.jpg';
        img.alt = '';
        img.className = 'fot';
        img.setAttribute ( 'class', 'fot' );
        
        
        div.appendChild ( a1 );
        div.innerHTML += ' | ';
        div.appendChild ( a2 );
        
        div2.appendChild ( img );
        
        li.appendChild ( div );
        li.appendChild ( div2 );
        
        var ul;
        
        if ( parent.document.getElementById ( 'boxes' ) )
        {
            ul = parent.document.getElementById ( 'boxes' );
            ul.appendChild ( li );
        }
        else
        {
            ul = document.createElement ( 'ul' );
            ul.id = 'boxes';
            ul.appendChild ( li );
            
            galeria = parent.document.getElementById ( 'galeria' );
            galeria.innerHTML = '';
            galeria.appendChild ( ul );
        }
        return false;
	}
    else
    {
        alert ( status );
    }
}
/**
 * Função para retirada de produto na loja
 * @author Julio Luiz <julio@magicwebdesign.com.br>
 * @date 11/06/2008
 */
function entregaLoja() {
	myLoadXml_img(
					'http://' + domain + '/loja/ajax_session.php?',
					'', 
					'', 
					'fentr_id=99', 
					function() { 
						if (req.readyState == 4 && req.status == 200 && req.responseText == 'ok') 
							window.location = 'identificacao';
					}
	);
}