/*****************************************************************************/
/* Strawberry Fair Hotel Javascript Code                                     */
/* Created March 2006 from existing code                                     */
/* 25/01/2007 - Google maps loading code added                               */
/* 25/01/2007 - Image rotation code added                                    */
/* 27/11/2009 - Updated                                                      */
/* 16/12/2009 - Updated email validation / Image rotation code removed       */
/* 23/06/2010 - Added date/time to subject to workaround gmail problem       */
/* 11/02/2011 - Changed email validation so email from address populated     */
/* 11/02/2011 - Removed Google maps apip code as no longer needed            */
/*****************************************************************************/

/*****************************************************************************/
/* Enquiry form validation code                                              */
/*****************************************************************************/
function KP_validateForm(){

   var currDate = new Date();
   var month = currDate.getMonth() + 1
   var day = currDate.getDate()
   var year = currDate.getFullYear()
   var hours = currDate.getHours()
   var minutes = currDate.getMinutes()

   
   if(document.forms['enqForm'].Name.value == ""){
      alert("Please enter your name")
	  document.forms['enqForm'].Name.focus()
	  return
   }

   if(document.forms['enqForm'].email.value == ""){
      alert("Please enter your email address")
	  document.forms['enqForm'].email.focus()
	  return
   }

   if(document.forms['enqForm'].Enquiry.value == ""){
      alert("Please enter details of your enquiry")
	  document.forms['enqForm'].Enquiry.focus()
	  return
   }
       
   if (KP_emailCheck(document.forms['enqForm'].email.value) == false){
      document.forms['enqForm'].email.value = ""
      document.forms['enqForm'].email.focus()
      return
   }
   
   // Add date/time to subject (gmail problem workaround)
   document.forms['enqForm'].subject.value = "Website Enquiry: " + day + "/" + month + "/" + year + " " + hours + ":" + minutes
   
   document.forms['enqForm'].submit();
}

function KP_emailCheck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail Address...Please try again")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail Address...Please try again")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail Address...Please try again")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail Address...Please try again")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail Address...Please try again")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail Address...Please try again")
	    return false
	 }
		
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail Address...Please try again")
	    return false
	 }

	 return true					
}

