﻿// common javascript functions

//the name of the form the user is current 'in'
//possible values: Search, ViewByCustomer, AddToOrder, FilterList ...
var ActiveForm = '';

//the id of the active form element (sometimes needed when submitting the active form)
var ActiveObjId = '';

//sets the name of the currently active form
function setActiveForm(formName, objId){
    ActiveForm = formName;
    ActiveObjId = objId;
    //alert(ActiveForm);
}

//determines which js function to call prior to submitting the form
function submitActiveForm(){
    //alert(ActiveForm);
    if (ActiveForm == 'Search'){
        return search();
    } else if (ActiveForm == 'OrderForm'){
        return updateOrder();
    } else if (ActiveForm == 'AddToOrder'){
        arg = ActiveObjId.substr(7,ActiveObjId.length-7);
        return addToOrder(arg);
    } else if (ActiveForm == 'QuickAddToOrder'){
        return quickOrder();
    }
    else if (ActiveForm == 'ViewByCustomer'){
        arg = document.getElementById('txtCustomerLookup').value;
        return setCustomer(arg);
    }
    else if (ActiveForm == 'LoginUser'){
        return loginUser();
    }
    else if (ActiveForm == 'LostPassword'){
        return lostPassword();
    }
    else if (ActiveForm == 'EditUser'){
        return editUser();
    }
    
    return true;
}

//opens the customer service email popup
function customerServicePopup()
{
    var winCustSvc = window.open('EmailPopup.aspx', 'winCustSvc', 'address=no,status=no,resizable=yes,scrollbars=auto,width=550,height=475');
    winCustSvc.focus();
}

//opens the address change request popup
function addressChangePopup(acct)
{
    var winAddrChg = window.open('AddressChange.aspx?acct='+acct, 'winAddrChg', 'address=no,status=no,resizable=yes,scrollbars=auto,width=550,height=600');
    winAddrChg.focus();
}


//current items list
function currentItemsList()
{
    var winCurrItems = window.open('CurrentItemsList.aspx', 'winCurrItems', 'address=no,status=no,resizable=no,scrollbars=no,width=700,height=680');
    winCurrItems.focus();
}

//Warranty
function warranty()
{
    var winWarranty = window.open('Warranty.aspx', 'winWarranty', 'address=no,status=no,resizable=no,scrollbars=no,width=700,height=680');
    winWarranty.focus();
}

//customer service - support territories
function supportTerritories()
{
    var winSuppTerr = window.open('SupportTerritories.aspx', 'winSuppTerr', 'address=no,status=no,resizable=no,scrollbars=yes,width=700,height=680');
    winSuppTerr.focus();
}

//Multi-Channel User
function multiChannelUser()
{
    var winMultiChannelUser = window.open('MultiChannelUser.aspx', 'winMultiChannelUser', 'address=no,status=no,resizable=no,scrollbars=no,width=540,height=580');
    winCurrItems.focus();
}

//Items by customer
function itemHistory()
{
    var winItemHistory = window.open('CustomerItemHistory.aspx', 'winItemHistory', 'address=no,status=no,resizable=no,scrollbars=no,width=600,height=680');
    winItemHistory.focus();
}

//PowellPRO login
function powellPROLogin()
{
    var winPowellPROLogin = window.open('PowellPROLogin.aspx', 'winPowellPROLogin', 'address=no,status=no,resizable=no,scrollbars=no,width=460,height=480');
    winPowellPROLogin.focus();
}

//Item Availability Report for CSR
function itemAvailability()
{
    var winItemAvail = window.open('ItemAvailabilityPopup.aspx', 'winItemAvail', 'address=no,status=no,resizable=no,scrollbars=yes,width=700,height=700');
    winSuppTerr.focus();
}
