//--------------------------------------------------
// Tracking for GWO
//--------------------------------------------------
if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+
(document.location.protocol=='https:'?'s://ssl':'://www')+
'.google-analytics.com/ga.js"></sc'+'ript>')

function TrackGWOConversion()
{        
    // DRTV prompts    
    try {
        var gwoTracker=_gat._getTracker("UA-32175-35");
	gwoTracker._trackPageview("/1323560371/goal");
    }catch(err){}       
}

//--------------------------------------------------
// GA Event tracking
//--------------------------------------------------
function TrackGAEvent(type)
{   
    var iAmount = 0;
    
    if (type == "DD") {
    	if ($('#amountOtherDD').is(":checked")) {
    	    iAmount = $('#other_amountDD').val();
    	} else {
    	    iAmount = $("#add_to_cartDD input[name='amount']:checked").val();
    	}
    	iAmount = iAmount * 12;
    }
        
    
    if (type == "CC") {
    	if ($('#amountOtherCC').is(":checked")) {
	    iAmount = $('#other_amountCC').val();
	} else {
	    iAmount = $("#add_to_cartCC input[name='amount']:checked").val();
    	}
    }
               
    var sLabel = "Standard Form (no extra message)";
    if ($('p.ask').length > 0) { 
    	sLabel = $('p.ask').html();
    }
    
    if (pageTracker) {
	pageTracker._trackEvent("Form Submit", "DRTV Price Prompt Test", sLabel, iAmount);
    }       
}


//--------------------------------------------------
// DRTV Test Tracking (used in 4 x places below)
//--------------------------------------------------
function TrackDRTVTest(type)
{        
    TrackGWOConversion();
    TrackGAEvent(type);
}


//--------------------------------------------------
// Selects correct radio button on focus of other text input
// Adds validation to the form
// requires jquery for the selectors
// $(document).ready is a jquery function for after page has loaded
//--------------------------------------------------
$(document).ready(
function ()
{		
    // focus DD
    $("#other_amountDD").focus(function () {    	
        $('#amountOtherDD').prop('checked', true);
    });
    
    // focus CC
    $("#other_amountCC").focus(function () {
        $('#amountOtherCC').prop('checked', true);
    });
    
    
    // valiation DD
    $("#add_to_cartDD").submit(function() {
      
      if ($('#amountOtherDD').is(":checked")) {
        if ($('#other_amountDD').val() >= 3) {                
           return true;
        }        
        $('#other_amountDD').css("border", "1px solid #F00");
        $('.overlabel').css({"font-weight" : "bold", "color" : "#F00"});
        return false;
      }            
      return true;
    });
    
    // valiation CC
    $("#add_to_cartCC").submit(function() {
          
          if ($('#amountOtherCC').is(":checked")) {
            if ($('#other_amountCC').val() >= 36) {                   
               return true;
            }        
            $('#other_amountCC').css("border", "1px solid #F00");
            $('.overlabel').css({"font-weight" : "bold", "color" : "#F00"});
            return false;
          }           
          return true;
    });
    
    
    // only show these links for JS is enabled
    $("#donation_switch_to_DD").css("display", "block");
    $("#donation_switch_to_CC").css("display", "block");
    
    // hide this initially
    $("#one-off_donation").addClass("hide_form");
    
    // add functions to links
    $("#link_switch_to_CC").click(function () {
            $("#regular_donation").addClass("hide_form");
            $("#one-off_donation").removeClass("hide_form");                       
    });
    
    $("#link_switch_to_DD").click(function () {                        
            $("#one-off_donation").addClass("hide_form");
            $("#regular_donation").removeClass("hide_form");
    });        
}
)
