HsaProductSelector.prototype._methodName = 'tilausvalitsin-1';

HsaProductSelector.prototype.mustSubmit = function() {
	var qs = 'inputIds=' + this.inputIds.join(',');
        for (var i=0 ; i<=this.inputIds.length-1 ; i++ ) {
			var z = this.inputIds[i];
			var ele = document.getElementById(z);
			qs += '&' + ele.name + '=' + ele.value;
	}

	jQuery.ajax(Hsa.form._ajaxRequestOptionsJ(Hsa.config.backendpath + this._methodName + '.xml', qs));
};

HsaProductSelector.prototype.ii = function(desc, id, width, size) {
    var $anc = jQuery('<a>');
	//var anc = document.createElement('A');

    $anc.attr('href', '#');
    $anc.addClass('button buttonPS')
    switch(width) {
        case 'wide': $anc.addClass('buttonPSWide'); break;
        case 'medium': $anc.addClass('buttonPSMedium'); break;
        case 'narrow': $anc.addClass('buttonPSNarrow'); break;
        default: $anc.addClass('buttonPSMedium'); break;
    }
    
    if (size == 'big') {
	    $anc.addClass('buttonPSBig');
	}
	$anc.html(desc);
	$anc.attr('id', 'productSelector_' + id);
	$anc[0].productSelectorValue = id;
	$anc.attr('productSelectorState', 'unchecked');
	$anc[0].productSelectorObject = this;
    
    /*
	anc.href='#';
	anc.className = 'button buttonPS';
    switch(width) {
        case 'wide': anc.className += ' buttonPSWide'; break;
        case 'medium': anc.className += ' buttonPSMedium'; break;
        case 'narrow': anc.className += ' buttonPSNarrow'; break;
        default: anc.className += ' buttonPSMedium'; break;
    }
    
	if (size == 'big') {
	    anc.className += ' buttonPSBig';
	}
	anc.innerHTML = desc;
	anc.id = 'productSelector_' + id;
	anc.productSelectorValue = id;
	anc.setAttribute('productSelectorState', 'unchecked');
	anc.productSelectorObject = this;
	*/
	
	/*
	img.className='productButton';
	img.setAttribute('productSelectorImg', src)
	img.setAttribute('productSelectorState', 'unchecked');
	img.src = '/img/tilaus_' + src + '_unchecked' + '.gif';
	img.id = 'productSelector_' + id;
	img.productSelectorValue = id;
	img.style.display = 'none';

	img.productSelectorObject = this;
	*/
    
    /*
	anc.onclick = function() {  
        var inputElem = document.getElementById(this.getAttribute('productSelectorGoesTo'));
        if (!inputElem)
            alert('Input element ' + this.getAttribute('productSelectorGoesTo') + ' is missing.');
        inputElem.value = this.productSelectorValue; // getAttribute('productSelectorState');
        if (this.getAttribute('productSelectorState') != 'checked') {
            this.setAttribute('productSelectorState', 'checked');
            this.className += ' buttonPSActive';
        } else {
            this.setAttribute('productSelectorState', 'unchecked');
        }
        this.productSelectorObject.mustSubmit();
        return false;
    };
	return anc;
	*/
	
	$anc.click(function() {  
	    if (jQuery(this).attr('productSelectorState') == 'disabled') {
	        return false;
	    }
        var inputElem = document.getElementById(jQuery(this).attr('productSelectorGoesTo'));
        if (!inputElem)
            alert('Input element ' + jQuery(this).attr('productSelectorGoesTo') + ' is missing.');
        inputElem.value = this.productSelectorValue; // getAttribute('productSelectorState');
        if (jQuery(this).attr('productSelectorState') != 'checked') {
            jQuery(this).attr('productSelectorState', 'checked');
            jQuery(this).addClass('buttonPSActive');
        } else {
            jQuery(this).attr('productSelectorState', 'unchecked');
            jQuery(this).removeClass('buttonPSActive');
        }
        this.productSelectorObject.mustSubmit();
        return false;
    });
	return $anc[0];
}

HsaProductSelector.prototype._init_included__createProduct = function(id, imgsrc) {
	var deh = document.createElement('A');
	deh.className = 'product fC';
	deh.setAttribute('href', '/tuoteperhe/hs/lightbox_example.html');
	deh.id = id;
	
	deh.appendChild(document.createElement('H5'));
	deh.lastChild.id = id + '_bubbleContent_title';
	deh.lastChild.className = 'infoBoxTitle';
	
	deh.appendChild(document.createElement('IMG'));
	var img = deh.lastChild;
	deh.lastChild.id = id + "_bubbleContent_img";
	deh.lastChild.src = '/img/productselector_infobox_' + imgsrc + '.png';
	deh.lastChild.setAttribute('productSelectorState', 'disabled');
	deh.lastChild.setAttribute('productSelectorImg', imgsrc);
	deh.lastChild.setAttribute('productType', 'lehti');
	deh.lastChild.setAttribute('productExt', 'jpg');
	deh.lastChild.className = 'product-image';
	
	deh.appendChild(document.createElement('IMG'));
	deh.lastChild.src = '/img/productselector_infobox_readmore.png';
	deh.lastChild.className = 'read-more';
	
	deh.appendChild(document.createElement('P'));
	deh.lastChild.className = 'infoBoxContent';
	deh.lastChild.id = id + '_bubbleContent_p';
	
	
	
	/*
	deh.lastChild.onmouseover = function(e) {
						if (this.parentNode.lastChild.lastChild.hsaReady) {
							this.parentNode.lastChild.lastChild.style.display = 'block';
						}
					}
	deh.lastChild.onmouseout = function() {
						this.parentNode.lastChild.lastChild.style.display = 'none';
					}
    */
    /*
	deh.appendChild(document.createElement('SPAN'));
	deh.lastChild.style.bottom = '148px';
	deh.lastChild.style.left = '40px';
	deh.lastChild.className='infoBoxWrapper';
	deh.lastChild.appendChild(document.createElement('SPAN'));
	deh.lastChild.lastChild.id='infoBoxProduct_' + id;
	deh.lastChild.lastChild.hsaImgRef = img;
	deh.lastChild.lastChild.className='infoBox';
	deh.lastChild.lastChild.style.display = 'none';

	deh.lastChild.lastChild.appendChild(document.createElement('SPAN')); // infoBoxTitle
	deh.lastChild.lastChild.lastChild.id = 'infoBoxProduct_' + id + '_bubbleContent_title';
	deh.lastChild.lastChild.lastChild.className = 'infoBoxTitle';
	
	deh.lastChild.lastChild.appendChild(document.createElement('SPAN'));
	deh.lastChild.lastChild.lastChild.className = 'infoBoxContent';
	deh.lastChild.lastChild.lastChild.id = 'infoBoxProduct_' + id + '_bubbleContent_p';
    */
    
	return deh;
};

/*
HsaProductSelector.prototype._init_included__createSmallProduct = function(id, imgsrc) {
	var deh = document.createElement('DIV');
	deh.className = 'section';
	deh.appendChild(document.createElement('IMG'));
	deh.lastChild.id = id;
	deh.lastChild.src = '/img/tilaus_osasto_' + imgsrc + '_disabled.gif';
	deh.lastChild.setAttribute('productSelectorState', 'disabled');
	deh.lastChild.setAttribute('productSelectorImg', imgsrc);
	deh.lastChild.setAttribute('productType', 'osasto');
	deh.lastChild.setAttribute('productExt', 'gif');
	deh.lastChild.onmouseover = function(e) {
						if (this.parentNode.lastChild.lastChild.hsaReady) {
							this.parentNode.lastChild.lastChild.style.display = 'block';
						}
					}
	deh.lastChild.onmouseout = function() {
						this.parentNode.lastChild.lastChild.style.display = 'none';
					}
	deh.appendChild(document.createElement('SPAN'));
	deh.lastChild.style.bottom = '30px';
	deh.lastChild.style.left = '40px';
	deh.lastChild.className='infoBoxWrapper';
	deh.lastChild.appendChild(document.createElement('SPAN'));
	deh.lastChild.lastChild.id='infoBoxProduct_' + id;
	deh.lastChild.lastChild.className='infoBox';
	deh.lastChild.lastChild.style.display = 'none';

	deh.lastChild.lastChild.appendChild(document.createElement('SPAN')); // infoBoxTitle
	deh.lastChild.lastChild.lastChild.id = 'infoBoxProduct_' + id + '_bubbleContent_title';
	deh.lastChild.lastChild.lastChild.className = 'infoBoxTitle';

	deh.lastChild.lastChild.appendChild(document.createElement('SPAN'));
	deh.lastChild.lastChild.lastChild.className = 'infoBoxContent';
	deh.lastChild.lastChild.lastChild.id = 'infoBoxProduct_' + id + '_bubbleContent_p';

	return deh;
};
*/

HsaProductSelector.prototype.init_included = function(putInsideDiv) {
	var epo = putInsideDiv;

    epo.appendChild(document.createElement('DIV'));
	epo.lastChild.id = 'selectedProducts';
	epo.lastChild.className = 'fC';
	
	epo.lastChild.appendChild(document.createElement('H4'));
	epo.lastChild.lastChild.appendChild(document.createTextNode('Tilaukseen sisältyy'));

	epo.lastChild.appendChild(this._init_included__createProduct('infoBoxProduct_productSelector_included_product_hs', 'hs'));
	epo.lastChild.appendChild(this._init_included__createProduct('infoBoxProduct_productSelector_included_product_nyt', 'nyt'));
	epo.lastChild.appendChild(this._init_included__createProduct('infoBoxProduct_productSelector_included_product_kl', 'kl'));
	epo.lastChild.appendChild(this._init_included__createProduct('infoBoxProduct_productSelector_included_product_digi', 'digi'));

    /*
	epo.appendChild(document.createElement('DIV'));
	epo.lastChild.id = 'sectionImagesContainer';
	epo.lastChild.className = 'fC';

	epo.lastChild.appendChild(this._init_included__createSmallProduct('productSelector_included_product_elamajaterveys', 'elama_ja_terveys'));
	epo.lastChild.appendChild(this._init_included__createSmallProduct('productSelector_included_product_tiedejaluonto', 'tiede_ja_luonto'));
	epo.lastChild.appendChild(this._init_included__createSmallProduct('productSelector_included_product_hintajalaatu', 'hinta_ja_laatu'));
	epo.lastChild.appendChild(this._init_included__createSmallProduct('productSelector_included_product_ruokajajuoma', 'ruoka_ja_juoma'));
//	epo.lastChild.appendChild(this._init_included__createSmallProduct('productSelector_included_product_kotijatyyli', 'koti_ja_tyyli'));
	epo.lastChild.appendChild(this._init_included__createSmallProduct('productSelector_included_product_menojapaluu', 'meno_ja_paluu'));
	epo.lastChild.appendChild(this._init_included__createSmallProduct('productSelector_included_product_auto', 'auto'));
	epo.lastChild.appendChild(this._init_included__createSmallProduct('productSelector_included_product_talous', 'talous'));
	epo.lastChild.appendChild(this._init_included__createSmallProduct('productSelector_included_product_asunto', 'asunto'));
	epo.lastChild.appendChild(this._init_included__createSmallProduct('productSelector_included_product_sunnuntai', 'sunnuntai'));
	*/
};

HsaProductSelector.prototype.init_subscriptionPrice = function(putInsideDiv) {
	var epo = putInsideDiv;

    epo.appendChild(document.createElement('DIV'));
	epo.lastChild.id = 'subscriptionPrice';
	epo.lastChild.className = 'fC';
	
	epo.lastChild.appendChild(document.createElement('H4'));
	epo.lastChild.lastChild.appendChild(document.createTextNode('Kokonaishinta'));
	
	epo.lastChild.appendChild(document.createElement('SPAN'));
	epo.lastChild.lastChild.className = 'price';
	epo.lastChild.lastChild.appendChild(document.createTextNode('325 €'));
	
	epo.lastChild.appendChild(document.createElement('SPAN'));
	epo.lastChild.lastChild.className = 'monthly';
	epo.lastChild.lastChild.appendChild(document.createTextNode('(18€/kk)'));

	/*
	epo.lastChild.appendChild(document.createElement('A'));
	epo.lastChild.lastChild.id = "subscriptionInfo_backButton";
	epo.lastChild.lastChild.className = 'button buttonStrong buttonLarge buttonBack';
	epo.lastChild.lastChild.setAttribute("href", "javascript:Hsa.form.setPhase('mainForm', '1'); Hsa.form.submitFormB(document.getElementById('mainForm'), document.getElementById('subscriptionInfo_backButton'));");
	epo.lastChild.lastChild.appendChild(document.createTextNode('Muokkaa tilaustasi'));
	*/

	epo.lastChild.appendChild(document.createElement('A'));
	epo.lastChild.lastChild.id = "subscriptionInfo_continueButton";
	epo.lastChild.lastChild.className = 'button buttonStrong buttonLarge';
	epo.lastChild.lastChild.setAttribute("href", "javascript:Hsa.form.submitFormB(document.getElementById('mainForm'), this);");
	epo.lastChild.lastChild.appendChild(document.createTextNode('Tilaa'));

	epo.lastChild.appendChild(document.createElement('DIV'));
	epo.lastChild.lastChild.className = 'free-text';
	epo.lastChild.lastChild.appendChild(document.createTextNode(''));

	epo.lastChild.appendChild(document.createElement('P'));
	epo.lastChild.lastChild.appendChild(document.createTextNode(''));
	
	/*
	epo.lastChild.appendChild(document.createElement('DIV'));
	epo.lastChild.className = 'clear'
	*/
	
};

HsaProductSelector.prototype.init = function(putInsideDiv, inputIds, methodName) {
	this.inputIds = inputIds;
	this._methodName = methodName;
	var epo = putInsideDiv;

    epo.appendChild(document.createElement('DIV'));
    epo.lastChild.className='basicContainer selectProductContainer';
    epo = epo.lastChild;

	epo.appendChild(document.createElement('DIV'));
	//epo.lastChild.className='columns fC';

	epo.lastChild.appendChild(document.createElement('DIV'));
	epo.lastChild.lastChild.id = 'selectProductType';
	epo.lastChild.lastChild.className = 'selectProductBlock';
	var selectProductType = epo.lastChild.lastChild;
	selectProductType.appendChild(document.createElement('H4'));
	selectProductType.lastChild.className='fC';
	selectProductType.lastChild.appendChild(document.createElement('SPAN'));
	selectProductType.lastChild.lastChild.className='step';
	selectProductType.lastChild.lastChild.appendChild(document.createTextNode('1'));
	selectProductType.lastChild.appendChild(document.createTextNode('Valitse tuote'));
	selectProductType.appendChild(this.ii('Helsingin Sanomat + HS Digilehti', 'prod_hs24', 'wide', 'big'));
	selectProductType.appendChild(this.ii('Helsingin Sanomat', 'prod_hs', 'normal', 'big'));
	selectProductType.appendChild(this.ii('HS Digilehti', 'prod_hsdigi', 'normal', 'big'));

	selectProductType.appendChild(document.createElement('DIV'));
	selectProductType.lastChild.className='clear';

	epo.lastChild.appendChild(document.createElement('DIV'));
	epo.lastChild.lastChild.id = 'selectSubscriptionDay';
	epo.lastChild.lastChild.className = 'selectProductBlock';
	var selectSubscriptionDay = epo.lastChild.lastChild;
	selectSubscriptionDay.appendChild(document.createElement('H4'));
	selectSubscriptionDay.lastChild.id = 'productSelector_title_subscriptionDay';
	selectSubscriptionDay.lastChild.appendChild(document.createElement('SPAN'));
	selectSubscriptionDay.lastChild.lastChild.appendChild(document.createTextNode('2'));
	selectSubscriptionDay.lastChild.lastChild.className='step';
	selectSubscriptionDay.lastChild.appendChild(document.createTextNode('Valitse tilauspäivät'));

	selectSubscriptionDay.appendChild(document.createElement('P'));
	selectSubscriptionDay.lastChild.className='disabledText';
	selectSubscriptionDay.lastChild.id='productSelector_days_disabledText';
	selectSubscriptionDay.lastChild.style.display = 'none';
	selectSubscriptionDay.lastChild.appendChild(document.createTextNode('')); //possible note text for disabled selectSubscriptionDay (now left empty)
	selectSubscriptionDay.appendChild(this.ii('7 päivänä viikossa', 'days_7', 'normal'));
	selectSubscriptionDay.appendChild(this.ii('Perjantai &ndash; Sunnuntai', 'days_pelasu', 'normal'));
	selectSubscriptionDay.appendChild(this.ii('Lauantai &ndash; Sunnuntai', 'days_lasu', 'normal'));
	selectSubscriptionDay.appendChild(this.ii('Sunnuntai', 'days_su', 'normal'));
	selectSubscriptionDay.appendChild(this.ii('Perjantai', 'days_pe', 'normal'));

	selectSubscriptionDay.appendChild(document.createElement('DIV'));
	selectSubscriptionDay.lastChild.className='clear';

	epo.appendChild(document.createElement('DIV'));
	epo.lastChild.className='columns fC';

	epo.lastChild.appendChild(document.createElement('DIV'));
	epo.lastChild.lastChild.id = 'selectSubscriptionType';
	epo.lastChild.lastChild.className = 'selectProductBlock';
	var selectSubscriptionType = epo.lastChild.lastChild;
	selectSubscriptionType.appendChild(document.createElement('H4'));
	selectSubscriptionType.lastChild.id = 'productSelector_title_subscriptionType';
	selectSubscriptionType.lastChild.appendChild(document.createElement('SPAN'));
	selectSubscriptionType.lastChild.lastChild.appendChild(document.createTextNode('3'));
	selectSubscriptionType.lastChild.lastChild.className='step';
	selectSubscriptionType.lastChild.appendChild(document.createTextNode('Valitse tilausmuoto'));
	
	/*
	selectSubscriptionType.appendChild(document.createElement('A'));
	selectSubscriptionType.lastChild.className='read-more lightbox';
	selectSubscriptionType.lastChild.setAttribute('href','/tilaus/lisatietoja_tilausmuoto.html');
	selectSubscriptionType.lastChild.appendChild(document.createTextNode('Lue lisää'));
	*/

	selectSubscriptionType.appendChild(document.createElement('P'));
	selectSubscriptionType.lastChild.className='disabledText';
	selectSubscriptionType.lastChild.id='productSelector_type_disabledText';
	selectSubscriptionType.lastChild.style.display = 'none';
	selectSubscriptionType.lastChild.appendChild(document.createTextNode('')); //possible note text for disabled selectSubscriptionType (now left empty)
	selectSubscriptionType.appendChild(this.ii('Jatkuva tilaus', 'type_jatkuva', 'normal'));
	selectSubscriptionType.appendChild(this.ii('Määräaikaistilaus', 'type_fixed', 'normal'));

	selectSubscriptionType.appendChild(document.createElement('DIV'));
	selectSubscriptionType.lastChild.className='clear';

	epo.lastChild.appendChild(document.createElement('DIV'));
	epo.lastChild.lastChild.id = 'selectSubscriptionMonth';
	epo.lastChild.lastChild.className = 'selectProductBlock';
	var selectSubscriptionMonth = epo.lastChild.lastChild;
	selectSubscriptionMonth.appendChild(document.createElement('H4'));
	selectSubscriptionMonth.lastChild.id = 'productSelector_title_subscriptionMonth';
	selectSubscriptionMonth.lastChild.appendChild(document.createElement('SPAN'));
	selectSubscriptionMonth.lastChild.lastChild.appendChild(document.createTextNode('4'));
	selectSubscriptionMonth.lastChild.lastChild.className='step';
	selectSubscriptionMonth.lastChild.appendChild(document.createElement('SPAN'));
	selectSubscriptionMonth.lastChild.lastChild.id = 'productSelector_m_4title';
	selectSubscriptionMonth.lastChild.lastChild.appendChild(document.createTextNode('Valitse laskutusväli'));

	/*
    selectSubscriptionMonth.appendChild(document.createElement('A'));
	selectSubscriptionMonth.lastChild.className='read-more lightbox';
	selectSubscriptionMonth.lastChild.setAttribute('href','/tilaus/lisatietoja_laskutusjakso.html');
	selectSubscriptionMonth.lastChild.appendChild(document.createTextNode('Lue lisää'));
	*/

	selectSubscriptionMonth.appendChild(document.createElement('P'));
	selectSubscriptionMonth.lastChild.className='disabledText';
	selectSubscriptionMonth.lastChild.id='productSelector_m_disabledText';
	selectSubscriptionMonth.lastChild.style.display = 'none';
	selectSubscriptionMonth.lastChild.appendChild(document.createTextNode('')); //possible note text for disabled selectSubscriptionMonth (now left empty)
	selectSubscriptionMonth.appendChild(this.ii('1 kk', 'm_1', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('2 kk', 'm_2', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('3 kk', 'm_3', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('4 kk', 'm_4', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('5 kk', 'm_5', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('6 kk', 'm_6', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('7 kk', 'm_7', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('8 kk', 'm_8', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('9 kk', 'm_9', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('10 kk', 'm_10', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('11 kk', 'm_11', 'narrow'));
	selectSubscriptionMonth.appendChild(this.ii('12 kk', 'm_12', 'narrow'));

	selectSubscriptionMonth.appendChild(document.createElement('DIV'));
	selectSubscriptionMonth.lastChild.className='clear';

	epo.appendChild(document.createElement('P'));
	epo.lastChild.id = 'productSelector_footerText';
	epo.lastChild.style.display = 'none';

	this.init_included(putInsideDiv);
	this.init_subscriptionPrice(putInsideDiv);
  };

HsaProductSelector.prototype._processEach = function (xmlElemNodes, goesTo) {
    for (var i=0 ; i<=xmlElemNodes.length-1 ; i++ ) {
        var responseElement = xmlElemNodes[i];
        
        if ( responseElement.nodeType != 1 )
            continue;

        var elemId = responseElement.nodeName;
        var elemState = responseElement.getAttribute('state');
        
        var $domNode = jQuery('#productSelector_' + elemId);
        if ($domNode.length == 0) {
            continue;
        }
        
        if (elemState == 'hidden') {
            $domNode.css('display','none');
            $domNode.attr('productSelectorState', 'hidden');
        } else if (elemState == 'disabled' || elemState == 'unchecked' || elemState == 'checked') {
            $domNode.css('display', 'block');
            $domNode.css('float', 'left');
            $domNode.attr('productSelectorState', elemState);
            if (elemState == 'disabled') {
                $domNode.addClass('buttonPSInactive');
                $domNode.attr('href', 'javascript:;')
            } else if (elemState == 'unchecked') {
                /*
                if (elemId == 'days_7') {
                    jQuery('#selectedProducts').show();
                    jQuery('#subscriptionInfo1').show();
                }
                */
                $domNode.removeClass('buttonPSInactive')
                $domNode.removeClass('buttonPSActive');
            } else if (elemState == 'checked') {
                $domNode.removeClass('buttonPSInactive')
                $domNode.addClass('buttonPSActive');
            }
        }
        
        
        
        if (elemId == 'days_disabledText') {
            if (elemState == 'hidden')
                jQuery('#productSelector_title_subscriptionDay').removeClass('disabled');
            else
                jQuery('#productSelector_title_subscriptionDay').addClass('disabled');
    
        } else if (elemId == 'type_disabledText') {
            if (elemState == 'hidden')
                jQuery('#productSelector_title_subscriptionType').removeClass('disabled');
            else
                jQuery('#productSelector_title_subscriptionType').addClass('disabled');
    
        } else if (elemId == 'm_disabledText') {
            if (elemState == 'hidden')
                jQuery('#productSelector_title_subscriptionMonth').removeClass('disabled');
            else
                jQuery('#productSelector_title_subscriptionMonth').addClass('disabled');
    
        } else if (elemId == 'm_4title') {
                document.getElementById('productSelector_m_4title').removeChild(document.getElementById('productSelector_m_4title').lastChild);
                document.getElementById('productSelector_m_4title').appendChild(document.createTextNode(responseElement.firstChild.nodeValue));
        } else {
            if ($domNode.attr('productSelectorState') != 'hidden')
                $domNode.attr('productSelectorGoesTo', goesTo);
                //jQuery('#selectedProducts').show();
                //jQuery('#subscriptionInfo1').show();
        }
    }
};

HsaProductSelector.prototype._processProductSelectorResponse = function (xmlElem) {
		var productType = xmlElem.getElementsByTagName('productType')[0];
		var subscriptionDay = xmlElem.getElementsByTagName('subscriptionDay')[0];
		var subscriptionType = xmlElem.getElementsByTagName('subscriptionType')[0];
		var subscriptionMonth = xmlElem.getElementsByTagName('subscriptionMonth')[0];
        
        //console.log(productType)
        
        //if (productType) {
            
        //}
    
		if (productType.childNodes)
			this._processEach(productType.childNodes, productType.getAttribute('goesTo'));
		if (subscriptionDay.childNodes)
			this._processEach(subscriptionDay.childNodes, subscriptionDay.getAttribute('goesTo'));
		if (subscriptionType)
			this._processEach(subscriptionType.childNodes, subscriptionType.getAttribute('goesTo'));
		if (subscriptionMonth)
			this._processEach(subscriptionMonth.childNodes, subscriptionMonth.getAttribute('goesTo'));
	};


HsaProductSelector.prototype._processIncludedResponse = function (responseElement) {
		var xmlElemNodes = responseElement.childNodes;
	        for (var i=0 ; i<=xmlElemNodes.length-1 ; i++ ) {
                        var responseElement = xmlElemNodes[i];

                        if ( responseElement.nodeType != 1 )
				continue;

			var elemId = responseElement.nodeName;
			var elemState = responseElement.getAttribute('state');

			var domNode = document.getElementById('infoBoxProduct_productSelector_included_' + elemId);
			if (!domNode)
				continue;
            
			
			if (elemState == 'disabled') {
				//domNode.style.display = 'none';
				jQuery(domNode).addClass('disabled')
				domNode.setAttribute('productSelectorState', 'disabled');
			} else if (elemState == 'checked') {
				//domNode.style.display = 'block';
				jQuery(domNode).removeClass('disabled')
				domNode.setAttribute('productSelectorState', 'checked');
			}
			
			//domNode.src = '/img/tilaus_' + domNode.getAttribute('productType') + '_' + domNode.getAttribute('productSelectorImg') + '_' + domNode.getAttribute('productSelectorState') + '.' + domNode.getAttribute('productExt');

                }
	};

HsaProductSelector.prototype._processProductResponse = function (responseElement) {
	var xmlElemNodes = responseElement.childNodes;

    for (var i=0 ; i<=xmlElemNodes.length-1 ; i++ ) {
        var responseElement = xmlElemNodes[i];

        if ( responseElement.nodeType != 1 )
			continue;

		var elemName = responseElement.nodeName;
		var elemId = responseElement.getAttribute('id');
		var elemType = responseElement.getAttribute('type');
		var elemValue = responseElement.firstChild.nodeValue;

		//console.log(elemId)

		var domNode = document.getElementById(elemId);
		if (!domNode)
			continue;
		
		//console.log(elemType)

		if (elemType == "content") {
			domNode.innerHTML = elemValue;
		} else if (elemType == "image") {
			domNode.setAttribute('src', elemValue);
		} else if (elemType == "link") {
			//console.log(elemValue)
			domNode.setAttribute('href', elemValue);
		}
    }
};
	
HsaProductSelector.prototype.openPreviousPhase = function(num) {
    alert(num);
}



function HsaProductSelector(putInsideDiv, inputIds, methodName) {
	jQuery.ajax(Hsa.form._ajaxRequestOptionsJ(Hsa.config.helpbubblebackendpath + 'productselector' + '.xml', 'foo=bar'));
	this.init(putInsideDiv, inputIds, methodName);
	this.mustSubmit();
	
	jQuery(".product").attr('rel', 'gallery').fancybox({
        padding: 35,
        scrolling: 'no'
    });
	
	};


