
// CallWebServiceMethods.js

// This function calls the Web service method and 
// passes the event callback function.  
function GetPostcodeInformatieWebserviceForPostadres()
{
    var field = document.getElementById("ctl00_phMainContent_txtPostadresPostcode");
    
    Partnerdashboard.Services.PostcodeService.GetPostcodeInformatie(field.value,
      SucceededCallbackPostcodeInformatieForPostadres,FailedCallback,
        "XmlDocument");
}

function GetPostcodeInformatieWebserviceForBezoekadres()
{
    var field  = document.getElementById("ctl00_phMainContent_txtBezoekadresPostcode");
    Partnerdashboard.Services.PostcodeService.GetPostcodeInformatie(field.value,
      SucceededCallbackPostcodeInformatieForBezoekadres,FailedCallback,
        "XmlDocument");
}

function GetPostcodeInformatieWebserviceForVestiging()
{

    var field  = document.getElementById("ctl00_phMainContent_txtPostcode");
    Partnerdashboard.Services.PostcodeService.GetPostcodeInformatie(field.value,
      SucceededCallbackPostcodeInformatieForVestiging,FailedCallback,
        "XmlDocument");
}

var _htmltablecontainer = null;

function GetHandelsnamenBySearchString(strSearch, htmltablecontainer, bedrijfsnaam)
{
    _htmltablecontainer = htmltablecontainer; 
    Partnerdashboard.WebServices.AFMService.GetHandelsnamenBySearchString(strSearch, bedrijfsnaam, SuccessGetHandelsnamenBySearchString,FailedGetHandelsnamenBySearchString, "XmlDocument");
}

function SuccessGetHandelsnamenBySearchString(result, userContext, methodName)
{
    _htmltablecontainer.style.display = 'none';
    _htmltablecontainer.innerHTML = result;
    _htmltablecontainer.style.display = '';
}

function FailedGetHandelsnamenBySearchString(error)
{


}



// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallbackPostcodeInformatieForPostadres(result, userContext, methodName)
{
   
    // Page element to display feedback.
   var txtStraat = document.getElementById("ctl00_phMainContent_txtPostadresStraat");
   var txtPlaats = document.getElementById("ctl00_phMainContent_txtPostadresWoonplaats");
   
    if (userContext == "XmlDocument")
	{
	    
	    var straat = null;
	    var plaats = null;

	    // Firefox
	    if(   result.childNodes[0].childNodes[1] )
	    {
	        straat = result.childNodes[0].childNodes[1].textContent;
	        plaats = result.childNodes[0].childNodes[2].textContent;
	    }
	    // IE
	    else
	    {
	        straat = result.childNodes[1].childNodes[1].text;
	        plaats = result.childNodes[1].childNodes[2].text;
	    }

    	
        txtStraat.value = straat;
        txtPlaats.value = plaats;
	}

}

function SucceededCallbackPostcodeInformatieForBezoekadres(result, userContext, methodName)
{

    // Page element to display feedback.
   var txtStraat = document.getElementById("ctl00_phMainContent_txtBezoekadresStraat");
   var txtPlaats = document.getElementById("ctl00_phMainContent_txtBezoekadresWoonplaats");
   
    if (userContext == "XmlDocument")
	{
	
	    var straat = null;
	    var plaats = null;

	    // Firefox
	    if(   result.childNodes[0].childNodes[1] )
	    {
	        straat = result.childNodes[0].childNodes[1].textContent;
	        plaats = result.childNodes[0].childNodes[2].textContent;
	    }
	    // IE
	    else
	    {
	        straat = result.childNodes[1].childNodes[1].text;
	        plaats = result.childNodes[1].childNodes[2].text;
	    }

    	
        txtStraat.value = straat;
        txtPlaats.value = plaats;
	}

}

function SucceededCallbackPostcodeInformatieForVestiging(result, userContext, methodName)
{
    // Page element to display feedback.
   var txtStraat = document.getElementById("ctl00_phMainContent_txtStraat");
   var txtPlaats = document.getElementById("ctl00_phMainContent_txtWoonplaats");
   var txtPostcodeCheck = document.getElementById("ctl00_phMainContent_txtPostcodeCheck");
   
    if (userContext == "XmlDocument")
	{
	
	    var straat = null;
	    var plaats = null;
	    var postcode = null;

	    // Firefox
	    if(   result.childNodes[0].childNodes[1] )
	    {
	        postcode = result.childNodes[0].childNodes[0].textContent;
	        straat = result.childNodes[0].childNodes[1].textContent;
	        plaats = result.childNodes[0].childNodes[2].textContent;
	        
	    }
	    // IE
	    else
	    {
	        postcode = result.childNodes[1].childNodes[0].text;
	        straat = result.childNodes[1].childNodes[1].text;
	        plaats = result.childNodes[1].childNodes[2].text;
	    }

    	/* Mogen geen postbussen zijn!*/
    	if( straat != "Postbus" )
    	{	
            txtStraat.value = straat;
            txtPlaats.value = plaats;
            txtPostcodeCheck.value = postcode;
            txtPostcodeCheck.readonly = false;
        }
        else
        {
            FailedCallback("error");
        }
	}

}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error)
{

    var txtPostcodeCheck = document.getElementById("ctl00_phMainContent_txtPostcodeCheck");
    if( txtPostcodeCheck )
    {
        txtPostcodeCheck.value = "NULL";
        txtPostcodeCheck.readonly = true;
    }
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();