function ajaxHttpRequest(){
	if(navigator.appName == "Microsoft Internet Explorer") 
		http = new ActiveXObject("Microsoft.XMLHTTP");
	else 
		http = new XMLHttpRequest();
}

function saveService(){
	var origin='w';
	var invoiceNo='';
	var jobType='1';
	var location='';
	var contactName=document.getElementById('contactName').value;
	var phone=document.getElementById('phone').value;
	var dropDate=document.getElementById('dropDate').value;
	var pickUp='';
	var email=document.getElementById('email').value;
	var itemCode='';
	var serialNo='';
	var fault=document.getElementById('fault').value;
	ajaxHttpRequest();
	var params='customerService.php?action=save&origin='+origin+'&invoiceNo='+invoiceNo+'&jobType='+jobType+'&location='+location+'&contactName='+contactName+'&phone='+phone+'&dropDate='+dropDate+'&pickUp='+pickUp+'&email='+email+'&itemCode='+itemCode+'&serialNo='+serialNo+'&fault='+fault;;
	http.open("GET", params);
	http.onreadystatechange=function() {
		if(http.readyState == 4) {
			alert(http.responseText);
		}
	}
	http.send(null);
}

function timer(){
	ajaxHttpRequest();
	var params='index.php?action=1';
	http.open("GET", params);
	http.onreadystatechange=function() {
		if(http.readyState == 4) {
			var tempData=http.responseText;
			start(tempData);
		}
	}
	http.send(null);
}

function start(data){
	oldData=data.split(",");
	var newData = new Array();
	for(var i in oldData){
		if(i==0){
			var current=oldData[i];
		}else{
			var t=setTimeout("changeTime('"+oldData[i]+"', '"+current+"')",1000);
		}
		
	}
}

function changeTime(id, current){
	var oldData=id;
	newData=oldData.split(":");
	var timeLeft=newData[1]-current
	var hours=0
	var min=0
	var hours=parseInt(timeLeft/parseInt(3600));
	
	
	for(var i=timeLeft;i>3600;i-=3600){
		var min=parseInt(parseInt(i-3600)/parseInt(60));
	}
	if(min==60){
		min='0'
	}
	
	for(var i=timeLeft;i>60;i-=60){
		var sec=parseInt(i-60);
	}
	if(sec==60){
		sec='0';
	}
	
	//var t=document.getElementById('time'+newData[0]).innerHTML
	
	if(hours<10){
		document.getElementById('hours').innerHTML='0'+hours
	}else{
		document.getElementById('hours').innerHTML=hours
	}
	
	if(min<10){
		document.getElementById('min').innerHTML='0'+min
	}else{
		document.getElementById('min').innerHTML=min
	}
	
	if(sec<10){
		document.getElementById('sec').innerHTML='0'+sec
	}else{
		document.getElementById('sec').innerHTML=sec
	}
	//document.getElementById('time'+newData[0]).innerHTML='Hours:'+hours+' Min:'+min+' Sec:'+sec;
	var current = parseInt(current)+parseInt(1);
	var t=setTimeout("changeTime('"+id+"', '"+(current)+"')",1000);
}
