stateError = false;
function inviteCheckForm(form) {
	form = form2param(form);
	AjaxRequest(inviteCheckFormParse,'?s=invite&m=check_form','POST',form);
}
function inviteCheckFormParse(html,xml) {
	if(html == "OK") {
      if(stateError) {
	      new Effect.toggle('form_error','slide', {duration: 0.5,afterUpdate: popupCenterContent})
      }
		new Effect.toggle('form','slide', {duration: 1,afterUpdate: popupCenterContent,afterFinish: inviteShowDone})
      stateError = false;
   } else {
   	document.getElementById('form_error').innerHTML = "<br />" + html;
      if(!stateError) {
	      new Effect.toggle('form_error','slide', {duration: 0.5,afterUpdate: popupCenterContent})
      }
     	stateError = true;
   }
//	popupCenterContent();
}

function inviteShowDone() {
	new Effect.toggle('form_done','blind', {duration: 0.5,afterUpdate: popupCenterContent})
}


function inviteCheckCode(code) {
   AjaxRequest(inviteCheckCodeParse,'?s=invite&m=check_code','POST','code='+code);
}
function inviteCheckCodeParse(html,xml) {
	document.getElementById('code_status').innerHTML = '<img src="' + html + '">';
}

function showGalleryImage(_image) {
	document.getElementById('gallery_image').src = _image;
}

function showHotelOverlay(_element) {
	document.getElementById(_element).style.display = 'block';
}
function hideHotelOverlay(_element) {
	document.getElementById(_element).style.display = 'none';
}

/* FUNCTIONS */

resetState = new Array();

function resetInput(element,name) {
	if(!resetState[name]) {
   	resetState[name] = true;
      element.value = "";
   }
}

var isIE_PNG = (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf('Opera') == -1);

function Popup(path,name,width,height,scrolling,resizable)
 {
   window.open(path,name,"width="+width+",height="+height+",scrollbars="+scrolling+",resizable="+resizable);
 }

/* ToolTip */

function getImageTooltip(image,imgInt,img) {
   var copy = new Image();
   copy.src = image.src;

   width = copy.width;
   height = copy.height;
   if(width > 640) width = 640;
   height = width/copy.width*height;

   if(height > 480) height = 480;
   width = height/copy.height*copy.width;

   extra = "";
   if(imgInt != null && imgInt != "undefined") {
   	extra = "onClick=\"addCode('"+imgInt+"','"+img+"')\"";
   }

   basic = "<img "+extra+" height=\'"+height+"\' width=\'"+width+"\' src=\'"+image.src+"\'>";
   return basic;
}

var updateInterval; // Intervall, in which the frame is recentered
var hideInterval; // Interval after which tooltip is closed, if its not reset
var closeable = false;

function showTooltip(which,content) {
   closeable = false;

   which.onmouseout = wantHideTooltip;

	window.clearInterval(updateInterval);
	d = document.getElementById('tooltip');
	d.innerHTML = content;
   d.style.display = "inline";
   centerize('tooltip');
   updateInterval = window.setInterval("centerize('tooltip')",250);
}

function hideTooltip(override) {
	if(closeable || override) {
		// clear intervals
		window.clearInterval(updateInterval);
		window.clearInterval(hideInterval);
   	// hide tooltip
	 	document.getElementById('tooltip').style.display = 'none';
	}
}

function wantHideTooltip() {
	closeable = true;
	hideInterval = window.setInterval("hideTooltip()",200);
}

function clearHideTooltip() {
	closeable = false;
	window.clearInterval(hideInterval);
}

var windowWidth = 0;
var windowHeight = 0;
var windowOffsetX = 0;
var windowOffsetY = 0;

function refreshWindowValues() {
	windowWidth = getWindowWidth();
	windowHeight = getWindowHeight();
   windowOffsetY = getWindowOffsetY();
   windowOffsetX = getWindowOffsetX();
}

function centerize(field,refresh) {
	d = document.getElementById(field);
   if(d) {
   	if(refresh == undefined) {
      	refresh = true;
      }
      if(refresh) {
      	refreshWindowValues();
      }
		dWidth = d.offsetWidth;
      dHeight = d.offsetHeight;

      x = (windowWidth-dWidth)/2;
      y = (windowHeight-dHeight)/2;

      x += windowOffsetX;
      y += windowOffsetY;

      d.style.left = x + "px";
		d.style.top = y + "px";
   }
}

function getWindowOffsetY() {
   if (self.pageYOffset) {
	   return self.pageYOffset;
   } else if (document.documentElement && document.documentElement.scrollTop) {
   	return document.documentElement.scrollTop;
   } else if (document.body) {
   	return document.body.scrollTop;
   }
}

function getWindowOffsetX() {
   if (self.pagecOffset) {
	   return self.pageXOffset;
   } else if (document.documentElement && document.documentElement.scrollLeft) {
   	return document.documentElement.scrollLeft;
   } else if (document.body) {
   	return document.body.scrollLeft;
   }
}

function getWindowWidth() {
   if (self.innerWidth) {
      return self.innerWidth;
   } else if (document.documentElement && document.documentElement.clientHeight) {
      return document.documentElement.clientWidth;
   } else if (document.body) {
      return document.body.clientWidth;
   }
}

function getWindowHeight() {
   if (self.innerHeight) {
      return self.innerHeight;
   } else if (document.documentElement && document.documentElement.clientHeight) {
      return document.documentElement.clientHeight;
   } else if (document.body) {
      return document.body.clientHeight;
   }
}