/*
 * Copyright (c) 2010 World Vision Canada. All Rights Reserved.
 *
 * THIS INFORMATION IS CONFIDENTIAL.
 *
 * NOTICE: This material is confidential and proprietary information of World Vision Canada
 * which may not be reproduced, used, sold, or transferred to any third party without the 
 * prior written consent of World Vision Canada.
 *
 */
 
var WVCSponsorWidget = {
    ServiceURL: 'http://spwidget.worldvision.ca/sponsorshipWidget/service.svc/',
    SponsorshipURL: 'http://children.worldvision.ca/sponsorship/Forms/Child.aspx',
    mc: 2222,
    noc: 1,
    lang: 'en'
}

$.extend({
  wvcSWSearch : function(parameter, callbackFnk){
    if(parameter == null) {
        parameter = "noc=" + WVCSponsorWidget.noc + "&lang=" + WVCSponsorWidget.lang;
    }
    $.ajax(
			{
				url: WVCSponsorWidget.ServiceURL + 'search',
				data: parameter,
				dataType: "jsonp",
				cache: false,
				success: function(response) {
					callbackFnk.call(this, response.SearchResult);
				}
			});  
  }
});


$.extend({
  wvcSWNext : function(parameter, callbackFnk){
    if(parameter == null) {
        parameter = "noc=" + WVCSponsorWidget.noc + "&lang=" + WVCSponsorWidget.lang;
    }
    $.ajax(
			{
				url: WVCSponsorWidget.ServiceURL + 'next',
				data: parameter,
				dataType: "jsonp",
				cache: false,
				success: function(response) {
					callbackFnk.call(this, response.NextResult);
				}
			});  
  }
});

$.extend({
  wvcSWPrevious : function(parameter, callbackFnk){
    if(parameter == null) {
        parameter = "noc=" + WVCSponsorWidget.noc + "&lang=" + WVCSponsorWidget.lang;
    }
    $.ajax(
			{
				url: WVCSponsorWidget.ServiceURL + 'previous',
				data: parameter,
				dataType: "jsonp",
				cache: false,
				success: function(response) {
					callbackFnk.call(this, response.PreviousResult);
				}
			});  
  }
});
 


function wvcSWGetCountriesList(dropdownList) {
		$.ajax(
			{
				url: WVCSponsorWidget.ServiceURL + 'countrieslist',
				data: "lang=" + WVCSponsorWidget.lang,
				dataType: "jsonp",
				cache: false,
				success: function(response) {
				    
					wvcUpdateCountries(response.GetCountriesListResult, dropdownList);
				}
			});
}

function wvcUpdateCountries(CountriesList, dropdownListName) {
    dropdownList = document.getElementById(dropdownListName)
    var arLen=CountriesList.length;
    dropdownList.options.length = 0;
    for ( var i=0, len=arLen; i<len; ++i ){
        var optn = document.createElement("OPTION");
        optn.text = CountriesList[i].Display;
        optn.value = CountriesList[i].Code;
        dropdownList.options.add(optn);
    }
} 


