var xmlhttp;

function checkLogin(user, pass)
{
//alert(user+ " " + pass);
if (user.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'>ENTER USER NAME</font></strong>";
	return;
	}
	
if (pass.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'>ENTER PASSWORD</font></strong>";
	return;
	}

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="http://www.paritek.com/ServiceTicket/checklogin.php";
url=url+"?user="+user;
url=url+"&pass="+pass;
url=url+"&sid="+Math.random();
//alert(url);
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}


function stateChanged()
{
	if (xmlhttp.readyState==4)
		{
			var response=xmlhttp.responseText;
			if (response!="good")
				{
					document.getElementById("txtMessage").innerHTML=response;
				}
			else {
					//document.getElementById("body").innerHTML=response;
					//window.location = "http://www.paritek.com/New/index.php"
					location.reload(true);
				}

		}
}


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function submitServiceTicket(employee, customer, datePerformed, startingTime, endingTime, mileage, typeOfWork, workPerformed, itemNumber1, itemDescription1, qty1, price1, itemNumber2, itemDescription2, qty2, price2, itemNumber3, itemDescription3, qty3, price3, itemNumber4, itemDescription4, qty4, price4, itemNumber5, itemDescription5, qty5, price5, itemNumber6, itemDescription6, qty6, price6, dateReturned1, timeStarted1, timeCompleted1, type1, dateReturned2, timeStarted2, timeCompleted2, type2, dateReturned3, timeStarted3, timeCompleted3, type3, dateReturned4, timeStarted4, timeCompleted4, type4, dateReturned5, timeStarted5, timeCompleted5, type5)
{

if (employee.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'><ul><li>ENTER EMPLOYEE NAME</li></ul></font></strong>";
	alert("You must enter an employee to continue.");
	return;
	}
	
if (customer.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'><ul><li>ENTER CUSTOMER NAME</li></ul></font></strong>";
	alert("You must enter a customer to continue.");
	return;
	}
	
if (datePerformed.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'><ul><li>ENTER DATE PERFORMED</li></ul></font></strong>";
	alert("You must enter a date that the work was performed to continue.");
	return;
	}
	
if (startingTime.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'><ul><li>ENTER STARTING TIME</li></ul></font></strong>";
	alert("You must enter a starting time to continue.");
	return;
	}
	
if (endingTime.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'><ul><li>ENTER ENDING TIME</li></ul></font></strong>";
	alert("You must enter an ending time to continue.");
	return;
	}
	
if (mileage.length==0)
	{
	mileage=0;
	}

if (isNumeric(mileage)==false)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'><ul><li>ENTER A NUMERIC MILEAGE</li></ul></font></strong>";
	alert("You must enter a numeric mileage to continue.");
	return;
	}
	
var index = document.serviceTicket.typeOfWork.selectedIndex
typeOfWork = document.serviceTicket.typeOfWork.options[index].value
	
if (typeOfWork.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'><ul><li>ENTER TYPE OF WORK PERFORMED</li></ul></font></strong>";
	alert("You must enter the type of work performed to continue.");
	return;
	}
	
if (workPerformed.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'><ul><li>ENTER WORK PERFORMED</li></ul></font></strong>";
	alert("You must enter the work performed details to continue.");
	return;
	}

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="http://www.paritek.com/ServiceTicket/insertServiceTicket.php";
url=url+"?employeeName="+employee;
url=url+"&customer="+customer;
url=url+"&datePerformed="+datePerformed;
url=url+"&startingTime="+startingTime;
url=url+"&endingTime="+endingTime;
url=url+"&mileage="+mileage;
url=url+"&typeOfWork="+typeOfWork;
url=url+"&workPerformed="+workPerformed;
url=url+"&itemNumber1="+itemNumber1;
url=url+"&itemDescription1="+itemDescription1;
url=url+"&qty1="+qty1;
url=url+"&price1="+price1;
url=url+"&itemNumber2="+itemNumber2;
url=url+"&itemDescription2="+itemDescription2;
url=url+"&qty2="+qty2;
url=url+"&price2="+price2;
url=url+"&itemNumber3="+itemNumber3;
url=url+"&itemDescription3="+itemDescription3;
url=url+"&qty3="+qty3;
url=url+"&price3="+price3;
url=url+"&itemNumber4="+itemNumber4;
url=url+"&itemDescription4="+itemDescription4;
url=url+"&qty4="+qty4;
url=url+"&price4="+price4;
url=url+"&itemNumber5="+itemNumber5;
url=url+"&itemDescription5="+itemDescription5;
url=url+"&qty5="+qty5;
url=url+"&price5="+price5;
url=url+"&itemNumber6="+itemNumber6;
url=url+"&itemDescription6="+itemDescription6;
url=url+"&qty6="+qty6;
url=url+"&dateReturned1="+dateReturned1;
url=url+"&timeStarted1="+timeStarted1;
url=url+"&timeCompleted1="+timeCompleted1;
url=url+"&type1="+type1;
url=url+"&dateReturned2="+dateReturned2;
url=url+"&timeStarted2="+timeStarted2;
url=url+"&timeCompleted2="+timeCompleted2;
url=url+"&type2="+type2;
url=url+"&dateReturned3="+dateReturned3;
url=url+"&timeStarted3="+timeStarted3;
url=url+"&timeCompleted3="+timeCompleted3;
url=url+"&type3="+type3;
url=url+"&dateReturned4="+dateReturned4;
url=url+"&timeStarted4="+timeStarted4;
url=url+"&timeCompleted4="+timeCompleted4;
url=url+"&type4="+type4;
url=url+"&dateReturned5="+dateReturned5;
url=url+"&timeStarted5="+timeStarted5;
url=url+"&timeCompleted5="+timeCompleted5;
url=url+"&type5="+type5;
url=url+"&sid="+Math.random();
//alert(url);
xmlhttp.onreadystatechange=insertServiceTicketStateChanged;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}

function insertServiceTicketStateChanged()
{
	if (xmlhttp.readyState==4)
		{
			var response=xmlhttp.responseText;
			if (response!="good")
				{
					document.getElementById("txtMessage").innerHTML=response;
					window.location = "#";
				}
			else {
					//document.getElementById("body").innerHTML=response;
					//window.location = "http://www.paritek.com/New/index.php"
					alert("Your service ticket was successful.");
					location.reload(true);
				}

		}
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function updatePassword(currentPass, newPass, confirm)
{
//alert("worked");
if (currentPass.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'>ENTER YOUR PASSWORD</font></strong>";
	alert("You must enter your password to continue.");
	return;
	}
	
if (newPass.length==0)
	{
	alert("You must enter a new password to continue.");
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'>ENTER NEW PASSWORD</font></strong>";
	return;
	}
	
if (confirm.length==0)
	{
	alert("You must confirm your new password to continue.");
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'>CONFIRM NEW PASSWORD</font></strong>";
	return;
	}	

if (newPass != confirm)
	{
	alert("Your new passwords do not match. Please try again.");
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'>PASSWORDS DON'T MATCH</font></strong>";
	return;
	}	

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="http://www.paritek.com/ServiceTicket/updatePassword.php";
url=url+"?currentPass="+currentPass;
url=url+"&newPass="+newPass;
url=url+"&sid="+Math.random();
//alert(url);
xmlhttp.onreadystatechange=updatePasswordStateChanged;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}

function updatePasswordStateChanged()
{
	if (xmlhttp.readyState==4)
		{
			var response=xmlhttp.responseText;
			if (response!="good")
				{
					if (response=="currentIncorrect")
					{
						alert("Your current password is incorrect. Please try again.");
						document.getElementById("txtMessage").innerHTML="<strong><font color='red'>CURRENT PASSWORD INCORRECT</font></strong>";
						return;
						
					} else {
						document.getElementById("txtMessage").innerHTML="<strong><font color='red'>"+response+"</font></strong>";
					
					}
				}
			else {
					alert("Your password was changed successfully.");
					window.location = "http://www.paritek.com/ServiceTicket/index.php";
				}

		}
}

function updateTasks(user)
{
//alert(user+ " " + pass);
if (user.length==0)
	{
	document.getElementById("txtMessage").innerHTML="<strong><font color='red'>ENTER USER NAME</font></strong>";
	return;
	}

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="http://www.paritek.com/ServiceTicket/updateTasks.php";
url=url+"?user="+user;
url=url+"&sid="+Math.random();
//alert(url);
xmlhttp.onreadystatechange=updateTasksStateChanged;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}


function updateTasksStateChanged()
{
	if (xmlhttp.readyState==4)
		{
			var response=xmlhttp.responseText;
			if (response!="good")
				{
					document.getElementById("tasksToComplete").innerHTML=response;
				}
			else {
					//document.getElementById("body").innerHTML=response;
					//window.location = "http://www.paritek.com/New/index.php"
					location.reload(true);
				}

		}
}
