//validate quantity as int or change to 1
function validate_qty($qtyid) {
   $qty=document.getElementById($qtyid).value;
   if(!parseInt($qty)) {
      document.getElementById($qtyid).value=1;
	 }
}
function cancel_checkout(){
   window.location=ROOTURL+'basket.php';
}

var $cal_type='';
function trigger_calendar($type,$m,$y,$d){
   $cal_type=$type;
   if($d){
      $url=ROOTURL+'inc/ajax/trigger_calendar.php?type='+$type+'&m='+$m+'&y='+$y+'&d='+$d;
      ajax_do(ajax_init(),$url,update_calendar,'GET');
	 }else{
      $url=ROOTURL+'inc/ajax/update_calendar.php?type='+$type+'&m='+$m+'&y='+$y;
      ajax_do(ajax_init(),$url,refresh_calendar,'GET');
   }
}

function update_calendar($xh_obj){
   $response=$xh_obj.responseXML.documentElement;
   $date=$response.getElementsByTagName('date')[0].firstChild.data;
   $status=$response.getElementsByTagName('status')[0].firstChild.data;
	 document.getElementById('change_'+$cal_type+'_date').value=$date;
}

function refresh_calendar($xh_obj){
   $response=$xh_obj.responseText;
	 document.getElementById('calendar'+$cal_type).innerHTML=$response;
}

function show_calendar($type){
   if($type!='from' && $type!='to')return false;
	 $cal=document.getElementById('calendar'+$type);
   if($cal.style.display=='none' || !$cal.style.display){
	    $cal.style.display='block';
			document.getElementById('calendarlink'+$type).firstChild.nodeValue='close calendar';
	 }else{
	    $cal.style.display='none';
			document.getElementById('calendarlink'+$type).firstChild.nodeValue='open calendar';
	 }
}
