﻿function OnRegistrationFormLoaded()
{

}

function ManageAdministrationBlock()
{

   $("#adminSection:visible").hide('slow');
   $("#adminSection:hidden").show('slow'); 
}

function ManageDAVBlock()
{
   $("#ArgeMemberTrue:visible").hide('slow');
   $("#ArgeMemberTrue:hidden").show('slow');      
}

function ManageWebAkteBlock()
{
   $("#IsWebAkteCustomerTrue:visible").hide('slow');
   $("#IsWebAkteCustomerTrue:hidden").show('slow');    
}

function RecommendationsLoaded(data)
{    
    if(data.ValidationSuccessful)
    {
         $("#validationSuccess").show('slow');
    }
    else
    {
        for(var i = 0; i < data.Data.length; i++)
        {
            $("#recommandationsList").append('<li><a href=\'#\' onclick=\'copySelectedIdentifierToTextBox("'+ data.Data[i] + '")\'>' + data.Data[i] +'</a><li>');
        }
        $("#recommandations").show('slow');
    }    
}

function CheckSchadenFixAIdentifierAvailability(schadenFixIdentifier, officeName, firstName, lastName)
{
    $("#recommandations:visible").hide();
    $("#validationSuccessful:visible").hide();

    $.getJSON(GetSchadenFixHost() + "Registration/CheckSchadenFixAIdentifierAvailabilityAsync",{ psSchadenFixIdentifier : schadenFixIdentifier, psOfficeName : officeName , psFirstName : firstName, psLastName : lastName}, RecommendationsLoaded);
}

function copySelectedIdentifierToTextBox(identifier)
{
    document.getElementById('Identifier').value = identifier;
    document.getElementById('IdentifierConfirmation').value = '';
}

function askWebAkteForUserData()
{
        $("#ajaxInfo:visible").hide();
        $("#ajaxInfo:hidden").show();

         $.ajax({ type: "POST",  
         url: GetSchadenFixHost() + "WebakteService/officeservice.asmx/GetKanzleiInfo",  
         dataType: "xml",  
         data: "psLogin=" + document.getElementById('WebAkteCustomerName').value + "&psPwd=" +document.getElementById('WebAkteCustomerPassword').value+ "&piCustsomerId=" +document.getElementById('WebAkteCustomerId').value,  
         processData: false,  
         error: function(XMLHttpRequest, textStatus, errorThrown) { ajaxError(XMLHttpRequest,textStatus, errorThrown); },  
         success: function(xml) { ajaxFinish(xml); }  
         }); 
}

function ajaxFinish(xml)  
{ 
             $("#ajaxInfo:hidden").show();
    $("#ajaxInfo:visible").hide();
         document.getElementById('FirstName').value = $("FirstName", xml).text();  
         document.getElementById('LastName').value = $("LastName", xml).text();  
         document.getElementById('OfficeName').value = $("OfficeName", xml).text();  
         document.getElementById('Street').value = $("Street", xml).text();  
         document.getElementById('PostalCode').value = $("PostalCode", xml).text();  
         document.getElementById('City').value = $("City", xml).text();  
         document.getElementById('Phone').value = $("Phone", xml).text(); 
         document.getElementById('Fax').value = $("Fax", xml).text(); 
         document.getElementById('EMail').value = $("EMail", xml).text();  
         
         submitRequestToVirtualEarth($("Street", xml).text(), $("PostalCode", xml).text(), $("City", xml).text())
         
}  
   
function ajaxError(xmlObj,textStatus,errorThrown)  
{ 
    alert("Fehler beim Abrufen der Daten. Bitte kontrollieren Sie Ihre Einstellungen und versuchen Sie es erneut");  
}

function GetWebAkteData(city, customer)
{
    $.ajax({ type: "POST",  
         url: GetSchadenFixHost() + city + "/" + customer + "/Admin/GetWebAkteAuthenticationData",  
         dataType: "json",  
         data: {},
         //data: "psLogin=" + document.getElementById('WebAkteCustomerName').value + "&psPwd=" +document.getElementById('WebAkteCustomerPassword').value+ "&piCustsomerId=" +document.getElementById('WebAkteCustomerId').value,  
         processData: true,  
         error: function(XMLHttpRequest, textStatus, errorThrown) { ajaxError(XMLHttpRequest,textStatus, errorThrown); },  
         success: function(webAkteData) { AuthenticateWebAkteUser(webAkteData); }  
         });
} 

function AuthenticateWebAkteUser(webAkteData)
{
        document.getElementById("iFrame").src = GetSecureHost() + "e.consult." + webAkteData.id + "/webakte/loadPage.asp?login=" + webAkteData.userName + "&pwd=" + webAkteData.pwd + "&kunden_nr=" + webAkteData.id +"&target=" + targetScript + "&city=" + webAkteData.city + "&customer=" + webAkteData.customer;

            //customerId = webAkteData.id;
       //$.ajax({ type: "POST",  
         //url: "https://secure.e-consult-ag.de/e.consult." + webAkteData.id +  "/webakte/login_fix.asp",
         //dataType: "text",  
         //data: "pwd=" + webAkteData.pwd + "&login=" + webAkteData.userName + "&kunden_nr=" + webAkteData.id,  
         //processData: false,  
         //error: function(XMLHttpRequest, textStatus, errorThrown) { ajaxError(XMLHttpRequest,textStatus, errorThrown); },  
         //success: function(result) { RedirectToWebAkte(result); }, 
         //async: false
         //}); 
}

function RedirectToWebAkte()
{
    document.getElementById("iFrame").src = GetSecureHost() + "e.consult." + customerId + "/webakte/" + targetScript;
}

