// JavaScript Document

var showJoinNow = false;

function editPageLoad(varName, selectName) {
	var id = document.getElementById(selectName).options[document.getElementById(selectName).selectedIndex].id;
	if (id == 'null') {
		document.getElementById('editframe').value = '';
		return false;
	}
	
	window.location = "?"+varName+"=" + document.getElementById(selectName).value;
}

function changeType(typeID, typeLabel){
  var link = "./types.php?typeID=" + typeID + "&typeLabel=" + typeLabel;
  window.location = link;
}

function changePage(link){
  window.location = link;
}

function changeRegistrationForm(userType){
  var link = "./registrationForm.php?userType=" + userType;
  window.location = link;
}


function buildingListing(buildingID){
  var link = "./listing.php?buildingID=" + buildingID;
  window.location = link;
}

function areaListing(areaID){
  var link = "./listing.php?areaID=" + areaID;
  window.location = link;
}



function ajaxFunction(type, arg1, offset, cid){

	var ajaxRequest = null;  // The variable that makes Ajax possible!

   try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
   } catch (e) {

   try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("This feature was disabled by your browser.");
				return false;
			}
		}
	}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState==4 || ajaxRequest.readyState=="complete"){
          if (type == 'search')
		  {
			var ajaxDisplay = document.getElementById('fuzzysearch');
			
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
	        ajaxDisplay.className="visible";			
            if (ajaxRequest.responseText.length > 200)
			{
			  ajaxDisplay.style.overflow = 'auto';			  
			} else
			{
			  ajaxDisplay.style.height = '';
			  ajaxDisplay.style.background = '#FFFFFF';			  
			  ajaxDisplay.style.overflow = "visible";				  
			}			
		  }
          if (type == 'newsletter')
		  {
	        alert(ajaxRequest.responseText);
		  }
      }
	}
    if (type == 'search'){
	  var rowsPerPage = 10;
      var queryString = "?searchText=" + document.getElementById('sSearch').value; 
//	  alert(queryString);
	  if (document.getElementById('sSearch').value.length >= 3)
	  {
        ajaxRequest.open("GET", "/includes.new/ajaxFunctions2.php" + queryString, true); 
	  ajaxRequest.send(null);	
	  }
 	}	
    if (type == 'archive'){
	  var rowsPerPage = 10;
      var queryString = "?searchType=archive&searchText=" + document.getElementById('sSearch2').value; 
//	  alert(queryString);
	  if (document.getElementById('sSearch2').value.length >= 3)
	  {
        ajaxRequest.open("GET", "./includes/ajaxFunctions.php" + queryString, true);
	  ajaxRequest.send(null);	
	  }
 	}	
    if (type == 'shop'){
	  var rowsPerPage = 10;
      var queryString = "?searchType=shop&searchText=" + document.getElementById('sSearch3').value; 
//	  alert(queryString);
	  if (document.getElementById('sSearch3').value.length >= 3)
	  {
        ajaxRequest.open("GET", "./includes/ajaxFunctions.php" + queryString, true);
	  ajaxRequest.send(null);	
	  }
 	}		
    if (type == 'newsletter'){
      var queryString = "?email=" + document.getElementById('newsletterEmail').value + "&contactList=" + arg1; 
//	  alert(queryString);
      ajaxRequest.open("GET", "./includes/ajaxNewsletter.php" + queryString, true);
	  ajaxRequest.send(null);	
 	}	
}

function addToAtrributeList(numItems) {

var catList = " ";
var box;
var i = 0;
alert(numItems);
for (var j = 1; j <= numItems; j++) {
  box = eval("document.usersForm.checkbox" + j); 	  
  if ((box)&&(box.checked == true))
  {
      catList += " "  + box.value + ",";
  }  
}
//alert("Hi"+catList);
inputCatList = eval("document.usersForm.catList");    
inputCatList.value = catList;
}

function replaceChars(entry) {
out = " "; // replace this
add = "_"; // with this
temp = "" + entry; // temporary holder

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + 
temp.substring((pos + out.length), temp.length));
}
return temp;
}

function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}

function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}

function closeSearch() {
	element('fuzzysearch').className="hidden";
}

function showJoin(id) {
  if (!showJoinNow)
  {
    showJoinNow = true;	  
	element(id).style.display="";
  }
  else	
  {
    showJoinNow = false;	  
	element(id).style.display="none";
  }
}

function closeJoin(id) {
	element(id).style.display="none";
}

function element( elementId )
{
   if ( document.getElementById )
   {
      return document.getElementById( elementId )
   }
   else if ( document.all )
   {
      return document.all[elementId]
   }
   else if ( document.layers ) 
   {
      return document[ elementId ]
   }
   else
   {
      //alert( "no element: " + elementId )
   }
}

function showFindAClub(divID) {
  for (var i=1; i<30; i++)
  {
	tempDiv = element('findAClub'+i);
    if (tempDiv)
	  tempDiv.style.display="none";
  }
  element(divID).style.display="";
}

function startBlink(numImages, clubName) {

  setInterval("doBlink('" + numImages + "', '" + clubName + "')", 5000);
}

var currentClubImage = 0;
var clubImageList = new Array();
function doBlink(numImages, clubName) {
//	numImages = 5;
//	clubName = "0bigInterchange";

	currentClubImage++;
	if (currentClubImage > clubImageList.length-1)
	  currentClubImage = 0;
//	if ()
    element('indClubMainImage').src = 'content/clubs/' + clubImageList[currentClubImage];
	
}

