// JavaScript Document

// -------------------------------------------
// will add target to external links (jQuery)
// -------------------------------------------
function externalLinks(){
	$('a[@rel^="external"]').attr('target', '_blank').click(function(){
		hideAmbassador();
	});
}
// -------------------------------------------

// -------------------------------------------
// coupons page popup
// -------------------------------------------
function setUpCouponPopup(){
	$('a.coupon').click(function(){
		var dimensions = new Array();
		dimensions = $(this).attr('rel').split('-');
		window.open(this.href,'viewer','width='+dimensions[0]+',height='+dimensions[0]);
		return false;
	});
}
// -------------------------------------------

// -------------------------------------------
// will close the "talking head" online ambassador (jQuery)
// -------------------------------------------
function hideAmbassador(){
	$("#onlineAmbassador_wrap").slideUp("slow");
}
// -------------------------------------------

// -------------------------------------------
// functions to launch MULTICAST Player
// -------------------------------------------
function launchPlayer(hashCode) {
	playerwin = window.open("http://vidego.multicastmedia.com/player.php?v=" + hashCode, "newwindow", "height=504,width=869", "toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no");
}

// -------------------------------------------

// -------------------------------------------
// functions to launch tee times app
// -------------------------------------------
var myhandle=null;

function checkit(UID,SiteID,PID,RedLine) {
// This function is used to close any open tee time windows, then open a new window for the tee time app to prevent application var problems
	if(myhandle && !(myhandle.closed)) {
 		//alert('Window is open - closing');
 		myhandle.close();
 		openit(UID,SiteID,PID,RedLine);
	} else {
 		//alert('Window is closed - opening');
 		openit(UID,SiteID,PID,RedLine);
	}
}
// -------------------------------------------
function openit(UID,SiteID,PID,RedLine,urlCourseID){
	var urlVars = 'https://secure.guestdesk.com/teetimes/?UID='+UID+'&SiteID='+SiteID+'&PID='+PID+'&ShowRedLine='+RedLine;
	if(urlCourseID != undefined){ urlVars += '&urlCourseID='+urlCourseID; }
	myhandle=window.open(urlVars,'windowName','toolbar=no,scrollbars=no,location=no,resizable=no,directories=no,status=yes,menubar=no,width=800,height=505,titlebar=TeeTimes,left=2,top=2')
}

// -------------------------------------------
// functions to launch golf packages app
// -------------------------------------------
function openGolfPackageSystem(ID,siteID,systemType,packageURLID){
	var urlVars = 'https://secure.guestdesk.com/golf/main.cfm?ID='+ID+'&siteID='+siteID+'&systemType='+systemType+'&packageURLID='+packageURLID;
	myhandle=window.open(urlVars,'windowName','toolbar=no,scrollbars=no,location=no,resizable=no,directories=no,status=yes,menubar=no,width=800,height=505,titlebar=GolfPackages,left=2,top=2')
}

// -------------------------------------------
// functions to track through omniture (jQuery)
// -------------------------------------------
$(document).ready(function(){
	externalLinks();
	$('a[@rel*=ImageBox]').lightBox();
	
	if ($('.gilink').length > 0) {
		$('.gilink').click(function(){
			s=s_gi('bambncom');
			s.linkTrackVars = 'prop19';
			s.prop19 = $(this).parent().parent().children(':first').children(':first').html().toLowerCase();
			s.tl(this, 'o', s.prop19);
		});
	}
	
	//remove the email address/zip code from side bar when clicked in there
	if ($('#tmEmail').length > 0) {
		$('#tmEmail').focus(function() {
			if ($(this).val() == 'email address') {
				$(this).val('');
			}
		});
		$('#tmEmail').blur(function() {
			if ($(this).val().length < 1) {
				$(this).val('email address');
			}
		})
	}
	if ($('#tmZip').length > 0) {
		$('#tmZip').focus(function() {
			if ($(this).val() == 'zip code') {
				$(this).val('');
			}
		});
		$('#tmZip').blur(function() {
			if ($(this).val().length < 1) {
				$(this).val('zip code');
			}
		})
	}
});