//
// *********************************************************************************
// *
// *               SSSSSSSSSSS  MM        MM    AAAAAAAA
// *              SSSSSSSSSSSS  MMM      MMM   AAAAAAAAAA
// *              SS            MMMM    MMMM  AA        AA
// *              SS            MM MM  MM MM  AA        AA
// *              SSSSSSSSSSSS  MM  MMMM  MM  AAAAAAAAAAAA
// *              SSSSSSSSSSSS  MM   MM   MM  AAAAAAAAAAAA
// *                        SS  MM        MM  AA        AA
// *                        SS  MM        MM  AA        AA
// *              SSSSSSSSSSSS  MM        MM  AA        AA
// *              SSSSSSSSSSS   MM        MM  AA        AA
// *
// *********************************************************************************
//
// *********************************************************************************
// Author:		Duncan Lawley
// Project:             Jason Boh's School of Martial Arts
// History:		(5/11/2003)    Creation
// *********************************************************************************
//

//====================================================================
function rollIn() {

        document.close.src = "./images/b_close_hi.gif";
}

//====================================================================
function rollOut() {

        document.close.src = "./images/b_close.gif";
}

//====================================================================
function mouseActivate(img, file) {

        img.src=file;
}

//====================================================================
function productPopup(picture, prodWidth, prodHeight) {

        // Set a title
        var title = 'SMA Equipment';

        // Set window dimensions and center in screen
        var iWndWidth      = parseInt(prodWidth) + (30 * 2);
        var iWndHeight     = parseInt(prodHeight) + (30 * 2) + 85;
        var iWndLeft       = ((screen.width / 2)  - (iWndWidth /2));
        var iWndTop        = ((screen.height / 2) - (iWndHeight /2));


        // Force minimum width for small images
        if (iWndWidth < 200)
                iWndWidth = 200;

        // Create basic window
        var wndAlert;
	wndAlert 	   = window.open("", "PopupProduct",
					 "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=1,resizable=0,width=" + iWndWidth+ ",height=" + iWndHeight+ ",left=" + iWndLeft+ ",top=" + iWndTop);

        // Output HTML content to window
        // HTML Validated... (29/11/2003)

	wndAlert.document.write('<html>');
	wndAlert.document.write('<head>');
	wndAlert.document.write('<title>' + title + '</title>');
        wndAlert.document.write('<link rel="STYLESHEET" type="text/css" href="./style/sma_style.css">');
	wndAlert.document.write('</head>');
	wndAlert.document.write('<body bgcolor="#000000" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">');
 	wndAlert.document.write('<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%" bgcolor="#FFFFFF">');

        wndAlert.document.write('<tr>');
	wndAlert.document.write('<td valign="middle" align="middle" height="100%">');
        wndAlert.document.write('<img id="SMA" src="' + picture + '" title="' + title + '"  width="' + prodWidth + '" height="' + prodHeight + '" border="0" name="GalleryPic" alt="">');
	wndAlert.document.write('</td>');
	wndAlert.document.write('</tr>');

        wndAlert.document.write('<tr><td align="left" valign="middle" height="50" bgcolor="#FFFFFF"><p><center><a class="prodclosebutton" href="#SMA" onclick="window.close();return(false);" target="new" title="Click here to close this window.">&nbsp;&bull;&nbsp;close&nbsp;&bull;&nbsp;</a></center></td></tr>');

	wndAlert.document.write('<tr><td align="left" height="25" bgcolor="#000000">');
	wndAlert.document.write('<font class="websiteurl">www.jasonboh.co.uk</font>');
	wndAlert.document.write('</td></tr>');

        wndAlert.document.write('</table>');
	wndAlert.document.write('</body>');
	wndAlert.document.write('</html>');

        // HTML Validated... (29/11/2003)

        return(0);
}

//====================================================================
function galleryPopup(picture, pictureWidth, pictureHeight, title) {

        // Set window dimensions and center in screen
        var iWndWidth      = parseInt(pictureWidth) + (30 * 2);
        var iWndHeight     = parseInt(pictureHeight) + (30 * 2) + 40 + 40;

        var iWndLeft       = ((screen.width / 2)  - (iWndWidth /2));
        var iWndTop        = ((screen.height / 2) - (iWndHeight /2));

        // Create basic window
        var wndAlert;
	wndAlert	= window.open("", "popupGallery",
					 "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=1,resizable=0,width=" + iWndWidth+ ",height=" + iWndHeight+ ",left=" + iWndLeft+ ",top=" + iWndTop);

        // Output HTML content to window
	wndAlert.document.write('<html>');
	wndAlert.document.write('<head>');
	wndAlert.document.write('<title>SMA Gallery Picture</title>');
        wndAlert.document.write('<link rel="STYLESHEET" type="text/css" href="./style/sma_style.css">');
	wndAlert.document.write('</head>');
	wndAlert.document.write('<body bgcolor="#CEB684" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" text="#000000"  style="background-image: url(./images/popup_back.jpg); background-repeat: no-repeat; background-position: bottom left">');
        wndAlert.document.write('<table width="100%" height="100%"><tr><td width="100%" height="100%" valign="middle">');
        wndAlert.document.write('<center>');
        wndAlert.document.write('<img id="SMA" src="' + picture + '" title="' + title + '"  width="' + pictureWidth + '" height="' + pictureHeight + '" border="1" border-color="#947942" name="GalleryPic" alt="">');
        wndAlert.document.write('<p><center>' + title + '</center>');
        wndAlert.document.write('<p><center><a class="closebutton" href="#SMA" onclick="window.close();return(false);" target="new" title="Click here to close this window.">&nbsp;&bull;&nbsp;close&nbsp;&bull;&nbsp;</a></center>');
        wndAlert.document.write('</center>');
        wndAlert.document.write('</td></tr></table>');
	wndAlert.document.write('</body>');
	wndAlert.document.write('</html>');

        return(0);
}


function setGalleryThumbNail(name, hi) {

        var imgTl = eval('document.' + name + '_tl');
        var imgTm = eval('document.' + name + '_tm');
        var imgTr = eval('document.' + name + '_tr');
        var imgMl = eval('document.' + name + '_ml');
        var imgMr = eval('document.' + name + '_mr');
        var imgBl = eval('document.' + name + '_bl');
        var imgBm = eval('document.' + name + '_bm');
        var imgBr = eval('document.' + name + '_br');

        if (hi) {
                imageTail = "_hi.gif";
        } else {
	        imageTail = ".gif";
        }

       	imgTl.src = './images/sur_tl' + imageTail;
        imgTm.src = './images/sur_tm' + imageTail;
        imgTr.src = './images/sur_tr' + imageTail;
        imgMl.src = './images/sur_ml' + imageTail;
        imgMr.src = './images/sur_mr' + imageTail;
        imgBl.src = './images/sur_bl' + imageTail;
        imgBm.src = './images/sur_bm' + imageTail;
        imgBr.src = './images/sur_br' + imageTail;

}

//====================================================================
function setThumbHi(name) {
	setGalleryThumbNail(name, true);
}

//====================================================================
function setThumbLow(name) {
	setGalleryThumbNail(name, false);
}

//====================================================================
function galleryThumbNail(thumb, thumbWidth, thumbHeight, pic, picWidth, picHeight, title) {


        // HTML Validated... (29/11/2003)
        statusStub = "Jason Boh\\'s School of Martial Arts - Show image: ";

 	document.write('<table cellspacing="0" cellpadding="0" border="0" bgcolor="#CEB684">');
        document.write('<tr>');
	document.write('<td bgcolor="white" valign="middle">');
        document.write('<a class="imglink" href="#SMA" onclick="galleryPopup(\'' + pic + '\', \'' + picWidth + '\', \'' + picHeight + '\', \'' + title + '\');return(false);" title="' + title + ' (click to enlarge)"><img src="'+ thumb + '" class="imglink" border="1" width="' + thumbWidth + '" height="' + thumbHeight + '"  onmouseover="window.parent.status=\'' + statusStub + title + '\';return(true);" onmouseout="window.parent.status=window.parent.defaultStatus;return(true);" ALT="' + title + ' (click to enlarge)"></a>');
	document.write('</td>');
	document.write('</tr>');
        document.write('</table>');

        // HTML Validated... (29/11/2003)
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function getFormattedDate(now) {

        var months = [	"January",
                        "February",
                        "March",
                        "April",
                        "May",
                        "June",
                        "July",
                        "August",
                        "September",
                        "October",
                        "November",
                        "December"
			];

        var days = [    "Sunday",
			"Monday",
			"Tuesday",
			"Wednesday",
			"Thursday",
			"Friday",
			"Saturday"
			];

        // var now = new Date();

        if (now == null) {
                now = new Date();
        }

        var result = "";
        var fraction = "";
        switch(now.getDate()) {
                case 1: 	fraction = "st"; break;
                case 21: 	fraction = "st"; break;
                case 31: 	fraction = "st"; break;
                case 2: 	fraction = "nd"; break;
                case 22: 	fraction = "nd"; break;
                case 3: 	fraction = "rd"; break;
                case 23: 	fraction = "rd"; break;
                default: 	fraction = "th"; break;
        }

        result += days[now.getDay()] + ", ";
        result += now.getDate() + fraction +" ";
        result += months[now.getMonth()] + " ";
        result += now.getYear();

        return(result);
}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function gradingTop() {

	document.write('<table cellpadding="3" cellspacing="1" border="0" bgcolor="#947942" width="400">');
        document.write('<tr bgcolor="white">');
	document.write('<td class="gt_title" width="25%">Student</td>');
	document.write('<td class="gt_title" width="25%">Belt</td>');
        document.write('<td class="gt_title" width="40%">Grade</td>');
	document.write('</tr>');
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function gradingBottom() {

	document.write('<tr bgcolor="white"><td class="gt_title" colspan="3"></td></tr>');
	document.write('</table>');
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function gradingEntry(grade, studentName) {

        gradeName        = "";
        gradeColour      = "";
        gradeImage       = "";
        switch(grade) {

                case 9: gradeName = "9th Kyu";  gradeColour = "Orange"; 		gradeImage = "belt_orange.gif"; 		break;
                case 8: gradeName = "8th Kyu";  gradeColour = "Red"; 			gradeImage = "belt_red.gif"; 			break;
                case 7: gradeName = "7th Kyu";  gradeColour = "Yellow"; 		gradeImage = "belt_yellow.gif"; 		break;
                case 6: gradeName = "6th Kyu";  gradeColour = "Green"; 			gradeImage = "belt_green.gif"; 			break;
                case 5: gradeName = "5th Kyu";  gradeColour = "Purple"; 		gradeImage = "belt_purple.gif"; 		break;
                case 4: gradeName = "4th Kyu";  gradeColour = "Purple & White"; 	gradeImage = "belt_purplewhite.gif"; 		break;
                case 3: gradeName = "3rd Kyu";  gradeColour = "Brown"; 			gradeImage = "belt_brown.gif"; 			break;
                case 2: gradeName = "2nd Kyu";  gradeColour = "Brown & White"; 		gradeImage = "belt_brownwhite.gif"; 		break;
                case 1: gradeName = "1st Kyu";  gradeColour = "Brown & Double White"; 	gradeImage = "belt_browntwowhite.gif"; 	break;
                case 0: gradeName = "Shodan";  	gradeColour = "Black"; 			gradeImage = "belt_black.gif"; 			break;
                default:
                        gradeName = "10th Kyu";	gradeColour = "White"; 	gradeImage = "belt_white.gif"; break;                        break;
        }

        document.write('<tr bgcolor="white">');
	document.write('<td class="gt_entry">' + studentName + '</td>');
	document.write('<td class="gt_entry" align="center"><img src="./images/' + gradeImage + '" border="0" width="84" height="14"></td>');
	document.write('<td class="gt_entry">' + gradeColour + ' (' + gradeName + ')</td>');
	document.write('</tr>');
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function daysRemaining(year, month, day) {

        var aMinute 	= 60 * 1000;
        var aHour       = aMinute * 60;
        var aDay        = aHour * 24;
        var now         = new Date();
        var then        = new Date(year, month -1, day +1);
        var remaining   = 0;

        remaining = then.getTime() - now.getTime();
        remaining = Math.floor(remaining / aDay);

        if (remaining < 0) {
                remaining = "0";
        }

        return(remaining);
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function gallerySlideshow() {

        // Set window dimensions and center in screen
        var iWndWidth      = screen.width - 40;
        var iWndHeight     = screen.height - 60;
        var iWndLeft       = ((screen.width / 2)  - (iWndWidth /2));
        var iWndTop        = ((screen.height / 2) - (iWndHeight /2));

        // Create basic window
        var wndAlert;
	wndAlert	= window.open(	"./photo_gallery_slideshow.html",
					"popupSlideshow",
					"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,resizable=1,width=" + iWndWidth+ ",height=" + iWndHeight+ ",left=" + iWndLeft+ ",top=" + iWndTop);
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function setGallery(link, galleryPage) {


        for(i=0; i < document.all.length; i++) {
                if (document.all[i].className == 'gal_titlestatic') {
                        document.all[i].className = 'gal_title';
                }
        }
	link.className = 'gal_titlestatic';
        document.all.gallerypreview.src = galleryPage;
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function getWebURL() {

        if (document.location.href.indexOf('jasonboh.com') != -1) {
        	return('www.jasonboh.com');
        } else {
		return('www.jasonboh.co.uk');
        }
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function getWebLink() {

        document.write('<a class="websiteurl" href="http://' + getWebURL() + '">' + getWebURL() + '</a>');
}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function displayBUN() {


        var msg = '\n\n\nJason Boh School of Martial Arts\n\n\n'+
		  'WARNING:You have requested access to a restricted area of this web-site \nthat is intended for the use of SMA staff members and instructors only.' +
		  '\n\n\n'+
                  'You are required to have authorisation and a login account from SMA before \nyou proceed. Unauthorised access to or misuse of this area of the web-site is \nprohibited and constitutes an offence under the Computer Misuse Act 1990.' +
                  '\n\n\n'+
		  'Are you sure you want to continue?'+ 
		  '\n\n\n';

        return(window.confirm(msg));
}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function getCookie(Name) {

       	var CurrentCookies 	= document.cookie;
        var CookieValue 	= "";
        var Top 		= 0;
        var End 		= 0;

	Top = CurrentCookies.indexOf(Name);
	if (Top != -1) {

                Top += Name.length;
        	End = CurrentCookies.indexOf(";", Top)
		if (End == -1) {
	        	End = CurrentCookies.length;
                }
	        CookieValue = CurrentCookies.substring((Top + 1), End);
                return(CookieValue);
	} else {

                return("");
	}
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function setCookie(Name, Value) {

	var now = new Date();
        now.setFullYear(now.getFullYear() + 1);
     	document.cookie = Name + "=" + Value + " ; expires=" + now.toGMTString();
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function setTempCookie(Name, Value) {

     	document.cookie = Name + "=" + Value + " ;";
}

//====================================================================
//====================================================================

function hide(section) {
	section.style.display="none";
}

function show(section) {
	section.style.display="inline";
}

function toggle(section) {

	// Hide or show section based on current state
	if (section.style.display=="none"){
		show(section);
	} else {
		hide(section);
        }
}

//====================================================================
//====================================================================

