var SITE_URL = "http://www.joseantonioreyes.net/";
window.onload = OnLoad;
window.onresize = OnResize;

function click(e) {return false;}
function oncontextmenu() {return false;} 

function OnLoad(){
	top.document.body.oncontextmenu=click;
	window.top.frames['IFMenu'].document.oncontextmenu=click;
	window.top.frames['IFMenuBar'].document.oncontextmenu=click;
	window.top.frames['IFContent'].document.oncontextmenu=click;
	window.top.document.getElementById('DIVLoad').style.display = 'none';	
}
function OnResize() {
	var OIframe = window.top.document.getElementById('IFContent');
	if (window.frames[OIframe.id]!=null) {
		if (document.body.clientHeight > window.frames[OIframe.id].document.body.scrollHeight)
			OIframe.height = '100%'	
		else
			OIframe.height = window.frames[OIframe.id].document.body.scrollHeight;	
	}
}
function SetHomePage(page) {
    page.style.behavior='url(#default#homepage)';
    page.setHomePage(SITE_URL);
}
function SetBookmark(url,title) {
    if (window.sidebar) window.sidebar.addPanel(title, url,"");

    else if( window.opera && window.print )
    {
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();
    }
    
    else if( document.all ) window.external.AddFavorite( url, title);
}
function ReDimIframe(OIframe) {
	var lang = GetLanguage();	
	var Page = window.frames[OIframe.id].document.location.href;	
	SetCV(lang,Page);	
	SetCurrentBook(lang);	
	RandomizeNews(lang);
	RandomizeQuote(lang);	
	RandomizePopup(lang);		
	document.body.scrollTop = '0';
	if (document.body.clientHeight > window.frames[OIframe.id].document.body.scrollHeight)
		OIframe.height = '100%'	
	else
		OIframe.height = window.frames[OIframe.id].document.body.scrollHeight;
}
function SetWelcomePage(Page) {
	var parag = window.top.document.getElementById('PWelcome');
	if (Page.indexOf('esp/welcome.html') >= 0) parag.style.display = 'inline'
	else parag.style.display = 'none';
}
function RandomizeQuote(lang) {
	var Quotes = GetQuotes(lang);
	var i = parseInt(Math.random() * Quotes.length);
	var quote = Quotes[i];
	var divStr = '<P class="Text"><STRONG>' + GetTitle('quote',lang) + '</STRONG><BR>';
	divStr += '<SPAN class="TextQuote"><img src="Images/1quote.gif" unselectable="on">&nbsp;' + quote[1] + '&nbsp;<img src="Images/2quote.gif" unselectable="on"><BR></SPAN></P>';
	divStr += '<P class="TextQuote" align="right" style="line-height:0px"><I>' + quote[0] + '</I></P>';	
	DIVRandomQuote.innerHTML = divStr;
}
function RandomizeNews(lang) {
	var tooltip;
	switch (lang) {
		case 'cat':
			tooltip = 'Veure més noticies';
			break;
		case 'eng':
			tooltip = 'View more news';		
			break;			
		default:
			tooltip = 'Ver más noticias';
			break;						
	}		
	var News = GetNews(lang);
	var i = parseInt(Math.random() * News.length);
	var news = News[i];
	var divStr = '<SPAN class="Text"><STRONG>' + GetTitle('news',lang) + '</STRONG><BR>' + news[0] + '<BR>';
	divStr += '<A class="MenuLink" href="#" title="' + tooltip + '" onclick="SetContentFrame(\'' + lang + '/news.html\');">' + news[1] + '</A></SPAN>';	
	DIVRandomNews.innerHTML = divStr;
	var NewsParagraph = window.frames['IFContent'].document.getElementById('SiteNews');
	if (NewsParagraph!=null) {
		divStr = '';
		for(i=News.length; i>0;) {
			news = News[--i];
			divStr += '<STRONG>' + news[0] + '</STRONG><BR>';
			divStr += news[1] + '<BR><BR>';
			NewsParagraph.innerHTML = divStr;
		}
	}
}
function RandomizePopup(lang) {
	var i = parseInt(Math.random() * 4);
	if (i == 1) {
		var Popups = GetPopups(lang);
		i = parseInt(Math.random() * Popups.length);
		var popup = Popups[i];
		DIVLeftInfo.style.display = 'inline';
		DIVRightInfo.style.display = 'inline';
		top.document.getElementById(popup[3]).innerHTML += GeneratePopup(popup);
		setTimeout('ResetPopup();',6000);
	}
}
function ResetPopup() {
	var PopupInfo = window.top.document.getElementById('DIVPopup');
	var LeftInfo = window.top.document.getElementById('DIVLeftInfo');
	var RightInfo = window.top.document.getElementById('DIVRightInfo');
	if (PopupInfo != null) {
		PopupInfo.style.display = 'none';
		PopupInfo.innerHTML = '';
	}	
	if (LeftInfo != null) {
		LeftInfo.style.display = 'none';
		LeftInfo.innerHTML = '';
	}
	if (RightInfo != null) {	
		RightInfo.style.display = 'none';
		RightInfo.innerHTML = '';
	}
}
function SetCV(lang,Page) {
	if (Page.indexOf('cv.html') >= 0) {
		var divStr = '<P class="Text"><STRONG>' + GetTitle('cv',lang) + '</STRONG><BR>';
		divStr += '<A href="#" onclick="window.open(\'Files/' + lang + '/JAReyesCV.pdf\',\'_blank\');">';
		switch (lang) {
			case 'cat':
				divStr += 'Descarrega aquí el currículum en format pdf.';
				break;
			case 'eng':
				divStr += 'Download here the resume in pdf format.';
				break;			
			default:
				divStr += 'Descarga aquí el currículum en formato pdf.';
				break;						
		}			
		divStr += '</A><BR></P>';
		DIVCV.innerHTML = divStr;
		DIVCV.style.display = 'inline';
	} else {
		DIVCV.style.display = 'none';
	}
}
function SetCurrentBook(lang) {
	var title, link;
	switch (lang) {
		case 'cat':
			title = 'Estic llegint...';
			link = '... i també he llegit';
			break;
		case 'eng':
			title = 'I am reading...';	
			link = '... and I also have read';	
			break;			
		default:
			title = 'Estoy leyendo...';
			link = '... y también he leído';
			break;						
	}
	var divStr = '<TABLE cellSpacing="0" cellPadding="3" width="100%" style="border: solid 1px #575c62;">';
	divStr += '<TR><TH class="Menu2" vAlign="middle" scope="col" align="left" colSpan="2" style="border-bottom: solid 1px #575c62;">';
	divStr += '<SPAN class="Text"><STRONG>' + title + '</STRONG></SPAN>';
	divStr += '</TH></TR>';
	divStr += '<TR><TH>';
	divStr += '<IMG align="absmiddle" hspace="10" src="Images/Books/TokioBlues.jpg" vspace="10" border="0" unselectable="on">';
	divStr += '</TH></TR>';
	//divStr += '<TR><TH>';
	//divStr += '<IMG align="absmiddle" hspace="10" src="Images/Books/asp2-intro.jpg" vspace="10" border="0" unselectable="on">';
	//divStr += '</TH></TR>';	
	divStr += '<TR><TH class="Menu" align="left">';
	divStr += '<A href="#" class="Text" onclick="SetContentFrame(\'' + lang + '/books.html\');">' + link + '</A>';
	divStr += '</TH></TR>';
	divStr += '</TABLE>';
	DIVBook.innerHTML = divStr;
}
function SetContentFrame(OPage) {
	ResetPopup();
	document.body.scrollTop = '0';
	window.top.frames['IFContent'].document.location.href = OPage;
}
function SetLanguage(lang) {
	var location = window.top.frames['IFContent'].document.location.href;
	var pos1 = location.lastIndexOf('/');
	var pos2 = location.length;	
	var loader = window.top.document.getElementById('DIVLoad');
	loader.style.display = 'inline';
	loader.innerHTML = '<img unselectable="on" src="Images/' + lang + '/load.gif">';
	window.top.frames['IFMenu'].document.location.href = '../' + lang + '/menu.html';
	window.top.frames['IFMenuBar'].document.location.href = '../' + lang + '/menubar.html';
	window.top.frames['IFContent'].document.location.href = '../' + lang + location.substr(pos1,pos2-pos1);
	ResetPopup();	
	//SetCookie("language",lang);
}
function GetLanguage() {
	var location = window.top.frames['IFContent'].document.location.href;
	var pos1 = location.lastIndexOf('/');
	return location.substr(pos1-3,3);
}
/*
function GetLanguage() {
	var lang = GetCookie("language");
	if (lang == null) {
		var location = window.top.frames['IFContent'].document.location.href;
		var pos1 = location.lastIndexOf('/');
		lang = location.substr(pos1-3,3);	
		SetCookie("language",lang);
	}
	return lang;
}
*/
function GetTitle(type,lang) {
	var Titles;
	switch (type) {
		case 'news':
			Titles = new Array("Noticies","News","Noticias");
			break;
		case 'quote':
			Titles = new Array("Cites","Quotes","Citas");
			break;
		case 'cv':
			Titles = new Array("Descarregar CV","Download Resume","Descargar CV");
			break;						
	}	
	switch (lang) {
		case 'cat':
			return Titles[0];
			break;
		case 'eng':
			return Titles[1];
			break;			
		default:
			return Titles[2];
			break;
	}
}
function GetDate(lang) {
	var date = new Date();
	var Days;
	var Months = new Array();
	switch (lang) {
		case 'cat':
			Days = new Array("Diumenge","Dilluns","Dimarts","Dimecres","Dijous","Divendres","Dissabte");
			Months = new Array("Gener","Febrer","Març","Abril","Maig","Juny","Juliol","Agost","Septembre","Octubre","Novembre","Decembre");
			return Days[date.getDay()] + ", " + date.getDate() + " de " + Months[date.getMonth()] + " de " + date.getFullYear();			
			break;
		case 'eng':
			Days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
			Months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
			return Days[date.getDay()] + " " + Months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear();			
			break;			
		default:
			Days = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
			Months = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
			return Days[date.getDay()] + ", " + date.getDate() + " de " + Months[date.getMonth()] + " de " + date.getFullYear();			
			break;
	}
}
// Create a cookie with the specified name and value.
// The cookie expires at the end of the month.
function SetCookie(sName, sValue) {
  var date = new Date();
  date.setTime(date.getTime() + (1000 * 60 * 60 * 24 * 31));
  top.document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}
function GetCookie(sName) {
  // cookies are separated by semicolons
  var aCookie = top.document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++) {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }
  // a cookie with the requested name does not exist
  return null;
}
// Delete the cookie with the specified name.
function DelCookie(sName) {
  top.document.cookie = sName + "=NULL; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
