﻿/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: checkLicence                                                                                    ***/
/***                                                                                                        ***/
/// <summary>
/// Calls an AJAX function to check if the licence is valid.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function checkLicence(strSerial, strFacCode, strLic1, strLic2, strLic3, strLic4, strLic5)
{
    /**********************************************************************************************************/
    /***  Get the serial/licence details                                                                    ***/
    /**********************************************************************************************************/

    var txtSerial = document.getElementById(strSerial);
    var txtFacCode = document.getElementById(strFacCode);
    var txtLic1 = document.getElementById(strLic1);
    var txtLic2 = document.getElementById(strLic2);
    var txtLic3 = document.getElementById(strLic3);
    var txtLic4 = document.getElementById(strLic4);
    var txtLic5 = document.getElementById(strLic5);

    var strSerial = txtSerial.value;
    var strFacCode = txtFacCode.value;
    var strLic1 = txtLic1.value;
    var strLic2 = txtLic2.value;
    var strLic3 = txtLic3.value;
    var strLic4 = txtLic4.value;
    var strLic5 = txtLic5.value;

    /**********************************************************************************************************/
    /***  Check the licence code (AJAX)                                                                     ***/
    /**********************************************************************************************************/

    PageMethods.CheckLicenceCode(strSerial,
        strFacCode,
        strLic1,
        strLic2,
        strLic3,
        strLic4,
        strLic5,
        checkLicence_CallBack);
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: checkLicence_CallBack                                                                           ***/
/***                                                                                                        ***/
/// <summary>
/// Call back for the AJAX function for checking the licence code.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function checkLicence_CallBack(response)
{
    var strArray = response.split(":");
    
    /**********************************************************************************************************/
    /***  Get the controls                                                                                  ***/
    /**********************************************************************************************************/
    
    var lblMessage = document.getElementById("ctl00_ContentPlaceHolderMainPanel_lblMessage");
    var lblExpiryDate = document.getElementById("ctl00_ContentPlaceHolderMainPanel_lblExpiryDate");
    var lblDaysLeft = document.getElementById("ctl00_ContentPlaceHolderMainPanel_lblDaysLeft");
    var butUpdate = document.getElementById("ctl00_ContentPlaceHolderMainPanel_butUpdate");
    
    /**********************************************************************************************************/
    /***  Set the text                                                                                      ***/
    /**********************************************************************************************************/
    
    lblMessage.innerHTML = strArray[0];
    lblExpiryDate.innerHTML = strArray[1];
    lblDaysLeft.innerHTML = strArray[2];
    
    /**********************************************************************************************************/
    /***  Set the CSS                                                                                       ***/
    /**********************************************************************************************************/
    
    lblMessage.className = strArray[3];
    lblExpiryDate.className = strArray[4];
    lblDaysLeft.className = strArray[4];
    
    /**********************************************************************************************************/
    /***  Enable/disable the update button                                                                  ***/
    /**********************************************************************************************************/
    
    butUpdate.disabled = strArray[5];
}
