

/* ============= john's rollover code [v1.0] (much better than that dreamweaver generated stuff!) ============= */
var bHover = false;
function swapImage(oLink, bOver){
	if(document.images){
		var oImage = oLink.childNodes[0];
		var imageName = oImage.src.substring(0, oImage.src.lastIndexOf("."));
		var imageExtension = oImage.src.substring(oImage.src.lastIndexOf("."));
		if (bOver) {
			if (oImage.src.lastIndexOf("-over")==-1) {
				oImage.src = imageName + "-over" + imageExtension;
				bHover = false;
			}
			else {
				bHover = true;
			}
		}
		else {
			if (!bHover) {
				oImage.src = imageName.substring(0, imageName.lastIndexOf("-")) + imageExtension;
			}
		}
	}
}

/* ============= john's big hairy form validator [v1.5] ============= */
function RequiredFields(oForm) {
	var bCompleted = true;
	var bValidEmail = true;
	var oField;
	var oEmailRegExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	var bChecked = false;
	
	for (var i=0;i<aRequired.length;i++) {
		oField = oForm.elements[aRequired[i]];
		if (oField.type=='text'||oField.type=='textarea'||oField.type=='password'||oField.type=='hidden') {
			if (oField.value.length==0) {
				bCompleted = false;
				highlight(oField);
			}
			else if (oField.name=='email') {
				if (!oEmailRegExp.test(oField.value)) {
					bValidEmail = false;
					highlight(oField);
				}
			}
		}
		else if (oField.type=='radio') {

			bChecked = false;
			for (j=0;j<oField.length;j++) {
				if (oField[j].checked) {
					bChecked = true;
				}
			}
			if (!bChecked) {
				highlight(oField);
				bCompleted = false;
			}
		}
		else if (oField.type=='select'||oField.type=='select-one') {
			if (oField.options[oField.selectedIndex].value.length==0) {
				bCompleted = false;
				highlight(oField);
			}
		}
		else {
			bChecked = false;
			for (j=0;j<oField.length;j++) {
				if (oField[j].checked) {
					bChecked = true;
				}
			}
			if (!bChecked) {
				highlight(oField);
				bCompleted = false;
			}
		}
	}
	if (!bCompleted) {
		alert('Please complete all required fields');
	}
	else if (!bValidEmail) {
		alert('Please check your email address');
	}
	var bResult = bCompleted && bValidEmail;

	if (bResult) {
		// loop through fields and find submit buttons then disable....
		for (i=0;i<oForm.elements.length;i++) {
			if (oForm.elements[i].type=='submit') {
				oForm.elements[i].disabled = true;				
			}
		}
	}
	return bResult;
}
function highlight(oField) {
	if (oField.type=='select'||oField.type=='select-one'||oField.type=='text'||oField.type=='textarea'||oField.type=='password') {
		oField.style.backgroundColor = 'lightyellow';
		oField.style.border = '1px solid red';
	}
	else {
//		oField.parentNode.style.backgroundColor = 'lightyellow';
//		oField.parentNode.style.border = '1px solid red';
		// radio...
		for (var i=0;i<oField.length;i++) {
			oField[i].style.backgroundColor = 'lightyellow';
			oField[i].style.border = '1px solid red';
		}
	}
//	alert(oField.name);
}
var aRequired = new Array();


/* ============= add getElementById functionality to IE4 ============= */
if (!document.getElementById && document.all) { 
	document.getElementById = new Function('id', 'return document.all[id]') 
}

/* ============= add To Favourites if you really want it ============= */
function addToFavourites() {
	if (navigator.userAgent.indexOf("Opera")>-1) {
		window.alert('The Opera web browser does not support this feature.');
	}
	else if (document.all&&navigator.userAgent.indexOf("Opera")<0) {
		window.external.AddFavorite(location.href, document.title);
	}
	else {
		window.alert('Your browser does not support this feature.\nPressing Ctrl + D will bookmark this page.');
	}
}


/* ============= John's not quite so hairy flash detect [v1.0] ============= */
var iRequiredVersion = 6;
var bShowFlash = false;

// standard IE & windows detection...
var bIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var bOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var bWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; 

if (bIE && bWin && !bOpera) {
	// Internet Explorer on Windows platform...
	document.write('<scr' + 'ipt language="vbscript"> \n');	
	document.write('On Error Resume Next \n');	
	document.write('	bShowFlash = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & iRequiredVersion)) \n');	
	document.write('On Error Goto 0 \n');	
	document.write('</scr' + 'ipt> \n');	
}
else if (navigator.plugins) {
	// looking at mozilla/netscape browser...
	var sFlashVersion = navigator.plugins["Shockwave Flash"].description;
	var iMajorVersion = parseInt(sFlashVersion.charAt(sFlashVersion.indexOf(".") - 1));
	if (iMajorVersion >= iRequiredVersion) {
		bShowFlash = true;
	}
}
else if (bOpera) {
	// wing it and hope that it has flash!
	bShowFlash = true;
}


// writes out the movie to the browser...
function writeMovieHtml(sMovieUrl, iWidth, iHeight, sClass) {
	if (sClass.length) {
		document.write('<div class="' + sClass + '">');
	}
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + iWidth + '" height="' + iHeight + '"');
	document.write('>');
	document.write('<param name="movie" value="' + sMovieUrl + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<embed src="' + sMovieUrl + '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + iWidth + '" height="' + iHeight + '"></embed>');
	document.write('</object>');
	if (sClass.length) {
		document.write('</div>');
	}
}


/* ========================== cookie handlers =========================== */
function setCookie(sKey, sValue) {
	var futdate = new Date()		//Get the current time and date
	var expdate = futdate.getTime()  //Get the milliseconds since Jan 1, 1970
	expdate += 3600*1000  //expires in 1 hour(milliseconds)
	futdate.setTime(expdate)
	var newCookie = sKey + "=" + escape(sValue) + "; path=/;"	//Set the new cookie values up
//	newCookie += " expires=" + futdate.toGMTString()
	window.document.cookie=newCookie //Write the cookie
}
function getCookie(sKey) {
	var oCookie = document.cookie;
	var sKey = sKey + "=";
	var iBegin = oCookie.indexOf("; " + sKey);
	if (iBegin == -1) {
		iBegin = oCookie.indexOf(sKey);
		if (iBegin != 0) {
			return null;
		}
	} 
	else {
		iBegin = iBegin + 2;
	}
	var iEnd = oCookie.indexOf(";", iBegin);
	if (iEnd == -1) {
		iEnd = oCookie.length;
	}
	return unescape(oCookie.substring(iBegin + sKey.length, iEnd));
}

function preloadImages() {
	if (document.images) {
		var aPreloadImages = new Array('regUsersLogin-over.gif','downloadBListings-over.gif','hoop-over.gif');
		var sPath = "images/main/";
		var oImage = new Image();
		
		for (var i=0; i<aPreloadImages.length; i++) {
			oImage.src = sPath + aPreloadImages[i];
		}
	}
}

function init() {
	preloadImages();
}

window.onload = init;

