﻿function GetHtmlElement(idvalue)
{
    var obj;
    for (i=0; i < document.forms['aspnetForm'].elements.length; i++)
    {
        obj = document.forms['aspnetForm'].elements[i];
        if (obj.id.indexOf(idvalue) > -1)
            return obj;
    }
    return null;
}

function showEmailDialog(userID)
{
    ManageCustomerService.GetUserInformation(userID, ShowEmailDialogStep2, ServiceCall_onTimeout, ServiceCall_onError);
}

function ShowEmailDialogStep2(arg)
{
    var userInformation = arg; 
    
    var labelEmailUserName = GetElementByName('LabelEmailUserName2');
    if( labelEmailUserName )
        labelEmailUserName.innerHTML = userInformation;    
        
    var txtEmailAddress = GetElementByName('txtEmailAddress');
    if( txtEmailAddress )
        txtEmailAddress.value = userInformation;    

    var txtMessage = GetElementByName('txtMessage');
    if( txtMessage )
        txtMessage.value = userInformation;    
        
    var emailConfirmPopupExtender = $find('EmailConfirmPopupExtender');
    if( emailConfirmPopupExtender )
        emailConfirmPopupExtender.show();
        
}

function ServiceCall_onTimeout(arg)
{
    alert('Timeout encountered retrieving user information. Please wait a moment and try again or contact support if you continue to receive this message.');
}

function ServiceCall_onError(arg)
{
    alert('Error encountered retrieving user information. Please wait a moment and try again or contact support if you continue to receive this message.');
}

function onEmailConfirmButton()
{
    var emailAddress = '';
    var txtEmailAddress = GetElementByName('txtEmailAddress');
    if( txtEmailAddress )
        emailAddress = txtEmailAddress.value;    

    var message = '';
    var txtMessage = GetElementByName('txtMessage');
    if( txtMessage )
        message = txtMessage.value;    

    ManageCustomerService.SendEmailNotification(emailAddress, message, emailSuccessful, email_onTimeout, email_onError);
}

function emailSuccessful(arg)
{
    alert('Email was sent successfully');
}

function email_onTimeout(arg)
{
    alert('Timeout encountered sending email notification. Please wait a moment and try again or contact support if you continue to receive this message.');
}

function email_onError(arg)
{
    alert('Error encountered sending email notification. Please wait a moment, double check the email address, and try again or contact support if you continue to receive this message.');
}


function ShowPasswordHelpDialog()
{
        
    var passwordHelpPopupExtender = $find('PasswordHelpPopupExtender');
    if( passwordHelpPopupExtender )
        passwordHelpPopupExtender.show();
        
}

function onPasswordHelpEmailConfirmButton()
{
    var emailAddress = '';
    var txtEmailAddress = GetElementByName('txtEmailAddress');
    if( txtEmailAddress )
        emailAddress = txtEmailAddress.value;    

    var message = '';
    var txtMessage = GetElementByName('txtMessage');
    if( txtMessage )
        message = txtMessage.value;    

    var userName = '';
    var txtUserName = GetElementByName('txtUserName2');
    if( txtUserName )
        userName = txtUserName.value;    

    var companyName = '';
    var company = GetElementByName('txtCompany1');
    if( company )
        companyName = company.value;    
        
    var phoneNumber = '';
    var txtPhoneNumber = GetElementByName('txtPhoneNumber');
    if( txtPhoneNumber )
        phoneNumber = txtPhoneNumber.value;    
        
    ManageCustomerService.SendPasswordHelpRequestEmail(emailAddress, phoneNumber, userName, companyName, message, emailSuccessful, email_onTimeout, email_onError);
}

function ShowRequestAccountDialog()
{
        
    var requestAccountPopupExtender = $find('RequestAccountPopupExtender');
    if( requestAccountPopupExtender )
        requestAccountPopupExtender.show();
}

function onRequestInformationConfirmButton()
{
    var emailAddress = '';
    var txtEmailAddress = GetElementByName('txtRequestAccountEmail');
    if( txtEmailAddress )
        emailAddress = txtEmailAddress.value;    

    var message = '';
    var txtMessage = GetElementByName('txtRequestAccountAdditionalComments');
    if( txtMessage )
        message = txtMessage.value;    

    var userName = '';
    var txtUserName = GetElementByName('txtRequestAccountName');
    if( txtUserName )
        userName = txtUserName.value;
        
    var companyName = '';
    var company = GetElementByName('txtCompany2');
    if( company )
        companyName = company.value;    

    var fmbAdmin = '';
    var txtFMBAdmin = GetElementByName('txtFMBAdministrator');
    if( txtFMBAdmin )
        fmbAdmin = txtFMBAdmin.value;    
        

    var phoneNumber = '';
    var txtPhoneNumber = GetElementByName('txtRequestAccountPhone');
    if( txtPhoneNumber )
        phoneNumber = txtPhoneNumber.value;    
        
    ManageCustomerService.SendAccountRequestEmail(emailAddress, phoneNumber, userName, companyName, fmbAdmin, message, emailSuccessful, email_onTimeout, email_onError);
}