// Disable right mouse click
var message = "Oops...";

function clickIE4() {
	if (event.button == 2) {
		alert(message);
		return false;
	}
}

function clickNS4(e) {
	if (document.layers || document.getElementById && ! document.all) {
		if (e.which == 2 || e.which == 3) {
			alert(message);
			return false;
		}
	}
}

if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown = clickNS4;
} else if (document.all && !document.getElementById) {
	document.onmousedown = clickIE4;
}

document.oncontextmenu = new Function("return false");


// validate enquire form
function validateEmail( x ) { 
    if ( x.name.value == '') {
        alert( 'Please input your name' );
        return false;
    } else if( x.email.value == '') {
    	alert( 'Please input your email address' );
    	return false;
    } else if( x.email.value.search(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/) == -1) {
        alert( 'Please input a valid email address' );
        return false;
    } else if( x.subject.value == '') {
        alert( 'Please input subject' );
        return false;
    } else if( x.comment.value == '') {
        alert( 'Please input your comment' );
        return false;
    } 
    
    return true;
}

function mailto( email ) { 
    document.location.href = 'mailto:'+email;
}

// preload image
pic1= new Image(33,24); 
pic1.src="/images/menu.gif"; 

function swap( name, but ) {
    document.images[name].src = '/images/antee'+but+'.gif';
}


function story() {    
    this.curstory = 'story1';
    this.curpage = 1;
    this.stories = new Array();
    this.stories['story1'] = new Array('FROG LOVE STORY', 4);
    this.stories['story2'] = new Array('STARFISH STORY', 4);
    this.stories['story3'] = new Array('ANT\'S LOVE STORY', 3);
    this.total = 3;
}

story.prototype.swapimg = function( curimg, curpage ) {
    this.curstory = curimg;
    this.curpage = curpage;

    document.images['leftpic'].src = '/images/storytime/'+curimg+'_'+curpage+'.jpg';
    document.images['rightpic'].src = '/images/storytime/'+curimg+'_'+curpage+'_rg.jpg';

    document.getElementById('storytimepagetitle').innerHTML = '<img src="/images/storytime/title_'+curimg+'.gif" height="16" alt="'+this.stories[curimg][0]+'" />'
    
    if( curpage < this.stories[curimg][1] )
    	document.getElementById('next').innerHTML = '<a href="javascript:story.swapimg(\''+curimg+'\','+(parseInt(curpage)+1)+')"><img src="/images/storytime/next.gif" width="40" height="10" alt="NEXT..." /></a>';
    else
        document.getElementById('next').innerHTML = '&nbsp;';
    this.drawmenu();
}

story.prototype.drawmenu = function() {
    strHTML = '<ul>';
    
    for(var i=1; i<=this.total; i++ ) {
    	strHTML += '<li>';
    	strHTML += '<a href="javascript:story.swapimg(\'story'+i+'\',1)"><img src="/images/storytime/menu_story'+i+'_trans.gif" height="16" alt="'+this.stories['story'+i][0]+'" /></a>';
    	
    	if( this.curstory == 'story'+i ) {
    	    for(var j=1; j<=this.stories['story'+i][1]; j++){
    	        if(this.curpage == j) {
    	            strHTML += '<span class="storypage">'+j+'</span>';
    	        } else {
    	            strHTML += '<a href="javascript:story.swapimg(\''+this.curstory+'\','+j+')">'+j+'</a>';
    	        }
    	    }
    	}
    	strHTML += '</li>';
    }
    
    
    strHTML += '<li style="width:34px"><a href="/storytime/"><img src="/images/storytime/menu_back_trans.gif" width="34" height="12" alt="BACK" /><a></li>' +
    	'</ul>';
    document.getElementById('storytimemenu').innerHTML = strHTML;
}

