var basePath = '';

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 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 trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}


function showLoginForm() {
	$('#loginContainer').modal({
		containerCss: {width: '360px', height: '200px', margin: '15% 0 0 -180px', padding: '10px'}
	});
}

function closeLoginForm() {
	$.modal.close();
}

var lastExpandedList = '';
function expandList(listID) {
	element = 'subList' + listID;
/*	if (lastExpandedList != '' && lastExpandedList != element) {
		elmnt = MM_findObj(lastExpandedList);
		if (elmnt.style.display == 'block') {
			elmnt.style.display = 'none';
		}
	}*/
	elmnt = MM_findObj(element);
	if (elmnt.style.display == 'block') {
		elmnt.style.display = 'none';
	} else {
		elmnt.style.display = 'block';
		lastExpandedList = element;
	}
}

function addToItinerary(cityID, venueID) {
	$.post(basePath + 'eng_itinerary.php', {'cityID': cityID, 'venueID': venueID}, function(data) 
	{
		data = data.split('|');
		if (data[0] == 'ERR') {
			elmnt = MM_findObj('venue' + data[1]);
			elmnt.checked = !elmnt.checked;
			infobox(data[2], 7500)
		}
		if (data[0] == 'SUC') {
			elmnt = MM_findObj('venue' + data[1]);
			if (data[2] == 'remove') {
				msg = '<strong>&quot;' + data[3] + '&quot;</strong> removed from your <strong>' + data[4] + '</strong> itinerary.'
			}
			if (data[2] == 'addto') {
				msg = '<strong>&quot;' + data[3] + '&quot;</strong> added to your <strong>' + data[4] + '</strong> itinerary.'
			}
			infobox(msg);
		}
	});
}
var libTO = 0;
function infobox(msg, holdTime){
	if(msg.length<1)
		return;
	
	if (holdTime === undefined) {
		holdTime = 2000;
	}
	
	$("#ibMessage").html(msg);
	$("#infoBox").fadeIn("slow",function()
	{
		window.clearTimeout(libTO);
		libTO = window.setTimeout("hideinfobox()",holdTime);
	}
	);
}

function hideinfobox(){
	$("#infoBox").fadeOut("slow",function()
	{
		$("#ibMessage").html("");
	}
	);
}

function closePlayer() {
	//$("#modalContainer").html("");
	$.modal.close();
}

function playVideo(videoID) {
	$('#videoPlayer').modal({
		containerCss: {width: '540px', height: '440px', margin: '5% 0 0 -270px', padding: '10px'}
	});
	var s1 = new SWFObject(basePath + "images/videoPlayer.swf?" + Math.random(),"videoPlayer","540","440","9.0.124","#FFFFFF");
	s1.addParam("allowfullscreen","true");
	s1.addParam("allowScriptAccess","always");
	s1.addParam("swliveconnect", "true");
	s1.addParam("flashvars","basePath=" + basePath + "&videoID=" + videoID);
	s1.write("modalContainer");
}

function showCommentForm() {
	elmnt = MM_findObj('addCommentMask');
	btn = MM_findObj('addCommentBtn');
	if (elmnt.style.display == 'block') {
		document.commentForm.reset();
		elmnt.style.display = 'none';
		btn.style.display = 'block';
	} else {
		elmnt.style.display = 'block';
		btn.style.display = 'none';
		document.commentForm.name.focus();
		$.post(basePath + 'eng_comment.php', {'reload': 'Yeap'}, function(data) 
		{
			reloadCode(Math.random(), 'imgCode');
		});
	}
}

function reloadCode(timeC, imagePlacer) {
	theObj = MM_findObj(imagePlacer);
	theObj.src=basePath + 'contactImg.php?k=' + timeC + theObj.name;
}

function showCommentNotify(elm) {
	obj = MM_findObj('notifyEml');
	if (elm.checked) {
		obj.style.display = 'block';
		document.commentForm.notifyEmail.value = '';
	} else {
		obj.style.display = 'none';
	}
}

function addTo() {
	obj = MM_findObj('shareButtons');
	if (obj.style.display == 'block') {
		obj.style.display = 'none';
	} else {
		obj.style.display = 'block';
		obj = MM_findObj('sendByMail');
		obj.style.display = 'none';
	}
}

function sendEmail() {
	obj = MM_findObj('sendByMail');
	if (obj.style.display == 'block') {
		obj.style.display = 'none';
	} else {
		obj.style.display = 'block';
		obj = MM_findObj('shareButtons');
		obj.style.display = 'none';
	}
}

function printPage() {
	var address = document.location.href;
	if (address.indexOf('?') > 0) {
		toAdd = '&printable=yes';
	} else {
		toAdd = '?printable=yes';
	}
	window.open(address + toAdd);
}

function fieldReset(obj, template) {
	if (template == 'keyword') {
		if (obj.value == 'Search site...') {
			obj.value = '';
		}
	}
	return true;
}

function fieldSet(obj, template) {
	if (template == 'keyword') {
		if (obj.value == '') {
			obj.value = 'Search site...';
		}
	}
	return true;
}
