var rv = {
	url:"/Reviews/reviews.php",
	numquestion : 6,
	numstar : 5
}

rv.setuplist = function(_cols, _rows, _id, _id2, _cnt, n){
	var pagecount = Math.ceil(_cnt/(_cols*_rows));
	$(_id+"-page").innerHTML = "";
	for (var i=0; i<pagecount; i++)
	{
		var _class = (n==i)? "act" : "nact";
		var _click = (n==i)? "" : "rv.setuplist("+_cols+", "+_rows+", '"+_id+"', '"+_id2+"', "+_cnt+", "+i+"); ";
		var _txt = (((_cols*_rows)*i)+1);
		var _txtto = ((_txt+(_cols*_rows)-1)>_cnt) ? _cnt : (_txt+(_cols*_rows)-1);
		_txt = _txt+"-"+_txtto;

		if (i==0) {
			var _plink = (n==0)? "" : "rv.setuplist("+_cols+", "+_rows+", '"+_id+"', '"+_id2+"', "+_cnt+", "+(n-1)+"); ";
			$(_id+"-page").innerHTML += '<a href="#'+_id2+'" onclick="'+_plink+'" class="nact">[Previous]</a>';
		}
		$(_id+"-page").innerHTML += '<a href="#'+_id2+'" class="'+_class+'" onclick="'+_click+'">['+_txt+']</a>';
		if ((i+1)==pagecount) {
			var _nlink = (n==i)? "" : "rv.setuplist("+_cols+", "+_rows+", '"+_id+"', '"+_id2+"', "+_cnt+", "+(n+1)+"); ";
			$(_id+"-page").innerHTML += '<a href="#'+_id2+'" onclick="'+_nlink+'" class="nact">[Next]</a>';
		}
		$(_id+"-"+((_cols*_rows)*i)).style.display = "none";
	}
	$(_id+"-"+((_cols*_rows)*n)).style.display = "";
}

rv.getparamsearch = function (Mode){
	if (!$("cbo-rv-Continent")) return "";
	var param = "Mode="+Mode;
	param += "&Continent="+$("cbo-rv-Continent").value;
	param += "&Country="+$("cbo-rv-Country").value;
	param += "&City="+$("cbo-rv-City").value;
	param += "&"+new Date().getTime();
	return param;
}

rv.reqCountry = function (){
	if (!$("cbo-rv-Country")) return;
	jssearch.settext2cboweb ($("cbo-rv-Country"), "-- loading --", true);
	jssearch.settext2cboweb ($("cbo-rv-City"), "-- loading --", true);
	jssearch.settext2cboweb ($("cbo-rv-Hotel"), "-- loading --", true);
	if (!rv.dCountry[$("cbo-rv-Continent").value])
	{
		rv.dCountry[$("cbo-rv-Continent").value] = [];
		var param = rv.getparamsearch("webCountry");
		Ajax.request (rv.url, param, rv.resCountry);
	}else{
		jssearch.settext2cboweb ($("cbo-rv-Country"), "-- select --", false);
		jssearch.settext2cboweb ($("cbo-rv-City"), "-- select --", true);
		jssearch.settext2cboweb ($("cbo-rv-Hotel"), "-- select --", true);
		jssearch.setcbo ($("cbo-rv-Country"), rv.dCountry[$("cbo-rv-Continent").value]);
	}
}

rv.resCountry = function (http) {if (http.readyState != 4) { return; }
	jssearch.settext2cboweb ($("cbo-rv-Country"), "-- select --", false);
	jssearch.settext2cboweb ($("cbo-rv-City"), "-- select --", true);
	jssearch.settext2cboweb ($("cbo-rv-Hotel"), "-- select --", true);
	var mytext = eval("("+http.responseText +")");
	rv.dCountry[$("cbo-rv-Continent").value] = mytext.webCountry;
	jssearch.setcbo ($("cbo-rv-Country"), mytext.webCountry) ;
	if(rv.CountryDefault){jssearch.setvaluecbo ($("cbo-rv-Country"), rv.CountryDefault);rv.reqCity();}
}

rv.reqCity = function (){
	if (!$("cbo-rv-City")) return;
	jssearch.settext2cboweb ($("cbo-rv-City"), "-- loading --", true);
	jssearch.settext2cboweb ($("cbo-rv-Hotel"), "-- loading --", true);
	if (!rv.dCity[$("cbo-rv-Country").value])
	{
		rv.dCity[$("cbo-rv-Country").value] = [];
		var param = rv.getparamsearch("webCity");
		Ajax.request (rv.url, param, rv.resCity);
	}else{
		jssearch.settext2cboweb ($("cbo-rv-City"), "-- select --", false);
		jssearch.settext2cboweb ($("cbo-rv-Hotel"), "-- select --", true);
		jssearch.setcbo ($("cbo-rv-City"), rv.dCity[$("cbo-rv-Country").value]) ;
	}
}

rv.resCity = function (http) {if (http.readyState != 4) { return; }
	jssearch.settext2cboweb ($("cbo-rv-City"), "-- select --", false);
	jssearch.settext2cboweb ($("cbo-rv-Hotel"), "-- select --", true);
	var mytext = eval("("+http.responseText +")");
	rv.dCity[$("cbo-rv-Country").value] = mytext.webCity;
	jssearch.setcbo ($("cbo-rv-City"), mytext.webCity) ;
	if(rv.CityDefault){jssearch.setvaluecbo ($("cbo-rv-City"), rv.CityDefault);rv.reqHotel();}
}

rv.reqHotel = function (){
	if (!$("cbo-rv-Hotel")) return;
	jssearch.settext2cboweb ($("cbo-rv-Hotel"), "-- loading --", true);
	if (!rv.dHotel[$("cbo-rv-City").value])
	{
		var param = rv.getparamsearch("webHotel");
		Ajax.request (rv.url, param, rv.resHotel);
	}else{
		jssearch.settext2cboweb ($("cbo-rv-Hotel"), "-- select --", false);
		jssearch.setcbo ($("cbo-rv-Hotel"), rv.dHotel[$("cbo-rv-City").value]) ;
	}
}

rv.resHotel = function (http) {if (http.readyState != 4) { return; }
	jssearch.settext2cboweb ($("cbo-rv-Hotel"), "-- select --", false);
	var mytext = eval("("+http.responseText +")");
	rv.dHotel[$("cbo-rv-City").value] = mytext.webHotel;
	jssearch.setcbo ($("cbo-rv-Hotel"), mytext.webHotel) ;
	if(rv.HotelDefault){jssearch.setvaluecbo ($("cbo-rv-Hotel"), rv.HotelDefault);}
}

rv.reqsearch = function(){
	var strContinent = $("cbo-rv-Continent").options[$("cbo-rv-Continent").selectedIndex].text.split(" ").join("_").split("&").join("_");
	var strCountry = $("cbo-rv-Country").options[$("cbo-rv-Country").selectedIndex].text.split(" ").join("_").split("&").join("_");
	var strCity = $("cbo-rv-City").options[$("cbo-rv-City").selectedIndex].text.split(" ").join("_").split("&").join("_");
	var strHotel = $("cbo-rv-Hotel").options[$("cbo-rv-Hotel").selectedIndex].text.split(" ").join("_").split("&").join("_");
	var str = "";
	if ($("cbo-rv-Hotel").value != "")
	{
		str = "/Reviews/"+strCountry+"/"+strCity+"/"+strHotel+".html";
	}else if ($("cbo-rv-City").value != ""){
		str = "/Reviews/"+strCountry+"/"+strCity+".html";
	}else if ($("cbo-rv-Country").value != ""){
		str = "/Reviews/"+strCountry+".html";
	}else if ($("cbo-rv-Continent").value!= ""){
		str = "/Reviews/"+strContinent+".html";
	}else{
		alert("Please select continent !");
		return;
	}
	window.open(str, "_self");
}

rv.RatingSelect =  function (obj, act){
	obj.className="g-rating-"+act;
	obj.setAttribute("Rating",act);
	rateType = obj.id;
	$("txt"+rateType).value = act;
	TotalRate = rv.callAVG(obj);
	rv.setMsg(TotalRate);
}

rv.sltRating = function(obj, act){
	obj.className="g-rating-"+act;
}

rv.sltRatingOut = function (obj){
	obj.className="g-rating-"+obj.getAttribute("Rating");
}

rv.callAVG = function (){
	var Value = parseFloat($("Value").getAttribute("Rating"));
	var Service = parseFloat($("Service").getAttribute("Rating"));
	var Cleanliness = parseFloat($("Cleanliness").getAttribute("Rating"));
	var Comfort = parseFloat($("Comfort").getAttribute("Rating"));
	var Amenities = parseFloat($("Amenities").getAttribute("Rating"));
	var Location = parseFloat($("Location").getAttribute("Rating"));

	TotalRate = Value+Service+Cleanliness+Comfort+Amenities+Location;
	TotalRate = Math.round(TotalRate/rv.numquestion);
	return TotalRate;
}

rv.setMsg = function (rating){
	var msg;
	switch (rating){
		case 0: msg='Terrible'; break ;
		case 1: msg='Terrible'; break ;
		case 2: msg='OK but some problem'; break ;
		case 3: msg='Fair'; break ;
		case 4: msg='Good'; break ;
		case 5: msg='Excellent'; break ;
	}

	$("lyGuestRating").innerHTML = rating+" / "+rv.numstar+" : "+msg;
	$("GuestRating").className="guest"+rating;
}

rv.BrowsImg = function (object){
	//num=object.id.substring(12,13);
	//tempHtml=$('file'+num).innerHTML;
	//type=object.value.substring((object.value.length)-4,object.value.length);

	//if(type!='.jpg'&&type!='.gif'){
	//	alert('Please upload picture ext in .jpg or .gif');
	//	$('file'+num).innerHTML=tempHtml;
	//}else{
	//	oImage = document.createElement('img');
	//	oImage.src=object.value;
	//	window.document.getElementById('imgPictureSq'+num).src=object.value;
	//}
}

rv.PostReview = function (){
	//Get value==========
	txtHotelReview=$("txtHotelReview").value;
	//Hide error==========
	$("errContinent").style.display = "none";
	$("errHotelReview").style.display="";
	$("errCountry").style.display = "none";
	$("errCity").style.display = "none";
	$("errHotel").style.display = "none";

	//Check error=========

	if ($("cboContinent").value=="")
	{
		$("errContinent").style.display = "";
		$("cboContinent").focus();
		return false;
	}
	else if($("cboCountry").value=="")
	{
		$("errCountry").style.display="";
		$("cboCountry").focus();
		return false;
	}
	else if($("cboCity").value=="")
	{
		$("errCity").style.display="";
		$("cboCity").focus();
		return false;
	}
	else if($("cboHotel").value=="")
	{
		$("errHotel").style.display="";
		$("cboHotel").focus();
		return false;
	}
	else if(txtHotelReview=="")
	{
		$("errHotelReview").style.display="";
		$("txtHotelReview").focus();
		return false;
	}
	else  { return true;}
}

