﻿// JScript File

function mn_displaymenu(val) {
    if (val == 0) return;
    mn_init();
}

function sessionwarn1() {
    setTimeout("sessionwarn2()", 600000);
    if (window.location.href.indexOf('signinout') == -1)
        alert('This is a warning that your session has been inactive for more than 10 minutes.\nAfter another 10 minute of inactivity you will have to sign in again.');
}

function sessionwarn2() {
    if (window.location.href.indexOf('signinout') == -1)
        alert('To protect your account your session has now expired due to inactivity. You will have to sign in again.');
    window.location.href = '../forms/signinout.aspx?force=yes';
}

///////////////////////////////////////////////////////////////



function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function changeImages() {
    if (document.images && (preloadFlag == true)) {
        for (var i = 0; i < changeImages.arguments.length; i += 2) {
            document[changeImages.arguments[i]].src = changeImages.arguments[i + 1];
        }
    }
}

var preloadFlag = false;
function preloadImages() {
    if (document.images) {
        home_over = newImage("../images/home-over.jpg");
        intake_over = newImage("../images/intake-over.jpg");
        outcome_over = newImage("../images/outcome-over.jpg");
        addedit_over = newImage("../images/addedit-over.jpg");
        care_over = newImage("../images/care-over.jpg");
        services_over = newImage("../images/services-over.jpg");
        reports_over = newImage("../images/reports-over.jpg");
        admin_over = newImage("../images/admin-over.jpg");
        preloadFlag = true;
    }
}

function loadWin(strURL) {
    objNewWinref = window.open(strURL);
}

function About() {
    window.open('adminabout.html', 'AboutPage', 'status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=400');
}

function Help() {
    window.open('http://www.petpoint.com/help', 'Help', 'status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
}

function Report(url, cim) {
    ClearLastFocus();
    var wh = window.open(url, cim, 'status=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=580,top=40');
    wh.window.focus();
    wh.window.location = url;
}
function MedicalReport(url, cim) {
    ClearLastFocus();
    var wh = window.open(url, cim, 'status=no,menubar=no,scrollbars=yes,resizable=yes,width=850,height=650,top=40');
    wh.window.focus();
}

function PhotoView(url, cim) {
    ClearLastFocus();
    window.open(url, cim, 'status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=400');
}

function PopupForm(url, cim) {
    ClearLastFocus();
    window.open(url, cim, 'status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
}

function SetFocusOnFirstInput() {
    var ua = navigator.userAgent.toLowerCase();

    //only Internet Explorer
    if (ua.indexOf("msie")) {
        var coll = document.all.tags("INPUT");

        if (coll != null) {
            c = true;
            i = 0;
            while (c) {
                if ((coll[i].type == "text") && (coll[i].readOnly == false) && (coll[i].disabled == false)) {
                    //coll[i].focus();
                    c = false;
                }
                i++;
                if (i == coll.length) c = false;
            }
        }
    }
}

// Load RTB info from the database into the DIV field on the web.
// so one can edit the database info in the Rich Text Box.
function LoadDiv() {
    var String = document.getElementById("cphWorkArea_txtRTB").value;
    TextEditor.innerHTML = String;   // set the innerHTML of the DIV to the text of the textbox
}
// sets the text in the Div to a textbox which you can pull the 
// data from to save in the database
function getHTML() {
    var String = TextEditor;  // The TextEditor DIV can not be in a form or the Java error out
    document.getElementById("cphWorkArea_txtRTB").value = String.innerHTML;   //you can't make the text box invisible or the Java will error out
}

// Sets focus to element with specified id
function DoFocus(id) {
    try { document.getElementById(id).focus(); } catch (ex) { }
}

// Saves id of active control in hidden field __LASTFOCUS
function SaveLastFocus(id) {
    try { document.getElementById('__LASTFOCUS').value = id } catch (e) { }
}

// Removes id of last active control
function ClearLastFocus() {
    try { document.getElementById('__LASTFOCUS').value = '' } catch (e) { }
}
function Click(ButtonType) {
    var mClick = null;

    if (ButtonType == 'N') {
        mClick = document.getElementById("cphSearchArea_ClickN");
    }
    else {
        if (ButtonType == 'P') {
            mClick = document.getElementById("cphSearchArea_ClickP");
        } else {
            mClick = document.getElementById("cphSearchArea_ClickF");
        }
    }
    if (mClick.value == "1") {
        return false;
    } else {
        mClick.value == "1";
        return true;
    }
}

// Opens embedded reports in a pop-up from AnimalSummary and Actions controls
function openAsPopup1(ddl) {
    var ddlKCval = ddl.options[ddl.selectedIndex].value;
    if ((ddlKCval != '0') && ((ddlKCval).indexOf('CustomKennelCard') < 0)) {
        if ((ddlKCval).indexOf('MedicalViewReport') > 0) {
            window.open(ddlKCval, 'cim', 'status=no,menubar=no,scrollbars=yes,resizable=yes,width=850,height=650,top=40');
        }
        else {
            window.open(ddlKCval, 'cim', 'status=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=580,top=40');
        }
        ddl.selectedIndex = 0;
        return true;
    }
    else if ((ddlKCval).indexOf('CustomKennelCard') >= 0) { //'IF IS Custom Kennel Card      
        window.open('../embeddedreports/CustomKennelCard.aspx?kennelcard=' + escape(ddlKCval), 'cim', 'status=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=580,top=40');
        ddl.selectedIndex = 0; //Reset Kennel Card drop-down
        return true;
    }
    else {
        ddl.selectedIndex = 0;
        return true;
    }
} 



//-------------------------------------------------------------------
// SectionBlock & ReportBlock - Collapsible
//-------------------------------------------------------------------
function toggleSectionBlock(obj) {
    var CollapsibleSBID = obj.nextSibling.id;
    var vis = obj.nextSibling.style;
    if (vis.display == 'none') {
        vis.display = 'block';
        obj.style.backgroundImage = "url(../images/icoOpen2.png)";
        document.cookie = "sbCookie1" + CollapsibleSBID + "=block; path=/"
    }
    else {
        vis.display = 'none';
        obj.style.backgroundImage = "url(../images/icoClose2.png)";
        document.cookie = "sbCookie1" + CollapsibleSBID + "=none;  path=/"
    }
}
function toggleReportBlock(obj) {
    var CollapsibleRBID = obj.nextSibling.id;
    var vis = obj.nextSibling.style;
    if (vis.display == 'none') {
        vis.display = 'block';
        obj.style.backgroundImage = "url(../images/icoOpen.png)";
        document.cookie = "rbCookie1" + CollapsibleRBID + "=block; path=/"
    }
    else {
        vis.display = 'none';
        obj.style.backgroundImage = "url(../images/icoClose.png)";
        document.cookie = "rbCookie1" + CollapsibleRBID + "=none;  path=/"
    }
}
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
function EndRequestHandler() {
    var myCookie = getCookie("sbCookie1" + CollapsibleSBID);
    var div1 = document.getElementById(CollapsibleSBID);

    if ((myCookie != null && myCookie != "") && (div1 != null && div1 != "")) {
        var obj = div1.previousSibling;
        if (myCookie == "block") {
            div1.style.display = "block";
            if (obj != null && obj != "") {
                obj.style.backgroundImage = "url(../images/icoOpen2.png)";
            }
        }
        else {
            div1.style.display = "none";
            if (obj != null && obj != "") {
                obj.style.backgroundImage = "url(../images/icoClose2.png)";
            }
        }
    }
}

function CheckAtLeastOneSelected(invoker, srch_name) {
    // Check Hiden var for Animal Tab
    var FoundHiddenField = false;
    var hdeHidden0 = window.document.getElementById("chdSingleRecMode0");
    var hdeHidden1 = window.document.getElementById("chdSingleRecMode1");
    var hdeHidden2 = window.document.getElementById("chdSingleRecMode2");
    var hdeHidden3 = window.document.getElementById("chdSingleRecMode3");
    if ((hdeHidden0 != null) || (hdeHidden1 != null) || (hdeHidden2 != null) || (hdeHidden3 != null)) {
        FoundHiddenField = true;
    }
    //  let's get all the inputs
    var OneSelected = false;
    var inputElements = document.getElementsByTagName('input');
    for (var i = 0; i < inputElements.length; i++) {
        var myElement = inputElements[i];
        // Filter through the input types looking for checkboxes
        if (myElement.type == "checkbox" && myElement.name.search(srch_name) != -1) {
            // Use the invoker (our calling element) as the reference 
            //  for our checkbox status
            if (FoundHiddenField == false) {
                if (myElement.checked) {
                    OneSelected = true;
                    break;
                }
            }
            if (FoundHiddenField == true) {
                myElement.checked = false;
                OneSelected = false;
            }

        }
    }
    if (OneSelected == false) {
        invoker.checked = true;
    }
}



//-------------------------------------------------------------------
// Checked/Uncheked Header Checkbox in FollowUp Module
//-------------------------------------------------------------------
function HeaderCheckboxClicked(invoker, srch_name) {
    //  let's get all the inputs
    var inputElements = document.getElementsByTagName('input');
    var hdeAllSelected = window.document.getElementById("chdAllSelected");
    for (var i = 0; i < inputElements.length; i++) {
        var myElement = inputElements[i];
        // Filter through the input types looking for checkboxes
        if (myElement.type == "checkbox" && myElement.name.search(srch_name) != -1) {
            myElement.checked = invoker.checked;
            if (hdeAllSelected != null) { hdeAllSelected.checked = invoker.checked; }
        }   
    }
}
function RowCheckboxClicked(invoker, srch_name) {
    //  let's get all the inputs
    var inputElements = document.getElementsByTagName('input');
    var hdeAllSelected = window.document.getElementById("chdAllSelected");
    var HeaderCheckBox;
    var AllRowsAreSelected = true;

    // Filter through the input types looking for Header CheckBox
    for (var i = 0; i < inputElements.length; i++) {
        var myElement = inputElements[i];        
        if (HeaderCheckBox == null && myElement.type == "checkbox" && myElement.name.search(srch_name) != -1) {
            HeaderCheckBox = myElement;
        }
    }

    if (invoker.checked == false) {
        AllRowsAreSelected = false;
    }
    else {
        for (i = 0; i < inputElements.length; i++) {
            myElement = inputElements[i];
            // Filter through the input types looking checkbox other, then Header CheckBox
            if (myElement.type == "checkbox" && myElement.name.search("chkSelected_Row") != -1) {
                if (myElement.checked == false) {
                    AllRowsAreSelected = false;
                }
            }
        }    
    }

    if (HeaderCheckBox != null) { HeaderCheckBox.checked = AllRowsAreSelected; }

    if (hdeAllSelected != null) { hdeAllSelected.value = AllRowsAreSelected; }

}
//-------------------------------------------------------------------
// Checked/Uncheked Header Checkbox in FollowUp Module
//-------------------------------------------------------------------




//-------------------------------------------------------------------
// Disable switching between tabs if isPPPageLoaded not defined
//-------------------------------------------------------------------
function passEvent() {
    return window.isPPPageLoaded != null;
}



// Following function is called from Animal Search Pop-up.
// It requires 3 hidden fields declared by following IDs and will hold respective search fields IDs
// For this function to copy ID to text-box ---> ddlCriteria.selectedText='Animal'  and   ddlCriteria2.selectedText='Animal #'

function copyAnimalIDToParentForm(anx) {
    var txtId = window.opener.document.getElementById('txtAnimalIdHolder');
    var cr1Id = window.opener.document.getElementById('ddlCriteria1IDHolder');
    var cr2Id = window.opener.document.getElementById('ddlCriteria2IDHolder');

    if ((txtId != null) && (cr1Id != null) && (cr2Id != null)) {
        var cr1 = window.opener.document.getElementById(cr1Id.value);
        var cr2 = window.opener.document.getElementById(cr2Id.value);
        var ani = window.opener.document.getElementById(txtId.value);

        if ((cr1 != null) && (cr2 != null) && (ani != null)) {
            // If ddlCriteria='Animal'  and   ddlCriteria2='Animal #' then copy AnimalID to text-box
            // We need ddl.text here bcz selectedValues may be different on different parent forms. However it requires the text (i.e. 'Animal' & 'Animal #') to be same. 
            if ((cr1.options[cr1.selectedIndex].text == "Animal") && (cr2.options[cr2.selectedIndex].text == "Animal #")) {
                ani.value = anx;
                //window.opener.focus();
                top.parent.opener.focus();
            } 
        }
    }
    return false;
}

// Following 3 functions (openPopup1,openPopup2,closePopupsOnSignOut) are part of Animal Search Pop-up functionality.
// We need to call pop-up from here as shown, bcz we need to close pop-ups on sign-out and to do that we need handles 'popWin','popWin2'
var popWin, popWin2;

// Pop-up called from MedicalSearchOnTab
function openPopup1(url, cim) {
    popWin = window.open(url, cim, 'status=no,menubar=no,scrollbars=yes,resizable=yes,width=940,height=580,top=40,left=100');
    popWin.window.focus();
}

// Pop-up called from AnimalSearchOnTab
function openPopup2(url, cim) {
    popWin2 = window.open(url, cim, 'status=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=580,top=40,left=100');
    popWin2.window.focus();
}

// Called from default.master on sign-out, will close pop-ups opened for Animal Search
function closePopupsOnSignOut() {
    if (popWin != null) {
        popWin.close();
    }
    if (popWin2 != null) {
        popWin2.close();
    }
}


//Adopter Checklist Checkboxes
function ACL_Prod_Clicked(cnf, c1, c2, c3, c4, c5, c6, c7, cOth, tOth) {
    var bProChecked = false;
    if (c4 != null) {
        bProChecked = (c1.checked || c2.checked || c3.checked || c4.checked || c5.checked || c6.checked || c7.checked || cOth.checked);
    }
    else {
        bProChecked = (c1.checked || c2.checked || c3.checked || c5.checked || c6.checked || c7.checked || cOth.checked);
    }

    if (bProChecked) {
        cnf.setAttribute("disabled", "disabled");
        //cnf.checked = false;
    }
    else {
        cnf.removeAttribute("disabled");
        //cnf.checked = true;
    }

    if (cOth.checked) {
        tOth.removeAttribute("disabled");
        tOth.removeAttribute("unselectable");
        tOth.removeAttribute("contenteditable");
        tOth.style.backgroundColor = "#ffffff";
    }
    else {
        tOth.setAttribute("disabled", "disabled");
        tOth.setAttribute("unselectable", "on");
        tOth.setAttribute("contenteditable", "false");
        tOth.style.backgroundColor = "#eaeaea";
        tOth.value = "";
    }
}
function ACL_NoFree_Clicked(cnf, c1, c2, c3, c4, c5, c6, c7, cOth, tOth) {
    if (cnf.checked) {
        c1.setAttribute("disabled", "disabled");
        c2.setAttribute("disabled", "disabled");
        c3.setAttribute("disabled", "disabled");
        if (c4 != null) {
            c4.setAttribute("disabled", "disabled");
            c4.checked = false;
        }
        c5.setAttribute("disabled", "disabled");
        c6.setAttribute("disabled", "disabled");
        c7.setAttribute("disabled", "disabled");
        cOth.setAttribute("disabled", "disabled");
        tOth.setAttribute("disabled", "disabled");
        tOth.setAttribute("unselectable", "on");
        tOth.setAttribute("contenteditable", "false");

        c1.checked = false;
        c2.checked = false;
        c3.checked = false;
        c5.checked = false;
        c6.checked = false;
        c7.checked = false;
        cOth.checked = false;
        tOth.value = "";
    }
    else {
        c1.removeAttribute("disabled");
        c2.removeAttribute("disabled");
        c3.removeAttribute("disabled");
        if (c4 != null) {
            c4.removeAttribute("disabled");
        }
        c5.removeAttribute("disabled");
        c6.removeAttribute("disabled");
        c7.removeAttribute("disabled");
        cOth.removeAttribute("disabled");
        if (cOth.checked) {
            tOth.removeAttribute("disabled");
            tOth.removeAttribute("unselectable");
            tOth.removeAttribute("contenteditable");
            tOth.style.backgroundColor = "#ffffff";
        }
        else {
            tOth.setAttribute("disabled", "disabled");
            tOth.setAttribute("unselectable", "on");
            tOth.setAttribute("contenteditable", "false");
            tOth.style.backgroundColor = "#eaeaea";
            tOth.value = "";
        }
    }
}

// called from PersonSearch select datagerid to validate Address for ownership
function CheckAddress(mStreetNumber, mStreetName, mStreetType, mCity, mProvince, mPostalCode) {
         //        var mStreetNumber = document.getElementById("cphSearchArea_Wizard1_ctrlPerson_txtStreetNumber");
         //        var mStreetName = document.getElementById("cphSearchArea_Wizard1_ctrlPerson_txtStreetName");
         //        var mStreetType = document.getElementById("cphSearchArea_Wizard1_ctrlPerson_ddlStreetType");
         //        var mCity = document.getElementById("cphSearchArea_Wizard1_ctrlPerson_ddlCity");
         //        var mProvince = document.getElementById("cphSearchArea_Wizard1_ctrlPerson_ddlState");
         //        var mPostalCode = document.getElementById("cphSearchArea_Wizard1_ctrlPerson_txtZipCode");

         //alert("In CheckAddress: ");

         if (mStreetNumber == null) {
                  return true;
                 }
                 else {
//                     if (mStreetNumber.disabled != false) {
//                         alert("mStreetNumber.disabled ");
//                         return false;
//                     }
//                     else {
                         if ((mStreetNumber == "") || (mStreetName == "")
                     || (mCity == "")
         	        || (mProvince == "")
         	        || (mPostalCode == "")) {
                             return confirm('Warning: Address is not specified or incomplete. An address is required to register a microchip.  Are you sure you want to proceed?');
                         }
                         else {
                             return true;
                         }
//                     }
                 }
     }

     function CheckNewAddressPersonEmbedded() {

         var mStreetNumber = document.getElementById("cphSearchArea_ctrlOwnership_ctrlPerson_ctrlPersonEmbeddedExpress_txtStreetNumber");
         var mStreetName = document.getElementById("cphSearchArea_ctrlOwnership_ctrlPerson_ctrlPersonEmbeddedExpress_txtStreetName");
         var mStreetType = document.getElementById("cphSearchArea_ctrlOwnership_ctrlPerson_ctrlPersonEmbeddedExpress_ddlStreetType");
         var mCity = document.getElementById("cphSearchArea_ctrlOwnership_ctrlPerson_ctrlPersonEmbeddedExpress_ddlCity");
         var mProvince = document.getElementById("cphSearchArea_ctrlOwnership_ctrlPerson_ctrlPersonEmbeddedExpress_ddlState");
         var mPostalCode = document.getElementById("cphSearchArea_ctrlOwnership_ctrlPerson_ctrlPersonEmbeddedExpress_txtZipCode");
         
//         if (mStreetNumber == null) {
//             return true;
//         }
//         else {
//             if (mStreetNumber.disabled != false) {
//                 return true;  // return true to ignore validation
//             }
//             else {
                 if ((mStreetNumber.value == "") || (mStreetName.value == "")
            || (mCity.value == "0")
	        || (mProvince.value == "0")
	        || (mPostalCode.value == "")) {
                     return confirm('Warning: Address is not specified or incomplete. An address is required to register a microchip.  Are you sure you want to proceed?');
                 }
                 else {
                     return true;
                 }
//             }
//         }
     }


