﻿var prevUserID = "";
var prevDomainID = ""
var prevSalesID=""
var prevTSID=""
function bindDatePicker(field) { 
    $(field).datepicker();
}

function bindPromotionCode() {

    $(".customerGroup").autocomplete("/newadmin/getInfo.aspx?type=customerGroup&domainName=" + $(".domain1").val());
}

function getPromotionCodeList(object, domainName) {

  
            $.ajax({
            url: "/newadmin/getinfo.aspx",
            data: "type=getPromotionCode&displayType=list&q=null&domainName=" + $(domainName).val(),
                async: false,
                cache: false,
                success: function(html) {
                        
                       $(object).html( html );
                }
            });
 
}
function chkCreditCard(ddlID)
{  
    var oDDL = document.getElementById(ddlID);
    var curText = oDDL.options[oDDL.selectedIndex].text;
    if (curText=='Credit Card')
    {
    document.getElementById('tr_CreditCard').style.display='block';
    }else{
    document.getElementById('tr_CreditCard').style.display='none';
    }
     
  
}

function getCustomerGroups(object, domainName) {

    $.ajax({
        url: "/newadmin/getinfo.aspx",
        data: "type=customerGroup&displayType=list&q=null&domainName=" + $(domainName).val(),
        async: false,
        cache: false,
        success: function(html) {

            $(object).html(html);
        }
    });
   
}

function doSpotlight() {

GetSpoltlightContent();
//TFC();
}
function GetSpoltlightContent()
{
 $.ajax({
        url: "quickinfo.aspx",
        data: "type=splotlight",        
        async: false,
        cache: false,
        success: function(html) {
            htmlSplit = html.split("|||~~|||")            
            $("#spotlightresults").html(htmlSplit[0]);
            $("#featuredresult").html(htmlSplit[1]);
            //alert(htmlSplit[2]);
            //document.getElementById('fadeshow2Script').innerHTML=htmlSplit[2];
            $("#fadeshow2Script").html(htmlSplit[2]);
        }
    });

}
function GetFullFeaturedArticle ()
{

 $.ajax({
        url: "quickinfo.aspx",
        data: "type=FeaturedArticle",        
        async: false,
        cache: false,
        success: function(html) {            
            $("#featuredresult").html(html);
        }
    });

}
function TFC()
{
 $.ajax({
        url: "quickinfo.aspx",
        data: "type=TFC",        
        async: false,
        cache: false,
        success: function(html) {
        
            
            $("#fadeshow2Script").html(html);
        }
    });



}
function searchPatient(type){

    
var txtMRN=$("#ctl00_ContentPlaceHolder1_txtMRN").val();
var txtLName=$("#ctl00_ContentPlaceHolder1_txtLName").val();
var txtFName=$("#ctl00_ContentPlaceHolder1_txtFName").val();
   $.ajax({
        url: "quickinfo.aspx",
        data: "type=" + type + "&txtMRN=" + txtMRN  + "&LName=" + txtLName + "&FName=" + txtFName,        
        async: false,
        cache: false,
        success: function(html) {                    
            $("#results").html(html);
        }
    });
}
function searchAccounts(type) {

    
    $.ajax({
        url: "/newadmin/quickinfo.aspx",
        data: "type=" + type + "&search=" + $("#search").val(),        
        async: false,
        cache: false,
        success: function(html) {
            
            $("#results").html(html);
        }
    });

}
function changeSecureRepPassword(userID) {
    $("#newPassword").val("");

    $('#dialog').dialog('option', 'title', "Set a new Password ")
    $('#dialog').dialog('option', 'buttons', { "Cancel": function() { $(this).dialog("close"); }, "Update": function() { setSecureRepNewPass(userID); $(this).dialog('close'); } });
    $("#dialog").dialog('open');
   
    $("#newPassword").focus();
}

function setSecureRepNewPass(userID) {

//if ($("#newPassword").val()=='')
//{
// $('pwdmsg').html('Please enter password.');
// $('pwdmsg').addClass("alertError");
// $('pwdmsg').show("slow")

//}




    $.ajax({
        url: "/newadmin/quickinfo.aspx",
        data: "type=saveSecureRepPassword&newPass=" + $("#newPassword").val() + "&userID=" + userID,
        async: false,
        cache: false,
        success: function(html) {
        htmlSplit = html.split("|")
       
         showAlertMessage(htmlSplit[0], "#" + userID, htmlSplit[1]);
          
        }
    });
    

}
function accountStatusConfirm(status,promCode,saleID,mess) {


    $('#dialog').dialog('option', 'title', "Warning !! ")
    $('#dialog').text(mess);
    $('#dialog').dialog('option', 'buttons', { "Cancel": function() { $(this).dialog("close"); }, "Continue": function() { accountStatusConfirmContinue(status,promCode,saleID);$(this).dialog('close');  } });
    $("#dialog").dialog('open');
   
 
}
function accountStatusConfirmContinue(status,promCode,saleID) {
   $.ajax({
        url: "/newadmin/modules/sales/sales.aspx",
        data: "type=accountStatus&status="+ status +"&promCode=" + promCode + "&saleID=" + saleID,
        async: false,
        cache: false,
        success: function(html) {
      // window.location.reload(true);
       window.location.href="/newadmin/modules/sales/sales.aspx?menuid=30";
       
        
          
        }
    });
    

}

function AccchangeSecureRepPassword(userID) {

    $("#newPassword").val("");

    $('#dialog').dialog('option', 'title', "Set a new Password ")
    $('#dialog').dialog('option', 'buttons', { "Cancel": function() { $(this).dialog("close"); }, "Update": function() { setSecureRepNewPass(userID); $(this).dialog('close'); } });
    $("#dialog").dialog('open');
   
    $("#newPassword").focus();
}

//function AccsetSecureRepNewPass(userID) {



//    $.ajax({
//        url: "/newadmin/modules/recipients/recipients.aspx",
//        data: "type=saveSecureRepPassword&newPass=" + $("#newPassword").val() + "&userID=" + userID,
//        async: false,
//        cache: false,
//        success: function(html) {
//        htmlSplit = html.split("|")
//       
//         showAlertMessage(htmlSplit[0], "#" + userID, htmlSplit[1]);
//          
//        }
//    });

//}
function changePassword(userID,id) {


    $("#newPassword").val("");
 
    $('#dialog').dialog('option', 'title', "Set a new Password ")
    $('#dialog').dialog('option', 'buttons', { "Cancel": function() { $(this).dialog("close"); }, "Update": function() { setNewPass(userID,id); $(this).dialog('close'); } });
    $("#dialog").dialog('open');
   
    $("#newPassword").focus();
}

function setNewPass(userID,id) {
  

    $.ajax({
        url: "/newadmin/quickinfo.aspx",
        data: "type=savePassword&newPass=" + $("#newPassword").val() + "&userID=" + userID,
        async: false,
        cache: false,
        success: function(html) {
        htmlSplit = html.split("|")
       
         showAlertMessage(htmlSplit[0], "#" + id, htmlSplit[1]);
          
        }
    });

}


function ViewTroubleshootuser(UserID)
{ 

   cancelEdit();
    prevTSID=UserID;
   
    data="type=editTroubleshootuser&userID=" + UserID ;
  
    
    $.ajax({
        url: "/newadmin/viewtroubleshootuser.aspx",
        data: data,
        async: false,
        cache: false,
        success: function(html) {

        $("#" + UserID).show()
        $("#" + UserID).html(html)
        
            bindPromotionCode()
        }
    });
}

function editRecord(userID) {
    cancelEdit()
    prevUserID=userID
    $.ajax({
        url: "/newadmin/editAccount.aspx",
        data: "type=editAccount&userID=" + userID,
        async: false,
        cache: false,
        success: function(html) {

        $("#" + userID).show()
        $("#" + userID).html(html)
        
            bindPromotionCode()
        }
    });
}

function cancelEdit() {


    if (prevUserID !="")
        $("#" + prevUserID).html("");
    if (prevDomainID != "")
        $("#" + prevDomainID).html("");
    if (prevSalesID!="")
        $("#" + prevSalesID).html("");
        if(prevTSID!="")
        $("#" + prevTSID).html("");
    
}

function updateRecord() {

    data = $("#" + prevUserID + " form").serialize();
    data = data.toString().replace(/__VIEWSTATE/i, "")
    

  
    
    $.ajax({
        url: "/newadmin/quickinfo.aspx",
        data: data + "&type=saveAccount&uID=" + prevUserID,
        async: false,
        cache: false,
        success: function(html) {
        htmlSplit = html.split("|")
         
         showAlertMessage(htmlSplit[0], "#" + prevUserID, htmlSplit[1]);
          
        }
    });
}
function confirmDelete(userID, username, domain) {
   
   
        $('#dialog1').text("You are about to delete an account permanently. All the messages will also be permanently deleted. Are you sure? ")
        $('#dialog1').dialog('option', 'title', "Delete the account?")
        $('#dialog1').dialog('option', 'buttons', { "Cancel": function() { $(this).dialog("close"); }, "Ok": function() { deleteAccount(userID, username, domain); $(this).dialog('close'); } });
        $("#dialog1").dialog('open');
        return false;


   
}


function deleteAccount(userID,username,domain) {
  


    $.ajax({
        url: "/newadmin/quickinfo.aspx",
        data: "type=deleteAccount&userID=" + userID + "&username=" + username + "&domainName="+ domain,
        async: false,
        cache: false,
        success: function(html) {
            htmlSplit = html.split("|")

            showAlertMessage(htmlSplit[0], "#" + userID, htmlSplit[1]);
            searchAccounts('accounts')
        }
    });
}


function editDomain(domainID) {
    cancelEdit()
    prevDomainID = domainID
    $.ajax({
        url: "/newadmin/editDomain.aspx",
        data: "type=editAccount&domainID=" + domainID,
        async: false,
        cache: false,
        success: function(html) {

        $("#" + domainID).show()
        $("#" + domainID).html(html)

          
        }
    });
}

function updateDomain() {
    data = $("#" + prevDomainID + " form").serialize();
    data = data.toString().replace(/__VIEWSTATE/i, "")


    
    $.ajax({
        url: "/newadmin/quickinfo.aspx",
        data: data + "&type=saveDomain&uID=" + prevDomainID,
        async: false,
        cache: false,
        success: function(html) {
            htmlSplit = html.split("|")

            showAlertMessage(htmlSplit[0], "#" + prevDomainID, htmlSplit[1]);

        }
    });
}

function confirmDeleteDomain(domainID, domain) {

    $('#dialog1').text("You are about to delete this domain. Domain and its users will be disabled in ME")
    $('#dialog1').dialog('option', 'title', "Delete the domain?")
    $('#dialog1').dialog('option', 'buttons', { "Cancel": function() { $(this).dialog("close"); }, "Ok": function() { deleteDomain(domainID, domain); $(this).dialog('close'); } });
    $("#dialog1").dialog('open');
    return false;

}


function deleteDomain(domainID, domain) {

    $.ajax({
        url: "/newadmin/quickinfo.aspx",
        data: "type=deleteDomain&domainID=" + domainID + "&domainName=" + domain,
        async: false,
        cache: false,
        success: function(html) {
            
            
            searchAccounts('domains')
        }
    });
}

function editSales(salesID) {

    cancelEdit()
    prevSalesID = salesID
    $.ajax({
        url: "/newadmin/editSales.aspx",
        data: "type=editAccount&salesID=" + salesID,
        async: false,
        cache: false,
        success: function(html) {

        $("#" + salesID).show()
        $("#" + salesID).html(html)


        }
    });
}

function saveSalesCode() {
    data = $("#" + prevSalesID + " form").serialize();
    data = data.toString().replace(/__VIEWSTATE/i, "")
    $.ajax({
        url: "/newadmin/quickinfo.aspx",
        data: data + "&type=saveSalesCode&uID=" + prevSalesID,
        async: false,
        cache: false,
        success: function(html) {
            htmlSplit = html.split("|")

            showAlertMessage(htmlSplit[0], "#" + prevSalesID, htmlSplit[1]);

        }
    });

}
function confirmDeleteSecureRecipient(recipientID)
{
 $('#dialog1').text("Are you sure to permanently delete this  recipient. ")
    $('#dialog1').dialog('option', 'title', "Delete the recipient?")
    $('#dialog1').dialog('option', 'buttons', { "Cancel": function() { $(this).dialog("close"); }, "Ok": function() { deleteSecureRecipient(recipientID); $(this).dialog('close'); } });
    $("#dialog1").dialog('open');
    return false;
}
function deleteSecureRecipient(recipientID)
{
$.ajax({
        url: "/newadmin/quickinfo.aspx",
        data: "type=deleteSecureRecipient&uID=" + recipientID,
        async: false,
        cache: false,
        success: function(html) {
          searchAccounts('securerecipients')
        }
    });


}
function confirmDeleteSales(salesID) {

    $('#dialog1').text("You are about to permanently delete this sales code. ")
    $('#dialog1').dialog('option', 'title', "Delete the sales code?")
    $('#dialog1').dialog('option', 'buttons', { "Cancel": function() { $(this).dialog("close"); }, "Ok": function() { deleteSales(salesID); $(this).dialog('close'); } });
    $("#dialog1").dialog('open');
    return false;

}

function deleteSales(salesID) 
{
 $.ajax({
        url: "/newadmin/quickinfo.aspx",
        data: "type=deleteSales&uID=" + salesID,
        async: false,
        cache: false,
        success: function(html) {
          searchAccounts('sales')
        }
    });

}
function showAlertMessage(type, object, message) {

    $(object).html(message);
    if (type == "success") {
        $(object).addClass("alertSuccess");
        setTimeout(function() { $(object).fadeOut("slow") }, 4000);
    }
    else
        $(object).addClass("alertError");
    $(object).show("slow")

}

function selectDeSelect(form)
    {
      var SelectAll = form.selectAll;
      for ( var i=0; i < form.elements.length; i++ )
         {
            var e = form.elements[i];
               if (SelectAll.checked)
              	{
                 	e.checked = true;
               	}
               else
               	{
                   	e.checked = false;
               	}
           }
    }
    
    
    function confirmCancelPage() {
   alert('ff');
   
        $('#dialog1').text("You are about to delete an account permanently. All the messages will also be permanently deleted. Are you sure? ")
        $('#dialog1').dialog('option', 'title', "Delete the account?")
       // $('#dialog1').dialog('option', 'buttons', { "Cancel": function() { $(this).dialog("close"); }, "Ok": window.location.href="frmPatientSearch.aspx"; $(this).dialog('close'); } });
        $("#dialog1").dialog('open');
        return false;


   
}
