// JavaScript Document

$(function() {
					$("a[rel^='ajax']").click(function () {
																							ajaxCall($(this).attr('rel').substring(5), $(this).attr('href'),1);
																							return false;
																							});
					
					$("#datumSelector").change(function() {
																							val = $(this).val();
																							if (val == '0')
																								return false;
																							window.location = siteURL+'index.php/start/matchesOnDay/' + val;
																							//ajaxCall('matchesList', siteURL+'index.php/start/matchesOnDay/' + val,1);
																							});
});

function ajaxCall(targetStr, href, showLoading, recurse, reltime) {
	try{
		if (showLoading == 1)
			$('#'+ targetStr).html('<div>loading ...</div>');
		
		$.ajax({ 
						url: href,
						complete: function(XMLHttpRequest, textStatus) {
							//alert(XMLHttpRequest.responseText);
							if (XMLHttpRequest.responseText == 'addmymatch') {
								$('#'+ targetStr).html('');
								var matchID = parseInt(targetStr.substring(6));
								$("#addmymatch" + matchID).css({display:'none'});
								return;
							}

							if (XMLHttpRequest.responseText != '')
									$('#'+ targetStr).html(XMLHttpRequest.responseText);
						},
						error: function(XMLHttpRequest, textStatus, errorThrown) {
							//alert(errorThrown + "\n" + textStatus);
						}
					});
		
		
		if (recurse == 1) {
			if (reltime != 'undefined')
				setTimeout("ajaxCall('" + targetStr + "','" + href + "', " + showLoading + ", " + recurse + ", " + reltime + ")",reltime);
			else
				setTimeout("ajaxCall('" + targetStr + "','" + href + "', " + showLoading + ", " + recurse + ",30000)",30000);
		}
		return false;
	} catch(e) {
		
	}
}

function postopneAjaxCall(targetStr, href, showLoading) {
	try {
		//alert(targetStr);
		targetString = targetStr;
		clearInterval(interval);
		interval = setInterval("ajaxCall('"+targetString+"', '"+href+"')", reloadtime);
		return false;
	} catch (e) {
		
	}
}
