/* Create the Accordion */

jQuery().ready( function() {

	if (profile_owner) {
		doSortables();
	}

});

var genMod = null;


function searchClubActv(){
	var _query = $('#facebox').find('#club_search_actv').val();
	location.href = "/search?query="+_query+"&catOnly=clubs&pg=1";
}

/* Autocompleter code */

function rc_formatItem(row) {
	return row[0];
}

function rc_formatResult(row) {
	return row[0].replace(/(<.+?>)/gi, '');
}

/*
 * autocompleter for edit
 */
function regClubAutoCompleter(_elem, _id, _key) {
	$(_elem).autocomplete('scripts.php?script=predictiveSearch&cat=club', {
		width :290,
		max :50,
		minChars :2,
		cacheLength :0,
		multiple :false,
		matchContains :false,
		formatItem :rc_formatItem,
		formatResult :rc_formatResult
	});

	$(_elem).result( function(event, data, formatted) {
		var _name 	= data[0];
		var _type 	= data[1];
		var _id 	= data[2];
		/* populate dropdown */
		if (_id){
			$('#club_id').val(_id);
			regFindTeams(_id);
		}
		//console.log(data);
		
		$(_elem).keyup(function(me) {
			//regFindTeams(0);
	    });

	});
}


/* 
 * Get the team dropdown for the selected club  
 */
function regFindTeams(_id){
	$.ajax({
		type: 	'POST',
		url: 	'scripts.php?script=getClubTeams',
		data:	'club_id='+_id,
		success: function(html){
			$('#team_selector').html(html);
		}
	});
}

function checkAge()
{
	
	/* the minumum age you want to allow in */
	var min_age 		= 13;
	var youthEndAge 	= 18;
	var year 			= parseInt($('#dob_year').val()); 
	var month 			= parseInt($('#dob_month').val() - 1); 
	var day 			= parseInt($('#dob_day').val()); 
	var theirDate 		= new Date((year + min_age), month, day);	
	var today 			= new Date();
	var isYouth 		= (today.getTime() - new Date((year + youthEndAge), month, day) < 0) ? 1:0;
	
    if(year != NaN && year != "undefined" && year > 0)
    {
    	if ( !theirDate.getTime() || (today.getTime() - theirDate.getTime()) < 0) { 
    		//$('#notify_content').html("<div style='text-align:left'> Goalrun does not knowingly collect or solicit personal information from anyone under the age of 13 or knowingly allow such persons to register. If you are under 13, please do not attempt to register or send any information about yourself to us, including your name, address, telephone number or email address. No one under the age of 13 may provide any personal information to or on Goalrun. In the event that we learn that we have collected personal information from a child under the age of 13 without verification of parental consent, we will delete that information as quickly as possible. If you believe that we might have any information from or about a child under the age of 13, please contact us through the Site Feedback Button at the bottom of the page.</div>");
    		 $('#notify_content').html("<div style='text-align:left'> Goalrun does not knowingly collect or solicit personal information. <br/>Persons under the age of 13 should not attempt to register with the site or send any information without prior parental consent. <br/><br/>For more information click to see a full breakdown of <a class='grLink' style='text-decoration:underline;' href='/legal?privacy'>Goalrun site policy</a>.</div>");
    		
            modal_base.init("error", "Children aged under 13", "#notification", "Explore", exploreNow);
    		return false;
    	}
    	
    	if (isYouth) {
    		alert("We recommend that minors 13 years of age or older ask their parents for permission before sending any information about themselves to anyone over the Internet.");		
    	}
    }
   
	
	return true;
};


function exploreNow(){
	location.href = "/search";
};
function ShowMatchesExtraInfo(element)
{
    var root = GetParentbyClass(element,"AppWrapper");
     if($(element).attr("class") == "matchCentreRightButtonClosed")
    {
        $(element).attr("class","matchCentreRightButtonOpen");
        $(root).find(".result_fixture_header").show();                   
    }
    else
    {
       $(element).attr("class","matchCentreRightButtonClosed"); 
       $(root).find(".result_fixture_header").hide();         
    }
    
};
function filterNews(id)
{
    var urlBase = "index?news";
    if(id == "#")
        location.href = urlBase;
    else
    {
        var info = id.split('|');
        var cid = info[0];
        var tid = info[1];
        var mdbcid = info[2];
        location.href = urlBase + "&cid=" + cid + "&tid=" + tid + "&mdbcid=" + mdbcid;
    }
}
