﻿
//LTRIM
function LTrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

//RTRIM
function RTrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
			var i = s.length - 1;       // Get length of string
			while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      	i--;
			s = s.substring(0, i+1);
   }
	return s;
}

//TRIM
function Trim(str)
{
   return RTrim(LTrim(str));
}

function checkMail(e1)
{
	var x = e1;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) {
		return true;
	}else{
		return false;
	} 
}


//CHECK THE CONTACTUS FORM
function check_contactus(form)  
{   
	//var onlyletters = /^[A-Za-zΑ-Ωα-ω_ \-]+$/;
	//var onlydigit	=	/^[0-9]+$/;
	var field 

	// check for the Email field
	field = Trim(form.Email.value);	 
	if  (checkMail(field) == false )
	{
		// put the prompt in the Email field 
		form.Email.focus(); 
		form.Email.style.background='#EE6565';
		alert("Fältet 'E-post' är tomt eller felaktigt ifyllt!");
		return false;
	}
	form.Email.style.background='#FFFFFF';
	
	// check for the Subject field
	field = Trim(form.Subject.value);	 

	if  (field.length  < 1 )
	{
		// put the prompt in the Subject field 
		form.Subject.focus(); 
		form.Subject.style.background='#EE6565';
		alert("Fältet 'Subject' är tomt!");
		return false;
	}
	form.Subject.style.background='#FFFFFF';
	
	// check for the message field
	field = Trim(form.Message.value);	 

	if  (field.length  < 1 )
	{
		// put the prompt in the message field 
		form.Message.focus(); 
		form.Message.style.background='#EE6565';
		alert("Fältet 'Meddelande' är tomt!");
		return false;
	}
	form.Message.style.background='#FFFFFF';
	
	// check for the captchacode field
	field = Trim(form.captchacode.value);	 

	if  (field.length  < 1 )
	{
		// put the prompt in the message field 
		form.captchacode.focus(); 
		form.captchacode.style.background='#EE6565';
		alert("Vänligen fyll i karaktärerna ifrån säkerhetsbilden");
		return false;
	}
	form.captchacode.style.background='#FFFFFF';
	
}


//CHECK THE GROUPBOOKING FORM
function check_groupbooking(form)  
{   
	//var onlyletters = /^[A-Za-zΑ-Ωα-ω_ \-]+$/;
	//var onlydigit	=	/^[0-9]+$/;
	var field 
	
	// check for the Name field
	field = Trim(form.Name.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Name field 
		form.Name.focus(); 
		form.Name.style.background='#EE6565';
		alert("Fältet 'Namn' är tomt!");
		return false;
	}
	form.Name.style.background='#FFFFFF';
	
	// check for the Surname field
	field = Trim(form.Surname.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Surname field 
		form.Surname.focus(); 
		form.Surname.style.background='#EE6565';
		alert("Fältet 'Efternamn' är tomt!");
		return false;
	}
	form.Surname.style.background='#FFFFFF';
	
	// check for the Group field
	field = Trim(form.Group.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Group field 
		form.Group.focus(); 
		form.Group.style.background='#EE6565';
		alert("Fältet 'Grupp/Organisation' är tomt!");
		return false;
	}
	form.Group.style.background='#FFFFFF';
	
	// check for the NoOfTravelers field
	field = Trim(form.NoOfTravelers.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the NoOfTravelers field 
		form.NoOfTravelers.focus(); 
		form.NoOfTravelers.style.background='#EE6565';
		alert("Fältet 'Antal resenärer totalt' är tomt");
		return false;
	}
	form.NoOfTravelers.style.background='#FFFFFF';
	
	// check for the Destination field
	field = Trim(form.Destination.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Destination field 
		form.Destination.focus(); 
		form.Destination.style.background='#EE6565';
		alert("Fältet 'Destination' är tomt");
		return false;
	}
	form.Destination.style.background='#FFFFFF';
	
	// check for the Checkin field
	field = Trim(form.Checkin.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Checkin field 
		form.Checkin.focus(); 
		form.Checkin.style.background='#EE6565';
		alert("Fältet 'Idealiskt incheckningdatum' är tomt!");
		return false;
	}
	form.Checkin.style.background='#FFFFFF';
	
	// check for the Checkout field
	field = Trim(form.Checkout.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Checkout field 
		form.Checkout.focus(); 
		form.Checkout.style.background='#EE6565';
		alert("Fältet 'Idealiskt utcheckningdatum' är tomt!");
		return false;
	}
	form.Checkout.style.background='#FFFFFF';
	
	// check for the StarRating field
	field = Trim(form.StarRating.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the StarRating field 
		form.StarRating.focus(); 
		form.StarRating.style.background='#EE6565';
		alert("Fältet 'Antal stjärnor' är tomt!");
		return false;
	}
	form.StarRating.style.background='#FFFFFF';
	
	// check for the BoardOption field
	field = Trim(form.BoardOption.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the BoardOption field 
		form.BoardOption.focus(); 
		form.BoardOption.style.background='#EE6565';
		alert("Fältet 'Boendealternativ' är tomt!");
		return false;
	}
	form.BoardOption.style.background='#FFFFFF';
	
	// check for the Email field
	field = Trim(form.Email.value);	 
	if  (checkMail(field) == false )
	{
		// put the prompt in the Email field 
		form.Email.focus(); 
		form.Email.style.background='#EE6565';
		alert("Fältet 'E-post' är tomt eller felaktigt ifyllt!");
		return false;
	}
	form.Email.style.background='#FFFFFF';
	
	// check for the Telephone field
	field = Trim(form.Telephone.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Telephone field 
		form.Telephone.focus(); 
		form.Telephone.style.background='#EE6565';
		alert("Fältet 'Telefon' är tomt!");
		return false;
	}
	form.Telephone.style.background='#FFFFFF';
	
	// check for the Country field
	field = Trim(form.Country.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Country field 
		form.Country.focus(); 
		form.Country.style.background='#EE6565';
		alert("Fältet 'Land'  är tomt!");
		return false;
	}
	form.Country.style.background='#FFFFFF';
}	
	
	
//CHECK THE SEND TO A FRIEND FORM
function check_sendtofriendform(form)  
{   
	//var onlyletters = /^[A-Za-zΑ-Ωα-ω_ \-]+$/;
	//var onlydigit	=	/^[0-9]+$/;
	var field 
	
	// check for the name1 field
	field = Trim(form.name1.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the name1 field 
		form.name1.focus(); 
		form.name1.style.background='#EE6565';
		alert("Fältet 'Namn' är tomt!");
		return false;
	}
	form.name1.style.background='#FFFFFF';
	
	// check for the email1 field
	field = Trim(form.email1.value);	 
	if  (checkMail(field) == false )
	{
		// put the prompt in the email1 field 
		form.email1.focus(); 
		form.email1.style.background='#EE6565';
		alert("Fältet 'E-post' är tomt eller felaktigt ifyllt!");
		return false;
	}
	form.email1.style.background='#FFFFFF';
	
	// check for the name2 field
	field = Trim(form.name2.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the name2 field 
		form.name2.focus(); 
		form.name2.style.background='#EE6565';
		alert("Fältet 'Namn' är tomt!");
		return false;
	}
	form.name2.style.background='#FFFFFF';
	
	// check for the email2 field
	field = Trim(form.email2.value);	 
	if  (checkMail(field) == false )
	{
		// put the prompt in the email2 field 
		form.email2.focus(); 
		form.email2.style.background='#EE6565';
		alert("Fältet 'E-post' är tomt eller felaktigt ifyllt!");
		return false;
	}
	form.email2.style.background='#FFFFFF';
}	
	
	
	
	
//CHECK THE ADD HOTEL REVIEW FORM
function check_hotelreviews(form)  
{   
	//var onlyletters = /^[A-Za-zΑ-Ωα-ω_ \-]+$/;
	//var onlydigit	=	/^[0-9]+$/;
	var field 
	
	// check for the Alias field
	field = Trim(form.Alias.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Alias field 
		form.Alias.focus(); 
		form.Alias.style.background='#EE6565';
		alert("Fältet 'Postat av' är tomt!");
		return false;
	}
	form.Alias.style.background='#FFFFFF';
	
	// check for the Email field
	field = Trim(form.Email.value);	 
	if  (checkMail(field) == false )
	{
		// put the prompt in the Email field 
		form.Email.focus(); 
		form.Email.style.background='#EE6565';
		alert("Fältet 'E-post' är tomt eller felaktigt ifyllt!");
		return false;
	}
	form.Email.style.background='#FFFFFF';
	
	// check for the Rating field
	field = Trim(form.Rating.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Rating field 
		form.Rating.focus(); 
		form.Rating.style.background='#EE6565';
		alert("Fältet 'Klassificering' är tomt!");
		return false;
	}
	form.Rating.style.background='#FFFFFF';
	
	// check for the Review field
	field = Trim(form.Review.value);	 
	if  (field.length  < 1 )
	{
		// put the prompt in the Review field 
		form.Review.focus(); 
		form.Review.style.background='#EE6565';
		alert("Fältet 'Recension' är tomt!");
		return false;
	}
	form.Review.style.background='#FFFFFF';
	if  (field.length  >2999 )
	{
		// put the prompt in the Review field 
		form.Review.focus(); 
		form.Review.style.background='#EE6565';
		alert("Fältet 'Recension' innehåller mer än 3000 tecken!");
		return false;
	}
	form.Review.style.background='#FFFFFF';
}

