// Title: Form Validator
// Version: 1.2
// Date: 12/10/2005 (dd/mm/yyyy)

// regular expressions or function to validate the format
<!--

function isValidDate(dateStr) {

   var datePat = /^\d{4}(\/|-)\d{1,2}(\/|-)\d{1,2}$/

   if (dateStr.match(datePat)) {

//        alert(matchArray[0]+"\n"+matchArray[1]+"\n"+matchArray[2]+"\n")

       return true

   } else {

       return false

   }

}

function dateDiff() {

   frm = document.form1;

   diff  = new Date();

   var dateto = frm.in_year.options[frm.in_year.selectedIndex].value + "/" + frm.in_month.options[frm.in_month.selectedIndex].value + "/" + frm.in_date.options[frm.in_date.selectedIndex].value;

   var datefrom = frm.out_year.options[frm.out_year.selectedIndex].value + "/" + frm.out_month.options[frm.out_month.selectedIndex].value + "/" + frm.out_date.options[frm.out_date.selectedIndex].value;



   if (isValidDate(dateto)&&isValidDate(datefrom)) {

       matchArray1 = dateto.split(/\/|-/)

       Year1 = matchArray1[0]

       Month1 = matchArray1[1]-1

       Day1 = matchArray1[2]

       matchArray2 = datefrom.split(/\/|-/)

       Year2 = matchArray2[0]

       Month2 = matchArray2[1]-1

       Day2 = matchArray2[2]

       date1 = new Date(Year1,Month1,Day1)

       date2 = new Date(Year2,Month2,Day2)

   }

   else {


       return false;

   }

   diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

   timediff = diff.getTime();

   days = Math.floor(timediff / (1000 * 60 * 60 * 24));

   timediff -= days * (1000 * 60 * 60 * 24);

   frm.total_nights.value = days;

   return true;

}

//-->
// form fields description structure
var a_fields = {
	'title': {
		'l': 'Title',  // label
		'r': false,    // required
		'f': 'alpha',  // format (see below)
		't': 't_title',// id of the element to highlight if input not validated
		
		'm': null,     // must match specified form field
		'mn': 2,       // minimum length
		'mx': 10       // maximum length
	},
	'first_name':{'l':'First Name','r':true,'f':'alpha','t':'t_first_name'},
	'last_name':{'l':'Last Name','r':true,'f':'alpha','t':'t_last_name'},
	'street_address':{'l':'Street Address','r':true,'t':'t_street_address'},
	'country':{'l':'Country','r':true,'t':'t_country'},
	'telephone_number':{'l':'Telephone Number','r':true,'f':'phone','t':'t_telephone_number'},
	'email':{'l':'E-mail','r':true,'f':'email','t':'t_email'},
	'room_type':{'l':'Room Type','r':true,'t':'t_room_type'},
	'bed_type':{'l':'Room Type','r':true,'t':'t_bed_type'},
	'no_rooms':{'l':'Number of Rooms','r':true,'f':'phone','t':'t_no_rooms'},
	'no_adults':{'l':'Number of Adults','r':true,'f':'phone','t':'t_no_adults'},
	'in_date':{'l':'Date Check-in','r':true,'t':'t_in_date'},
	'in_month':{'l':'Month Check-in','r':true,'t':'t_in_date'},
	'in_year':{'l':'Year Check-in','r':true,'t':'t_in_date'},
	'out_date':{'l':'Date Check-out','r':true,'t':'t_out_date'},
	'out_month':{'l':'Month Check-out','r':true,'t':'t_out_date'},
	'out_year':{'l':'Year Check-out','r':true,'t':'t_out_date'}
},

o_config = {
	'to_disable' : ['Submit', 'Reset'],
	'alert' : 1
}

// validator constructor call
var v = new validator('registration', a_fields, o_config);
