﻿// CallWebServiceMethods.js
// This function calls the Web service method and 
// passes the event callback function. 
var divForResultsId;
var imgForLoadingId;
var showResults;
var queueNumber = 0;
 
function SearchMarriages( isAPostBack, txtValue, txtPID, CurrentPage, SortOrder, divForResults, imgForLoading) 
{
    showResults = isAPostBack;
    divForResultsId = divForResults;
    imgForLoadingId = imgForLoading;
    queueNumber = queueNumber + 1;
    VitalRecords.VitalRecordsWS.GetMarriageResultsXML(queueNumber, txtValue, txtPID, CurrentPage, SortOrder,
    SucceededCallback);
    
}

function SearchMarriagesAdvanced( isAPostBack, hasSearchData, txtGL, txtGF, txtBL, txtBF, txtPID, txtMonth, txtYear, CurrentPage, SortOrder, divForResults, imgForLoading) 
{
    showResults = isAPostBack;
    divForResultsId = divForResults;
    imgForLoadingId = imgForLoading;
    queueNumber = queueNumber + 1;
    if ( hasSearchData ) {
        VitalRecords.VitalRecordsWS.GetMarriageResultsAdvancedXML(queueNumber, txtGL, txtGF, txtBL, txtBF, txtPID, txtMonth, txtYear, CurrentPage, SortOrder,
        SucceededCallback);   
    } else {
        var RsltElem = document.getElementById(divForResultsId);
        if ( RsltElem != null ) {
            RsltElem.innerHTML = ''; 
        }
        
        var ctlImgForLoading = document.getElementById( imgForLoadingId );
        if ( ctlImgForLoading != null ) {
            ctlImgForLoading.style.display = 'none';
        }
    }
}

function SearchBirths( isAPostBack, txtValue, txtPID, CurrentPage, SortOrder, divForResults, imgForLoading) 
{
    showResults = isAPostBack;
    divForResultsId = divForResults;
    imgForLoadingId = imgForLoading;
    queueNumber = queueNumber + 1;
    VitalRecords.VitalRecordsWS.GetBirthResultsXML(queueNumber, txtValue, txtPID, CurrentPage, SortOrder,
    SucceededCallback);
    
}

function SearchBirthsAdvanced( isAPostBack, hasSearchData, txtL, txtF, txtML, txtMF, txtFL, txtFF, txtPID, txtMonth, txtDay, txtYear, CurrentPage, SortOrder, divForResults, imgForLoading) 
{
    showResults = isAPostBack;
    divForResultsId = divForResults;
    imgForLoadingId = imgForLoading;
    queueNumber = queueNumber + 1;
    if ( hasSearchData ) {
        VitalRecords.VitalRecordsWS.GetBirthResultsAdvancedXML(queueNumber, txtL, txtF, txtML, txtMF, txtFL, txtFF, txtPID, txtMonth, txtDay, txtYear, CurrentPage, SortOrder,
        SucceededCallback);   
    } else {
        var RsltElem = document.getElementById(divForResultsId);
        if ( RsltElem != null ) {
            RsltElem.innerHTML = ''; 
        }
        
        var ctlImgForLoading = document.getElementById( imgForLoadingId );
        if ( ctlImgForLoading != null ) {
            ctlImgForLoading.style.display = 'none';
        }
    }
}

function SearchDeaths( isAPostBack, txtValue, txtPID, CurrentPage, SortOrder, divForResults, imgForLoading) 
{
    showResults = isAPostBack;
    divForResultsId = divForResults;
    imgForLoadingId = imgForLoading;
    queueNumber = queueNumber + 1;
    VitalRecords.VitalRecordsWS.GetDeathResultsXML(queueNumber, txtValue, txtPID, CurrentPage, SortOrder,
    SucceededCallback);
}

function SearchDeathsAdvanced( isAPostBack, hasSearchData, txtL, txtF, txtPID, txtAge, txtMonth, txtDay, txtYear, CurrentPage, SortOrder, divForResults, imgForLoading) 
{
    showResults = isAPostBack;
    divForResultsId = divForResults;
    imgForLoadingId = imgForLoading;
    queueNumber = queueNumber + 1;
    if ( hasSearchData ) {
        VitalRecords.VitalRecordsWS.GetDeathResultsAdvancedXML(queueNumber, txtL, txtF, txtPID, txtAge, txtMonth, txtDay, txtYear, CurrentPage, SortOrder,
        SucceededCallback);  
    } else {
        var RsltElem = document.getElementById(divForResultsId);
        if ( RsltElem != null ) {
            RsltElem.innerHTML = ''; 
        }
        
        var ctlImgForLoading = document.getElementById( imgForLoadingId );
        if ( ctlImgForLoading != null ) {
            ctlImgForLoading.style.display = 'none';
        }
    }    
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the 
// calling method name as parameters.
function SucceededCallbackWithContext(result, userContext, methodName)
{
    var output;
    
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");
    
    var readResult;
    if (userContext == "XmlDocument")
	{
	
	    if (document.all) 
	        readResult = 
		        result.documentElement.firstChild.text;
		else
		    // Firefox
		   readResult =
		        result.documentElement.firstChild.textContent;
		
	     RsltElem.innerHTML = "XmlDocument content: " + readResult;
	}
    
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs)
{   
    if ( showResults && ( queueNumber.toString() == result.substring( 0, queueNumber.toString().length ) ) ) {
        if ( showResultsToUser != null ) {
            showResultsToUser( divForResultsId, result.substring( queueNumber.toString().length, result.length ), imgForLoadingId );
            return;
        } else {
            // Page element to display feedback.
            var RsltElem = document.getElementById( divForResultsId );
            RsltElem.style.display = '';
            RsltElem.innerHTML = result.substring( queueNumber.toString().length, result.length );  
        }
    }

    var ctlImgForLoading = document.getElementById( imgForLoadingId );
    if ( ctlImgForLoading != null ) {
        ctlImgForLoading.style.display = 'none';
    }
}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error)
{
    // Display the error.    
    var RsltElem = 
        document.getElementById(divForResultsId);
    RsltElem.innerHTML = 
    "Service Error: " + error.get_message();
    
    var ctlImgForLoading = document.getElementById( imgForLoadingId );
    if ( ctlImgForLoading != null ) {
        ctlImgForLoading.style.display = 'none';
    }
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();