function showArticle(articleId, pageId, zoomLevel) {
	var url = '/ndp/del/article/' + articleId;
	if (pageId) {
		url += '/' + pageId;
	}
	if (zoomLevel && zoomLevel >= 0) {
		url += '?zoomLevel=' + zoomLevel;
	} else if (viewerBean) {
		url += '?zoomLevel=' + viewerBean.zoomLevel;
	}
	viewerBean = null;
//	window.location.href = url;
	document.location = url;
	return false;
} 

function printPage(pageId) {
	var url = "/ndp/imageservice/nla.news-page" + pageId + "/print";
	window.open(url);
}

function printArticle(articleId, format, openPrintPopup) {
	if (typeof openPrintPopup == 'undefined') {
		openPrintPopup = false;
	}
	var s = format.substr(0, 1).toUpperCase() + format.substr(1).toLowerCase();
//	var url = "/ndp/del/printArticle" + s + "/" + articleId + "/" + viewerBean.zoomLevel;
	var url = "/ndp/del/printArticle" + s + "/" + articleId + "/" + viewerBean.zoomLevel + "?print=" + (openPrintPopup ? "y" : "n");
	window.open(url);
}

function showDialog(dEle) {
	 $("#" + dEle).show() ;
}

function closeDialog(dEle) {
	$("#" + dEle).hide() ;
}

function openUrl(url) {
	window.open(url, '_blank');
}

function gopage(pid, zoomLevel) {
	var defaultZoomLevel = 1;
	if (zoomLevel == null || zoomLevel < 0) {
		zoomLevel = (viewerBean != null) ? viewerBean.zoomLevel : defaultZoomLevel;
	}
	window.location.href = '/ndp/del/page/' + pid + '?zoomLevel=' + zoomLevel;
	return false;
}

function getCookieValue(cookieName) {
	var val = "";
	var ck = document.cookie;
	if (ck.length > 0) {
		var n1 = ck.indexOf(cookieName + "=");
		if (n1 >= 0) {
			n1 += cookieName.length + 1;
			var n2 = ck.indexOf(";", n1);
			if (n2 < 0) {
				n2 = ck.length;
			}
			val = ck.substring(n1, n2);
		}
	}
	return val;
}

//function checkCaptcha(originalCaptchaText, captchaText, redirectId, redirectUrl) {
function checkCaptcha(originalCaptchaText, captchaText, onSuccess) {
	if (captchaText == null || captchaText == '') {
		alert("Please enter the captcha.");
	} else if (originalCaptchaText == null || originalCaptchaText == '') {
		alert("Your session has expired.");
	} else if (captchaText != originalCaptchaText) {
		alert("Your captcha doesn't match the text. Please try again.");
	} else {
		// Ok, store in a cookie
		$.cookie('newspaperCaptcha', captchaText, {path: '/'});

		// Hardcode!!!
//		if (redirectId != null && redirectId != '' && redirectUrl != null && redirectUrl != '') {
//			$('#' + redirectId).attr('href', redirectUrl);
//		}
		$('#tagId').attr('href', '/static/ndp/oxideDesign/addTag.html');
		$('#annotationId').attr('href', '/static/ndp/oxideDesign/addAnnotation.html');
		$('.popup').each(function(i) {
			var eId = $(this).attr('id');
			if (eId.indexOf('editAnnotation_') == 0) {
				var annoId = eId.substr(15);
				$(this).attr('href', '/ndp/del/editAnnotation/' + annoId);
			}
		});

		// Remove popup
		$('#popup, #mask').remove();
		$('body').removeClass('popup');
		
		if (onSuccess) {
			onSuccess();
		}
		
	}
}

function addViewEntirePage(pageId) {
	// Add button
	$('#header').append('<p class="buttons" id="return"><a href="javascript:gopage(' + pageId + ', 1);">View entire page</a></p>');
/*
	$('#viewer').append('<p class="buttons" id="return"><a href="javascript:gopage(' + pageId + ', 1);">View entire page</a></p>');
	// Try to center the button
	var left = parseInt($('#viewer').css('width'));
	if (isNaN(left) || left == 0) {
		left = 600;
	}
	$('#return').css('left', '' + ((left - 100) / 2) + 'px');
*/
}
