/*******
Ressalva
http://www.ressalva.com.sapo.pt
*******/

function AbrirPag(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,height=315px,width=315px,left = 99,top = 200");
}


function AdFavoritos(){
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		var url="http://www.ressalva.com.sapo.pt";
		var title="Pag. Pessoal Ressalva. De tudo um pouco.";
		document.write('<A HREF="javascript:window.ext');
		document.write('ernal.AddFavorite(url,title);" ');
		document.write('onMouseOver=" window.status=');
		document.write("'Adicione o meu site aos seus favoritos!'; return true ");
		document.write('"onMouseOut=" window.status=');
		document.write("' '; return true ");
		document.write('">Adicionar este site aos seus Favoritos!</a>');
	}
	else {
		var msg = "N&atilde;o te esque&ccedil;as de c&aacute; voltar!";
		if(navigator.appName == "Netscape") msg += " (CTRL-D)";
		document.write(msg);
	}

}

function showdate() {

// Get today's current date.
var now = new Date();

// Array list of days.
var days = new Array('Domingo','Segunda','Ter&ccedil;a','Quarta','Quinta','Sexta','S&aacute;bado');

// Array list of months.
var months = new Array('Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number)	{
	return (number < 1000) ? number + 1900 : number;
								}

// Join it all together
today =  days[now.getDay()] + ", " +
         date + " de " +
         months[now.getMonth()] + " de " +
         (fourdigits(now.getYear())) ;

// Print out the data.
document.write(today);
}

function searchWeb() {
if (document.search.engines.selectedIndex==0) { window.location.href="http://www.aeiou.pt/pesquisa/?p="+document.search.queryText.value.replace(" ","+"); }
if (document.search.engines.selectedIndex==1) { window.location.href="http://www.alltheweb.com/search?cat=web&cs=utf-8&l=any&q="+document.search.queryText.value.replace(" ","+"); }
if (document.search.engines.selectedIndex==2) { window.location.href="http://altavista.com/web/results?pg=q&what=web&fmt=.&q="+document.search.queryText.value.replace(" ","+"); }
if (document.search.engines.selectedIndex==3) { window.location.href="http://www.ask.com/main/askjeeves.asp?x=22&y=13&ask="+document.search.queryText.value.replace(" ","+"); }
if (document.search.engines.selectedIndex==4) { window.location.href="http://www.business.com/search/rslt_default.asp?query="+document.search.queryText.value.replace(" ","+"); }
if (document.search.engines.selectedIndex==5) { window.location.href="http://www.google.pt/search?btnG=Google+Search&q="+document.search.queryText.value.replace(" ","+"); }
if (document.search.engines.selectedIndex==6) { window.location.href="http://www.mamma.com/Mamma?lang=1&timeout=4&query="+document.search.queryText.value.replace(" ","+"); }
if (document.search.engines.selectedIndex==7) { window.location.href="http://search.metacrawler.com/texis/search?brand=metacrawler&q="+document.search.queryText.value.replace(" ","+"); }
if (document.search.engines.selectedIndex==8) { window.location.href="http://search.msn.co.uk/results.asp?co=20&RS=CHECKED&FORM=SMCB&ba=0&v=1&CY=en-gb&q="+document.search.queryText.value.replace(" ","+"); }
if (document.search.engines.selectedIndex==9) { window.location.href="http://pesquisa.sapo.pt/search/HP?enc=utf-8&barra=resumo&t=0&q="+document.search.queryText.value.replace(" ","+"); }
if (document.search.engines.selectedIndex==10) { window.location.href="http://search.yahoo.com/search?p="+document.search.queryText.value.replace(" ","+"); }
}

function BanMiniPos1() {
var how_many_ads = 5;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
if (ad==1) {
url="http://amigos.com/go/g851538";
banner="http://ressalva.com.sapo.pt/banners/amigos.gif";
width="120";
height="29";
}
if (ad==2) {
url="http://fun-clover.com";
banner="http://www.fun-clover.com/banners/fun-cloverbanner120x60.gif";
width="120";
height="60";
}
if (ad==3) {
url="http://www.lingerie-sensual.com/?af=264";
banner="http://ressalva.com.sapo.pt/banners/lingerielogo.jpg";
width="120";
height="35";
}
if (ad==4) {
url="http://www.chip7afiliados.com/b.asp?id=2905";
banner="http://ressalva.com.sapo.pt/banners/chip7logo.jpg";
width="120";
height="60";
}
if (ad==5) {
url="http://action.metaffiliation.com/suivi.php?mclic=S3D1348588116";
banner="http://action.metaffiliation.com/suivi.php?maff=S3D1348588116";
width="120";
height="60";
}
document.write('<center>');
document.write('<a target="_top" href=\"' + url + '\" target=\"_top\">');
document.write('<img border="0" src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' >');
document.write('</a>');
document.write('</center>');
}

function BanMiniPos2() {
var how_many_ads = 5;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
if (ad==5) {
url="http://amigos.com/go/g851538";
banner="http://ressalva.com.sapo.pt/banners/amigos.gif";
width="120";
height="29";
}
if (ad==1) {
url="http://fun-clover.com";
banner="http://www.fun-clover.com/banners/fun-cloverbanner120x60.gif";
width="120";
height="60";
}
if (ad==2) {
url="http://www.lingerie-sensual.com/?af=264";
banner="http://ressalva.com.sapo.pt/banners/lingerielogo.jpg";
width="120";
height="35";
}
if (ad==3) {
url="http://www.chip7afiliados.com/b.asp?id=2905";
banner="http://ressalva.com.sapo.pt/banners/chip7logo.jpg";
width="120";
height="60";
}
if (ad==4) {
url="http://action.metaffiliation.com/suivi.php?mclic=S3D1348588116";
banner="http://action.metaffiliation.com/suivi.php?maff=S3D1348588116";
width="120";
height="60";
}
document.write('<center>');
document.write('<a target="_top" href=\"' + url + '\" target=\"_top\">');
document.write('<img border="0" src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' >');
document.write('</a>');
document.write('</center>');
}

function BanMiniPos3() {
var how_many_ads = 5;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
if (ad==4) {
url="http://amigos.com/go/g851538";
banner="http://ressalva.com.sapo.pt/banners/amigos.gif";
width="120";
height="29";
}
if (ad==5) {
url="http://fun-clover.com";
banner="http://www.fun-clover.com/banners/fun-cloverbanner120x60.gif";
width="120";
height="60";
}
if (ad==1) {
url="http://www.lingerie-sensual.com/?af=264";
banner="http://ressalva.com.sapo.pt/banners/lingerielogo.jpg";
width="120";
height="35";
}
if (ad==2) {
url="http://www.chip7afiliados.com/b.asp?id=2905";
banner="http://ressalva.com.sapo.pt/banners/chip7logo.jpg";
width="120";
height="60";
}
if (ad==3) {
url="http://action.metaffiliation.com/suivi.php?mclic=S3D1348588116";
banner="http://action.metaffiliation.com/suivi.php?maff=S3D1348588116";
width="120";
height="60";
}
document.write('<center>');
document.write('<a target="_top" href=\"' + url + '\" target=\"_top\">');
document.write('<img border="0" src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' >');
document.write('</a>');
document.write('</center>');
}

//------------------------------\\

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;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (2 < argc) ? argv[2] : null;
  var path = (3 < argc) ? argv[3] : null;
  var domain = (4 < argc) ? argv[4] : null;
  var secure = (5 < argc) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
   ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
   ((path == null) ? "" : ("; path=" + path)) +
   ((domain == null) ? "" : ("; domain=" + domain)) +
   ((secure == true) ? "; secure" : "");
}



function DisplayInfo() {
  var expdate = new Date();
  var visit;
  expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365));
  if(!(visit = GetCookie("visit")))
  visit = 0;
  visit++;
  SetCookie("visit", visit, expdate, "/", null, false);
  var message;
  if(visit == 1)
	  message="Ben-vindo ao Ressalva!";
  if(visit== 2)
	  message="Ben-vindo novamente ao Ressalva!";
  if(visit == 3)
	  message="Adiciona-me aos teus Favoritos para que voltes sempre.";
  if(visit == 4)
	  message="Tenho aqui muitas coisas que podes fazer!";
  if(visit == 5)
	  message="Envia-me um email para que eu possa melhorar.";
  if(visit == 6)
	  message="Ainda com cenas? Faz como estivesses em casa.";
  if(visit == 7)
	  message="Faz de mim a tua Homepage.";
  if(visit == 8)
	  message="Achas que falta algum link interessante? Diz-me por email.";
  if(visit == 9)
	  message="Podes falar de mim aos teus amigos.";
  if(visit >= 10)
 	  message=fraseAl();
  if(visit == 100)
	  message="Obrigado por me escolheres e os parabens de 100 visitas.";
  return message;
}

function ResetCounts() {
  var expdate = new Date();
  expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365));
  visit = 0;
  SetCookie("visit", visit, expdate , "/", null, false);
  history.go(0);
}
//------------------------------\\

function ObterNome(){
	if(username == null || username=="")
	{
		document.write('Visitante');
	}
	else{
  		document.write(username);
	}
}

//------------------------------\\

function greet() {
  var todaydate = new Date();
  var timeis = todaydate.getTime();
  todaydate.setTime(timeis);
  var houris = todaydate.getHours();
  if (houris > 18) display = "Boa noite";
  else if (houris >=12) display = "Boa tarde";
  else display = "Bom dia";
  var title = document.title;
if(username == null || username=="")
{
	var welcome = (display);
  	document.write(welcome);
	document.write(' Visitante. (<a onclick=\"startnome(\'inome.html\')\"><font color=\"#000080\"><u>Inserir Nome</u></font></a>)<br>Bem-vindo ao Ressalva.');
	document.write('<br>');	
}
else{
  	var welcome = (display + " " + username +"!");
  	document.write(welcome);
	document.write('<br>');
	var message=DisplayInfo();
  	document.write(message);
	document.write('<br>');
}
}

function startnome(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,height=200px,width=200px,left = 99,top = 200");
}

function inserirnome(){
	document.write('<form> Por favor escreva o seu nome: <input name=\"nameinput\" type=\"text\">');
	document.write('<br> <br>');
	document.write('<input value=\"Guardar\" onclick=\"set_name(this.form)\" type=\"button\">');
	document.write('</form>');
		
}

function fraseAl(){
var numfrases = 15;
var now = new Date();
var sec = now.getSeconds();
var num = sec % numfrases;
num +=1;
if(num==1){frase="Envia-me um email para que eu possa melhorar.";}
if(num==2){frase="Achas que falta algum link interessante? Diz-me por email.";}
if(num==3){frase="Podes falar de mim aos teus amigos.";}
if(num==4){frase="Tenho aqui muitas coisas que podes fazer!";}
if(num==5){frase="Joga no Ressalva Casino e ganhe dinheiro!";}
if(num==6){frase="Sabes o significa PTC? R:No link Ganhe Dinheiro.";}
if(num==7){frase="A Mini Vitrine tem muita coisa interessante.";}
if(num==8){frase="Sabes como ler emails e receber uns cents? R:No link Ganhe Dinheiro.";}
if(num==9){frase="Tens algum site? Faz-me teu parceiro, troca de links ou banners.";}
if(num==10){frase="Sabes jogar poker ou blackjack? Experimente no Ressalva Casino.";}
if(num==11){frase="Podes encontrar algo que precises na Mini Vitrine.";}
if(num==12){frase="Inscreve-te no top 10 da lista no link Ganhe Dinheiro.";}
if(num==13){frase="Queres fazer Publicidade do teu site manda-me um email.";}
if(num==14){frase="Queres receber a minha Newsletter? Inscreve-te";}
if(num==15){frase="Tenho uma Newsletter com muita coisa interessante.";}
return frase;
}

//--------------------------------------\\
var username = GetCookie('username');

function set_name(form){
	username = form.nameinput.value;
	pathname = location.pathname;
	myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	var largeExpDate = new Date ();
	largeExpDate.setTime(largeExpDate.getTime() + (365 * 24 * 3600 * 1000));
	SetCookie('username',username,largeExpDate,myDomain);
	if(username == null || username=="")
	{
		this.close();	
	}	
	else{
  		this.close();
		newindow('index.html');
	}
	
}

function newindow(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes");
}

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;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" +
    expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

/*******
Ressalva
http://www.ressalva.com.sapo.pt
*******/
