function insertParam(key, value) {
    key = escape(key); value = escape(value);

    var kvp = document.location.search.substr(1).split('&');

    var i=kvp.length; var x; while(i--) {
        x = kvp[i].split('=');

        if (x[0]==key) {
                x[1] = value;
                kvp[i] = x.join('=');
                break;
        }
    }

    if (i<0) {
    	kvp[kvp.length] = [key,value].join('=');
    }

    //this will reload the page, it's likely better to store this until finished
    document.location.search = kvp.join('&'); 
}

function getSelectedStateId() {
	var countryId = document.getElementById("countryId").value;

	if (countryId > 0) {
		insertParam("countryId", countryId);
		this.form.submit();
	} else {
		return;
	}
}

function getSelectedState(id, ajaxUrl, selectedStateId) {
	
    countryId = document.getElementById('countryId').value;
	address = ajaxUrl + '?countryId=' + countryId + '&countyId=' + selectedStateId;

	$.ajax({
		url: address,
		cache: false,
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getSelectedCountryId() {
	var countyId = document.getElementById("countyId").value;

	if (countyId > 0) {
		insertParam("countyId", countyId);
		this.form.submit();
	} else {
		return;
	}
}

function getTeamByDivision(id, ajaxUrl, teamGenderId, currentTeamId, opponentTeamId) {

    divisionId = document.getElementById('divisionId').value;
	address = ajaxUrl + '?divisionId=' + divisionId + '&opponentTeamId=' + opponentTeamId + '&currentTeamId=' + currentTeamId + '&teamGenderId=' + teamGenderId;

	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getSelectedDivisionId() {
	var countyId = document.getElementById("countyId").value;

	if (countyId > 0) {
		insertParam("countyId", countyId);
		this.form.submit();
	} else {
		return;
	}
}

function getConferencesByDivision(id, ajaxUrl, conferenceGenderId) {
	divisionId = document.getElementById('divisionId').value;
	address = ajaxUrl + '?divisionId=' + divisionId + '&conferenceGenderId=' + conferenceGenderId;

	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getConferencesByDivisionOptions(id, ajaxUrl, divisionId, genderId) {
	address = ajaxUrl + '?divisionId=' + divisionId + '&conferenceGenderId=' + genderId + '&type=options';
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getConferencesByDivisionWithName(id, ajaxUrl, divisionName, conferenceName, conferenceGenderId, teamContainerName, teamName, option) {
	divisionId = document.getElementById(divisionName).value;
	address = ajaxUrl + '?divisionId=' + divisionId  + '&divisionName=' + divisionName + '&conferenceName=' + conferenceName + '&conferenceGenderId=' + conferenceGenderId + '&teamContainerName=' + teamContainerName + '&teamName=' + teamName + "&type=" + option;

	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getConferencesByDivisionNameTop(id, ajaxUrl) {
	divisionId = document.getElementById('divisionId').value;
	genderId = document.getElementById('genderId').value;
	address = ajaxUrl + '?divisionId=' + divisionId + '&conferenceGenderId=' + genderId + '&type=position_top';

	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getTeamsByDivisionWithName(id, ajaxUrl, divisionName, playerGenderId, teamName, option) {
	divisionId = document.getElementById(divisionName).value;
	address = ajaxUrl + '?divisionId=' + divisionId + '&playerGenderId=' + playerGenderId + '&teamName=' + teamName + "&type=" + option;
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getTeamsByDivisionAndConfWithName(id, ajaxUrl, divisionName, conferenceName, playerGenderId, teamName, option) {
	divisionId = document.getElementById(divisionName).value;
	conferenceId = document.getElementById(conferenceName).value;
	address = ajaxUrl + '?divisionId=' + divisionId  + '&divisionName=' + divisionName + '&conferenceId=' + conferenceId  + '&conferenceName=' + conferenceName + '&playerGenderId=' + playerGenderId + '&teamName=' + teamName + "&type=" + option;
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}


function resetClgDirConf() {
	$("#conferenceId").html("<option value=\"\">Select Conference</options>");
}

function getClgDirConf() {
	if ($("#divisionId").val() == "") {
		resetClgDirConf();
	} else {
		$("#conferenceId").attr("disabled","disabled");
		$.ajax({
			url: '/ajax/getConferencesByDivision.jsp?divisionId=' + $("#divisionId").val() + '&conferenceGenderId=' + $("#genderId").val() + '&type=options',
			cache: false,                                                                                                                
			success: function(html) {
				$("#conferenceId").html("<option value=\"\">Select Conference</options>" + html);
				$("#conferenceId").removeAttr("disabled");
			}
		});
	}
	return false;
}

function getClubsByRegion(id, ajaxUrl, regionId) {
	var regionId = ((document.getElementById('regionId')!=null)?document.getElementById('regionId').value:regionId);

	address = ajaxUrl + '?regionId=' + regionId;
	
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getTeamsByClub(id, ajaxUrl) {
	
	clubId = ((document.getElementById('clubId')!=null)?document.getElementById('clubId').value:0);
	groupId = ((document.getElementById('groupId')!=null)?document.getElementById('groupId').value:0);
	genderId = ((document.getElementById('genderId')!=null)?document.getElementById('genderId').value:'');

	address = ajaxUrl + '?clubId=' + clubId + '&groupId=' + groupId + '&genderId=' + genderId;

	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getAgeGroupsByGender(id, ajaxUrl, genderId) {
	genderId = ((document.getElementById('genderId')!=null)?document.getElementById('genderId').value:'');
	address = ajaxUrl + '?genderId=' + genderId;
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getAgeGroupsByGenderNameTop(id, ajaxUrl) {
	genderId = document.getElementById('genderId').value;
	address = ajaxUrl + '?genderId=' + genderId + '&type=position_top';

	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function pausecomp(ms) {
ms += new Date().getTime();
while (new Date() < ms){}
} 

function getSelectRegionByStateId(id, ajaxUrl) {
	regionId = ((document.getElementById('regionId')!=null)?document.getElementById('regionId').value:'');
	countyId = ((document.getElementById('countyId')!=null)?document.getElementById('countyId').value:'');
	address = ajaxUrl + '?regionId=' + regionId + '&countyId=' + countyId;

	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			regionId = html.trim();
			document.getElementById(id).value = regionId;
			document.getElementById(id).onchange();
		}
	});
}

function getSelectRegionByState(id, ajaxUrl, secondId, secondAjaxUrl) {
	regionId = ((document.getElementById('regionId')!=null)?document.getElementById('regionId').value:'');
	countyId = ((document.getElementById('countyId')!=null)?document.getElementById('countyId').value:'');
	address = ajaxUrl + '?regionId=' + regionId + '&countyId=' + countyId;

	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			regionId = html.trim();
			document.getElementById(id).value = regionId;
			document.getElementById(id).onchange = getClubsByRegion(secondId,secondAjaxUrl);
			document.getElementById(id).onchange();
		}
	});
}

function getStatesByRegion(id, ajaxUrl) {
	regionId = ((document.getElementById('regionId')!=null)?document.getElementById('regionId').value:'');
	//countyId = ((document.getElementById('countyId')!=null)?document.getElementById('countyId').value:'');
	//address = ajaxUrl + '?regionId=' + regionId + '&countyId=' + countyId;
	address = ajaxUrl + '?regionId=' + regionId;
	//alert("address=" + address);
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}

function getStatesByRegionNameTop(id, ajaxUrl) {
	regionId = ((document.getElementById('regionId')!=null)?document.getElementById('regionId').value:'');
	//countyId = ((document.getElementById('countyId')!=null)?document.getElementById('countyId').value:'');
	//address = ajaxUrl + '?regionId=' + regionId + '&countyId=' + countyId;
	address = ajaxUrl + '?regionId=' + regionId + '&type=position_top';
	//alert("address=" + address);
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			document.getElementById(id).innerHTML = html;
		}
	});
}


function resetClgDirDivs() {
	$("#divisionId").html("<option value=\"\">Select Division</options>");
	$("#conferenceId").html("<option value=\"\">Select Conference</options>");
}

function getClgDirDivs() {
	if ($("#genderId").val() == "") {
		resetClgDirDivs();
	} else {
		resetClgDirConf();
		$("#divisionId").attr("disabled","disabled");
		$.ajax({
			url: '/ajax/getDivisions.jsp',
			cache: false,                                                                                                                
			success: function(html) {
				$("#divisionId").html("<option value=\"\">Select Division</options>" + html);
				$("#divisionId").removeAttr("disabled");
			}
		});
	}
	return false;
}

function loadScoresTop(divisionId, genderId) {
	$.ajax({
		url: '/ajax/getScoreboardTopScores.jsp?divisionId=' + divisionId + '&genderId=' + genderId,
		cache: false,                                                                                                                
		success: function(html) {
			$("#wrap").html(html);
		    jQuery('#mycarousel').jcarousel();
		}
	});
}

function loadScoresTopLink(divisionId, genderId) {
	$.ajax({
		url: '/ajax/getScoreboardTopLink.jsp?divisionId=' + divisionId + '&genderId=' + genderId,
		cache: false,                                                                                                                
		success: function(html) {
			$("#completeScoreboard").html(html);
		}
	});
}

function setTab(tabname) {
	$('.divtab').removeClass('divtabsel');
	$('#divtab'+tabname).addClass('divtabsel');
}

$(function() {
$('.divtab').mouseover(function(){
	$(this).addClass('divtabhover');
}).mouseout(function(){
	$(this).removeClass('divtabhover');
});
});

function loadHomeConfereceStandigs() {
	divisionId = document.getElementById('defaultDivisionId').value;
	conferenceId = document.getElementById('standingsConferenceId').value;
	genderId = document.getElementById('standingsGenderId').value;
	
	address = '/ajax/getHomeConferenceStandings.jsp?divisionId=' + divisionId + '&standingsConferenceId=' + conferenceId + '&standingsGenderId=' + genderId;
	
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			$("#homeConfStandings").html(html);
		//	$("#headerLink").html("College Conference Standings <a href=\"" + response.encodeURL("/college/conferencestandings/?genderId=" + standingsGenderId) + "\">Click Here To View the Full List</a>");
		}
	});
}

function loadClgPlayersTop100(divisionId, genderId, classId) {
	
	address = '/ajax/getClgHomePlayersTop100.jsp?topDivisionId=' + divisionId + '&topGenderId=' + genderId + '&topClassId=' + classId;
	
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			$("#topWrap").html(html);
		}
	});
}


function setClgTopTab(tabname) {
	$('.tabTip4').removeClass('tabTip4Selectat');
	$('#tab'+tabname).addClass('tabTip4Selectat');
}

/* home new featured article module */

function positionOverlay(tabnr) {
	//functii de calcul pentru text-overlay
	inaltime = $("#mod_tab"+tabnr+" #over_2 h3").height() + $("#mod_tab"+tabnr+" #over_2 div").height() + 26;
	inaltime_text = inaltime +"px";
//	top_text = (-inaltime-26) + "px";
	top_text = (-inaltime) + "px";
	$("#mod_tab"+tabnr+" #over_1").css({top:top_text, height:inaltime_text});
}

function calc(modtab)
{
	switch (modtab){
		case 'stories':	tabnr = 1; break; 
		case 'videos':	tabnr = 3; break;
		case 'rankings':tabnr = 2; break;
		case 'discover':tabnr = 4; break;
		case 'popular':tabnr = 4;  break;
	}

	inaltime = $("#mod_tab"+tabnr+" #over_2 h3").height() + $("#mod_tab"+tabnr+" #over_2 div").height() + 26;
	inaltime_text = inaltime +"px";
	top_text = (-inaltime) + "px";
	$("#mod_tab"+tabnr+" #over_1").css({top:top_text, height:inaltime_text});
}

function showFeaturedNews(topId,sectionid,isvideo,modtab) {
	
	$('#featured_items_'+modtab+' .carotier').removeClass('featured_carot_active');
	$('#featured_items_'+modtab+' .carotier').addClass('featured_carot');
	$('.c'+topId).addClass('featured_carot_active');
	
//	address = '/?option=com_ajax&task=module&command=tds_featured_article&isClick=1&topId=' + topId + '&sectionid=' + sectionid + '&isvideo=' + isvideo + '&modtab=' + modtab;
	address = '/ajax/getHomeCollegeFeaturedArticles.jsp?topId=' + topId + '&sectionid=' + sectionid + '&isvideo=' + isvideo + '&modtab=' + modtab;

    $.ajax({
		url: address,
		cache: false,
		success: function(html){
			id = 'featured_top_' + modtab;
            if (document.getElementById) {
                document.getElementById(id).innerHTML = html;
            }
            else {
                if (document.layers) { // Netscape 4
                        document.id.innerHTML = html;
                }
                else { // IE 4
                        document.all.id.innerHTML = html;
                }
            }
			setTimeout('calc("'+modtab+'")',0);
      }
    });

	
}
var topfeaturedtabIDS=new Array('mod_tab1','mod_tab2','mod_tab3','mod_tab4');
var	player = null;

function switchFeaturedTab(id,nrtabs){hideallF(nrtabs); showF(id);resetallT(nrtabs);activateT(id);}
function stateListener(obj) { 
    currentState = obj.newstate; 
    var tmp = document.getElementById("statId");
    if (tmp) { tmp.innerHTML = "state: " + currentState; }
}

function hideallF(nrtabs){
	for (var i=0;i<nrtabs;i++)
		{hideF(topfeaturedtabIDS[i]);
		}
	//player=document.getElementById('thePlayer');
	//zplayer = player.id;
	//player.sendEvent('STOP');
}
function resetallT(nrtabs){for (var i=1;i<=nrtabs;i++){
	tabid="featured_tab_"+i;document.getElementById(tabid).className='featured_tab';
	separatorid = "featured_separator_"+i;document.getElementById(separatorid).className='featured_tab_separator';}}
	
function activateT(id){
	var tabnr=id.substring(id.length-1,id.length);
	tabid="featured_tab_"+tabnr;document.getElementById(tabid).className='featured_tab_selected';
	separatorid = "featured_separator_"+tabnr;document.getElementById(separatorid).className='featured_tab_separator_selected';
	//alert (tabnr);
		//functii de calcul pentru text-overlay
	inaltime = $("#mod_tab"+tabnr+" #over_2 h3").height() + $("#mod_tab"+tabnr+" #over_2 div").height() + 26;
	inaltime_text = inaltime +"px";
//	top_text = (-inaltime-26) + "px";
	top_text = (-inaltime) + "px";
	$("#mod_tab"+tabnr+" #over_1").css({top:top_text, height:inaltime_text});
	}
	
function hideF(id) {
	if (document.getElementById) {document.getElementById(id).style.display = 'none';}
    else {if (document.layers) {document.id.display = 'none';}
    else {document.all.id.style.display = 'none';}}}
function showF(id) {if (document.getElementById) {document.getElementById(id).style.display = 'block';}
    else {if (document.layers) {document.id.display = 'block';}
    else {document.all.id.style.display = 'block';}}} 
 
/* end home new featured article module */


function loadClgRanks(divisionId, genderId) {
	
	address = '/ajax/getCollegeHomeRankings.jsp?ranksDivisionId=' + divisionId + '&ranksGenderId=' + genderId;
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			$("#rankingsWrap").html(html);
		}
	});
}


function setClgRanksTab(tabname) {
	$('.tabTip3').removeClass('tabTip3Selectat');
	$('#rankTab'+tabname).addClass('tabTip3Selectat');
}

function setBracketsTab(tabname) {
	$('.bracketTab').removeClass('bracketTabSelected');
	$('#bracketTab'+tabname).addClass('bracketTabSelected');
}

function loadCollegeBrackets(divisionId, genderId, divName) {

	address = '/ajax/getCollegeBrackets.jsp?divisionId=' + divisionId + '&genderId=' + genderId + '&divName=' + divName;
	
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			$("#bracketsWrap").html(html);
		}
	});
}
/*
$(function() {
$('.bracketTab').mouseover(function(){
	$(this).addClass('bracketTabHover');
}).mouseout(function(){
	$(this).removeClass('bracketTabHover');
});
});
*/

function setClubPlayersTopTab(maintabname, gender, secondtabname) {
	$('.tabClubTop').removeClass('tabTip5Selectat');
	$('#tabTop'+maintabname).addClass('tabTip5Selectat');
	
	$('.tabGrady').removeClass('tabTip4Selectat');
	$('#'+gender+'TabYear'+secondtabname).addClass('tabTip4Selectat');
}

function loadClubPlayersTop100(genderId, grady) {
	
	address = '/ajax/getClubHomePlayersTop100.jsp?topGenderId=' + genderId + '&grady=' + grady;
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			$("#topWrap").html(html);
		}
	});
}

function setCommTab(tabname) {
	$('.tabComm').removeClass('tabTip5Selectat');
	$('#tabComm'+tabname).addClass('tabTip5Selectat');
}

function loadHomeCommitments(genderId) {
	
	address = '/ajax/getClubHomeCommitments.jsp?commGenderId=' + genderId;
	
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			$("#commitmentsWrap").html(html);
		}
	});
}

function setClubRanksTopTab(maintabname, gender, secondtabname) {
	$('.rankTab').removeClass('tabTip5Selectat');
	$('#rankTab'+maintabname).addClass('tabTip5Selectat');
	
	$('.tabAgeGroup').removeClass('tabTip4Selectat');
	$('#'+gender+'TabAge'+secondtabname).addClass('tabTip4Selectat');
}

function loadClubRanksTop50(genderId, groupId) {
	
	address = '/ajax/getClubHomeTeamsRankings.jsp?topGenderId=' + genderId + '&groupId=' + groupId;
	$.ajax({
		url: address,
		cache: false,                                                                                                                
		success: function(html) {
			$("#rankingsWrap").html(html);
		}
	});
}

function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
document.getElementById(d).style.display = "none"; 
}

function showHideContent(start, name, d, end) {
if(d.length < 1) { return; }

	for (i=start; i <=end; i++) {
		document.getElementById(name + i).style.display = "none";
	}
	
	if(document.getElementById(name + d).style.display == "none") { document.getElementById(name + d).style.display = "block"; }
	
}


function setHomePlayersTabs(maintabname, gender, secondtabname) {
	$('.tabTop').removeClass('tabTip5Selectat');
	$('#tabTop'+maintabname).addClass('tabTip5Selectat');
	
	$('.tabGrady').removeClass('tabTip4Selectat');
	$('#'+gender+'TabYear'+secondtabname).addClass('tabTip4Selectat');	
	
	$('.tabClg').removeClass('tabTip6Selectat');
	$('#'+gender+'Clg'+secondtabname).addClass('tabTip6Selectat');
	
}
