﻿
///reference for NewsLetterEditor.js///

document.write('<script type="text/javascript" language="javascript" src="Library/Javascript/NewsLetterEditor.js"></script>');

///reference for Email Marketing.js///

document.write('<script type="text/javascript" language="javascript" src="Library/Javascript/EmailMarketing.js"></script>');



function GetParentByTagName(parentTagName, childElementObj) {
    var parent = childElementObj.parentNode;
    while (parent.tagName.toLowerCase() != parentTagName.toLowerCase()) {
        parent = parent.parentNode;
    }
    return parent;
}


/*-------------------Site ROle JS -----------------------------*/

function OnCheckBoxCheckChanged(evt) {

    var src = window.event != window.undefined ? window.event.srcElement : evt.target;

    var nodeClick = src.tagName.toLowerCase() == "a";
    var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "checkbox");
    if (isChkBoxClick) {
        var parentTable = GetParentByTagName("table", src);
        var nxtSibling = parentTable.nextSibling;
        if (nxtSibling && nxtSibling.nodeType == 1)//check if nxt sibling is not null & is an element node 
        {
            if (nxtSibling.tagName.toLowerCase() == "div") //if node has children 
            {
                //check or uncheck children at all levels 
                CheckUncheckChildren(parentTable.nextSibling, src.checked);
            }
        }
        //check or uncheck parents at all levels 
        CheckUncheckParents(src, src.checked);
    }
}
function CheckUncheckChildren(childContainer, check) {

    var childChkBoxes = childContainer.getElementsByTagName("input");
    var childChkBoxCount = childChkBoxes.length;

    for (var i = 0; i < childChkBoxCount; i++) {
        childChkBoxes[i].checked = check;
    }
}
function CheckUncheckParents(srcChild, check) {

    var parentDiv = GetParentByTagName("div", srcChild);
    var parentNodeTable = parentDiv.previousSibling;

    if (parentNodeTable) {
        var checkUncheckSwitch;

        if (check) //checkbox checked 
        {
            checkUncheckSwitch = true;

        }
        else if (IsAnySiblingsChecked(srcChild)) {
            checkUncheckSwitch = true;


        }
        else {
            checkUncheckSwitch = false;


        }

        var inpElemsInParentTable = parentNodeTable.getElementsByTagName("input");
        if (inpElemsInParentTable.length > 0) {
            var parentNodeChkBox = inpElemsInParentTable[0];
            parentNodeChkBox.checked = checkUncheckSwitch;
            //do the same recursively 
            CheckUncheckParents(parentNodeChkBox, checkUncheckSwitch);
        }
    }
}
function AreAllSiblingsChecked(chkBox) {
    var parentDiv = GetParentByTagName("div", chkBox);
    var childCount = parentDiv.childNodes.length;
    for (var i = 0; i < childCount; i++) {
        if (parentDiv.childNodes[i].nodeType == 1) //check if the child node is an element node 
        {
            if (parentDiv.childNodes[i].tagName.toLowerCase() == "table") {
                var prevChkBox = parentDiv.childNodes[i].getElementsByTagName("input")[0];
                //if any of sibling nodes are not checked, return false 
                if (!prevChkBox.checked) {
                    return false;
                }
            }
        }
    }
    return true;
}

function IsAnySiblingsChecked(chkBox) {
    var IsAnySiblingChecked = false;
    var parentDiv = GetParentByTagName("div", chkBox);
    var childCount = parentDiv.childNodes.length;
    for (var i = 0; i < childCount; i++) {
        if (parentDiv.childNodes[i].nodeType == 1) //check if the child node is an element node 
        {
            if (parentDiv.childNodes[i].tagName.toLowerCase() == "table") {
                var prevChkBox = parentDiv.childNodes[i].getElementsByTagName("input")[0];
                //if any of sibling nodes are not checked, return false
                if (prevChkBox.checked) {
                    IsAnySiblingChecked = true;
                }
            }
        }
    }
    return IsAnySiblingChecked;
}

// function to open dialog box
function OpenDialog(p_strUrl) {
    var WinSettings = "center:yes;resizable:no;dialogHeight:400px;dialogWidth:700px;";
    window.showModalDialog(p_strUrl, null, WinSettings);
}

// function to open dialog box
function OpenWindow(p_strUrl, p_strCaption, p_strWidth, p_strHeight) {
    var WinSettings = "menubar=0,resizable=0,width=" + p_strWidth + ",height=" + p_strHeight;
    window.open(p_strUrl, p_strCaption, WinSettings);
    return false;
}


// Function to disable backbutton
function disableBackButton() {
    window.history.forward();
}

/* ChangeHeight method has been replaced with the new one, made by Hifsa */

function changeHeight() {
    //debugger;
    var l_intheight;
    var l_intwidth;
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    if (typeof window.innerWidth != 'undefined') {
        l_intheight = window.innerHeight
        l_intwidth = window.innerWidth
    }
    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0) {
        l_intheight = document.documentElement.clientHeight
        l_intwidth = document.documentElement.clientWidth
    }
    // older versions of IE
    else {
        l_intheight = document.getElementsByTagName('body')[0].clientHeight
        l_intwidth = document.getElementsByTagName('body')[0].clientWidth
    }

    var l_intscreenHeight = screen.height;
    var l_intscreenWidth = screen.width;

    var l_intcontainerheight = l_intheight - 20 - 80 - 55;
    var l_intinnerscreen = l_intcontainerheight - 10;

    var l_intcontainerwidth = l_intwidth - 219 - 21;
    var l_intinnerscreenwidth = l_intcontainerwidth - 29;
    //Left Menu Height var
    var l_intLeftMenucontainerheight = l_intcontainerheight + 1;
    l_intLeftMenucontainerheight += "px";

    l_intcontainerheight += "px";
    l_intinnerscreen += "px";

    l_intcontainerwidth += "px";
    l_intinnerscreenwidth += "px";

    var control = document.getElementById("divcontainer");
    control.style.height = l_intcontainerheight;
    control.style.width = l_intcontainerwidth;

    var control2 = document.getElementById("divInnercontainer");
    control2.style.height = l_intinnerscreen;
    control2.style.width = l_intinnerscreenwidth;

    //this is for Left Menu Height
    var control3 = document.getElementById("divleftMenu");
    control3.style.height = l_intLeftMenucontainerheight;

    //topTabs
    var control4 = document.getElementById("topTabs");
    control4.style.width = l_intcontainerwidth;

    //divCmsFooterRight
    var control5 = document.getElementById("divCmsFooterRight");
    control5.style.width = l_intcontainerwidth;


}

function NumericOnly(e, validchars, txt) { // v3.0

    // This is how this controls should be used, 2nd param are the allowable characters.
    // TextBox1.Attributes.Add("onKeyPress", "return NumericOnly(event,'1234567890','" + TextBox1.ClientID + "')")
    var ie = (navigator.appName == 'Microsoft Internet Explorer');

    var key = '', keychar = '';
    //key = getKeyCode(e);
    if (ie)
        key = e.keyCode;
    else
        key = e.charCode;

    if ((document.getElementById(txt).value.indexOf('.') != -1) && (key == 46))
        return false;
    if (key == null)
        return true;
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    validchars = validchars.toLowerCase();

    if (validchars.indexOf(keychar) != -1)
        return true;
    if (key == null || key == 0 || key == 8 || key == 9 || key == 13 || key == 27)
        return true;
    return false;
}


var m_strhdnFilterControlNameID = "";
var m_strbtnAutoPostBackID = "";

function confirmDelete() {

    if (confirm('Are you sure you want to delete this record?')) {
        return true;
    }
    else { return false; }
}

function confirmClose() {
    
    if (confirm('Save Change (ok/cancel) ?')) {

         return true;
     }
     else {
         var modalPopupBehavior = $find('ModalPopupBehavior'); // check the behavior you defined
         modalPopupBehavior.hide();
         return false;
     }
}

function confirmDeleteControls(deleteMessage) {
    if (confirm(deleteMessage)) {
        return true;
    }
    else { return false; }
}

function confirmDeletePage(isChildExsist) {

    if (isChildExsist == 0) {

        if (confirm('Are you sure you want to delete this record?')) {
            return true;
        }
        else { return false; }
    }
    else {

        alert('Cannot Delete this page b/c this page associated with other pages');
        return false;
    }
    return false;

}

function confirmDeleteFolder() {
    if (confirm('Are you sure you want to delete this record? Deleting this record may cause some inconsistency in application as all of the subfolders and pages will be deleted with their database entries.')) {
        return true;
    }
    else { return false; }
}

function confirmModifyFolder() {
    if (confirm('Are you sure you want to modify this record? Modifying this record may cause some inconsistency in application as all of the subfolders and pages will be modified with their database entries.')) {
        return true;
    }
    else { return false; }
}

function confirmAssignProduct(ProductCost) {

    if (confirm('The cost for this product is £' + ProductCost + '. Are you sure you want to add this product?')) {
        return true;
    }
    else { return false; }
}


function PageCall(ControlName) {

    // It will check whether the page is modified or not. If it is modified, it will prompt user to stay on the page or move from it.
    // Currently it is only for four screens of staff module
    var l_oPTCControl = document.getElementById(hdnControlNameID);
    if (l_oPTCControl.value == 'PTCMailingListSourceControl' || l_oPTCControl.value == 'PTCMailingList' || l_oPTCControl.value == 'PTCMailingGroupUsers' || l_oPTCControl == 'PTCViewAllNewsFeedControl' || l_oPTCControl.value == 'PTCSurveyBuilder') {

        if (!UnloadingForm()) {
            return;
        }

    }


    var Id = hdnTopMenuClickID;
    l_oControl = document.getElementById(Id);
    l_oControl.value = "False";

    var Id = hdnControlNameID;
    l_oControl = document.getElementById(Id);
    l_oControl.value = ControlName;

    var Id = hdnIsPostBackID;
    l_oControl = document.getElementById(Id);
    l_oControl.value = "false";

    $("#divInnercontainer").scrollTop(0);

    __doPostBack('ctl00$btnPostBack', '');

}

function ControlCommunicate(ControlName, IsPostBack, QueryString, ActiveRightControlName) {


    var Id = hdnControlCommunicationStringID;
    l_oControl = document.getElementById(Id);
    l_oControl.value = QueryString;


    var Id = hdnSelectedRightControlID;
    l_ohdnRightControl = document.getElementById(Id);

    if (ActiveRightControlName != '')
        l_ohdnRightControl.value = ActiveRightControlName;


    if (IsPostBack != true) {
        PageCall(ControlName)
    }
    else {
        __doPostBack('ctl00$btnPostBack', '');
    }
}


// This function will call when the Top menu clicks to load new module
function MainMenuPageCall(ControlName) {

    // It will check whether the page is modified or not. If it is modified, it will prompt user to stay on the page or move from it.
    // Currently it is only for four screens of staff module
    var l_oPTCControl = document.getElementById(hdnControlNameID);
    if (l_oPTCControl.value == 'PTCTempStaffForm' || l_oPTCControl.value == 'PTCCandidateForm' || l_oPTCControl.value == 'PTCRegistrationDetailsControl' || l_oPTCControl == 'PTCRefereesControl' || l_oPTCControl == 'PTCMailingListSourceFilterControl') {

        if (!UnloadingForm()) {
            return;
        }

    }

    var Id = hdnTopMenuClickID;
    l_oControl = document.getElementById(Id);
    l_oControl.value = "True";

    var Id = hdnControlNameID;
    l_oControl = document.getElementById(Id);
    l_oControl.value = ControlName;

    var Id = hdnIsPostBackID;
    l_oControl = document.getElementById(Id);
    l_oControl.value = "false";

    __doPostBack('ctl00$btnPostBack', '');
}


function onUserChange() {

    var Id = hdnControlNameID;
    l_oControl = document.getElementById(Id);
    var l_oControlName = l_oControl.value;

    PageCall(l_oControlName);
}


function init(index) {

    $('.accordion').accordion({
        active: index, change: RightAccordionChange
    });

}

function RightAccordionChange(event, ui) {

    var Id = hdnSelectedRightControlID;
    l_ohdnRightControl = document.getElementById(Id);
    l_ohdnRightControl.value = ui.newHeader.context.innerText;


}

function AutoCompletePostBack(control) {

    var Id = m_strhdnFilterControlNameID;
    l_oControl = document.getElementById(Id);

    if (l_oControl.value != control.id) {
        l_oControl.value = control.id;

        var Id = m_strbtnAutoPostBackID;
        __doPostBack(Id, '');
    }

}

function PTCPageinit() {
    $(".PageAccordion").accordion({
        active: 0, collapsible: true
    });
}

function PTCPageDynamicinit(AccordionDivIndex) {
    $(".PageAccordion").accordion({
        active: AccordionDivIndex, collapsible: true, autoHeight: false
    });
}

function doClick(buttonName, e) {
    //the purpose of this function is to allow the enter key to
    //point to the correct button to click.
    var key;

    if (window.event)
        key = window.event.keyCode;  //IE
    else
        key = e.which;  //firefox

    if (key == 13) {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null) { //If we find the button click it
            btn.click();
            event.keyCode = 0
        }
    }
}


/* -- Currently for insurance claim management grid for implementing check all system but later it can use with other grids */

function CheckAll(checkAllBox) {

    var frm = document.forms[0];
    var hdnCheckID = m_strhdnCheckClientID;
    var hdnCheck = document.getElementById(hdnCheckID);
    var hdnCheckAll

    var hdnCheckAllId = m_strhdnCheckAllClientID;

    if (hdnCheckAllId != null && hdnCheckAllId != '') {
        hdnCheckAll = document.getElementById(hdnCheckAllId);
    }

    if (checkAllBox.checked) {
        hdnCheck.value = 1
        hdnCheckAll.value = 1
    }
    else {
        hdnCheck.value = 0
        hdnCheckAll.value = 0
    }

    var actVar = checkAllBox.checked;
    for (i = 0; i < frm.elements.length; i++) {
        e = frm.elements[i];

        if (e.type == 'checkbox' && e.id.indexOf('chkApprove') > 0)
            e.checked = actVar;

    }
}

function ChangeCheckAllStatus(chkBox) {
    var CheckAllId = _mstrCheckAllID

    if (CheckAllId != null && CheckAllId != '') {
        var CheckAll = document.getElementById(CheckAllId)
        if (CheckAll != null) {
            if (chkBox.checked == false) {
                CheckAll.checked = false;
                var hdnCheckAllId = m_strhdnCheckAllClientID;

                if (hdnCheckAllId != null && hdnCheckAllId != '') {
                    hdnCheckAll = document.getElementById(hdnCheckAllId);
                    hdnCheckAll.value = 0;
                }



            }
        }

    }

}

/* -- End Currently for insurance claim management grid for implementing check all system but later it can use with other grids */

// JQuery Calendar calling in user personal control
function CalendarInit() {

    $("#divCalendar").datepicker({
        onSelect: function(dateText, inst) { ControlCommunicate('PTCDayCalendar', false, 'Scheduler_SelectedDate=' + dateText, ''); }
    });
}


//JQuery for Color Picker
function ColorPickerInit(inputBoxID) {
    $(inputBoxID).ColorPicker({
        onSubmit: function(hsb, hex, rgb, el) {
            $(el).val(hex);
            $(el).ColorPickerHide();
        },
        onBeforeShow: function() {
            $(this).ColorPickerSetColor(this.value);
        }
    })
        .bind('keyup', function() {
            $(this).ColorPickerSetColor(this.value);
        });
}

/*--------- New JS For Ajax File Uploader ---------------------*/


function FileUploadInitDefault(p_divUploadTree, p_UploadControlID, p_uploadHandler, p_isMultipleFile, p_strFolderPath, p_uploaderFileDescription, p_uploaderFileExtensions, p_uploaderMaxFileSize, p_hdnUploadedFilesID, p_lblUploadedFilesID) {


    var l_divUpload = document.getElementById(p_divUploadTree);
    if (l_divUpload != null && typeof (l_divUpload) != 'undefined') {
        l_divUpload.style.display = "block";
        $(p_UploadControlID).uploadify({
            'uploader': 'Library/Images/FileUpload/uploadify.swf',
            'script': p_uploadHandler,
            'scriptData': { 'folderPath': p_strFolderPath },
            'cancelImg': 'Library/Images/FileUpload/cancel.png',
            'auto': true,
            'multi': p_isMultipleFile,
            'fileDesc': p_uploaderFileDescription,
            'fileExt': p_uploaderFileExtensions,
            'queueSizeLimit': 90,
            'sizeLimit': p_uploaderMaxFileSize,
            'buttonText': 'Upload File',
            'onComplete': function(event, queueID, fileObj, response, data) {
                var l_strUploadedFiles = document.getElementById(p_hdnUploadedFilesID);
                l_strUploadedFiles.value = l_strUploadedFiles.value + response + fileObj.name + ",";
                var l_lblUploadedFiles = document.getElementById(p_lblUploadedFilesID);
                l_lblUploadedFiles.innerHTML = "<b>Uploaded Files</b>: <br/>" + l_strUploadedFiles.value.replace(/,/g, '<br/>');
            },
            'onAllComplete': function(event, queueID, fileObj, response, data) {
            },
            'onError': function() {
                alert("File uploading failed");
            }
        });
    }
}

function FileUploadInit(p_divUploadTree, p_UploadControlID, p_uploadHandler, p_isMultipleFile, p_strFolderPath, p_uploaderFileDescription, p_uploaderFileExtensions, p_uploaderMaxFileSize, p_hdnUploadedFilesID, p_lblUploadedFilesID, p_btnOKID) {


    var l_divUpload = document.getElementById(p_divUploadTree);
    if (l_divUpload != null && typeof (l_divUpload) != 'undefined') {
        l_divUpload.style.display = "block";

        var a = p_UploadControlID.replace('#', '');
        //    document.getElementById(a).style;


        $(p_UploadControlID).uploadify({
            'uploader': 'Library/Images/FileUpload/uploadify.swf',
            //'buttonImg': 'Library/images/Backgrounds/button2.png',
            //'width': ,
            'script': p_uploadHandler,
            'scriptData': { 'folderPath': p_strFolderPath },
            'cancelImg': 'Library/Images/FileUpload/cancel.png',
            'auto': true,
            'multi': p_isMultipleFile,
            'fileDesc': p_uploaderFileDescription,
            'fileExt': p_uploaderFileExtensions,
            'queueSizeLimit': 90,
            'sizeLimit': p_uploaderMaxFileSize,
            'buttonText': 'Upload File',
            'onComplete': function(event, queueID, fileObj, response, data) {
                var l_strUploadedFiles = document.getElementById(p_hdnUploadedFilesID);
                l_strUploadedFiles.value = l_strUploadedFiles.value + response + fileObj.name + ",";
                var l_lblUploadedFiles = document.getElementById(p_lblUploadedFilesID);
                l_lblUploadedFiles.innerHTML = "<b>Uploaded Files</b>: <br/>" + l_strUploadedFiles.value.replace(/,/g, '<br/>');
            },
            'onAllComplete': function(event, queueID, fileObj, response, data) {
                document.getElementById(p_btnOKID).click();
            },
            'onError': function() {
                alert("File uploading failed");
            }
        });
    }
}
function FileSelectInit(p_selectControlID, p_divSelectTree, p_imgPreview, p_selectHandler, p_selectFolderPath, p_hdnTreeSelectedFile, p_lblPreviewCaption, p_strAppPath) {
    var l_divSelect = document.getElementById(p_divSelectTree);
    if (l_divSelect != null && typeof (l_divSelect) != 'undefined') {
        l_divSelect.style.display = "block";

        $(p_selectControlID).fileTree({
            root: p_selectFolderPath,
            script: p_selectHandler,
            expandEasing: 'easeOutBounce',
            collapseEasing: 'easeOutBounce',
            multiFolder: false,
            folderEvent: 'click' //'dblclick',
        },
                function(file) {
                    var l_strSelectedFiles = document.getElementById(p_hdnTreeSelectedFile);
                    l_strSelectedFiles.value = file;
                    var l_strPreviewCaption = document.getElementById(p_lblPreviewCaption);
                    //l_strPreviewCaption.innerHTML = file;
                    var fileName = file.toString().replace(p_selectFolderPath, "").replace(/\\/g, "/");
                    var fileNameElems = fileName.split('/');
                    l_strPreviewCaption.innerHTML = fileNameElems[fileNameElems.length - 1];
                    var l_strPreviewImage = document.getElementById(p_imgPreview);
                    var l_strAppFolderPath = p_selectFolderPath.replace(p_strAppPath, "");
                    var l_strImageURL = l_strAppFolderPath + fileName;
                    CreateThumbnail(l_strImageURL.replace(/\\/g, "/"), 'existingimg');
                    //
                    //l_strPreviewImage.src = l_strAppFolderPath + fileName;
                    //l_strSelectedFiles.value = l_strSelectedFiles.value + file + ",";                
                    //alert(l_strPreviewImage.innerHTML);
                }
             );
    }
}


function CancelUpload(p_strhdnUploadFilesID, p_strhdnTreeSelectedFileID) {

    //p_hdnUploadedID, p_hdnSelectedID
    var l_hdnUploaded = document.getElementById(p_strhdnUploadFilesID);
    l_hdnUploaded.value = "";
    var l_hdnSelected = document.getElementById(p_strhdnTreeSelectedFileID);
    l_hdnSelected.value = "";

    return false;
}

function SubmitUpload(p_strbtnOKID) {

    __doPostBack(p_strbtnOKID, "");
}

/*----------------------------End --------------------------*/


/*------------- JQuery Tool Tip --------------------------*/

function ToolTipInit(p_strObjectName) {
    $(p_strObjectName).cluetip({ splitTitle: '|', dropShadow: false, showTitle: false });

}

/*--------------------JQuery ToolTip -----------------------*/

/*-------------------Candidate Form -  -------------------*/

/* Toggle Introduced By DropDown */
function ToggleIntroducedBY(p_oDDlSource, p_strIntroducedByClientID) {


    if (p_oDDlSource != null) {

        var l_strSource = p_oDDlSource.options[p_oDDlSource.selectedIndex].value;
        var l_otxtIntroducedBY = document.getElementById(p_strIntroducedByClientID);

        if (l_otxtIntroducedBY != null) {
            if (l_strSource == "Friend") {
                l_otxtIntroducedBY.style.display = "";
            }
            else {
                l_otxtIntroducedBY.style.display = "none";
            }

        }


    }
}

/* ----- Toggle Work Permit Radio Buttons */
function ToggleWorkPermit(p_orblCitizen, p_strrblWorkPermitID, p_strlblWPArrangedBYID, p_strtxtWPArrangedBYID, p_strSelectedValue) {


    if (p_orblCitizen != null) {
        var l_strSelectedValue = "";
        var l_olblWPArrangedBY = document.getElementById(p_strlblWPArrangedBYID);
        var l_otxtWPArrangedBY = document.getElementById(p_strtxtWPArrangedBYID);

        if (p_strSelectedValue <= 0)
            l_strSelectedValue = $('input[type=radio][id*=' + p_orblCitizen.id + ']:checked').val();
        else
            l_strSelectedValue = p_strSelectedValue;

        if (l_strSelectedValue == 4) {
            if ($('#' + p_strrblWorkPermitID) != null) {

                var radioButtons = $('input[type=radio][id*=' + p_strrblWorkPermitID + ']');
                var radioLabels = document.getElementById(p_strrblWorkPermitID).getElementsByTagName("label");

                if (radioButtons.length == 4) {

                    radioButtons[0].disabled = true;
                    radioLabels[0].disabled = true;
                    radioButtons[1].disabled = false;
                    radioLabels[1].disabled = false;
                    radioButtons[2].disabled = false;
                    radioLabels[2].disabled = false;
                    radioButtons[3].disabled = false;
                    radioLabels[3].disabled = false;

                    if (p_strSelectedValue <= 0) {
                        if ($('input[type=radio][id*=' + p_strrblWorkPermitID + ']:checked').val() == "1")
                            $('input[type=radio][id*=' + p_strrblWorkPermitID + '][value="' + 2 + '"]').attr('checked', 'checked');
                    }


                }


                l_olblWPArrangedBY.style.display = "";
                l_otxtWPArrangedBY.style.display = "";

            }

        }
        else {

            if ($('#' + p_strrblWorkPermitID) != null) {

                var radioButtons = $('input[type=radio][id*=' + p_strrblWorkPermitID + ']');
                var radioLabels = document.getElementById(p_strrblWorkPermitID).getElementsByTagName("label");

                if (radioButtons.length == 4) {

                    radioButtons[0].disabled = false;
                    radioLabels[0].disabled = false;
                    radioButtons[1].disabled = true;
                    radioLabels[1].disabled = true;
                    radioButtons[2].disabled = true;
                    radioLabels[2].disabled = true;
                    radioButtons[3].disabled = true;
                    radioLabels[3].disabled = true;

                    if (p_strSelectedValue <= 0) {
                        $('input[type=radio][id*=' + p_strrblWorkPermitID + '][value="' + 1 + '"]').attr('checked', 'checked');
                    }


                }

                l_olblWPArrangedBY.style.display = "none";
                l_otxtWPArrangedBY.style.display = "none";

            }

        }

    }

}

/*--------------------------------Candidate Form -----------------------------------------*/

/*-----------------Tempstaff Form -----------------------*/

function CalculateExpiryDate(p_otxtDate, p_strtxtExpiryDateID) {

    var l_dtDate = p_otxtDate.value;
    var l_strSourceDateArray = l_dtDate.split("/");
    var t = null;

    if (l_strSourceDateArray.length >= 3) {
        t = new Date(l_strSourceDateArray[2], l_strSourceDateArray[1] - 1, l_strSourceDateArray[0], 0, 0, 0, 0);
        t.setDate(t.getDate() + 364);
    }

    //new Date(year, month, day, hours, minutes, seconds, milliseconds);



    if (t != null && t != 'NaN') {
        if (document.getElementById(p_strtxtExpiryDateID) != null) {
            var l_strDate = t.format("dd/MM/yyyy");
            var l_strDateArray = l_strDate.split("/");

            if (l_strDateArray.length >= 3) {
                document.getElementById(p_strtxtExpiryDateID).value = l_strDateArray[0] + "/" + l_strDateArray[1] + "/" + l_strDateArray[2];
            }

        }


    }

}


/*------------------TempStaff Form----------------------*/

/*----------------------Course Booking Details------------------------------------*/
function confirmChangeStatus(p_strMessage, p_strIsAlert) {

    if (p_strIsAlert == "true") {

        alert(p_strMessage);
        return false;
    }
    else {

        if (confirm(p_strMessage)) {
            return true;
        }
        else { return false; }

    }
}

/*------------------------Course Booking Details----------------------------------*/

/*-------------------------HealthCare Booking Details ------------------------------*/
function CalculateShiftEndTime(p_otxtDate, p_strtxtShiftID) {
    var l_dtShiftEndTime = p_otxtDate.value;
    var l_oShiftControl = document.getElementById(p_strtxtShiftID)

    if (l_dtShiftEndTime == '') {

        if (l_oShiftControl != null) {

            var l_HrMinArray = l_oShiftControl.value.split(':');

            if (l_HrMinArray.length == 2) {
                var l_dtShiftDateTime = new Date(1900, 1, 1, l_HrMinArray[0], l_HrMinArray[1], 0, 0);

                if (l_dtShiftDateTime != null && l_dtShiftDateTime != 'NaN') {
                    l_dtShiftDateTime.setTime(l_dtShiftDateTime.getTime() + (8 * 60 * 60 * 1000));

                    if (p_otxtDate != null) {

                        if (l_dtShiftDateTime.getMinutes() == 0)
                            p_otxtDate.value = l_dtShiftDateTime.getHours() + ":00";
                        else
                            p_otxtDate.value = l_dtShiftDateTime.getHours() + ":" + l_dtShiftDateTime.getMinutes();
                    }
                }

            }


        }

    }


}


function CalculateHrsDiff(p_strtxtShiftID, p_strtxtShiftEndID, p_strtxtHrsID) {


    var l_oShiftControl = document.getElementById(p_strtxtShiftID);
    var l_oShiftEndControl = document.getElementById(p_strtxtShiftEndID);
    var l_oHrsControl = document.getElementById(p_strtxtHrsID);


    if (l_oShiftControl != null && l_oShiftEndControl != null && l_oHrsControl != null) {

        var l_ShiftValue = l_oShiftControl.value;
        var l_ShiftEndValue = l_oShiftEndControl.value;

        if (l_ShiftValue != "" && l_ShiftEndValue != "") {

            var l_HrMinShitArray = l_ShiftValue.split(':');
            var l_HrMinShiftEndArray = l_ShiftEndValue.split(':');
            var l_dtShiftDateTime;
            var l_dtShiftEndDateTime;

            if (l_HrMinShitArray.length == 2)
                l_dtShiftDateTime = new Date(1900, 1, 1, l_HrMinShitArray[0], l_HrMinShitArray[1], 0, 0);

            if (l_HrMinShiftEndArray.length == 2)
                l_dtShiftEndDateTime = new Date(1900, 1, 1, l_HrMinShiftEndArray[0], l_HrMinShiftEndArray[1], 0, 0);

            if (l_dtShiftDateTime != null && l_dtShiftDateTime != 'NaN' && l_dtShiftEndDateTime != null && l_dtShiftEndDateTime != 'NaN') {

                if (l_dtShiftEndDateTime < l_dtShiftDateTime) {
                    l_dtShiftEndDateTime.setDate(l_dtShiftEndDateTime.getDate() + 1);

                    var milsecDiff = Math.abs(l_dtShiftEndDateTime - l_dtShiftDateTime); // You Will get Diffrence in Milliseconds
                    var l_intTotalMinutes = milsecDiff / (1000 * 60);
                    var l_intHours = Math.floor(l_intTotalMinutes / 60);
                    var l_intMinutes = l_intTotalMinutes % 60;
                    if (l_intMinutes <= 0)
                        l_oHrsControl.value = String(l_intHours) + ":00";
                    else
                        l_oHrsControl.value = String(l_intHours) + ":" + String(l_intMinutes);

                }
                else {
                    var milsecDiff = Math.abs(l_dtShiftEndDateTime - l_dtShiftDateTime); // You Will get Diffrence in Milliseconds
                    var l_intTotalMinutes = milsecDiff / (1000 * 60);
                    var l_intHours = Math.floor(l_intTotalMinutes / 60);
                    var l_intMinutes = l_intTotalMinutes % 60;
                    if (l_intMinutes <= 0)
                        l_oHrsControl.value = String(l_intHours) + ":00";
                    else
                        l_oHrsControl.value = String(l_intHours) + ":" + String(l_intMinutes);

                }

            }

        }


    }

}


function SetDateTimeOnCheck(p_strCheckBoxID, p_strDateControlID, p_strTimeControlID, p_strProvID) {

    var l_oChkBoxControl = document.getElementById(p_strCheckBoxID);
    var l_otxtDateControl = document.getElementById(p_strDateControlID);
    var l_otxtTimeControl = document.getElementById(p_strTimeControlID);
    var l_oChkBoxProvisionalControl = document.getElementById(p_strProvID);


    if (l_oChkBoxControl != null && l_otxtDateControl != null && l_otxtTimeControl != null) {

        if (l_oChkBoxControl.checked) {
            var l_dtToday = new Date();
            l_otxtDateControl.value = l_dtToday.format("dd/MM/yyyy");
            l_otxtTimeControl.value = l_dtToday.format("HH:mm");
            if (l_oChkBoxProvisionalControl != null) {
                l_oChkBoxProvisionalControl.checked = false;
            }
        }



    }

}




/*-------------------------HealthCare Booking Details ------------------------------*/


/*-----------------------------Script for Autosave--------------------------------*/

function form_is_modified(oForm) {
    var el, opt, hasDefault, i = 0, j;
    while (el = oForm.elements[i++]) {

        // Put the check of lastcontactdate and reminder date of contact note control. Because these fields do not update when you press next and previous
        // Hence have updated them through register java script and then it changes the default value and always show change.
        if (el.id.indexOf('txtLastContactDate') <= 0 && el.id.indexOf('txtReminderDate') <= 0) {

            switch (el.type) {
                case 'text':
                case 'textarea':
                    //case 'hidden':
                    if (!/^\s*$/.test(el.value) && el.value != el.defaultValue) return true;
                    break;
                case 'checkbox':
                case 'radio':
                    if (el.checked != el.defaultChecked) return true;
                    break;
                case 'select-one':
                case 'select-multiple':
                    j = 0, hasDefault = false;
                    while (opt = el.options[j++])
                        if (opt.defaultSelected) hasDefault = true;
                    j = hasDefault ? 0 : 1;
                    while (opt = el.options[j++])
                        if (opt.selected != opt.defaultSelected) return true;
                    break;
            }

        }

    }
    return false;
}


function HideModalPopUp() {

    alert('hello');
    $Find('ctl00_cpHolderBody_PTCMailMergeManagementControl_PTCMailingListParentControl_PTCMailingGroupUsers_ModalPopupExtender').hide();
    return false;

}


function UnloadingForm() {

    return true;

    // Comment the code here to check whether the system flickering relates to this autosave functionality
    /*
    if (form_is_modified(document.forms[0])) {
    if (confirm('You have modified the page but not saved it. Are you sure you want to move from here without saving the information?'))
    return true;
    else
    return false;
    }
    else
    return true;
    */

}



/*--------------------------------Script for Autosave--------------------------------*/




function DisplayErrorMessage(pstrMsg) {
    alert(pstrMsg);
    return false;

}

/************For DropDown Selected Value******************/

function setSelectedValueinHiddenField(p_oListLstBox, hdnFieldID) {


    var l_olstBox = p_oListLstBox;
    var HiddenFld = document.getElementById(hdnFieldID);

    for (i = 0; i < l_olstBox.options.length; i++) {
        if (l_olstBox.options[i].selected) {

            //HiddenFld.value = l_olstBox.options[i].innerHTML + '|' + l_olstBox.options[i].value;
            HiddenFld.value = l_olstBox.options[i].innerHTML;
        }
    }
}

/****************End For DropDown Selected Value****************/



/* Method added by Hifsa for control the width */
/*function changeHeight() {
//debugger;
var l_intheight;
var l_intwidth;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined') {
l_intheight = window.innerHeight
l_intwidth = window.innerWidth
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0) {
l_intheight = document.documentElement.clientHeight
l_intwidth = document.documentElement.clientWidth
}
// older versions of IE
else {
l_intheight = document.getElementsByTagName('body')[0].clientHeight
l_intwidth = document.getElementsByTagName('body')[0].clientWidth
}

var l_intscreenHeight = screen.height;
var l_intscreenWidth = screen.width;

var l_intcontainerheight = l_intheight - 48 - 50;
var l_intinnerscreen = l_intcontainerheight - 9;

var l_intcontainerwidth = l_intwidth - 83 - 8;
var l_intinnerscreenwidth = l_intcontainerwidth - 9;

l_intcontainerheight += "px";
l_intinnerscreen += "px";

l_intcontainerwidth += "px";
l_intinnerscreenwidth += "px";

var control = document.getElementById("divcontainer");
control.style.height = l_intcontainerheight;
control.style.width = l_intcontainerwidth;

var control2 = document.getElementById("divInnercontainer");
control2.style.height = l_intinnerscreen;
control2.style.width = l_intinnerscreenwidth;
}
*/
function EmailTextStatusOnLoad(pStatus, Survey_EmailAddressID) {
    var liObject = document.getElementById(Survey_EmailAddressID);

    if (liObject != null) {
        if (pStatus)
            liObject.style.display = '';
        else
            liObject.style.display = 'none';
    }

}

function HideSurveyEmailAddress(ddlResourceTypeID, Survey_EmailAddressID) {

    var ddlResourceTypeSelectedValue = $get(ddlResourceTypeID).checked;

    if (ddlResourceTypeSelectedValue) {
        ShowControl(Survey_EmailAddressID);
    }
    else {
        HideControl(Survey_EmailAddressID);
    }
}
// Start: Added by Mishal for site object toggling
function toggle_view(id) {

    var divImgSet1 = document.getElementById('divMenu'); //$get('divMenu');
    var divImgSet2 = document.getElementById('divLarge'); //$get('divLarge');
    var divImgSet3 = document.getElementById('divMedium'); //$get('divMedium');
    var divEnable = document.getElementById(id);
    var divClose = document.getElementById('divClose'); //$get('divClose');
    var divText = document.getElementById('divText');
    var imgDivText = document.getElementById('imgDivText');
    divText.style.display = "block";
    divImgSet1.style.display = "none";
    divImgSet2.style.display = "none";
    divImgSet3.style.display = "none";

    if (divEnable != null && typeof (divEnable) != 'undefined') {
        divText.style.display = "block";
        divClose.style.display = "block";
        if (divEnable == divImgSet1) {
            divImgSet1.style.display = "block";
            imgDivText.innerText = "Menu Images";
        }
        else if (divEnable == divImgSet2) {
            divImgSet2.style.display = "block";
            imgDivText.innerText = "Large Images";
        }
        else if (divEnable == divImgSet3) {
            divImgSet3.style.display = "block";
            imgDivText.innerText = "Medium Images";
        }
    }
    else {
        divText.style.display = "none";
    }

}

function toggle(id) {
    var divImgSet1 = document.getElementById('divMenu'); //$get('divMenu');
    var divImgSet2 = document.getElementById('divLarge'); //$get('divLarge');
    var divImgSet3 = document.getElementById('divMedium'); //$get('divMedium');
    var imgDivText = document.getElementById('imgDivText'); //$get('imgDivText');

    var divEna = document.getElementById(id);
    if (divEna != null) {

        divImgSet1.style.display = "none";
        divImgSet2.style.display = "none";
        divImgSet3.style.display = "none";
        imgDivText.innerText = "";
    }
    else {
        divEna.style.display = "none";
    }
} //End

function CreateThumbnail(imageURL, InputID) {

    if (imageURL != '') {

        $(':file[name=' + InputID + ']').inputFileThumb({
            'file': imageURL,
            'title': '',
            'description': '',
            'extensions': ['png', 'jpg', 'jpeg', 'gif'],
            'deleteInput': 'delete_hidden',
            'height': '250px',
            'width': '270px',
            'deleteInput': false,
            'editTitle': ''
        });
    }
    else {

        $(':file[name=' + InputID + ']').inputFileThumb({
            'file': 'Library/Images/NoImage.jpg',
            'title': '',
            'description': '',
            'extensions': ['png', 'jpg', 'jpeg', 'gif'],
            'deleteInput': 'delete_hidden',
            'height': '250px',
            'width': '270px',
            'deleteInput': false,
            'editTitle': ''
        });


    }
}


//Added by Mishal for online survey Add Question senario
function ddlQuestionOptionType_IndexChanged(ddlQuestionOptionTypeID, txtOptionsValueID, lblOptionValueID, cbIsRequiredFieldID, liIsRequiredID, liMessageBoxID, rfvQuestionOption, rfvErrorMessage) {

    var ddlQuestionOptionTypeSelectedValue = $(ddlQuestionOptionTypeID).val();
    var cbIsRequiredField = document.getElementById(cbIsRequiredFieldID);

    var rfvQuestionOptionValue = document.getElementById(rfvQuestionOption);
    var rfvErrorMessageValue = document.getElementById(rfvErrorMessage);
    if (ddlQuestionOptionTypeSelectedValue == "1" || ddlQuestionOptionTypeSelectedValue == "2" || ddlQuestionOptionTypeSelectedValue == "6") {

        HideControl(txtOptionsValueID);
        ValidatorEnable(rfvQuestionOptionValue, false);
        HideControl(lblOptionValueID);
        ShowControl(liIsRequiredID);
        if (cbIsRequiredField.checked) {
            ShowControl(liMessageBoxID);
            ValidatorEnable(rfvErrorMessageValue, true);
        }
        else {

            ValidatorEnable(rfvErrorMessageValue, false);

        }


    }
    else if (ddlQuestionOptionTypeSelectedValue == "0") {
        HideControl(txtOptionsValueID);
        HideControl(lblOptionValueID);
        HideControl(liIsRequiredID);
        HideControl(liMessageBoxID);
        ValidatorEnable(rfvErrorMessageValue, false);
    }
    else {
        ShowControl(txtOptionsValueID);
        ShowControl(lblOptionValueID);
        ShowControl(liIsRequiredID);
        ValidatorEnable(rfvQuestionOptionValue, true);
        if (cbIsRequiredField.checked) {
            ShowControl(liMessageBoxID);
            ValidatorEnable(rfvErrorMessageValue, true);
        }

        else {

            ValidatorEnable(rfvErrorMessageValue, false);

        }
    }

}
function HideControl(HideControlID) {
    //document.getElementById(HideControlID).style.display='none';
    $(HideControlID).hide();

}
function ShowControl(ShowControlID) {
    //  document.getElementById(ShowControlID).style.display='';
    $(ShowControlID).show();
}
function ShowHideErrorMessageBox(cbIsRequiredID, liErrorMessageBoxID, rfvErrorMessage) {

    var cbIsRequired = document.getElementById(cbIsRequiredID);
    var rfvErrorMessageValue = document.getElementById(rfvErrorMessage);
    if (cbIsRequired.checked) {


        ShowControl(liErrorMessageBoxID);
        ValidatorEnable(rfvErrorMessageValue, true);

    }
    else {
        HideControl(liErrorMessageBoxID);
        ValidatorEnable(rfvErrorMessageValue, false);
    }


}
/////////////////////////////////////////////////////////////////////////

function DropdownSelectedValue(p_oDropDownObject) {
    var e = p_oDropDownObject;
    var strSelectedValue = e.options[e.selectedIndex].value;

    return strSelectedValue;

}
function ddlQuestionOptionValue(ddlQuestionValue) {
    document.getElementById(m_hdnQuestionToSwapID).value = $(ddlQuestionValue).val();
}
