﻿sessionID = getURLParam('sessionID')

$(document).ready(function() {

Webservice.getComparisons(showComparisons)
    
    $("h1").html(host);
		
    $('#prgList a').click( function() {
        var prgID = encodeURI($(this).find('strong').text())
		
		if (document.location.search == '') {
			search = '?'
		} else {
			search = document.location.search.replace(/\&prgID=[^\&]+/,'')
		}
		
        document.location.href = 'calc.html' + search + '&prgID=' + prgID
        return false
    })
})

function showComparisons(Comparisons) {
	if (Comparisons == null) return
    for (var i = 0; i < Comparisons.length; i++) {
		if (Comparisons[i].numProducts == 0) continue
		
		debug(Comparisons[i].name)
        switch (Comparisons[i].name) {
            case 'TV-Geräte':
                prgID = 'tv'
                break;
            case 'DVD/Video':
                prgID = 'dvd'
                break;
            case 'Receiver/Set-Top-Boxen':
                prgID = 'receiver'
                break;
            case 'Audio / Heimkino-Systeme':
            case 'Audio/Heimkino-Systeme':
				prgID = 'homeentertainment'
                break;
            case 'Kühlen/Gefrieren':
                prgID = 'fridges'
                break;
            case 'Geschirrspüler': 
                prgID = 'dishwasher'
                break;
            case 'Waschen/Trocknen':
                prgID = 'washer'
                break;
        }
        $("#prg_" + prgID + ' a').append('<span>Vergleich: ' + Comparisons[i].numProducts + ' Produkte</span>')
    }
}