function FormCheck()
{
  
  var showEmailNotification = false;
	var result   = true;
	var message = '';
	// if-clause can be deleted if translation is done!
	if(typeof Translations[languageCode]['rqAlertErrorsOccured'] != 'undefined') {
	  message  += '<p><strong>' + Translations[languageCode]['rqAlertErrorsOccured'] + '</strong></p>';
	}
	if (document.getElementById("multiple")) 
	{
		if (document.getElementById("multiple").value == '') 
		{
			message += '<p>' + Translations[languageCode]['rqAlertNoObjects'] + '</p>';
			result = false;	
		}
	}
	if (document.getElementsByName("part")[0]) 
	{		
		if(document.getElementsByName("part")[0].value == '') 
		{
			message += '<p>' + Translations[languageCode]['rqAlertNoApartment'] + '</p>';
			result = false;	
		}
    }
	if(document.getElementsByName("startdate_day")[0]) {
		if (document.getElementsByName("startdate_day")[0].value == '') 
		{
			message += '<p>' + Translations[languageCode]['rqAlertStartDayEmpty'] + '</p>';
			result = false;
		}
	}
	if (document.getElementsByName("startdate_month")[0]) {
		if (document.getElementsByName("startdate_month")[0].value == '')
		{
		  message += '<p>' + Translations[languageCode]['rqAlertStartMonthEmpty'] + '</p>';
			result = false;
		}
	}
	if (document.getElementsByName("period1")[0]) {
		if (document.getElementsByName("period1")[0].value == '') 
		{
		  message += '<p>' + Translations[languageCode]['rqAlertNoDuration'] + '</p>';
			result = false;
		}
	}
	if (document.getElementsByName("tripSelect")[0]) {
		if (document.getElementsByName("tripSelect")[0].value == '') 
		{
		  message += '<p>' + Translations[languageCode]['rqAlertNoTripSelected'] + '</p>';
			result = false;
		}
	}
	if (document.getElementsByName("adults")[0].value == '')
	{
	  message += '<p>' + Translations[languageCode]['rqAlertNoAdults'] + '</p>';
		result = false;	
	}
	if (document.getElementsByName("appellation")[0].value == '') 
	{
	  message += '<p>' + Translations[languageCode]['rqAlertNoAppellation'] + '</p>';
		result = false;	
	}
	else if(document.getElementsByName("appellation")[0].value == 'company')
	{
	    if(document.getElementsByName("company")[0].value == '')
	    {
	      message += '<p>' + Translations[languageCode]['rqAlertNoCompany'] + '</p>';
		    result = false;	
	    }
  }
	if (document.getElementsByName("name")[0].value == '') 
	{
	  message += '<p>' + Translations[languageCode]['rqAlertNoName'] + '</p>';
		result = false;	
	}
	if (typeof maxPersons != 'undefined' && (parseInt(document.getElementsByName("adults")[0].value) + parseInt(document.getElementsByName("children")[0].value)) > maxPersons) 
	{
	  message += '<p>' + Translations[languageCode]['rqAlertToManyPersons'] + " " + maxPersons + '</p>';
		result = false;	
	}
	if (document.getElementsByName("firstname")[0].value == '') 
	{
	  message += '<p>' + Translations[languageCode]['rqAlertNoFirstname'] + '</p>';
		result = false;	
	}		
	if (document.getElementsByName("phone")[0].value == prefixAndNumber && document.getElementsByName("fax")[0].value == prefixAndNumber && document.getElementsByName("mail")[0].value == '') 
	{
	  message += '<p>' + Translations[languageCode]['rqAlertNoContactData'] + '</p>';
		result = false;
	}
	// only for searchRequests
  if (typeof chooseDestination != 'undefined' && chooseDestination == true && document.getElementsByName("wishCountry")[0].value == '' && document.getElementsByName("wishRegion")[0].value == '' && document.getElementsByName("wishCity")[0].value == '') 
	{
	  message += '<p>' + Translations[languageCode]['rqAlertNoDestination'] + '</p>';
		result = false;
	}
	
	if (document.getElementsByName("mail")[0].value != '')
	{
		var mail1 = false;
		var mail2 = false;
		if (document.getElementsByName("mail")[0]) mail1 = document.getElementsByName("mail")[0].value;
		if (document.getElementsByName("mail2")[0]) mail2 = document.getElementsByName("mail2")[0].value;		
		var ergMessage = validateMail(mail1, mail2);
		if (ergMessage != "")
		{ 
			message += '<p>' + ergMessage + '</p>';
			result = false;			
		}
	} else showEmailNotification = true;
	
	if(typeof emailNotification == 'undefined' || emailNotification == false) showEmailNotification = false;
	
	if (result == false) {
	  showNotificationLayer(message);
	  return false;
	} else if(showEmailNotification) {
    showEmailNotificationLayer();
    return false;
  } else {
	  if (document.getElementsByName("phone")[0].value == prefixAndNumber || document.getElementsByName("phone")[0].value == '') {
	    document.getElementsByName("phone")[0].value = '';
	    document.getElementsByName("phoneAdd")[0].value = '';
	  }
	  if (document.getElementsByName("fax")[0].value == prefixAndNumber || document.getElementsByName("fax")[0].value == '') {
	    document.getElementsByName("fax")[0].value = '';
	    document.getElementsByName("faxAdd")[0].value = '';
	  }
	}
	return result;
}

function showNotificationLayer(message) {
  setLayerHead(Translations[languageCode]['layerNotice']);
  setLayerText(message + '<p><input type="button" value="' + Translations[languageCode]['OK'] + '" onclick="hideLayer(); return false;" /></p>');
  setLayerStyle('default', 'default', '400px', 'default', 'default', 'default');
  showLayer();
}

function showEmailNotificationLayer() {
  setLayerHead(Translations[languageCode]['layerNotice']);
  setLayerText('<p>' + Translations[languageCode]['emailNotificationLayerText'] + '</p><p>' + Translations[languageCode]['contactEMail'] + ': <input type="text" name="mail" id="lyEmailNotificationInput"></p><p><input type="button" value="' + Translations[languageCode]['cancel'] + '" onclick="hideLayer();" /> <input class="rightButton" type="submit" onclick="emailNotificationLayerSubmit(); return false;" value="' + Translations[languageCode]['OK'] + '"></p>');
  setLayerStyle('default', 'default', '400px', 'default', 'default', 'default');
  showLayer();
}

function validateMail(mail_1, mail_2) 
{
	if(mail_1 != mail_2 || mail_1 == '') {
		return Translations[languageCode]['rqAlertMailsNotEqual'];		
	} else if(!emailCheck(mail_1)) {
		return Translations[languageCode]['rqAlertEmailSeemsIncorrect'];		
	} else {		
		return "";
	}
}

/*
<!-- Original author:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
<!-- old Source on http://www.jsmadeeasy.com/javascripts/Forms/Email%20Address%20Validation/template.htm -->
*/
function emailCheck (emailStr) {
	/* The following pattern is used to check if the entered e-mail address
		fits the user@domain format.  It also is used to separate the username
		from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
		characters.  We don't want to allow special characters in the address.
		These characters include ( ) < @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a
		username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
		which case, there are no rules about which characters are allowed
		and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
		is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
		rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
		e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
		non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
		For example, in john.doe@somewhere.com, john and doe are words.
		Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
		domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	/* Begin with the coarse pattern to simply break up user@domain into
		different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		/* Too many/few @'s or something; basically, this address doesn't
			even fit the general mould of a valid e-mail address. */
		//alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid
	if (user.match(userPat)==null) {
			// user is not valid
			//alert("The part of your email address before the '@' doesn't seem to be valid.")
			return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
			// this is an IP address
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
						//alert("Destination IP address is invalid!")
			return false
				}
			}
			return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("Part of your email address after the '@' doesn't seem to be valid")
			return false
	}

	/* Now we need to break up the domain to get a count of how many atoms
		it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
			domArr[domArr.length-1].length>6) {
		// the address must end in a two letter or other TLD including museum
		//alert("The address must end in a top level domain (e.g. .com), or two letter country.")
		return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
		//var errStr="This address is missing a hostname!"
		//alert(errStr)
		return false
	}

	if(emailStr.indexOf("@tonline.") != -1) {
		if(confirm(Translations[languageCode]['rqAlertTonline'])) return false;
	}

	// If we've got this far, everything's valid!
	return true;
}


function checkMaxDays(name) {
 if (document.getElementsByName(name + "_month").length && document.getElementsByName(name + "_day").length) {
 	 maxDays = days[(document.getElementsByName(name + "_month")[0].selectedIndex)];
 	 if (maxDays)
 	 {
 	 if (document.getElementsByName(name + "_day")[0].value > maxDays) 
 	   document.getElementsByName(name + "_day")[0].value = maxDays;
 	 if ((document.getElementsByName(name + "_month")[0].selectedIndex > 0) && (document.getElementsByName(name + "_day")[0].value == 0)) 
 	   document.getElementsByName(name + "_day")[0].selectedIndex = 1;
 	 if (document.getElementsByName(name + "_weekday").length) {
 	 	 if ((document.getElementsByName(name + "_month")[0].selectedIndex > 0) && (document.getElementsByName(name + "_day")[0].selectedIndex > 0)) 
 	 	 {
	 	   year  = (document.getElementsByName(name + "_month")[0].options[document.getElementsByName(name + "_month")[0].selectedIndex].value.substr(0, 4)); 
	 	   month = (document.getElementsByName(name + "_month")[0].options[document.getElementsByName(name + "_month")[0].selectedIndex].value.substr(4));
	 	   day   = (document.getElementsByName(name + "_day")[0].options[document.getElementsByName(name + "_day")[0].selectedIndex].value);

	 	   selectedDate = new Date(year, month - 1, day);
	 	   document.getElementsByName(name + "_weekday")[0].value = weekDays[selectedDate.getDay()];
 	   } else 
 	     document.getElementsByName(name + "_weekday")[0].value = '';
 	 } 
 	}
 }
}

//Change the prefix of the selected country into all unfilled phoneNumbers
function changePrefix(number)
{
	if (document.getElementById('rqPhone').value == '' || document.getElementById('rqPhone').value == prefixAndNumber)
	{
		for(var i = 0; i < document.getElementById('rqPhoneAdd').length; i++)
		{
			if(document.getElementById('rqPhoneAdd').options[i].text == number)
			{
				document.getElementById('rqPhoneAdd').options[i].selected = true;
				break;
			}
		}
	}

	if (document.getElementById('rqFax').value == '' || document.getElementById('rqFax').value == prefixAndNumber)
	{
		for(var i = 0; i < document.getElementById('rqFaxAdd').length; i++)
		{
			if(document.getElementById('rqFaxAdd').options[i].text == number)
			{
				document.getElementById('rqFaxAdd').options[i].selected=true;
				break;
			}
		}
	}
}

function alternateCalendar(vMode) {
  if(vMode == 'show') {
    document.getElementById('alternateCalendar').style.display = 'block';
    document.getElementById('alternateDate').style.display = 'none';
  } else {
    document.getElementById('alternateCalendar').style.display = 'none';
    document.getElementById('alternateDate').style.display = 'block';
    
    document.getElementById('cl2Day').selectedIndex = 0;
    document.getElementById('cl2Month').selectedIndex = 0;
    document.getElementById('period2').selectedIndex = 6;
  }
}

function onlyNumbers(key) {
  // KeyCodes
  // 48 - 57  > Numbers
  // 96 - 105 > NumPad Numbers
  // 8        > Backspace
  // 37 / 39  > Left- / RightArrow
  // 32       > Space
  // 16       > shift
  // 35 / 36  > End / Pos1
  // 46       > Del
  if((key >= 48 && key <= 57) || (key >= 96 && key <= 105) || key == 8 || key == 37 || key == 39 || key == 32 || key == 16 || key == 35 || key == 36 || key == 46) return true;
  else return false;
}

function turnBlack(ele) {
  ele.style.color = '#000';
}

function countChars() {
  allowedChars = 255;
  leftChars = allowedChars - document.getElementById('rqAdditions').value.length;
  if(leftChars <= 0) {
    document.getElementById('chars').innerHTML = '(' + charsString.split('%CHARS%').join(0) + ')';
    document.getElementById('rqAdditions').value = document.getElementById('rqAdditions').value.substring(0, allowedChars); 
  } else document.getElementById('chars').innerHTML = '(' + charsString.split('%CHARS%').join(leftChars) + ')';
}

function showCompanyField(val) {
  if(val == 'company') document.getElementById('companyName').style.display = 'block';
  else document.getElementById('companyName').style.display = 'none';
}

function changeAdults()
{
	var actAdults = document.getElementById('rqTraveler').value;
	var actChilds = document.getElementById('rqChildren').value;
	//clear selectbox Childs
	for (i = document.getElementById('rqTraveler').length; i > 0 ; i--)
	{
		document.getElementById('rqTraveler')[i] = null;
	}
	
	if (actChilds < minChilds) adults = maxPersons - minChilds;	
	else adults = maxPersons - actChilds;
		
	//fill selectbox Childs
	for (i = 1; i <= adults; i++)
	{
		addme = new Option(adultsText(i), i, false, ((actAdults == i) ? true : false));
		document.getElementById('rqTraveler')[document.getElementById('rqTraveler').length] = addme;
	}
}

function changeChilds()
{
	var actAdults = document.getElementById('rqTraveler').value;
	var actChilds = document.getElementById('rqChildren').value;
	//clear selectbox Childs
	for (i = document.getElementById('rqChildren').length; i > 0 ; i--)
	{
		document.getElementById('rqChildren')[i] = null;
	}
	
	if (actAdults > 0) var childs = maxPersons - actAdults;
	else var childs = maxPersons - 1;
	//fill selectbox Childs
	for (i = 0; i <= childs; i++)
	{
		addme = new Option(childsText(i), i, false, ((actChilds == i) ? true : false));
		document.getElementById('rqChildren')[document.getElementById('rqChildren').length] = addme;
	}
}

//return adultsText
function adultsText(persons)
{
	var text = '';
	if (persons == 1) text = '1 ' + Translations[languageCode]['bookingAdult'];
	else text = persons + ' ' + Translations[languageCode]['bookingAdults'];
	return text;
}

//return childstext
function childsText(childs)
{
	var text = '';
	if (childs == 0) text = Translations[languageCode]['bookingNone'];
	else if (childs == 1) text = '1 ' + Translations[languageCode]['bookingCountChild'];
	else text = childs + ' ' + Translations[languageCode]['bookingCountChilds'];
	return text;
}
