var _8x6 = (screen.width < 900);

function setSize() {
	if(!_8x6) return;
document.getElementsByTagName('link')[0].href = 'index800x600.css';
var imgs = document.getElementsByTagName('img');
	for(var i in imgs)
		if(imgs[i].className == 'toscale') 
			imgs[i].src = imgs[i].src.replace(/imgs\//,'imgs/800x600/');
}

// subs
var ER = { 'bod': new RegExp('<\\/?body[^>]*>'), 
           'src': new RegExp(' src=\\"\\.\\.\\/imgs','ig'), 
					 'ftb': new RegExp('class=\\"fototab\\"') };
var wfunc = function(ret) { var msg = { 'uninitialized': 'Não iniciado', 'loading': 'Carregando...', 
						                            'loaded': 'Carregando...', 'interactive': 'Carregando...',
																				'complete': 'Houve algum problema no carregamento...' };
						$('alltd').innerHTML = msg[ret]; };
var lfunc = function(ret) { var arr = ret.split(ER.bod); if(!arr[1]) return;
                            var conts = arr[1].replace(ER.src,' src="/imgs');
                            $('alltd').innerHTML = conts;
														  if(ER.ftb.test(conts)) makeImgLinks(); 
														galleryno(); };
var _url = /localhost/.test(location.href) ? 
             'http://localhost/bocaina/': 'http://www.pousadabocaina.com.br/';

function makeImgLinks() {
setDragDrop('drag','photoboard');
var tabs = document.getElementsByTagName('table'), imgcnt = 0,
    tit = $('titlephoto'), divall = $('photoboard');
  for(var i in tabs) {
		if(tabs[i].className == 'fototab') {
		//var er = /cachoeira|caminho|bar/;
		var timgs = tabs[i].getElementsByTagName('img');
		  for(var j = 0; j < timgs.length; j++) {
			imgcnt++;
			  timgs[j].onclick = function() { 
				$('titlephoto').innerHTML = this.alt;
				$('imgtoshow').alt = this.alt;
				$('imgtoshow').src = this.src.replace(/thumbnails/,'images');
				var pb = $('photoboard');
				pb.style.display = '';
				var scrl = document.all ? document.documentElement.scrollTop : window.pageYOffset;
				  if(parseInt(pb.style.top) < scrl) pb.style.top = (scrl + 5)+'px';
				};
			}
		}
	}
}

function reqform(frm) { 
	if(check(frm)) {
	var ajx = new ajax();
	ajx.sendForm(frm,wfunc,lfunc);
	}
return false;
}

//function newRequest(txt) {
//var ajx = new ajax();
//ajx.sendLoad(txt+(txt == 'tarifas' ? '.php' : '.html'), wfunc, lfunc);
//ajaxHistory.add('$("'+txt+'").onclick()');
//$('hback').className = ajaxHistory.hasBack() ? 'discl' : 'disimg';
//$('hback').title = ajaxHistory.hasBack() ? 'Voltar' : '';
//$('hback').onclick = new Function(ajaxHistory.hasBack() ? 'ajaxHistory.go(-1)' : '');
//$('hfward').className = ajaxHistory.hasForward() ? 'discl' : 'disimg';
//$('hfward').title = ajaxHistory.hasForward() ? 'Avançar' : '';
//$('hfward').onclick = new Function(ajaxHistory.hasForward() ? 'ajaxHistory.go(1)' : '');
//}

function newRequest(txt) {
var ajx = new ajax();
ajx.sendLoad(txt+(txt == 'tarifas' ? '.php' : '.html'), wfunc, lfunc);
_ajax.history.add('$("'+txt+'").onclick()');
$('hback').className = _ajax.history.hasBack() ? 'discl' : 'disimg';
$('hback').title = _ajax.history.hasBack() ? 'Voltar' : '';
$('hback').onclick = new Function(_ajax.history.hasBack() ? '_ajax.history.go(-1)' : '');
$('hfward').className = _ajax.history.hasForward() ? 'discl' : 'disimg';
$('hfward').title = _ajax.history.hasForward() ? 'Avançar' : '';
$('hfward').onclick = new Function(_ajax.history.hasForward() ? '_ajax.history.go(1)' : '');
}

function maketabs() {
var tds = document.getElementsByTagName('td');
  for(var i in tds) {
	  if((tds[i].className || false) && /tabs/.test(tds[i].className)) {
 		removeClass(tds[i],'tabsel');
		removeClass(tds[i],'tabover');
			tds[i].onmouseover = function() { 
 			addClass(this, 'tabover');
			};
			tds[i].onmouseout = function() {
 			removeClass(this,'tabover');
			};
			tds[i].onclick = function() {
			  if(/tabsel/.test(this.className)) return false;
				if(this.id == 'inicio') { location.href = '..'; return false; }
			seltab(this);
			newRequest(this.id);
			setTimeout('rewidth()',150);
			};
		}
	}
}

function seltab(td) {
maketabs();
addClass(td,'tabsel');
//td.style.backgroundImage = 'url(../imgs/aba_sel.jpg)';
td.onmouseout = null;
td.onmouseover = null;
}

function setbgbar() {
var tds = document.getElementsByTagName('td');
  for(var i in tds) if(tds[i].className == 'bgbarra') 
	  tds[i].style.backgroundPosition = document.all ? 'top' : '0px';
}

function relogio(trgtid) {
var days = ["domingo", "segunda-feira", "ter&ccedil;a-feira", "quarta-feira",
						"quinta-feira", "sexta-feira", "s&aacute;bado"];
var months = ["janeiro", "fevereiro", "mar&ccedil;o", "abril", "maio", "junho", 
							"julho", "agosto", "setembro", "outubro", "novembro", "dezembro"];
var dat = new Date(), wday = dat.getDay(), mday = dat.getDate(), month = dat.getMonth(), year = dat.getFullYear();
$(trgtid).innerHTML = 'S&atilde;o Pedro da Serra - '+days[wday]+', '+mday+' de '+
                                             months[month]+' de '+year;
}

function setHeight() {
var theight = getBodyHeight() - (document.all ? 200 : 160);
theight = (theight > 0 ? theight : 0);
theight = (theight < 220 ? 220 : theight)+'px';
$('alltd').style.height = theight;
}

function rewidth() { 
var tab1 = $('stage');
var tab2 = $('alltab');
tab1.style.width = tab2.style.width = '100%';
var tab3 = (tab1.getElementsByTagName('table')[0] || false);
  if(tab3) tab3.style.width = '100%';
}

// index
function makemenu() {
menutds = getmenutds();
  for(var i in menutds) { 
		menutds[i].onmouseover = function() { /*sound('out');*/ addClass(this,'overitem'); };
		menutds[i].onmouseout = function() { removeClass(this,'overitem'); };
		menutds[i].onclick = function() { location.replace(location.href.replace(/\/?(index\.[a-z]+)?$/,'/')+(this.id == 'pousada' ? 'html' : 'html?'+this.id)); };
	}
}

function getmenutds() {
var tds = document.getElementsByTagName('td'), ret = {}, j = 0;
  for(var j in tds) if(/^item/.test(tds[j].className)) { ret[j] = tds[j]; j++; }
return ret;
}

// all

function getBodyHeight() {
  if(self.innerHeight)  return self.innerHeight; 
  else if(document.documentElement && document.documentElement.clientHeight) 
    return document.documentElement.clientHeight;
  else if (document.body)  return document.body.clientHeight;  
  else return 0;
}

// mostra ou esconde o elemento seguinte ao que foi clicado
function showHideNext(elem) {
objtoscroll = elem;
nex = elem.nextSibling;
  while(nex.nodeType != 1) nex = nex.nextSibling;
nex.style.display = nex.style.display == 'none' ? '' : 'none';
  if(nex.style.display != 'none') {
  elem.className += ' selitem';
  setTimeout('objtoscroll.scrollIntoView()',100);
  } else {
  elem.className = elem.className.replace(/ selitem/g, '');
  }
}

function getNextTag(elem) {
var nex = elem.nextSibling;
  while(nex.nodeType != 1) nex = nex.nextSibling;
return nex;
}

function getPreviousTag(elem) {
var prev = elem.previousSibling;
  while(prev.nodeType != 1) prev = prev.previousSibling;
return prev;
}

function removeClass(el, classn) {
  if (!(el && el.className)) return;
var cls = el.className.split(" ");
var ar = new Array();
  for (var i = cls.length; i > 0;) {
    if (cls[--i] != classn) {
      ar[ar.length] = cls[i];
    }
  }
el.className = ar.join(" ");
}

function addClass(el, classn) {
  removeClass(el, classn);
  el.className += ' '+classn;
}

function galleryno() {
	if(!document.all) return;
var imgs = document.getElementsByTagName('img');
  for(var i = 0; i < imgs.length; i++) { //alert(imgs[i].src);
	imgs[i].src = imgs[i].src.replace(/^[^\n]+bocaina\//g, _url);
	imgs[i].galleryimg = "no";
	}
}

function flashTag(id, src, wid, hei) { 
var widt = (wid ? 'width="'+wid+'" ' : ''), 
    heig = (hei ? 'height="'+hei+'" ' : ''),
    noloop = (flashTag.arguments[4]);
  if(navigator.appName == "Netscape") {
	var loop = noloop ? 'loop="false" ' : '';
	return '<embed src="'+src+'" quality="high" '+widt+heig+loop+
				 'type="application/x-shockwave-flash" name="'+id+'"></embed>';
	} else  {
	var loop = noloop ? '<param name="LOOP" value="false" />' : '';
	return '<object id="'+id+'" type="application/x-shockwave-flash" data="'+src+'" '+
				 (wid ? 'width="'+wid+'" ' : '')+(hei ? 'height="'+hei+'" ' : '')+'>'+
				 '<param name="movie" value="'+src+'" />'+loop+'</object>';
	}
}

function check(frm) {
var frms = { 'reservas': {'nome': 'Preencha o seu nome',
												 'telefone': 'Informe um telefone de contato',
												 'email': 'Informe o seu e-mail',
												 'periodo_de': 'A partir de que dia pretende se hospedar?',
												 'periodo_ate': 'Até que dia pretende ficar?',
												 'periodo_mes': 'Informe o mês...',
												 'quantos': 'A reserva é para quantas pessoas?' },
             'mensagem': {'name': 'Preencha o seu nome',
						              'email': 'Informe o seu e-mail',
													'subject': 'Dê um título para a mensagem',
													'content': 'Você não digitou nada!'} };

  for(var i = 0; i < frm.elements.length; i++) { //alert(frm.name);
		if(/\w/.test(frm.elements[i].name) && (frms[frm.id][frm.elements[i].name] || false)) {
			if(/^\s*$/.test(frm.elements[i].value)) {
			alert(frms[frm.id][frm.elements[i].name]);
			frm.elements[i].focus();
			return false;
			} else if((frms[frm.id][frm.elements[i].name] || false)) {
				if(/mail/.test(frm.elements[i].name) && 
					 !(/^[\w-\.]{2,}@[\w-\.]{2,}\.[a-z]{2,4}$/.test(frm.elements[i].value))) {
				alert('Isso não parece um endereço de e-mail válido...');
				frm.elements[i].focus();
				frm.elements[i].select();
				return false;
				}
				else if(/fone/.test(frm.elements[i].name) && 
					 !(/^\s*\(?\d[\d\-\(\)\s]{7,20}$/.test(frm.elements[i].value))) {
				alert('Isso não parece um número de telefone...');
				frm.elements[i].focus();
				frm.elements[i].select();
				return false;
				}
			}
		}
	}
return true;
}

function $(id,doc) { return (doc || document).getElementById(id); }
