// GLOBAL FUCNTIONS ////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

function replaceCharacters(conversionString,inChar,outChar) // TRIM CHARACTERS
{
  var convertedString = conversionString.split(inChar);
  convertedString = convertedString.join(outChar);
  return convertedString;
}

function OpenLink(Url) // OPEN EXTERNAL LINK
{	
	var wSize =	((window.screen.availWidth) * 0.8);
	var hSize =	((window.screen.availHeight)* 0.7);
	var LeftPos = (( window.screen.availWidth - wSize) / 2);
	var TopPos = (( window.screen.availHeight - hSize) / 4);
	
	window.open( Url, "Popup", "height=" + hSize + ", width=" + wSize + ", top=" + TopPos + ", left=" + LeftPos + ", toolbar=1, menubar=1, location=1, resizable=1, scrollbars=1, status=1, titlebar=1");
}

function openAffETTWindow(ID) // OPEN EXTERNAL BOOKING LINK
{
	var newWindow,winProp,targetURL;	
	var wSize =	480;
	var hSize =	550;
	var LeftPos = (( window.screen.availWidth - wSize) / 2);
	var TopPos = (( window.screen.availHeight - hSize) / 2);	
	targetURL ='http://www.teetimeking.com//AffETT/default.asp?AffiliateID='+ID
	newWindow=window.open(targetURL, "Booking", "height=" + hSize + ", width=" + wSize + ", top=" + TopPos + ", left=" + LeftPos + ", toolbar=0, menubar=0, location=0, resizable=0, scrollbars=1, status=0, titlebar=0");
}

function gOver(e) // LINK EFFECTS MOUSEOVER
{
	if(navigator.appName != 'Microsoft Internet Explorer')
		e = e.target;
	else
		e = window.event.srcElement;

	e.style.cursor = "pointer";

	if (e.parentNode.tagName == "TR")
		e.style.border = "1px #454545 solid";
	else if (e.parentNode.tagName == "TD")
		e.parentNode.style.border = "1px #454545 solid";	
	else
		e.parentNode.parentNode.style.border = "1px #454545 solid";
}

function gOut(e) // LINK EFFECTS MOUSEOUT
{
	if(navigator.appName != 'Microsoft Internet Explorer')
		e = e.target;
	else
		e = window.event.srcElement;
	
	if (e.parentNode.tagName == "TR")
		e.style.border = "1px #DED8B8 solid";
	else if (e.parentNode.tagName == "TD") 
		e.parentNode.style.border = "1px #DED8B8 solid";
	else
		e.parentNode.parentNode.style.border = "1px #DED8B8 solid";
}

function toggleLang() // LANG SWAP
{	
	if(getCookie("lang") == "en")
		setCookie("lang","fr");
	else
		setCookie("lang","en");
	
	setCookie("menu","")
	window.parent.location = "../" + getCookie("lang");
}

function getCookie(name) { // use: getCookie("name");
    var re = new RegExp(name + "=([^;]+)");
    var value = re.exec(document.cookie);
    return (value != null) ? unescape(value[1]) : null;
}
var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days

function setCookie(name, value) { // use: setCookie("name", value);
    document.cookie=name + "=" + escape(value) + ";" + "path=/;"; // + ";" + "expires=" + expiry.toGMTString();
}     
	 
// MENU NAVIGATION /////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

function tmClick(url) // TOP MENU CLICK
{
	parent.frames["content"].location = url;
	setCookie("menu", "");
}

function mOver(e) // LEFT MENU MOUSEOVER
{
	if(navigator.appName != 'Microsoft Internet Explorer')
		e = e.target;
	else
		e = window.event.srcElement;

	oldSrc = e.src;
	e.style.cursor = "pointer";
	e.src = replaceCharacters(oldSrc,'.gif','_over.gif');	
}

function mOut(e) // LEFT MENU MOUSEOUT
{
	if(navigator.appName != 'Microsoft Internet Explorer')
		e = e.target;
	else
		e = window.event.srcElement;

	oldSrc = e.src;
	e.src = replaceCharacters(oldSrc,'_over.gif','.gif');
}

function mClick(url,menu) // LEFT MENU CLICK
{
	window.location = url;
	setCookie("menu", menu);
}

function mBuilder() // LEFT MENU BUILDER
{		
	param = getCookie("menu");	
	
	if (param == "rates") {
		document.mRates.src = "../images/" + getCookie("lang") + "/menu_rates_active.gif";
		document.mRates.setAttribute("onmouseover","");
		document.mRates.setAttribute("onmouseout","");
	}
	if (param == "academy") {
		document.mAcademy.src = "../images/" + getCookie("lang") + "/menu_academy_active.gif";
		document.mAcademy.setAttribute("onmouseover","");
		document.mAcademy.setAttribute("onmouseout","");
	}
	if (param == "holes") {
		document.mHoles.src = "../images/" + getCookie("lang") + "/menu_holes_active.gif";
		document.mHoles.setAttribute("onmouseover","");
		document.mHoles.setAttribute("onmouseout","");
	}
	if (param == "tour") {
		document.mTour.src = "../images/" + getCookie("lang") + "/menu_tour_active.gif";
		document.mTour.setAttribute("onmouseover","");
		document.mTour.setAttribute("onmouseout","");
	}
	if (param == "packages") {
		document.mPackages.src = "../images/" + getCookie("lang") + "/menu_packages_active.gif";
		document.mPackages.setAttribute("onmouseover","");
		document.mPackages.setAttribute("onmouseout","");
	}
	if (param == "members") {
		document.mMembers.src = "../images/" + getCookie("lang") + "/menu_members_active.gif";
		document.mMembers.setAttribute("onmouseover","");
		document.mMembers.setAttribute("onmouseout","");
	}
	if (param == "corporate") {
		document.mCorporate.src = "../images/" + getCookie("lang") + "/menu_corporate_active.gif";
		document.mCorporate.setAttribute("onmouseover","");
		document.mCorporate.setAttribute("onmouseout","");
	}
	if (param == "services") {
		document.mServices.src = "../images/" + getCookie("lang") + "/menu_services_active.gif";
		document.mServices.setAttribute("onmouseover","");
		document.mServices.setAttribute("onmouseout","");
	}
	if (param == "bio") {
		document.mBio.src = "../images/" + getCookie("lang") + "/menu_bio_active.gif";
		document.mBio.setAttribute("onmouseover","");
		document.mBio.setAttribute("onmouseout","");
	}
	else {}
}

// SCORE CARD //////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

function showBigHole() // SCORE CARD PICTURE DISPLAY
{
	var wSize =	265;
	var hSize =	265;
	var LeftPos = (( window.screen.availWidth - wSize) / 2);
	var TopPos = (( window.screen.availHeight - hSize) / 2);
	var pictureLink = "../images/holes/" + holeCurrent + ".jpg";
		
	//window.open( pictureLink, "picture", "height="+hSize+", width="+wSize+", top=" + TopPos + ", left=" + LeftPos + ", menubar=0, location=0, resizable=0, status=0, titlebar=0");
}

function showHole(hole) // SCORE CARD DISPLAY
{
	lastHole = holeCurrent;
	holeCurrent = hole;	
	document.getElementById("holeName").innerHTML = "<b>" +holeName[hole-1] + "</b>";
	document.getElementById("holeNumber").innerHTML =  nameHole + hole;
	document.getElementById("holePar").innerHTML = namePar + holePar[hole-1];
	document.getElementById("holeDistance").innerHTML = holeDistance[hole-1];
	document.getElementById("holeTribute").innerHTML = holeTribute[hole-1];
	document.getElementById("holeComment").innerHTML = holeComment[hole-1];
	document.holePreview.src = "../images/holes/" + hole + ".jpg";	
	showOutHole(lastHole);
	showOverHole(holeCurrent);
}

function nextHole() // NEXT HOLE
{
	if(holeCurrent == 18)
		showHole(1);
	else
		showHole(holeCurrent + 1);
}

function prevHole() // PREVIOUS HOLE
{	
	if(holeCurrent == 1)
		showHole(18);
	else
		showHole(holeCurrent - 1);
}

function showOverHole(hole) // SCORE CARD HOLE DISPLAY MOUSEOVER
{
	var row1 = scorecard.rows;
	var column1 = row1[0].cells;
	var column2 = row1[1].cells;
	var column3 = row1[2].cells;
	var column4 = row1[3].cells;
	var column5 = row1[4].cells;
	column1[hole].style.backgroundColor = "#ECE9D4";
	column2[hole].style.backgroundColor = "#666666";
	column3[hole].style.backgroundColor = "#FFFFFF";
	column4[hole].style.backgroundColor = "#F59210";
	column5[hole].style.backgroundColor = "#ECE9D4";
}

function showOutHole(hole) // SCORE CARD HOLE DISPLAY MOUSEOUT
{
	if(holeCurrent != hole)
	{
		var row1 = scorecard.rows;
		var column1 = row1[0].cells;
		var column2 = row1[1].cells;
		var column3 = row1[2].cells;
		var column4 = row1[3].cells;
		var column5 = row1[4].cells;
		column1[hole].style.backgroundColor = "";
		column2[hole].style.backgroundColor = "";
		column3[hole].style.backgroundColor = "";
		column4[hole].style.backgroundColor = "";
		column5[hole].style.backgroundColor = "";
	}
}

function mOverHole(e,value) // NAV MOUSEOVER & MOUSEOUT
{
	if(navigator.appName != 'Microsoft Internet Explorer')
		e = e.target;
	else
		e = window.event.srcElement;

	if(value == 1) {
		e.style.cursor = "pointer";
		
		if (e.parentNode.tagName == "TR")
			e.style.backgroundColor = "#DED8B8";
		else
			e.parentNode.style.backgroundColor = "#DED8B8";
			
	}
	else {
		e.style.cursor = "default";
		
		if (e.parentNode.tagName == "TR")
			e.style.backgroundColor = "";
		else
			e.parentNode.style.backgroundColor = "";
	}
}

// MOVIE GALLERY ///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

function playMovie(movie) // MOVIE POPUP
{
	var wSize =	320;
	var hSize =	308;
	var LeftPos = (( window.screen.availWidth - wSize) / 2);
	var TopPos = (( window.screen.availHeight - hSize) / 2);
	var videoLink = "../videos/"+ getCookie("lang") + movie + ".html";
		
	window.open( videoLink, "movie", "height="+hSize+", width="+wSize+", top=" + TopPos + ", left=" + LeftPos + ", menubar=0, location=0, resizable=0, status=0, titlebar=0");
}

function playPopupMovie(movie) // MOVIE NAVIGATION
{
	window.location = getCookie("lang") + movie + ".html";
}

function playOverMovie(value) // MOVIE NAVIGATION MOUSEOVER & MOUSEOUT
{	
	if(navigator.appName != 'Microsoft Internet Explorer')
		e = e.target;
	else
		e = window.event.srcElement;

	if(value == 1) {		
		e.style.cursor = "pointer";
		e.style.backgroundColor = "#F7F6EE";
	}
	else {
		e.style.cursor = "default";
		e.style.backgroundColor = "";		
	}
}

// PICTURE GALLERY /////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

var gallerySelect = 1;
var galleryLast = 1;

function playGallery(gallery) // MOVIE POPUP
{
	setCookie("gallery", gallery);
	
	var wSize =	622;
	var hSize =	525;
	var LeftPos = (( window.screen.availWidth - wSize) / 2);
	var TopPos = (( window.screen.availHeight - hSize) / 2);
	var videoLink = "gallery/"+ gallery + ".html";
		
	window.open( videoLink, "gallery", "height="+hSize+", width="+wSize+", top=" + TopPos + ", left=" + LeftPos + ", menubar=0, location=0, resizable=0, status=0, titlebar=0");
}

function showOverGallery(e) // GALLERY MOUSEOVER
{
	if(navigator.appName != 'Microsoft Internet Explorer')
		e = e.target;
	else
		e = window.event.srcElement;

	e.setAttribute("oldBG", e.style.backgroundColor);
	e.setAttribute("oldColor", e.style.color);
	
	e.style.cursor = "pointer";
	e.style.backgroundColor = "#F7F6EE";
	e.style.color = "#454545";
}

function showOutGallery(e) // GALLERY MOUSEOUT
{
	if(navigator.appName != 'Microsoft Internet Explorer')
		e = e.target;
	else
		e = window.event.srcElement;

	e.style.backgroundColor = e.getAttribute("oldBG");
	e.style.color = e.getAttribute("oldColor");
}

function nextGallery() // NEXT GALLERY
{
	if(gallerySelect == galleryItems)
		showGallery(1);
	else
		showGallery(gallerySelect + 1);
}

function showGallery(i) // GALLERY DISPLAY
{
	galleryLast = gallerySelect;
	gallerySelect = i;	
	
	var rowSelect = gallleryGrid.rows;	
	if (i <= 30) {
		var columnSelect = rowSelect[0].cells;
		o = i - 1;
	}
	else {
		var columnSelect = rowSelect[1].cells;
		o = i - 31;
	}
	
	var rowLast = gallleryGrid.rows;	
	if (galleryLast <= 30) {
		var columnLast = rowLast[0].cells;
		l = galleryLast - 1;
	}
	else {
		var columnLast = rowLast[1].cells;
		l = galleryLast - 31;
	}

	document.gallery.src =  "../../images/gallery/" + getCookie("gallery") + "/" + i + ".jpg";	

	columnSelect[o].style.backgroundColor = "#F59210";
	columnSelect[o].style.color = "#FFFFFF";	
	columnSelect[o].setAttribute("oldOut", columnSelect[o].getAttribute("onmouseout"));
	columnSelect[o].setAttribute("oldOver", columnSelect[o].getAttribute("onmouseover"));
	columnSelect[o].setAttribute("onmouseout","");
	columnSelect[o].setAttribute("onmouseover","");	
	
	columnLast[l].style.backgroundColor = "#666666";
	columnLast[l].style.color = "#FFFFFF";
	columnLast[l].setAttribute("onmouseout", columnSelect[o].getAttribute("oldOut"));
	columnLast[l].setAttribute("onmouseover", columnSelect[o].getAttribute("oldOver"));	
}