// JavaScript Document

function signIn() {
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ffversion > 0) {
	}
}
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion > 0)
{ 
}
}

	tb_show("Login", "dft_signin.php?KeepThis=true&TB_iframe=true&height=150&width=400", false);
}


function signOut() {
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ffversion > 0)
	{ }
}
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion > 0)
{ }
}
	tb_show("Logout", "dft_signout.php?KeepThis=true&TB_iframe=true&height=150&width=400", false);
}

function updateMobileInfo() {
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ffversion > 0)
	{ scroll(0, 2000); }
}
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion > 0)
{  }
}
	tb_show("Update Mobile Information", "updateMobileInfo.php?KeepThis=true&TB_iframe=true&height=500&width=700", false);
}

function checkCurrentlyWatching() {
$(".watchNow").each(function () {
	var thisVid = $(this).attr("vidid");
      $(this).html('<a href="javascript:sendToPlayer(' + thisVid + ');">Watch Now</a>');
    });
$(".itemSelected > .watchNow").html("Currently Watching");
}

function updateNormalPage(vid, sid) {
	
videoID = vid;
showID = sid;
if ( $("#characterPod").length > 0 ) {  
changeSpryData(sid);
}
$.get('shared_libs/php-bin/services/ajax/getAJAXcontent.php?param=getVideoMetaData&id=' + vid + '', function(data){
$("#videoMetaTitle").html(data);
});

$.get('shared_libs/php-bin/services/ajax/getAJAXcontent.php?param=getShowTitle&id=' + vid + '', function(data){
$(".itemSelected").addClass("item");
$(".itemSelected").removeClass("itemSelected");
var string = "#" + data;
$(string).addClass("itemSelected");
checkCurrentlyWatching();
});

if ( $("#comments").length > 0 ) {  
getComments(videoID,showID, 0, 5);
}
	else {
		
	$(".itemSelected").addClass("item");
	$(".itemSelected").removeClass("itemSelected");
	}
}

function changeSpryData(showid) {
	
			ds1.url = 'shared_libs/php-bin/services/characterList.php?showid=' + showid;
			ds1.loadData();


	// Callers are allowed to pass either a string, an object or an array of

	// strings and/or objects for the 'subPaths' option, so make sure we normalize

	// the subPaths value to be an array.



	}



function newTag(sid) {
	$.get('shared_libs/php-bin/services/ajax/getAJAXcontent.php?param=getRandomTag&showid=' + sid + '', function(data){
$("#logo").html(data);	
																											 });
}

function tagTimer(sid, timeout) {
newTag(sid);
setInterval ( "newTag(" + sid + ")", timeout );
}

function postComment(vidid,showid,myComment) {

	$.post("comments/php-bin/services/postComment.php", { comment: myComment, vid: vidid, show: showid },
		     function(data){
   $("#comments > #postComments").html(data);	
  });
}

function deleteComment(commentId) {
	$.post("comments/php-bin/services/removeComment.php", { comment: commentId },
		     function(data){
			
   getComments(videoID,showID, 0, 5);
  });
}

function showPostComment() {
	$("#paginationCommentWrapper").css("display", "none");
	if (readCookie('dft_userid') > 0) {
	$("#comments > #viewComments").css("display", "none");
	$("#comments > #postComments").css("display", "block");
	$("#commentTab").addClass("select");
	$("#commentTab").html("View Comments");
	$("#commentTab").attr("href", "javascript:hidePostComment()");
	}
	else {
		$("#comments > #viewComments").css("display", "none");
		$("#comments > #loginComments").css("display", "block");
		$("#commentTab").html("View Comments");
		$("#commentTab").attr("href", "javascript:hidePostComment()");
	}
}
function hidePostComment() {
	$("#paginationCommentWrapper").css("display", "block");
	$("#comments > #viewComments").css("display", "block");
	$("#comments > #postComments").css("display", "none");
	$("#comments > #loginComments").css("display", "none");
	$("#commentTab").removeClass("select");
	$("#commentTab").html("Post Comment");
	getComments(videoID,showID, 0, 5);
	$("#commentTab").attr("href", "javascript:showPostComment()");
}

function getComments(vidid, showid, rangeMin, rangeMax) {
	$("#paginationCommentWrapper").css("display", "block");
	$.get('comments/php-bin/component.php?vidid=' + vidid + '&showid=' + showid + '&rangeMin=' + rangeMin + '&rangeMax=' + rangeMax + '', function(data){
		$("#comments > #viewComments").html(data);		
		$("#comments > #postComments").html('<form name="comment" id="domComment"><div class="inputfield"><div class="fieldDesc">Comment:</div><textarea name="commentText" id="commentText" cols="40" rows="10"></textarea></div><div class="inputfield"><a href="javascript:postComment(videoID, showID, document.forms[\'comment\'].commentText.value)">Post Comment</a></div> </form>');
	
	
	
	});

}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
var parentLogic = "";
function tabEvent(parent,clickElem,targetElem,script,param) {
	
		parentLogic = param;

       $.get("" + script + "?param=" + param +"&sortby=" + getChildLogic() + getFilterLogic(), function(data){
        $(targetElem).html(data);
        buildPagination();
        if (gethideViewMore()) {
           $('#viewOptions').css('display', 'none');	
        }
});
        $(parent + " ul#tabs li a").removeClass("select");
        $(clickElem).addClass("select");
    }
function nill() {
   
}
function getParentLogic() {
	return parentLogic
}
var childLogic = "";

	function subTabEvent (parent,clickElem,targetElem,script,param) {
	childLogic = param;
       $.get("" + script + "?param=" + getParentLogic() + "&sortby=" + param + getFilterLogic(), function(data){
        $(targetElem).html(data);
        buildPagination();
        if (gethideViewMore()) {
           $('#viewOptions').css('display', 'none');	
        }

});
        $(parent + " #subTabs li a").removeClass("select");
        $(clickElem).addClass("select");
    }
    function getChildLogic() {
    return childLogic;
    }
var filterLogic = "";
    function filterEvent(script,param1,param2,targetElem) {
    filterLogic = "&show=" + param1 + "&artist=" + param2;
   
    $.get("" + script + "?param=" + getParentLogic() + "&sortby=" + getChildLogic() + filterLogic, function(data){
    	 buildPagination();

        $(targetElem).html(data);
            	if (gethideViewMore()) {
           $('#viewOptions').css('display', 'none');	
        }
});
    }
    function getFilterLogic() {
    return filterLogic;
    }

 function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }
     
function stopLoading() {
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion > 0)
{ document.execCommand("Stop");
}
}
else {
	window.stop();	
}
}

function isLoggedIn() {
if (readCookie('dft_userid') > 0) {	
return true;
}
else {
return false;	
}
}


function isArtist() {
if (readCookie('dft_fa') > 0) {	
 	return true;
 	}
 	else {
 	return false;	
 	}

}



