function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var ajaxContext="/ajax2/ajax.do";
var ajaxSports="sailing";
function ajaxExecute(ajaxURL,divid)
{
	var http = getHTTPObject(); // Create the HTTP Object
	if(ajaxURL!="")
	{
		if(ajaxURL.indexOf("?")==-1)
			ajaxURL+="?refresh_this="+new Date().getTime();
		else
			ajaxURL+="&refresh_this="+new Date().getTime();

		http.open("GET",ajaxURL,true);
		ajaxURL="";
		http.onreadystatechange = function(){
		  if (http.readyState == 4) {
			var elem = document.getElementById(divid);
			elem.innerHTML=http.responseText;
		  }
		};
		http.send(null);
	}
}

function searchClubs(country,keyword)
{
  ajaxUrl=ajaxContext+"?sports="+escape(ajaxSports)+"&page=eventClubs&data=clubs&country="+escape(country)+"&keyword="+escape(keyword);
  ajaxExecute(ajaxUrl,"clubs_listing");
}

function searchEventsShortListNew(country,max)
{
  ajaxUrl=ajaxContext+"?sports="+escape(ajaxSports)+"&page=eventsShortListNew&data=events&sort=startdate&country="+escape(country)+"&max="+max;
  ajaxExecute(ajaxUrl,"events_short_list");
}
function searchEventsShortList(country,max)
{
  ajaxUrl=ajaxContext+"?sports="+escape(ajaxSports)+"&page=eventsShortList&data=events&sort=startdate&country="+escape(country)+"&max="+max;
  ajaxExecute(ajaxUrl,"events_short_list");
}
function searchEventsList(country,eventName,clubName,startDate,endDate,year)
{
  ajaxUrl=ajaxContext+"?sports="+escape(ajaxSports)+"&page=eventsList&data=events&sort=startdate&country="+escape(country)+"&eventName="+escape(eventName)+"&clubName="+escape(clubName)+"&startDate="+escape(startDate)+"&endDate="+escape(endDate)+"&year="+escape(year);
  ajaxExecute(ajaxUrl,"event_listing");
}


function searchSailteamList()
{
  ajaxUrl=ajaxContext+"?page=sailteamList&data=sailteam";
  ajaxExecute(ajaxUrl,"sailteam_listing");
}


function getSportClubs(sport)
{
  var id="clubs";
  var http = getHTTPObject(); // Create the HTTP Object
  url=ajaxContext+"?sports="+escape(sport)+"&page=generatePromoClubs&data=promoClubs";
  http.open("GET",url,true);
  http.onreadystatechange = function(){
  if (http.readyState == 4) {
	var elem = document.getElementById(id);
	addOptions(http.responseText,id);
	}
  };
  http.send(null);
}

function getClubEvents(sport,clubid)
{
  var id="events";
  var http = getHTTPObject(); // Create the HTTP Object
  url=ajaxContext+"?sports="+escape(sport)+"&page=generatePromoEvents&data=promoEvents&clubid="+clubid;
  http.open("GET",url,true);
  http.onreadystatechange = function(){
  if (http.readyState == 4) {
	var elem = document.getElementById(id);
	addOptions(http.responseText,id);
	}
  };
  http.send(null);
}

function displayPromoCodes(sport,eventid)
{
  ajaxUrl=ajaxContext+"?sports="+escape(sport)+"&page=generatePromo&data=promoCodes&eventid="+eventid;
  ajaxExecute(ajaxUrl,"promo_code");
}



function getClubCountries(id)
{
  var http = getHTTPObject(); // Create the HTTP Object
  url=ajaxContext+"?sports="+escape(ajaxSports)+"&page=clubCountries&data=countries";
  http.open("GET",url,true);
  http.onreadystatechange = function(){
  if (http.readyState == 4) {
	var elem = document.getElementById(id);
	addOptions(http.responseText,id);
	}
  };
  http.send(null);
}
function addOptions(optionsV,id)
{
 eid = document.getElementById(id);
 eid.options.length=0;
 var opa = optionsV.split("###");
 for(i=0;i<opa.length;i++)
 {
 var optn = document.createElement("OPTION");
 var opav=opa[i].split("=");
 optn.text = opav[1];
 optn.value = opav[0];
 eid.options.add(optn);
 }
}
function setDisplay(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}