var open = null;

var max_height = 250;

var votes = new Array();

var last_vote;

function set_last_vote(lv){
	last_vote = lv;
}

function thanks(){
	window.alert(unescape("Besten Dank f%FCr Ihre Teilnahme!"));
	ajax.location.href="";
	document.location.href = "index.html";
}

function send_vote(){
	
	var get = "";
	var has_votes = false;
	var div = "";
	var total_votes = 0;
	
	for(i=1;i<21;i++){
		if(votes[i] == true){
			get += div + i;
			div = ",";
			has_votes = true;
			total_votes++;
		}
	}
	
	if(has_votes == true){
		
		var msg;
		
		if(total_votes > 1){
			msg = unescape("Sie haben " + total_votes + " Produkte ausgew%E4hlt.\nWollen Sie jetzt f%FCr diese Produkte stimmen?");
		}else{
			msg = unescape("Sie haben " + total_votes + " Produkt ausgew%E4hlt.\nWollen Sie jetzt f%FCr dieses Produkt stimmen?");
		}
	
		if(window.confirm(msg)){
			ajax.location.href = "send_vote.php?type=1&votes=" + get + "&last_vote=" + last_vote;
		}
	}else{
		window.alert(unescape("Bitte stimmen Sie mindestens f%FCr ein Produkt!"));
	}
}

function add_vote(which){
	
	total_votes = 0;
	
	for(i=1;i<21;i++){
		if(votes[i] == true)
			total_votes ++;
	}
	
	if(votes[which] != true && total_votes < 5){
		votes[which] = true;
		
		document.getElementById('vote_td' + which).innerHTML = "<a class=\"linkpink\" href=\"javascript:add_vote(" + which + ")\" id=\"add_vote" + which + "\">&raquo; dieses Produkt abw&auml;hlen</a><img src=\"pics/haken.gif\" alt=\"\" height=\"42\" width=\"32\" border=\"0\">";
		
	}else if(votes[which] != true && total_votes == 5){
		window.alert(unescape("Sie k%F6nnen f%FCr maximal 5 Produkte stimmen"));
	}else if(votes[which] == true){
		votes[which] = false;
		document.getElementById('vote_td' + which).innerHTML = "<a class=\"linkpink\" href=\"javascript:add_vote(" + which + ")\" id=\"add_vote" + which + "\">&raquo; dieses Produkt w&auml;hlen</a>";
	}
}


function set_open(which){
	open = which;
	document.getElementById('mehr_lesen_div' + which).style.display = "none";
	document.getElementById('mehr_lesen' + which).innerHTML = "&raquo; weniger lesen<br />";
	ajax.location.href = "get_abstimmung1.php?product=" + which;
}

function implode(which, h){

	document.getElementById('mehr_lesen_div' + open).style.height = h + "px";

	h -= 10;

	if(h > 0){
		window.setTimeout("implode('" + which + "'," + h + ")", 10);
	}else{
		document.getElementById('mehr_lesen_div' + open).style.height = "0px";
		document.getElementById('mehr_lesen_div' + open).style.display = "none";
		document.getElementById('mehr_lesen' + open).innerHTML = "&raquo; mehr lesen<br />";
		if(open != which){
			set_open(which);
		}else{
			open = null;
		}
	}

}

function mehr_lesen(which){

	if(open != null && open != which){
		
		implode(which, max_height);
		
	}else if(open == null){
		set_open(which);
	}else if(open == which){
		implode(which, max_height);
	}
}
