/*
 * 	MoFuse Premium API
 *	Mobile Detect & Redirect
*/
var mfp_url='http://www.hotelfarol.com.br/mobile.aspx';
var mfp_host_name=document.location.hostname;
var mfp_request_uri=document.location.pathname;
var mfp_no_mobile=location.search;
var mfp_cookie=document.cookie;

function DetectMobile(){
var mfp_ua=navigator.userAgent.toLowerCase();
var mfp_devices=['vnd.wap.xhtml+xml','sony','symbian','nokia','samsung','mobile','windows ce','epoc','opera mini','nitro','j2me','midp-','cldc-','netfront','mot','up.browser','up.link','audiovox','blackberry','ericsson','panasonic','philips','sanyo','sharp','sie-','portalmmm','blazer','avantgo','danger','palm','series60','palmsource','pocketpc','smartphone','rover','ipaq','au-mic','alcatel','ericy','vodafone','wap1','wap2','teleca','playstation','lge','lg-','iphone','android','htc','dream','webos','bolt','nintendo'];
for(var i in mfp_devices){
if(mfp_ua.indexOf(mfp_devices[i])!=-1){
return true}}}
if(mfp_no_mobile!='?nomobile=1'&&mfp_cookie.indexOf('mfp_no_mobile')==-1){mfp_is_mobile=DetectMobile();
if(mfp_is_mobile){window.location=mfp_url+"?mobile="+mfp_host_name+"&mobilew="+mfp_request_uri}}
else{if(mfp_cookie.indexOf('mfp_no_mobile')!=-1){}
else{mfp_cookie_expires=new Date();
mfp_cookie_expires.setTime(mfp_cookie_expires.getTime()+1000*60*60*24);document.cookie="mfp_no_mobile=1; expires="+mfp_cookie_expires.toGMTString()+"; path=/;"}}



function DcetectMobile()
{   
var agent = navigator.userAgent;
var isIphone = (agent.indexOf('iPhone') != -1);
var isSymbian = (agent.indexOf('Symbian') != -1);

if (isIphone) { 
    window.location = 'http://www.hotelfarol.com.br/apple/iphone.aspx';
}
else if(screen.width <=400){
    window.location ='http://www.hotelfarol.com.br/camera/mobile.aspx?mobile='+agent;
    }
}

function OnloadIphone()
{
window.scrollTo(0,1); //Best called from the onload event
}
function formatar(src, mask) 
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
 
if (texto.substring(0,1) != saida) 
  {
	src.value += texto.substring(0,1);
  }  
src.value = src.value.toUpperCase();
}
// Permite apenas número no campo
// onKeyPress="return checkIt(event)"
function checkIt(evt) {
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode

	if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 44 ) {
		alert ("Por favor\nUtilize apenas números")
		return false
	}
	return true
}

var show = 'S';
var hide = 'H';


function abreMapaG(theID, action) {
	document.all.google_maps.style.display = 'block';
	document.all.mapa_antigo.style.display = 'none';
}

function abreMapaA(theID, action) {
	document.all.mapa_antigo.style.display = 'block';
	document.all.google_maps.style.display = 'none';
}

function abreJANELA(url,parametro) {
   JANELA = window.open(url,'JANELA',parametro);
}

function ResizeColunas()
	{
		var intConteudo = document.all.tblConteudo.scrollHeight;
		
		//alert(intConteudo);

		document.all.tdDireita.height = intConteudo;	
		document.all.tdEsquerda.height = intConteudo;	
	}

function popdate(obj,div,tam,ddd)
{
   if (ddd) 
   {
       day = ""
       mmonth = ""
       ano = ""
       c = 1
       char = ""
       for (s=0;s<parseInt(ddd.length);s++)
       {
           char = ddd.substr(s,1)
           if (char == "/") 
           {
               c++; 
               s++; 
               char = ddd.substr(s,1);
           }
           if (c==1) day    += char
           if (c==2) mmonth += char
           if (c==3) ano    += char
       }
       //ddd = mmonth + "/" + day + "/" + ano
	   ddd = ano + "/" + mmonth + "/"  + day   
   }
 
   if(!ddd) {today = new Date()} else {today = new Date(ddd)}
   date_Form = eval (obj)
   if (date_Form.value == "") { date_Form = new Date()} else {date_Form = new Date(date_Form.value)}
 
   ano = today.getFullYear();
   mmonth = today.getMonth ();
   day = today.toString ().substr (8,2)
 
   umonth = new Array ('Janeiro', 'Fevereiro','Marco','Abri','Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
   days_Feb = (!(ano % 4) ? 29 : 28)
   days = new Array (31, days_Feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

   if ((mmonth < 0) || (mmonth > 11))  alert(mmonth)
   if ((mmonth - 1) == -1) {month_prior = 11; year_prior = ano - 1} else {month_prior = mmonth - 1; year_prior = ano}
   if ((mmonth + 1) == 12) {month_next  = 0;  year_next  = ano + 1} else {month_next  = mmonth + 1; year_next  = ano}
   txt  = "<table bgcolor='#336699' style='border:solid #336699; border-width:2' cellspacing='0' cellpadding='3' border='0' width='"+tam+"' height='"+tam*1.1 +"'>"
   txt += "<tr bgcolor='#FFFFFF'><td colspan='7' align='center'><table border='0' cellpadding='0' width='100%' bgcolor='#FFFFFF'><tr>"
   txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano-1).toString())+"') class='Cabecalho_Calendario' title='Ano Anterior'><<</a></td>"
   txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_prior+1).toString() + "/" + year_prior.toString())+"') class='Cabecalho_Calendario' title='Mês Anterior'><</a></td>"
   txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_next+1).toString()  + "/" + year_next.toString())+"') class='Cabecalho_Calendario' title='Próximo Mês'>></a></td>"
   txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano+1).toString())+"') class='Cabecalho_Calendario' title='Próximo Ano'>>></a></td>"
   txt += "<td width=20% align=right><a href=javascript:force_close('"+div+"') class='Cabecalho_Calendario' title='Fechar Calendário'><b>X</b></a></td></tr></table></td></tr>"
   txt += "<tr><td colspan='7' align='right' bgcolor='#003366' class='mes1'><a href=javascript:pop_year('"+obj+"','"+div+"','"+tam+"','" + (mmonth+1) + "') class='mes1'>" + ano.toString() + "</a>"
   txt += " <a href=javascript:pop_month('"+obj+"','"+div+"','"+tam+"','" + ano + "') class='mes1'>" + umonth[mmonth] + "</a> <div id='popd' style='position:absolute'></div></td></tr>"
   txt += "<tr bgcolor='#336699'><td width='14%' class='dia' align=center><b>Dom</b></td><td width='14%' class='dia' align=center><b>Seg</b></td><td width='14%' class='dia' align=center><b>Ter</b></td><td width='14%' class='dia' align=center><b>Qua</b></td><td width='14%' class='dia' align=center><b>Qui</b></td><td width='14%' class='dia' align=center><b>Sex<b></td><td width='14%' class='dia' align=center><b>Sab</b></td></tr>"
   today1 = new Date((mmonth+1).toString() +"/01/"+ano.toString());
   diainicio = today1.getDay () + 1;
   week = d = 1
   start = false;

   for (n=1;n<= 42;n++) 
   {
       if (week == 1)  txt += "<tr bgcolor='#336699' align=center>"
       if (week==diainicio) {start = true}
       if (d > days[mmonth]) {start=false}
       if (start) 
       {
           dat = new Date((mmonth+1).toString() + "/" + d + "/" + ano.toString())
           day_dat   = dat.toString().substr(0,10)
           day_today  = date_Form.toString().substr(0,10)
           year_dat  = dat.getFullYear ()
           year_today = date_Form.getFullYear ()
           colorcell = ((day_dat == day_today) && (year_dat == year_today) ? " bgcolor='#FFCC00' " : "" )
					 mesp = mmonth+1;
					 if (mesp<10){
					 mes_sh = '0' + mesp
					 }else{
					 mes_sh = mesp
					 }
					 
					 if(d<10){
					 	d = '0' + d;
					 }
					 
           txt += "<td"+colorcell+" align=center><a href=javascript:block('"+ d + "/" + (mes_sh).toString() + "/" + ano.toString() +"','"+ obj +"','" + div +"') class='data'>"+ d.toString() + "</a></td>"
           d ++ 
       } 
       else 
       { 
           txt += "<td class='data' align=center> </td>"
       }
       week ++
       if (week == 8) 
       { 
           week = 1; txt += "</tr>"} 
       }
       txt += "</table>"
       div2 = eval (div)
       div2.innerHTML = txt 
	   
}
 
// função para exibir a janela com os meses
function pop_month(obj, div, tam, ano)
{
 txt  = "<table bgcolor='#336699' border='0' width=80>"
 for (n = 0; n < 12; n++) { txt += "<tr><td align=center><font size=1 face=verdana color=#FFFFF><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+("01/" + (n+1).toString() + "/" + ano.toString())+"') style='color:#ffffff; text-decoration:none;'>" + umonth[n] +"</a></td></tr>" }
 txt += "</table>"
 popd.innerHTML = txt
}

// função para exibir a janela com os anos
function pop_year(obj, div, tam, umonth)
{
 txt  = "<table bgcolor='#336699' border='0' width=160>"
 l = 1
 for (n=1991; n<2012; n++)
 {  if (l == 1) txt += "<tr>"
    txt += "<td align=center><font size=1 face=verdana color=#FFFFF><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+(umonth.toString () +"/01/" + n) +"') style='color:#ffffff; text-decoration:none;'>" + n + "</a></font></td>"
    l++
    if (l == 4) 
       {txt += "</tr>"; l = 1 } 
 }
 txt += "</tr></table>"
 popd.innerHTML = txt 
}

// função para fechar o calendário
function force_close(div) 
   { //div2 = eval (div); div2.innerHTML = ''
	   new Effect.SlideUp(div)
   }
   
// função para fechar o calendário e setar a data no campo de data associado
function block(data, obj, div)
{ 
   force_close (div)
   obj2 = eval(obj)
   obj2.value = data 
   
}
function showPic (whichpic) { 
	if (document.getElementById) { 
		document.getElementById('placeholder').src = whichpic.href; 
		initImage();
		return false; 
	} else { 
		return true; 
	} 
}

function initImage() {
	imageId = 'placeholder';
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	fadeIn(imageId,0);
}

function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 5;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 30);
		}
	}
}
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

            
function popup(){
	var pop = window.open("about:blank","_blank","width=10,height=100,top=0,left=0");
	if (pop == null || pop.closed == true){
		h = 1;
		$.prompt('ATENÇÃO! Seu bloqueador de pop-up está ativado! Para a visualização do conteúdo desta página, é necessário desbloqueá-lo.');
	}
	else {
		h = 0;
		pop.close();
	}
	
   var width = 500;
   var height = 600;
 
   var left = 99;
   var top = 99;
 
URL = "http://www.hotelfarol.com.br/regulamentoreserva.aspx";
 
   window.open(URL,'Regulamento', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}


 function validarCPF(src){
   var cpf = src.value;
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if(!filtro.test(cpf)){
     window.alert("CPF inválido. Tente novamente.");
	  src.focus();
	  src.value="";
	  	  return false;
   }
   
   cpf =cpf.replace(".", "");
   cpf =cpf.replace(".", "");
   cpf = cpf.replace("-", "");
    
   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999"){
	  window.alert("CPF inválido. Tente novamente.");
	  src.focus();
	  src.value="";
	  	  return false;

   }

   soma = 0;
   for(i = 0; i < 9; i++)
   	 soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(9))){
	 window.alert("CPF inválido. Tente novamente.");
	  src.focus();
	  src.value="";
	  	  return false;
   }
   soma = 0;
   for(i = 0; i < 10; i ++)
	 soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(10))){
     alert("CPF inválido. Tente novamente.");
	  src.focus();
	  src.value="";
	  	  return false;
   }
   return true;
 }
 
 function validaCNPJ(src) {
                 CNPJ = src.value;
                 erro = new String
             if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! \n\n"; 
                 if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
                 if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
                 }
                 //substituir os caracteres que não são números
               if(document.layers && parseInt(navigator.appVersion) == 4){
                       x = CNPJ.substring(0,2);
                       x += CNPJ. substring (3,6);
                       x += CNPJ. substring (7,10);
                       x += CNPJ. substring (11,15);
                       x += CNPJ. substring (16,18);
                       CNPJ = x; 
               } else {
                       CNPJ = CNPJ. replace (".","");
                       CNPJ = CNPJ. replace (".","");
                       CNPJ = CNPJ. replace ("-","");
                       CNPJ = CNPJ. replace ("/","");
               }
               var nonNumbers = /\D/;
               if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n"; 
               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){
                       alert(erro);
                       src.focus();
                       src.value="";
                       return false;
               } 
               return true;
       }

