/*function getCountries(divId, countryId, subCountryId, level)
{
		if(countryId.length > 0)
		{
			var imageLoading = "<img src='" + shop.url + "/ecommerce/images/icons/smallLoading.gif'>"
			ajaxLoad(shop.url + '/ajaxTemplates/basket/checkoutScreen/subCountriesAjax.cfm?countryId='+countryId+'&subCountryId='+subCountryId+'&level='+(parseInt(level))+'&addToSession=1', $(divId), 'reloadBasket()', imageLoading);
		}
		else{
			selectCountryShippingMethod(0);
			$(divId).innerHTML = "";
			if($('shippingMethodDiv'))$('shippingMethodDiv').innerHTML = "";
		}
}*/
function getCountries(divId, countryId, subCountryId, level)
	{
	selectCountryShippingMethod(-1);
	if(countryId.length > 0)
	{
	var imageLoading = "<img src='" + shop.url + "/ecommerce/images/icons/smallLoading.gif'>"
			ajaxLoad(shop.url + '/ajaxTemplates/basket/checkoutScreen/subCountriesAjax.cfm?countryId='+countryId+'&subCountryId='+subCountryId+		'&level='+(parseInt(level))+'&addToSession=1', $(divId), 'reloadBasket()', imageLoading);
		}
		else{
			//selectCountryShippingMethod(0);
		$(divId).innerHTML = "";
		if($('shippingMethodDiv'))$('shippingMethodDiv').innerHTML = "";
		}
	}

function getSubCountries(divId, countryId, subCountryId, level)
{
		if(checkSessionCountries() == false){window.location.href = shop.url + '/ecommerce/basket/basket.cfm'; return;}
		if(subCountryId.length > 0)
		{
			var imageLoading = "<img src='" + shop.url + "/ecommerce/images/icons/smallLoading.gif'>"
			var result = checkShippingMethod(countryId, subCountryId, level);
			if(result == false){ //more shipping countries
				ajaxLoad(shop.url + '/ajaxTemplates/basket/checkoutScreen/subCountriesAjax.cfm?countryId='+countryId+'&subCountryId='+subCountryId+'&level='+level+'&addToSession=1' , $(divId), 'reloadBasket()', imageLoading);
				if($('shippingMethodDiv'))$('shippingMethodDiv').innerHTML = "";
			}
			else{ //show shipping method
				ajaxLoad(shop.url + '/ajaxTemplates/basket/checkoutScreen/subCountriesAjax.cfm?countryId='+countryId+'&subCountryId='+subCountryId+'&level='+level+'&addToSession=1' ,  $(divId),  'reloadBasket()', imageLoading);
			}
		}
		else{
			$(divId).innerHTML = "";
			if($('shippingMethodDiv'))$('shippingMethodDiv').innerHTML = "";
			selectCountryShippingMethod(0);
		}
}

function sameHeightBasket(){
}

function reloadBasket(){
	var file = "ajaxLoad(shop.url+'/ajaxTemplates/basket/checkoutScreen/basketButtons.cfm', $('basketButtons'), 'sameHeightBasket()')";
	ajaxLoad(shop.url+'/ajaxTemplates/basket/checkoutScreen/totalsBasket.cfm', $('totalBasket'), file);
}

function selectCountryShippingMethod(value){
	ajaxLoad(shop.url+'/ajaxTemplates/common/checkoutActions.cfm?action=shipping&shippingMethodId='+value, null, '');
	ajaxLoad(shop.url+'/ajaxTemplates/common/checkoutActions.cfm?action=countryShippingMethod&countryShippingMethodId='+value, null, 'reloadBasket()');
}

function selectShippingMethod(value){
	ajaxLoad(shop.url+'/ajaxTemplates/common/checkoutActions.cfm?action=shipping&shippingMethodId='+value, null, 'reloadBasket()');
}

function checkSessionCountries(){
	var xmlObj = createXMLRequest();
	
	xmlObj.open('GET', shop.url + '/ajaxTemplates/basket/checkoutScreen/checkSessionCountries.cfm?noCache='+getUniqueId(), false);
	xmlObj.send(null);
	if(xmlObj.responseText.indexOf('0') != -1)return false;
	return true;
}

function checkShippingMethod(countryId, subCountryId, level){
	var xmlObj = createXMLRequest();
	
	xmlObj.open('GET', shop.url + '/ajaxTemplates/basket/checkoutScreen/checkShippingMethod.cfm?countryId='+countryId+'&subCountryId='+subCountryId+'&level='+level+'&noCache='+getUniqueId(), false);
	xmlObj.send(null);
	if(xmlObj.responseText.indexOf('0') == 0)return true;
	return false;
}

function changeSelectShippingMethod(obj, nameClass, nameClassSelected){
	$$('.'+nameClassSelected).each(function(el){el.removeClass(nameClassSelected);}); 
	$(obj).className = nameClass + " "+ nameClassSelected;
}
