﻿/**
 * Search configurator element client-side script
 *
 * @author: Natalie Vegerina nvegerina@infostroy.com.ua
 **/
var SearchConfiguratorElement = {
    init : function(nothingSelestedText, andText)
    {
        this.nothingSelected = nothingSelestedText;
        this.and = andText;
    },
    init2 : function(nothingSelestedText, andText, fromText, toText)
    {
        this.nothingSelected = nothingSelestedText;
        this.and = andText;
        this.from = fromText;
        this.to = toText;
    },
    radioButtonSelectionChanged : function(buttonName, elementId)
    {
        var html = " | ";
        var element = document.getElementById(elementId);
	    var buttons = document.getElementsByName(buttonName);
        for(var i=0; i<buttons.length; i++)
        {
            var button = buttons.item(i);
            if(button.checked)
            {
                if(button.nextSibling.innerHTML == this.nothingSelected)
                {
                    html += button.nextSibling.innerHTML;
                }
                else
                {
                    html += "<b>" + button.nextSibling.innerHTML + "</b>";
                }
                break;
            }
        }
            
        element.innerHTML = html;
    },
    checkBoxSelectionChanged : function(array, elementId)
    {
        var selections = Array();
        var html = " | ";
		var element = document.getElementById(elementId);
        for(var i=0; i<array.length; i++)
        {
            var box = document.getElementById(array[i]);
            if(box.checked)
            {
                selections.push(box.nextSibling.innerHTML);
            }
        }
        
        if(selections.length == 0)
        {
            html += this.nothingSelected;
        }
        else
        {
            for(var i=0; i<selections.length; i++)
            {
                if(i == selections.length-1 && selections.length > 1)
                {
                    html += " " + this.and + " ";
                }
                else
                {
                    if(i > 0)
                    {
                        html += ", ";
                    }
                }
                
                html += "<b>" + selections[i] + "</b>"
            }
        }
        
        element.innerHTML = html;
    },
    priceSelectionChanged : function(fromBoxId, toBoxId, elementId)
    {
        var html = " | ";
		var fromBox = document.getElementById(fromBoxId);
		var toBox = document.getElementById(toBoxId);
		var element = document.getElementById(elementId);
		if(fromBox.value != "0" && fromBox.value != null && fromBox.value != "")
		{
		    html += this.from + " <b>" + fromBox.value + "</b> EUR "
		}
		
		if(toBox.value != "0" && toBox.value != null && toBox.value != "")
		{
		    html += this.to + " <b>" + toBox.value + "</b> EUR"
		}
		
		if(html == " | ")
		{
		    html += this.nothingSelected;
		}
		
        element.innerHTML = html;
    }
};
