function addJQuery(){	
	var e = document.createElement('script');  
	e.src = '/js/jquery.js';
	e.type='text/javascript';
	document.getElementsByTagName("head")[0].appendChild(e);
}

if (typeof jQuery === 'undefined') {  
	addJQuery();
}

function addJS(url){
	var e = document.createElement('script');  
	e.src = url;
	e.type='text/javascript';
	document.getElementsByTagName("head")[0].appendChild(e);
}

function addCSS(url){
	var e = document.createElement('link');  
	e.href = url;
	e.rel = 'stylesheet';
	e.type='text/css';
	document.getElementsByTagName("head")[0].appendChild(e);
}

function addSubFaixa(src){
	$('body').prepend('<div id="subfaixa" style="width:100%;">' + src + '</div>');
}

// logo mouseOver home
$(document).ready(function(){
	if(menu == 0){			 
		$('#logo-imagem').hover(function () {
			this.src = '/img/logo_siciliano_home.png';
		}, function () {
			this.src = '/img/logo_siciliano.png';
		});
	}
	if($(".mensagem").html() == "<br>" | $(".mensagem").html() == ""){
		$(".mensagem").hide();		
	}
	addJS('/js/subfaixa.js');
});

// verifica data fornecida
function CheckDate(sDate) {
 var iDD, iMM, iAAAA, iMaxDD, bBissexto;
 
 if (sDate.length < 10) {
  //window.alert('Informe a data no formato "dd/mm/aaaa".');
  return false;
 }
 
 iDD = sDate.substr(0, 2);
 iMM = sDate.substr(3, 2);
 iAAAA = sDate.substr(6, 4);
 
 if ((isNaN(iDD)) || (isNaN(iMM)) || (isNaN(iAAAA))) {
  //window.alert('Forneça apenas números na data.');
  return false;
 } 
 
 bBissexto = false;
 
 if (((iAAAA % 4) == 0) && (((iAAAA % 100) != 0) || ((iAAAA % 400) == 0))) {
  bBissexto = true;
 }

 switch (iMM) {
  case "01":
  case "03":
  case "05":
  case "07":
  case "08":
  case "10":
  case "12":
   iMaxDD = 31;
   break;
   
  case "04":
  case "06":
  case "09":
  case "11":
   iMaxDD = 30;
   break;
   
  case "02":
   if (bBissexto) {
    iMaxDD = 29;
   }
   else {
    iMaxDD = 28;
   }
   
   break;
   
  default:
   //window.alert('O mês fornecido não é válido.');
   return false;
 }

 if ((iDD < 0) || (iDD > iMaxDD)) {
  //window.alert('O dia fornecido não é válido.');
  return false;
 }

 return true;  
}

// verifica hora fornecida
function CheckTime(sTime) {
 var iHH, iMM;
 
 if (sTime.length < 5) {
  //window.alert('Informe a hora no formato "hh:mm".');
  return false;
 }
 
 iHH = sTime.substr(0, 2);
 iMM = sTime.substr(3, 2);
 
 if ((isNaN(iHH)) || (isNaN(iMM))) {
  //window.alert('Forneça apenas números na hora.');
  return false;
 } 
 
 if ((iHH < 0) || (iHH > 23)) {
  //window.alert('A hora fornecida não é válida.');
  return false;
 }

 if ((iMM < 0) || (iMM > 59)) {
  //window.alert('O minuto fornecido não é válido.');
  return false;
 }

 return true;
}

// permite apenas digitacao de numeros
// deve ser usado no evento do input
function NumberOnly(Obj) {
 var data = new String(Obj.value);
 var dataok = '';
 var cont = 0;

 
 for (i = 0; i < data.length; i++) {
  if ((data.charAt(i) >= '0') && (data.charAt(i) <= '9')) {
   dataok += data.charAt(i);
  }
  else cont++;
 }
	
 if (cont > 0) {  
  Obj.value = dataok;
 }
}

// verifica o formato de um endereco de e-mail
function CheckMail(sMail) {
 sValido = "abcdefghijklmnopqrstuvwxyz1234567890@-_.";
 
 if (sMail == "") return false;
 
 if ((sMail.substr(0, 1) == "@") || (sMail.substr(0, 1) == ".")) return false;
 
 // checa arrobas e caracteres
 sMail = sMail.toLowerCase();
 
 iAux1 = 0;
 iAux2 = 0;
 
 for (iAux1 = 0; iAux1 < sMail.length; iAux1 ++) {
  if (sMail.substr(iAux1, 1) == "@") iAux2++;
  
  if (sValido.indexOf(sMail.substr(iAux1, 1)) < 0) iAux2 = 10;
 }
 
 if (iAux2 != 1) return false;
 
 // checa dominio
 sAux = sMail.substr(sMail.indexOf("@") + 1, sMail.length);
 
 if (sAux == "") return false;
 
 if (sAux.indexOf(".") < 0) return false;
 
 if (sAux.indexOf("..") >= 0) return false;
 
 if (sAux.substr(0, 1) == ".") return false;
 
 if (sAux.substr(sAux.length - 1, 1) == ".") return false;
 
 return true;
}

function trim(str){
   result = "";
   for(i=0;i < str.length;i++){
      if(str.substr(i,1) != " "){
         result = result + str.substr(i,1);

      }
   }
   return result;
}

function Avise(sPRO_Id) {
  window.open("/buscaproduto/buscaproduto.dll?pg=avise.htm&pro_id=" + sPRO_Id, "avise", "width=420,height=350,top=20");
}

function limpa_string(S) {
 // Deixa so' os digitos no numero
 var Digitos = "0123456789";
 var temp = "";
 var digito = "";

 for (var j = 0; j < S.length; j++)	{
  digito = S.charAt(j);
  
  if (Digitos.indexOf(digito) >= 0) {
   temp = temp + digito
  }
 } //for

 return temp
}

function valida_CPF(s)	{
   var i;
   s = limpa_string(s);
   var c = s.substr(0,9);
   var dv = s.substr(9,2);
   var d1 = 0;
   for (i = 0; i < 9; i++)
   {
      d1 += c.charAt(i)*(10-i);
   }
        if (d1 == 0) return false;
   d1 = 11 - (d1 % 11);
   if (d1 > 9) d1 = 0;
   if (dv.charAt(0) != d1)
   {
      return false;
   }

   d1 *= 2;
   for (i = 0; i < 9; i++)
   {
      d1 += c.charAt(i)*(11-i);
   }
   d1 = 11 - (d1 % 11);
   if (d1 > 9) d1 = 0;
   if (dv.charAt(1) != d1)
   {
      return false;
   }
   return true;
}

function valida_CGC(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
	return true;
}

<!-- ABRIR POPUP DIRETAMENTE AO ACESSAR A PÀGINA PRINCIPAL !-->


function Link() {
 opener.window.location='<#link_banner>';
 self.close();
}

/* Chama SWF e tira barra de ativação do IE */

function addSWF(URL, WIDTH, HEIGHT, TRANSPARENT) {
 document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '); 
 document.write('width="'+ WIDTH +'" height="'+ HEIGHT +'">');
 document.write(' <param name="movie" value="'+ URL +'">');
 document.write(' <param name="quality" value="high">');

 if ( TRANSPARENT ) {
  document.write(' <param name="Wmode" value="transparent">'); 
 }

 document.write(' <embed src="'+ URL +'" quality="high" ');

 if ( TRANSPARENT ) {
  document.write('Wmode = "transparent" ');
 }

 document.write ('type="application/x-shockwave-flash" width="'+ WIDTH +'" height="'+ HEIGHT +'"></embed> ');
 document.write ('</object>');
}

/* chama POPUP link(url),largura(int),altura(int),scrollbars(yes/no),name(string) */

function popup(url,width,height,scrollbars,name) {

centerLeft = (screen.width) ? (screen.width - width) / 2 : 0;
centertop = (screen.height) ? (screen.height - height) / 2 : 0;

if(scrollbars == undefined){
	scrollbars = "no";
}

if(name == undefined){
	name = "popup";
}

specs = "width=" + width + ",height=" + height + ",left=" + centerLeft + ",top=" + centertop +  ",scrollbars=" + scrollbars + ",location=no,menubar=no,resizable=no,status=no,titlebar=no,toolbar=no";

window.open(url,name,specs);

}

/* chama POPUP da Faixa */ 

function popupFaixa(url){
	width = 403;
	height = 503;
	popup(url,width,height,"yes");
}
/* Parâmetros na url */
function getUrlVars() {
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for(var i = 0; i < hashes.length; i++) {
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
  }
  return vars;
}

var hash = getUrlVars();
function esconderMenuPesquisa(){    
	$(document).ready( function () {
		$("#barraLateral-esquerda").hide();
		$("#conteudo-pesquisa").css("width","100%");
	});
}

// SICILIANO MODAL
var SicilianoModalWindow = {
	parent:'body',
	windowId:null,
	content:null,
	width:null,
	height:null,
	close:function()
	{		
		sicilianoModalFechar();
	},
	open:function()
	{
		var modal = '';
		modal += '<div class="siciliano-modal-overlay" style="display:none;"></div>';
		modal += '<div id="' + this.windowId + '" class="siciliano-modal-window" style="width:' + this.width + 'px; height:' + this.height + 'px; margin-top:-' + (this.height / 2) + 'px; margin-left:-' + (this.width / 2) + 'px; display:none;">';
		modal += this.content;
		modal += '</div>';	
		$(this.parent).append(modal);
		$('.siciliano-modal-window').append('<a class="siciliano-close-window"></a>');
		$('.siciliano-close-window').click(function(){SicilianoModalWindow.close();});
		$('.siciliano-modal-overlay').click(function(){SicilianoModalWindow.close();});
		// Animando entrada
		$('.siciliano-modal-overlay').fadeIn('fast',function(){$('.siciliano-modal-window').fadeIn('fast');});
	}
};

function sicilianoModalFechar(){
	// Animando entrada
	$('.siciliano-modal-window').fadeOut('fast',function(){
		$('.siciliano-modal-overlay').fadeOut('fast', function(){
			$('.siciliano-modal-window').remove();
			$('.siciliano-modal-overlay').remove();
		});
	});	
}

function sicilianoModal(source,width,height){
	SicilianoModalWindow.windowId = 'sicilianoModal';
	SicilianoModalWindow.width = width;
	SicilianoModalWindow.height = height;
	if(source.search("^#") != -1){
		SicilianoModalWindow.content = $(source).html();
	} else {
		SicilianoModalWindow.content = '<iframe width="' + width + '" height="' + height + '" frameborder="0" src="' + source + '"></iframe>';
	}
	SicilianoModalWindow.open();	
};

function saraivaModalGarntiaEstendida(a){
	var h1 = 560;	
	var h2 = 420;	
	if(a == 'up'){
		$('.siciliano-modal-window').animate({
			height:h1,
			'margin-top':'-320px'
		});
		$('#sicilianoModal iframe').animate({
			height:h1-5								
		});		
	}else{
		$('.siciliano-modal-window').animate({
			height:h2,
			'margin-top':'-197.5px'			
		});
		$('#sicilianoModal iframe').animate({
			height:h2							
		});
	}	
}

function radioBoxGarantia(){
	// INÍCIO: iniciar checado
	$('#ge-0').attr('checked','true');	
	//$('.corpo_termo').fadeOut();
	$('.pesquisa-item-icone').eq(0).addClass('selecionado');	
	$('.termos-condicoes').fadeOut();	
	parent.saraivaModalGarntiaEstendida('down');
	$('.aceitar').fadeOut();
	// FIM: iniciar checado
	$('.pesquisa-item-icone').click(function(){
		var cb = $($(this).children('.plano-garantia-txt').next()).children();
		$('.pesquisa-item-icone').removeClass('selecionado');
		$(this).addClass('selecionado');
		cb.attr('checked','true');
			if(cb.attr('id') != 'ge-0' ){			
				$('.termos-condicoes').fadeIn();
				parent.saraivaModalGarntiaEstendida('up');
				$('.continuar').fadeOut();								
				//$('.corpo_termo').fadeIn();
				$('.aceitar').fadeIn();	
			}else{
				$('.termos-condicoes').fadeOut();
				parent.saraivaModalGarntiaEstendida('down');
				$('.continuar').fadeIn();
				//$('.corpo_termo').fadeOut();
				$('.aceitar').fadeOut();
			}
	});	
}

// getCookie

function getCookieVal(offset) {
 var endstr = document.cookie.indexOf(";", offset);  
 if (endstr == -1) {endstr = document.cookie.length;}  
 return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name) {
 var arg = name + "=";
 var alen = arg.length;
 var clen = document.cookie.length;
 var i = 0; 
 while (i < clen) {
  var j = i + alen;
  if (document.cookie.substring(i, j) == arg) {return getCookieVal(j);}  
  i = document.cookie.indexOf(" ", i) + 1;  
  if (i == 0) {break;}
  } 
 return null;
}
