

function initAddToWishListAjax()
{	
	ajaxEngine.registerRequest("SYAddToWishListAjax", "SYAddToWishListAjax");	
			
	var WishlistUpdateDisplay = {};	
	WishlistUpdateDisplay.ajaxUpdate = function(ajaxResponse) 
	{			
		var fieldNames = ajaxResponse.childNodes;  
		for (var i = 0; i < fieldNames.length; i++) 
	   	{	
	   		if(ajaxResponse.childNodes[i].nodeType == 1 && ajaxResponse.childNodes[i].nodeName == "wishlist")
	   		{
	   			var ourResult = ajaxResponse.childNodes[i];		   			
				var attr_id = ourResult.getAttribute("id");    			
				var attr_success = ourResult.getAttribute("success"); 	
						
			    var element = $(attr_id);
			    if (element) {
			    	displayWishlistMessage(element, attr_success);
			    }
	   		}
	   	}
	}
	
	ajaxEngine.registerAjaxObject("WishlistUpdateDisplay", WishlistUpdateDisplay);	
}	

function getAddToWishListAjaxParams(catentryId)
{
	return 'catEntryId=' + catentryId + '&quantity=1&orderId=.&URL=&mode=add&'+ baseUrlParameters;
}

function initPricingAjax() 
{
	ajaxEngine.registerRequest("SYGetContractUnitPrices", "SYGetContractUnitPrices");	
	
	var ProductPricingAjaxResponseObject = {};
	ProductPricingAjaxResponseObject.ajaxUpdate = function(ajaxResponse) {				
		var fieldNames = ajaxResponse.childNodes;  
		var stringToUse = {};		
		for (var i = 0; i < fieldNames.length; i++) 
	   	{	  
	   		if ((fieldNames[i].nodeType == 1) && (fieldNames[i].getAttribute("id")=="products"))
	   		{	 
	   			var extendedTextNodes = fieldNames[i].childNodes;
	   			for(var textCount = 0; textCount < extendedTextNodes.length; textCount++){
	   				if(textCount==0)
	   					stringToUse = fieldNames[i].childNodes[textCount].data;
	   				else
	   					stringToUse = stringToUse + fieldNames[i].childNodes[textCount].data;
	   			}				
				break;
	   		}	   			   		
	   	}
	   	 						
		var myJSONObject = eval('('+stringToUse+')');	
		
		for (productId in myJSONObject.products)
		{ 				
			displayPriceSection(productId, myJSONObject.products[productId]);
		}		
	}

	ajaxEngine.registerAjaxObject("ProductPricingAjaxResponseObject", ProductPricingAjaxResponseObject);
}	

function initProductButtonsAjax() 
{
	ajaxEngine.registerRequest("SYGetProductButtonMessageFromCacheAjax", "SYGetProductButtonMessageFromCacheAjax");	
	
	var ProductButtonsAjaxResponseObject = {};
	ProductButtonsAjaxResponseObject.ajaxUpdate = function(ajaxResponse) {		
			
		var fieldNames = ajaxResponse.childNodes;  
		var stringToUse = {};		
		for (var i = 0; i < fieldNames.length; i++) 
	   	{	  
	   		if ((fieldNames[i].nodeType == 1) && (fieldNames[i].getAttribute("id")=="products"))
	   		{	 
	   			var extendedTextNodes = fieldNames[i].childNodes;
	   			for(var textCount = 0; textCount < extendedTextNodes.length; textCount++){
	   				if(textCount==0)
	   					stringToUse = fieldNames[i].childNodes[textCount].data;
	   				else
	   					stringToUse = stringToUse + fieldNames[i].childNodes[textCount].data;
	   			}				
				break;
	   		}	   			   		
	   	}
	   	 						
		var myJSONObject = eval('('+stringToUse+')');	
		
		for (productId in myJSONObject.products)
		{ 		
			displayProductButtonSection(productId, myJSONObject.products[productId]);	
		}		
	}

	ajaxEngine.registerAjaxObject("ProductButtonsAjaxResponseObject", ProductButtonsAjaxResponseObject);
}	

function initReviewsAjax() 
{
	ajaxEngine.registerAjaxElement("reviewSubTabContent");
	ajaxEngine.registerAjaxElement("reviewsPaginationArea");
	ajaxEngine.registerRequest("SYGetProductReviewsAjax", "SYGetProductReviewsAjax");
	ajaxEngine.registerAjaxObject("setupReviewTab", setupReviewTab);
	ajaxEngine.registerAjaxObject("setupReviewTabPagination", setupReviewTabPagination);
	ajaxEngine.registerAjaxObject("setupLoadReviewPhotos", setupLoadReviewPhotos);	
}	

var setupReviewTab = {};
setupReviewTab.ajaxUpdate = function(ajaxResponse){
	ReviewsTabUtils.setupReviewTabInteractions();
}

var setupReviewTabPagination = {};
setupReviewTabPagination.ajaxUpdate = function(ajaxResponse){
	ReviewsTabUtils.setupPagination('.paginationContainer');
}

var setupLoadReviewPhotos = {};
setupLoadReviewPhotos.ajaxUpdate = function(ajaxResponse){
	loadReviewPhotos();
}

function submitReviewsSearch(number,action,value)
{
    var param="";
	if(action){
	    if(action=='consumerReviewsShowReview-jcCustomSelectList'){
	    	param=getReviewPaginationParameters(number,null,value)+"&action=filter";
	    }else if(action=='consumerReviewsSortBy-jcCustomSelectList'){
			param=getReviewPaginationParameters(number,value,null)+"&action=sort";
	    }
    }else
    {
    	param=getReviewPaginationParameters(number);
    }
    
   
	ajaxEngine.sendRequest('SYGetProductReviewsAjax', {method:'post', parameters: param});
}

function getReviewPaginationParameters(number,reviewsort,reviewfilter) 
{
		var paramArray = new Array();
		paramArray.push('reviewpagenum='+(number));
		if((typeof(reviewsort)!='undefined' && reviewsort!=null)){
		paramArray.push('reviewsort='+reviewsort);
		}else{
		paramArray.push('reviewsort='+$('consumerReviewsSortBy-jcCustom').value);
		}
		
		if(typeof(reviewfilter)!='undefined' && reviewfilter!=null){
		paramArray.push('reviewfilter='+reviewfilter);
		}else{
		var value=$('consumerReviewsShowReview-jcCustom').value;
		if(value=='') value=0;
		paramArray.push('reviewfilter='+value);
		}

		var paramJoin = paramArray.join("&")+ "&" + baseUrlParameters+"&catentryids="+catentryIds+"&productId="+productId;
		return paramJoin;
}

var currentPageHTTPS=(window.location.toString().substring(0,5)=='https');

function convertBVSecure(url)
{
if(currentPageHTTPS && currentPageHTTPS==true){
var secureUrl=url.replace('http://','https://');
secureUrl=secureUrl.replace('/'+bvNonSecureDisplayCode+'/','/'+bvSecureDisplayCode+'/');
return secureUrl;
}
return url;
}

function loadReviewPhotos()
{
		$$('.bvPhotoRef').each(function(element){
		  if(element.href && element.readAttribute('data-href'))
		   		{
		   		element.href=convertBVSecure(element.readAttribute('data-href'));
		   		}
		   if($(element.childNodes[0]) && $(element.childNodes[0]).readAttribute('data-src'))
		   		{
		   		$(element.childNodes[0]).src=convertBVSecure($(element.childNodes[0]).readAttribute('data-src'));
				}
		});		
}

