var xmlhttp=null;
	if (window.createRequest) {
	xmlHttp = window.createRequest();
}
else {

if (window.ActiveXObject) {
    
	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
	
	xmlHttp = new XMLHttpRequest();
}
}

	/*==============STATIC VARIABLE===========*/
	//var ROOT = "http://localhost/internettv/";
	var ROOT = "http://officialinternettv.com/";

/*==============STATIC VARIABLE===========*/

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="'+ROOT	+'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="'+ROOT	+'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="'+ROOT	+'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="'+ROOT	+'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="'+ROOT	+'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 = ROOT+"images/stars/starempty.gif";
   starfill = new Image();
   starfill.src= ROOT+"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)
{
	/*msrsPOST = false; // use POST instead of GET
	RSExecute(rateURL,"RateStation",rating,channelId,ratingType,userId,cb,cbError);	*/
	RateSite(rating, channelId, ratingType, userId);
	closeDiv(channelId,rating);		
}
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", ROOT+"rateStation.php?rating=" + rating + "&channelId="+ channelId, true);  
		xmlHttp.onreadystatechange = LoadContaints;
		xmlHttp.send(null);
  	}
	
}

function LoadContaints()
{
	if (xmlHttp.readyState == 4) 
	{
		if (xmlHttp.status == 200) 
		{
		} 
		else 
		{
		  //alert("here was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}

function viewIcrease(site_id,cook_name)
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
 	{
		xmlHttp.open("GET", ROOT+"increaseView.php?site_id=" + site_id+"&cook_name="+cook_name, 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);
	//viewDateUpdate(site_id);
	if(cook_name == null)
	{
		setCookie(name, value);
	}
	viewIcrease(site_id,cook_name);
	
	window.open(url,'watchwindow','height=600, width=800, resizable=1,location=1,status=1,scrollbars=1');
}
function viewSite(site_id)
{
	var name='INCVIEW'+site_id;
	var value=site_id;
	var cook_name=getCookie(name);
	//viewDateUpdate(site_id);
	if(cook_name == null)
	{
		setCookie(name, value);
	}
	viewIcrease(site_id,cook_name);
}

function AddToMyTv(userid,site_id,action)
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
 	{
		document.getElementById("addmytv"+site_id).src=ROOT+"images/removetv.gif";
		xmlHttp.open("GET", ROOT+"addmyfavorite.php?user_id="+ userid +"&site_id=" + site_id +"&action="+action, true);  
		xmlHttp.onreadystatechange = LoadAddFavorite;
		xmlHttp.send(null);
		document.getElementById("rem"+site_id).innerHTML="<a onclick=\"RemoveMyTv('"+userid+"','"+site_id+"','Remove')\" style='cursor:pointer;'><img src='"+ROOT+"images/removetv.gif' id='addmytv"+site_id+"' hspace='3' align='absmiddle' /></a>";
  	}
}
function RemoveMyTv(userid,site_id,action)
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
 	{
		document.getElementById("addmytv"+site_id).src=ROOT+"images/addmytv.gif";
		xmlHttp.open("GET", ROOT+"addmyfavorite.php?user_id="+ userid +"&site_id=" + site_id +"&action="+action, true);  
		xmlHttp.onreadystatechange = LoadAddFavorite;
		xmlHttp.send(null);
			document.getElementById("rem"+site_id).innerHTML="<a onclick=\"AddToMyTv('"+userid+"','"+site_id+"','Add')\" style='cursor:pointer;'><img src='"+ROOT+"images/addmytv.gif' id='addmytv"+site_id+"' hspace='3' align='absmiddle' /></a>";
		
  	}
}
function LoadAddFavorite()
{
	if (xmlHttp.readyState == 4) 
	{
		if (xmlHttp.status == 200) 
		{
			 document.getElementById("myFavDiv").innerHTML = xmlHttp.responseText ;
			 
		} 
		else 
		{
		  //alert("here was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}


function check_user()
{
	var username= document.getElementById("username").value;
	var msg="";
	var msgStart = "<font color='red'><b>Please correct the following issue.</b><br><br>";
	msgStart += "<ul>";
	var msgEnd = "</ul></font>";
	if(username=='')
	{
		msg +="<li>Please Enter user name\n</li>";
		msg=msgStart+msg+msgEnd;
		document.getElementById("error").innerHTML=msg;
		document.getElementById("username").focus();
		return false;
	}
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		xmlHttp.open("GET", ROOT+"mail_check.php?username=" + username, true);  
		xmlHttp.onreadystatechange = LoadUser;
		xmlHttp.send(null);
	}
	
}

function LoadUser()
{
	if (xmlHttp.readyState == 4) 
	{
		if (xmlHttp.status == 200) 
		{
			 
			var msg="";
			var msgStart = "<font color='red'><b>Please correct the following issue.</b><br><br>";
			msgStart += "<ul>";
			var msgEnd = "</ul></font>";
			var status = xmlHttp.responseText;
			if(status=='Invalid')
			{
				msg +="<li>Username already exists";
				msg=msgStart+msg+msgEnd;
				document.getElementById("error").innerHTML = msg;
				document.getElementById("username").focus();
				return false
			}
			 
		} 
		else 
		{
		  //alert("here was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}


function check_mail()
{
	
	var email= document.getElementById("email").value;
	var msg="";
	var msgStart = "<font color='red'><b>Please correct the following issue.</b><br><br>";
	msgStart += "<ul>";
	var msgEnd = "</ul></font>";
	if(email=='')
	{
		msg +="<li>Please Enter email\n</li>";
		msg=msgStart+msg+msgEnd;
		document.getElementById("error").innerHTML=msg;
		document.getElementById("email").focus();
		return false;
	}
	if(email!=''&&!email.match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/))
	{
		msg +="<li>Please Enter vaid email\n</li>";
		msg=msgStart+msg+msgEnd;
		document.getElementById("error").innerHTML=msg;
		document.getElementById("email").focus();
		return false;
	}
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		xmlHttp.open("GET", ROOT+"mail_check.php?email=" + email, true);  
		xmlHttp.onreadystatechange = LoadMail;
		xmlHttp.send(null);
	}
}

function LoadMail()
{
	if (xmlHttp.readyState == 4) 
	{
		if (xmlHttp.status == 200) 
		{
			 
			var msg="";
			var msgStart = "<font color='red'><b>Please correct the following issue.</b><br><br>";
			msgStart += "<ul>";
			var msgEnd = "</ul></font>";
			var status = xmlHttp.responseText;
			if(status=='Invalid')
			{
				msg +="<li>Email address already exists";
				msg=msgStart+msg+msgEnd;
				document.getElementById("error").innerHTML = msg;
				document.getElementById("email").focus();
				return false
			}
			 
		} 
		else 
		{
		  //alert("here was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}
