﻿// JScript File
var m_animDIV = null;
var firstTimeSend="true";
var loadingImg = new Image();	
loadingImg.src = appPathScript + "/media/images/general/animated_clock.gif";

function showLoading(obj)
{
    obj.innerHTML = "<table width='100%' height='100%' class='Loading'><tr><td valign='middle' align='center'><img src='" + loadingImg.src + "' style=''><br/><br/>Loading...</td></tr></table>";
}

function callbackGetObjectInnerHTML(response)
{
    m_animDIV.innerHTML = response; 
}

function getAnimationInfo(AnimID)
{
    
    if(firstTimeSend=="true")
    {
		var url = appPathScript + "/Pages/Application/Player/PlayerRelated.aspx";
		var params = "AnimationID="+AnimID;
		
		m_animDIV = document.getElementById("relatedSection");
		AJAX.syncWithCallback(url, params, "callbackGetObjectInnerHTML", false, false);
    }
    
}

function addAnimationToFav()
{
	if(playerAnimationID==null || playerAnimationID<=0)
    {
        return;
    }
    else
    {
	    var url = appPathScript + "/Pages/Application/Player/PlayerQuickSrv.aspx";
	    var params = "action=addanimtofav&animationID=" + playerAnimationID;
	    var callbackFunc = "callbackAddAnimToFav";
	    AJAX.asyncWithCallback(url, params, callbackFunc, true, false) ;
    }
}
	
function setYourRating(v)
{

	if(playerAnimationID==null || playerAnimationID<=0)
		return;
			
	var url = appPathScript + "/Pages/Application/Player/PlayerQuickSrv.aspx";
	var params = "action=setYourRating&animationID=" + playerAnimationID + "&voteRate=" + v;

	var callbackFunc = "callbackSetYourRating";
	AJAX.asyncWithCallback(url, params, callbackFunc, true, false) ;
}

function setFlagAnimation(f)
{
	if(playerAnimationID==null || playerAnimationID<=0)
		return;
		
	var ddl = document.getElementById(f).getElementsByTagName('select')[0];
	if(ddl.options[ddl.selectedIndex].value<=0)
		return;
	else
		var v = ddl.options[ddl.selectedIndex].value;
	
	var url = appPathScript + "/Pages/Application/Player/PlayerQuickSrv.aspx";
	var params = "action=setFlagAnimation&animationID=" + playerAnimationID + "&fID=" + v;

	var callbackFunc = "callbackSetFlagAnimation";
	AJAX.asyncWithCallback(url, params, callbackFunc, true, false) ;
	
}

function callbackSetFlagAnimation(response)
{

	if(response == "-1")	
		showCustomPopupExt("popupId", "Flags", "You have already flaged this animation", new Array("OK,hidePopup('popupId')"), 300,'2');
	
	else if(response == "0")
		showCustomPopupExt("popupId", "Flags", "General error, try later", new Array("OK,hidePopup('popupId')"), 300,'2');
	
	else // response == "1"	
	{
		showCustomPopupExt("popupId", "Flags", "Thank you for flagging", new Array("OK,hidePopup('popupId')"), 300,'2');
	}
	
}
	
function callbackSetYourRating(response)
{
	if(response == "-2")
	{		
		showPopupExt('popup_your_rating_sign_in','2');
	}	
	else
	{
	     if(response == "-1")
	     {
	 	    showCustomPopupExt("popupId", "Your rating", "You have already voted for this animation", new Array("OK,hidePopup('popupId')"), 300,'2');
	     }
	     else
	     {
	          if(response == "0")
	          {
	  	        showCustomPopupExt("popupId", "Your rating", "General error, try later", new Array("OK,hidePopup('popupId')"), 300,'2');
	          }
	          else // response == "1"
	          {
		        //showCustomPopup("popupId", "Your rating", "Thank you for voting", new Array("OK,hidePopup('popupId')"), 300);
		        document.getElementById('tdThanks').style.display = '';
		        rateMovie(response);
	           }
	      }   
	 }  
}

function callbackAddAnimToFav(response)
{
	if(response == "-2")
		showPopupExt('popup_favorites_sign_in','2');
	
	else if(response == "-1")
		showCustomPopupExt("popupId", "Add to favorites", "This movie already exists in your favorites", new Array("OK,hidePopup('popupId')"), 300,'2');
	
	else if(response == "0")
		showCustomPopupExt("popupId", "Add to favorites", "General error, try later", new Array("OK,hidePopup('popupId')"), 300,'2');
	
	else // response == "1"
		showPopupExt('popup_add_to_favorites','2');
}
	
function GetLinkPress(id)
{
    if (document.getElementById(id))
    {   
        toggleLinkActivation(id);
    }
    else
    {
        window.setTimeout(function() {
            GetLinkPress(id);
        }, 1000);
    }
}
	
	
function DoSaveFromWhere(isBack,idd,hiddenId)
{
    if(isNullOrUndefined(isBack) == true)
	{
		
    }
    else    
    { 
        idd.href +=  document.getElementById(OldMovieSelected).value + document.getElementById('OldMovieSelectedSort').value + document.getElementById('OldMovieSelectedTimeLine').value;       
    }
    
}
//Handle saving from where did we come for continues related ( when we move to 
// to other pages
function SaveFromWhereHelp(id)
{
   
    var isBack = true;    
    DoSaveFromWhere(isBack,this,OldMovieSelected);
}

function SetParams(animId,ParamName,ParamValue,GoToName,GoToValue)
{
	document.getElementById("hidParams").value = "animationID=" + animId +
	"&" + ParamName + "=" +ParamValue;
	var CheckOld = document.getElementById(OldMovieSelected);
	CheckOld.value = "&" + GoToName +"="+GoToValue;
}
function SetParamsCutout( animId )
{
    document.getElementById("hidParams").value = "animationID=" + animId;// + "&isCO=true";	
}

function setSelectedOptionByValue(objSelect, selectedVal)
{
    objSelect.options[objSelect.selectedIndex].selected = false;
    var selectedIndexByDefault = objSelect.selectedIndex;
    var isSelected = false;            
    for (var i=0; i < objSelect.options.length; i++)
    {
        if (objSelect.options[i].value==selectedVal)
        {
            objSelect.options[i].selected = true;
            isSelected = true;
            break;
        }                     
    }
    if (!isSelected)
    {
        objSelect.options[selectedIndexByDefault].selected = true;
    }	
}