// ------------------------
// --- SCROLL FUNCTIONS ---
// ------------------------

function slideContent(source){
	resetForm();
	resetButtons();
	document.getElementById('ratesuccess').style.display='none';
	scroll.toElement('hotel_'+source);
}
var scroll = new Fx.Scroll('featurecontainer', {
	wait: false,
	duration: 2000,
	offset: {'x': 0, 'y': 0},
	transition: Fx.Transitions.Quad.easeInOut,
	wheelStops: false
});


// ------------------------------------------------
// --- ELEMENT SET UP, POSITIONING AND RESIZING ---
// ------------------------------------------------

document.getElementById('rateit').style.display='none';
document.getElementById('ratesuccess').style.display='none';

for(hfb=0; hfb<arrFeatureElements.length; hfb++){
	document.getElementById("hotel_"+arrFeatureElements[hfb]).style.left=(hfb*803)+'px';
	document.getElementById("hotel_"+arrFeatureElements[hfb]).style.position='absolute';
	document.getElementById("hotel_"+arrFeatureElements[hfb]).style.display='block';
} 
function resizeContent(){
	heightall=0;
	for(hfb=0; hfb<arrFeatureElements.length; hfb++){
		tempheight=document.getElementById("hotel_"+arrFeatureElements[hfb]).clientHeight;
		if(tempheight>heightall){heightall=tempheight;};
	} 
	document.getElementById("featurecontainer").style.height=heightall+"px";
	document.getElementById("hotel_intro").style.height=heightall+"px";
	document.getElementById("rateit").style.marginTop="-"+heightall+"px";
	document.getElementById("rateit").style.height=heightall+"px";
	document.getElementById("ratesuccess").style.marginTop="-"+heightall+"px";
	document.getElementById("ratesuccess").style.height=heightall+"px";
}
setInterval("resizeContent()",50);


// ------------------------------------
// --- RATE THIS IDEA FORM HANDLING ---
// ------------------------------------

//-- DISPLAY FORM ON REQUEST
function showForm(source,actionarea){
	if((document.getElementById('rateit').style.display=='none')&&(document.getElementById('ratesuccess').style.display=='none')){
		document.getElementById('frmActionarea').value=actionarea;
		document.getElementById('frmIdea').value=source;
		document.getElementById("rateit").style.width='328px';
		document.getElementById("rateit").style.cssFloat='right';
		document.getElementById("rateit").style.styleFloat='right';
		document.getElementById("ratesuccess").style.width='328px';
		document.getElementById("ratesuccess").style.cssFloat='right';
		document.getElementById("ratesuccess").style.styleFloat='right';
		document.getElementById('rateit').style.display='block';
		document.getElementById('rate_'+source).firstChild.src='images/buttons/btn_rateitform_back.gif';
		document.getElementById('rate_'+source).firstChild.title='Back';
		document.getElementById('rate_'+source).firstChild.alt='Back';
		document.getElementById('ratingerror').nextSibling.className='';
		document.getElementById('ratingerror').style.display='none';
	}else{
		resetThanks();
		resetForm();
		resetButtons();
	}
}


//-- FORM SUBMIT ACTION
function submitForm(){
	// GATHER INPUT
	var strActionArea=document.getElementById('rateit').frmActionarea.value;
	var strRoom=document.getElementById('rateit').frmRoom.value;
	var strIdeaName=document.getElementById('rateit').frmIdea.value;
	var strIdeaComment=escape(document.getElementById('rateit').frmComments.value);

	for(x=0; x<5; x++){
		if(document.getElementById('rateit').frmRating[x].checked){
			var strIdeaRating=document.getElementById('rateit').frmRating[x].value;
		}
	}
	if(strIdeaRating==undefined){
		// PROCESS INVALID INPUT
		document.getElementById('ratingerror').style.display='block';
		document.getElementById('ratingerror').nextSibling.className='redtext';
	}else{
		// PROCESS INPUT
		strFormSubmission="frmRoom="+strRoom+"&frmActionarea="+strActionArea+"&frmIdea="+strIdeaName+"&frmRating="+strIdeaRating+"&frmComments="+strIdeaComment;
		document.getElementById('ratingerror').nextSibling.className='';
		processForm();
	}
}

//-- PROCESS SUBMIT VIA SERVER CALL
function processForm(){
	// SET XMLHTTP
	xmlrequest = false;
	if(window.XMLHttpRequest){
		try{xmlrequest=new XMLHttpRequest();}catch(e){xmlrequest=false;}
	}else if(window.ActiveXObject){
		try{xmlrequest=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlrequest=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){xmlrequest=false;}}
	}
	if(xmlrequest){
		xmlrequest.onreadystatechange=processFormResponse;
		xmlrequest.open("POST","xml/processRating.asp",true);
		xmlrequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlrequest.send(strFormSubmission);
	}
}

//-- PROCESS SERVER RESPONSE
function processFormResponse(){
	try{
		// DETECT RESPONSE STATUS
		if(xmlrequest.readyState==4){
			if (xmlrequest.status==200){
				responseobject=xmlrequest.responseXML;
				var strStatus=responseobject.getElementsByTagName('status')[0].firstChild.data;
				// SHOW ERROR MESSAGE
				if(strStatus=="ERROR"){
					document.getElementById('ratingerror').style.display='block';
				// SHOW SUCCESS MESSAGE
				}else{
					document.getElementById('ratingerror').nextSibling.className='';
					document.getElementById('ratingerror').style.display='none';
					document.getElementById('ratesuccess').style.display='block';
					resetForm();
					setTimeout("resetThanks();",12000);
				}
			}
		}
	}catch(e){
		// ON CATASTROPHIC FAILURE SHOW ERROR MESSAGE
		document.getElementById('ratingerror').style.display='block';
	}
}

//-- HIDE "BACK" BUTTON STATE FOR ALL FORMS
function resetButtons(){
	for(hfb=0; hfb<arrFeatureElements.length; hfb++){
		if(arrFeatureElements[hfb]!="intro"){
			document.getElementById('rate_'+arrFeatureElements[hfb]).firstChild.src='images/buttons/btn_rateitform.gif';
			document.getElementById('rate_'+arrFeatureElements[hfb]).firstChild.title='Rate it';
			document.getElementById('rate_'+arrFeatureElements[hfb]).firstChild.alt='Rate it';
		} 
	}
}

//-- RESET THANKYOU MESSAGE
function resetThanks(){
	document.getElementById('ratesuccess').style.display='none';
	resetButtons();
}

//-- RESET FORM TO DEFAULT VARS
function resetForm(){
	document.getElementById("rateit").style.display='none';
	document.getElementById("rateit").frmIdea.value='';
	document.getElementById("rateit").frmComments.value=strDefaultComment;
	for(x=0; x<5; x++){document.getElementById('rateit').frmRating[x].checked=false;};
}