﻿
///////////////////////////////////////////////////////////////////////////////
// RcnClientFx
///////////////////////////////////////////////////////////////////////////////

var RcnClientFx = new _RcnClientFx();

function _RcnClientFx()
{
}

_RcnClientFx.prototype.GetRcnObjectById = function()
{
    if ( arguments.length )
    {
        var element = document.getElementById( this.elementId );
        return element.rcnObject;
    }
    return null;
}

_RcnClientFx.prototype.GetRcnObject = function(element)
{
    return element.rcnObject;
}

_RcnClientFx.prototype.AttachRcnObject = function(element, obj)
{
    element.rcnObject = obj;
}

_RcnClientFx.prototype.CopyPrototype = function(descendant, parent) 
{   
    var sConstructor = parent.toString();   
    var aMatch = sConstructor.match( /\s*function (.*)\(/ );   
    if ( aMatch != null ) 
    { 
        descendant.prototype[aMatch[1]] = parent;
    }   
    for (var m in parent.prototype) 
    {   
        descendant.prototype[m] = parent.prototype[m];   
    }   
    sConstructor = descendant.toString();   
    aMatch = sConstructor.match( /\s*function (.*)\(/ );   
    if ( aMatch != null ) 
    { 
        descendant.prototype.className = aMatch[1];
    }   
    descendant.baseClass = parent.prototype;
}  

_RcnClientFx.prototype.ShowPrototypes = function(src)
{
    var str = "";
    for (var m in src.prototype) 
    {   
        str += m + "\r\n";
    } 
    return str;
}


///////////////////////////////////////////////////////////////////////////////
// RcnObject
///////////////////////////////////////////////////////////////////////////////

function RcnObject()
{
    this.InitInstance();
}

RcnObject.prototype.ClassName = function()
{
    return this.className;
}

RcnObject.prototype.InitInstance = function()
{
    if(!this.className)
    {
        this.className = 'RcnObject';
        this.baseClass = null;
    }
}

///////////////////////////////////////////////////////////////////////////////
// RcnDictionary
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnDictionary, RcnObject);

function RcnDictionary()
{
    this.InitInstance();
}

RcnDictionary.prototype.InitInstance = function()
{
    RcnDictionary.baseClass.InitInstance.call(this);
}

RcnDictionary.prototype.Lookup = function(key) 
{
    return this[key];
}

RcnDictionary.prototype.Add = function()
{
    for (count=0; count < arguments.length; count += 2) 
    {
        this[arguments[count]] = arguments[count+1];
    }
}

RcnDictionary.prototype.Delete = function(key) 
{
    for (arg in arguments) 
    {
        this[arg] = null;
    }
}

///////////////////////////////////////////////////////////////////////////////
// RcnElement
///////////////////////////////////////////////////////////////////////////////

RcnClientFx.CopyPrototype(RcnElement, RcnObject);

function RcnElement()
{
    if ( arguments.length )
        this.InitInstance(arguments[0]);
}

RcnElement.prototype.InitInstance = function(id)
{
    RcnElement.baseClass.InitInstance.call(this);
    this.elementId = id;
    this.element = document.getElementById(this.elementId);
    if( this.element )
    {
        RcnClientFx.AttachRcnObject(this.element, this);
    }
}

RcnElement.prototype.ElementId = function()
{
    // get
    return this.elementId;
}

RcnElement.prototype.Element = function()
{
    // get
    return this.element;
}

///////////////////////////////////////////////////////////////////////////////
// RcnEvent
///////////////////////////////////////////////////////////////////////////////

RcnClientFx.CopyPrototype(RcnEvent, RcnObject);

function RcnEvent(src)
{
    if ( arguments.length )
        this.InitInstance(arguments[0]);
}

RcnEvent.prototype.InitInstance = function(src)
{
    RcnEvent.baseClass.InitInstance.call(this);
    this.src = src;
}

RcnEvent.prototype.Src = function()
{
    // get
    return this.src;
}

///////////////////////////////////////////////////////////////////////////////
// RcnEventPublisher
///////////////////////////////////////////////////////////////////////////////

RcnClientFx.CopyPrototype(RcnEventPublisher, RcnObject);

function RcnEventPublisher()
{
    this.InitInstance();
}

RcnEventPublisher.prototype.InitInstance = function()
{
    RcnElement.baseClass.InitInstance.call(this);
    this.eventDictionary = new RcnDictionary();
}

RcnEventPublisher.prototype.AttachEvent = function(eventObj, subscriber)
{
    var eventArr = this.eventDictionary.Lookup(eventObj.ClassName);
    if( eventArr == null )
    {
        eventArr = new Array();    
        this.eventDictionary.Add(eventObj.ClassName, eventArr);
    }
    eventArr.push(subscriber);
}

RcnEventPublisher.prototype.TrigEvent = function(eventObj)
{
    var eventArr = this.eventDictionary.Lookup(eventObj.ClassName);
    if( eventArr != null )
    {
        for( subscriber in eventArr )
        {
            eventArr[subscriber].HandleEvent(eventObj);
        }
    }
}

///////////////////////////////////////////////////////////////////////////////
// RcnEventSubscriber
///////////////////////////////////////////////////////////////////////////////

RcnClientFx.CopyPrototype(RcnEventSubscriber, RcnObject);

function RcnEventSubscriber()
{
    this.InitInstance();
}

RcnEventSubscriber.prototype.InitInstance = function()
{
    RcnEventSubscriber.baseClass.InitInstance.call(this);
}

RcnEventSubscriber.prototype.HandleEvent = function(eventObj)
{
    alert("Override function 'HandleEvent' for event '" + eventObj.ClassName() + "'");
}

///////////////////////////////////////////////////////////////////////////////
// RcnElementEventSubscriber
///////////////////////////////////////////////////////////////////////////////

RcnClientFx.CopyPrototype(RcnElementEventSubscriber, RcnEventSubscriber);
RcnClientFx.CopyPrototype(RcnElementEventSubscriber, RcnElement);
RcnElementEventSubscriber.baseClass = RcnElement.prototype;
RcnElementEventSubscriber.baseClass2 = RcnEventSubscriber.prototype;

function RcnElementEventSubscriber()
{
    if( arguments.length )
        this.InitInstance(arguments[0]);
}

RcnElementEventSubscriber.prototype.InitInstance = function(id)
{
    RcnElementEventSubscriber.baseClass2.InitInstance.call(this);
    RcnElementEventSubscriber.baseClass.InitInstance.call(this, id);
}

///////////////////////////////////////////////////////////////////////////////
// RcnElementEventPublisher
///////////////////////////////////////////////////////////////////////////////

RcnClientFx.CopyPrototype(RcnElementEventPublisher, RcnEventPublisher);
RcnClientFx.CopyPrototype(RcnElementEventPublisher, RcnElement);
RcnElementEventPublisher.baseClass = RcnElement.prototype;
RcnElementEventPublisher.baseClass2 = RcnEventPublisher.prototype;

function RcnElementEventPublisher()
{
    this.InitInstance();
}

RcnElementEventPublisher.prototype.InitInstance = function(id)
{
    RcnElementEventSubscriber.baseClass2.InitInstance.call(this);
    RcnElementEventSubscriber.baseClass.InitInstance.call(this, id);
}

///////////////////////////////////////////////////////////////////////////////
// RcnElementEventPublisherSubscriber
///////////////////////////////////////////////////////////////////////////////

RcnClientFx.CopyPrototype(RcnElementEventPublisherSubscriber, RcnEventPublisher);
RcnClientFx.CopyPrototype(RcnElementEventPublisherSubscriber, RcnElementEventSubscriber);
RcnElementEventPublisherSubscriber.baseClass = RcnElementEventSubscriber.prototype;
RcnElementEventPublisherSubscriber.baseClass2 = RcnEventPublisher.prototype;

function RcnElementEventPublisherSubscriber()
{
    this.InitInstance();
}

RcnElementEventPublisherSubscriber.prototype.InitInstance = function(id)
{
    RcnElementEventPublisherSubscriber.baseClass2.InitInstance.call(this);
    RcnElementEventPublisherSubscriber.baseClass.InitInstance.call(this, id);
}





// Write out title from image to span om proctpages

/*addOnLoad("setImgHover()");


function setImgHover(){ 
	var allImgs = document.getElementsByTagName('img');
	for(i = 0; i < allImgs.length; i++){
		if(allImgs[i].className == "hoverText"){
			allImgs[i].onmouseover = showTitle;
			allImgs[i].onmouseout = removeTitle;
		}	
	}	
}
function showTitle(){
	if(document.getElementById("messageContainer")){
		document.getElementById("messageContainer").innerHTML = this.title;	
	}
}
function removeTitle(){
	if(document.getElementById("messageContainer")){
		document.getElementById("messageContainer").innerHTML = "";
	}
}
*/
// Open Close read more span in prodpages

addOnLoad("addReadMore()");

var readMoreStatus = "open";

function addReadMore(){
	showHide();
	var allAs = document.getElementsByTagName('a');
	for(i = 0; i < allAs.length; i++){
		if(allAs[i].className == "readMore"){
			allAs[i].onclick = showHide;
			break;
		}
	}
}
function showHide(){
	if(readMoreStatus == null){
		openReadMore();
		return false;
	}
	else if(openReadMore != null){
		hideReadMore();
		return false;
	}
}
function hideReadMore(){
	var allSpans = document.getElementsByTagName('span');
	for(i = 0; i < allSpans.length; i++){
	    if(allSpans[i].className == "shorten"){
	        allSpans[i].style.display = "inline";
	    }
		if(allSpans[i].className == "bread"){
			allSpans[i].style.display = "none";	
			readMoreStatus = null;
		}
	}
}
function openReadMore(){
	var allSpans = document.getElementsByTagName('span');
	for(i = 0; i < allSpans.length; i++){
	    if(allSpans[i].className == "shorten"){
	        allSpans[i].style.display = "none";
	    }
		if(allSpans[i].className == "bread"){
			allSpans[i].style.display = "inline";
			readMoreStatus = "open";
		}
	}
}
// Brows Comments.
	var product_comments = new Array(); // The array which contains the comments
	var commentPage = 0; // Current page
	var commentsPerPage = 999; // Number of objects per page

	function init_comments() {
	
		// Find the Div that contains the comments
		var allDivs = document.getElementsByTagName('BODY')[0].getElementsByTagName('DIV');
		for( i = 0 ; i < allDivs.length ; ++i ) {
			if( allDivs[i].className == 'comments' ) {
				break;
			}
		}
		
		// Save the comments from HTML into an Array
		var allComments = allDivs[i].getElementsByTagName('DIV');
		for( i = 0 ; i < allComments.length; ++i ) {
			product_comments[i] = allComments[i].innerHTML;
		}
		browseComments(0); // Send 0 to the browse-function will display the current page (start-page)			
	}

function browseComments( direction ) {

		// Calculate which page will be current and check that the current page exists
		commentPage = commentPage + direction;
		if( commentPage <= 0 ) {
			commentPage = 0;
		} else if( commentPage >= ( Math.ceil( product_comments.length / commentsPerPage ) -1 ) ) {
			commentPage = Math.ceil(product_comments.length / commentsPerPage) -1;
		}
		
		// Once again find the Div that contains the comments
		var allDivs = document.getElementsByTagName('BODY')[0].getElementsByTagName('DIV');
		for( i = 0 ; i < allDivs.length ; ++i ) {
			if( allDivs[i].className == 'comments' ) {
				comments_cont = allDivs[i];
				break;
			}
		}
		
		// Empty the comments Div and fill it with the comments associated with the current page
		comments_cont.innerHTML = '';
		var tempArray = new Array();
		for( i = ( commentPage * commentsPerPage ) ; i < ( ( commentPage * commentsPerPage ) + commentsPerPage ) && i < product_comments.length ; ++i ) {
			tempArray[i] = document.createElement('DIV');
			tempArray[i].className = 'comment_container';
			comments_cont.appendChild(tempArray[i]);
			tempArray[i].innerHTML = product_comments[i];
		}
		comments_cont.style.display = 'block'; // Display the comments container
	}

// Show and hide comment layer

addOnLoad("initOpenLayer()");

/* WorkAround: Making explicit call to function to close the comments layer as the now comments layer will  
   always be visible on Page Load. This is to ensure that alignment of login textboxes is correct. Without this
   workaround the three parts of textbox are not aligned together when the page is loaded and any Javascript      call on the page fixes the problem and brings them together. This problem is currently appearing only in
   Internet Explorer, not in Firefox.
*/
addOnLoad("closeComments()");

var commentStatus = null; 

function initOpenLayer(){
	if(document.getElementById("openLayer1Head") && document.getElementById("hideComment")){
		document.getElementById("openLayer1Head").onclick = openCloseComment;
		document.getElementById("hideComment").onclick = openCloseComment;
	}
}
function openCloseComment(){
	if(commentStatus != null){
		closeComments();
	}
	else{
		openComments();
	}
}
function closeComments(){
	if(document.getElementById("openLayer1Body")){
		document.getElementById("openLayer1Body").style.display = "none";
		commentStatus = null;
	}
}
function openComments(){
	if(document.getElementById("openLayer1Body")){
		document.getElementById("openLayer1Body").style.display = "block";		
		commentStatus = "open";
	}
}

// Show and hide Combination Discount Pushset based on the items count

addOnLoad("initOpenCombinationDiscountPushSets('PushSets')");
var pushsetsContainer;
var pushsetItems;
var combinationDiscountStatus = null; 

function initOpenCombinationDiscountPushSets(PushSets)
{
   // get the container for all pushset items
   pushsetsContainer = document.getElementById(PushSets);   
   if(pushsetsContainer != null)
   {
        var tempArray = pushsetsContainer.getElementsByTagName('div');
        pushsetItems = new Array();
        var pushsetItemIndex = 0;
        var index = 0;
        
        // Get all pushset items and put them in an array
        for(index = 0; index <tempArray.length; index++)
        {
            if(tempArray[index].id == "PushsetItem")
            {
                pushsetItems[pushsetItemIndex] = tempArray[index];
                pushsetItemIndex++;                
            }            
        }
        
        /* If the length of array containing pushset items is more than 3, then hide the remaining pushset
           items and attach onclick handlers to the buttons to open/close this layer of extra pushset items */ 
        if(pushsetItems.length > 3)
        {
	        for(index = 3; index < pushsetItems.length; index++)
	            pushsetItems[index].style.display = 'none';	  
	       
	        var openPushSetLayerButton = document.getElementById("openPushSetLayerButton");
	        if(openPushSetLayerButton)
	            openPushSetLayerButton.onclick = openClosePushSetItemsLayer;
	      
	        var closePushSetLayerButton = document.getElementById("closePushSetLayerButton");
	        if(closePushSetLayerButton)
	            closePushSetLayerButton.onclick = openClosePushSetItemsLayer;
	       
	        var closePushSetLayer = document.getElementById("closePushSetLayer");
            if(closePushSetLayer)
                closePushSetLayer.style.display = 'none';            
        }	   
   }   
}

function openClosePushSetItemsLayer()
{
    if(combinationDiscountStatus == null)
        openPushSetItemsLayer();    
    else
        closePushSetItemsLayer();    
}

// function to open the layer of extra pushset items
function openPushSetItemsLayer()
{
    // display layer containing close button
    var closePushSetLayer = document.getElementById("closePushSetLayer");
    if(closePushSetLayer)
        closePushSetLayer.style.display = 'block';
    
    // hide layer containing open button    
    var openPushSetLayer = document.getElementById("openPushSetLayer");
    if(openPushSetLayer)
        openPushSetLayer.style.display = 'none';
        
    var index;
    // display all pushset items 
    for(index =0; index < pushsetItems.length; index++)
    {
        if(pushsetItems[index].style.display == 'none')
            pushsetItems[index].style.display = 'block';      
    }    
    combinationDiscountStatus = "open";        
}

// function to close the layer of extra pushset items
function closePushSetItemsLayer()
{
    var index;
    if(pushsetItems.length > 3)
    {
        // hide all extra (more than 3) pushset items
        for(index = 3; index < pushsetItems.length; index++)
            pushsetItems[index].style.display = 'none';       
    }
    
    // display layer containing open button
    var openPushSetLayer = document.getElementById("openPushSetLayer");
    if(openPushSetLayer)
        openPushSetLayer.style.display = 'block';
     
    // hide layer contianing close button 
    var closePushSetLayer = document.getElementById("closePushSetLayer");
    if(closePushSetLayer)
        closePushSetLayer.style.display = 'none';
    
    combinationDiscountStatus = null;    
}










////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Class declaration of the Client Side Arrays.Changes made in the file should be reflected to Multiple.js and QuickOrder.js
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Article(articleId, name, image, imgPath, zoomImgPath, pricePrefix, variants, labelPos1Visible, labelPos2Visible, labelPos3Visible, labelPos4Visible) {
    this.ArticleId = articleId;
    this.Name = name;                               // Article display name
    this.Img = image;                               // The name of the product/article image
    this.ImgPath = imgPath;                         // the path to the product/article image
    this.ZoomImgPath = zoomImgPath;                         // the path to the product/article image
    this.PricePrefix = pricePrefix;                 // the prefix before the price (e.g. fr.)
    this.Variants = variants;                       // Variants
    this.LabelPos1Visible = labelPos1Visible;
    this.LabelPos2Visible = labelPos2Visible;
    this.LabelPos3Visible = labelPos3Visible;
    this.LabelPos4Visible = labelPos4Visible;
}

//function Variant(variantId,name,price,isOneClickArticle,isFromPrice,hasAlternatePrice,alternatePrice,isAffectedByDiscount,hasDate,dateDisplay,availability,deliveryStatus,hasSimilarVariants,similarProductsLink,hasDiscountInfoText,discountInfoTextDisplay)
function Variant(variantId, name, price, isOneClickArticle, isFromPrice, hasAlternatePrice, alternatePrice, isAffectedByDiscount, hasDate, dateDisplay, availability, deliveryStatus, hasSimilarVariants, similarProductsLink, hasDiscountInfoText, discountInfoTextDisplay, bookingNo, partpaymentmonth) {
    this.VariantId = variantId;
    this.Name = name;                                   // the display text of the variant.
    this.Price = price;                                 // string, the current price to display
    this.IsOneClickArticle = isOneClickArticle;         // 1 if IsOneClickArticle else 0
    this.IsFromPrice = isFromPrice;                     // 1 if IsFromPrice else 0
    this.HasAlternatePrice = hasAlternatePrice;         // 1 if HasAlternatePrice else 0
    this.AlternatePrice = alternatePrice;               // string, the formated alternate price string
    this.IsAffectedByDiscount = isAffectedByDiscount;   // 1 if IsAffectedByDiscount else 0
    this.HasDate = hasDate;                             // 1 if HasDate else 0
    this.DateDisplay = dateDisplay;                     // string, the formated date string
    this.Availability = availability;                   // 0: NotApplicable,  1:InStock,  2:NoStock,  3:SoldOut
    this.DeliveryStatus = deliveryStatus;               // string, delivery status
    this.HasSimilarVariants = hasSimilarVariants;       // 0 if nosimilarVariants or if not applicable else 1.                       
    this.SimilarProductsLink = similarProductsLink;     // the link to listpage with similar products.
    this.HasDiscountInfoText = hasDiscountInfoText;     // 1 if HasDiscountInfoText else 0
    this.DiscountInfoTextDisplay = discountInfoTextDisplay; // string, the formated DiscountInfoText string
    //Added: Boris Estrada, Guide Konsult Gbg AB, 2006-10-02 (EL99160).
    this.BookingNo = bookingNo;                         // the VariantActivity's booking no.
    //Added: David Johansson, Sigma Solutions, 2008-05-12 (el99534). {10} PartPaymentMonth
    this.PartPaymentMonth = partpaymentmonth;           //PartPaymentMonth ex. 299kr/mån
}

function MatchSet(pushSetId, pricePrefix, buyText, item) {
    this.PushSetId = pushSetId;         // the identity of the PushSet if applicable, else 0.
    this.PricePrefix = pricePrefix;     // string, the prefix before the price (e.g. fr.)
    this.BuyText = buyText;             // string, the text of the buy button.
    this.Item = item;                   // MSItem
}
function MSItem(imgUrl, name, price, link, oneClickProduct, isFromPrice, hasAlternatePrice, alternatePrice, isAffectedByDiscount, hasDate, dateDisplay, articleId) {
    this.ImgUrl = imgUrl;                               // string, the path to the item image
    this.Name = name;                                   // string, the text to display
    this.Price = price;                                 // string, the formated price string
    this.Link = link;                                   // string, the internal link to DetailPage
    this.OneClickProduct = oneClickProduct;             // 1 if oneClickProduct else 0
    this.IsFromPrice = isFromPrice;                     // 1 if IsFromPrice else 0
    this.HasAlternatePrice = hasAlternatePrice;         // 1 if HasAlternatePrice else 0
    this.AlternatePrice = alternatePrice;               // string, the formated alternate price string
    this.IsAffectedByDiscount = isAffectedByDiscount;   // 1 if IsAffectedByDiscount else 0
    this.HasDate = hasDate;                             // 1 if HasDate else 0
    this.DateDisplay = dateDisplay;                     // string, the formated date string
    this.ArticleId = articleId;                         // the articleId
}


function RenderAvailability() {
    var articleIndex = document.getElementById('RcnArticleIndex').value;
    var variantIndex = document.getElementById('RcnVariantIndex').value;
    var objAvailability = document.getElementById('RcnAvailability');
    var objAvailabilityInStock = document.getElementById('RcnAvailabilityInStock');
    var objAvailabilityNoStock = document.getElementById('RcnAvailabilityNoStock');
    var objDeliveryStatus = document.getElementById('RcnAvailabilityDeliveryStatus');
    var objAvailabilityLowStock = document.getElementById('RcnAvailabilityLowStock');
    var objAvailabilityInStockAlmostSoldOut = document.getElementById('RcnAvailabilityInStockAlmostSoldOut');
    var objAvailabilityDeliveryAlmostSoldOut = document.getElementById('RcnAvailabilityDeliveryAlmostSoldOut');
    var objInStockInfoLink = document.getElementById('RcnInStockInfoLink');
    var objNoStockInfoLink = document.getElementById('RcnNoStockInfoLink');

    if (articleIndex == '0' || articleIndex == '') {
        articleIndex = 0;
    }

    if (variantIndex == '0' || variantIndex == '') {
        variantIndex = 0;
    }

    // Set DeliveryStatus
    if (A[articleIndex].Variants[variantIndex].Availability > 0) {
        objAvailability.style.display = 'inline';
        objAvailabilityInStock.style.display = 'none';
        objAvailabilityNoStock.style.display = 'inline';
    }
    else {
        objAvailability.style.display = 'none';
        objAvailabilityLowStock.style.display = 'none';
    }

    // In Stock
    if (A[articleIndex].Variants[variantIndex].Availability == 1) {
        objAvailabilityInStock.style.display = 'inline';
        objAvailabilityNoStock.style.display = 'none';
        objAvailabilityLowStock.style.display = 'none';
        objAvailabilityInStockAlmostSoldOut.style.display = 'none';
        objAvailabilityDeliveryAlmostSoldOut.style.display = 'none';
        objInStockInfoLink.style.display = 'inline';
        objNoStockInfoLink.style.display = 'none';
    }

    // No Stock
    if (A[articleIndex].Variants[variantIndex].Availability == 2) {
        objDeliveryStatus.innerHTML = A[articleIndex].Variants[variantIndex].DeliveryStatus;
        objAvailabilityInStock.style.display = 'none';
        objAvailabilityNoStock.style.display = 'inline';
        objAvailabilityLowStock.style.display = 'none';
        objAvailabilityInStockAlmostSoldOut.style.display = 'none';
        objAvailabilityDeliveryAlmostSoldOut.style.display = 'none';
        objInStockInfoLink.style.display = 'none';
        objNoStockInfoLink.style.display = 'inline';
        
    }
    else {
        // TODO: What todo, should probably never happen
        objDeliveryStatus.innerHTML = A[articleIndex].Variants[variantIndex].DeliveryStatus;
        objAvailabilityInStock.style.display = 'none';
        objAvailabilityNoStock.style.display = 'inline';
        objAvailabilityLowStock.style.display = 'none';
        objAvailabilityInStockAlmostSoldOut.style.display = 'none';
        objAvailabilityDeliveryAlmostSoldOut.style.display = 'none';
//        objDeliveryInfoLink.style.display = 'inline';
    }

    /* Low Stock Warning */

    if (A[articleIndex].Variants[variantIndex].Availability == 4) {
        objAvailabilityInStock.style.display = 'inline';
        objAvailabilityNoStock.style.display = 'none';
        objAvailabilityLowStock.style.display = 'block';
        objAvailabilityInStockAlmostSoldOut.style.display = 'inline';
        objAvailabilityDeliveryAlmostSoldOut.style.display = 'none';
    }

    if (A[articleIndex].Variants[variantIndex].Availability == 5) {
        objDeliveryStatus.innerHTML = A[articleIndex].Variants[variantIndex].DeliveryStatus;
        objAvailabilityInStock.style.display = 'none';
        objAvailabilityNoStock.style.display = 'inline';
        objAvailabilityLowStock.style.display = 'block';
        objAvailabilityInStockAlmostSoldOut.style.display = 'none';
        objAvailabilityDeliveryAlmostSoldOut.style.display = 'inline';
    }

}

function RenderArticleDisplay(index) {
    // if called without parameters then display text from "ViewState"
    if (arguments.length < 1)
        index = document.getElementById('RcnArticleIndex').value;

    if (index == '')
        index = 0;

    var objArticleDisplay = document.getElementById('RcnArticleDisplay');
    objArticleDisplay.innerHTML = A[index].Name;
}

//Added: Boris Estrada, Guide Konsult Gbg AB, 2006-10-02 (EL99160).
function RenderArticleNo(index) {
    // if called without parameters then display text from "ViewState"
    if (arguments.length < 1)
        index = document.getElementById('RcnArticleIndex').value;

    if (index == '')
        index = 0;


    var variantIndex = document.getElementById('RcnVariantIndex').value;

    if (variantIndex == '0' || variantIndex == '') {
        variantIndex = 0;
    }

    var objArticleDisplay = document.getElementById('RcnArticleNo');
    var objArticleText = document.getElementById('RcnArticleNoText');

    if (A[index].ArticleId != -1 && A[index].Variants[variantIndex].BookingNo != '') {
        objArticleText.style.visibility = 'visible';
        objArticleDisplay.innerHTML = ": " + A[index].Variants[variantIndex].BookingNo; //+ A[index].ArticleId;
    }
    else {
        objArticleText.style.visibility = 'hidden';
        objArticleDisplay.innerHTML = "";
    }
}

function RenderPriceInfo() {
    // TODO: Check that the object above exist before rendering...
    var objAlternatePrice = document.getElementById('PCAlternatePrice');
    var objFromPrice = document.getElementById('PCFromPrice');
    var objPrice = document.getElementById('PCPrice');
    //Added: David Johansson, Sigma Solutions, 2008-05-12 (el99534). {10} PartPaymentMonth
    var objPartPaymentMonth = document.getElementById('PCPartPaymentMonth');
    var objNicePrice = document.getElementById('PCNicePrice');
    var objDate = document.getElementById('PCDate');
    var objDiscountInfoText = document.getElementById('PCDiscountInfoText');


    // Get article- and variant index from the hidden state controls.
    var articleIndex = document.getElementById('RcnArticleIndex').value;
    var variantIndex = document.getElementById('RcnVariantIndex').value;

    if (articleIndex == '0' || articleIndex == '')
        articleIndex = 0;

    if (variantIndex == '0' || variantIndex == '')
        variantIndex = 0;


    // Alternate price

    if (A[articleIndex].Variants[variantIndex].HasAlternatePrice == 1) {
        objAlternatePrice.innerHTML = '(' + A[articleIndex].Variants[variantIndex].AlternatePrice + ')';
        objAlternatePrice.style.display = 'inline';
    }
    else {
        objAlternatePrice.style.display = 'none';
    }

    // Current Price
    objPrice.innerHTML = A[articleIndex].Variants[variantIndex].Price;
    objNicePrice.innerHTML = A[articleIndex].Variants[variantIndex].Price;
    objFromPrice.innerHTML = A[articleIndex].PricePrefix;
    if (A[articleIndex].Variants[variantIndex].IsAffectedByDiscount == 1 && A[articleIndex].Variants[variantIndex].HasAlternatePrice == 1) {
        objNicePrice.style.display = 'inline';
        objPrice.style.display = 'none';
    }
    else {
        objNicePrice.style.display = 'none';
        objPrice.style.display = 'inline';
    }

    // Show PricePrefix
    if (A[articleIndex].Variants[variantIndex].IsFromPrice == 1)
        objFromPrice.style.display = 'inline';
    else
        objFromPrice.style.display = 'none';

    // Show date.
    if (A[articleIndex].Variants[variantIndex].HasDate == 1) {
        objDate.innerHTML = A[articleIndex].Variants[variantIndex].DateDisplay;
        objDate.style.display = 'inline';
    }
    else {
        objDate.style.display = 'none';
    }

    // Info text.
    if (A[articleIndex].Variants[variantIndex].HasDiscountInfoText == 1) {
        objDiscountInfoText.innerHTML = A[articleIndex].Variants[variantIndex].DiscountInfoTextDisplay;
        objDiscountInfoText.style.display = 'inline';
    }
    else {
        objDiscountInfoText.style.display = 'none';
    }

    //Show the calculated PartPaymentMonth price
    objPartPaymentMonth.innerHTML = A[articleIndex].Variants[variantIndex].PartPaymentMonth;
}

/************************************************************************
RenderMatchSet: Renders HTML to the client side MatchSet control
parameters     index:  Identifies the index of the MatchSet Array
ctrlId: (optional) The element id of the div to render.
************************************************************************/
function RenderMatchSet(index, ctrlId) {
    // If this function is called with MatchSet array index only.
    if (arguments.length < 2)
        ctrlId = 'MatchSetContainer';

    var matchSetContainer = document.getElementById(ctrlId);

    // Check that we have a MatchSet to render
    // Check that MatchSet for this index exist.
    // Check that we have an element to render to.
    if (M.length <= index || M[index].Item.length <= 0 || matchSetContainer == undefined)
        return;

    var s = new Array();
    var price = '';
    var comDate = '';
    var buyButton = '';
    s.push("<ul>");
    for (i = 0; i < M[index].Item.length; i++) {
        s.push('<li');
        if (i == 0)
            s.push(' class="firstColumn"');

        s.push('><div class="matchImage">');
        s.push('<a href="');
        s.push(M[index].Item[i].Link);
        s.push('"><img class="thumbnailBig" src="');
        s.push(M[index].Item[i].ImgUrl);
        s.push('" alt="" /></a></div>');
        s.push('<div class="matchText">');
        s.push('<span class="matchProductItemType">');
        var name = M[index].Item[i].Name;
        if (name.length > 10)
            name = name.substring(0,9) + '...';
        s.push(name);
        s.push('</span><br/>');
        
        if (M[index].Item[i].IsFromPrice == 1)
            price = M[index].PricePrefix;

        price += M[index].Item[i].Price;
        s.push(price);

        s.push('</div></li>');
    }
    s.push("</ul>");
    
    matchSetContainer.innerHTML = s.join('');
}

function RenderProductImage(index, htmlAnchorId, htmlImageId) {

    if (arguments.length < 3)
        htmlImageId = 'RcnProductImage';

    if (arguments.length < 2)
        htmlAnchorId = 'RcnProductImageLink';

    if (arguments.length < 1)
        index = 0;

    // Check that we have an element to render to.
    if (!document.getElementById(htmlImageId)) {
        alert('RcnProductImage not found');
        return;
    }
    var objImg = document.getElementById(htmlImageId);

    if (!document.getElementById(htmlAnchorId)) {
        alert('RcnProductImageLink not found');
        return;
    }
    var objLink = document.getElementById(htmlAnchorId);

    // set image src
    var cssValue = 'url(' + A[index].ImgPath + ')';
    $('#' + htmlImageId).css('background-image', cssValue);
    
    objImg.src = A[index].ImgPath;
    var zoomExt = Sys.UI.Behavior.getBehaviorByName(objImg, 'ZoomImageBehavior');
    if (zoomExt) {
        zoomExt.set_zoomImageSrc(A[index].ZoomImgPath);
        zoomExt.set_onClickScript("PopupZoom('" + A[index].Img + "');");
    }
    // set a href to pop zoom window
    objLink.href = PopupZoomUrl(A[index].Img);

    // hide promotion labels
    var labelPos1 = getLabelPos("1");
    var labelPos2 = getLabelPos("2");
    var labelPos3 = getLabelPos("3");
    var labelPos4 = getLabelPos("4");
    if (index > 0) {
        if (labelPos1 != null) {

            if (A[index].LabelPos1Visible) {
                labelPos1.style.display = '';
            } else {
                labelPos1.style.display = 'none';
            }
        }

        if (labelPos2 != null) {

            if (A[index].LabelPos2Visible) {
                labelPos2.style.display = '';
            } else {
                labelPos2.style.display = 'none';
            }
        }

        if (labelPos3 != null) {

            if (A[index].LabelPos3Visible) {
                labelPos3.style.display = '';
            } else {
                labelPos3.style.display = 'none';
            }
        }

        if (labelPos4 != null) {

            if (A[index].LabelPos4Visible) {
                labelPos4.style.display = '';
            } else {
                labelPos4.style.display = 'none';
            }
        }
    }
    else {
    }
}

function PopupZoom(imgSrc) {
    url = '/misc/ProductZoom.aspx?ImageSource=' + imgSrc;
    window.open(url);
}

function getLabelPos(number) {
    var objects = document.getElementsByTagName('img');
    for (i = 0; i < objects.length; i++) {
        if (objects[i].id.indexOf('imgLabelPos' + number) > 0) {
            return objects[i];
        }
    }
    return null;
}

function RenderProductZoomLink(index, htmlAnchorId) {
    if (arguments.length < 2)
        htmlAnchorId = 'RcnProductZoom';

    if (arguments.length < 1) {
        index = document.getElementById('RcnArticleIndex').value;
        if (index == '')
            index = 0;
    }

    if (!document.getElementById(htmlAnchorId)) {
        alert('element ' + htmlAnchorId + ' not found.');
        return;
    }
    var objLink = document.getElementById(htmlAnchorId);
    objLink.href = PopupZoomUrl(A[index].Img);
}

function PopupZoomUrl(imgSrc) {
    if (arguments.length < 1) {
        alert('missing variable imgSrc in function PopupZoomUrl(imgSrc)');
        return;
    }

    return url = '/misc/ProductZoom.aspx?ImageSource=' + imgSrc;
}

/************************************************************************
PopulateVariants:   Populates the variant select.
ctrl:   The id of the HTMLSelect control.
index:  The article index.
************************************************************************/
function PopulateVariants(ctrl, index) {
    if (document.getElementById(ctrl)) {
        var ddl = document.getElementById(ctrl);
        var selectedText = '';
        var variantIndex = 0;
        var findOption = false;

        // delete existing items
        for (i = ddl.options.length; i > 0; i--)
            ddl.options[i] = null;

        // Add the variants. Observe that VariantIndex 0 represents the article when no variant is selected (i.e. do not render index = 0 to the selectbox options)
        for (j = 1; j < A[index].Variants.length; j++)
            addOption(ddl, A[index].Variants[j].Name, A[index].Variants[j].VariantId);

        if (ddl.options.length == 2) {
            variantIndex = 1;
            selectedText = ddl.options[1].text;
            SaveVariantIndexToViewState(1);
        }
        // Try to get previously selected item (variant).
        var previousSelection = ddl.selectedIndex > 0 ? ddl.selectedIndex : (document.getElementById('RcnVariantIndex').value > 0 ? document.getElementById('RcnVariantIndex').value : 0)
        if (previousSelection > 0) {
            if (ddl.options[previousSelection] != null) {
                findOption = true;
                selectedText = ddl.options[previousSelection].text;
            }
            else {
                selectedText = ddl.options[0].text;
            }
        }

        if (findOption == true) {
            for (z = 0; z < ddl.options.length; z++) {
                if (ddl.options[z].text == selectedText)
                    variantIndex = z;
            }
        }

        // Set selected item.
        ddl.selectedIndex = variantIndex;

        // Finally save current variant index to the client side "viewState" (hidden input)
        SaveVariantIndexToViewState(variantIndex);

        // Returns the selected variantIndex
        return variantIndex;
    }
}
/************************************************************************
addOption:   Adds an OPTION to a HTMLSelect control.
selectbox:  The HTMLSelect element.
text:       Sets the text.
value:      Sets the value.
************************************************************************/
function addOption(selectbox, text, value) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Functions to set focus on the article images.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**************************************************************************
HideImageBorders:   Removes the border from all article images
***************************************************************************/
function HideImageBorders() {
    for (i = 0; i <= A.length; i++) {
        if (document.getElementById('Border' + i)) {
            document.getElementById('Border' + i).className = "";
        }
    }
}
/*************************************************************************************
RenderArticleImageBorder:   Renders a border arround the article image with this index
**************************************************************************************/
function RenderArticleImageBorder(index) {
    HideImageBorders();
    if (document.getElementById('Border' + index)) {
        document.getElementById('Border' + index).className = "product_smallthumb_active";
    }
}
/**************************************************************************
GetArticleIndexOnArticleId: Returns article index on articleId
***************************************************************************/
function GetArticleIndexOnArticleId(articleId) {
    var index = 0;
    for (i = 0; i < A.length; i++) {
        if (A[i].ArticleId == articleId)
            index = i;
    }
    return index;
}
/**************************************************************************
GetArticleIdOnIndex:    Returns articleId on article index
***************************************************************************/
function GetArticleIdOnIndex(articleIndex) {
    return A[articleIndex].ArticleId;
}
/**************************************************************************
GetVariantIdOnIndex:    Returns variantId on article- index and variant index
***************************************************************************/
function GetVariantIdOnIndex(articleIndex, variantIndex) {
    return A[articleIndex].Variants[variantIndex].VariantId;
}

/**************************************************************************
SaveArticleIndexToViewState:    Sets current article index and articleId
to the hidden input html input fields in order
to maintain state between postbacks.
                                
parameters:     index:      The zero-based index of the selected article.
***************************************************************************/
function SaveArticleIndexToViewState(index) {
    if (!document.getElementById('RcnArticleIndex'))
        return;
    document.getElementById('RcnArticleIndex').value = index;

    // Save articleId to hidden field.
    if (!document.getElementById('RcnArticleId')) {
        alert('Missing element RcnArticleId');
        return
    }
    document.getElementById('RcnArticleId').value = GetArticleIdOnIndex(index);
}

/**************************************************************************
SaveVariantIndexToViewState:    Sets current variant index and variantId
to the hidden input html input fields in order
to maintain state between postbacks.
                                
parameters:     index:      The zero-based index of the selected variant.
***************************************************************************/
function SaveVariantIndexToViewState(index) {
    if (!document.getElementById('RcnVariantIndex'))
        return;
    document.getElementById('RcnVariantIndex').value = index;

    // Save variantId to hidden field.
    if (!document.getElementById('RcnVariantId')) {
        alert('Missing element RcnVariantId');
        return
    }
    document.getElementById('RcnVariantId').value = GetVariantIdOnIndex(document.getElementById('RcnArticleIndex').value, index);
}

/***********************************************************************************
SaveVariantIdToViewState:   Sets variantId to the hidden html input field RcnVariantId.
variantId:     The variantId to write to the hidden field
***********************************************************************************/
function SaveVariantIdToViewState(variantId) {
    if (!document.getElementById('RcnVariantId'))
        return;
    document.getElementById('RcnVariantId').value = variantId;
}

/***********************************************************************************
SetSelectedIndex:   Method to set the selected index of a HTMLSelect control
ctrlId:     The element id of the control
index:      The index to set as selected.
***********************************************************************************/
function SetSelectedIndex(ctrlId, index) {
    if (!document.getElementById(ctrlId))
        return;

    var ctrl = document.getElementById(ctrlId);

    if (ctrl.options.length < index)
        return;

    ctrl.selectedIndex = index;
}


///////////////////////////////////////////////////////////////////////////////
// RcnSelect    Test class attach to <select>
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnSelect, RcnElementEventPublisherSubscriber);

function RcnSelect(id) {
    if (arguments.length)
        this.InitInstance(id);
}

RcnSelect.prototype.InitInstance = function(id) {
    RcnSelect.baseClass.InitInstance.call(this, id);
    if (this.Element()) {
        this.Element().onchange = this.OnSelectChangeHandler;
    }
}

RcnSelect.prototype.OnSelectChangeHandler = function() {
    RcnClientFx.GetRcnObject(this).SelectChange();
}

RcnSelect.prototype.SelectChange = function() {
    alert(this.Element().selectedIndex);
    this.TrigEvent(new RcnArticleEvent(this, this.Element().selectedIndex));
}

///////////////////////////////////////////////////////////////////////////////
// RcnArticleImage:     Class attach to the Article Image
//          id:             The element id of the HTMLImage <img>.
//          articleIndex:   The article index representing this image.
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnArticleImage, RcnElementEventPublisherSubscriber);

function RcnArticleImage(id, articleIndex) {
    if (arguments.length)
        this.InitInstance(id, articleIndex);
}

RcnArticleImage.prototype.InitInstance = function(id, articleIndex) {
    RcnArticleImage.baseClass.InitInstance.call(this, id);
    this.articleImageElement = document.getElementById(id);
    this.articleImageIndex = articleIndex;

    if (this.articleImageElement) {
        // onClick
        this.articleImageElement.onclick = this.OnClickHandler;

        // onMouseOver
        this.articleImageElement.onmouseover = this.OnMouseOverHandler;

        // onMouseOut
        this.articleImageElement.onmouseout = this.OnMouseOutHandler;
    }
}

RcnArticleImage.prototype.OnClickHandler = function() {
    RcnClientFx.GetRcnObject(this).ArticleImageClick();
}
RcnArticleImage.prototype.ArticleImageClick = function() {
    // Store the articleIndex
    SaveArticleIndexToViewState(this.articleImageIndex);

    // Trigger the RcnArticleEvent
    this.TrigEvent(new RcnArticleEvent(this, this.articleImageIndex));
}

RcnArticleImage.prototype.OnMouseOverHandler = function() {
    RcnClientFx.GetRcnObject(this).ArticleImageOnMouseOver();
}
RcnArticleImage.prototype.ArticleImageOnMouseOver = function() {
    // Trigger the RcnArticleOnMouseOverEvent
    this.TrigEvent(new RcnArticleOnMouseOverEvent(this, this.articleImageIndex));
}

RcnArticleImage.prototype.OnMouseOutHandler = function() {
    RcnClientFx.GetRcnObject(this).ArticleImageOnMouseOut();
}
RcnArticleImage.prototype.ArticleImageOnMouseOut = function() {
    this.TrigEvent(new RcnArticleOnMouseOutEvent(this, this.articleImageIndex));
}

RcnArticleImage.prototype.HandleEvent = function(eventObj) {
    if (eventObj.ClassName() == "RcnArticleEvent") {
        if (eventObj.ArticleIndex() == this.articleImageIndex) {
            // Call function that renders a border round the selected article image.
            RenderArticleImageBorder(this.articleImageIndex);
        }
    }
}

///////////////////////////////////////////////////////////////////////////////
// RcnSelector  Class attach to <div><select1/><select2/></div>
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnSelector, RcnElementEventPublisherSubscriber);

function RcnSelector(id, idArticle, idVariant) {
    if (arguments.length)
        this.InitInstance(id, idArticle, idVariant);
}

RcnSelector.prototype.InitInstance = function(id, idArticle, idVariant) {
    RcnSelector.baseClass.InitInstance.call(this, id);
    this.articleElement = document.getElementById(idArticle);
    this.variantElement = document.getElementById(idVariant);

    if (this.articleElement) {
        RcnClientFx.AttachRcnObject(this.articleElement, this);
        this.articleElement.onchange = this.OnArticleSelectChangeHandler
    }

    if (this.variantElement) {
        RcnClientFx.AttachRcnObject(this.variantElement, this);
        this.variantElement.onchange = this.OnVariantSelectChangeHandler
    }
}

RcnSelector.prototype.OnArticleSelectChangeHandler = function() {
    RcnClientFx.GetRcnObject(this).ArticleSelectChange();
}

RcnSelector.prototype.OnVariantSelectChangeHandler = function() {
    RcnClientFx.GetRcnObject(this).VariantSelectChange();
}

RcnSelector.prototype.ArticleSelectChange = function() {
    // Store the articleIndex
    SaveArticleIndexToViewState(this.articleElement.selectedIndex);

    // Mark the article image
    RenderArticleImageBorder(this.articleElement.selectedIndex);

    // Populate variants and get the new variantId, trigger events.
    // But, only if the variant select box is redered to page.
    if (this.variantElement) {
        var selectedVariantIndex = PopulateVariants(this.variantElement.id, this.articleElement.selectedIndex);

        // Trigger events
        this.TrigEvent(new RcnVariantEvent(this, selectedVariantIndex));
        this.TrigEvent(new RcnArticleVariantEvent(this, this.articleElement.selectedIndex, selectedVariantIndex));
    }
    else {
        var oldVariantIndex = document.getElementById('RcnVariantIndex').value;
        var selectedVariantIndex = 0;
        if (this.articleElement.selectedIndex > 0)
            selectedVariantIndex = 1;

        // Store the variantIndex
        SaveVariantIndexToViewState(selectedVariantIndex);

        if (oldVariantIndex != selectedVariantIndex) {
            // Trigger events
            this.TrigEvent(new RcnVariantEvent(this, selectedVariantIndex));
            this.TrigEvent(new RcnArticleVariantEvent(this, this.articleElement.selectedIndex, selectedVariantIndex));
        }
    }

    // Trigger events.
    this.TrigEvent(new RcnArticleEvent(this, this.articleElement.selectedIndex));

}

RcnSelector.prototype.VariantSelectChange = function() {
    // Store the variantIndex
    SaveVariantIndexToViewState(this.variantElement.selectedIndex);

    this.TrigEvent(new RcnVariantEvent(this, this.variantElement.selectedIndex));
    this.TrigEvent(new RcnArticleVariantEvent(this, this.articleElement.selectedIndex, this.variantElement.selectedIndex));
}

RcnSelector.prototype.HandleEvent = function(eventObj) {
    // I only let my RcnSelector attach to the ArticleImages and not to itself. Therefore some "events are handled" in the ArticleSelectChange function above...
    if (eventObj.ClassName() == 'RcnArticleEvent') {

        // The user has clicked on an article image.

        // Change selected index of the article HTMLSelect        
        SetSelectedIndex(this.articleElement.id, eventObj.ArticleIndex());

        // Re-populate Variants, if the variant select box exist
        if (this.variantElement) {
            var selectedVariantIndex = PopulateVariants(this.variantElement.id, eventObj.ArticleIndex());
            // Trigger events
            this.TrigEvent(new RcnVariantEvent(this, selectedVariantIndex));
            this.TrigEvent(new RcnArticleVariantEvent(this, this.articleElement.selectedIndex, selectedVariantIndex));
        }
        else {
            var oldVariantIndex = document.getElementById('RcnVariantIndex').value;
            var selectedVariantIndex = 0;
            if (this.articleElement.selectedIndex > 0)
                selectedVariantIndex = 1;

            // Store the variantIndex
            SaveVariantIndexToViewState(selectedVariantIndex);

            if (oldVariantIndex != selectedVariantIndex) {
                // Trigger events
                this.TrigEvent(new RcnVariantEvent(this, selectedVariantIndex));
                this.TrigEvent(new RcnArticleVariantEvent(this, this.articleElement.selectedIndex, selectedVariantIndex));
            }
        }
    }
}

///////////////////////////////////////////////////////////////////////////////
// RcnDivMatchSet    Test class attach to the MatchSet <div>
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnDivMatchSet, RcnElementEventSubscriber);

function RcnDivMatchSet(id) {
    if (arguments.length)
        this.InitInstance(id);
}

RcnDivMatchSet.prototype.InitInstance = function(id) {
    RcnDivMatchSet.baseClass.InitInstance.call(this, id);
}

RcnDivMatchSet.prototype.HandleEvent = function(eventObj) {
    if (eventObj.ClassName() == "RcnArticleEvent") {
        RenderMatchSet(eventObj.ArticleIndex(), this.Element().id);
    }
}

///////////////////////////////////////////////////////////////////////////////
// RcnArticleDisplay
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnArticleDisplay, RcnElementEventSubscriber);

function RcnArticleDisplay(id) {
    if (arguments.length)
        this.InitInstance(id);
}

RcnArticleDisplay.prototype.InitInstance = function(id) {
    RcnArticleDisplay.baseClass.InitInstance.call(this, id);
}

RcnArticleDisplay.prototype.HandleEvent = function(eventObj) {
    if (eventObj.ClassName() == "RcnArticleEvent") {
        RenderArticleDisplay(eventObj.ArticleIndex());
    }

    if (eventObj.ClassName() == "RcnArticleOnMouseOverEvent") {
        RenderArticleDisplay(eventObj.ArticleIndex());
    }

    if (eventObj.ClassName() == "RcnArticleOnMouseOutEvent") {
        // call RenderArticleDisplay() without parameters to reset text.
        RenderArticleDisplay();
    }
}

///////////////////////////////////////////////////////////////////////////////
// RcnProductImage      Class attach to the RcnProductImage control <a><img /></a>
// parameters:          htmlAnchorId: the element id of <a> surrounding the <img> product image.
//                      htmlImageId:  the element id of <img> the product image.
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnProductImage, RcnElementEventSubscriber);

function RcnProductImage(htmlAnchorId, htmlImageId) {
    if (arguments.length)
        this.InitInstance(htmlAnchorId, htmlImageId);
}

RcnProductImage.prototype.InitInstance = function(htmlAnchorId, htmlImageId) {
    RcnProductImage.baseClass.InitInstance.call(this, htmlAnchorId, htmlImageId);
    this.htmlAnchorElement = document.getElementById(htmlAnchorId);
    this.htmlImageElement = document.getElementById(htmlImageId);
}

RcnProductImage.prototype.HandleEvent = function(eventObj) {
    if (eventObj.ClassName() == "RcnArticleEvent") {
        RenderProductImage(eventObj.ArticleIndex(), this.htmlAnchorElement.id, this.htmlImageElement.id);
    }
}

///////////////////////////////////////////////////////////////////////////////
// RcnPriceCommunicator  Class attach to the Price Communicator on DetailPage   
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnPriceCommunicator, RcnElementEventSubscriber);

function RcnPriceCommunicator(id) {
    if (arguments.length)
        this.InitInstance(id);
}

RcnPriceCommunicator.prototype.InitInstance = function(id) {
    RcnPriceCommunicator.baseClass.InitInstance.call(this, id);
}

RcnPriceCommunicator.prototype.HandleEvent = function(eventObj) {
    if (eventObj.ClassName() == "RcnArticleEvent") {
        RenderPriceInfo();
        RenderArticleNo(eventObj.ArticleIndex());
    }

    if (eventObj.ClassName() == "RcnVariantEvent") {
        RenderPriceInfo();
    }

    if (eventObj.ClassName() == "RcnArticleVariantEvent") {
        RenderPriceInfo();
        RenderArticleNo(eventObj.ArticleIndex());
    }
}

///////////////////////////////////////////////////////////////////////////////
// RcnAvailability  
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnAvailability, RcnElementEventSubscriber);

function RcnAvailability(id) {
    if (arguments.length)
        this.InitInstance(id);
}

RcnAvailability.prototype.InitInstance = function(id) {
    RcnAvailability.baseClass.InitInstance.call(this, id);
}

RcnAvailability.prototype.HandleEvent = function(eventObj) {
    if (eventObj.ClassName() == "RcnArticleEvent") {
        RenderAvailability();
    }

    if (eventObj.ClassName() == "RcnVariantEvent") {
        RenderAvailability();
    }

    if (eventObj.ClassName() == "RcnArticleVariantEvent") {
        RenderAvailability();
    }
}


/** Event Section ***********************************************************/

///////////////////////////////////////////////////////////////////////////////
// RcnArticleEvent    
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnArticleEvent, RcnEvent);

function RcnArticleEvent(src, articleIndex) {
    if (arguments.length)
        this.InitInstance(src, articleIndex);
}

RcnArticleEvent.prototype.InitInstance = function(src, articleIndex) {
    RcnArticleEvent.baseClass.InitInstance.call(this, src);
    this.articleIndex = articleIndex;
}

RcnArticleEvent.prototype.ArticleIndex = function() {
    //set
    if (arguments.length)
        this.articleIndex = arguments[0];

    //get
    return this.articleIndex;
}

///////////////////////////////////////////////////////////////////////////////
// RcnVariantEvent    
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnVariantEvent, RcnEvent);

function RcnVariantEvent(src, variantIndex) {
    if (arguments.length)
        this.InitInstance(src, variantIndex);
}

RcnVariantEvent.prototype.InitInstance = function(src, variantIndex) {
    RcnVariantEvent.baseClass.InitInstance.call(this, src);
    this.variantIndex = variantIndex;
}

RcnVariantEvent.prototype.VariantIndex = function() {
    //set
    if (arguments.length)
        this.variantIndex = arguments[0];

    //get
    return this.variantIndex;
}

///////////////////////////////////////////////////////////////////////////////
// RcnArticleVariantEvent    
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnArticleVariantEvent, RcnEvent);

function RcnArticleVariantEvent(src, articleIndex, variantIndex) {
    if (arguments.length)
        this.InitInstance(src, articleIndex, variantIndex);
}

RcnArticleVariantEvent.prototype.InitInstance = function(src, articleIndex, variantIndex) {
    RcnArticleVariantEvent.baseClass.InitInstance.call(this, src);
    this.articleIndex = articleIndex;
    this.variantIndex = variantIndex;
}

RcnArticleVariantEvent.prototype.ArticleIndex = function() {
    //set
    if (arguments.length)
        this.articleIndex = arguments[0];

    //get
    return this.articleIndex;
}

RcnArticleVariantEvent.prototype.VariantIndex = function() {
    //set
    if (arguments.length)
        this.variantIndex = arguments[0];

    //get
    return this.variantIndex;
}

///////////////////////////////////////////////////////////////////////////////
// RcnArticleOnMouseOverEvent    
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnArticleOnMouseOverEvent, RcnEvent);

function RcnArticleOnMouseOverEvent(src, articleIndex) {
    if (arguments.length)
        this.InitInstance(src, articleIndex);
}

RcnArticleOnMouseOverEvent.prototype.InitInstance = function(src, articleIndex) {
    RcnArticleOnMouseOverEvent.baseClass.InitInstance.call(this, src);
    this.articleIndex = articleIndex;
}

RcnArticleOnMouseOverEvent.prototype.ArticleIndex = function() {
    //set
    if (arguments.length)
        this.articleIndex = arguments[0];

    //get
    return this.articleIndex;
}

///////////////////////////////////////////////////////////////////////////////
// RcnArticleOnMouseOutEvent    
///////////////////////////////////////////////////////////////////////////////
RcnClientFx.CopyPrototype(RcnArticleOnMouseOutEvent, RcnEvent);

function RcnArticleOnMouseOutEvent(src, articleIndex) {
    if (arguments.length)
        this.InitInstance(src, articleIndex);
}

RcnArticleOnMouseOutEvent.prototype.InitInstance = function(src, articleIndex) {
    RcnArticleOnMouseOutEvent.baseClass.InitInstance.call(this, src);
    this.articleIndex = articleIndex;
}

RcnArticleOnMouseOutEvent.prototype.ArticleIndex = function() {
    //set
    if (arguments.length)
        this.articleIndex = arguments[0];

    //get
    return this.articleIndex;
}

function ChangeToAlternateProductImage(fullpath, image, zoomImgPath) {
    if (!rcnProductImage)
        return false;
    var objImg = rcnProductImage.htmlImageElement;
    var cssValue = 'url(' + fullpath + ')';
    objImg.src = fullpath;

    $('.bigImage').css('background-image', cssValue);

    $('.bigImage').unbind('click').click(function() {
        PopupZoom(image);
    });
    
    var maxlbls = 4;
    var index = 1;
    for (index = 1; index < (maxlbls + 1); index++) {
        var lbl = getLabelPos(index);
        if (lbl != null) {
            lbl.style.display = '';
        }
    }

    return true;
}

function showVideo(videoType, Url, Control) {
    if (videoType == 'ThreeSixty') {
        s.tl(this, 'o', 'ThreeSixtyPlay');
        mboxUpdate('LaRedouteThreeSixtyClick');
    } else {
        s.tl(this, 'o', 'CatwalkPlay');
        mboxUpdate('LaRedouteCatwalkClick');
    }

    if (videoType == 'ThreeSixty') {
        var layer = new SWFObject("http://media.redcatsnordic.com/laredoute/movies/s3dplayer.swf?nocache=" + Math.random(), "threesixty", "400", "400", "9", "#ffffff");
        layer.addVariable("imageArch", Url);
    } else {
    var layer = new SWFObject("http://media.redcatsnordic.com/laredoute/movies/laredoute_catwalk_player.swf", "catwalk", "400", "400", "9", "#FFFFFF");
        layer.addVariable("videoURL", Url);
    }
    layer.addParam("wmode", "window");
    layer.addParam("allowScriptAccess", "sameDomain");
    layer.addParam("align", "middle");
    layer.addParam("scale", "showall");
    layer.addParam("allowFullScreen", "true");
    layer.write('productVideo');

    $('.productVideo').fadeIn("slow");
}

function InitAndSetVariant(articleSelectId, variantSelectId) {
    var selArt = document.getElementById(articleSelectId);
    var selVar = document.getElementById(variantSelectId);

    if (selArt != null && selVar != null) {
        // If an article is selected and variants are not initialized
        if (selArt.selectedIndex != 0 && selVar.options.length <= 1) {
            // store variantindex from hidden control because it gets 
            // overwritten in the onchange event
            var variantIndex = document.getElementById('RcnVariantIndex').value;

            // trigger onchange event to init variant dropdown
            selArt.onchange();
            if (selVar.options.length == 2)
                variantIndex = 1;
            selVar.selectedIndex = variantIndex;
        }
    }
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();