function setCookie (name, value, expireDays, path, domain, secure){
	var cookie = name + "=" + escape(value);
	
	if (!expireDays)  expireDays = 365;
	var date = new Date();
	date.setDate (date.getDate() + expireDays);
	cookie += "; expires=" + date.toUTCString();
	if(path) cookie += "; path=" + escape(path);
	if(domain) cookie += "; domain=" + escape(domain);  
	if(secure) cookie += "; secure";
	document.cookie = cookie;
}

function deleteCookie (name){
  var date = new Date();
  date.setTime (date.getTime() - 1);
  document.cookie = name += "=; expires=" + date.toGMTString();
}

function getCookie (name){
  var cookie = document.cookie.match ( '(^|;) ?'+name+'=([^;]*)(;|$)' );
  if(cookie) return (unescape(cookie[2]));
  else return null;
}

function closeWindow() {
	//uncomment to open a new window and close this parent window without warning
	//var newwin=window.open("popUp.htm",'popup','');
	if(navigator.appName == "Microsoft Internet Explorer") {
		this.focus();
		self.opener = this;self.close(); 
	}
	else { 
		window.open('', '_parent', ''); 
		window.close(); 
	}
	return true;
}

function listCities(district) {
	$.ajax({
		url: '/registration',
		type: 'POST',
		data: 'action=listcities&district_id=' + district,
		timeout: 2000,
		success: function(html){			
			$('#cities').html(html);
		}
	  });
}

function setOnlineStatus(status) {
	$.ajax({
		url: '/users',
		type: 'POST',
		data: 'action=setonlinestatus&status='+status
	  });
}

function getUserName(user_id, element) {
	$.ajax({
		url: '/registration',
		type: 'POST',
		data: 'action=get_user_name&user_id=' + user_id,
		success: function(html) {			
			element.style.display = '';
			element.innerHTML = html;
		}
	  });
}

function reservationDateEndVisibility(recurring) {
	if (recurring == 'no') $('#reservationdateend').hide();
	else $('#reservationdateend').show();
}

function keepOnline() {
	onlineStatusUpdater = new Ajax.PeriodicalUpdater('todays_reservations','?site=reservation', {
		method: 'post',
		parameters: {action: 'todaysReservations'},
		frequency: 60,
		decay: 1
	});
}

// Translations
function switchColumn(Column){
	var Width;
	var Text;
	if(document.getElementById(Column).style.width == '0px'){
		Width = 'auto';
		Text = '>|<';
	} else {
		Width = '0px';
		Text = '|<>|';
	}
	document.getElementById(Column).style.width = Width;
	document.getElementById(Column+'_sign').innerHTML = Text;
}

function ivSwitcher() {
	if (document.getElementById('iv_image').style.display != 'none') {
		document.getElementById('iv_image').style.display = 'none';
		document.getElementById('iv_video').style.display = '';
		document.getElementById('iv_holder').width = '320';
		document.getElementById('iv_holder').height = '240';
		document.getElementById('iv_button').innerHTML = '';
		document.getElementById('iv_button').id = '';
	} else {
		document.getElementById('iv_image').style.display = '';
		document.getElementById('iv_video').style.display = 'none';
		document.getElementById('iv_holder').width = '206';
		document.getElementById('iv_holder').height = '206';
	}
}