function hasChar(str){
    for (var i=0;i<str.length;i++){
        if (!(str.charAt(i)>='0' && str.charAt(i)<='9')){
            if (i==0 && str.charAt(i)!='+')
               return false;
            else
               return false;
        }
    }
    return true;
}


function validateVehicleReserve(){

var form_el=document.form1;

if (form_el.car_group.value==''){
alert('No Car Group selected.');
return false;
}


var car_sel='';
if (form_el.car_selection.length){
for (var i=0; i < form_el.car_selection.length; i++){
   if (form_el.car_selection[i].checked){
      car_sel = form_el.car_selection[i].value;
   }
}

if (car_sel==''){
alert('No car has been selected');
return false;
}
}


this.document.getElementById('wait').innerHTML='<font size=3><b><i>Processing Request</i></b></font><BR><img src="img/photo_loading.gif" />';

return true;

}




function validateClientReserve(){

var form_el=document.form1;

if (form_el.name.value==''){
alert('Customer name is empty');
return false;
}
if (form_el.surname.value==''){
alert('Customer surname is empty');
return false;
}

if (form_el.passport.value==''){
alert('Passport is empty');
return false;
}
if (form_el.passport_country.value==''){
alert('Country of passport is empty');
return false;
}

if (form_el.phone.value=='' && form_el.mobile.value==''){
alert('Telephone or mobile number cannot be empty');
return false;
}
else {
    if (form_el.phone.value!=''){
        if (!hasChar(form_el.phone.value)){
            alert ('Invalid Telephone Number');
            return false;
        }
    }
    if (form_el.mobile.value!=''){
        if (!hasChar(form_el.mobile.value)){
            alert ('Invalid Mobile Number');
            return false;
        }
    }

}


if (form_el.address.value=='' || form_el.city.value=='' || form_el.areacode.value==''){
alert('Address is incomplete');
return false;
}
if (form_el.email.value==''){
alert('E-mail is empty');
return false;
}
else {
  var email_str=form_el.email.value;
  if (email_str.length<=4){
      alert('E-mail too short');
      return false;
  }
  else {
     var atFound=false;
     var dotFound=false;
     var counter=0;
     var midcounter=0;
     for (var i=0; i<email_str.length;i++){
        if (dotFound && atFound)
           counter++;
        if (email_str.charAt(i)=='@')
           atFound=true;
        else if (email_str.charAt(i)=='.' && atFound)
           dotFound=true;
        if (dotFound && !atFound){
           alert('Invalid E-mail (\'.\' before \'@\')');
           return false;
        }
        if (atFound && !dotFound)
           midcounter++;
           
     }
     if (!dotFound || !atFound || counter<2 || midcounter==0){
         alert('Invalid E-mail (Missing \'@\' or \'.\' or empty after \'.\' or empty between \'@\' and \'.\'');
         return false;
     }
      
   }
}

if (form_el.country.value==''){
alert('Country is empty');
return false;
}


this.document.getElementById('wait').innerHTML='<font size=3><b><i>Processing Request</i></b></font><BR><img src="img/photo_loading.gif" />';

return true;
}


function validateReserveDateLoc(){

var form_el=document.form1;

if (form_el.pick_city.value=='' || (form_el.pick_city.value=='Other' && form_el.alt_pick.value=='')){
alert('Pick up location is empty');
return false;
}
if (form_el.return_loc.value=='' || (form_el.return_loc.value=='Other' && form_el.alt_drop.value=='')){
alert('Drop off location is empty');
return false;
}
if (form_el.PickUpDate.value==''){
alert('Pick up date is empty');
return false;
}

if (form_el.ReturnDate.value==''){
alert('Drop off date is empty');
return false;
}

var today = new Date();

var pickDay = new Date();
var arr=form_el.PickUpDate.value.split("/");
pickDay.setFullYear(arr[2],arr[1]-1,arr[0]);

if (pickDay<today){
alert('Pick up date cannot be in the past');
return false;
}

var dropDay = new Date();
var arr=form_el.ReturnDate.value.split("/");
dropDay.setFullYear(arr[2],arr[1]-1,arr[0]);

if (dropDay<pickDay){
alert('Drop off date cannot be before pick up date');
return false;
}

var numOfDays=((dropDay-pickDay)/86400000);

var s=form_el.drop_hour.value*1-form_el.pick_hour.value*1+(form_el.drop_min.value-form_el.pick_min.value)/60;
if (s>=2)
	numOfDays++;

if (numOfDays<3){
alert('For reservations less than 3 days please contact 4U Rentals directly.');
return false;
}

this.document.getElementById('wait').innerHTML='<font size=3><b><i>Processing Request</i></b></font><BR><img src="img/photo_loading.gif" />';

return true;
}