var request;

function createRequest() {
  try {
	request = new XMLHttpRequest();
  } catch (trymicrosoft) {
	try {
	  request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (othermicrosoft) {
	  try {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (failed) {
		request = false;
	  }
	}
  }

  if (!request)
	alert("Error initializing XMLHttpRequest!");
}


 function starOver(strASIN,intStar){
 	for(var i=1;i<=5;i++){

 		if(i<=intStar){
 			window.document.getElementById('img'+i+'_'+strASIN).src = 'images/star_on.gif';
 		}else{
 			window.document.getElementById('img'+i+'_'+strASIN).src = 'images/star_off.gif';
 		}

 	}
 }
 function starOut(strASIN, intRating){
 	for(var i=1;i<=5;i++){

 		if(i<=intRating){
  			window.document.getElementById('img'+i+'_'+strASIN).src = 'images/star_on.gif';
 		}else{
  			window.document.getElementById('img'+i+'_'+strASIN).src = 'images/star_off.gif';
 		}

 	}
 }
 function vote(strASIN,intRating){
 	
 	var strText = "";

  	for(var i=1;i<=5;i++){

  		if(i<=intRating){
   			strText = strText + '<img src="images/star_click.gif">';
  		}else{
  			strText = strText + '<img src="images/star_off.gif">';
  		}

 	}

 	document.getElementById('div_'+strASIN).innerHTML = strText;

	// Create Request
	createRequest();

	// Set Variables
	var url = "vote.php?ASIN="+strASIN+"&rating="+intRating;

	// Send Request
	request.open("GET", url, true);

	// On Response send to function
	request.onreadystatechange = voteSuccess;

	// Close Request
	request.send(null);

 }
 function voteSuccess(){
	// http readystate 4 - complete
	if (request.readyState == 4){
		// http status 200 - OK
		if (request.status == 200){
			// store the responseText
			var response = request.responseText;
			//alert("Thank you for voting!");
		}
	}
 }
 
function toggleCalendar()
{
	if(document.getElementById('div_calendar').style.display == 'none')
	{
		document.getElementById('div_calendar').style.display = ''
	}
	else
	{
		document.getElementById('div_calendar').style.display = 'none'
	}

}
function validateSearch()
{
	if(document.getElementById('search').value == '')
	{
		alert('Please enter a search value.');
		return false;
	}
	else if(document.getElementById('search').value.length < 3)
	{
		alert('Search value must be at least 3 characters.');
		return false;	
	}
	else
	{
		return true;
	}
}