var xmlHttp
var request = 'reqprint';
function getOrders(action,post)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="./mapper.php?p=gallery/include/gallerylinker.php";
 if ( (action == 'reqprint') || (action == 'search') && (action != request) )
 { 
	request = action; 
	show_progressbar('content');
 } 
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
//DEBUG!
//alert("action="+action+post);
//------
if (xmlHttp.overrideMimeType) {
	//xmlHttp.overrideMimeType('text/html; charset=ISO-8859-15'); 
} else {
	//xmlHttp.setoption(0, "Windows-1252"); //iso-8859-1");
}
orderFilter = '';

if ( document.getElementById('divProductFilter') )
{
	if ( document.getElementById('divProductFilter').innerHTML != '' ) { orderFilter += "&product="+document.getElementById('divProductFilter').innerHTML; }
}

var stringSent = "action="+action+post+orderFilter;
xmlHttp.send("action="+action+post+orderFilter);
}

function stateChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	searchResult=xmlHttp.responseText;
	document.getElementById("content").innerHTML=searchResult;
	// STAR RATING
    $('.star').hover(function (){
        var star = $(this).attr('id').split('star')[1];
        //alert($(this).index(this)+" "+star);
        $(this).parent().css("background-position","0 -" + (32 * star) + "px");
    });
    $('.star-rating').mouseout(function (){
        var originalresult = $(this).attr('id').split('result')[1];
        $(this).css("background-position","0 -" + (32 * originalresult) + "px");
    });

    $('.star').click(function (){
   	    var id = $(this).parent().attr('id').split('rating')[1].split('result')[0];
   	    var rating = $(this).attr('id').split('star')[1];
   	    var thisparent = $(this).parent();
   	    $.ajax({
   	        type: "POST",
   	        url: "./mapper.php?p=gallery/include/vote.php",
   	        data: "id=" + id + "&rating=" + rating,
	   	    success: function(data){
	   	    	if (data == 0)
	   	    	{
	   	    		$('#resultoutput'+id).html("Already voted");
		   	    	$('#resultoutput'+id).css("display","block");
	   	    	}
	   	    	else {
		   	    	var roundrating2 = data.split('rating')[1].split('votecount')[0];
		   	    	var votecount = data.split('rating')[1].split('votecount')[1];
		   	    	var roundtohalf = roundToHalf(roundrating2);
		   	    	thisparent.attr('id',"rating"+id+"result"+roundtohalf);
		   	    	thisparent.css("background-position","0 -" + (32 * roundtohalf) + "px");
		   	    	$('#result'+id).html("<span style='color:green'>"+roundrating2+" / 5</span> out of "+votecount+" votes");
		   	    	$('#resultoutput'+id).html("Vote recorded");
		   	    	$('#resultoutput'+id).css("display","block");
	   	    	}
	   	    }
   	    });
   	    //$(this).parent().removeAttr("id");
   	    //$(this).parent().html(" ");
   	});	
 } 
}

function switchButton(i)
{
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function show_progressbar(id) {
	//replace_html(id, '<img src="../include/loading/loading.gif" width="16px" height="16px" /> Loading');
}

function replace_html(id, content) {
	document.getElementById(id).innerHTML = content;	
}

function do_nothing()
{
	return 0;
}


