
function flash(src,w,h,string_values) {
    if(string_values==undefined)
        document.write('<object type="application/x-shockwave-flash" data="'+src+'" width="'+w+'" height="'+h+'" wmode="transparent"><param name="movie" value="'+src+'" /><param name="wmode" value="transparent" /></object>');
    else
        document.write('<object type="application/x-shockwave-flash" data="'+src+'" width="'+w+'" height="'+h+'" wmode="transparent"><param name="movie" value="'+src+'" /><param name="wmode" value="transparent" /><param name="FlashVars" value="'+string_values+'" /></object>');
}

function in_array(needle, haystack, argStrict) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true

    var found = false, key, strict = !!argStrict;

    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }

    return found;
}


function strpos( haystack, needle, offset){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14

    var i = (haystack+'').indexOf( needle, offset );
    return i===-1 ? false : i;
}

function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}

function checkData (data) {
   dia = (data.substring(0,2));
   mes = (data.substring(3,5));
   ano = (data.substring(6,10));

   if ((dia < 1)||(dia < 1 || dia > 30) && (  mes == 4 || mes == 6 || mes == 9 || mes == 11 ) || dia > 31) {
      return false;
   }

   if (mes < 1 || mes > 12 ) {
      return false;
   }

   if (mes == 2 && ( dia < 1 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
      return false;
   }

   return true;

}

function str_replace(search, replace, subject) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'

    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;

    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };

    return sa ? s : s[0];
}

function validaCPF(param) {

    //str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');

	 cpf = str_replace(['-', '.'], '', param);
	 erro = new String;
	 if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n";
	 var nonNumbers = /\D/;
	 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";
	 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
			 erro += "Numero de CPF invalido!"
   }
   var a = [];
   var b = new Number;
   var c = 11;
   for (i=0; i<11; i++){
		   a[i] = cpf.charAt(i);
		   if (i < 9) b += (a[i] * --c);
   }
   if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
   b = 0;
   c = 11;
   for (y=0; y<10; y++) b += (a[y] * c--);
   if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
   if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		   erro +="CPF - Digito verificador com problema!";
   }
   if (erro.length > 0){
		   alert(erro);
		   return false;
   }
   return true;
}

function validaCnpj(CNPJ) {
   var erro = '';
   if(document.layers && parseInt(navigator.appVersion) == 4){
      x = CNPJ;
      CNPJ = x;
   } else {
      CNPJ = CNPJ. replace (".","");
      CNPJ = CNPJ. replace (".","");
      CNPJ = CNPJ. replace ("-","");
      CNPJ = CNPJ. replace ("/","");
   }
   var nonNumbers = /\D/;
   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])){
      erro +="Dígito verificador com problema!";
   }
   if (erro.length > 0){
      return false;
   }
   return true;
}

$(document).ready(function() {
   $('#seu_nome').example("Seu Nome");
   $('#seu_email').example("Seu E-mail");
   $('#amigo_nome').example("Nome da Pessoa");
   $('#amigo_email').example("E-mail da Pessoa");
   $('#login').example("Login");
   $('#user-cabecalho').example("Login");
   $('#senha-cabecalho').example("Senha");

   
   $('.bloco-titulo2').click(function(){
      $(this).next().toggle();
      if($(this).children('div').hasClass('abrir')){
         ret = $(this).children('div').attr('class').replace('abrir', 'fechar');
      } else{
         ret = $(this).children('div').attr('class').replace('fechar', 'abrir');
      }
      $(this).children('div').attr('class',ret);
   });

   $("#submit-informe").click(function(){
      if ($("#seu_nome").val() == '' || $("#seu_nome").val() == 'Seu Nome'){
         alert('Por favor informe seu nome');
         $("#seu_nome").focus();
      } else {
         if($("#seu_email").val() == '' || $("#seu_email").val() == 'Seu E-mail'){
            alert('Por favor informe seu email');
            $("#seu_email").focus();
         } else {
            if($("#amigo_nome").val() == '' || $("#amigo_nome").val() == 'Nome da Pessoa'){
               alert('Por favor informe o nome de seu amigo');
               $("#amigo_nome").focus();
            } else {
               if($("#amigo_email").val() == '' || $("#amigo_email").val() == 'E-mail da Pessoa'){
                  alert('Por favor informe o email de seu amigo');
                  $("#amigo_email").focus();
               } else {
                  $.ajax({
                     url:'indique.inc.php?seu_nome='+$("#seu_nome").val()+"&seu_email="+$("#seu_email").val()+"&amigo_nome="+$("#amigo_nome").val()+"&amigo_email="+$("#amigo_email").val(),
                     success: function(resultado){
                        if (trim(resultado) == '0') {
                           alert("E-mail enviado com sucesso!");
                           $('#seu_nome').val("Seu Nome");
                           $('#seu_email').val("Seu E-mail");
                           $('#amigo_nome').val("Nome da Pessoa");
                           $('#amigo_email').val("E-mail da Pessoa");
                        } else {
                           if (trim(resultado) == '1') {
                              alert('Problemas no envio do email!');
                           } else {
                              alert("Verifique o formato dos endere�os de e-mail");
                           }
                        }
                     }
                  });
               }
            }
         }
      }
   });

   /*
   $('.headlink').hover(
      function () {
         $(this).children('ul').slideDown("fast");
      },
      function () {
         $(this).children('ul').slideUp("fast");
      }
   );*/
   /*
   $('.headlink').each(function() {
      $(this).hover(
         function () {
            $(this).children('ul').slideDown("fast");
         },
         function () {
            $(this).children('ul').slideUp("fast");
         }
      );
   });
*/

});

function menuSlide(obj) {
   $(obj).hover(
      function () {
         $(obj).children('ul').slideDown("fast");
      },
      function () {
        $(obj).children('ul').slideUp("fast");
      }
   );
}
