var ERROR_NO_VIDEO_BODY_TEXT = 'Please enter a comment.';
var ERROR_LOGIN_REQUIRED = 'Please login and proceed further.';
var ERROR_REPORT_ABUSE_SAME_USER = 'Sorry, you cannot report abuse your own comments';
var ERROR_VIDEO_REMOVE_FROM_FAVS = 'Remove From Favorites';
var ERROR_VIDEO_ADD_TO_FAVS = 'Add To Favorites';

var ERROR_PLAYLIST_ADD_SUCCESS = 'Video has been added to your playlist successfully.';
var ERROR_PLAYLIST_ADD_FAILURE = 'Sorry, there may be an error while adding video to playlist.';
var ERROR_PLAYLIST_EXISTS = 'Sorry, video already exists in the playlist.';

var ERROR_VIDEO_TERMS = "Your video cannot be uploaded without you agreeing to our Terms of Use and Privacy Policy.";
var ERROR_VIDEO_TITLE = "Looks like you forgot to give a title.";

var extArray = new Array(".flv",".mov",".wmv",".avi",".mpeg",".mpg",".mp4",".ram");
var ERROR_DELETE_VIDEO_COMMENT = "Are you sure you want to delete this video comment?";
var ERROR_DELETE_VIDEO = "Are you sure you want to delete this video?";
var VIDEO_TITLE_ABUSE = 'Report Abuse';

var AjaxObject = 
{
handleSuccess_pagination:function(o){
	document.getElementById('video_loading').style.display = 'none';
	document.getElementById("video_loading").innerHTML = '';
	document.getElementById("video_view").innerHTML = o.responseText;
	//document.getElementById("pagination2").innerHTML = o.responseText;    	    	
	//document.getElementById("adda_scribble_view").innerHTML = o.responseText;    
  },
 handleFailure_pagination:function(o){
    // Failure handler                                                                                                                                   
    },
 handleSuccess_delete_video:function(o){
    document.getElementById('video_loading').style.display = 'none';
    document.getElementById("video_loading").innerHTML = '';
    document.getElementById("video").innerHTML = o.responseText;    		
  },
 handleFailure_delete_video:function(o){
    // Failure handler                                                                                                                                   
  },
handleStart_videos:function(){
	document.getElementById("video_loading").innerHTML = loading;
    },
handleComplete_videos:function(){
	document.getElementById("video_loading").innerHTML = loading;
    },
handleAbort_videos:function(){
	// Abort handler
    },
 handleStart_video:function(){
    document.getElementById("video_loading").innerHTML = loading;
  },
 handleComplete_video:function(){
    document.getElementById("video_loading").innerHTML = loading;
  },
 handleAbort_video :function(){
    // Abort handler
  },
 handleSuccess_video_abuse:function(o){
    if(o.responseText == 701)
      {
	  //document.getElementById('report_abuse_video').innerHTML = 'Under Review';
	  document.getElementById('report_abuse_video').innerHTML = '<a href="#" class="vertmiddle"><img src="/storage/image/default/icon/ico-under-review.gif" width="25" height="25" border="0" alt="" class="vertmiddle zero"> <b>Under Review</b></a><br class="spacer3">';

	  document.getElementById('video_success_title').innerHTML = '<h2>' + VIDEO_TITLE_ABUSE + '</h2>';
	  success_message = 'This video has been reported as abusive. It is currently under review.'
	  document.getElementById('video_success_message').innerHTML = success_message;
	  document.getElementById('video_dialog1').style.display = 'none';
	  document.getElementById('video_dialog4').style.display = 'block';
	  YAHOO.example.video_container1.video_dialog4.show();
      }
    else
	{
	    hideVideoPopup();
	}
    
  },
 handleSuccess_video_comments_abuse:function(o){
    if(o.responseText == 701)
      { 
	var abuse_id = 	document.getElementById('abuse_id').value;
	document.getElementById('abusepopup_'+abuse_id).innerHTML = '<a href="#" class="gray999">Under Review</a>';
	document.getElementById('video_success_title').innerHTML = '<h2>' + VIDEO_TITLE_ABUSE + '</h2>';
	success_message = 'This video comment has been reported as abusive. It is currently under review.'
	document.getElementById('video_success_message').innerHTML = success_message;
	document.getElementById('video_dialog2').style.display = 'none';
	document.getElementById('video_dialog4').style.display = 'block';
	YAHOO.example.video_container1.video_dialog4.show();
      }
    else
      {  
	if(o.responseText != '') 
	  {
	    displayErrorMessage('error_video_comments',o.responseText);
	  }
	hideVideoCommentsPopup();
      }
    
  },
 handleSuccess_delete_video_comment:function(o){
    document.getElementById("video_landing_comments").innerHTML = o.responseText;        
  },
 handleFailure_delete_video_comment:function(o){
    // Failure handler                                                                                                                                   
  }
 ,
handleSuccess_video_favs:function(o){
    if(o.responseText == 902)
      {
	document.getElementById("favorites").innerHTML = ERROR_VIDEO_REMOVE_FROM_FAVS;
      }
    else if(o.responseText == 901)
      {
	document.getElementById("favorites").innerHTML = ERROR_VIDEO_ADD_TO_FAVS;
      }
    else
      {
	displayErrorMessage('error_video_comments',o.responseText);
      }

  },
 handleFailure_video_favs:function(o){
    // Failure handler                                                                                                                                   
    },
handleSuccess_video_addtoplaylist:function(o){

    var response = o.responseText;

    if(response == 903)
      {
	displayErrorMessage('error_video_comments',ERROR_LOGIN_REQUIRED);
      }
    else if(response == 905)
      {
	displayErrorMessage('error_video_comments',ERROR_PLAYLIST_ADD_SUCCESS);
      }
    else if(response == 906)
      {
	displayErrorMessage('error_video_comments',ERROR_PLAYLIST_ADD_FAILURE);
      }
    else if(response == 907)
      {
	displayErrorMessage('error_video_comments',ERROR_PLAYLIST_EXISTS);
      }
    else
      {
	displayErrorMessage('error_video_comments',ERROR_PLAYLIST_ADD_FAILURE);
      }
    
    hideAddToPlaylistPopup();

  },
 handleFailure_video_addtoplaylist:function(o){
    // Failure handler                                                                                                             
    displayErrorMessage('error_video_comments',ERROR_PLAYLIST_ADD_FAILURE);
    }
,
handleSuccess_video_favs:function(o){
    if(o.responseText == 902)
      {
	document.getElementById("favorites").innerHTML = ERROR_VIDEO_REMOVE_FROM_FAVS;
      }
    else if(o.responseText == 901)
      {
	document.getElementById("favorites").innerHTML = ERROR_VIDEO_ADD_TO_FAVS;
      }
    else
      {
	displayErrorMessage('error_video_comments',o.responseText);
      }

  },
handleFailure_video_favs:function(o){
	// Failure handler                                                                                                                                   
    },
handleSuccess_video_from_user:function(o){

	var response = o.responseText;
	document.getElementById("same_user_video").innerHTML = '';
	document.getElementById("same_user_video").innerHTML = response;

    },
handleFailure_video_from_user:function(o){
	// Failure handler                                                                                                             
	// displayErrorMessage('error_video_comments',ERROR_PLAYLIST_ADD_FAILURE);
  }
};

/*
 * Define the callback object for success and failure
 * handlers as well as object scope.
 */
var callback_delete_video =
{
    customevents:{ 
	        onStart:AjaxObject.handleStart_video, 
	        onComplete:AjaxObject.handleComplete_video,     
	        onAbort:AjaxObject.handleAbort_video
	    }, 
    success:AjaxObject.handleSuccess_delete_video,
    failure:AjaxObject.handleFailure_delete_video,
    scope: AjaxObject

};

/*
 * Define the callback object for success and failure
 * handlers as well as object scope.
 */
var callback_pagination =
{
    customevents:{ 
	        onStart:AjaxObject.handleStart_videos, 
	        onComplete:AjaxObject.handleComplete_videos,	       
	        onAbort:AjaxObject.handleAbort_videos 
	    }, 
    success:AjaxObject.handleSuccess_pagination,
    failure:AjaxObject.handleFailure_pagination,
    scope: AjaxObject
};


var callback_video_abuse =
{
    success:AjaxObject.handleSuccess_video_abuse,
    scope: AjaxObject
};
function callback_video_comments_abuse(data)
{  

    if(data == 701)
      { 
        //video_dialog4
	var abuse_id = 	document.getElementById('abuse_id').value;
	document.getElementById('abusepopup_'+abuse_id).innerHTML = 'Under Review';
	//document.getElementById('video_success_title').innerHTML = '<h2>' + VIDEO_TITLE_ABUSE + '</h2>';
	success_message = 'This video comment has been reported as abusive. It is currently under review.'
	document.getElementById('video_success_message').innerHTML = success_message;
	document.getElementById('video_dialog2').style.display = 'none';
	document.getElementById('video_dialog4').style.display = 'block';
        document.getElementById('mymedia').style.display='block';
        $("#video_dialog2").dialog('destroy');
        $("#video_dialog4").dialog('destroy');
          $(function() {
      		$("#video_dialog4").dialog({
		bgiframe: true,
                title:'Report Abuse',
                width:600,
		modal: true,
                draggable: true,
                resizable:false
                });
            
             });  
      }
    else
      {  
	if(data != '') 
	  {
	    displayErrorMessage('error_video_comments',data);
	  }
	//hideVideoCommentsPopup();
         document.getElementById('mymedia').style.display='block';
	 document.getElementById('video_dialog2').style.display='none';
	 $("#video_dialog2").dialog('destroy');
      }
     
}


/* Callback object with custom events defined */ 
var callback_delete_video_comment = { 

    customevents:{ 
	        onStart:AjaxObject.handleStart_video, 
	        onComplete:AjaxObject.handleComplete_video,     
	        onAbort:AjaxObject.handleAbort_video
	    }, 
	success:AjaxObject.handleSuccess_delete_video_comment,
	failure:AjaxObject.handleFailure_delete_video_comment,
	scope: AjaxObject
   };      

/*
 * Define the callback object for success and failure
 * handlers as well as object scope.
 */
var callback_video_favs =
{
 success:AjaxObject.handleSuccess_video_favs,
 failure:AjaxObject.handleFailure_video_favs,
 scope: AjaxObject
};

/* Callback object with custom events defined */ 
var callback_video_addtoplaylist = { 

    customevents:{ 
	        onStart:AjaxObject.handleStart_video, 
	        onComplete:AjaxObject.handleComplete_video,     
	        onAbort:AjaxObject.handleAbort_video
	    }, 
	success:AjaxObject.handleSuccess_video_addtoplaylist,
	failure:AjaxObject.handleFailure_video_addtoplaylist,
	scope: AjaxObject
   };      

/* Callback object with custom events defined */ 
var callback_video_from_user = { 

    customevents:{ 
	        onStart:AjaxObject.handleStart_video, 
	        onComplete:AjaxObject.handleComplete_video,     
	        onAbort:AjaxObject.handleAbort_video
	    }, 
	success:AjaxObject.handleSuccess_video_from_user,
	failure:AjaxObject.handleFailure_video_from_user,
	scope: AjaxObject
   };      

/* Method to Disable Submit Button */
function submitVideoComment(frm)
{
    var add_button = frm.submit_comment;

    add_button.value = "Adding Data....";

    add_button.disabled = true;

    frm.submit();
}

/* Method to Display Character counts */
function restw(frm,max,dispentered)
{
    var inp = frm.value.replace(/^\s+|\s+$/g,'');
    var l = parseInt(inp.length)
        if (l > max)
	    {
                inp = inp.substr(0,max)
		frm.value = inp
	    }
    document.getElementById(dispentered).innerHTML = inp.length;
}

//! Pagination
function pagination(base_url,keyword,show_from)
{  
    var post_data = 'keyword='+keyword+'&pagination=y'+'&show_from='+show_from;

    if(keyword == '')
	{
	    
	    YAHOO.util.Connect.asyncRequest('POST',base_url, callback_pagination, post_data);       
	}
    else
	{
		
	    YAHOO.util.Connect.asyncRequest('POST',base_url, callback_pagination, post_data);       
	
	}

    if(env_value == 'Online')
	{
	    pageTracker._trackPageview(base_url);
	}
    
 

}

/* Method to toggle TABS display Status */
function toggleDivs(div_id)
{

  var tab_divs = new Array('tab_related_search','tab_related_user','tab_playlist_user');
  var tab_divs_class = new Array('relatedLink','hisherLink','playlist');

  for( var i = 0; i < 3 ; i++) 
    {
      if(tab_divs[i] == div_id)
	{
	  document.getElementById(tab_divs_class[i]).className = 'black videotabactive';
	  document.getElementById(tab_divs[i]).style.display = 'block';
	}
      else
	{
	  document.getElementById(tab_divs_class[i]).className = 'black videotab';
	  document.getElementById(tab_divs[i]).style.display = 'none';
	}
      
    }
}

function saveVideoComments(frm)
{

    document.getElementById('error_video_comments').style.display = 'none';
    document.getElementById('error_video_comments').innerHTML = '';
    
    var body_text = frm.body.value;

    if(body_text == '')
	{
	  displayErrorMessage('error_video_comments_main',ERROR_NO_VIDEO_BODY_TEXT);
	  return false;
	}
    else
	{
	    frm.submit();
	}
}

function deleteVideoComments(comment_id)
{
    if(confirm(ERROR_DELETE_VIDEO_COMMENT))
      {
      
	var video_id = document.getElementById('video_post_id').value;
	var video_comment_id = comment_id;
	var postData ='comment_id='+video_comment_id+'&video_post_id='+video_id;
	var url = system_base_url+'ajax/video/_delete_video_comment/' ;
	YAHOO.util.Connect.asyncRequest('POST',url,callback_delete_video_comment,postData);	    

	if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}

      }

}

function saveVideoReportAbuse()
{
    var selected_types = '';
    var comma = '';   
    var select_action = false;
    var abuse_types = document.video_abuse_form.abuse_type;
    var logged_in_user_id = document.getElementById('logged_in_user_id').value;
    
    for(var i=0;i<6;i++)
	{
	    if(abuse_types[i].value != '')
		{
		    if(abuse_types[i].checked)
			{
			    selected_types = selected_types + comma + abuse_types[i].value;			    
			    comma = ',';	
			    select_action = true;
			}
		}
	    
	}
    
    if(logged_in_user_id == '' || isNaN(logged_in_user_id) )
       {
	 document.getElementById('abuse_error_msg').innerHTML = ERROR_LOGIN_REQUIRED;
	 // displayErrorMessage('abuse_error_msg',ERROR_LOGIN_REQUIRED);
       }
    else if(select_action == false)
	{
	  document.getElementById('abuse_error_msg').innerHTML = 'Please select the reason for your complaint.';
	}
    else
	{	 
	  var video_abuse_id = document.getElementById('video_abuse_id').value;
	  var video_user_id = document.getElementById('video_user_id').value;
	  var postData ='abuse_types='+selected_types+'&video_abuse_id='+video_abuse_id+'&video_user_id='+video_user_id;
	  var url = system_base_url+'ajax/video/_abuse_video/' ;
	  YAHOO.util.Connect.asyncRequest('POST',url, callback_video_abuse, postData);	    
	  if(env_value == 'Online')
	      {
		  pageTracker._trackPageview(url);
	      }
	  
	 
	}

}

function saveVideoCommentsReportAbuse()
{
  
    var selected_types = '';
    var comma = '';   
    var select_action = false;
    var abuse_types = document.video_comments_abuse_form.abuse_type;
    var login_user_id = document.getElementById('login_user_id').value;
    
    for(var i=0;i<6;i++)
	{
	    if(abuse_types[i].value != '')
		{
		    if(abuse_types[i].checked)
			{
			  selected_types = selected_types + comma + abuse_types[i].value;			    
			  comma = ',';	
			  select_action = true;
			}
		}
	    
	}
     
    if(login_user_id == '' || isNaN(login_user_id))
       {
         document.getElementById('abuse_comments_error_msg').style.display = "block";
	 document.getElementById('abuse_comments_error_msg').innerHTML = ERROR_LOGIN_REQUIRED;
	 //displayErrorMessage('error_video_comments',ERROR_LOGIN_REQUIRED);	 
       }
    else if(select_action == false)
      {
        document.getElementById('abuse_comments_error_msg').style.display = "block";
	document.getElementById('abuse_comments_error_msg').innerHTML = 'Please select the reason for your complaint.';
      }
    else
    { 	 
            
	    var abuse_id = document.getElementById('abuse_id').value;
	    var abuse_user_id = document.getElementById('abuse_user_id').value;
	    var login_user_id = document.getElementById('login_user_id').value;
	    var postData ='abuse_types='+selected_types+'&abuse_id='+abuse_id+'&abuse_user_id='+abuse_user_id+'&login_user_id='+login_user_id;
	    var url = system_base_url+'ajax/video/_abuse_video_comments/'  ;
           
	    jQuery.post(url,postData,callback_video_comments_abuse);
	    //YAHOO.util.Connect.asyncRequest('POST',url, callback_video_comments_abuse, postData);	    
	 
	    if(env_value == 'Online')
	      {
		  pageTracker._trackPageview(url);
	      }
	  
	    
    }

}

//! Function to add / remove from favorites
function addRemoveFavorites(video_id,login_user_id)
{

    if(login_user_id == '' || isNaN(login_user_id))
       {
	 displayErrorMessage('error_video_comments',ERROR_LOGIN_REQUIRED);
       }
    else
      {	 
	var post_data = 'video_id='+video_id+'&login_user_id='+login_user_id;
	YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/video/_favorite_video',callback_video_favs,post_data);
      }

}

//! add to playlist by user
function addToPlaylist(playlist_id,video_id)
{
  var login_user_id = document.getElementById('logged_in_user_id').value;
  
  if(login_user_id == '' || isNaN(login_user_id))
    {
      displayErrorMessage('error_video_comments',ERROR_LOGIN_REQUIRED);
    }
  else
    {	 
      var post_data = 'playlist_id='+playlist_id+'&video_id='+video_id+'&login_user_id='+login_user_id;
      var url = system_base_url+'ajax/video/_add_to_playlist' ;
      YAHOO.util.Connect.asyncRequest('POST',url,callback_video_addtoplaylist,post_data);

      if(env_value == 'Online')
	  {
	      pageTracker._trackPageview(url);
	  }
      
    }
  
}

function uploadVideo(form,file,embed) 
{ 
   var allowSubmit = false;
   var radioObj = document.frmVideoUpload.upload_type;
   var radioLength = document.frmVideoUpload.upload_type.length;
   
   var error_title = '';
   var error_embed = '';
   var error_policy = ''; 
   var error_file = ''; 
   
   for (i=0;i<radioLength;i++)
     {
       if (radioObj[i].checked==true && radioObj[i].value == 'embeded')
	 {
	   file = '';
	 }
     }
  
   if(file !="")
       {
	   while (file.indexOf("\\") != -1)
	       file = file.slice(file.indexOf("\\") + 1);
	       ext = file.slice(file.lastIndexOf(".")).toLowerCase();
       
	       for (var i = 0; i < extArray.length; i++) 
		   {
		       if (extArray[i] == ext) 
			   {
			     document.getElementById("video_file_box").setAttribute("class", "");
			     document.getElementById("error_video_file").innerHTML = '';
			     allowSubmit = true;
			       break; 
			   }
		       else
			 {
			     var errorMsg = "The video failed to upload. Ensure video format is *.flv,*.mov, *.wmv,*.avi, *.mpeg,*.mpg,*.mp4,*.ram. Max file size: 30 MB / Length: 10 mins.";
			 }
		   }
       }
   else if(embed != "")
       {
	   str = document.getElementById('embed_code').value;
	   if(str.match(/([\<object])([^\>]{1,})*([\>])/i)==null)
	       {
		 displayErrorMessage('error_video_embed',"This is not a embed code");
		 error_embed = true;  
	       }
	   else
	       {
		 document.getElementById("video_embed_box").setAttribute("class", "");
		 document.getElementById("error_video_embed").innerHTML = '';
		 allowSubmit = true;
	       }
       }
   else
     {
       var errorMsg = "Looks like you forgot to add the video file.";
     }
  
  if (!allowSubmit) 
    {
      document.getElementById("video_file_box").setAttribute("className", "err");
      document.getElementById("video_embed_box").setAttribute("className", "err");
      displayErrorMessage('error_video_file',errorMsg);
      displayErrorMessage('error_video_embed',errorMsg);
    }

  if(document.frmVideoUpload.title.value == "")
    {
      error_title = true;
      document.getElementById("video_title_error").setAttribute("className", "err");
      displayErrorMessage('error_video_title',ERROR_VIDEO_TITLE);
     }
  else
    {
      document.getElementById("video_title_error").setAttribute("className", "");
      document.getElementById("error_video_title").innerHTML = '';
    }
  
  if(!(document.frmVideoUpload.policy.checked))
    {
      error_policy = true;
      document.getElementById("video_terms_error").setAttribute("className", "err");
      displayErrorMessage('error_video_terms',ERROR_VIDEO_TERMS);
      //      alert(ERROR_VIDEO_TERMS);
    }
  else
    {
      document.getElementById("video_terms_error").setAttribute("className", "");
      document.getElementById("error_video_terms").innerHTML = '';
    }

  if(allowSubmit == false || error_embed == true || error_title == true || error_policy==true )
    {
      return false;
    }

  var add_button = form.btnadd;  
  add_button.disabled = true;  
  form.submit();
  
}

function deleteVideoConfirmation(sendto)
{

  if(confirm(ERROR_DELETE_VIDEO))
    {
      window.location = system_base_url + 'video/_delete_video/'+sendto;
    }
  return false;
}
function doPlaylistAdd()
{
  var video_id=document.getElementById('main_video_id').value;
  window.location = system_base_url + 'video/_show_add_playlist/'+video_id;
}

function videoFromUsers(show_from_video)
{
    var lastpage = document.getElementById('lastpage').value;
    // var show_from_video = document.getElementById('show_from_video').value;
    if(show_from_video != 0)
	{
	    var user_id = document.getElementById('object_user_id').value;
	    var postData ='user_id='+user_id+'&show_from_video='+show_from_video+'&pagination=yes';
	    var url = system_base_url+'ajax/video/_show_user_video/' ;
	    YAHOO.util.Connect.asyncRequest('POST',url,callback_video_from_user,postData);	    
	}
      if(env_value == 'Online')
	  {
	      pageTracker._trackPageview(url);
	  }


}
function changeUploadType(div1,div2,frm)
{
  frm.checked = true;
  document.getElementById(div1).style.display='block';
  document.getElementById(div2).style.display='none';

}

//! add to playlist by user by jquery
function addToPlaylistJquery(playlist_id,video_id)
{
  var login_user_id = document.getElementById('logged_in_user_id').value;
  
  if(login_user_id == '' || isNaN(login_user_id))
    {
      displayErrorMessage('error_video_comments',ERROR_LOGIN_REQUIRED);
    }
  else
    {	
      var post_data = 'playlist_id='+playlist_id+'&video_id='+video_id+'&login_user_id='+login_user_id;
      var url = system_base_url+'ajax/video/_add_to_playlist' ;
      jQuery.post(url,post_data,callback_video_addtoplaylistJquery);

      if(env_value == 'Online')
	  {
	      pageTracker._trackPageview(url);
	  }
            
    }
  
}

// return data after ajac call through jquery
function callback_video_addtoplaylistJquery(data)
{
   document.getElementById('error_video_comments').style.display='block';
    if(data == 903)
      {
        document.getElementById('error_video_comments').setAttribute('className','error');
	displayErrorMessage('error_video_comments',ERROR_LOGIN_REQUIRED);
      }
    else if(data == 905)
      {
        document.getElementById('error_video_comments').setAttribute('className','success');
	displayErrorMessage('error_video_comments',ERROR_PLAYLIST_ADD_SUCCESS);
      }
    else if(data == 906)
      {
        document.getElementById('error_video_comments').setAttribute('className','error');
	displayErrorMessage('error_video_comments',ERROR_PLAYLIST_ADD_FAILURE);
      }
    else if(data == 907)
      {
        document.getElementById('error_video_comments').setAttribute('className','error');
	displayErrorMessage('error_video_comments',ERROR_PLAYLIST_EXISTS);
      }
    else
      {
        document.getElementById('error_video_comments').setAttribute('className','error');
	displayErrorMessage('error_video_comments',ERROR_PLAYLIST_ADD_FAILURE);
      }
    
    document.getElementById('mymedia').style.display='block';
    document.getElementById('video_dialog3').style.display='none';
    $("#video_dialog3").dialog('destroy');
}



//! Function to add / remove from favorites through jquery
function addRemoveFavoritesJquery(video_id,login_user_id)
{
    if(login_user_id == '' || isNaN(login_user_id))
       {
	 displayErrorMessage('error_video_comments',ERROR_LOGIN_REQUIRED);
       }
    else
      {	 
	var post_data = 'video_id='+video_id+'&login_user_id='+login_user_id;
	jQuery.post(system_base_url+'ajax/video/_favorite_video/',post_data, callback_video_favsJquery);
      }

}
// method to get data after ajax call in jquery
function callback_video_favsJquery(data)
{
 
  if(data == 902)
      {
	document.getElementById("favorites").innerHTML = ERROR_VIDEO_REMOVE_FROM_FAVS;
      }
    else if(data == 901)
      {
	document.getElementById("favorites").innerHTML = ERROR_VIDEO_ADD_TO_FAVS;
      }
    else
      {
	displayErrorMessage('error_video_comments',data);
      }
}


//! Function to mark report abuse to a video through jquery
function saveVideoReportAbuseJquery()
{
    var selected_types = '';
    var comma = '';   
    var select_action = false;
    var abuse_types = document.video_abuse_form.abuse_type;
    var logged_in_user_id = document.getElementById('logged_in_user_id').value;
    
    for(var i=0;i<6;i++)
	{
	    if(abuse_types[i].value != '')
		{
		    if(abuse_types[i].checked)
			{
			    selected_types = selected_types + comma + abuse_types[i].value;			    
			    comma = ',';	
			    select_action = true;
			}
		}
	    
	}
    document.getElementById('abuse_error_msg').style.display ="block";
    if(logged_in_user_id == '' || isNaN(logged_in_user_id) )
       {
	 document.getElementById('abuse_error_msg').innerHTML = ERROR_LOGIN_REQUIRED;
	 // displayErrorMessage('abuse_error_msg',ERROR_LOGIN_REQUIRED);
       }
    else if(select_action == false)
	{
	  document.getElementById('abuse_error_msg').innerHTML = 'Please select the reason for your complaint.';
 	}
    else
	{	
          
          document.getElementById('abuse_error_msg').style.display="none";
	  var video_abuse_id = document.getElementById('video_abuse_id_main').value;
	  var video_user_id = document.getElementById('video_user_id').value;
	  var postData ='abuse_types='+selected_types+'&video_abuse_id='+video_abuse_id+'&video_user_id='+video_user_id;
	  var url = system_base_url+'ajax/video/_abuse_video/' ;
	  jQuery.post(url, postData, callback_video_abuseJquery);	    
	   if(env_value == 'Online')
	  {
	      pageTracker._trackPageview(url);
	  }
     

	}

}
// hide abuse popup
function closePopupReportAbuseJquery()
{
 document.getElementById('mymedia').style.display = "block";
 $("#video_dialog1").dialog('destroy');
}

// method that returns ajax data through jquery
function callback_video_abuseJquery(data)
{
if(data == 701)
      {
	  //document.getElementById('report_abuse_video').innerHTML = 'Under Review';
	  document.getElementById('report_abuse_video').innerHTML = '<img src="/storage/image/default/icon/ico-under-review.gif" width="25" height="25" border="0" alt="" class="vertical-align"> Under Review';

	  //document.getElementById('video_success_title').innerHTML = '<h2>' + VIDEO_TITLE_ABUSE + '</h2>';
	  success_message = 'This video has been reported as abusive. It is currently under review.'
	  document.getElementById('video_success_message').innerHTML = success_message;
	  document.getElementById('video_dialog1').style.display = 'none';
	  document.getElementById('video_dialog4').style.display = 'block';
	  // YAHOO.example.video_container1.video_dialog4.show();
          $("#video_dialog1").dialog('destroy');
          $("#video_dialog4").dialog('destroy');
          $(function() {
      		$("#video_dialog4").dialog({
		bgiframe: true,
                title:'Report Abuse',
                width:600,
		modal: true,
                draggable: true,
                resizable:false
                });
            
             });  

      }
    else
	{
	    hideVideoPopupJquery();
	}
    
  }

// method to delete video comments through jquery
function deleteVideoCommentsJquery(comment_id)
{
    if(confirm(ERROR_DELETE_VIDEO_COMMENT))
      {
      
	var video_id = document.getElementById('video_post_id').value;
	var video_comment_id = comment_id;
	var postData ='comment_id='+video_comment_id+'&video_post_id='+video_id;
	var url = system_base_url+'ajax/video/_delete_video_comment/' ;
	jQuery.post(url,postData,callback_delete_video_commentJquery);	    
	if(env_value == 'Online')
	    {
		pageTracker._trackPageview(url);
	    }
	

      }

}

// method returns data from server side
function callback_delete_video_commentJquery(data)
{
  if(document.getElementById("video_post_error"))
    {
      document.getElementById("video_post_error").style.display = "none";
    }
  else if(document.getElementById("video_comments_error"))
    {
      document.getElementById("video_comments_error").style.display = "none";
    }
document.getElementById("video_landing_comments").innerHTML = data;
}

