var xmlhttp=null;
	if (window.createRequest) {
	xmlHttp = window.createRequest();
}
else {

if (window.ActiveXObject) {
    
	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
	
	xmlHttp = new XMLHttpRequest();
}
}



function gridMouseOver(obj,channelId) {
	for (var i = 1; i <= obj.id.substring(obj.id.length, obj.id.length-1); i++)
	{
		document.getElementById(channelId + 'star' + i).src=starfill.src;
	}
}
function gridMouseOut(obj,channelId) {
	for (var j = 1; j <= 5; j++)
	{
		document.getElementById(channelId + 'star' + j).src=starempty.src;
	}
}
function openDiv(channelId,userId)
{
	document.getElementById('ratinggrid' + channelId).innerHTML = '<img src="images/stars/rating-empty-star.gif" name="' + channelId + 'star1" id="' + channelId + 'star1" border="0" style="cursor:pointer;" onclick="RateStation(1,' + channelId + ',1,' + userId + ')" onmouseout="gridMouseOut(this,' + channelId + ')" onmouseover="gridMouseOver(this,' + channelId + ')" onerror="" height="12" width="12"><img src="images/stars/rating-empty-star.gif" name="' + channelId + 'star2" id="' + channelId + 'star2" border="0" style="cursor:pointer;" onclick="RateStation(2,' + channelId + ',1,' + userId + ')" onmouseout="gridMouseOut(this,' + channelId + ')" onmouseover="gridMouseOver(this,' + channelId + ')" onerror="" height="12" width="12"><img src="images/stars/rating-empty-star.gif" name="' + channelId + 'star3" id="' + channelId + 'star3" border="0" style="cursor:pointer;" onclick="RateStation(3,' + channelId + ',1,' + userId + ')" onmouseout="gridMouseOut(this,' + channelId + ')" onmouseover="gridMouseOver(this,' + channelId + ')" onerror="" height="12" width="12"><img src="images/stars/rating-empty-star.gif" name="' + channelId + 'star4" id="' + channelId + 'star4" border="0" style="cursor:pointer;" onclick="RateStation(4,' + channelId + ',1,' + userId + ')" onmouseout="gridMouseOut(this,' + channelId + ')" onmouseover="gridMouseOver(this,' + channelId + ')" onerror="" height="12" width="12"><img src="images/stars/rating-empty-star.gif" name="' + channelId + 'star5" id="' + channelId + 'star5" border="0" style="cursor:pointer;" onclick="RateStation(5,' + channelId + ',1,' + userId + ')" onmouseout="gridMouseOut(this,' + channelId + ')" onmouseover="gridMouseOver(this,' + channelId + ')" onerror="" height="12" width="12">'; 

loadStars();
}
function loadStars()
{
   starempty = new Image();
   starempty.src = "images/stars/starempty.gif";
   starfill = new Image();
   starfill.src= "images/stars/starfill.gif";
}

function closeDiv(channelId,rating)
{
	setCookie(channelId, rating);
	document.getElementById('ratinggrid' + channelId).style.display = 'none';
	document.getElementById('ratelink' + channelId).style.display = 'none';
}

function RateStation(rating, channelId, ratingType, userId)
{
	alert(channelId);
	/*msrsPOST = false; // use POST instead of GET
	RSExecute(rateURL,"RateStation",rating,channelId,ratingType,userId,cb,cbError);	*/
	RateSite(rating, channelId, ratingType, userId);
	closeDiv(channelId,rating);	
	document.getElementById("ratelink"+channelId).style.display="none";
}
function setCookie(name, value, expires, path, domain, secure)
{
	var days = 0;
	var expdate = new Date("January 1, 2031");
	expdate.setTime(expdate.getTime() + days*24*60*60*1000);
	expires = expdate;
					
	document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}
function getCookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else
	{
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	{
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

function RateSite(rating, channelId, ratingType, userId)
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
 	{
		xmlHttp.open("GET", "rateStation.php?rating=" + rating + "&channelId="+ channelId, true);  
		xmlHttp.onreadystatechange = LoadContaints;
		xmlHttp.send(null);
  	}
	
}

function LoadContaints()
{
	if (xmlHttp.readyState == 4) 
	{
		if (xmlHttp.status == 200) 
		{
		  //document.getElementById("inbox").innerHTML = xmlHttp.responseText ;
		} 
		else 
		{
		  //alert("here was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}

function viewIcrease(idea_id)
{
	//alert(site_id);
	var name='INCVIEW'+idea_id;
	var value=idea_id;
	var cook_name=getCookie(name);
	if(cook_name == null)
	{
		setCookie(name, value);
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
 		{
		xmlHttp.open("GET", "increaseView.php?idea_id=" + idea_id, true);  
		xmlHttp.onreadystatechange = LoadView;
		xmlHttp.send(null);
  	}
	}
}
function LoadView()
{
	if (xmlHttp.readyState == 4) 
	{
		if (xmlHttp.status == 200) 
		{
		  //document.getElementById("inbox").innerHTML = xmlHttp.responseText ;
		} 
		else 
		{
		  //alert("here was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}



function WatchNow(url,site_id)
{
	var name='INCVIEW'+site_id;
	var value=site_id;
	var cook_name=getCookie(name);
	if(cook_name == null)
	{
		setCookie(name, value);
		viewIcrease(site_id);
	}
	
	window.open(url,'watchwindow','height=600, width=800, resizable=1,location=1,status=1,scrollbars=1');
}
