// JavaScript Document

// -------------------------------------------
// will add target to external links (jQuery)
// -------------------------------------------
function externalLinks(){
	$('a[@rel^="external"]').attr('target', '_blank').click(function(){
		hideAmbassador();
	});
}
// -------------------------------------------

// -------------------------------------------
// functions to launch Stay and Play
// -------------------------------------------
function stayandplay() {
	playerwin = window.open("https://secure.guestdesk.com/golf/?ID=365&siteID=golfinsidermb", "newwindow", "height=505,width=800", "toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no");
}




// -------------------------------------------
// 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')
}

function openNew(url){
	myhandle=window.open(url,'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(){
	var urlVars = 'https://secure.guestdesk.com/golf/?ID=365&siteID=golfinsidermb';
	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')
}

	
	active_color = '#000'; 
	inactive_color = '#999';
    $(document).ready(function() {
        $(".Ratingwrapper").each(function(i) {
            var explanationDiv = $(this).find(".explanation");
            var explanationText = $(this).find(".explanationText");
            var hdnField = $(this).find(".explanation >input:hidden");
            var ratingLabel = $(this).find(".ratingLabel");
            var ratingCap = $(this).find(".rating");

            //Hide the radio button labels since we don't need because javascript is enabled
            ratingLabel.hide();

            //Show the rating label we do need.
            ratingCap.show();

            //Hide the explanation section since javascipt is enabled
            explanationDiv.hide();

            //Turn the radio buttons into our stars
            $(this).find(".question").stars({
                captionEl: $(this).find(".caption")
            });

            $(this).find(".question").click(function() {
                var instance = $(this).data("stars");
                $(this).find(".caption");
                hdnField.val(instance.options.value);

                if (instance.options.value == 1 || instance.options.value == 2 || instance.options.value == 3 || instance.options.value == 4) {
                    explanationDiv.show();
                    if (explanationText.val() == "NA") {
                        explanationText.val('').focus();
                    }
                    else {
                        explanationText.focus();
                    }
                }
                else {
                    explanationDiv.hide();
                    explanationText.val("NA");
                }
            });
        });
		
		$("input.default-value").css("color", inactive_color);
		  var default_values = new Array();
		  $("input.default-value").focus(function() {
			if (!default_values[this.id]) {
			  default_values[this.id] = this.value;
			}
			if (this.value == default_values[this.id]) {
			  this.value = '';
			  this.style.color = active_color;
			}
			$(this).blur(function() {
			  if (this.value == '') {
				this.style.color = inactive_color;
				this.value = default_values[this.id];
			  }
			});
		  });
		  
		$(".box").fancybox(); 
		
		$("table.forum tbody tr").hover(function(){
				$(this).addClass('hover');
			}, function() {
				$(this).removeClass('hover');
		});
    });