// JavaScript Document
function internetE() {
	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)
{ 
		return true;
}
else {
		return false;
}
}
else {
	return false;
}
}
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 unregMobileSend(cid, type, url) {
	launchTB("sendMediaItem.php?type=" + type + "&method=sms&mywallpaper_loc=" + encodeURIComponent(url) + "&offerId=" + cid + "&keepThis=true&TB_iframe=true&height=640width=605", "Send To Phone");
}
function unregPcSend(cid, type, url) {
	launchTB("sendMediaItem.php?type=" + type + "&method=email&mywallpaper_loc=" + encodeURIComponent(url) + "&offerId=" + cid + "&keepThis=true&TB_iframe=true&height=640width=605", "Download To Pc");
}
function launchTB(url, title) {
    tb_show(title, url, false);
}
function downloadWallpaper(url,cid) {
	if (readCookie('dft_userid') > 0) {
		
		if (url.match(/\?/) != null) {
			url = url + "&KeepThis=true&TB_iframe=true&height=600&width=800";
		}
		else {
			url = url + "?KeepThis=true&TB_iframe=true&height=800&width=600";
		}
			launchTB(url, "Right click image & Hit Save As...");
	}
	else {
		unregPcSend(cid, "wallpaper", url);
	}
}
function sendSMSWallpaper(url,cid) {
		unregMobileSend(cid, "wallpaper", url);
}


function isignIn(cb) {
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?&cb=" + cb + "&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");
		var thisSid = $(this).attr("sid");
      $(this).html('<a href="javascript:sendToPlayer(' + thisVid + ', ' + thisSid + ');">Watch Now</a>');
    });
$(".itemSelected > .watchNow").html("Currently Watching");
}


function updateUserPage(vid, sid) {
	videoID = vid;
	showID = sid;
if ( $("#characterPod").length > 0 ) {  
  reloadCpod(sid);
}

$.get('shared_libs/php-bin/services/ajax/getAJAXcontent.php?param=getVideoMetaData&id=' + vid + '&sid=' + showID, function(data){
$("#videoMetaTitle").html("<h1> User Videos | </h1>" + data);
});

$.get('shared_libs/php-bin/services/ajax/getAJAXcontent.php?param=getShowTitle&id=' + vid + '&sid=' + showID, function(data){
$(".itemSelected").addClass("item");
$(".itemSelected").removeClass("itemSelected");
var string = "#" + data;
$(string).addClass("itemSelected");
checkCurrentlyWatching();
});
if ( $("#comments").length > 0 ) {  
	getUserComments(videoID,showID, 0, 5);
}
	else {
		
	$(".itemSelected").addClass("item");
	$(".itemSelected").removeClass("itemSelected");
	};

}

function updateNormalPage(vid, sid) {
if (sid == 9) {
	updateUserPage(vid, sid);
}
else {
	
videoID = vid;
showID = sid;
if ( $("#characterPod").length > 0 ) {  
  reloadCpod(sid);
}
if (sid == 17){
	$.get('shared_libs/php-bin/services/ajax/getAJAXcontent.php?param=getJazzPod&id='+ videoID +'', function(data){
	$("#jazzBelt").html(data);
	});
	$.get('shared_libs/php-bin/services/ajax/getAJAXcontent.php?param=getArtistByVid&id='+ videoID +'', function(data){
	thisMovie('jazz').updateArtist(data);
	});
	$.get('shared_libs/php-bin/services/ajax/getAJAXcontent.php?param=getArtistSoundBytes&id='+ videoID +'', function(data){
	setJazzWidget(data);
	});
}
$.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);
	rebuildPagination(videoID, showID);
}
	else {
		
	$(".itemSelected").addClass("item");
	$(".itemSelected").removeClass("itemSelected");
	}
}

}

function changeSpryData(showid) {
	}

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 SetCookie(cookieName,cookieValue,nDays) { 
var today = new Date(); 
var expire = new Date(); 
if (nDays==null || nDays==0) { 
	nDays=1 
	}
expire.setTime(today.getTime() + 3600000*24*nDays); 
document.cookie = cookieName+"="+escape(cookieValue) 
+ ";expires="+expire.toGMTString(); 
} 

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 updateArtist(target, param) {
	//alert("shared_libs/php-bin/services/getArtistByShow.php?showid=" + param + "&type=" + getCurrentTab());
	$.get("/shared_libs/php-bin/services/ajax/getArtistByShow.php?showid=" + param + "&type=" + getCurrentTab(), function(data) {
		//alert(data);
		$(target).html(data);
	});
}
    function filterEvent(script,param1,param2,targetElem, uArtists) {
    if (uArtists == true) {
    	updateArtist("#artist", param1)
    }
    
    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 updatePageAfterLogin(screenname,userid) {
	$('#loginName').text('Hey '+screenname);
	$('#logonInfoBox').html('<a href="about.php?keepThis=true&TB_iframe=true&height=240width=605" title="About Digital Funtown" class="thickbox">about</a> | <a href="javascript:signOut();">logout</a>');
	if ($('#comments').html()) 
		{showPostComment();}
	//Notify all flash elements
	if (thisMovie('myvideoPlayer'));
	{thisMovie('myvideoPlayer').updateLoginStatus(true, userid);}
}
function updatePageAfterLogout() {
	$('#loginName').text('');
	$('#logonInfoBox').html('<a href="about.php?keepThis=true&amp;TB_iframe=true&amp;height=240width=605" title="About Digital Funtown" class="thickbox">about</a> | <a href="javascript:signIn();">login</a> | <a href="register.php">register</a>');
	if ($('#comments').html()) 
		{hidePostComment();}
	//Notify all flash elements
	if (thisMovie('myvideoPlayer'));
	{thisMovie('myvideoPlayer').updateLoginStatus(false, '0');}	

}
	
