function ge(id){return document.getElementById(id);}function arrayLookup(array,keyName,val){for(var i=0;i<array.length;i++){var ret=eval('if(array[i].'+keyName+' == val) array[i]; else null;');if(ret!=null)return ret;}return null;}function subarrayLookup(array,subindex,val){for(var i=0;i<array.length;i++){if(array[i][subindex]==val)return array[i];}return null;}function subarrayBinLookup(array,subindex,val){var low=0;var high=array.length-1;while(low<=high){var aTry=parseInt((low+high)/2);var checkThis=array[aTry][subindex];if(checkThis<val){low=aTry+1;continue;}if(checkThis>val){high=aTry-1;continue;}return array[aTry];}return null;}function arraySelect(array,propertyName,val){var res=new Array();for(var i=0;i<array.length;i++){eval('if(array[i].'+propertyName+' == val) res.push(array[i]);');}return res;}function subarraySelect(array,subindex,val){var res=new Array();for(var i=0;i<array.length;i++){if(array[i][subindex]==val)res.push(array[i]);}return res;}function ArrIndexOf(arr,object){for(var i=0;i<arr.length;i++)if(arr[i]==object)return i;return-1;}function ArrWithout(arr,object){for(var i=0;i<arr.length;i++){if(arr[i]==object)arr.splice(i,1);}}function clearOptions(elem){while(elem.options.length>1){elem.options[1]=null;}}function setVis(elem,vis){if(vis)elem.style.display="";else elem.style.display="none";}function addDays(myDate,days){return new Date(myDate.getTime()+days*24*60*60*1000);}function daysDiff(date1,date2){var ONE_DAY=1000*60*60*24
var date1_ms=date1.getTime()
var date2_ms=date2.getTime()
var difference_ms=Math.abs(date1_ms-date2_ms)
return Math.round(difference_ms/ONE_DAY)}function dateEqual(date1,date2){return(date1.toDateString()==date2.toDateString());}function formatDate(date){return(date.getDate()+"/"+(date.getMonth()+1)+"/"+date.getFullYear());}function formatDateForQS(date){return(date.getDate()+"|"+(date.getMonth()+1)+"|"+date.getFullYear());}function parseDate(date){var parts=date.split("/");if(parts.length==3){if(!isNaN(parts[0])&&!isNaN(parts[1])&&!isNaN(parts[2])){parts[1]--;var test=new Date(parts[2],parts[1],parts[0]);if(test.getDate()==parts[0]&&test.getMonth()==parts[1]&&test.getFullYear()==parts[2])return test;}}return false;}function formatCurrency(num){num=num.toString().replace(/\$|\,/g,'');if(isNaN(num))num="0";sign=(num==(num=Math.abs(num)));num=Math.floor(num*100+0.50000000001);cents=num%100;num=Math.floor(num/100).toString();if(cents<10)cents="0"+cents;for(var i=0;i<Math.floor((num.length-(1+i))/3);i++)num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));return(((sign)?'':'-')+'$'+num+'.'+cents);}function formatPriceRange(priceLow,priceHigh){if(priceLow==priceHigh)return formatCurrency(priceLow);else return formatCurrency(priceLow)+" - "+formatCurrency(priceHigh);}function selectOptionByVal(id,val){var optionElem=ge(id);for(var i=0;i<optionElem.options.length;i++){var opt=optionElem.options[i];if(opt.value==""&&(!val||val==""))opt.selected=true;else if(val&&opt.value==val)opt.selected=true;else opt.selected=false;}}


function Redirecter(URL){
	
	window.location = URL;
	
}

function checkLength(cntrl,errCntrl)
{
	if(cntrl.value.length > 200)
	{
		cntrl.value = cntrl.value.substring(0,200);
		document.getElementById(errCntrl).style.display = 'block';
	}
	else
		document.getElementById(errCntrl).style.display = 'none';
}

function getURLPageName()
{
	var loc = window.location.href; 
	loc = (loc.indexOf('?') != -1)? loc.substring(0,loc.indexOf('?')) : loc;

	return (loc.lastIndexOf("/") != -1) ? loc.substring(loc.lastIndexOf("/")+1) : loc;
}

function RequestQueryString(val)
{
	var loc = window.top.location.href; 
	loc = (loc.indexOf('?') != -1)? loc.substring(loc.indexOf('?')+1,loc.length) : null;
	
	if(loc != null)
	{
		var Query = loc.split("&");
		
		for(i=0;i<=Query.length;i++)
		{
			var splitQuery = Query[i].split("=");
			if(splitQuery.length == 2 && splitQuery[0] == val)
				return Query[i].substring(Query[i].indexOf('=')+1,Query[i].length);
		}
	}
	return loc
}

function getLoginRedirect()
{
	var loc = window.top.location.href;
	loc = (loc.indexOf('?') != -1)? loc.substring(loc.indexOf('?')+1,loc.length) : null;
	
	if(loc != null)
	{
		var Query = loc.split("=");
		
		if(Query[0] == 'returnurl')
		{
			loc = (loc.indexOf('=') != -1)? loc.substring(loc.indexOf('=')+1,loc.length) : '';
			loc = (loc.indexOf('&') != -1)? loc.substring(0,loc.indexOf('&')) + "?" + loc.substring(loc.indexOf('&')+1,loc.length) : loc;
			window.top.location = loc;
		}
		else
			window.top.location = 'matesprofile.aspx';	
	}
	else
		window.top.location = 'matesprofile.aspx';
}

function GLProfileFromPopUp(GolfLinkNo)
{
	var popup = parent.document.getElementById('popupFrame');
	var popupinner = parent.document.getElementById('popupInner');
	
	popup.style.width = '525px';
	popupinner.style.width = '524px';
	
	window.location = 'profile.aspx?glno=' + GolfLinkNo;
}

function ResizeModal(width,height)
{
	parent.document.getElementById('popupFrame').style.width = width + 'px';
	//parent.document.getElementById('popupInner').style.width = width + 'px';
	parent.document.getElementById('popupFrame').style.height = height + 'px';
	//parent.document.getElementById('popupInner').style.height = (height+30) + 'px';
	parent.gPopupContainer.style.width = (width+4) + 'px';
	parent.gPopupContainer.style.height = (height+30) + 'px';
}

function openClubPopup(id)
{
	clubPopup = window.open('ClubPopup.aspx?ClubID='+id,'','width=500,height=400,scrollbars=1');
	if (window.focus) {clubPopup.focus()}
}

function noPostBack(sNewFormAction)
{
    document.forms[0].action = sNewFormAction;
    document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+ ";path=/";
}

function setDefaultClick(buttonid,e){ 

      var evt = e ? e : window.event;

      var bt = document.getElementById(buttonid);

      if (bt){ 
          if (evt.keyCode == 13){ 
                bt.click(); 
                return false; 
          } 
      } 
}

/*
Sets the Homepage to Golflink. This only works on IE due to 
setting issues on Firefox and Chrome does display a homepage
*/
function SetHomePageOnMainPage()
	{
		
		if(document.getElementById('GLLogin_chkSetAsHomePage').checked)
		{
				document.body.style.behavior='url(#default#homepage)';
				document.body.setHomePage('http://www.golflink.com.au');
				_uacct = "UA-375373-1";
				urchinTracker('/SetHomePageOnMainPage.step');

		}
	}
/*
Sets the Homepage to Golflink. This only works on IE due to 
setting issues on Firefox and Chrome does display a homepage
*/
function SetHomePageOnLoginPage()
	{
		
		//var browserName=navigator.appName;
		if(document.getElementById('ucLoginBox_chkSetAsHomePage').checked)
		{
			//if (browserName=="Microsoft Internet Explorer")
			//{
				document.body.style.behavior='url(#default#homepage)';
				document.body.setHomePage('http://www.golflink.com.au');
			//}
			//Code below is for firefox
			/*
			else if (browserName=="Netscape")	
			{
				try
				{  
					netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
				}  
				catch(e)  
				{  
					alert("this action was aviod by your browser,if you want to enable,please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");  
				}
				var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
				prefs.setCharPref('browser.startup.homepage','http://www.golflink.com.au');
			}
			*/
			_uacct = "UA-375373-1";
			urchinTracker('/SetHomePageOnLoginPage.step');
		}
	}
		