

/* ============= 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 = '#BBDAE9';
		oField.style.border = '1px solid #132A57';
	}
	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 = '#BBDAE9';
			oField[i].style.border = '1px solid #132A57';
		}
	}
//	alert(oField.name);
}
var aRequired = new Array();

function HighlightContactMethod(oSelect) {
	// reset required...
	var sValue = oSelect[oSelect.selectedIndex].value;
	var oLabel = document.getElementById('label_Telephone');
	if (sValue == 'Telephone') {
		oLabel.innerHTML = " *";
	}
	else {
		oLabel.innerHTML = "";
	}
}

/*
function HighlightContactMethod(oSelect) {
	// reset required...
	var oLabel;
	for (var i=1;i<oSelect.options.length;i++) {
		oLabel = document.getElementById('label_' + oSelect[i].value);
		if (oLabel.innerHTML.indexOf("*")!=-1) {
			if (i!=oSelect.selectedIndex) {
				oLabel.innerHTML = oLabel.innerHTML.substring(0, oLabel.innerHTML.indexOf("*"));
			}
		}
		else if (i==oSelect.selectedIndex) {
			oLabel.innerHTML = oLabel.innerHTML + " *";
		}
	}
}
*/


/* ============= 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 = 7;
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="index_files/' + sMovieUrl + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<embed src="index_files/' + sMovieUrl + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + iWidth + '" height="' + iHeight + '"></embed>');
	document.write('</object>');
	if (sClass.length) {
		document.write('</div>');
	}
}

/*
****************************************************************
Based on the script by Khalid Ali http://www.webapplikations.com
*****************************************************************
*/
var sParsedXml = "";
function ParseNoscript(sElementId){
	var oXmlDoc = document.getElementById(sElementId);
	if (oXmlDoc) {
		if (document.all) {
			// detect IE and just write out innerHTML...
			document.write(oXmlDoc.innerHTML);
		} else {
			parseXML(oXmlDoc);
			document.write(sParsedXml);
		}
	}
}

function parseXML(oNode){
	if (oNode.nodeType==1){
		if (oNode.hasChildNodes) {
			if (oNode.childNodes[0].nodeValue!=null) {
				sParsedXml += oNode.childNodes[0].nodeValue;
			}
			for(var i=0;i<oNode.childNodes.length;i++ ){
				var oChildNodes = oNode.childNodes;
				if (getNoneTextNode(oChildNodes)!=3) {
					parseXML(oChildNodes.item(i));
				} else {
	//				sParsedXml += "name = "+oChildNodes[i].oNodeName+", value = "+oChildNodes[i].childoNodes[0].oNodeValue;
				}
			}
		}
	}
}

function getNoneTextNode(oNode){
	if(oNode.hasChildNodes && oNode.firstChild.nodeType!=3){
		return oNode.firstChild;
	}
	else if(oNode.hasChildNodes && oNode.childNodes[1].nodeType==1){
		return oNode.childNodes[1];
	}
	else if(oNode.hasChildNodes && oNode.firstChild.nodeType==1){
		return oNode.firstChild;
	}
	return null;
}

/* ========================== 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('nav/aboutUs-over.gif','nav/boatSalesTitle-over.gif','nav/boatServices-over.gif','nav/contactUs-over.gif','nav/generalServices-over.gif','nav/home-over.gif','nav/sales-over.gif','nav/specialOffers-over.gif','home/boatServicesTitle-over.gif','home/boatGeneralSVTitle-over.gif','home/boatSalesTitle-over.gif');
		var sPath = "images/";
		var oImage = new Image();
		
		for (var i=0; i<aPreloadImages.length; i++) {
			oImage.src = sPath + aPreloadImages[i];
		}
	}
}

function init() {
	// use to call runtime events once page has loaded...
	preloadImages();
}

window.onload = init;


/* 
DHTML cross browser event handlers (addEvent & getEventSrc)
coutesy of http://www.sitepoint.com/article/1206
*/
function addEvent(objObject, strEventName, fnHandler) {
	if (objObject.addEventListener) {
		objObject.addEventListener(strEventName, fnHandler, false);
	}
	else if (objObject.attachEvent) {
		objObject.attachEvent("on" + strEventName, fnHandler);
	}
}
function getEventSrc(e) {
	if (!e) e = window.event;
	if (e.originalTarget) {
		return e.originalTarget;
	}
	else if (e.srcElement) {
		return e.srcElement;
	}
}

window.onload = init;

/*  POPPER  */

function PopUp(sHref, sName, sFeatures) {
		if (!sFeatures.length) {
				sFeatures = "directories=no,height=400,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no,width=620";
		}
		var newWin = window.open(sHref, sName, sFeatures);
		return false;
}