// Original JS code by Amazon.com
//  modified by KonyvNet.hu

// EXCHANGER kell hozza
// session adatok is kellenek! (sess_name;sess_id)

var dpmegvanKepek     = new Array("img/megvan-checkbox-off.gif", "img/megvan-checkbox-on.gif");
var megvanKepek       = new Array("img/megvan-radio-off.gif","img/megvan-radio-on.gif");
var historyNemerdekelKepek = new Array("img/nemerdekel-checkbox-off.gif", "img/nemerdekel-checkbox-on.gif");
var nemerdekelKepek   = new Array("img/nemerdekel-radio-off.gif", "img/nemerdekel-radio-on.gif");
var ajanloKepek       = new Array("img/ajanlo-checkbox-off.gif", "img/ajanlo-checkbox-on.gif");
var nixel             = "img/nixel.gif"
var elmentveKep       = "img/elmentve.gif";
var csillagKepek      = new Array(
	"img/ertekeles0.gif",
	"img/ertekeles1.gif",
	"img/ertekeles2.gif",
	"img/ertekeles3.gif",
	"img/ertekeles4.gif",
	"img/ertekeles5.gif");

var csillagMap = new Array('0,0,22,20',
	'23,0,36,20',
	'37,0,50,20',
	'51,0,64,20',
	'65,0,87,20');

var savedRatings       = new Array();
var savedNotInterested = new Array();
var savedIsOwned       = new Array();
var savedExcluded      = new Array();
var starTwinkler       = new Array();
var delayTime          = 200;
var allImages          = new Array();

function kn_preloadImages(){
for (i=0; i < kn_preloadImages.length ;i++){
allImages[i] = new Image();
allImages[i].src = kn_preloadImages.arguments[i];
}
}

kn_preloadImages(csillagKepek);
kn_preloadImages(dpmegvanKepek);
kn_preloadImages(megvanKepek);
kn_preloadImages(historyNemerdekelKepek);
kn_preloadImages(nemerdekelKepek);
kn_preloadImages(ajanloKepek);
kn_preloadImages(elmentveKep);

function kn_swapHistoryNemerdekel(asin, state){
	if (state == 'alt'){
		notInterested = (savedNotInterested[asin] ? 0 : 1);
	} else if (typeof state != 'undefined') {
		notInterested = state;
	} else {
		notInterested = savedNotInterested[asin];
	}
	document.images["notInterested." + asin].src = historyNemerdekelKepek[notInterested];
}

function kn_swapNemerdekel(asin, state){
	if (state == 'alt'){
		notInterested = (savedNotInterested[asin] ? 0 : 1);
	} else if (typeof state != 'undefined') {
		notInterested = state;
	} else {
		notInterested = savedNotInterested[asin];
	}
	if (document.images["notInterested." + asin]) {
		document.images["notInterested." + asin].src = nemerdekelKepek[notInterested];
	}
}

function kn_swapDpMegvan(asin, state){
	if (state == 'alt'){
		isOwned = (savedIsOwned[asin] ? 0 : 1);
	} else {
		isOwned = savedIsOwned[asin];
	}
	document.images["isOwned." + asin].src = dpmegvanKepek[isOwned];
}

function kn_swapMegvan(asin, state){
	if (state == 'alt'){
		isOwned = (savedIsOwned[asin] ? 0 : 1);
	} else if (typeof state != 'undefined') {
		isOwned = state;
	} else {
		isOwned = savedIsOwned[asin];
	}
	document.images["isOwned." + asin].src = megvanKepek[isOwned];
}

function kn_swapAjanlo(asin, state){
	if (state == 'alt'){
		excluded = (savedExcluded[asin] ? 0 : 1);
	} else {
		excluded = savedExcluded[asin];
	}
	document.images["excluded." + asin].src = ajanloKepek[excluded];
}

function kn_showDefaultMessage(asin){
	var imageID = "thanks" + asin;
	document.write("<img vspace=2 src='" + nixel + "' id='" + imageID + "' height=16>"); 
}

function kn_swapElmentveMessage(asin){
	document.images['thanks' + asin].src = elmentveKep;
}

function kn_restoreDefaultMessage(asin){
	document.images['thanks' + asin].src = nixel;
}

function kn_sendRating(asin, ratingType, ratingValue){

	kn_restoreDefaultMessage(asin);

	var submitURL = 'user.php?mit=ertekeles_save&konyv_id=' + asin + '&' + sess_name + '=' + sess_id;

	if ( ( (ratingType == 'onetofive') || (ratingType == 'owned') )
	&& ( savedNotInterested[asin] == 1 ) ) {
		//submitURL = submitURL + '&amp;rating.notinterested.1=NONE';
		savedNotInterested[asin] = 0;
	} else if ( ratingType == 'notinterested' ) {
		if ( savedRatings[asin] > 0 ) {
			//submitURL = submitURL + '&amp;rating.onetofive.1=NONE';
			savedRatings[asin] = 0;
		}
		if ( savedIsOwned[asin] == 1 ) {
			//submitURL = submitURL + '&amp;rating.owned.1=NONE';
			savedIsOwned[asin] = 0;
		}
	}

	if (typeof savedRatings[asin] == 'undefined') r = 0;
	else r = savedRatings[asin];
	if (typeof savedIsOwned[asin] == 'undefined') o = 0;
	else o = savedIsOwned[asin];

	submitURL = submitURL + '&pont=' + r;
	submitURL = submitURL + '&megvan=' + o;
	submitURL = submitURL + '&hasznalva_ajanlashoz=1';
	submitURL = submitURL + '&nemerdekel=0';

	//window.location.href = submitURL + "&return.response=204";
	sendDataToServer(submitURL);
	window.setTimeout("kn_swapElmentveMessage('"+asin+"')", delayTime);
}

function kn_sendCsillagok(asin, rating){
	savedRatings[asin] = rating;
	kn_sendRating(asin, 'onetofive', rating);
}

function kn_sendNemerdekel(asin){
	savedNotInterested[asin] = (savedNotInterested[asin] ? 0 : 1);
	rating = (savedNotInterested[asin] ? 'NOTINTERESTED' : 'NONE');
	kn_sendRating(asin, 'notinterested', rating);
}

function kn_sendMegvan(asin){
	savedIsOwned[asin] = (savedIsOwned[asin] ? 0 : 1);
	rating = (savedIsOwned[asin] ? 'OWN' : 'NONE');
	kn_sendRating(asin, 'owned', rating);
}

function kn_sendAjanlo(asin){
	savedExcluded[asin] = (savedExcluded[asin] ? 0 : 1);
	rating = (savedExcluded[asin] ? 'EXCLUDE' : 'NONE');
	kn_sendRating(asin, 'excluded', rating);
}

function kn_swapCsillag(asin, rating){
	if (typeof rating == 'undefined'){
		rating = savedRatings[asin];
	}

	if (typeof rating == 'undefined') rating = 0;

	document.images["stars." + asin].src = csillagKepek[rating];
}

function kn_csillagMouseOver(asin, rating){
	if (starTwinkler[asin] != 0){
		window.clearTimeout(starTwinkler[asin]);
		starTwinkler[asin] = 0;
	}
	kn_swapCsillag(asin, rating); 
}

function kn_csillagMouseOut(asin){
	starTwinkler[asin] = window.setTimeout("kn_swapCsillag('"+asin+"')", delayTime);
}

function kn_showHistoryNemerdekel(asin, notInterested){
	var imageID = "notInterested." + asin;
	document.write("<img src='" + historyNemerdekelKepek[notInterested] + "'");
	document.write("id='" + imageID + "' ");
	document.write("onClick=\"kn_swapHistoryNemerdekel('" + asin + "', 'alt');");
	document.write("window.setTimeout('kn_sendNemerdekel(\\'" + asin + "\\');', delayTime);\" ");
	document.write("border=0 height=16 valign=absmiddle>");
}

function kn_showNemerdekel(asin, notInterested){
	var imageID = "notInterested." + asin;
	document.write("<img src='" + nemerdekelKepek[notInterested] + "'");
	document.write("id='" + imageID + "' ");
	document.write("onClick=\"kn_swapNemerdekel('" + asin + "', 'alt');");

	document.write("kn_swapCsillag('" + asin + "', 0);");
	document.write("kn_swapMegvan('" + asin + "', 0);");

	document.write("window.setTimeout('kn_sendNemerdekel(\\'" + asin + "\\');', delayTime);\" ");
	document.write("border=0 height=16 valign=absmiddle>");
}

function kn_showDpMegvan(asin, isOwned){
	var imageID = "isOwned." + asin;
	document.write("<img src='" + dpmegvanKepek[isOwned] + "'");
	document.write("id='" + imageID + "' ");
	document.write("onClick=\"kn_swapDpMegvan('" + asin + "', 'alt');");
	document.write("window.setTimeout('kn_sendMegvan(\\'" + asin + "\\');', delayTime);\" ");
	document.write("border=0 height=16 valign=absmiddle>");
}

function kn_showMegvan(asin, isOwned){
	var imageID = "isOwned." + asin;
	document.write("<img src='" + megvanKepek[isOwned] + "'");
	document.write("id='" + imageID + "' ");
	document.write("onClick=\"kn_swapMegvan('" + asin + "', 'alt');");
	document.write("kn_swapNemerdekel('" + asin + "', 0);");
	document.write("window.setTimeout('kn_sendMegvan(\\'" + asin + "\\');', delayTime);\" ");
	document.write("border=0 height=16 valign=absmiddle>");
}

function kn_showAjanlo(asin, exluded){
	var imageID = "excluded." + asin;
	document.write("<img src='" + ajanloKepek[excluded] + "'");
	document.write("id='" + imageID + "' ");
	document.write("onClick=\"kn_swapAjanlo('" + asin + "', 'alt');");
	document.write("window.setTimeout('kn_sendAjanlo(\\'" + asin + "\\');', delayTime);\" ");
	document.write("border=0 height=16 valign=absmiddle>");
}

function kn_showCsillagok(asin, rating){
	var starID = "stars." + asin;
	starTwinkler[asin] = 0;
	document.write("<map name='starmap" + asin +"'>");
	var i = 0;
	for (i = 1; i < 6; i++) {
		document.write("<area shape=rect " + 
		"coords='" + csillagMap[i-1] + "' " +
		"onMouseOver=\"kn_csillagMouseOver('" + asin + "'," + i + ");\" " +
		"onMouseOut=\"kn_csillagMouseOut('" + asin + "');\" " +
		"onClick=\"kn_sendCsillagok('" + asin + "'," + i + ");" +
		"kn_swapNemerdekel('" + asin + "', 0);" +
		"\" >");


	}
	document.write("</map>");
	document.write("<img vspace=2 src='" + csillagKepek[rating] + "'");
	document.write(" border=0 usemap='#starmap" + asin);
	document.write("' id='" + starID + "'>");
}

