﻿///////////////////////////////////////////////////////////////////////////////////////
// 2011 Bay Dynamics, inc
// Javascript Functions
// mls 2011
///////////////////////////////////////////////////////////////////////////////////////

var pMenu1State = 0;

function ImgMouseOverOut(obj, state) {

    if (obj.id == "img" + thePage)
        return;

    var theImage = document.getElementById(obj.id); /// <reference path="BDStyleSheet.css" />

    theImage.src = (state == 0) ? theImage.src.replace("Inactive", "Over") : theImage.src.replace("Over", "Inactive");
}

function DoDownloadFile(fileID) {
    var sUrl = "/Filedownload.aspx?UserId=Download&Function=ProductFiles&FileId=" + fileID;
    var bdFileDownloadWin = window.open(sUrl, "bdFileDownloadWindow", "location=1,status=1,scrollbars=1,  width=300,height=300");
    //   bdFileDownloadWin.mo(0, 0);
}

function DoDownloadIncidentFile(fileId) {
    window.open("/FileDownload.aspx?FileId=" + fileId + "&Function=IncidentFiles", "dlWin", "height=10,width=10", false);
}

// this is a very rudimentary Expand Contract function for our left hand links stuff
// (or anything that needs a Expan / Collapse effect)
function ExpandContractMenu(obj) {
    var theMenu = document.getElementById(obj);
    var theMenuIcon = document.getElementById(obj + "Icon")

    theMenuIcon.src = theMenu.style.visibility == "collapse" ? "/Images/buttonCollapse.png" : "/Images/buttonExpand.png";
    theMenu.style.visibility = theMenu.style.visibility == "collapse" ? "visible" : "collapse";
}

// JS for the RegistrationPage
function btnSubmitRequest() {

    // Quick Data Validation
    var sErrors = "";

    var formElement = document.getElementById("bdContent_txtFirstName");
    sErrors += formElement.value == "" ? "First Name is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtLastName");
    sErrors += formElement.value == "" ? "Last Name is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtCompanyName"); //ctl00_cphContent
    sErrors += formElement.value == "" ? "Company Name is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtEmailAddress");
    sErrors += formElement.value == "" ? "Email Address is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtPhone");
    sErrors += formElement.value == "" ? "Phone is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtAddress1");
    sErrors += formElement.value == "" ? "Address is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtCity");
    sErrors += formElement.value == "" ? "City is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtState");
    sErrors += formElement.value == "" ? "State is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtCountry");
    sErrors += formElement.value == "" ? "Country is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtZip");
    sErrors += formElement.value == "" ? "Postal Code is Required \r\n" : "";

    // regex fixed to allow somename@somedomain.somesubdomain.again (john.doe@johndoe.com.br)
    formElement = document.getElementById("bdContent_txtEmailAddress");
    if (formElement.value != "") {
        var regexEmailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
        sErrors += (!regexEmailPattern.test(formElement.value)) ? "Email Address appears to be invalid\r\n" : "";

    } 

    if (sErrors != "") {
        sErrors = "Please correct the following errors in order to continue:\r\n\r\n" + sErrors;
        alert(sErrors);
        return;
    }

    __doPostBack();

}

// JS for the RegistrationPage
function btnSubmitRequestLite() {

    // Quick Data Validation
    var sErrors = "";

    var formElement = document.getElementById("bdContent_txtFirstName");
    sErrors += formElement.value == "" ? "First Name is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtLastName");
    sErrors += formElement.value == "" ? "Last Name is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtCompanyName"); //ctl00_cphContent
    sErrors += formElement.value == "" ? "Company Name is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtEmailAddress");
    sErrors += formElement.value == "" ? "Email Address is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtPhone");
    sErrors += formElement.value == "" ? "Phone is Required \r\n" : "";
    formElement = document.getElementById("bdContent_txtAddress1");
    

    // regex fixed to allow somename@somedomain.somesubdomain.again (john.doe@johndoe.com.br)
    formElement = document.getElementById("bdContent_txtEmailAddress");
    if (formElement.value != "") {
        var regexEmailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        sErrors += (!regexEmailPattern.test(formElement.value)) ? "Email Address appears to be invalid\r\n" : "";

    }

    if (sErrors != "") {
        sErrors = "Please correct the following errors in order to continue:\r\n\r\n" + sErrors;
        alert(sErrors);
        return;
    }

    __doPostBack();

}

// Another stab ar x-browser hide collapse
function ShowAccountDiv(obj) {

    return;
    var div1 = document.getElementById("divAccount1");
    var div2 = document.getElementById("divAccount2");
    var div3 = document.getElementById("divAccount3");

    div1.style.visibility = "hidden";
    div1.style.height = "0";

    div2.style.visibility = "hidden";
    div2.style.height = "0";

    div3.style.visibility = "hidden";
    div3.style.height = "0";

    var theDiv = document.getElementById(obj);
    theDiv.style.visibility = "visible";
    //theDiv.style.height = "100";
}

// javascript for Support Agreement
//bdContent_ctrlRegistration_btnContinue
function EnableDisableSupportAgreementButton() {

    var theCheckbox = document.getElementById("chkAgree");
    var theButton = document.getElementById("bdContent_ctrlRegistration_btnContinue");

    //alert(theCheckbox.checked ? "Checked" : "Not Checked");
    theButton.disabled = theCheckbox.checked ? false : true;
}
