/* CREATE DOM LISTENER AND EVENTS FOR TOP 10 */
window.addEvent('domready', function(){
	var clubSlide = new Fx.Slide('top-clubs');
	//clubSlide.hide(); 
	$('topClubs').addEvent('click', function(e){
		e = new Event(e);
		clubSlide.toggle();
		restaurantSlide.slideOut();
		barSlide.slideOut();
		e.stop();
	});
	var barSlide = new Fx.Slide('top-bars');
	barSlide.hide(); 
	$('topBars').addEvent('click', function(e){
		e = new Event(e);
		barSlide.toggle();
		restaurantSlide.slideOut();
		clubSlide.slideOut();
		e.stop();
	});
	var restaurantSlide = new Fx.Slide('top-restaurants');
	restaurantSlide.hide(); 
	$('topRestaurants').addEvent('click', function(e){
		e = new Event(e);
		restaurantSlide.toggle();
		barSlide.slideOut();
		clubSlide.slideOut();
		e.stop();
	});
}); 

/* CHECK FORM FUNCTION FOR LOGIN PANEL ON LEFT */
function checkform (form) {
	var type = document.getElementById('loginType');
	var user = document.getElementById('username');
	var pass = document.getElementById('password');
	var error = "";
  if (type.options[type.selectedIndex].value == "") {
   error = "<li>Select a <strong>Login Type</strong></li>";
  }
  if (user.value == "") {
    error = error+"<li>Enter your <strong>Username</strong></li>";
  }
  if (pass.value == "") {
    error = error+"<li>Enter your <strong>Password</strong></li>";
  }
  if (error != "") {
  	document.getElementById('loginError').innerHTML = '<h2 class="red">Login Error: </h2><strong>Please...</strong><ul class="errorUL">'+error+'</ul>';
	Mediabox.open('#mb_inline', 'LOGIN ERROR', 'lightbox[inline 260 100]');
	return false;
  } else {
  	return true;
  }
}

/* DYNAMIC AREA DROPDOWN FUNCTIONS */
var request = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
request = false;
}
}
@end @*/
if (!request && typeof XMLHttpRequest != 'undefined') {
	request = new XMLHttpRequest();
}

function fillSelect(get, fieldToPopulate, actual_value, session) {
	if (actual_value != undefined) { 
		var url = "scripts/csa_ajax.php?"+get+"=" + escape(actual_value) + "&getSession=" + escape(session);
		request.open("GET", url, true);
			request.onreadystatechange = function() {
				createOptions(fieldToPopulate);
			}
		request.send(null);
	}
}

function createOptions(field) {
	if (request.readyState == 4) {
		if (request.status == 200) {
			var response = request.responseText;
			var list=document.getElementById(field);
			var values=response.split('|');
			for (i=1; i<values.length; i++) {
				var value_info=values[i].split('~');
				var x=document.createElement('option');
				x.value = value_info[0];
				var y=document.createTextNode(value_info[1]);
				x.appendChild(y);
				list.appendChild(x);
			}
		}
	}
}

function initCs(take_value, populate, id, session) {
	var country=document.getElementById(take_value);
		if(this.value!="") {
			var list=document.getElementById(populate);
			while (list.childNodes[0]) {
				list.removeChild(list.childNodes[0])
			}
			fillSelect(id, populate, this.value, session);
		} 
	fillSelect(id, populate, country.value, session);
}

