
function  fulfil_fields(days, one,two,eight,fifteen,thirty,deposit){
if (days ==1){
document.calculator.calc_day.value = one;
document.calculator.calc_category.value = "1 day";
document.calculator.calc_deposit.value  = deposit;
document.calculator.calc_hire.value = days * document.calculator.calc_day.value ;
}else if ((days>1) && (days<8)){
document.calculator.calc_day.value = two;
document.calculator.calc_category.value = "2-7 days";
document.calculator.calc_deposit.value  = deposit;
document.calculator.calc_hire.value = days * document.calculator.calc_day.value ;
}else if ((days>=8) && (days<15)){
document.calculator.calc_day.value = eight;
document.calculator.calc_category.value = "8-14 days";
document.calculator.calc_deposit.value  = deposit;
document.calculator.calc_hire.value = days * document.calculator.calc_day.value ;
}else if ((days>=15) && (days<31)){
document.calculator.calc_day.value = fifteen;
document.calculator.calc_category.value = "15-30 days";
document.calculator.calc_deposit.value  = deposit;
document.calculator.calc_hire.value = days * document.calculator.calc_day.value ;
}else if (days>=31){
document.calculator.calc_day.value = thirty;
document.calculator.calc_category.value = "30+ days";
document.calculator.calc_deposit.value  = deposit;
document.calculator.calc_hire.value = days * document.calculator.calc_day.value ;
}	
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function calc(one,two,eight, fifteen, thirty, deposit)
{var days=0;		
		one_minute=60*1000;
		one_hour=one_minute*60;
		one_day=one_hour*24;
	var	start_date_object= new Date();
	var	end_date_object = new Date();

		
days = document.calculator.days.value;
if (!IsNumeric(days)) 
   { 
      alert('The entered statement is not a number! ') 
      
      return false; 
      } 

	start=document.calculator.start_date.value;
	end = document.calculator.end_date.value;
	
if (days ==0||(start !=""&&end !="")){

	document.calculator.days.value="0";
	if (start&&end){
	
 
		start_arr = start.split("-");
		start_year= start_arr[0];
		start_month=start_arr[1];
		start_day = start_arr[2];
		start_date_object.setDate(start_day);
		start_date_object.setMonth(start_month);
		start_date_object.setYear(start_year);
		
		end_arr = end.split("-");
		end_year= end_arr[0];
		end_month=end_arr[1];
		end_day = end_arr[2];		
		end_date_object.setDate(end_day);
		end_date_object.setMonth(end_month);
		end_date_object.setYear(end_year);		
		
		var diff = end_date_object.getTime() - start_date_object.getTime()
		diff = Math.floor(diff/one_day);		
		fulfil_fields(diff,one,two, eight,fifteen,thirty,deposit);
		document.calculator.days2.value = diff;
	}

} else if (days>0){
document.calculator.start_date.value="";
document.calculator.end_date.value="";
fulfil_fields(days,one,two, eight,fifteen,thirty,deposit);
} // if days>0
}// end of the function calc

function changehours()
{
document.form1.end_hour.value = document.form1.start_hour.value;
document.form1.end_min.value = document.form1.start_min.value;

}
function getFormData()
	{	
		alert(document.forms[0].innerHTML);
	}
function clear_fields()
{
document.calculator.start_date.value="";
document.calculator.end_date.value="";
document.calculator.calc_day.value = "";
document.calculator.days2.value="";
document.calculator.calc_category.value = "";
document.calculator.calc_deposit.value = "";
document.calculator.calc_hire.value = "";
}

function clear_days_field(){
document.calculator.days.value="0";
}

function IsEmpty(value) {
   if ((value.length==0) ||
   (value==null)) {
      return true;
   }
   else { return false; }
}	

function checkinput_cars(){
	var ok=true;	
		
	if (IsEmpty(document.form1.name.value))
	{
		ok=false; 
		alert('Enter your name!');
		document.form1.name.focus();		
		document.form1.name.select();
	} else
					if (IsEmpty(document.form1.phone.value)&&IsEmpty(document.form1.email.value))
					{ 
					ok=false;
					alert('Enter valid phone number or å-mail, please!');		
					document.form1.phone.focus();
					document.form1.phone.select();
					
					} else
								if (IsEmpty(document.form1.calendar1b.value)){
								ok=false;
								alert('Enter pick-up date, please!');
								document.form1.calendar1b.focus();
								} else
							if(IsEmpty(document.form1.calendar2b.value)){
											ok=false;
											alert('Enter return date, please!');
											document.form1.calendar2b.focus();
											} else
											  if(document.form1.radiobtn_group01_radio01[2].checked && IsEmpty(document.form1.start_dest_other.value)){
												ok=false;
												alert('Enter delivery place, please!');
												document.form1.start_dest_other.focus();
											}  else
											  if(document.form1.radiobtn_group02_radio01[2].checked && IsEmpty(document.form1.end_dest_other.value)){
												ok=false;
												alert('Enter return plase, please!');
												document.form1.end_dest_other.focus();
									}
											
				
	return ok;
}
	



function checkinput_transfer(){
	var ok=true;	
		
	if(IsEmpty(document.form1.name.value))
	{
		ok=false; 
		alert('Enter your name, please!');
		document.form1.name.focus();		
		document.form1.name.select();
	}else
					if (IsEmpty(document.form1.phone.value)&&IsEmpty(document.form1.email.value))
					{ 
					ok=false;
					alert('Enter a valid phone number or e-mail, please!');		
					document.form1.phone.focus();
					document.form1.phone.select();
					
					}else
						if(IsEmpty(document.form1.passangers.value)||(isNaN(document.form1.passangers.value))){
								ok=false;
								alert('Enter the number of the passangers, please!');
								document.form1.passangers.focus();
								document.form1.passangers.select();
								}else
								if (IsEmpty(document.form1.calendar1b.value)){
								ok=false;
								alert('Enter pick-up date, please!');
								document.form1.calendar1b.focus();
								}else
							if(IsEmpty(document.form1.start_destination.value)){
											ok=false;
											alert('Enter pick-up place, please!');
											document.form1.start_destination.focus();
											document.form1.start_destination.select();
											} 
											
				
	return ok;
}
var myWindow;

function openCenteredWindow(url) {
    var width = 530;
    var height = 480;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    window.open(url, "child", windowFeatures);
	
}
