var SiteImagesDefault = null;
var CobrandImages = null;

var CLEAR_VIDEO_COMMENTS_CONFIRMATION_RATE = 2000;

//rotating thumb functions
var changing_thumbs = new Array();
function changeThumb(index, i, num_thumbs, path, dimStr, ext)
{
	if (changing_thumbs[index])
	{
		$(index).src = path + "_" + i + "_" + dimStr + "." + ext;
		
		i = i % num_thumbs;
		i++;
		setTimeout("changeThumb('" + index + "'," + i + ", " + num_thumbs + ", '" + path + "', '" + dimStr + "', '" + ext + "')", 600);
	}
}	
function startThumbChange(index, num_thumbs, path, dimStr, ext)
{	
	changing_thumbs[index] = true;
	
	changeThumb(index, 1, num_thumbs, path, dimStr, ext);
}
function endThumbChange(index, origPath)
{
	changing_thumbs[index] = false;
	$(index).src = origPath;
}

function RedirectParent(url)
{
    if ( window.opener == null )
    {
        window.location.href = url;
    }
    else
    {
        window.opener.location.href = url;
        window.close();
    }
}

// This function is included to overcome a bug in Netscape's implementation
// of the escape () function:

function myunescape (str)
{
	// convert all + signs to %20
	str = str.replace( /\+/g, "%20" );

	return unescape (str);
}


function reportvideo( videoID )
{
	var url = '/index.php?show=ajaxFlagVideo';
	new Ajax.Request(url, {
		  method: 'post',
		  parameters: "videoID="+videoID,
	 	  onSuccess: function(transport) {
			  alert('Thanks for reporting, we will check this vidoe asap!');
		  }
	});
}

function bookmarksite(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
	}


function comment_report(commentID)
{
	var url = '/index.php?show=ajaxVideoCommentReport';
	new Ajax.Request(url, {
		  method: 'post',
		  parameters: "commentID="+commentID,
	 	  onSuccess: function(transport) {
			  alert('Thanks for reporting, we will check this comment asap!');
		  }
	});
}

function commentsubmit()
{
	var vid = $('commentvid').value;
	var content = $('commentcontent').value;

	if ( content == "" )
	{
		alert( "Please enter a comment first!" );
		return;
	}

	// set confirmation text
	var ele = document.getElementById( "videoCommentsConfirmationDiv" );
	if ( ele )
	{
		if ( ele.innerHTML == "" )
			ele.innerHTML = "Your comment has been submitted!";
		else
		{
			ele.innerHTML = "Oops! Your comment has already been sent!";
			return;	// only allow 1 comment submitted per page
		}
	}

	// update the video comments count div
	ele = document.getElementById( "videoCommentsCountDiv" );
	if ( ele )
	{
		var curCount = ele.innerHTML;
		++curCount;
		ele.innerHTML = curCount;
	}

	var url = '/index.php?show=ajaxSubmitVideoComment';
	new Ajax.Request(url, {
		  method: 'post',
		  parameters: "videoID="+vid+"&comment="+content,
	 	  onSuccess: function(transport) {
		  }
	});
}

function ClearVideoCommentsConfirmationDiv()
{
	var ele = document.getElementById( "videoCommentsConfirmationDiv" );
	if ( ele )
	{
		ele.innerHTML = "";
	}
}

function showsharebox()
{
	$('sharebox').show();
}

function showembedbox()
{
	$('showembedbox').show();
}

function listswith(type)
{
	if(type == "related")
	{
		$('comments').removeClassName('current');
		$('related').removeClassName('current');
		$('related').addClassName('current');

		$('commentlist').hide();
		$('commenttext').hide();
		$('relatedvideolist').show();
	}

	if(type == "comments")
	{
		$('comments').removeClassName('current');
		$('related').removeClassName('current');
		$('comments').addClassName('current');

		$('commentlist').show();
		$('commenttext').show();
		$('relatedvideolist').hide();
	}
}

function checkreg()
{

	if($('sign_captach').value == "" || $('sign_password2').value == "" || $('sign_password').value == "" || $('sign_usename').value == "" || $('sign_email').value == "")
	{
		alert('please input all necessary infos!');
		return false;
	}

	if($('sign_password2').value != $('sign_password').value)
	{
		alert('please check your password, need to input the same password!');
		return false;
	}

	if(!$('sign_agreement').checked)
	{
		alert('You need agree with the terms and condtions and privacy policy when you reg the account!');
		return false;
	}
	
	if(!isValidEmail($('sign_email').value))
	{
		alert('Email address is not correct!');
		return false;
	}

}

function checkfeedback()
{
	if(!isValidEmail($('email').value))
	{
		alert('Please input the correct email address');
		return false;
	}

	if($('message').value == "")
	{
		alert('Please input the message');
		return false;
	}


	if($('name').value == "")
	{
		alert('Please input the message');
		return false;
	}


}

function checkinvit()
{
	var email=0;

	for ( i = 1; i <= 5; i++ )
	{
		if ( $( "friend"+i+"_email" ).value != "" )
		{
			if ( !isValidEmail( $( "friend"+i+"_email" ).value ) )
			{
				alert("Email address(s) is/are not valid!");
				return false;
			}
            
			email++;
		}
		
	}

	if ( email == 0 )
	{
		alert("You have to input one email address at least!");
		return false;
	}
	
	if ( $("my_preferred_name").value == "" )
	{
		alert("You have to input your name!");
		return false;
	}

	if ( $("message").value == "")
	{
		alert("You have to input a message to send to your friends!");
		return false;
	}

	if ( $("verifycode").value == "")
	{
		alert("Please enter the verify code below!");
		return false;
	}

	return true;
}

function iif(expr, ifTrue, ifFalse)
{
  return (expr ? ifTrue : ifFalse);
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function findAbsPos(oId)
{
	var o = document.getElementById( oId );
	var obj = o;
	var x = 0;
	var y = 0;

	if ( o.offsetParent )
	{
		x = o.offsetLeft;
		y = o.offsetTop;

		while ( o = o.offsetParent )
		{
			x += parseInt( o.offsetLeft );
			y += parseInt( o.offsetTop );
		}
	}
	return [ x,	y ];
}

function getFormParameters(theForm)
{
	var oFields = document.getElementById( theForm ).elements;
	var x = 0;
	var paramStr = "";

	if ( oFields != null )
	{
		for (x = 0; x <= oFields.length - 1; x++)
		{
			if ( ( oFields[ x ].type == "hidden" ) || ( oFields[ x ].type == "text" ) )
			{
				paramStr += "&" + oFields[ x ].name + "=" + encodeURI( oFields[ x ].value );
			}

			if ( oFields[ x ].type == "textarea" )
			{
				paramStr += "&" + oFields[ x ].name + "=" + encodeURI( oFields[ x ].value );
			}

			else if ( oFields[ x ].type == "checkbox" )
			{
				paramStr += "&" + oFields[ x ].name + "=" + ( oFields[ x ].checked ? "1" : "0" );
			}

			else if ( oFields[ x ].type == "radio" )
			{
				paramStr += "&" + oFields[ x ].name + "=" + ( oFields[ x ].checked ? "1" : "0" );
			}

			else if ( oFields[ x ].type == "select-one" )
			{
				paramStr += "&" + oFields[ x ].name + "=" + oFields[ x ].value;
			}
		}
	}

	return paramStr;
}

function calcAge(fromDate)
{
    var Age = -1;
    var today = new Date();
    var birthDate = parseDate( fromDate );

    if ( birthDate != null )
    {
        Age = today.getFullYear() - birthDate.getFullYear();
        
        if ( birthDate.getMonth() > today.getMonth() )
        {
            Age -= 1;
        }
        else if ( birthDate.getMonth() == today.getMonth() && birthDate.getDate() > today.getDate() )
        {
            Age -= 1;
        }
    }
    
    return Age;
}

function generatePassword(length)
{
	if ( ( length = null ) || ( length <= 0 ) || ( length >= 21 ) )
		length = 5;

	chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	pass = "";

	for (x = 0; x < length; x++)
	{
		i = Math.floor( Math.random() * 62 );
		pass += chars.charAt( i );
	}

	return pass;
}

function calcZodiacSign(bDay)
{
	var thisFullDate = parseDate( bDay );
	var thisYear = thisFullDate.getFullYear();
	var thisMonth = thisFullDate.getMonth() + 1;
	var thisDate = thisFullDate.getDate();
	var zodiacSign = "";

	if ( thisMonth == 1 && thisDate >= 20 || thisMonth == 2 && thisDate <= 18 )
	{
		zodiacSign = "Aquarius";
	}

	if ( thisMonth == 2 && thisDate >= 19 || thisMonth == 3 && thisDate <= 20 )
	{
		zodiacSign = "Pisces";
	}

	if ( thisMonth == 3 && thisDate >= 21 || thisMonth == 4 && thisDate <= 19 )
	{
		zodiacSign = "Aries";
	}

	if ( thisMonth == 4 && thisDate >= 20 || thisMonth == 5 && thisDate <= 20 )
	{
		zodiacSign = "Taurus";
	}

	if ( thisMonth == 5 && thisDate >= 21 || thisMonth == 6 && thisDate <= 21 )
	{
		zodiacSign = "Gemini";
	}

	if ( thisMonth == 6 && thisDate >= 22 || thisMonth == 7 && thisDate <= 22 )
	{
		zodiacSign = "Cancer";
	}

	if ( thisMonth == 7 && thisDate >= 23 || thisMonth == 8 && thisDate <= 22 )
	{
		zodiacSign = "Leo";
	}

	if ( thisMonth == 8 && thisDate >= 23 || thisMonth == 9 && thisDate <= 22 )
	{
		zodiacSign = "Virgo";
	}

	if ( thisMonth == 9 && thisDate >= 23 || thisMonth == 10 && thisDate <= 22 )
	{
		zodiacSign = "Libra";
	}

	if ( thisMonth == 10 && thisDate >= 23 || thisMonth == 11 && thisDate <= 21 )
	{
		zodiacSign = "Scorpio";
	}

	if ( thisMonth == 11 && thisDate >= 22 || thisMonth == 12 && thisDate <= 21 )
	{
		zodiacSign = "Sagittarius";
	}

	if ( thisMonth == 12 && thisDate >= 22 || thisMonth == 1 && thisDate <= 19 )
	{
		zodiacSign = "Capricorn";
	}
	return zodiacSign;
}

function calcChineseSign(bDay)
{
	var startYear = 1901;
	var thisFullDate = parseDate( bDay );
	var thisYear = thisFullDate.getFullYear();
	var thisMonth = thisFullDate.getMonth();
	var thisDate = thisFullDate.getDate();
	var chineseSign = "";

	x = ( startYear - thisYear ) % 12

	if ( x == 1 || x == -11 )
	{
		chineseSign = "Rat";
	}

	if ( x == 0 )
	{
		chineseSign = "Ox";
	}

	if ( x == 11 || x == -1 )
	{
		chineseSign = "Tiger";
	}

	if ( x == 10 || x == -2 )
	{
		chineseSign = "Rabbit/Cat";
	}

	if ( x == 9 || x == -3 )
	{
		chineseSign = "Dragon";
	}

	if ( x == 8 || x == -4 )
	{
		chineseSign = "Snake";
	}

	if ( x == 7 || x == -5 )
	{
		chineseSign = "Horse";
	}

	if ( x == 6 || x == -6 )
	{
		chineseSign = "Sheep";
	}

	if ( x == 5 || x == -7 )
	{
		chineseSign = "Monkey";
	}

	if ( x == 4 || x == -8 )
	{
		chineseSign = "Cock/Phoenix";
	}

	if ( x == 3 || x == -9 )
	{
		chineseSign = "Dog";
	}

	if ( x == 2 || x == -10 )
	{
		chineseSign = "Boar";
	}
	return chineseSign;
}

function isValidEmail(Email)
{
	var checkTLD = 1;
	var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat = /^(.+)@(.+)$/;
	var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars = "\[^\\s" + specialChars + "\]";
	var quotedUser = "(\"[^\"]*\")";
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom = validChars + '+';
	var word = "(" + atom + "|" + quotedUser + ")";
	var userPat = new RegExp( "^" + word + "(\\." + word + ")*$" );
	var domainPat = new RegExp( "^" + atom + "(\\." + atom + ")*$" );
	var matchArray = Email.match( emailPat );

	if ( matchArray == null )
		return false;

	var user = matchArray[ 1 ];
	var domain = matchArray[ 2 ];

	for (i = 0; i < user.length; i++)
	{
		if ( user.charCodeAt( i ) > 127 )
		{
			return false;
		}
	}

	for (i = 0; i < domain.length; i++)
	{
		if ( domain.charCodeAt( i ) > 127 )
		{
			return false;
		}
	}

	if ( user.match( userPat ) == null )
	{
		return false;
	}

	var IPArray = domain.match( ipDomainPat );

	if ( IPArray != null )
	{
		for (var i = 1; i <= 4; i++)
		{
			if ( IPArray[ i ] > 255 )
			{
				return false;
			}
		}
		return true;
	}

	var atomPat = new RegExp( "^" + atom + "$" );
	var domArr = domain.split( "." );
	var len = domArr.length;

	for (i = 0; i < len; i++)
	{
		if ( domArr[ i ].search( atomPat ) == -1 )
		{
			return false;
		}
	}

	if ( checkTLD && domArr[ domArr.length - 1 ].length != 2 && domArr[ domArr.length - 1 ].search( knownDomsPat ) == -1 )
	{
		return false;
	}

	if ( len < 2 )
	{
		return false;
	}

	return true;
}

function isObject(o)
{
	return ( typeof o != "undefined" );
}

function explodeParamStr(responseText)
{
	var KeyName = 0;
	var KeyValue = 1;
	var ResponseList = responseText.split( "&" );
	var ResponseValues = new Array();

	for (i = 0; i < ResponseList.length; ++i)
	{
		ValueName = ResponseList[ i ].split( "=" );
		ResponseValues[ ValueName[ KeyName ] ] = ValueName[ KeyValue ];
	}
	return ResponseValues;
}

// Implementation of a new Array() method indexOf
if ( !Array.prototype.indexOf )
{
	Array.prototype.indexOf = function( elementValue, iStart, iEnd )
	{
		iStart = ( iStart == null ) ? 0 : iStart;
		iEnd = ( iEnd == null ) || ( iEnd > this.length ) || ( iEnd < iStart ) ? this.length : iEnd;

		for (iIndex = iStart; iStart < iEnd; iIndex++)
		{
			if ( this[ iIndex ] == elementValue )
				return iIndex;
		}
		return -1;
	}
}

/*
 * AJax Object found at http://www.hunlock.com/blogs/The_Ultimate_Ajax_Object
 *
 * Creating a new AJax Object:
 * var myRequest = new ajaxObject('http://www.somedomain.com/process.php');
 *
 *
 * Creating a call back funciton
 * var myRequest = new ajaxObject('http://www.somedomain.com/process.php', processData);
 *
 * function processData(responseText, responseStatus)
 * {
 *   if (responseStatus==200)
 *   {
 *     alert(responseText);
 *   }
 *   else
 *   {
 *     alert(responseStatus + ' -- Error Processing Request);
 *   }
 * }
 *
 */

function oAjax(url, callbackFunction, responsePanel, contentType)
{
	var that = this;
	var urlCall = url;
	this.responsePanel = responsePanel;
	this.updating = false;
	this.contentType = ( contentType == null ) ? "application/x-www-form-urlencoded" : contentType;

	this.callback = callbackFunction || function()
	{
	};

	this.abort = function()
	{
		if ( that.updating )
		{
			that.updating = false;
			that.AJAX.abort();
			that.AJAX = null;
		}
	}

	this.update = function( passData, postMethod )
	{
		if ( that.updating )
		{
			return false;
		}

		that.AJAX = null;

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

		if ( that.AJAX == null )
		{
			return false;
		}
		else
		{
			that.AJAX.onreadystatechange = function()
			{
				if ( that.AJAX.readyState == 4 )
				{
					that.updating = false;
					that.callback( that.AJAX.responseText, that.AJAX.status, that.responsePanel );
					that.AJAX = null;
				}
			}

			this.updating = new Date();

			if ( /post/i.test( postMethod ) )
			{
				try
				{
					var uri = urlCall + '?' + that.updating.getTime();
					that.AJAX.open( "POST", urlCall, true );
					that.AJAX.setRequestHeader( "Content-type", this.contentType ); // "application/x-www-form-urlencoded");
					that.AJAX.setRequestHeader( "Content-Length", passData.length );
					that.AJAX.send( passData );
				}
				catch (e)
				{
					if ( this.responsePanel != null )
						document.getElementById( this.responsePanel ) .innerHTML = e.description;

					else
						alert( e.description );
				}
			}
			else
			{
				try
				{
					var uri = urlCall + '?' + passData + '&timestamp=' + ( that.updating.getTime() );
					that.AJAX.open( "GET", uri, true );
					that.AJAX.send( null );
				}
				catch (e)
				{
					if ( this.responsePanel != null )
						document.getElementById( this.responsePanel ) .innerHTML = e.description;

					else
						alert( e.description );
				}
			}

			return true;
		}
	}
}

var base64KeyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function base64_Encode(input)
{
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	do
	{
		chr1 = input.charCodeAt( i++ );
		chr2 = input.charCodeAt( i++ );
		chr3 = input.charCodeAt( i++ );

		enc1 = chr1 >> 2;
		enc2 = ( ( chr1 & 3 ) << 4 ) | ( chr2 >> 4 );
		enc3 = ( ( chr2 & 15 ) << 2 ) | ( chr3 >> 6 );
		enc4 = chr3 & 63;

		if ( isNaN( chr2 ) )
		{
			enc3 = enc4 = 64;
		}

		else if ( isNaN( chr3 ) )
		{
			enc4 = 64;
		}

		output = output + base64KeyStr.charAt( enc1 ) + base64KeyStr.charAt( enc2 ) + base64KeyStr.charAt( enc3 ) + base64KeyStr.charAt( enc4 );
	} while ( i < input.length );

	return output;
}

function base64_Decode( inputTxt )
{
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	if ( isObject( inputTxt ) )
	{
		// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
		inputTxt = inputTxt.replace( /[^A-Za-z0-9\+\/\=]/g, "" );

		do
		{
			enc1 = base64KeyStr.indexOf( inputTxt.charAt( i++ ) );
			enc2 = base64KeyStr.indexOf( inputTxt.charAt( i++ ) );
			enc3 = base64KeyStr.indexOf( inputTxt.charAt( i++ ) );
			enc4 = base64KeyStr.indexOf( inputTxt.charAt( i++ ) );

			chr1 = ( enc1 << 2 ) | ( enc2 >> 4 );
			chr2 = ( ( enc2 & 15 ) << 4 ) | ( enc3 >> 2 );
			chr3 = ( ( enc3 & 3 ) << 6 ) | enc4;

			output = output + String.fromCharCode( chr1 );

			if ( enc3 != 64 )
			{
				output = output + String.fromCharCode( chr2 );
			}

			if ( enc4 != 64 )
			{
				output = output + String.fromCharCode( chr3 );
			}
		} while ( i < inputTxt.length );
	}

	return output;
}

function getInputFileSize(FormId, InputBoxId)
{
	try
	{
		var oForm = document.getElementById( FormId );
		var oInputBox = document.getElementById( InputBoxId );

		var oas = new ActiveXObject( "Scripting.FileSystemObject" );
		var Filename = document.oForm.oInputBox.value;
		var oFile = oas.getFile( Filename );
		var fileSize = oFile.size;

		if ( fileSize > 500 )
		{
			Msg = Filename + " is " + fileSize + " bytes!\n";
			Msg += "Please only send files less than 500KB!";
			alert( Msg );
			return false;
		}

		else
		{
			Msg = Filename + " is " + fileSize + " bytes!\n";
			Msg += "Thank you for not sending a file larger than 500KB!";
			alert( Msg );
			return true;
		}
	}
	catch (e)
	{
		alert( e );
	}
}

function GetBrowserTimeZoneInfo()
{
    var d = new Date();
    var jan1Local = new Date( d.getFullYear(), 0, 1, 0, 0, 0, 0 );
    var july1Local = new Date( d.getFullYear(), 6, 1, 0, 0, 0, 0 );
    var jan1GMTTemp = jan1Local.toGMTString();
    var july1GMTTemp = july1Local.toGMTString();
    var jan1GMT = new Date( jan1GMTTemp.substring( 0, jan1GMTTemp.lastIndexOf( " " ) - 1 ) );
    var july1GMT = new Date( july1GMTTemp.substring( 0, july1GMTTemp.lastIndexOf( " " ) - 1 ) );
    var janGMTDiffHour = ( jan1Local - jan1GMT ) / ( 1000 * 3600 );
    var julyGMTDiffHour = ( july1Local - july1GMT ) / ( 1000 * 3600 );

    var dst = 0;

    if ( janGMTDiffHour != julyGMTDiffHour )
    {
        dst = 1;
    }

    var res = new Array();
    res[ "stdHourOffset" ] = janGMTDiffHour;
    res[ "dst" ] = dst;

    return res;
}

function NumberFormat( nStr )
{
	nStr += '';
	x = nStr.split( '.' );
	x1 = x[ 0 ];
	x2 = x.length > 1 ? '.' + x[ 1 ] : '';
	var rgx = /(\d+)(\d{3})/;

	while ( rgx.test( x1 ) )
	{
		x1 = x1.replace( rgx, '$1' + ',' + '$2' );
	}
	return x1 + x2;
}

function checkOS()
{
	if ( navigator.userAgent.indexOf( 'IRIX' ) != -1 )
	{
		var OpSys = "Irix";
	}

	else if ( ( navigator.userAgent.indexOf( 'Win' ) != -1 ) && ( navigator.userAgent.indexOf( '95' ) != -1 ) )
	{
		var OpSys = "Windows95";
	}

	else if ( navigator.userAgent.indexOf( 'Win' ) != -1 )
	{
		var OpSys = "Windows3.1 or NT";
	}

	else if ( navigator.userAgent.indexOf( 'Mac' ) != -1 )
	{
		var OpSys = "Macintosh";
	}

	else
	{
		var OpSys = "other";
	}
	return OpSys;
}

function fixStateInput( oSi, oCi )
{
	if ( ( oCi.options[ oCi.selectedIndex ].text != "United States" ) ||
	     ( oCi.options[ oCi.selectedIndex ].text != "Canada" ) )
	{
		for ( i = 0; i < oSi.options.length; i++ )
		{
			if ( oSi.options[ i ].text == "NON USA/Canada" )
			{
				oSi.options[ i ].selected = true;
			}
		}
	}

	return (true);
}


function fixCountryInput( oSi, oCi )
{
	if ( ( oSi.options[ oSi.selectedIndex ].text != "NON USA/Canada" ) )
	{
		for ( i = 0; i < oCi.options.length; i++ )
		{
			if ( oCi.options[ i ].text == "United States" )
			{
				oCi.options[ i ].selected = true;
			}
		}
	}

	return (true);
}

function SubmitSearch()
{
	var searchStr  = document.searchForm.searchStr.value;
	var searchType = document.searchForm.searchType.value;
	var searchCID  = document.searchForm.searchCID.value;

	if ( searchStr == "" )
		return false;

	document.location = "http://" + document.location.hostname + "/search/" + searchStr + "/" + searchType + "/" + searchCID + "/1";
	return false;
}

function VideoCommentsClickPageNumber( pageNumber, numItemsPerPage, videoID )
{
	var url = '/index.php?show=ajaxGetTotalVideoComments';
	new Ajax.Request(url, {
		  method: 'post',
		  parameters: "videoID=" + videoID,
	 	  onSuccess: function(transport) 
		  {
			  var totalVideoComments = parseInt( transport.responseText );
			  var ele = document.getElementById( "videoCommentsCountDiv" ).innerHTML = totalVideoComments;

		      GetVideoComments( pageNumber, numItemsPerPage, videoID );
		  }
	});	
}

function GetVideoComments( pageNumber, numItemsPerPage, videoID )
{
	var url = '/index.php?show=ajaxGetVideoComments';
	new Ajax.Request(url, {
		  method: 'post',
		  parameters: "videoID=" + videoID + "&pageNumber=" + pageNumber + "&numItemsPerPage=" + numItemsPerPage,
	 	  onSuccess: function(transport) 
		  {
			    var ele = document.getElementById( "commentsDisplayDiv" );
				var comments = transport.responseText.split( "," );
				var html = "";
				html += '<table border="0" cellspacing="0" cellpadding="0" id="listing">';
				for ( i = 0; i < comments.length; ++i )
				{
					var pipeSplit = comments[ i ].split( "|" );
					var contents = base64_Decode( pipeSplit[ 0 ] );
					var timeFmt  = base64_Decode( pipeSplit[ 1 ] );
					
					html += "<tr>";
					html +=   "<td>";
					html +=		"<div class='comm_con'><p>" + contents + "</p></div>";
					html +=		"<div class='comm_time'>Submitted on" + timeFmt + "</div>";
					html +=	"</td>";
					html += "</tr>";
					html += "<tr><td>&nbsp;</td></tr>";
				}
				html += '</table>';			

				ele.innerHTML = html;
		  }
	});	
}

/*
//<!--
// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4,
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection

// Everything you always wanted to know about your JavaScript client
// but were afraid to ask. Creates "is_" variables indicating:
// (1) browser vendor:
//     is_nav, is_ie, is_opera, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,
//     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,
//     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//     is_sun, is_sun4, is_sun5, is_suni86
//     is_irix, is_irix5, is_irix6
//     is_hpux, is_hpux9, is_hpux10
//     is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//     is_linux, is_sco, is_unixware, is_mpras, is_reliant
//     is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when new versions of browsers are released, so
// in conditional code forks, use is_ie5up ("IE 5.0 or greater")
// is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5
// to check version in code which you want to work on future
// versions.

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1);

    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3) is_js = 1.1;
    else if (is_opera5up) is_js = 1.3;
    else if (is_opera) is_js = 1.1;
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
    else if (is_hotjava3up) is_js = 1.4;
    else if (is_nav6 || is_gecko) is_js = 1.5;
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    else if (is_nav6up) is_js = 1.5;
    // NOTE: ie5up on mac is 1.4
    else if (is_ie5up) is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else is_js = 0.0;

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) ||
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
               (agt.indexOf("windows 16-bit")!=-1) );

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 ||
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) ||
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||
                    (agt.indexOf("ibm-webexplorer")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) is_js = 1.4;
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) ||
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) ||
                                (agt.indexOf("powerpc")!=-1)));

    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);
    var is_aix2  = (agt.indexOf("aix 2") !=-1);
    var is_aix3  = (agt.indexOf("aix 3") !=-1);
    var is_aix4  = (agt.indexOf("aix 4") !=-1);
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1);
    var is_mpras    = (agt.indexOf("ncr")!=-1);
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux ||
                 is_sco ||is_unixware || is_mpras || is_reliant ||
                 is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));
*/

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();



