function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function showMap(basePath, mapID) {
	window.open(basePath + 'map.php?addressID=' + mapID, 'mapViewer', 'height=720,width=780,scrollbars=no,scrolling=no,status=yes');
}

function fieldReset(obj, template) {
	if (obj.value == template) {
		obj.value = '';
	}
	return true;
}

function fieldSet(obj, template) {
	if (obj.value == '') {
		obj.value = template;
	}
	return true;
}

function resetForm(obj, quick) {
	if (quick == false) {
		if (obj.name.value == 'Event name') {
			obj.name.value = '';
		}
	}
	
	if (obj.keyword.value == 'Keyword') {
		obj.keyword.value = '';
	}
}

function resetBooklink(lnk) {
	lnk.href='javascript: doBookmark(lnk);';
}

function doBookmark(lnk) { 
	title = top.document.title;
	url = top.location.href;

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title);
	} else if(window.opera && window.print) { // Opera Hotlist
		resetBooklink(lnk);
		return true; 
	} else {
		resetBooklink(lnk);
		alert("We are sorry for the inconvenience but your browser does not support this feature. You must manually add this page to your bookmarks.");
	}
}

function setBookmark(lnk) { 
	if(window.opera && window.print) { // Opera Hotlist
		lnk.href = top.location.href;
		lnk.title = top.document.title;
	}
}

function mailPage() {
	spObj = MM_findObj('mailPageForm');
	if (spObj.style.display == 'none' || spObj.style.display == '' || spObj.style.display == null) {
		spObj.style.display = 'block';
		document.mailPage.urladdress.value = escape(document.location.href);
		document.mailPage.pagetitle.value = escape(document.title);
	} else {
		spObj.style.display = 'none';
	}
}

function printPage(kind, id, base) {
	if (kind == 'evt') {
		urlID = 'eventID';
	}
	if (kind == 'ven') {
		urlID = 'venueID';
	}
	if (kind == 'fea') {
		urlID = 'featureID';
	}
	if (kind == 'mov') {
		urlID = 'filmID';
	}
	window.open(base + 'printable?' + urlID + '=' + id);
}

function doPrintPage() {
	window.print();
}

function showDontMiss() {
	ld = MM_findObj('loader');
	imgFile = MM_findObj('dnmissIMG');
	imgHolder = MM_findObj('dnmissIMGholder');
	
	var maxWidth = 630;
	imgWidth = imgFile.width;
	
	if (imgWidth > 630) {
		imgHeight = imgFile.height;
		ratio = imgHeight / imgWidth;
	
		imgFile.width = maxWidth;
		imgFile.height = 630 * ratio;
	}
	
	ld.style.display = 'none';
	imgHolder.style.display = 'block';
	imgHolder.style.overflow = '';
	imgHolder.style.width = maxWidth + 'px';
}

function changeLanguage(nl) {
	for(x = 0; x < langs.length; x++) {
		el = MM_findObj('lnk_' + langs[x]);
		el.style.color = '#000000';
		el = MM_findObj('text_' + langs[x]);
		el.style.display = 'none';
	}
	el = MM_findObj('lnk_' + nl);
	el.style.color = '#dadada';
	el = MM_findObj('text_' + nl);
	el.style.display = 'block';
}

function checkShownLangs() {
	hasShown = false;
	for(x = 0; x < langs.length; x++) {
		el = MM_findObj('text_' + langs[x]);
		if (el.style.display == 'block')
			hasShown = true;
	}
	
	if (hasShown == false) {
		changeLanguage(langs[0]);
	}
}

function adicionar() {
	obj = MM_findObj('addFavoritos');
	if (obj.style.display == 'block') {
		obj.style.display = 'none';
	} else {
		obj.style.display = 'block';
		obj = MM_findObj('sendByMail');
		obj.style.display = 'none';
		obj = MM_findObj('shareButtons');
		obj.style.display = 'none';
	}
}
