function highlightStar(num) {
	var a;
	for(a=1; a < 5; a++) {
		var star = document.getElementById('s'+a);
		if(a<=num) {
			star.src='/gfx/star_on.gif';
		} else {
			star.src='/gfx/star.gif';
		}
	}
}

function newsletterAdd() {
	var form = document.getElementById('newsletterForm');
	form.action = '?s=dodaj_do_newslettera';
	if(newsletterCheckReg()) {
		form.submit();
	}
}

function newsletterDelete() {
	var form = document.getElementById('newsletterForm');
	form.action = '?s=wypisz_z_newslettera';
	if(newsletterCheckReg()) {
		form.submit();
	}
}

function newsletterCheckReg() {
	if(document.getElementById('newsletter_input_accept').checked == true) {
		return true;
	} else {
		alert('Proszę zaakceptować warunki regulaminu i spróbować ponownie.');
		return false;
	}
}

function newsletterName() {
	if(document.getElementById("newsletter_name").value.length == 0) {
		document.getElementById("newsletter_name").value = "Imię i Nazwisko";
	}
}

function newsletterEmail() {
	if(document.getElementById("newsletter_email").value.length == 0) {
		document.getElementById("newsletter_email").value = "Twój adres e-mail";
	}
}

function makeCommentForm(mid) {
	var mainContener = document.getElementById('mainCommentsContener');
	mainContener.innerHTML = '<form method="post" action="/addComment.php?id='+ mid + '" id="comment_form" onsubmit="submitCommentForm(); return false;"><table cellpadding="0" cellspacing="0" border="0" width="407"><tr><td><input type="text" name="author" style="width: 401px" value="Wpisz autora" id="comment_author" /></td></tr><tr><td><textarea name="content" style="width: 401px; height: 74px" id="comment_text">Twój komentarz</textarea></td></tr><tr><td style="text-align: right"><input type="submit" value="Wyślij" id="inpSubCom" style="border: 0; background-color: #507e00; color: #fff; padding: 2px; margin: 2px" /></td></tr></table></form>';
}

function submitCommentForm() {
var comment_author = document.getElementById('comment_author').value;
var comment_text = document.getElementById('comment_text').value;

if(comment_text != 'Twój komentarz' && comment_author != 'Wpisz autora') {
advAJAX.submit(document.getElementById("comment_form"), {
    onSuccess : function(obj) { document.getElementById('mainCommentsContener').innerHTML = obj.responseText; },
    onError : function(obj) { alert("Error: " + obj.status); }
});
document.getElementById('inpSubCom').disabled = "disabled";
} else {
alert('Prosze wypełnić autora i/lub treść komentarza');
}
}

function vote(mid, rate) {
	var a;
	for(a=1; a < 5; a++) {
		var star = document.getElementById('s'+a);
		star.onclick = '';
		star.onmouseover = '';
	}
	advAJAX.setDefaultParameters({
	    onInitialization : function(obj) { document.getElementById(obj.tag).innerHTML = ""; },
	    onLoading : function(obj) { document.getElementById(obj.tag).innerHTML = "Oczekiwanie na odpowiedz serwera..."; },
	    onSuccess : function(obj) { document.getElementById(obj.tag).innerHTML = obj.responseText; },
	    onError : function(obj) { document.getElementById(obj.tag).innerHTML = "^_^"; }
	});
	
	advAJAX.get({
	    url : "/vote.php?id=" + mid + "&rate=" + rate,
	    tag : "your_rate"
	});
	advAJAX.get({
	    url : "/getGenRate.php?id=" + mid,
	    tag : "general_rate"
	});
}

function loadPoOd(id, tab) {
	document.getElementById('poOd').innerHTML = '<a href="' + tab[id][0] + '"><img src="' + tab[id][1] + '" alt="" /></a>';
}

function ajaxLoadMovie(id) {
	advAJAX.get({ url : "ajaxContent.php?t=m&id=" + id,
		onSuccess : function(obj) { document.getElementById('contentContainer').innerHTML = obj.responseText; makeCommentForm(id); },
		onError : function(obj) { alert("Error: " + obj.status); },
		onLoading : function(obj) {  }
	});
}
