/* This method sets the dayField and monthYearField from the formName form to the specified date value */
function setFormDayMonthYearFields(date, formName, dayField, monthField, yearField) {
	var day = date.getDate();
	var month = date.getMonth()+1;
	var year = date.getYear();
	if (day<10) day = '0'+day;
	if (month<10) month = '0'+month;

	<!-- IE returns 2004 for the year, NN returns 104 -->
	if (year<2000) year=1900+year;
	
	document[formName][dayField].value = day;
	document[formName][monthField].value = month;
	document[formName][yearField].value = year;
}

			/**
			 * This method prefills the outbound date with 2 days in the future.
			 */
			function prefillAankomstDate() {
				var date = new Date();
				date.setDate(date.getDate()+1);
				
				setFormDayMonthYearFields(date, 'checking', 'van_dag', 'van_maand', 'van_jaar');
			}

			/**
			 * This method prefills the inbound date with 7 days after the outbound date.
			 */
			function prefillVertrekDate() {
				var day = document.checking['van_dag'].value;
				var month = document.checking['van_maand'].value;
				var year = document.checking['van_jaar'].value;

				
				var date = new Date(year, month-1, day);
				
				date.setDate(date.getDate()+1);
				
				setFormDayMonthYearFields(date, 'checking', 'tot_dag', 'tot_maand', 'tot_jaar');
			}
			

function openWindow(url, naam, features) 
  {
    if (typeof _hwin == "object" && _hwin && !_hwin.closed) 
      {
	_hwin.location.replace(url)
      } 
    else 
      {
	_hwin = window.open(url, naam, features);
      }
    setTimeout("_hwin.focus()", 255);
}



/////////
function CheckRequiredFields(arr) {
var errormessage = new String();
// Put field checks below this point.

	//Naw gegevens controleren
    if ( stringEmpty ( document.checking.achternaam.value ) )
	{ errormessage += "\n-There is no lastname specified."; }
    if ( stringEmpty ( document.checking.telefoon.value ) )
	{ errormessage += "\n-There is no telephonenumber specified."; }
    if ( stringEmpty ( document.checking.adres.value ) )
	{ errormessage += "\n-There is no address specified."; }
    if ( stringEmpty ( document.checking.postcode.value ) )
	{ errormessage += "\n-There is no postal code specified."; }
    if ( stringEmpty ( document.checking.plaats.value ) )
	{ errormessage += "\n-There is no city specified."; }

    if ( stringEmpty ( document.checking.email.value ) )
	{ errormessage += "\n-There is no e-mailaddress specified."; }

    else if ( noAtSign ( document.checking.email.value ) )
	{ errormessage += "\n-The e-mailaddress is missing the '@'-sign."; }
    else if ( nothingBeforeAt ( document.checking.email.value ) )
	{ errormessage += "\n-There are no characters placed before the '@'-sign."; }
    else if ( noValidPeriod ( document.checking.email.value ) )
	{ errormessage += "\n-There is no dot in the e-mailaddress."; }
    else if ( noValidSuffix ( document.checking.email.value ) )
	{ errormessage += "\n-There is no domain address specified."; }

        
if(NoneWithCheck(document.checking.roomcode))
	{ errormessage += "\n-There is no room specified."; }
if(arr == '0') {    
	if(NoneWithCheck(document.checking.cctype))
		{ errormessage += "\n-There is no creditcard type specified."; }
	if(WithoutContent( document.checking.ccnumber.value ) )
		{ errormessage += "\n-There is no creditcard number specified."; }
	if(WithoutSelectionValue(document.checking.ccexpiry_m))
		{ errormessage += "\n-There is no expiry month specified for the creditcard."; }
	if(WithoutSelectionValue(document.checking.ccexpiry_y))
		{ errormessage += "\n-There is no expiry year specified for the creditcard."; }
}
if(WithoutCheck(document.checking.av))
	{ errormessage += "\n-You didn't agree the terms and conditions of cancellation and the general terms and conditions."; }
	
	
	
// Put field checks above this point.
if(errormessage.length > 2) {
	alert('The following information is missing or incorrect:\n' + errormessage);
	return false;
	}
return true;
} // end of function CheckRequiredFields()


/////////
function CheckEmaillijstFields() {
var errormessage = new String();
// Put field checks below this point.

    if ( WithoutContent ( document.emaillist.naam.value ) )
	{ errormessage += "\n-There is no name specified."; }

    if ( WithoutContent ( document.emaillist.emailadres.value ) )
	{ errormessage += "\n-There is no e-mailaddress specified."; }

    else if ( noAtSign ( document.emaillist.emailadres.value ) )
	{ errormessage += "\n-The e-mailaddress is missing the '@'-sign."; }
    else if ( nothingBeforeAt ( document.emaillist.emailadres.value ) )
	{ errormessage += "\n-There are no characters placed before the '@'-sign."; }
    else if ( noValidPeriod ( document.emaillist.emailadres.value ) )
	{ errormessage += "\n-There is no dot in the e-mailaddress."; }
    else if ( noValidSuffix ( document.emaillist.emailadres.value ) )
	{ errormessage += "\n-There is no domain address specified."; }

        
// Put field checks above this point.
if(errormessage.length > 2) {
	alert(errormessage);
	return false;
	}
return true;
} // end of function CheckEmailField()


/////////
function CheckContactFields() {
var errormessage = new String();
// Put field checks below this point.

    if ( stringEmpty ( document.contact.naam.value ) )
	{ errormessage += "You did not specified your name."; }


	
// Put field checks above this point.
if(errormessage.length > 2) {
	alert(errormessage);
	return false;
	}
return true;
} // end of function CheckRequiredFields()




///////////////////////////////////////////////////////////
function WithoutContent(ss) {
if(ss.length > 0) { return false; }
return true;
}

function NoneWithContent(ss) {
for(var i = 0; i < ss.length; i++) {
	if(ss[i].value.length > 0) { return false; }
	}
return true;
}

function NoneWithCheck(ss) {
for(var i = 0; i < ss.length; i++) {
	if(ss[i].checked) { return false; }
	}
return true;
}

function WithoutCheck(ss) {
if(ss.checked) { return false; }
return true;
}

function WithoutSelectionValue(ss) {
for(var i = 0; i < ss.length; i++) {
	if(ss[i].selected) {
		if(ss[i].value.length) { return false; }
		}
	}
return true;
}


function checkValidation ( addressField ) {
    if ( stringEmpty ( addressField.value ) )
        alert ( "Error! There is no E-Mail address entered" );
    else if ( noAtSign ( addressField.value ) )
        alert ( "Error! The E-Mail address does not contain an '@' character" );
    else if ( nothingBeforeAt ( addressField.value ) )
        alert ( "Error! An E-Mail address must contain at least one character before the '@' character" );
    else if ( noLeftBracket ( addressField.value ) )
        alert ( "Error! The E-Mail address contains a right square bracket ']',\nbut no corresponding left square bracket '['" );
    else if ( noRightBracket ( addressField.value ) )
        alert ( "Error! The E-Mail address contains a left square bracket '[',\nbut no corresponding right square bracket ']'" );
    else if ( noValidPeriod ( addressField.value ) )
        alert ( "Error! An E-Mail address must contain a period ('.') character" );
    else if ( noValidSuffix ( addressField.value ) )
        alert ( "Error! An E-Mail address must contain a two or three character suffix" );
    else
        return (true);

    return ( false );
}

function linkCheckValidation ( formField ) {
    if ( checkValidation ( formField ) == true ) {
        alert ( 'E-Mail Address Validates OK' );
    }

    return ( false );
}

function stringEmpty ( address ) {
    // CHECK THAT THE STRING IS NOT EMPTY
    if ( address.length < 1 ) {
        return ( true );
    } else {
        return ( false );
    }
}

function noAtSign ( address ) {
    // CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
    if ( address.indexOf ( '@', 0 ) == -1 ) {
        return ( true )
    } else {
        return ( false );
    }
}

function nothingBeforeAt ( address ) {
    // CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
    if ( address.indexOf ( '@', 0 ) < 1 ) {
        return ( true )
    } else {
        return ( false );
    }
}

function noLeftBracket ( address ) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR LEFT BRACKET
    if ( address.indexOf ( '[', 0 ) == -1 && address.charAt ( address.length - 1 ) == ']' ) {
        return ( true )
    } else {
        return ( false );
    }
}

function noRightBracket ( address ) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR RIGHT BRACKET
    if ( address.indexOf ( '[', 0 ) > -1 && address.charAt ( address.length - 1 ) != ']' ) {
        return ( true );
    } else {
        return ( false );
    }
}

function noValidPeriod ( address ) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if ( address.indexOf ( '@', 0 ) > 1 && address.charAt ( address.length - 1 ) == ']' )
        return ( false );

    // CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
    if ( address.indexOf ( '.', 0 ) == -1 )
        return ( true );

    return ( false );
}

function noValidSuffix ( address ) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if ( address.indexOf ( '@', 0 ) > 1 && address.charAt ( address.length - 1 ) == ']' )
        return ( false );

    // CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
    var len = address.length;
    var pos = address.lastIndexOf ( '.', len - 1 ) + 1;
    if ( ( len - pos ) < 2 || ( len - pos ) > 3 ) {
        return ( true );
    } else {
        return ( false );
    }
}


