// Jquery section
var $j = jQuery.noConflict();
jQuery(document).ready( function() {
	$j('.helpDialog').hide();
	$j('.cancel').click( function(e) {
		if (!confirm("Are you sure you want to cancel?")) {
			e.preventDefault();
		}
	});
	$j('.datagrid').click( function(e) {
		var eventTarget = e.target;
		if (eventTarget.tagName == 'A') {
			var parent = eventTarget.parentNode;
			if(parent.className == 'cancel')
			{
				if (!confirm("Are you sure you want to cancel?")) {
					e.preventDefault();
				}
			}
		}
	});
	//$j('img.tips').cluetip({sticky: true, activation: 'hover', splitTitle: '|', closePosition: 'title', closeText: '<img src="/images/close.png" alt="close" />'});
	$j('img.tips').cluetip({sticky: true, activation: 'hover', width: 400, closePosition: 'title', closeText: '<img src="/images/close.png" alt="close" />'});
    $j('div.h2_accordion').accordion({header: 'h2', collapsible: true, active: false, clearStyle: true});
    $j('div.h3_accordion').accordion({header: 'h3', collapsible: true, active: false, clearStyle: true});
    
    // Fast book goalie eligibility listing
    $j('#imm_eligible .eligible').hide();
    var eligible = $j('#imm_eligible .eligible').get(0)
    if(eligible != null)
    {
    	showEligible();
    }
    $j('#immediate_hire_form .form_row').change(function() {
    	showEligible();
    });
    // open gigs ticker
    var newsList = $j(".open_gigs_ticker ul").get(0);
	if(newsList != null && newsList.childElementCount > 5)
	{
	$j(".open_gigs_ticker").jCarouselLite({
		vertical: true,
		hoverPause:true,
		visible: 5,
		auto:1000,
		speed:1000
	});
	}
    // Avoid double submit on forms
	$j('form').submit(function(){  
		     $j(':submit', this).click(function() {  
		         return false;  
		     });  
		 });
    
});

var clearedSearch = false;


function showEligible()
{
    $j('#imm_eligible .eligible').hide();
	var rating = $j('#imm_reservation_immediate_min_rating').get(0).value;
	var level = $j('#imm_reservation_immediate_level_id').get(0).value;
	var id = '#rating_'+rating+'_level_'+level;
	$j(id).show();
}

function endsWithArr(fullStr, endStrArr) {
	var lower = fullStr.toLowerCase();
	for (x in endStrArr) {
		if (endsWith(lower, endStrArr[x])) {
			return true;
		}
	}
	return false;
}

function endsWith(fullStr, endStr) {
	// Look at the end of FullStr for the substring the size of EndStr
	var fullStrEnd = fullStr.substr(fullStr.length - endStr.length);
	// If it matches, it does end with EndStr
	return fullStrEnd == endStr;
}
