var imagePath = CCM_IMAGE_PATH + "/rating";

var ratingBox;
var ratingBoxWidth = 320;
var ratingBoxHeight = 300;
var isDom = document.getElementById;
var rwIsLoaded = false;
var rb;
var canRate = false;

rating_close_off = new Image();
rating_close_off.src = imagePath + "/rating_close_off.gif";
rating_close_on = new Image();
rating_close_on.src = imagePath + "/rating_close_on.gif";

alertMessage = "Thank you for your input. We'll be reviewing it shortly.";

ratingBox = '<div id="ratingBox" style="border: 1px solid #9D9A92; background: #fff; width: ' + ratingBoxWidth + 'px;height: ' + ratingBoxHeight + 'px;position: absolute; top: 0px; left: 0px; visibility: hidden">';
ratingBox += '<form method="post" action="' + CMM_DISPATCHER_FILENAME + '?cID=' + CCM_CID + '&stask=rate">';
ratingBox += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
ratingBox += '<tr><td><img src="' + imagePath + '/rating_header_01.gif" width="288" height="40" alt=""></TD>';
ratingBox += '<td><A HREF="#" onclick="javascript:closeRatingWindow()" onmouseout="turnOffImage(\'rating_close\')" onmouseover="turnOnImage(\'rating_close\')"><IMG id="rating_close" src="' + imagePath + '/rating_close_off.gif" WIDTH=32 HEIGHT=40 BORDER=0 ALT=""></A></td>';
ratingBox += '</tr></table>';
ratingBox += '<div style="padding: 8px"><input type="radio" name="sNum" value="1">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9">&nbsp;<img src="' + imagePath + '/rating_circle_empty.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_empty.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_empty.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_empty.gif" width="9" height="9" border="0">&nbsp;&nbsp;&nbsp;Sucktastic<br>';
ratingBox += '<input type="radio" name="sNum" value="2">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_empty.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_empty.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_empty.gif" width="9" height="9" border="0">&nbsp;&nbsp;&nbsp;Terrible<br>';
ratingBox += '<input type="radio" name="sNum" value="3" checked>&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_empty.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_empty.gif" width="9" height="9" border="0">&nbsp;&nbsp;&nbsp;Feh<br>';
ratingBox += '<input type="radio" name="sNum" value="4">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_empty.gif" width="9" height="9" border="0">&nbsp;&nbsp;&nbsp;Pretty damn good<br>';
ratingBox += '<input type="radio" name="sNum" value="5">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9" border="0">&nbsp;<img src="' + imagePath + '/rating_circle_filled.gif" width="9" height="9" border="0">&nbsp;&nbsp;&nbsp;Awesomely Outrageous<br>';
ratingBox += '<br><strong>Comments</strong>:<br><textarea name="sDescription" style="width: 100%; height: 70px"></textarea><br>';
ratingBox += '<br><input type="submit" name="rate" value="rate" onclick="alert(\'' + alertMessage + '\')">';
ratingBox += '</div></form>';
ratingBox += '</div>';

if (isDom) {
	document.write(ratingBox);
	rb = document.getElementById("ratingBox");
}

function resizeWindows() {
	if (rwIsLoaded) {
		popUserRating();
	}
}

function closeRatingWindow() {
	rb.style.visibility = "hidden";
	//rb.innerHTML = "";
	//rb.style.left = 0;
	//rb.style.top = 0;
	rwIsLoaded = false;
}

function popUserRating() {
	scrollOffset = (window.pageYOffset) ? window.pageYOffset : document.body.scrollTop;
	if (isDom) { 
		//lp = (window.screenLeft) ? (myWidth / 2) - (ratingBoxWidth / 2) : (myWidth / 2) - (ratingBoxWidth / 2);
		//tp = (window.screenTop) ? (myHeight / 2) - (ratingBoxHeight / 2): (myHeight / 2) - (ratingBoxHeight / 2);
		lp = (window.screenLeft) ? (document.body.clientWidth / 2) - (ratingBoxWidth / 2) : (document.body.clientWidth / 2) - (ratingBoxWidth / 2);
		tp = (window.screenTop) ? (document.body.clientHeight / 2) - (ratingBoxHeight / 2) + scrollOffset: (document.body.clientHeight / 2) - (ratingBoxHeight / 2) + scrollOffset;
		/*if (tp < 355) {
			tp = 355;
		}*/
		
		rb.style.top = tp;
		rb.style.left = lp;

		hideElement('SELECT', rb);
		hideElement('APPLET', rb);
		hideElement('OBJECT', rb);
		hideElement('EMBED', rb);
		
		rb.style.visibility = "visible";
		rwIsLoaded = true;
	}
}

window.onresize = resizeWindows;