// JavaScript Document
var newwindow = '';

function AddToFavorites(vid,h)
{
	var v = 'videoid='+ vid +'&h='+ h;
	var u = 'index.cfm?fuseaction=vids.addfavorite';

	var myx = new Ajax.Updater({success:'favorite', failure:'favorite'}, u, {asynchronous:true,method:'post', parameters:v});
}

function AddToProfile(vid,h)
{
	var v = 'videoid='+ vid +'&h='+ h;
	var u = 'index.cfm?fuseaction=vids.addprofile';

	var myx = new Ajax.Updater({success:'profile', failure:'profile'}, u, {asynchronous:true,method:'post', parameters:v});
}

function AddComment(vid,h)
{
	var c = $('comment').value;
	
	c = stripHTML(c);

	if(!c.length){
		alert('Your comment cannot contain HTML. Please enter a new comment.');
		$('comment').value = '';
		$('comment').focus();
		return false;
	}
	
	if(checkComment(c))
	{
		var v = 'videoid='+ vid +'&hash='+ h + '&comment=' + encodeURIComponent(c);
		var u = 'index.cfm?fuseaction=newvids.addcomment';			
		
		var myx = new Ajax.Updater({success:'addcomment', failure:'commentmsg'}, u, {asynchronous:true,method:'post', parameters:v});
	}
}

function Rate(vid, h, r)
{
	var v = 'videoid='+ vid +'&hash='+ h + '&rate=' + r;
	var u = 'index.cfm?fuseaction=vids.addrating';

	var myx = new Ajax.Updater({success:'vrate', failure:'vrate'}, u, {asynchronous:true,method:'post', parameters:v});
}


function confirmDelete(){
	if(confirm('Are you sure you want to delete this video?'))
		return true;
	else
		return false;
}

function checkComment(c){			
	if(!c.length){
		//alert('You cannot leave a blank comment!');
		alert('You cannot leave a blank comment!');
		return false;
	}
	
	if(c.length > 250){
		//alert('Your comment cannot be more than 250 characters long!');
		alert('Your comment cannot be more than 250 characters long!');
		return false;
	}
				
	return true;
}

function stripHTML(str) 
{
	return str.replace(/(<([^>]+)>)/ig,"");
}

function fill(num){
	var img;
	unfill(5);
	if(num){
		for( i = num; i > 0; i--){
			img = document.getElementById('man' + i);
			img.src = 'http://x.myspace.com/images/vids/b_man-on.gif';
		}
	}
}

function unfill(num){
	var img;
	
	if(num){
		for( i = num; i > 0; i--){
			img = document.getElementById('man' + i);
			img.src = 'http://x.myspace.com/images/vids/b_man-off.gif';
		}
	}
}

function updatelength() {
	var maxChars = 250;
	var t = $('comment');
	var d = $('coml');
	var len = 0;
	
	if (t.value.length > maxChars) 
		t.value = t.value.substring(0,maxChars);

	len = maxChars - t.value.length;

	d.innerHTML = len.toString();
}

function AddCommentWithIndicator(vid, posterID, h) {
	var c = $('comment').value;
	
	c = stripHTML(c);

	if(!c.length){
		alert('Your comment cannot contain HTML. Please enter a new comment.');
		$('comment').value = '';
		$('comment').focus();
		return false;
	}
	
	if(checkComment(c))
	{
		var v = 'videoid='+ vid + '&posterID=' + posterID + '&hash='+ h + '&comment=' + encodeURIComponent(c);
		var u = 'index.cfm?fuseaction=vids.addcomment';			
		
		var myx = new Ajax.Updater({success:'addcomment', failure:'commentmsg'}, u, {asynchronous:true,method:'post', parameters:v});
	}
}
