function getStarsForProduct(product_id) {
	if (product_id > 0) {
		$.ajax({
			type: "POST",
			url: "/getStars.php",
			processData: false,
			data: "product_id="+product_id+"",
			error: function(){
			//	alert("Error");
			},
			success: function(res){ 
				$("#bxStars"+product_id).html(res);
				$("#bxStars"+product_id).fadeIn("slow");
			} 
		});
	} 
}

/* Original Functions */
$.fn.setFocus = function(e){
	if (document.getElementById(e)) document.getElementById(e).focus();
	return this;
}; 


$.fn.ajaxSubmit = function(e) {		
	/* Change a form's submission type to ajax */
	
	this.submit(function(){
		// confirm form
		var confirmTxt = $("#confirmTxt").val();
		input_box = confirm(confirmTxt);	
		if (input_box == true)	{
		} else {
			return false;	
		}
			
			
		var params = {};
			$(this)
			.find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], option[@selected], textarea")
			.filter(":enabled")
			.each(function() {
			params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
		});
			
		$("#btnSubmit").hide();
		$("#loader").show();	
		$.post(this.getAttribute("action") + "?call=ajax", params, function(xml){
			strError = "BĹ‚Ä…d w czasie wysyĹ‚ania formularza. SprĂłbuj jeszcze raz.";
			oFocus = null;
			record = xml.getElementsByTagName("status");
			var status = record[0].childNodes[0].nodeValue;
					
			if (status == 1) {
				parseValidationResponses(xml);
				record = xml.getElementsByTagName("location");
				var strRedirect = record[0].childNodes[0].nodeValue;
				if (strRedirect =='0') {
				} else {
					window.location = "index.php?"+strRedirect;
				}

				$("#loader").hide();
				$("#outputInfo").text("Form has been sent. Thank you!");
			} else {
				parseValidationResponses(xml);
				$("#loader").hide();
				$("#btnSubmit").show();
				//alert("Znaleziono bĹ‚Ä™dy:\n" + strError);
				//$("div.formErrors").html("<h3>BĹ‚Ä…d<\/h3><ul>" + strError.replace(/(\t)(.+)/g, "<li>$2<\/li>") + "<\/ul>").filter(":hidden").fadeIn("normal");
				if (oFocus) $("#" + oFocus).get(0).focus();
			}
		});
		return false;
	});			
	return this;
} 

function parseValidationResponses(xml) {
	record = xml.getElementsByTagName("field");
	var name = new Array();
	var message = new Array();
	var results = new Array();

	for (i = 0; i < record.length; i++) {
		name[i] 	= record[i].childNodes[0].childNodes[0].nodeValue;
		results[i] 	= record[i].childNodes[1].childNodes[0].nodeValue;
		message[i] 	= record[i].childNodes[2].childNodes[0].nodeValue;
	}
	
	for(var i = 0; i < name.length; i++) {
		$("#resp_"+name[i]).html('');
	}
	for(var i = 0; i < name.length; i++) {
		if (results[i] == 1) {
			$("#resp_"+name[i]).css('color','green');
		} else {
			$("#resp_"+name[i]).css('color','red');
		}
		$("#resp_"+name[i]).html(message[i]);
	}
} 

function sendCompetition() {
	var name = $("#comp_name").val();
	var email = $("#comp_email").val();
	
	if (name != ''  && email != '') {
			$.ajax({
				type: "POST",
				url: "/sendCompetition.php",
				processData: false,
				data: "name="+name+"&email="+email,
				error: function(){
				//	alert("Error");
				},
				success: function(res){ 
					if (res == 'ERR_EMAIL') 
						$("div.errBox").html("incorrect email").filter(":hidden").fadeIn("normal").fadeOut(2000);  
					if (res == 'OK') 
						$("div.msgBox").html("Your email has been sent. Thank you.").filter(":hidden").fadeIn("normal").fadeOut(5000); 
					if (res == 'ERR') 
						$("div.errBox").html("Internal error - please try again.").filter(":hidden").fadeIn("normal").fadeOut(2000); 
				} 
			});
	} else {
		$("div.errBox").html("enter name and email").filter(":hidden").fadeIn("normal").fadeOut(2000);  
	}
}
 