// Tracking System JavaScript Document
function loadContent(id,page){
	$('#'+id).load(page);
}
/*gen funcs begin*/
function fnSetStep(tsid,setStep){
	
	$.get('./include/tracksys.func.php',{fn:'fnSetStep',trackid:tsid, stp: setStep});
	return false;
	
}

function fnCheckDates( thisId )
{	
	var multiVal = $('#'+thisId).val();
	if(multiVal == 'Any'){
		$('input[id^="dates"]').attr({"checked":true});
	}
	else {
		alert('If none of the dates listed are suitable, please call 01920 481 000 to arrange an alternative date.');
		$('input[id^="dates"]').attr({"checked":false});
	}
}

function OLDfnFrmSub(tsid){
	
	var vRoad = $('#road').attr("checked");
	var vHand = $('#hand').attr("checked");
	
	if(!vRoad){
		
		alert('If your road is not suitable for a 7,5 ton vehicle, please call 01920 481 000.');
		
	}
	else if(!vHand){
		
		alert('If there will be nobody available to help the delivery driver with larger items, please call 01920 481 000.');
		
	}
	else {
	/**/
	var chkConfirm = frmConfirm();
	
	if(chkConfirm){
		
		var getDates = $('#frmCustDet').serialize();
		var sendValues = 'fn=fnGetDtime&trackid='+tsid+'&'+getDates;
		//alert(sendValues);
		
			$.get('include/tracksys.func.php',sendValues, function(response){
																	 
																		$('#msg').html(response);
																		$('#msg').show();
																		window.location.href='thankyou.php';
																	 
																	 });
		
		
	}
	else {
		return false;
	}
	/**/
	}

}

function frmConfirm(){
	
	return confirm('If you\'ve made your selections please click OK otherwise click CANCEL to return.\nThank you!'); 
	
}

function fnShowLorry(){
	$('#trLorry').toggle();
}

function fnFrmSub(tsid){
	
	var vRoad = $('#road :selected').val();
	var vHand = $('#hand :selected').val();
	
	if(vRoad == 0){
		
		alert('Please indicate if your road is suitable for a 7,5 ton vehicle.\nClick the link on the right to see an image.');
		
	}
	else if(vRoad == 2){
		
		alert('If your road is not suitable for a 7,5 ton vehicle, please call 01920 481 000.');
		if(vHand == 0){
			alert('Please indicate if there will be somebody available to assist the driver with large items.');
		}
		else if(vHand == 2 || vHand == 1){
			fnDoSubmit(tsid);
		}
		else {
			alert('An error has occured, please call 01920 481 000 for further assistance.');
		}
	}
	else if(vRoad == 1){
		
		if(vHand == 0){
			alert('Please indicate if there will be somebody available to assist the driver with large items.');
		}
		else if(vHand == 2 || vHand == 1){
			fnDoSubmit(tsid);
		}
		else {
			alert('An error has occured, please call 01920 481 000 for further assistance.');
		}
		
	}
	else {
		alert('An error has occured, please call 01920 481 000 for further assistance.');
	}

}

function fnDoSubmit(tsid){
	
	var chkConfirm = frmConfirm();
	
	if(chkConfirm){
		
		var getDates = $('#frmCustDet').serialize();
		var sendValues = 'fn=fnGetDtime&trackid='+tsid+'&'+getDates;
		//alert(sendValues);
		$('#submit_container').html('Please wait ...<br /><img src="/images/ajax-loader.gif" style="border:none;" alt="loading..." />');		
			$.get('/process-tracking-request.php',sendValues, function(response){
				$('#msg').html(response);
				$('#msg').show();
				window.location.href='/index.php?header=thankyou';
			});
		
	}
	else {
		return false;
	}	
	
	
}