/* $Revision: 17816 $ $Date: 2010-11-08 18:18:22 +0100 (Mon, 08 Nov 2010) $ */

function switchCardProduct(productCardId,cardDefinitionId,loggedInPrice,notLoggedInPrice, cardRatio, numberOfPanels,updateFlash) {	
   var addCardInit = document.addCardPanelInit;
   // Changing logged in price label
   var loggedInPriceLabel = document.getElementById(addCardInit.loggedInPriceLabelId);
   loggedInPriceLabel.innerHTML = loggedInPrice;
   // Changing not logged in price label
   var notLoggedInPriceLabel = document.getElementById(addCardInit.notLoggedInPriceLabelId);
   notLoggedInPriceLabel.innerHTML = notLoggedInPrice;
   // Changing description label
   var cardDescription  = "";
   if("square"==cardRatio) {
	   cardDescription = addCardInit.squareCardDescription;
   } else {
	   if(numberOfPanels==1) {
		   cardDescription = addCardInit.singleStandardCardDescription;
	   } else {
		   cardDescription = addCardInit.doubleStandardCardDescription;
	   }
   }
   var descriptionLabel = document.getElementById(addCardInit.descriptionLabelId);
   descriptionLabel.innerHTML = cardDescription;
   // Changing selected product id
   var productHiddenField = document.getElementById(addCardInit.selectedProductHiddenFieldId);
   productHiddenField.value = productCardId;
   // Changing selected card definition id
   var cardDefinitionHiddenField = document.getElementById(addCardInit.selectedCardDefinitionHiddenFieldId);
   cardDefinitionHiddenField.value = cardDefinitionId;
   // Switching preview flash panels amount
   if(updateFlash) {
	   switchPreviewCardPanelsAmount(numberOfPanels);
   }
}

function changeCardDefinition(cardDefinitionId, ratio, orientation,hasDesignedBackside, singleProductId, doubleProductId,singleProductLogedInPrice,singleProductNotLogedInPrice,doubleProductLogedInPrice,doubleProductNotLogedInPrice,issoundcard,soundid,soundartist,soundtitle) {
	var addCardInit = document.addCardPanelInit;
	// Hiding/Displaying product choice radios
	var radioGroup = document.getElementById(addCardInit.radioGroupId);
	var numberOfPanels = 1;
	if(doubleProductId!=null&&singleProductId!=null) {
		// Setting onclick handlers on radios
		// Single radio
		window.eval("document.getElementById('"+addCardInit.singleRadioId+"').onclick=function(){"+getProductRadioOnClickHandler(singleProductId,cardDefinitionId,singleProductLogedInPrice,singleProductNotLogedInPrice, ratio, 1)+";}");
		// Double radio
		var doubleRadio =  document.getElementById(addCardInit.doubleRadioId);
		window.eval("document.getElementById('"+addCardInit.doubleRadioId+"').onclick=function(){"+getProductRadioOnClickHandler(doubleProductId,cardDefinitionId,doubleProductLogedInPrice,doubleProductNotLogedInPrice, ratio, 2)+";}");		
		doubleRadio.checked = true;
		// Displaying radio group
		radioGroup.style.display="block";
	} else {
		// Hiding radio group
		radioGroup.style.display="none";
	}	
	// Preselecting one of the options
	if(doubleProductId!=null) {
		numberOfPanels = 2;
		switchCardProduct(doubleProductId,cardDefinitionId,doubleProductLogedInPrice,doubleProductNotLogedInPrice,ratio,numberOfPanels,false);
	} else {
		numberOfPanels = 1;
		switchCardProduct(singleProductId,cardDefinitionId,singleProductLogedInPrice,singleProductNotLogedInPrice,ratio,numberOfPanels,false);
	}
	// Checking if we need to show sound notification container
	var displayValue = null;
	if(issoundcard) {
		displayValue="block";
	} else {
		displayValue="none";
	}
	document.getElementById(addCardInit.soundNotificationComponentId).style.display = displayValue;
	// Setting preview data to flash	
	reEmbedFlashPreview(cardDefinitionId,ratio,orientation,numberOfPanels,hasDesignedBackside,issoundcard,soundid,soundartist,soundtitle);
}

function getProductRadioOnClickHandler(productCardId,cardDefinitionId,loggedInPrice,notLoggedInPrice,cardRatio, numberOfPanels) {
	var onClick = "switchCardProduct(";
	onClick+="'"+productCardId+"',";
	onClick+="'"+cardDefinitionId+"',";
	onClick+="'"+loggedInPrice+"',";
	onClick+="'"+notLoggedInPrice+"',";
	onClick+="'"+cardRatio+"',";
	onClick+=""+numberOfPanels+",";
	onClick+="true";
	onClick+=");";
	return onClick;
}
