// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// email

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Pease enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

function checkEmailReco (strng) {
var error="";
if (strng != "") {
 
  var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = strng + " is not a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
 
}

   
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPrice (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the rent amount.\n";
}

else
{
    if (isNaN(parseInt(strng))) {
       error = "The rent field contains illegal characters!\n";
  
    }
}
return error;
}

function checkHandphone (strng) {
	var error = "";
	if (strng == "") {
	   error = "You didn't enter your mobile phone number. \n";
	}

	else
	{
	    if (isNaN(parseInt(strng))) {
	       error = "Just enter your plain phone number without any delimiters and without the +65!\n";
	  
	    }
	}

return error;
}

function checkSize (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the size.\n";
}
else
{

    if (isNaN(parseInt(strng))) {
       error = "The size field contains illegal characters!\n";
  
    }
}    

return error;
}

function checkUtilities (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the utilities amount.\n";
}

else
{
    if (isNaN(parseInt(strng))) {
       error = "The utilities field contains illegal characters!\n";
  
    }
}

return error;
}

function checkDeposit (strng) {
var error = "";


if (strng != "")
{
    if (isNaN(parseInt(strng))) {
       error = "The deposit field contains illegal characters!\n";
  
    }
}

return error;
}

function checkAgentfee (strng) {
var error = "";
if (strng != "")
{
    if (isNaN(parseInt(strng))) {
       error = "The agent fee field contains illegal characters!\n";
  
    }
}
else
{
	error = "You have to specify an agent fee. Put 0 if you are not an agent.\n";	
}

return error;
}

function checkTitle (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a title.\n";
}
return error;
}

function checkText (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the text.\n";
}
return error;
}

function checkName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your name.\n";
}
return error;
}

function checkFirstName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your first name.\n";
}
return error;
}

function checkLastName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your last name.\n";
}
return error;
}

function checkStreetName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a street name.\n";
}
return error;
}

function checkHostelName (strng) {
	var error = "";
	if (strng == "") {
	   error = "You didn't enter the hostel name.\n";
	}
	return error;
	}

function checkHouseNumber (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your block/house number.\n";
}


return error;
}

function checkFloorNumber (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your floor number.\n";
}
else
{

    if (isNaN(parseInt(strng))) {
       error = "The floor number field contains illegal characters!\n";
  
    }
}    

return error;
}

function checkUnitNumber (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your unit number.\n";
}
else
{

    if (isNaN(parseInt(strng))) {
       error = "The unit number field contains illegal characters!\n";
  
    }
}    
return error;
}

function checkRoomPriceEdit (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the new price for the room per night.\n";
}
else
{

    if (isNaN(parseInt(strng))) {
       error = "The room price field contains illegal characters!\n";
  
    }
}    
return error;
}

function checkMaxGuests (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the maximum number of guests allowed in that room.\n";
}
else
{

    if (isNaN(parseInt(strng))) {
       error = "The maximum guest number field contains illegal characters!\n";
  
    }
}    
return error;
}

function checkBedNumber (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the number of beds in that room.\n";
}
else
{

    if (isNaN(parseInt(strng))) {
       error = "The bed number field contains illegal characters!\n";
  
    }
}    
return error;
}

function checkCVV (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the CVV number.\n";
}
else
{

    if (isNaN(parseInt(strng))) {
       error = "The CVV number field contains illegal characters!\n";
  
    }
}    


return error;
}

function checkPostalCodeValid (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your postalcode.\n";
}
else
{

    if (isNaN(parseInt(strng))) {
       error = "The postalcode field contains illegal characters!\n";
  
    }
}    

return error;
}

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your phone number.\n";
}
return error;
}


function checkPostalcode (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a postal code.\n";
}
return error;
}

function checkAddress (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter an address.\n";
}
return error;
}

function checkDescription (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a description.\n";
}
return error;
}

function checkMailText (strng) {
	var error = "";
	if ((strng == "") || (strng == "Enter recommendation text here!")) {
	   error = "You didn't enter the email text.\n";
	}
	return error;
	}

function checkPics (theForm) {
var error = "";
var at_least_one = false;
var fields = theForm.elements["my_field[]"];
for (i=0; i<5; i++){
	if (!(fields[i].value == ""))
	{
		at_least_one = true;
		break;
	}
}
if (at_least_one == false)
{
	error = "You have to upload at least one picture.\n"
}
return error;
}

function checkUploadedPics (theForm) {
	var error = "";
	var at_least_one = false;
	var fields = theForm.elements["my_field[]"];
	for (i=0; i<6; i++){
		if (!(fields[i].value == ""))
		{
			at_least_one = true;
			break;
		}
	}
	if (at_least_one == false)
	{
		return confirm('Offers without pictures will mostly be ignored by users! \n\n Do you really want to proceed without uploading a picture?'); 
	}
	
	document.getElementById("uploading").style.display = "block";
	return true;
	}

function checkUploadedPicsEnq (theForm) {
	var error = "";
	var at_least_one = false;
	var fields = theForm.elements["my_field[]"];
	for (i=0; i<3; i++){
		if (!(fields[i].value == ""))
		{
			at_least_one = true;
			break;
		}
	}
	if (at_least_one == false)
	{
		return confirm('Do you really want to proceed without uploading a picture?'); 
	}
	return true;
	}

function checkUploadedPicsSTS (theForm) {
	var error = "";
	var at_least_one = false;
	var fields = theForm.elements["my_field[]"];
	for (i=0; i<6; i++){
		if (!(fields[i].value == ""))
		{
			at_least_one = true;
			break;
		}
	}
	if (at_least_one == false)
	{
		alert('You have to upload at least one picture.'); 
		return false;
	}
	
	document.getElementById("uploading").style.display = "block";
	document.getElementById('upload_pics').disabled = true
	return true;
	}

function checkAssociateMail (theForm) {
	var error = "";
	var at_least_one = false;
	var fields = theForm.elements["email_address[]"];
	for (i=0; i<5; i++){
		if (!(fields[i].value == ""))
		{
			at_least_one = true;
			break;
		}
	}
	if (at_least_one == false)
	{
		error = "You have to enter at least one email address.\n"; 
		
	}
	
	
	return error;
	}

function checkRoomPrice (theForm) {
var error = "";
var at_least_one = false;
var fields = theForm.elements["price[]"];
for (i=0; i<fields.length; i++){
	if (fields[i].value == "")
	{
		at_least_one = true;
	
	}
	else
	{
		 if (isNaN(parseInt(fields[i].value))) {
      		 error = "The price field contains illegal characters!\n";
  		 }	
	}
}
if (at_least_one == true)
{
	error = "You have to enter the price for all of your rooms.\n"
}
return error;
}


function checkDirections (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the directions.\n";
}
return error;
}

function checkContact (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the contact information.\n";
}
return error;
}

function checkPwEmpty (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}
return error;
}

function checkRetrieveEmpty (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter an eMail address.\n";
}
return error;
}

// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } 
return error;
}       


// non-empty textbox

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n"
  }
return error;	  
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
} 

function checkType(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose a rental type.\n";
    }    
return error;
}   

function checkDistrict(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose a district.\n";
    }    
return error;
} 

function checkMRT(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose the closest station.\n";
    }    
return error;
} 

function checkRoomtype(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose a roomtype.\n";
    }    
return error;
}     

function checkReEnter(theForm) {
var error = "";
if (theForm.email.value != theForm.re_email.value)
{
	error = "Reentered email doesn't match entered email!"
}
return error;
}

function checkReEnterPw(theForm) {
var error = "";
if (theForm.new_pw.value != theForm.new_pw_re.value)
{
	error = "Entered passwords are not the same!"
}
return error;
}

function checkReEnterRetrieveEmail(theForm) {
var error = "";
if (theForm.email.value != theForm.email_re.value)
{
	error = "Entered eMail addresses are not the same!"
}
return error;
}

function checkReEnterContact(theForm) {
var error = "";
if (theForm.sender_email.value != theForm.re_email.value)
{
	error = "Reentered email doesn't match entered email!"
}
return error;
}


function checkAccept(theForm) {
var error = "";
if (!theForm.accept.checked)
{
	error = "You have to accept the terms and conditions!"
}
return error;

}


function checkFromDate (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the starting date.\n";
}
else
{
	var dateFilter = /\d{2}-\d{2}-\d{4}/;
    if (!(dateFilter.test(strng))) { 
     error = "Invalid date format. Format accepted is: dd-mm-yyyy\n";
	}
	
}   
return error; 
}
function checkToDate (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the final date.\n";
}
else
{
	var dateFilter = /\d{2}-\d{2}-\d{4}/;
    if (!(dateFilter.test(strng))) { 
     error = "Invalid date format. Format accepted is: dd-mm-yyyy\n";
	}
	
}   
return error; 
}

function checkDeptDate (strng) {
	var error = "";
	if (strng == "") {
	   error = "You have to choose a date until which your place is bookable!\n";
	}
	
	return error; 
	}

function checkArrivalDate (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the arrival date.\n";
}
else
{
	var dateFilter = /\d{2}-\d{2}-\d{4}/;
    if (!(dateFilter.test(strng))) { 
     error = "Invalid date format. Format accepted is: dd-mm-yyyy\n";
	}
	
}   
return error; 
}
function checkWholeFormSignUp(theForm) {
    
    var why = "";
    why += checkFirstName(theForm.first_name.value);
    why += checkLastName(theForm.last_name.value);
    why += checkStreetName(theForm.street.value);
    why += checkHouseNumber(theForm.block.value);
    why += checkFloorNumber(theForm.floor.value);
    why += checkUnitNumber(theForm.unit.value);
    why += checkPostalCodeValid(theForm.postalcode.value);
    why += checkHandphone(theForm.handphone.value);
    why += checkEmail(theForm.email.value);
    why += checkReEnterRetrieveEmail(theForm);
    
    why += checkStreetName(theForm.rm_street.value);
    why += checkHouseNumber(theForm.rm_block.value);
    why += checkFloorNumber(theForm.rm_floor.value);
    why += checkUnitNumber(theForm.rm_unit.value);
    why += checkPostalCodeValid(theForm.rm_postalcode.value);


       if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkWholeFormJoin(theForm) {
    
    var why = "";
    why += checkFirstName(theForm.first_name.value);
    why += checkLastName(theForm.last_name.value);
    why += checkStreetName(theForm.street.value);
    why += checkHouseNumber(theForm.block.value);
    why += checkFloorNumber(theForm.floor.value);
    why += checkUnitNumber(theForm.unit.value);
    why += checkPostalCodeValid(theForm.postalcode.value);
    why += checkHandphone(theForm.handphone.value);
    why += checkEmail(theForm.email.value);
    why += checkReEnterRetrieveEmail(theForm);
    
    why += checkStreetName(theForm.rm_street.value);
    why += checkHouseNumber(theForm.rm_block.value);
    why += checkPostalCodeValid(theForm.rm_postalcode.value);


       if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkWholeFormSignUpHostel(theForm) {
    
    var why = "";
    why += checkFirstName(theForm.first_name.value);
    why += checkLastName(theForm.last_name.value);
    why += checkStreetName(theForm.street.value);
    why += checkHouseNumber(theForm.block.value);
    why += checkFloorNumber(theForm.floor.value);
    why += checkUnitNumber(theForm.unit.value);
    why += checkPostalCodeValid(theForm.postalcode.value);
    why += checkHandphone(theForm.handphone.value);
    why += checkEmail(theForm.email.value);
    why += checkReEnterRetrieveEmail(theForm);
    
    why += checkStreetName(theForm.rm_street.value);
    why += checkHouseNumber(theForm.rm_block.value);
    why += checkFloorNumber(theForm.rm_floor.value);
    why += checkUnitNumber(theForm.rm_unit.value);
    why += checkPostalCodeValid(theForm.rm_postalcode.value);
    why += CheckHostelName(theForm.building.value);


       if (why != "") {
       alert(why);
       return false;
    }
return true;
}


function checkWholeFormProceed(theForm) {
    
    var why = "";
  //  why += checkFromDate(theForm.from.value);
  //  why += checkToDate(theForm.to.value);
    
    why += checkDistrict(theForm.dist.selectedIndex);
    why += checkMRT(theForm.mrt.selectedIndex);
    why += checkDescription(theForm.description.value);
    why += checkDirections(theForm.directions.value);
    why += checkContact(theForm.contact.value);
    why += checkDeptDate(theForm.deptDate.value);
    why += checkRoomPrice(theForm);

       if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkWholeFormProceedHostel(theForm) {
    
    var why = "";
  //  why += checkFromDate(theForm.from.value);
  //  why += checkToDate(theForm.to.value);
    
    why += checkDistrict(theForm.dist.selectedIndex);
    why += checkMRT(theForm.mrt.selectedIndex);
    why += checkDescription(theForm.description.value);
    why += checkDirections(theForm.directions.value);
    why += checkContact(theForm.contact.value);
    why += checkDeptDate(theForm.deptDate.value);
    

       if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkWholeFormAssociates(theForm) {
    
    var why = "";
    
    why += checkAssociateMail(theForm);
    why += checkMailText(theForm.email_text.value);


       if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkWholeFormRooms(theForm) {
    
    var why = "";
    why += checkRoomPrice(theForm);
    

       if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkWholeFormReview(theForm) {
    
    var why = "";
    why += checkFromDate(theForm.from.value);
    why += checkToDate(theForm.to.value);
    why += checkDistrict(theForm.dist.selectedIndex);
    why += checkMRT(theForm.mrt.selectedIndex);
    why += checkDescription(theForm.description.value);
    why += checkDirections(theForm.directions.value);
    why += checkContact(theForm.contact.value);
    

       if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkWholeFormStart(theForm) {
    
    var why = "";
    why += checkArrivalDate(theForm.arriving.value);
   
    

       if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkWholeFormConfirm(theForm) {
    
    var why = "";
    why += checkFirstName(theForm.firstName.value);
    why += checkLastName(theForm.lastName.value);
    why += checkPhone(theForm.phone.value);
    why += checkEmail(theForm.email.value);
    why += checkReEnterRetrieveEmail(theForm);
    why += checkCVV(theForm.cvv2Number.value);
   
    

       if (why != "") {
       alert(why);
       return false;
    }
return true;
}
function checkRetrieveBK(theForm) {
    var why = "";
    why += checkReEnterRetrieveEmail(theForm);
    why += checkRetrieveEmpty(theForm.email.value);
    why += checkEmailReco(theForm.email.value);
    
   
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function expandCollapseNew() {
	for (var i=0; i<expandCollapseNew.arguments.length; i++) {
		var element = document.getElementById(expandCollapseNew.arguments[i]);
		element.style.display = (element.style.display == "none") ? "block" : "none";
	}
}

function checkWholeFormManage(theForm) {
    
    var why = "";
    
    why += checkDistrict(theForm.dist.selectedIndex);
    why += checkMRT(theForm.mrt.selectedIndex);
    why += checkDescription(theForm.description.value);
    why += checkDirections(theForm.directions.value);
    why += checkContact(theForm.contact.value);
    

       if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkWholeFormEditRoom(theForm) {
    
    var why = "";
    
    why += checkRoomPriceEdit(theForm.price.value);
    why += checkMaxGuests(theForm.guests.value);
    why += checkBedNumber(theForm.beds.value);
    

       if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function jsUpload(upload_field)
{
    // this is just an example of checking file extensions
    // if you do not need extension checking, remove 
    // everything down to line
    // upload_field.form.submit();

    var re_text = /\.jpg|\.gif|\.png/i;
    var filename = upload_field.value;

    /* Checking file type */
    if (filename.search(re_text) == -1)
    {
        alert("File does not have picture (jpg, gif, png) extension");
        upload_field.form.reset();
        return false;
    }

    return true;
}