﻿/*
* UFA Standard, Basic, Default Java Scripts
*
*/


$(document).ready(function () {
    $("#featured > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 10000, true);
});


$(document).ready(function () {
    $('.menuitem img').animate({ width: 120 }, 0);
    $('.menuitem').mouseover(function () {
        gridimage = $(this).find('img');
        gridimage.stop().animate({ width: 170 }, 180);
    }).mouseout(function () {
        gridimage.stop().animate({ width: 120 }, 180);
    });
}); 


/*
* SimpleModal Basic Modal Dialog
* http://www.ericmmartin.com/projects/simplemodal/
* http://code.google.com/p/simplemodal/
*
* Copyright (c) 2010 Eric Martin - http://ericmmartin.com
*
* Licensed under the MIT license:
*   http://www.opensource.org/licenses/mit-license.php
*
* Revision: $Id: basic.js 243 2010-03-15 14:23:14Z emartin24 $
*
*/

jQuery(function ($) {
    $('#basic-modal .basic').click(function (e) {
        $('#basic-modal-content').modal();

        return false;
    });
});


/*
Script by Anubhav Misra (anubhav_misra@hotmail.com)
Submitted to JavaScript Kit (http://javascriptkit.com)
For this and 400+ free scripts, visit http://javascriptkit.com
*/

function validate(text1, text2, text3, text4) {
    if (text1 == text2 && text3 == text4)
        load('/divisions/prevention/iso/iso.aspx');
    else {
        load('/divisions/prevention/iso/fail.aspx');
    }
}
function load(url) {
    location.href = url;
}

/*This is for the accordian menu for the health and safety page*/
function initMenus() {
    $('div ul.menu ul').hide();
    $.each($('div ul.menu'), function () {
        $('#' + this.id + '.expandfirst div ul:first').show();
    });
    $('div ul.menu li a').click(
		function () {
		    var checkElement = $(this).next();
		    var parent = this.parentNode.parentNode.id;

		    if ($('#' + parent).hasClass('noaccordion')) {
		        $(this).next().slideToggle('normal');
		        return false;
		    }
		    if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		        if ($('#' + parent).hasClass('collapsible')) {
		            $('#' + parent + ' ul:visible').slideUp('normal');
		        }
		        return false;
		    }
		    if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		        $('#' + parent + ' ul:visible').slideUp('normal');
		        checkElement.slideDown('normal');
		        return false;
		    }
		}
	);
}
$(document).ready(function () { initMenus(); });



//**********************************************************************
//  (credit card payments) Steven Packham(Unified Fire Authority SLC)

/*This is for radio buttons syncronization on step 1 payment page*/

function ClearRadiosOnPageLoad() {
    var radio1s = document.getElementsByName("Radio1");
    for (ind = 0; ind < radio1s.length; ind++) {
        radio1s[ind].selected = false;
    }
}

function CheckIfOneSelected() {
    var errorlabel = document.getElementById('Label_Error');
    errorlabel.innerText = "";
    errorlabel.textContent = "";
    if (Page_ClientValidate('ValidationGroupPayType1')) {
            return true;
        }
        else {
        errorlabel.textContent = "(Select A Payment Type)";
        errorlabel.innerText = "(Select A Payment Type)";
        return false;
    }

}

//******************* Show/Hide Element for Other Than credit Card Name

function ShowNamedOther(sender, otherTableID) {
    var tableNamedOther = document.getElementById(otherTableID);
    if (sender.checked) {
        tableNamedOther.style.display = '';
    }
    else {
        tableNamedOther.style.display = 'none';
    }
}

function ShowNamedOtherOnLoad() {
    var otherCheckBoxes =document.getElementsByClassName('OtherCheckBoxes');
    for (ind = 0; ind < otherCheckBoxes.length; ind++) {
        ShowNamedOther(otherCheckBoxes[ind]);
    }
}



//**************  Checks for Expired CC on client Side

function setCCExpiredDate(monthDropDownID, yearDropDownID, errorLabelID) {
    var monthDDCont = document.getElementById(monthDropDownID);
    var yearDDCont = document.getElementById(yearDropDownID);
    var errLblCont = document.getElementById(errorLabelID);

    if (monthDDCont.selectedIndex > 0 && yearDDCont.selectedIndex > 0) {

        var today = new Date();
        var today = new Date(today.getFullYear(), today.getMonth(), 0, 0, 0, 0);
        var expDate = new Date(yearDDCont.value, monthDDCont.selectedIndex - 1, 0, 0, 0, 0);

        if (expDate < today) {
            errLblCont.style.display = "";
            return;
        }

    }
    errLblCont.style.display = "none";
}

//***  Ensure only one checkbox is checked for class books or both

function uncheckOtherBooks(sender) {
    checkboxes = sender.parentNode.getElementsByTagName('input');
    if (checkboxes[1] === sender && checkboxes[1].checked) {
        checkboxes[2].checked = false;
        return;
       }
    if (checkboxes[2] === sender && checkboxes[2].checked) {
        checkboxes[1].checked = false;
       }
} 

//*** Ensure Date isnt lost on postback reload

function SetHiddenDate(sender, hiddenID) {
    var input = sender.parentNode.parentNode.getElementsByTagName("input")[1];
    if (sender.value != "" && sender.value != "__/__/____") {
        if (input != null) {
            input.value = sender.value;
        }
    }
}

function cancelBack() {
    if (navigator.appName == "Microsoft Internet Explorer"){
        if ((event.keyCode == 8 || (event.keyCode == 37 && event.altKey) ||  (event.keyCode == 39 && event.altKey))
            &&
           (event.srcElement.isTextEdit == false || (event.srcElement.isTextEdit == true && event.srcElement.readOnly == true))
          ) {
            event.cancelBubble = true;
            event.returnValue = false;
        }
    }
}

function createPayWizard(width, height, url) {
    var windParams = "width=" + width + ", height=" + height + ", resizable=yes, scrollbars=1";
    window.open(url, "UFAPaymentWizard", windParams);
}

function createPayReceipt(CCFieldsID, VerifyInvoiceID, multiple_allowed) {
    var passdata = new Array();
     var on_error = "";
    passdata[0]   = document.getElementById(CCFieldsID);
    passdata[1] = document.getElementById(VerifyInvoiceID);
    passdata[2] = multiple_allowed;
    var dialog_result = window.showModalDialog("PaymentReceipt.aspx", passdata, "dialogWidth: 980px; dialogheight: 800px; resizable:yes; status: yes; scroll: yes; unadorned: no;");
    if (dialog_result == "exit" || multiple_allowed == false) {
        window.close();
    }
    if (dialog_result == "next_payment") {
        window.resizeTo(1040, 800);
        self.resizeTo(1040, 800);
        document.getElementById("hidden_nextpaymentfirstpage").value = "true";
        document.getElementById("Button_Previous").click();
    } else {
        window.close();
    }
        
}


function onPaymentReceiptPageLoad() {
    if (document.getElementById('hidden_CCFieldSet').value != 'set') {
        document.getElementById('hidden_CCFields').value = window.dialogArguments[0].value;
        document.getElementById('hidden_Invoices').value = window.dialogArguments[1].value;
        document.getElementById('hidden_CCFieldSet').value = 'set';
        document.forms[0].submit();
    }
}


function clientValidationCheck(validationGroup, validationGroupOther, forOtherCheckBoxID) {
   var result = false;
    if (validationGroupOther != "" && document.getElementById(forOtherCheckBoxID).checked) {
            result = (Page_ClientValidate(validationGroup) && Page_ClientValidate(validationGroupOther));
        }
        else {
          result = Page_ClientValidate(validationGroup);
        }
    if (result) {
      window.resizeTo(1040, 1020);
      self.resizeTo(1040, 1020);
  }
  return result;
}

function CheckDuplicateInvoices(input_descriptionInvoiceID) {
    var invoiceDescriptions = new Array();
    var invoiceDescriptions = getElementsByClass(input_descriptionInvoiceID, document, "input");
    var hidden_NoDupInvoiceTag = document.getElementById("hidden_noduplicateINVOICEIDS");
    while (invoiceDescriptions.length > 1) {
       for(ind = 1; ind<invoiceDescriptions.length; ind ++){
           if (invoiceDescriptions[0].value == invoiceDescriptions[ind].value) {
               hidden_NoDupInvoiceTag.value = "false";
               return;
           }
           invoiceDescriptions.splice(0, 1);
       }
   }
   hidden_NoDupInvoiceTag.value = "true";
}

function getElementsByClass(searchClass, node, tag) {
    var classElements = new Array();
    if (node == null)
        node = document;
    if (tag == null)
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className)) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function getElementsByIDEndString(searchClass, node, tag) {
    var classElements = new Array();
    if (node == null)
        node = document;
    if (tag == null)
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s|^.*)" + searchClass + "($)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].id)) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function updateTotals() {
    var invoiceAmounts = getElementsByIDEndString("RadMaskedTextBox_AMT", document, "input");
    var totalLabel = document.getElementById("label_runningtotal");
    var runningTotal = 0;
 
 
 if(totalLabel != undefined && invoiceAmounts.length > 1){
            for( ind = 0; ind < invoiceAmounts.length; ind++)
            {
                runningTotal = runningTotal + parseFloat( invoiceAmounts[ind].value);
            }


            totalLabel.style.display = "";
            totalLabel.innerText = 'Total Invoice AMT: ' + formatCurrency(runningTotal);
            totalLabel.textContent = totalLabel.innerText;
    }
    else{
        totalLabel.style.display = "none";
        totalLabel.innerText = "$0.00";
    }
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' +
num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + '$' + num + '.' + cents);
}
//************(End credit card payments) Steven Packham stevecpk123@yahoo.com(Unified Fire Authority SLC)
