function GetObj(objectId)
{
	return document.getElementById(objectId);
}

function isObj(obj)
{
	if(obj) return true;
	return false;
}

function checkInput(obj, value)
{
	if(obj)
	{
		setMessage("");
		
		if(obj.value == value)
		{
			obj.value = "";
		}
		else if(obj.value == "")
		{
			obj.value = value;
		}
		else
		{
			cleanMessage();
		}
	}
}

function isEmpty(obj)
{
	if(obj.value == "") return true;
	return false;
}

function isEmail(obj)
{
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (filter.test(obj.value)) return true;
	return false;
}

function isPostcode(obj)
{
	var filter = /^[1-9]{1}[0-9]{3}[a-zA-Z]{2}$/;
	
	if (filter.test(obj.value)) return true;
	return false;
}

function isSameAsTitle(obj)
{
	if(obj.value == obj.title) return true;
	return false;
}

function focusObject(obj)
{
	obj.focus();
}

function setMessageById(value, messageId)
{
	objMessage = document.getElementById(messageId);
	
	if(objMessage)
	{
		objMessage.innerHTML = value;
	}
}

function setMessage(value, objectId)
{
	objMessage = document.getElementById(objectId);
		
	if(objMessage)
	{
		objMessage.innerHTML = value;
	}
	else
	{
		objMessage = document.getElementById('message');
		
		if(objMessage)
		{
			if(value != "")
			{
				objMessage.innerHTML = value;
			}
		}
	}
}

function cleanMessage()
{
	objMessage = document.getElementById('message');
		
	if(objMessage)
	{
		objMessage.innerHTML = "";
	}
}

// T Leon

function SendBookingRequest()
{
	objCaptcha 	= document.getElementById('captcha');
	
	if(objCaptcha)
	{
		if(isEmpty(objCaptcha) || isSameAsTitle(objCaptcha))
		{
			focusObject(objCaptcha);
			setMessage("Please, enter the <strong>captcha</strong> code!");
			return;
		}
		
		document.BookingForm.submit();
	}
}

function SendGuestbookRequest()
{
	objReaction	= document.getElementById('guestbook_reaction');
	objName 	= document.getElementById('guestbook_name');
	objEmail 	= document.getElementById('guestbook_email');
	objCaptcha 	= document.getElementById('captcha');
	
	if(objReaction && objName && objEmail && objCaptcha)
	{
		if(isEmpty(objName) || isSameAsTitle(objName))
		{
			focusObject(objName);
			setMessage("Please, fill out your <strong>name</strong>!");
			return;
		}
		
		if(isEmpty(objEmail) || isSameAsTitle(objEmail))
		{
			focusObject(objEmail);
			setMessage("Please, fill out your <strong>e-mail address</strong>!");
			return;
		}
		// hendrik
		if(!isEmail(objEmail))
		{
			focusObject(objEmail);
			setMessage("The given e-mail address is not valid!");
			return;
		}
		
		if(isEmpty(objReaction) || isSameAsTitle(objReaction))
		{
			focusObject(objReaction);
			setMessage("Please, fill out your <strong>reaction</strong>!");
			return;
		}
		
		if(isEmpty(objCaptcha) || isSameAsTitle(objCaptcha))
		{
			focusObject(objCaptcha);
			setMessage("Please, enter the <strong>captcha</strong> code!");
			return;
		}
		
		document.GuestbookForm.submit();
	}
}

function SendContactRequest()
{
	objReaction	= document.getElementById('contact_reaction');
	objName 	= document.getElementById('contact_name');
	objEmail 	= document.getElementById('contact_email');
	objCaptcha 	= document.getElementById('captcha');
	
	if(objReaction && objName && objEmail && objCaptcha)
	{
		if(isEmpty(objName) || isSameAsTitle(objName))
		{
			focusObject(objName);
			setMessage("Please, fill out your <strong>name</strong>!");
			return;
		}
		
		if(isEmpty(objEmail) || isSameAsTitle(objEmail))
		{
			focusObject(objEmail);
			setMessage("Please, fill out your <strong>e-mail address</strong>!");
			return;
		}
		// hendrik
		if(!isEmail(objEmail))
		{
			focusObject(objEmail);
			setMessage("The given e-mail address is not valid!");
			return;
		}
		
		if(isEmpty(objReaction) || isSameAsTitle(objReaction))
		{
			focusObject(objReaction);
			setMessage("Please, fill out your <strong>reaction</strong>!");
			return;
		}
		
		if(isEmpty(objCaptcha) || isSameAsTitle(objCaptcha))
		{
			focusObject(objCaptcha);
			setMessage("Please, enter the <strong>captcha</strong> code!");
			return;
		}
		
		document.ContactForm.submit();
	}
}

function SendMailinglistRequest()
{
	objEmail 	= document.getElementById('m_email');
	
	if(objEmail)
	{	
		if(isEmpty(objEmail) || isSameAsTitle(objEmail))
		{
			focusObject(objEmail);
			setMessageById("Please, fill out your <strong>e-mail address</strong>!","CommonMessage");
			return;
		}

		if(!isEmail(objEmail))
		{
			focusObject(objEmail);
			setMessageById("The given <strong>e-mail address</strong> is not valid!","CommonMessage");
			return;
		}
				
		document.MailinglistForm.submit();
	}
}

function ReloadCaptcha()
{
	ImageObj = GetObj('captchaimage');
	
	if(ImageObj)
	{
		ImageObj.src = "";
		ImageObj.src = "captcha/dynamicimage.php";
	}
}

function ShowMoreReactions(iNext, sObjectId)
{
	// GuestbookItems
	var sUrl = 'guestbookitems.php?iStart=' + iNext;
			
	$("#" + sObjectId).load(sUrl);
}