var domain = document.domain;

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

function player() {
  window.open('player.htm','tour','width=500, height=230, status=no');
}
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 CONTATO!");
        document.f1.nome.focus();
    }
    else if (!validaemail(document.f1.emai.value)) {
        alert("Preencha o campo E-MAIL!");
        document.f1.emai.focus();
    }
    else if ( ! validaCPF( document.f1.cpf.value ) )
    {
        alert("Preencha corretamente o campo CPF!");
        document.f1.cpf.focus();
    }
    else if ( ! validaCNPJ( document.f1.cnpj.value ) )
    {
        alert("Preencha corretamente o campo CNPJ!");
        document.f1.cnpj.focus();
    }
    else if ( document.f1.mensagem.value.length < 3 ){
        alert("Preencha o campo MENSAGEM!");
        document.f1.mensagem.focus();
    } else {
        document.f1.submit();
    }
  }
  else if (param == 4) {
    if (document.f1.recad_nome.value.length < 3) {
      alert("Preencha o campo NOME!");
      document.f1.recad_nome.focus();
    }
    else if (escape(document.f1.recad_nome.value).length > 64) {
      alert("Campo NOME deve conter no máximo 64 caracteres!");
      document.f1.recad_nome.focus();
    }
    else if (!validaemail(document.f1.recad_email.value)) {
      alert("Preencha o campo E-MAIL!");
      document.f1.recad_email.focus();
    }
    else if (escape(document.f1.recad_email.value).length > 128) {
      alert("Campo E-MAIL deve conter no máximo 128 caracteres!");
      document.f1.recad_email.focus();
    }
    else if (document.f1.recad_recado.value.length < 3) {
      alert("Preencha o campo MENSAGEM!");
      document.f1.recad_recado.focus();
    }
    else if (escape(document.f1.recad_recado.value).length > 255) {
      alert("Campo MENSAGEM deve conter no máximo 255 caracteres!");
      document.f1.recad_recado.focus();
    }
    else if (document.f1.recad_codigo.value.length < 3) {
      alert("Preencha o campo CÓDIGO!");
      document.f1.recad_codigo.focus();
    }
    else if (escape(document.f1.recad_codigo.value).length > 4) {
      alert("Campo CÓDIGO deve conter no máximo 4 caracteres!");
      document.f1.recad_codigo.focus();
    }
    else {
      document.f1.submit();
    }
  }
}


function validaCPF( cpf )
{
    // Tira os pontos e o traço
    exp = /[^0-9]/g;
    cpf = cpf.replace( exp, '' );

    // Verifica se o campo é nulo
    if (cpf == '')
        return false;

    // Aqui começa a checagem do CPF
    var posicao, i, soma, dv, dv_informado;
    var digito = new Array(10);
    dv_informado = cpf.substr(9, 2); // Retira os dois últimos dígitos do número informado

    // Desemembra o número do CPF na array DIGITO
    for (i=0; i<=8; i++)
        digito[i] = cpf.substr( i, 1);

    // Calcula o valor do 10º dígito da verificação
    posicao = 10;
    soma = 0;
    for (i=0; i<=8; i++)
    {
        soma    = soma + digito[i] * posicao;
        posicao = posicao - 1;
    }
    digito[9] = soma % 11;
    if (digito[9] < 2)
        digito[9] = 0;
    else
        digito[9] = 11 - digito[9];

    // Calcula o valor do 11º dígito da verificação
    posicao = 11;
    soma = 0;
    for (i=0; i<=9; i++)
    {
        soma    = soma + digito[i] * posicao;
        posicao = posicao - 1;
    }
    digito[10] = soma % 11;
    if (digito[10] < 2)
        digito[10] = 0;
    else
        digito[10] = 11 - digito[10];

    // Verifica se os valores dos dígitos verificadores conferem
    dv = digito[9] * 10 + digito[10];

    if (dv != dv_informado)
        return false;
    else
        return true;
}

function validaCNPJ( cnpj ) {

    // Tira os pontos e o traço
    exp = /[^0-9]/g;
    cnpj = cnpj.replace( exp, '' );

    if (cnpj.length < 14)
        return false;

    var a = [];
    var b = new Number;
    var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];

    for (i=0; i<12; i++){
        a[i] = cnpj.charAt(i);
        b += a[i] * c[i+1];
    }

    if ((x = b % 11) < 2)
        a[12] = 0;
    else
        a[12] = 11-x;

    b = 0;
    for (y=0; y<13; y++)
        b += (a[y] * c[y]);

    if ((x = b % 11) < 2)
        a[13] = 0;
    else
        a[13] = 11-x;

    if ((cnpj.charAt(12) != a[12]) || (cnpj.charAt(13) != a[13]))
        return false;

    return true;
}

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('foto.htm?'+foto,'imagem','width=100, height=100, status=no');
}
function tour() {
  window.open('tour.htm','tour','width=650, height=350, status=no');
}

var res = screen.height;
	if (res <= 600)
	{
		document.write('<style type="text/css">#geral{min-height:86%;_height:86%;}<\/style>')
	}
	else if ( res == 768 )
	{
		document.write('<style type="text/css">#geral{min-height:85%;_height:85%;}<\/style>')
	}
	else if ( res == 864 )
	{
		document.write('<style type="text/css">#geral{min-height:88%;_height:88%;}<\/style>')
	}
	else if ( res == 1024 )
	{
		document.write('<style type="text/css">#geral{min-height:91%;_height:91%;}<\/style>')
	}
	else if ( res == 1200 )
	{
		document.write('<style type="text/css">#geral{min-height:93%;_height:93%;}<\/style>')
	}
	else
	{
		document.write('<style type="text/css">#geral{min-height:95%;_height:95%;}<\/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;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function changeImg ( imagem,clipping,imagemOriginal)
{
    parent.document.getElementById('img_grande').src = imagem ;
    if(imagemOriginal!="" && (clipping=="t" || clipping=="true"))
    {
    	document.getElementById('linkBaixarImagem').href="http://"+domain+"/baixarImagem.php?img="+imagemOriginal;
    	$('div#baixarImagem').show();
    }
    else
    {
    	$('div#baixarImagem').hide();
    }
}

/*
function verificaExistenciaImagemClipping(idGaleria,idImagem)
{
    caminho = url+valor;
    // PROCURA POR UM OBJETO NATIVO (MOZILLA/SAFARI)
    if ( window.XMLHttpRequest )
    {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", caminho, true);
        req.send(null);
    // PROCURA POR UMA VERSAO ACTIVEX (IE)
    }
    else if ( window.ActiveXObject )
    {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if ( req )
        {
            req.onreadystatechange = processReqChange;
            req.open("GET", caminho, true);
            req.send();
        }
    }
}
*/

//Funções Ajax
//url -> página a ser carregada, parametros -> colocar os parametros separados por "&", div -> onde será carregado o resultado
var g=0;
function AjaxRequest(url, elemento)
{
	var ajax = objAjax();
	if(ajax == null)
	{
		alert("Impossível concluir a operação");
	}

	url2 = url+Math.random();

	ajax.open("GET",url2,true);
	ajax.onreadystatechange = function()
	{
		if(ajax.readyState == 4)
		{
			document.getElementById(elemento).src = url+'&amp;' + (g++);
		}
	}

	ajax.send(null);
}

function objAjax()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	return xmlHttp;
}

// SOBE O TEXTO
function scrollmarquee()
{
	if (parseInt(cross_marquee.style.top) > actualheight*(-1))
		cross_marquee.style.top = parseInt(cross_marquee.style.top)-copyspeed+"px";
	else
		cross_marquee.style.top = parseInt(marqueeheight)+"px";
}

function initializemarquee(id_container,id_marquee)
{
	cross_marquee = document.getElementById(id_marquee);
	marqueeheight = document.getElementById(id_container).offsetHeight;
	actualheight  = cross_marquee.offsetHeight;

	if (window.opera || navigator.userAgent.indexOf("Netscape/7") != -1)
	{ // SE FOR OPERA OR NETSCAPE 7X, ADICIONAR SCROLLBARS TO SCROLL
		cross_marquee.style.height   = marqueeheight+"px";
		cross_marquee.style.overflow = "scroll";
		return
	}

	lefttimeout = setTimeout('leftinterval = setInterval("scrollmarquee()",30)',0);
}

function mouseOut()
{
	window.clearInterval(lefttimeout);
	window.clearInterval(leftinterval);
}
