function clearname()
{
if(document.getElementById("mailinglist").mailname.value=='')document.getElementById("mailinglist").mailname.value='Name (Optional)';
}

function populatename()
{
if(document.getElementById("mailinglist").mailname.value=='Name (Optional)')document.getElementById("mailinglist").mailname.value='';
}

function clearemail()
{
if(document.getElementById("mailinglist").mailemail.value=='')document.getElementById("mailinglist").mailemail.value='Email Address';
}

function populateemail()
{
if(document.getElementById("mailinglist").mailemail.value=='Email Address')document.getElementById("mailinglist").mailemail.value='';
}

function checkemail() {
      if (document.getElementById("mailinglist").security2.value!="")
		 {alert("Please fill in all Required Fields marked with (*)");
         return false;}
}

function echeck(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. Please Correct.")
		   return false
		}

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

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

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

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

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

 		 return true					
	}

function validateemail(){
	var emailID=document.getElementById("mailinglist").mailemail
	
	if (echeck(emailID.value)==false){
		return false
	}
	return true
}

function autotab(original,destination){
	  if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))destination.focus()
}

function unsure()
{
document.getElementById("booking").eventdate.value="Undecided";
}

function other()
{
if (document.getElementById("booking").occasion.value=="Other") {document.getElementById("booking").occasionother.disabled=false;} else {document.getElementById("booking").occasionother.disabled=true;document.getElementById("booking").occasionother.value="";}
}

function other2()
{
if (document.getElementById("booking").foundsite.value=="Other") {document.getElementById("booking").foundsiteother.disabled=false;} else {document.getElementById("booking").foundsiteother.disabled=true;document.getElementById("booking").foundsiteother.value="";}
}

function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function checkform() {
      if (document.getElementById("booking").name.value=="" ||
	      document.getElementById("booking").email.value=="" ||
	      document.getElementById("booking").eventdate.value=="" ||
		  document.getElementById("booking").starttime1.value=="-" ||
		  document.getElementById("booking").starttime2.value=="-" ||
		  document.getElementById("booking").pricerange.value=="" ||
		  document.getElementById("booking").security.value!="")
		 {alert("Please fill in all Required Fields marked with (*)"); 
         return false;}
}

function echeck(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. Please Correct.")
		   return false
		}

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

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

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

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

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

 		 return true					
	}

function validateform(){
	var emailID=document.getElementById("booking").email
	
	if (echeck(emailID.value)==false){
		return false
	}
	return true
}
$(document).ready(function(){
	$("#eventdate").datepicker({ 
		showOn: "both", 
		buttonImage: "../../images/calendar.gif", 
		buttonImageOnly: true
	});
});
