function callChangePage(pageCount) {
	var textField = document.getElementById("gridPageIndex");
	var textFieldValue = parseInt(textField.value);
	
	if((textFieldValue != null) && (textFieldValue >=1) && (textFieldValue <= pageCount))
	{
	
		urlString = window.location.href;
		var index = urlString.indexOf("&page=");
	
		if(index > 1)
		{
	
			var PageValueToReplace = urlString.substring(index);
			var PageValueReplacewith = PageValueToReplace.substring(0, (PageValueToReplace.indexOf('='))+1);
			PageValueReplacewith = PageValueReplacewith + textFieldValue;
			urlString = urlString.replace(PageValueToReplace, PageValueReplacewith);
	
		}
		else // The case is; query string not contains the page, so add it.
		{
			if(urlString.indexOf("?") < 1 )
			{
				urlString = urlString + '?';
			}
			urlString = urlString + '&page=' + textFieldValue;
	
		}
	
		window.location.href = urlString;
	}
	else
	{
	
		// Display the warning message if the page number not in correct range.
		alert('Page index should be in the range of 1 to ' + pageCount);
	
	}
	return true;
}

// This function is being used for the admin section
// to pass the sport drop down selected value to the 
// current URL.
function adminSportChange(dropdown_adminSport) {
	
	var sportIndex  = dropdown_adminSport.selectedIndex;    
	var SelectedValue = dropdown_adminSport.options[sportIndex].value;
	var url = window.location.toString();
	var qs = url.split("?");
	var queryData = parseQueryString(qs[1]);
	var newQs = qs[0] + '?';
	var done = 0;
	for (var key in queryData){
		if (key == 'adminSport') {
			newQs += 'adminSport=' + SelectedValue + ';';
			done = 1;
		} else {
			if (key != '') {
				newQs += key + '=' + queryData[key][0] + ';';
			}
		}
	}
	if (done != 1) {
		newQs += 'adminSport=' + SelectedValue;
	}
	window.location.href = newQs;
	return true;
}

/* parseQueryString.js - a function to parse and decode query strings
 *
 * The author of this program, Safalra (Stephen Morley), irrevocably releases
 * all rights to this program, with the intention of it becoming part of the
 * public domain. Because this program is released into the public domain, it
 * comes with no warranty either expressed or implied, to the extent permitted
 * by law.
 *
 * For more public domain JavaScript code by the same author, visit:
 * http://www.safalra.com/web-design/javascript/
 */

function parseQueryString(_1){var _2={};if(_1==undefined){_1=location.search?location.search:"";}if(_1.charAt(0)=="?"){_1=_1.substring(1);}_1=_1.replace(/\+/g," ");var _3=_1.split(/[&;]/g);for(var i=0;i<_3.length;i++){var _5=_3[i].split("=");var _6=decodeURIComponent(_5[0]);var _7=decodeURIComponent(_5[1]);if(!_2[_6]){_2[_6]=[];}_2[_6].push((_5.length==1)?"":_7);}return _2;}

function ajax_college_search_url(field, querystring) {
	return querystring + "&sport_id=" + $F('sport_id');
}

function GenerateRandomString(stringlength) {
	var keylist="abcdefghijklmnopqrstuvwxyz123456789"
	var random='';
	for (i=0;i<stringlength;i++)
	random+=keylist.charAt(Math.floor(Math.random()*keylist.length))
	var textField = document.getElementById("coupon_code");
	textField.value = random;
}

function toggleCouponCodeRow(dropdown_coupontype) {
	var sportIndex  = dropdown_coupontype.selectedIndex;    
	var SelectedValue = dropdown_coupontype.options[sportIndex].value;
	if( SelectedValue == 'public'){
		document.getElementById('row_couponcode').style.display = '';
	} else {
		document.getElementById('row_couponcode').style.display = 'none';
	}
    
    if( SelectedValue == 'standing'){
        document.getElementById('row_recipient_emails').style.display = '';
    } else {
        document.getElementById('row_recipient_emails').style.display = 'none';
    }
	return true;
}

function validatePhone (phone) {
	var isvalid = false;
	// International format
	var regex = /^\+(?:[0-9] ?){6,14}[0-9]$/;
	if (regex.test(phone)) {
		isvalid = true;
	}
	// US formats, options 1 at beginning
	var regex = /^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
	if (regex.test(phone)) {
		isvalid = true;
	}
	return isvalid;
}