
var cookie_expire = 183
var cookie_domain = ".gozorentals.com"
var cookie_path = "/"
var _username = ""
var confirm_message = ""
var formname = "enquiries"
var send_form = 1
var this_date = new Date()
this_date = this_date.toLocaleString()
var alphamess="Only alphabetic, hyphen and whitespace characters are allowed in this field!"
var nummess="Only digit and whitespace characters are allowed in this field!"
var message="Copyright 2003 by 'Right click disabled by \nGozo Rentals. Copyright.";

function get_date(current_form) {
var this_date = new Date()
this_date = this_date.toLocaleString()
current_form.request.value = "Property Rental Enquiry: " + current_form.name.value + " " + current_form.name.value + " (" + this_date + ")" 
}


function setform(formname) {
formname.name.focus();
formname.name.select();
}

function setform2(formname, element) {
formname.element.focus();
formname.element.select();
}

if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
// document.onmousedown=noclick;


function focus_handler(field_message) {
    // Display a status message at the bottom of the browser for this field 
    status = field_message
}
function click_handler() {

    if (confirm("Click OK to send form now, or CANCEL if you want to return to edit the form!")) {
        return true
    }
    else {
        return false
    }
}


function openpopup(){
var popurl="thankyou.htm"
winpops=window.open(popurl,"","width=400,height=338,status,scrollbars,resizable,")
}

function form_check(current_form, sendform)   {

var returntype=true;

if (current_form.name.value == "")
    {
      alert("Please enter your name");
      changeBg('name');
      current_form.name.focus();
      current_form.name.select();
      return false;
    }

var returntype = check_alpha(current_form.name.value) 
if (!returntype) {
      alert(alphamess);
      changeBg('name');
      current_form.name.focus();
      current_form.name.select();
      return false;
}
resetBg('name');

if (current_form.surname.value == "")
    {
      alert("Please enter your surname");
      changeBg('surname');
      current_form.surname.focus();
      current_form.surname.select();
      return false;
    }

var returntype = check_alpha(current_form.surname.value) 
if (!returntype) {
      alert(alphamess);
      changeBg('surname');
      current_form.surname.focus();
      current_form.surname.select();
      return false;
}
resetBg('surname');


//if (current_form.home_phone.value == "")
//    {
//      alert("Please enter your home telephone number");
//      changeBg('home_phone');
//      current_form.home_phone.focus();
//      current_form.home_phone.select();

//      return false;
//    }
var returntype = check_num(current_form.mobile.value) 
if (!returntype) {
      alert(nummess);
      changeBg('mobile');
      current_form.mobile.focus();
      current_form.mobile.select();
      return false;
}
else {
      resetBg('mobile');
     }
var returntype = check_num(current_form.home_phone.value) 
if (!returntype) {
      alert(nummess);
      changeBg('home_phone');
      current_form.home_phone.focus();
      current_form.home_phone.select();
      return false;
}
else {
      resetBg('home_phone');
     }
var returntype = check_num(current_form.work_phone.value) 
if (!returntype) {
      alert(nummess);
      changeBg('work_phone');
      current_form.work_phone.focus();
      current_form.work_phone.select();
      return false;
}
else {
      resetBg('work_phone');
     }   
if (current_form.email.value == "")
    {
      alert("Please enter your email address");
      changeBg('email');
     current_form.email.focus();
       return (false);
    }

    if (current_form.email.value.indexOf("@") == -1 || current_form.email.value.indexOf(".") == -1 ||
                             current_form.email.value == "")
    {
      alert("You have not entered a valid email address (e.g. yourname@yourdomain.ext)");
      changeBg('email');
      current_form.email.focus();
      current_form.email.select();
      return (false);
    }

else {
      resetBg('email');
     }
     
var returntype = check_num(current_form.fax.value) 
if (!returntype) {
      alert(nummess);
      changeBg('fax');
      current_form.fax.focus();
      current_form.fax.select();
      return false;
}
else {
      resetBg('fax');
     }


if (current_form.arrival.value == "")
    {
      alert("Please enter your arrival date (dd/mm/yyyy)");
      changeBg('arrival');
      current_form.arrival.focus();
      current_form.arrival.select();
      return false;
    }
  
var returntype = check_date(current_form.arrival)
if (!returntype) {
      alert("Please enter a valid date (dd/mm/yyyy)");
      changeBg('arrival');
      current_form.arrival.focus();
      current_form.arrival.select();
      return false;
    }
resetBg('arrival');

if (current_form.departure.value == "")
    {
      alert("Please enter your departure date (dd/mm/yyyy)");
      changeBg('departure');
      current_form.departure.focus();
      current_form.departure.select();
      return false;
    }
var returntype = check_date(current_form.departure)
if (!returntype) {
      alert("Please enter a valid date (dd/mm/yyyy)");
      changeBg('departure');
      current_form.departure.focus();
      current_form.departure.select();
      return false;
    }
resetBg('departure');
if (current_form.adults.options[0].selected) {
    	alert('We need to know how may adults will be staying!');
     	changeBg('adults');
     	current_form.adults.focus();
    	return (false);
  }
else {
      resetBg('adults');
     }
if (current_form.children.options[0].selected) {
    	alert('We need to know how may children will be staying!');
     	changeBg('children');
     	current_form.children.focus();
    	return (false);
  }
else {
      resetBg('children');
     }     

if (current_form.properties.options[0].selected) {
    	alert('You need to select one or more properties you are interest in!');
     	changeBg('properties');
     	current_form.properties.focus();
    	return (false);
  }
else {
      resetBg('properties');
     }
var this_date = new Date()
this_date = this_date.toLocaleString()
current_form.request.value = "Property Rental Enquiry: " + current_form.properties.value + " (" + this_date + ")" 

//  only do this if form is being submitted
if (sendform == 1) {


// basic validation passed. Now prompt user to send form

//	display_data(current_form);    
    
    	confirm_message += "\n______________________________\n\n" +
                       "Do you want to submit this data?"
	if (confirm(confirm_message)) {
       	 	return true;
    	}
    	else {
        	return false;
    	}

}
return (true);

}

function openpopup2(){
var popurl="formreply.htm"
winpops=window.open(popurl,"","width=704,height=500,status,scrollbars,resizable,")
}

function check_date(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = "/";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
	return (false);
   }
return (true);
}

function check_alpha(current_field)
{

var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ -abcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
  var checkStr = current_field;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
 }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}


function check_num(current_field)
{
  var checkOK = "0123456789- \t\r\n\f";
  var checkStr = current_field;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}



function get_selections(current_list) {

    var selected_array = new Array()
    var current_index = 0
    for (var counter = 0; counter < current_list.options.length; counter++) {
        if (current_list.options[counter].selected) {
            selected_array[current_index] = current_list.options[counter].index
            current_index++
        }
    }
    return selected_array
}


function resetBg(layername) { 
   if (document.all) document.all(layername).style.backgroundColor="#dfefff"; 
   else if (document.layers) document.layers[layername].bgColor='white';
} 
function changeBg(layername) { 
   if (document.all) document.all(layername).style.backgroundColor="#fA7d5C"; 
   else if (document.layers) document.layers[layername].bgColor='yellow';
} 




