function launchPage(p){	flippingBook.getFlippingBookReference().flipGotoPage(p); hideIndex(); return false;} 
function showIndex() { hideSubscribe(); hideEmail(); e = document.getElementById('index'); if (e.style.display == 'block') e.style.display = 'none'; else e.style.display = 'block'; return false;}
function hideIndex() { document.getElementById('index').style.display = 'none'; return false;}
function showSubscribe() { clearSubscribeForm(); hideIndex(); hideEmail(); e = document.getElementById('subscribe'); if (e.style.display == 'block') e.style.display = 'none'; else e.style.display = 'block'; return false;}
function hideSubscribe() { document.getElementById('subscribe').setAttribute('style','display:none'); return false;}
function showEmail() { clearEmailForm(); hideIndex(); hideSubscribe(); e = document.getElementById('email'); if (e.style.display == 'block') e.style.display = 'none'; else e.style.display = 'block'; return false;}
function hideEmail() { document.getElementById('email').setAttribute('style','display:none'); return false;}

flippingBook.onUpdatePagination = function(pageString)
{
	var currentPage = parseInt(pageString);
	var pageSpan = (String(pageString).split('-').length > 1) ? 1 : 0;
	var linkMarkup = '';
	var numLinks = 0;
	
	for (var i = currentPage; i <= (currentPage + pageSpan); i++ )
	{
		if (flippingBook.links[i])
		{
			for (var j = 0; j < flippingBook.links[i].length; j++)
			{
				numLinks++;
				linkMarkup = linkMarkup + '<a target="_blank" href="' + flippingBook.links[i][j].u + '">' + flippingBook.links[i][j].t + '</a>\r\n';
			}
		}
	}
	var x = document.getElementById("linkContainer");
	x.innerHTML = linkMarkup;
	
	document.getElementById("pageLinks").style.display = (numLinks > 0) ? 'block' : 'none';
	document.getElementById("pageLinks").className = 'inactive';
	
	x = document.getElementById("showLinks");
	x.innerHTML = 'Web Links (' + numLinks + ')';
	
}

function windowSizeChanged()
{
    var tmp = getWindowSize();
    if (!((tmp.width == windowSize.width && tmp.height == windowSize.height)))
    {
        window.location.href = window.location.href;
    }
}

function showLinks() {	document.getElementById("pageLinks").className = (document.getElementById("pageLinks").className == 'inactive') ? '' : 'inactive'; }
function hideLinks() {	document.getElementById("pageLinks").className = 'inactive'; }

function clearEmailForm()
{
    var txtEmailFromName = document.getElementById('txtEmailFromName');
    var txtEmailFromAddress = document.getElementById('txtEmailFromAddress');
    var txtEmailToAddress = document.getElementById('txtEmailToAddress');
    var txtMessage = document.getElementById('txtMessage');
    var vEmailFromName = document.getElementById('vEmailFromName');
    var vEmailFromAddress = document.getElementById('vEmailFromAddress');
    var vEmailToAddress = document.getElementById('vEmailToAddress');
    
    txtEmailFromName.value = '';
    txtEmailFromAddress.value = '';
    txtEmailToAddress.value = '';
    txtMessage.value = 'Type a short message here (optional)';
    vEmailFromName.style.display = 'none';
    vEmailFromAddress.style.display = 'none';
    vEmailToAddress.style.display = 'none';
}

function validateEmailForm()
{
    var valid = true;
    var txtEmailFromName = document.getElementById('txtEmailFromName');
    var txtEmailFromAddress = document.getElementById('txtEmailFromAddress');
    var txtEmailToAddress = document.getElementById('txtEmailToAddress');
    
    if (txtEmailFromName.value == '')
    {
        document.getElementById('vEmailFromName').style.display = 'inline';
        valid = false;
    }
    else
    {
        document.getElementById('vEmailFromName').style.display = 'none';       
    }
    
    if (!validateEmailAddress(txtEmailFromAddress.value))
    {
        document.getElementById('vEmailFromAddress').style.display = 'inline';
        valid = false;
    }
    else
    {
        document.getElementById('vEmailFromAddress').style.display = 'none';       
    }
    
    if (!validateEmailAddress(txtEmailToAddress.value))
    {
        document.getElementById('vEmailToAddress').style.display = 'inline';
        valid = false;
    }
    else
    {
        document.getElementById('vEmailToAddress').style.display = 'none';       
    }
        
    return valid;
}

function clearEmailForm()
{
    var txtEmailFromName = document.getElementById('txtEmailFromName');
    var txtEmailFromAddress = document.getElementById('txtEmailFromAddress');
    var txtEmailToAddress = document.getElementById('txtEmailToAddress');
    var txtMessage = document.getElementById('txtMessage');
    var vEmailFromName = document.getElementById('vEmailFromName');
    var vEmailFromAddress = document.getElementById('vEmailFromAddress');
    var vEmailToAddress = document.getElementById('vEmailToAddress');
    
    txtEmailFromName.value = '';
    txtEmailFromAddress.value = '';
    txtEmailToAddress.value = '';
    txtMessage.value = 'Type a short message here (optional)';
    vEmailFromName.style.display = 'none';
    vEmailFromAddress.style.display = 'none';
    vEmailToAddress.style.display = 'none';
}

function validateSubscribeForm()
{
    var valid = true;
    var txtSubscribeName = document.getElementById('txtSubscribeName');
    var txtSubscribeEmail = document.getElementById('txtSubscribeEmail');

    if (txtSubscribeName.value == '')
    {
        document.getElementById('vSubscribeName').style.display = 'inline';
        valid = false;
    }
    else
    {
        document.getElementById('vSubscribeName').style.display = 'none';       
    }
    
    if (!validateEmailAddress(txtSubscribeEmail.value))
    {
        document.getElementById('vSubscribeEmail').style.display = 'inline';
        valid = false;
    }
    else
    {
        document.getElementById('vSubscribeEmail').style.display = 'none';       
    }
    
        
    return valid;
}

function clearSubscribeForm()
{
    var txtSubscribeName = document.getElementById('txtSubscribeName');
    var txtSubscribeEmail = document.getElementById('txtSubscribeEmail');
    var vSubscribeName = document.getElementById('vSubscribeName');
    var vSubscribeEmail = document.getElementById('vSubscribeEmail');

    
    txtSubscribeName.value = '';
    txtSubscribeEmail.value = '';

    vSubscribeName.style.display = 'none';
    vSubscribeEmail.style.display = 'none';
}

function validateEmailAddress(address)
{
    var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return pattern.test(address);
}