﻿jQuery("html").addClass("js");

jQuery.noConflict();

jQuery(function ($) {
    Engine = {
        fixes: {
        // JavaScript Fixes :P
    },
    ui: {
        bannercycle: function () {
            $('#banner').cycle({
                fx: 'fade',
                timeout: 8000,
                pause: true
                // choose your transition type, ex: fade, scrollUp, shuffle, etc...
                // See http://jquery.malsup.com/cycle/lite/ for features
            });
        },

        zebratable: function () {
                $("table.tablecolors tr:even").addClass("even");
                $("table.tablecolors tr:odd").addClass("odd"); //This is not required - you can avoid this if you have a table background
                $("table.tablecolors tr").hover(function () {
                    $(this).addClass("hovcolor");
                }, function () {
                    $(this).removeClass("hovcolor");
                });
                $("table.tablecolors tr").click(function () {
                    //$("table.tablecolors tr").removeClass("highlightcolor"); // Remove this line if you dont want to de-highlight the previously highlighted row
                    $(this).toggleClass("highlightcolor");
                });
        },

      bannercycle: function () {
          $('#banner').cycle({
              fx: 'fade',
              timeout: 8000,
              pause: true
              // choose your transition type, ex: fade, scrollUp, shuffle, etc...
              // See http://jquery.malsup.com/cycle/lite/ for features
          });
      },

 fancyboxLinkImages: function () {  

    if (document.getElementById('departmentImage1').src.toLowerCase().indexOf('.jpg') == -1 && document.getElementById('departmentImage1').src.indexOf('.gif') == -1) {
        $('#departmentImage1').parent().remove();
    } else {
        $('#departmentImage1').parent().css('display','inline');
    }
    if (document.getElementById('departmentImage2').src.toLowerCase().indexOf('.jpg') == -1 && document.getElementById('departmentImage2').src.indexOf('.gif') == -1) {
        $('#departmentImage2').parent().remove();       
    } else {
        $('#departmentImage2').parent().css('display','inline');
    }
    if (document.getElementById('departmentImage3').src.toLowerCase().indexOf('.jpg') == -1 && document.getElementById('departmentImage3').src.indexOf('.gif') == -1) {
        $('#departmentImage3').parent().remove();     
    } else {
        $('#departmentImage3').parent().css('display','inline');
    }
    if (document.getElementById('departmentImage4').src.toLowerCase().indexOf('.jpg') == -1 && document.getElementById('departmentImage4').src.indexOf('.gif') == -1) {
        $('#departmentImage4').parent().remove();      
    } else {
        $('#departmentImage4').parent().css('display','inline');
    }
    if (document.getElementById('departmentImage5').src.toLowerCase().indexOf('.jpg') == -1 && document.getElementById('departmentImage5').src.indexOf('.gif') == -1) {
        $('#departmentImage5').parent().remove();       
    } else {
        $('#departmentImage5').parent().css('display','inline');
    }

  $('a[rel=fancybox]').fancybox({
    'transitionIn'    : 'none',
    'transitionOut'    : 'none',
    'titlePosition'   : 'over',
    'titleFormat'    : function(title, currentArray, currentIndex, currentOpts) {
      return '<span id="fancybox-title-over">' + title + '</span>';
    }
  });


},

        print: function () {
            $("#print").html("<a href='#' title='Print (CTRL + P)'><span>Print</span></a>").click(function () { window.print(); return false; });
        }

    }
}
})

/*  On WINDOW loaded */
jQuery(window).load(function ($) {
    Engine.ui.bannercycle();
    Engine.ui.zebratable();
    Engine.ui.fancyboxLinkImages();
    Engine.ui.print();
});


/*  DW javascript */
function isRadioButtonChecked(theOption, theForm) {
    if (theForm.elements[theOption].checked) {
        return true;
    }
    else {
        for (i = 0; i < theForm.elements[theOption].length; i++) {
            if (theForm.elements[theOption][i].checked) {
                return true;
            }
        }
    }
    return false;
}

function validateEmail(email) {
    var regExp = /^[\w\-_]+(\.[\w\-_]+)*@[\w\-_]+(\.[\w\-_]+)*\.[a-z]{2,4}$/i;
    return regExp.test(email);
}
/* Extranet form login */
function checkform() {
    if (document.ExtUserForm.ForgotPassword.checked) {
        if ((document.ExtUserForm.ForgotPassword.checked) && (document.ExtUserForm.Username.value.length <= 0)) {
            alert('To recieve your password, please specify username.');
            document.ExtUserForm.Username.focus();
            return false;
        }
    }
    else {
        if (document.ExtUserForm.Username.value.length <= 0) {
            alert('Specify username');
            document.ExtUserForm.Username.focus();
            return false;
        }

        if (document.ExtUserForm.Password.value.length <= 0) {
            alert('Specify password');
            document.ExtUserForm.Password.focus();
            return false;
        }
    }

    return true;
}

function ToggleForgotPassword() {
    var uform = document.forms["ExtUserForm"];
    uform.elements["Password"].disabled = uform.elements["ForgotPassword"].checked;
    uform.elements["Username"].innerText = "E-mail address";
}
/* Create user extension */
function randomPassword(length) {
    chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    pass = "";
    for (x = 0; x < length; x++) {
        i = Math.floor(Math.random() * 62);
        pass += chars.charAt(i);
    }
    return pass;
}
function formSubmit() {
    document.UserManagementEditForm.UserManagement_Form_NewPassword.value = randomPassword(8);
    document.UserManagementEditForm.UserManagement_Form_NewPasswordConfirm.value = document.UserManagementEditForm.UserManagement_Form_NewPassword.value;
    document.UserManagementEditForm.UserManagement_Form_Fax.value = document.UserManagementEditForm.UserManagement_Form_NewPassword.value;
    document.UserManagementEditForm.UserManagement_Form_UserName.value = document.UserManagementEditForm.UserManagement_Form_Email.value;
    document.UserManagementEditForm.UserManagement_Form_Name.value = document.UserManagementEditForm.UserManagement_Form_Name1.value + " " + document.UserManagementEditForm.UserManagement_Form_Name2.value;
    if (document.UserManagementEditForm.iAmHCP.checked)
        document.UserManagementEditForm.submit();
    return false;
}

