/*=====================================================================
 Filename: sbc_utils.js -- Written by ndelmedico@waca.com
 Created: 5/17/2004 -- Last Updated: 5/26/2004
 This file contains client-side functions for Sprint PCM website
======================================================================*/

/*=====================================================================
Description: Enables/Disables equipment registration form elements
======================================================================*/
function spcEnable(oBox, iItem) {
    var oForm = document.aspnetForm;
    var oItem; var oMake; var oModel; var oSerial;
    switch(iItem) {
        case 1:
            oItem = oForm.selCompType; oMake = oForm.txtCompMake;
            oModel = oForm.txtCompMod; oSerial = oForm.txtCompSer;
            break;
        case 2:
            oMake = oForm.selModemMake; oModel = oForm.txtModemMod;
            oSerial = oForm.txtModemSer;
            break;
        case 3:
            oMake = oForm.selRouterMake; oModel = oForm.txtRouterMod;
            oSerial = oForm.txtRouterSer;
            break;
    }
    if (oBox.checked) {
        if (oItem) {oItem.disabled = false;}
        oMake.disabled = false; oModel.disabled = false; oSerial.disabled = false;
    } else {
        if (oItem) {oItem.disabled = true;}
        oMake.disabled = true; oModel.disabled = true; oSerial.disabled = true;
    }
}

/*=====================================================================
Description: Validates and submits equipment registration form
======================================================================*/
function spcCheckEquip() {
    var oForm = document.aspnetForm; var sErrors = ""; var bSubmit = false;
    if (oForm.chkRegComp) {
        if (oForm.chkRegComp.checked) {
            bSubmit = true;
            if (oForm.selCompType.options[oForm.selCompType.options.selectedIndex].value == "") {sErrors += "\n-  Please select a Computer Type to continue.";}
            if (Trim(oForm.txtCompMake.value) == "") {sErrors += "\n-  Please enter a Computer Make to continue.";}
            if (!isValidChar(oForm.txtCompMake.value, sAlpha + sNumeric)) {sErrors += "\n-  The Computer Make entered contains invalid characters.";}
            if (Trim(oForm.txtCompMod.value) != "") {
                if (!isValidChar(oForm.txtCompMod.value, sAlpha + sNumeric)) {sErrors += "\n-  The Computer Model entered contains invalid characters.";}
            }
            if (Trim(oForm.txtCompSer.value) == "") {sErrors += "\n-  Please enter your Computer's Serial Number to continue.";}
            if (!isValidChar(oForm.txtCompSer.value, sAlpha + sNumeric)) {sErrors += "\n-  The Computer Serial entered contains invalid characters.";}
        }
    }
    if (oForm.chkRegModem) {
        if (oForm.chkRegModem.checked) {
            bSubmit = true;
            if (oForm.selModemMake.options[oForm.selModemMake.options.selectedIndex].value == "") {sErrors += "\n-  Please select a Modem Make to continue.";}
            if (Trim(oForm.txtModemMod.value) != "") {
                if (!isValidChar(oForm.txtModemMod.value, sAlpha + sNumeric)) {sErrors += "\n-  The Modem Model entered contains invalid characters.";}
            }
            if (Trim(oForm.txtModemSer.value) == "") {sErrors += "\n-  Please enter your Modem's Serial Number to continue.";}
            if (!isValidChar(oForm.txtModemSer.value, sAlpha + sNumeric)) {sErrors += "\n-  The Modem Serial entered contains invalid characters.";}
        }
    }
    if (oForm.chkRegRouter) {
        if (oForm.chkRegRouter.checked) {
            bSubmit = true;
            if (oForm.selRouterMake.options[oForm.selRouterMake.options.selectedIndex].value == "") {sErrors += "\n-  Please select a Router Make to continue.";}
            if (Trim(oForm.txtRouterMod.value) != "") {
                if (!isValidChar(oForm.txtRouterMod.value, sAlpha + sNumeric)) {sErrors += "\n-  The Router Model entered contains invalid characters.";}
            }
            if (Trim(oForm.txtRouterSer.value) == "") {sErrors += "\n-  Please enter your Router's Serial Number to continue.";}
            if (!isValidChar(oForm.txtRouterSer.value, sAlpha + sNumeric)) {sErrors += "\n-  The Router Serial entered contains invalid characters.";}
        }
    }
    if (sErrors != "") {displayError(sErrors); return false;}
    else if (bSubmit) {return true;}
    else {alert("You must register at least one piece of equipment before submitting."); return false;}
}

/*=====================================================================
Description: Validates and submits equipment transfer form
======================================================================*/
function spcCheckTransfer() {
    var oForm = document.aspnetForm; var sErrors = "";
    if (oForm.selCompType.options[oForm.selCompType.options.selectedIndex].value == "") {sErrors += "\n-  Please select a Computer Type to continue.";}
    if (Trim(oForm.txtCompMake.value) == "") {sErrors += "\n-  Please enter a Computer Make to continue.";}
    if (!isValidChar(oForm.txtCompMake.value, sAlpha + sNumeric)) {sErrors += "\n-  The Computer Make entered contains invalid characters.";}
    if (Trim(oForm.txtCompMod.value) != "") {
        if (!isValidChar(oForm.txtCompMod.value, sAlpha + sNumeric)) {sErrors += "\n-  The Computer Model entered contains invalid characters.";}
    }
    if (Trim(oForm.txtCompSer.value) == "") {sErrors += "\n-  Please enter your Computer's Serial Number to continue.";}
    if (!isValidChar(oForm.txtCompSer.value, sAlpha + sNumeric)) {sErrors += "\n-  The Computer Serial entered contains invalid characters.";}
    if (sErrors != "") {displayError(sErrors); return false;}
    else {return true;}
}

/*=====================================================================
Description: Validates claim item selection form
======================================================================*/
function spcClaimSelect() {
    var oForm = document.aspnetForm; var sErrors = "";
    var bChecked = false; var bEligible = false;
    if (oForm.radClaimItem.length) {
        for (var i = 0; i < oForm.radClaimItem.length; i++) {
            if (oForm.radClaimItem[i].checked) {bChecked = true;}
            if (!oForm.radClaimItem[i].disabled) {bEligible = true;}
        }
    } else {
        if (oForm.radClaimItem.checked) {bChecked = true;}
        if (!oForm.radClaimItem.disabled) {bEligible = true;}
    }
    if (!bEligible) {alert("Your equipment has been registered for less than 30 days and is not eligible for claims at this time."); return false;}
    if (!bChecked) {displayError("\n-  Please select a piece of equipment to continue."); return false;}
    return true;
}

/*=====================================================================
Description: Validates and submits claim submission form
======================================================================*/
function spcValidateClaim() {
    var oForm = document.aspnetForm; var sErrors = "";
    if (oForm.selTime.options[oForm.selTime.options.selectedIndex].value == "") {sErrors += "\n-  Please select the best time to reach you.";}
    if (!isPhone(oForm.txtPhone.value)) {sErrors += "\n-  Please enter a contact phone number.";}
    if (!isEmail(oForm.txtEmail.value)) {sErrors += "\n-  Please enter a valid contact email address.";}
    if (Trim(oForm.txtReason.value).length < 10) {sErrors += "\n-  Please enter a description of the problem with your equipment.";}
    if (sErrors != "") {displayError(sErrors); return false;}
    else {return true;}
}

/*=====================================================================
Description: Change install frame location to embedded install object
======================================================================*/
function spcDownload(sProgramName) {
    var oFrame = document.getElementById == null ? document.getElementById("pcmframe") : window.frames["pcmframe"];
    if (spcBrowserCheck(sProgramName)) {
        if (confirm("In order to install " + sProgramName + ", you will need the Warranty ID Number located on this page. Click 'OK' to continue with the install or click 'Cancel' to exit and write down your Warranty ID Number. You may then then click the 'Install Now' button again when you are ready.")) {
            oFrame.location.replace("/cbell/dll/spc_dla.asp");
        }
    }
}

/*=====================================================================
Description: Checks user agent prior to PC Maintenance download
======================================================================*/
function spcBrowserCheck(sProgramName) {
    var bValidAgent = false; var sBrowser = navigator.appName;
    if (sBrowser == "Microsoft Internet Explorer") {
        var sAgentString = navigator.userAgent;
        if (sAgentString.indexOf("Opera") == -1) {bValidAgent = true;}
    }
    if (!bValidAgent) {
        alert("In order to install " + sProgramName + ", you need Microsoft Internet Explorer 5 or higher installed " +
              "on your machine. If you need to download the software, click OK when prompted and you " +
              "will be directed to Microsoft's download site. If the software is already installed on your " +
              "machine, click Cancel at the next prompt and then return to this page using Internet Explorer.");
        if (confirm("Would you like to download Microsoft Internet Explorer now?")) {this.open("http://www.microsoft.com/ie/", "winDownload", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,width=760,height=560");}
        return false;
    } else {
        return true;
    }
}

/*=====================================================================
Description: Validates and submits support request form
======================================================================*/
function spcSupport() {
    var oForm = document.aspnetForm; var sErrors = "";
    if (Trim(oForm.txtName.value) == "" || Trim(oForm.txtName.value).indexOf(" ") == -1) {sErrors += "\n-  Please enter your full name.";}
    if (!isPhone(oForm.txtPhone.value)) {sErrors += "\n-  Please enter a contact phone number.";}
    if (!isEmail(oForm.txtEmail.value)) {sErrors += "\n-  Please enter a valid contact email address.";}
    if (Trim(oForm.txtReason.value).length < 10) {sErrors += "\n-  Please enter a description of the problem you are having.";}
    if (sErrors != "") {displayError(sErrors); return false;}
    else {return true;}
}