

/*--------------------------------------

   Scorecard Functions//
    
--------------------------------------*/

function checkScorecard(control)
{
    var myCourse = (control);
    $.ajax(
            {
                type: "POST",
                url: "scorecardExists.php",
                data: "course="+myCourse,
                success: function(msg)
                {
                    $('#toggleScorecard').html(msg);
                }
            });
}

function makeScorecard(control)
{
        var course = (control);
//        var course2 = (course2.value);
//        alert (course);
        $.ajax(
        {
            type: "POST",
            url: "scorecard.php",
            data: "course="+course+"&make=1",
            success: function(msg)
            {
                $('#toggleScorecard').html(msg);
            }
         });

    }    

function hideScorecard(control)
{
/*        var course = (control);
//        var course2 = (course2.value);
//        alert (course);
        $.ajax(
        {
            type: "POST",
            url: "scorecard.php",
            data: "course="+course+"&make=0",
            success: function(msg)
            {
                $('#toggleScorecard').html(msg);
            }
         });
*/
        // If checked
        if ($("#addScore").is(":checked"))
        {
            //show the hidden div
            $("#scorecard").show("fast");
        }
        else
        {     
            //otherwise, hide it
            $("#scorecard").hide("fast");
        }
} 

function killScorecard(control)
{
		if ($("#addScore").is(":checked"))
		{
				//show the hidden div
				$("#scorecard").show("fast");
		}
		else
		{     
				//otherwise, hide it
				alert("This will delete all scorecard information. Are you sure?")
				$("#scorecard").hide("fast");
		}


/*        var course = (control);
//        var course2 = (course2.value);
//        alert (course);
        $.ajax(
        {
            type: "POST",
            url: "scorecard.php",
            data: "course="+course+"&make=0",
            success: function(msg)
            {
                $('#toggleScorecard').html(msg);
            }
         });
*/
        // If checked
}

/*--------------------------------------

    Datepicker
    
--------------------------------------*/

$(document).ready(function() 
{
    $('#roundDate').datepick({rangeSelect: false, numberOfMonths: 2, dateFormat: 'yy-mm-dd'});
});


/*--------------------------------------

    Toggle GIR/Fairway/Putts
    
--------------------------------------*/

function togglePutts(toggle)
{
    if(document.addRound.enableputts.checked)
    {
        for(i=0; i < 18; i++)
        {
            adj = i + 1;
            document.addRound.elements[toggle+'['+adj+']'].disabled=false;
        }
    }
    else
    {
        for(i=0; i < 18; i++)
        {
            adj = i + 1;
            document.addRound.elements[toggle+'['+adj+']'].disabled=true;
            document.addRound.elements[toggle+'['+adj+']'].value='';
        }
    }
}

function toggleFair(toggle)
{
    if(document.addRound.enablefair.checked)
    {
        for(i=0; i < 18; i++)
        {
            adj = i + 1;
            document.addRound.elements[toggle+'['+adj+']'].disabled=false;
        }
    }
    else
    {
        for(i=0; i < 18; i++)
        {
            adj = i + 1;
            document.addRound.elements[toggle+'['+adj+']'].disabled=true;
            document.addRound.elements[toggle+'['+adj+']'].value='';
        }
    }
}

function toggleGir(toggle)
{
    if(document.addRound.enablegir.checked)
    {
        for(i=0; i < 18; i++)
        {
            adj = i + 1;
            document.addRound.elements[toggle+'['+adj+']'].disabled=false;
        }
    }
    else
    {
        for(i=0; i < 18; i++)
        {
            adj = i + 1;
            document.addRound.elements[toggle+'['+adj+']'].disabled=true;
            document.addRound.elements[toggle+'['+adj+']'].value='';
        }
    }
}

/*--------------------------------------

    Toggle Password
    
--------------------------------------*/

function activatePass()
{    
    if(document.updateProfile.updatePass.checked)
    {
        document.updateProfile.userPass.disabled=false;
        document.updateProfile.userPass2.disabled=false;
    }
    
    else
    {
        document.updateProfile.userPass.disabled=true;
        document.updateProfile.userPass2.disabled=true;
    }
}

/*--------------------------------------

    Show hide Checkbox
    
--------------------------------------*/

function showMe (it, box) {
  var vis = (box.checked) ? "block" : "none";
  document.getElementById(it).style.display = vis;
}

/*
$(document).ready(function(){

$("input[type=checkbox]").click(function(){

  if ($(this).is(":checked")) {
      $("#holes").show();
    }
  else if($(this).not(":checked")) {
      $("#holes").hide();
    }
});

});

/*--------------------------------------

    Tips
    
--------------------------------------*/

$(document).ready(function() 
{

        $.fn.qtip.styles.mystyle =
        {
             width: 350,
             'padding': '8px',
             'font-family': 'Arial',
             'font-size': '12px',
             background: '#B3FA6B',
             color: '#006633',
             textAlign: 'left',
             
             border: {
                    width: 2,
                    radius: 2,
                    color: '#6EBF26'
             }
        };

//---- Tip Slope ---- //

$('#mygcSlopeTip').qtip(
    {
   content: 'Slope is a measurement of the difficulty of a course relative to the course rating. Slope ranges from 55 to 155, with an average of 113, and can be found on the score card.',
     position: {
         corner:
         {
                tooltip: 'leftMiddle',
                target: 'rightMiddle'
            }
        },
   style:'mystyle'

     });
     

//---- Tip Course Rating ---- //

$('#mygcRatingTip').qtip(
    {
   content: 'The course rating is an estimation of the difficulty of a golf course and can typically be found on the score card. Values tend to be between 65 and 75.',
     position: {
         corner:
         {
                tooltip: 'leftMiddle',
                target: 'rightMiddle'
            }
        },
   style:'mystyle'

     });


//---- Tip Password ---- //

$('#pass').qtip(
    {
   content: 'Please note that passwords are not encrypted so don\'t use a secure one! Passwords can be a maximum of 20 characters.',
     position: {
         corner:
         {
                tooltip: 'leftMiddle',
                target: 'rightMiddle'
            }
        },
   style:'mystyle'

     }); 

});


/*--------------------------------------

    Form Styles

--------------------------------------*/

$(function(){
$('#Top').jqTransform({imgPath:'jqtranform/jqtransformplugin/img/'});
$('#holes').jqTransform({imgPath:'jqtranform/jqtransformplugin/img/'});
$('#Bottom').jqTransform({imgPath:'jqtranform/jqtransformplugin/img/'});
$('#logmein').jqTransform({imgPath:'jqtranform/jqtransformplugin/img/'});
$('#signup').jqTransform({imgPath:'jqtranform/jqtransformplugin/img/'});
$('#contact').jqTransform({imgPath:'jqtranform/jqtransformplugin/img/'});
$('#signmeup').jqTransform({imgPath:'jqtranform/jqtransformplugin/img/'});
});

/*--------------------------------------

    Fade Out For Success Messages

--------------------------------------*/

$(document).ready(function()
     {
            $("#success").fadeOut(5000);
        });


/*--------------------------------------

    Alert on Delete

--------------------------------------*/

function decision(message, url){
if(confirm(message)) location.href = url;
}


/*--------------------------------------

    Sleek Buttons

--------------------------------------*/


$(document).ready(function(){
    
        // remove link background images since we're re-doing the hover interaction below 
        // (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
        // we also want to only remove the image on non-selected nav items, so this is a bit more complicated
        $(".nav").children("li").each(function() {
            var current = "nav current-" + ($(this).attr("class"));
            var parentClass = $(".nav").attr("class");
            if (parentClass != current) {
                $(this).children("a").css({backgroundImage:"none"});
            }
        });    


        // create events for each nav item
        attachNavEvents(".nav", "home");
        attachNavEvents(".nav", "round");
        attachNavEvents(".nav", "course");
        attachNavEvents(".nav", "profile");
        attachNavEvents(".nav", "roundAdd");
        attachNavEvents(".nav", "courseAdd");    

        function attachNavEvents(parent, myClass) {
            $(parent + " ." + myClass).mouseover(function() {
                $(this).append('<div class="nav-' + myClass + '"></div>');
                $("div.nav-" + myClass).css({display:"none"}).fadeIn(200);
            }).mouseout(function() {
                $("div.nav-" + myClass).fadeOut(200, function() {
                    $(this).remove();
                });
            }).mousedown(function() {
                $("div.nav-" + myClass).attr("class", "nav-" + myClass + "-click");
            }).mouseup(function() {
                $("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
            });
        }



    });

// ----- Change BG and Border on Forms ----- //
/*
        $(document).ready(function() {
            $('input[type="text"]').addClass("idleField");
               $('input[type="text"]').focus(function() {
                   $(this).removeClass("idleField").addClass("focusField");
                if (this.value == this.defaultValue){ 
                    this.value = '';
                }
                if(this.value != this.defaultValue){
                    this.select();
                }
            });
            $('input[type="text"]').blur(function() {
                $(this).removeClass("focusField").addClass("idleField");
                if ($.trim(this.value) == ''){
                    this.value = (this.defaultValue ? this.defaultValue : '');
                }
            });
        });    

        $(document).ready(function() {
            $('input[type="password"]').addClass("idleField");
               $('input[type="password"]').focus(function() {
                   $(this).removeClass("idleField").addClass("focusField");
                if (this.value == this.defaultValue){ 
                    this.value = '';
                }
                if(this.value != this.defaultValue){
                    this.select();
                }
            });
            $('input[type="password"]').blur(function() {
                $(this).removeClass("focusField").addClass("idleField");
                if ($.trim(this.value) == ''){
                    this.value = (this.defaultValue ? this.defaultValue : '');
                }
            });
        });    
*/


