/*===========
AJAX XML HTTP
===========*/
var xmlhttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
{
	try 
	{
		xmlhttp = new XMLHttpRequest();
	} 
	catch (e) 
	{
		xmlhttp = false;
	}
}
if (!xmlhttp && window.createRequest) 
{
	try 
	{
		xmlhttp = window.createRequest();
	} 
	catch (e) 
	{
		xmlhttp = false;
	}
}
/*===============
AJAX XML HTTP EOF
===============*/


/* ===================================================================
Special thanks to HJ for his support concerning the star rating system
=================================================================== */
function Stars(oOptions)
{
	this.opt = oOptions;
	this.bCanVote = true;
	this.init();
}


Stars.prototype.init = function()
{
	if (typeof(window.myStarOnImage) == 'undefined')
	{
		window.myStarOnImage = new Image();
		window.myStarOnImage.src = this.opt.sOnImg;
	}
	
	// Output the stars
	for (var i = 1; i <= this.opt.iNumStars; i++)
		document.write('<img id="travelAgent' + this.opt.sId + '-star' + i + '" src="' + this.opt.sOffImg + '" style="cursor:pointer;" onmouseover="' + this.opt.sSelf + '.handleMouseOver(' + i +');" onmouseout="' + this.opt.sSelf + '.handleMouseOut(' + i + ');" onclick="' + this.opt.sSelf + '.handleClick(\'starForm' + this.opt.sId + '\', ' + i + ');" />');
	
	// Output the image to reset the score
	document.write('&nbsp;&nbsp;<img id="cancelRating-' + this.opt.sId + '" src="/i/zl-cancelrating.png" style="cursor:pointer;" onclick="' + this.opt.sSelf + '.handleReset(' + this.opt.iNumStars + ')" alt="Waardering annuleren" title="Waardering annuleren" />');
	
	// Output the form
	document.write('<form method="post" action="" name="starForm' +  this.opt.sId + '"><input type="hidden" name="totalScore" value="" /><div class="button"><span class="button_text" onclick="return ' + this.opt.sSelf + '.checkForm(\'starForm' + this.opt.sId + '\', \'' + this.opt.sAlertMessage + '\');">' + this.opt.sButtonText + '</span></div></form>');
}


Stars.prototype.handleMouseOver = function (iStarIndex)
{
	if (this.bCanVote)
		for (var i = 1; i <= iStarIndex; i++)
		{
			document.getElementById('travelAgent' + this.opt.sId + '-star' + i).src = 'http://www.zelena-laguna.com' + this.opt.sOnImg;
		}
}


Stars.prototype.handleMouseOut = function (iStarIndex)
{
	if (this.bCanVote)
		for (var i = 1; i <= iStarIndex; i++)
			document.getElementById('travelAgent' + this.opt.sId + '-star' + i).src = this.opt.sOffImg;
}


Stars.prototype.handleClick = function (sSelectForm, iStarIndex)
{
	if (this.bCanVote)
		document.forms[sSelectForm].totalScore.value = iStarIndex;
		this.bCanVote = false;
}


Stars.prototype.handleReset = function (iStarIndex)
{
	for (var i = 1; i <= iStarIndex; i++)
	{
		document.getElementById('travelAgent' + this.opt.sId + '-star' + i).src = 'http://www.zelena-laguna.com' + this.opt.sOffImg;
	}
	
	document.forms['starForm' + this.opt.sId].totalScore.value = '';
	this.bCanVote = true;
}


Stars.prototype.checkForm = function (sCheckForm, sErrorMessage)
{
	if (document.forms[sCheckForm].totalScore.value == '')
	{
		alert(sErrorMessage);
		return false;
	}
	else
	{
		totalScore = document.forms[sCheckForm].totalScore.value;
		sId = this.opt.sId;
		
		// The innerHTML function
		function setInnerHTML(element, toValue)
		{
			// IE has this built in...
			if (typeof(element.innerHTML) != 'undefined')
			element.innerHTML = toValue;
			// Otherwise, try createContextualFragment().
			else
			{
				var range = document.createRange();
				range.selectNodeContents(element);
				range.deleteContents();
				element.appendChild(range.createContextualFragment(toValue));
			}
		}
		
		// Preload the waiting image
		if (typeof('http://www.zelena-laguna.com/i/zl-sending.gif') == 'undefined')
		{
			sendingImage = new Image();
			sendingImage.src = 'http://www.zelena-laguna.com/i/zl-sending.gif';
		}
		
		// Make result block visible
		document.getElementById('rateTravelAgentResultText-' + sId).style.display = 'block';
		
		// Output waiting message
		setInnerHTML(document.getElementById('rateTravelAgentResultText-' + sId), '<div class="rateTravelAgentResultText"><img src="/i/zl-sending.gif" alt="" /><br />'  + this.opt.sWaitingMessage + '</div>');
		
		xmlhttp.open('GET', '/reviewhandler/' + this.opt.sId + '/' + totalScore, true);
		xmlhttp.onreadystatechange = function() 
		{
			if (xmlhttp.readyState == 4)
			{
				setInnerHTML(document.getElementById('rateTravelAgentResultText-' + sId), '<div class="rateTravelAgentResultText">' + xmlhttp.responseText + '</div>');
			}
			else
			{
				return;
			}
		}
		xmlhttp.send(null);
		
	foldRating('rate-travel-agent-' + this.opt.sId);
	document.getElementById('rate-travel-agent-link-' + this.opt.sId).style.display = 'none';
	
	return true;
	}
}


function foldRating(sWhichRating)
{
	document.getElementById(sWhichRating).style.display = (document.getElementById(sWhichRating).style.display == 'none') ? 'block' : 'none';
}

/*====================
Star rating system EOF
====================*/


/*====================
Bookmarking function
====================*/
function addSiteToBookmarks(title, url)
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
		
	else if(window.opera && window.print)
	{ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	
	else if(document.all) // ie
		window.external.AddFavorite(url, title);
}
/*======================
Bookmarking function EOF
======================*/

