﻿/*
-- Hides the alert label
--
-- Called by: JobStatus.aspx
*/
function hideAlertLabel()
{
    var label = findSpanOrLabel('alertLabel');
    
    if (label != null)
    {
        label.style.visibility = 'hidden';
    }
}


/*
-- Enable or disable the search button based on whether a customer reference no. or ITS job no. has been provided.
--
-- Called by: JobStatus.aspx
*/
function enableSearchButton(textbox)
{
    if (trim(textbox.value).length > 0)
    {
        enableSubmitButton('searchButton', true);
        findSubmitButtonByID(0, 'searchButton').focus();
    }
    else
    {
        enableSubmitButton('searchButton', false);
    }
}

/*
-- If a customer reference no. is entered as search criteria, this function clears the ITS Job No. search
-- criteria and vice versa.
--
-- Called by: JobStatus.aspx
*/
function clearOtherCriteria(textboxName)
{
    if (textboxName.indexOf('jobNoTextBox') > -1)
    {
        findTextBox(0, 'referenceNoTextBox').value = '\0';
    }
    else
    {
        findTextBox(0, 'jobNoTextBox').value = '\0';
    }
    
    if (findTextBox(0, 'referenceNoTextBox').value.length == 0 && findTextBox(0, 'jobNoTextBox').value.length == 0)
    {
        enableSubmitButton('searchButton', false);
    }
    else
    {
        enableSubmitButton('searchButton', true);
    }
}

/*
-- Throw an alert to remind the user to make a note of the ITS Job No.
--
-- Called by: Assetconfirmation.aspx
*/
function confirmationAlert()
{
    var label = findSpanOrLabel('jobNumberLabel');
    var jobNo;
    var st = 0;
    var fnd = -1;

    if (label != null)
    {
        fnd = label.innerText.indexOf('Job Number ', st);       // "Job Number 999999 has been created
        st = fnd + 'Job Number '.length;                        // First space past 'Job Number '
        fnd = label.innerText.indexOf(' ', st);                 // First space past the actual job number.
        jobNo = label.innerText.substr(st, fnd - st);

        alert('Please make sure that you have made a note of job number ' + jobNo + ' before continuing.');
    }
}

/*
-- Check that all mandatory fields have been populated. Confirm with the user that 
-- they want to proceed.
--
-- Called by: Customer/AssetPage.aspx
*/
function submitCheck()
{
    var msg;
    var label;
    var contactTextbox;
    var phoneTextbox;
    var missing = false;
    var focusOn;

    if (!checkMandatoryFields('mandatoryLabel'))
    {
        return false;
    }
    
     // Clear mandatory label message
    label = findSpanOrLabel('mandatoryLabel');
    label.innerText = '';
    
    // If the contact name or phone number is blank, confirm this with the user
    msg = 'The following fields are blank\n\r';
    
    contactTextbox = findTextBox(0, 'siteContactTextBox');
    if (contactTextbox != null && trim(contactTextbox.value).length == 0)
    {
        msg += '\n\r\tContact';
        missing = true;
        focusOn = contactTextbox;
    }
    
    phoneTextbox = findTextBox(0, 'sitePhoneTextBox');
    if (phoneTextbox != null && trim(phoneTextbox.value).length == 0)
    {
        msg += '\n\r\tPhone';
        missing = true;
        if (focusOn == null)
        {
            focusOn = phoneTextbox;
        }
    }   
    
    if (missing)
    {
        msg += '\n\r\r\nDo you want to correct this before continuing ?';
    
        if (confirm(msg))
        {
            focusOn.focus();
            return false;
        }
    }

    // Confirm with the user that the invoice is to be created.
    msg = 'A job will now be created for this asset.';
    if (confirm(msg)) 
    {
        return true;
    }
    else 
    {
        return false;
    }
}

/*
-- Sets the style in the serial no. textbox to indicate if the field is mandatory
-- according to the asset type selected. 
--
-- Called by: Customer/AssetPage.aspx
*/
function serialNoMandatory(assetDropDownList, serialNoTextBoxID)
{
    var idx = assetDropDownList.selectedIndex;
    var textbox;
    var label;

    textbox = findTextBox(0, serialNoTextBoxID);

    // A serial no. is required for this asset type
    if (assetDropDownList.options[idx].value == 'True')
    {
        textbox.className = 'TextBoxEditMand';
        textbox.disabled = false;
    }
    else
    {
        // A serial no. is not required for this asset type - disable the control
        textbox.className = 'TextBoxDisabled';
        textbox.disabled = true;

        // Remove the star from the mandatory label for the serial no.
        label = findLabelById('serialNoMandatoryLabel');
        label.innerText = '';
    }
}

function validate(f) 
{   
	if (f.txt_jobnumber != null)
	{	
		if (f.txt_jobnumber.value == "")
		{
			alert("Please Enter your Reference Number First!");
			f.txt_jobnumber.focus();
			f.txt_jobnumber.select();
			return;
		}
		f.dologon.value = 1;
		f.submit();
	}
}

function setfocus(f) 
{
	if (f.txt_jobnumber != null)
	{
		f.txt_jobnumber.focus();
		f.txt_jobnumber.select();
	}
}

function intOnly(e)
{
	//     <backspace>				0 - 9
	if (e.keyCode != 8 & (e.keyCode < 48 | e.keyCode > 57))
	{
		e.keyCode = '\0';
	}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/*
-- Alert user if no search criteria selected or both search criteria entered 
-- when searchButton pressed
--
-- Called by: JobStatus.aspx
*/
function checkForSearchCriteria()
{
    if (findTextBox(0, 'referenceNoTextBox').value.length == 0 && findTextBox(0, 'jobNoTextBox').value.length == 0)
    {
        alert("Please enter either a Customer Reference or ITS Job number.");
    }
    else if (findTextBox(0, 'referenceNoTextBox').value.length != 0 && findTextBox(0, 'jobNoTextBox').value.length != 0)
    {
        alert("Please search via either Customer Reference Number OR ITS Job number.");
    }
}

/*
-- Alert user if no search criteria selected (jobNoTextbox) when searchButton pressed
--
-- Called by: OpenJobStatus.aspx
*/
function checkForJobNo()
{
    if (findTextBox(0, 'jobNoTextBox').value.length == 0)
    {
        alert("Please enter an ITS Job number.");
    }
}

