﻿function GoToFirstDetailQty()
{
  CalculateLaborTotal();
  var o;
  o = document.getElementById("ctl00_cphMaster_grdDetail_ctl02_txtPartQuantity");
  try
  {
    o.focus();
  }
  catch(err)
  {}
}

function chkBadSerial_Click()
{
  aspnetForm.ctl00_cphMaster_txtSerialNumber.disabled = false;
  if(aspnetForm.ctl00_cphMaster_chkBadSerial.checked)
  {
    aspnetForm.ctl00_cphMaster_txtModelNumber.disabled = false;
    aspnetForm.ctl00_cphMaster_txtModelNumber.focus();
    if (aspnetForm.ctl00_cphMaster_txtModelNumber.value == "")
      alert("If There Is No Serial Number, Please Enter A Model Number");
      
    aspnetForm.ctl00_cphMaster_txtSerialNumber.value = "";
    aspnetForm.ctl00_cphMaster_txtSerialNumber.disabled = true;
  }
}

function ddlLaborApproval_SelectedIndexChanged()
{
  // the N is the value for reject
  if(aspnetForm.ctl00_cphMaster_ddlLaborApproval.value == 'N') 
  {
    aspnetForm.ctl00_cphMaster_ddlRejectCode.disabled = false;
  }
  else
  {
    aspnetForm.ctl00_cphMaster_ddlRejectCode.selectedIndex  = 0;
    aspnetForm.ctl00_cphMaster_ddlRejectCode.disabled = true;
  }
}


function CheckAuthCode()
{
  if(aspnetForm.ctl00_cphMaster_chkDealerStock.checked)
  {
    if(aspnetForm.ctl00_cphMaster_txtSpecialAuth.value == "")
    {
      alert("A Special Authorization Code Is Requird For Dealer Stock");
      aspnetForm.ctl00_cphMaster_chkDealerStock.checked = false;
    }
  }
}



function ConfirmLaborOnly()
{
  if (aspnetForm.ctl00_cphMaster_rbLaborOnly.checked)
  {
    if(confirm("All Parts Will Be Deleted, Are You Sure?"))
    {
      document.getElementById("ctl00_cphMaster_grdDetail").style.display = "none";
      
      aspnetForm.ctl00_cphMaster_txtMileageCost.disabled = false;
      aspnetForm.ctl00_cphMaster_txtLaborCharge.disabled = false;
      aspnetForm.ctl00_cphMaster_txtExtendedLabor.disabled = false;
      aspnetForm.ctl00_cphMaster_txtMilesOutsideRadius.disabled = false;
    }
    else
      aspnetForm.ctl00_cphMaster_rbBoth.checked = true;
  }
}

function ConfirmPartsOnly()
{
  if (aspnetForm.ctl00_cphMaster_rbPartsOnly.checked)
  {
    if(confirm("All Service Charges Will Be Set To 0, Are You Sure?"))
    {
      document.getElementById("ctl00_cphMaster_grdDetail").style.display = "block";

      aspnetForm.ctl00_cphMaster_txtMileageCost.value = "0.00";
      aspnetForm.ctl00_cphMaster_txtLaborCharge.value = "0.00";
      aspnetForm.ctl00_cphMaster_txtExtendedLabor.value = "0.00";
      aspnetForm.ctl00_cphMaster_txtMilesOutsideRadius.value = "0";
      aspnetForm.ctl00_cphMaster_txtTotalLabor.value = 0;

      aspnetForm.ctl00_cphMaster_txtMileageCost.disabled = true;
      aspnetForm.ctl00_cphMaster_txtLaborCharge.disabled = true;
      aspnetForm.ctl00_cphMaster_txtExtendedLabor.disabled = true;
      aspnetForm.ctl00_cphMaster_txtMilesOutsideRadius.disabled = true;
    }
    else
      aspnetForm.ctl00_cphMaster_rbBoth.checked = true;
  }
}

function SetupBoth()
{
  if (aspnetForm.ctl00_cphMaster_rbBoth.checked)
  {
    document.getElementById("ctl00_cphMaster_grdDetail").style.display = "block";
    aspnetForm.ctl00_cphMaster_txtMileageCost.disabled = false;
    aspnetForm.ctl00_cphMaster_txtLaborCharge.disabled = false;
    aspnetForm.ctl00_cphMaster_txtExtendedLabor.disabled = false;
    aspnetForm.ctl00_cphMaster_txtMilesOutsideRadius.disabled = false;
  }
}


function MileageWarning()
{
  if (aspnetForm.ctl00_cphMaster_txtMileageCost.value != "" && aspnetForm.ctl00_cphMaster_txtMileageCost.value != "0")
  {
    var msg;
    msg = "If Mileage Is In Excess Of Your Contracted Rate It Will Be Subject To Verification. \n";
    msg = msg + "Failure To Follow Thes Agreed-Upon Rates Will Result In Rejected Invoices. \n";
    msg = msg + "Please Contact Your Regional Technical Manager For Further Consideration.";
    alert(msg);
  }
  
}




function CalculateLaborTotal()
{
		var total;
		total = 0;
		if (aspnetForm.ctl00_cphMaster_txtMileageCost.value != '')
			total = total + parseFloat(aspnetForm.ctl00_cphMaster_txtMileageCost.value);
		
		if (aspnetForm.ctl00_cphMaster_txtLaborCharge.value != '')
			total = total + parseFloat(aspnetForm.ctl00_cphMaster_txtLaborCharge.value);
			
		if (aspnetForm.ctl00_cphMaster_txtExtendedLabor.value != '')
			total = total + parseFloat(aspnetForm.ctl00_cphMaster_txtExtendedLabor.value);
			
			

		aspnetForm.ctl00_cphMaster_txtTotalLabor.value = total.toFixed(2);
}

function TwoDigitToYear()
{
  var num;
	num = parseFloat(aspnetForm.ctl00_cphMaster_txtPurchasedYear.value);
	
  if(num > 80 && num < 100)
    aspnetForm.ctl00_cphMaster_txtPurchasedYear.value = "19" + aspnetForm.ctl00_cphMaster_txtPurchasedYear.value;
    
  if(num > -1 && num < 10)
    aspnetForm.ctl00_cphMaster_txtPurchasedYear.value = "200" + num.toFixed(0);
    
  if(num > 9 && num < 81)
    aspnetForm.ctl00_cphMaster_txtPurchasedYear.value = "20" + num.toFixed(0);
    
    
	num = parseFloat(aspnetForm.ctl00_cphMaster_txtReceivedYear.value);
	
  if(num > 80 && num < 100)
    aspnetForm.ctl00_cphMaster_txtReceivedYear.value = "19" + aspnetForm.ctl00_cphMaster_txtReceivedYear.value;
    
  if(num > -1 && num < 10)
    aspnetForm.ctl00_cphMaster_txtReceivedYear.value = "200" + num.toFixed(0);
    
  if(num > 9 && num < 81)
    aspnetForm.ctl00_cphMaster_txtReceivedYear.value = "20" + num.toFixed(0);
    
    
    
	num = parseFloat(aspnetForm.ctl00_cphMaster_txtRepairedYear.value);
	
  if(num > 80 && num < 100)
    aspnetForm.ctl00_cphMaster_txtRepairedYear.value = "19" + aspnetForm.ctl00_cphMaster_txtRepairedYear.value;
    
  if(num > -1 && num < 10)
    aspnetForm.ctl00_cphMaster_txtRepairedYear.value = "200" + num.toFixed(0);
    
  if(num > 9 && num < 81)
    aspnetForm.ctl00_cphMaster_txtRepairedYear.value = "20" + num.toFixed(0);
    
    
}
