//For top Videos
function topVideosPager(strURL,ch_id) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            UpdateVideoPagerResult(self.xmlHttpReq.responseText,ch_id);
        }
    }
    self.xmlHttpReq.send(strURL);
}

function get_top_video_no(a,url2,chnl,did) {	
	if(a.keyCode==13) {		
		page = document.getElementById(did).value;		
		url2 = url2+'&page2='+page;		
		topVideosPager(url2,chnl);
	}
}

function UpdateVideoPagerResult(str,ch_id){
    document.getElementById("div_"+ch_id).innerHTML = str;
}
//For Channel Video Contest
function showContestForm(arg)
{
	if(is_login == 0) {
		show_login_text('showContestForm|'+arg,'popup');
	}
	else {
		document.getElementById("frmContest").reset();
		document.getElementById("contErr").innerHTML = "";
		document.getElementById("divContest").style.display='block';
		document.getElementById("hdn_CID").value = arg;
		if(document.getElementById("hdn_CID").value == "referral"){
			document.getElementById("contest_captcha").style.display = "none";
			document.getElementById("contest_btns").style.display = "none";
		}
		else {
			document.getElementById("contest_captcha").style.display = "block";
			document.getElementById("contest_btns").style.display = "block";
		}
		$('cont_ajaxLoader').show();
		formObj = document.getElementById('frmContest');
		postUrl = "action_view_video.php";
		$(formObj).request({	
			action:postUrl,
		  method: 'post',
		  parameters: { actionType:'VIEW_CONTEST'}, 
		  onSuccess:handleShowContestResponse, 
		  onException: handleShowContestError
		});
	}
}
function handleShowContestResponse(transport)
{
		data=transport.responseText.evalJSON();
		if(data.MESSAGE == "PAGE_RELOAD")
				location.reload();
		else
		{
				if(data.STATUS=="SUCCESS")
				{
						document.getElementById("contest_Content").innerHTML = data.MESSAGE;
						if(document.getElementById("contest_description").scrollHeight == 440) {
							document.getElementById("contest_description").style.overflow = "hidden";
						}
						document.getElementById("CONTEST_WELCOME").innerHTML = data.UPDATEDATA;
						reloadPicContestCaptcha();
						$('cont_ajaxLoader').hide();
				}
				else
				{
						document.getElementById("contErr").innerHTML = data.MESSAGE;
						reloadPicContestCaptcha();
						$('cont_ajaxLoader').hide();
						closeContestForm()
				}
		}
}

function handleShowContestError(transport)
{
	document.getElementById("contErr").innerHTML = "Error processing: Please try later.";
	reloadPicContestCaptcha();
	$('cont_ajaxLoader').hide();
}
function closeContestForm()
{
	document.getElementById("contErr").innerHTML = "";
	document.getElementById("contest_Content").innerHTML = "";
	document.getElementById("CONTEST_WELCOME").innerHTML = "";
	document.getElementById("hdn_CID").value = "";
	document.getElementById("frmContest").reset();
	document.getElementById("contest_captcha").style.display = "block";
	document.getElementById("contest_btns").style.display = "block";
	thisMovie('contestslider').sendTextToFlash('play');
	reloadPicContestCaptcha();
	document.getElementById("divContest").style.display='';
}
function reloadPicContestCaptcha()
{
	document.getElementById("picContestCaptcha").src="captcha.php?forsec=vvcon&"+Math.random();
}
function postVote(formObj,postUrl)
{
		$('cont_ajaxLoader').show();
		$(formObj).request({	
		action:postUrl,
	  method: 'post',
	  parameters: { actionType:'POST_VOTE'}, 
	  onSuccess:handleVotingResponse, 
	  onException: handleVotingError
	});
}	
function handleVotingResponse(transport)
{
		data=transport.responseText.evalJSON();
		if(data.MESSAGE == "PAGE_RELOAD")
				location.reload();
		else
		{
				if(data.STATUS=="SUCCESS")
				{
						//document.getElementById("divResultset").innerHTML = data.UPDATEDATA;
						document.getElementById("votingStatus").innerHTML = data.MESSAGE;
						reloadPicContestCaptcha();
						$('cont_ajaxLoader').hide();
						closeContestForm();
				}
				else
				{
						document.getElementById("contErr").innerHTML = data.MESSAGE;
						reloadPicContestCaptcha();
						$('cont_ajaxLoader').hide();
				}
		}
}

function handleVotingError(transport)
{
	document.getElementById("contErr").innerHTML = "Error processing: Please try later.";
	reloadPicContestCaptcha();
	$('cont_ajaxLoader').hide();
}


//For related videos in ind picture page
function getVdos(vdotype,vkey,uid)
{
		var pars;
		var myAjax = new Ajax.Request("view_video.php?action=GetVDOS&cat="+vdotype+"&viewkey="+vkey+"&UID="+uid, {method: 'post', parameters: pars,
		onSuccess: populateVdoList
		});	
}

function populateVdoList(transport)
{
	data=transport.responseText;
	document.getElementById("Related_Vdos").innerHTML = data;
}

//show report box
function reportComment(cid,touid)
{
		//document.getElementById("over2").style.height = document.body.scrollHeight + "px";
		//document.getElementById("over2").style.width = document.body.scrollWidth + "px";
		document.getElementById("divErr2").innerHTML = "";
		$('ajaxLoader2').hide();
		
		if(document.getElementById("divComment"))
		{
			document.getElementById("divComment").style.display='none';
		}
		document.getElementById("divReport").style.display='block';
		document.getElementById("frmReport").reset();
		document.getElementById("hdnCID").value=cid;
		document.getElementById("hdnTOUID").value=touid;			
		location.href="#vid_report";
}

// hide report box
function closeDivReport()
{
	document.getElementById('divReport').style.display='none';
}

// show add comment box
function addComment()
{
		//document.getElementById("over").style.height = document.body.scrollHeight + "px";
		//document.getElementById("over").style.width = document.body.scrollWidth + "px";
		document.getElementById("divErr").innerHTML = "";
		//clearRating();
		$('ajaxLoader1').hide();
		
		if(document.getElementById("divReport"))
		{
			document.getElementById("divReport").style.display='none';
		}
		document.getElementById("divComment").style.display='block';
		document.getElementById('hdnRate').value="";
		document.getElementById('comment').value="";
		document.getElementById('videoCommentCapcha').value="";
		//document.getElementById("frmComment").reset();
		location.href="#vid_comment";
}

// hide add comment box
function closeDivComment()
{
	document.getElementById('divComment').style.display='none';
	rate_comment_view(0);
}

function manipulateRating(rate,imgurl)
{
	document.getElementById('hdnRate').value = rate;
	for(i=2; i<=rate; i=i+2)
	{
		document.getElementById("img"+i).src = imgurl+"/tpl_icon_star_full.gif";
	}
	for(i=parseInt(rate)+2; i<=10; i=i+2)
	{
		document.getElementById("img"+i).src = imgurl+"/tpl_icon_star_empty.gif";
	}	
}

function manipulateRating2(rate,imgurl)
{
	document.getElementById('hdnRate').value = rate;
	for(i=2; i<=rate; i=i+2)
	{
		document.getElementById("image"+i).src = imgurl+"/tpl_icon_star_full.gif";
	}
	for(i=parseInt(rate)+2; i<=10; i=i+2)
	{
		document.getElementById("image"+i).src = imgurl+"/tpl_icon_star_empty.gif";
	}	
}

function clearRating()
{
	for(i=2; i<=10; i=i+2)
	{
		document.getElementById("img"+i).src = imgurl+"/tpl_icon_star_empty.gif";
	}	
}

// delete comment
function delVideoComment(cid,vid)
{
		var pars = '';
		path = "action_view_video.php?actionType=DELETE_COMMENT&cid="+cid+"&vid="+vid;
			
		var myAjax = new Ajax.Request(path, {method: 'post', parameters: pars,
		onSuccess: handleDelVideoCommentResponse
		});	
}

function handleDelVideoCommentResponse(transport)
{
		data=transport.responseText.evalJSON();
		if(data.MESSAGE == "PAGE_RELOAD")
				location.reload();
		else
		{
				if(data.STATUS=="SUCCESS")
				{
						document.getElementById("divStatus").innerHTML = data.MESSAGE;
						document.getElementById("divResultset").innerHTML = data.UPDATEDATA;
				}
				else
				{
						document.getElementById("divStatus").innerHTML = "Error in deleting Comment.";
				}
		}
}

// post the comment form
function postComment(formObj,postUrl)
{
		$('ajaxLoader1').show();
		$(formObj).request({	
		action:postUrl,
	  method: 'post',
	  parameters: { actionType:'POST_COMMENT'}, 
	  onSuccess:handleCommentResponse, 
	  onException: handleCommentError
	});
}	
function handleCommentResponse(transport)
{
		data=transport.responseText.evalJSON();
		if(data.MESSAGE == "PAGE_RELOAD")
				location.reload();
		else
		{
				var var1 = data.UPDATEDATA.split("|");
				if(data.STATUS=="SUCCESS")
				{
						document.getElementById("comment_result").innerHTML = var1[1];
						document.getElementById("divResultset").innerHTML = var1[0];
						document.getElementById("divStatus").innerHTML = data.MESSAGE;
						reloadVdoCommentCaptcha();
						rate_comment_view(0);
						closeDivComment();
				}
				else
				{
						document.getElementById("divErr").innerHTML = data.MESSAGE;
						reloadVdoCommentCaptcha();
				}
				$('ajaxLoader1').hide();
		}
}

function handleCommentError(transport)
{
	document.getElementById("divErr").innerHTML = "Error processing: Please try later.";
	reloadVdoCommentCaptcha();
	$('ajaxLoader1').hide();
}

function grpVideopostComment(formObj,postUrl)
{
		$('ajaxLoader1').show();
		$(formObj).request({	
		action:postUrl,
	  method: 'post',
	  parameters: { actionType:'POST_COMMENT_GRP'}, 
	  onSuccess:handlegrpVideoCommentResponse, 
	  onException: handlegrpVideoCommentError
	});
}	
function handlegrpVideoCommentResponse(transport)
{
		data=transport.responseText.evalJSON();
		if(data.MESSAGE == "PAGE_RELOAD")
				location.reload();
		else
		{
				if(data.STATUS=="SUCCESS")
				{
						document.getElementById("divResultset").innerHTML = data.UPDATEDATA;
						document.getElementById("divStatus").innerHTML = data.MESSAGE;
						reloadVdoCommentCaptcha();
						rate_comment_view(0);
						closeDivComment();
				}
				else
				{
						document.getElementById("divErr").innerHTML = data.MESSAGE;
						reloadVdoCommentCaptcha();
				}
				$('ajaxLoader1').hide();
		}
}

function handlegrpVideoCommentError(transport)
{
	document.getElementById("divErr").innerHTML = "Error processing: Please try later.";
	reloadVdoCommentCaptcha();
	$('ajaxLoader1').hide();
}

function reloadVdoCommentCaptcha()
{
	document.getElementById("vdoCommentCaptcha").src="captcha.php?forsec=vvcom&"+Math.random();
}

// post report
function postReport(formObj,postUrl)
{
		$('ajaxLoader2').show();
		$(formObj).request({	
		action:postUrl,
	  method: 'post',
	  parameters: { actionType:'POST_REPORT'}, 
	  onSuccess:handleReportResponse, 
	  onException: handleReportError
	});
}	
function handleReportResponse(transport)
{
		data=transport.responseText.evalJSON();
		if(data.MESSAGE == "PAGE_RELOAD")
				location.reload();
		else
		{
				if(data.STATUS=="SUCCESS")
				{
						document.getElementById("divStatus").innerHTML = data.MESSAGE;
						//alert(data.MESSAGE);
						closeDivReport();
				}
				else
				{
						document.getElementById("divErr2").innerHTML = data.MESSAGE;
				}
				$('ajaxLoader2').hide();
		}
}

function handleReportError(transport)
{
	document.getElementById("divErr2").innerHTML = "Error processing: Please try later.";
	$('ajaxLoader2').hide();
}

function addToFavorite()
{
		formObj = document.getElementById('frmActions');
		postUrl = 'action_view_video.php';
		$('ajxStatus').hide();
		$('ajxLoader').show();
		$(formObj).request({	
		action:postUrl,
	  method: 'post',
	  parameters: { actionType:'ADD_FAVORITE'}, 
	  onSuccess:handleActionResponse, 
	  onException: handleActionError
	});	
}

function handleActionResponse(transport)
{
	data = transport.responseText.evalJSON();
	if(data.MESSAGE == "PAGE_RELOAD") {
		location.reload();
	}
	else {
		if(data.STATUS=="SUCCESS")
		{
				document.getElementById("ajxStatus").innerHTML = "<font style='color:#e26600; font-weight:bold'>"+data.MESSAGE+"</font>";
		}
		else
		{
				document.getElementById("ajxStatus").innerHTML = "<font style='color:#e26600; font-weight:bold'>"+data.MESSAGE+"</font>";
		}
		$('ajxStatus').show();
		$('ajxLoader').hide();
	}
}

function handleActionError(transport)
{
	document.getElementById("ajxStatus").innerHTML = "Error processing: Please try later.";
		$('ajxStatus').show();
		$('ajxLoader').hide();	
}

function inappropriateRequest()
{
		formObj = document.getElementById('frmActions');
		postUrl = 'action_view_video.php';
		$('ajxStatus').hide();
		$('ajxLoader').show();
		$(formObj).request({	
		action:postUrl,
	  method: 'post',
	  parameters: { actionType:'INAPPROPRIATE'}, 
	  onSuccess:handleActionResponse, 
	  onException: handleActionError
	});	
}

function featureRequest()
{
		formObj = document.getElementById('frmActions');
		postUrl = 'action_view_video.php';
		$('ajxStatus').hide();
		$('ajxLoader').show();
		$(formObj).request({	
		action:postUrl,
	  method: 'post',
	  parameters: { actionType:'FEATURE'}, 
	  onSuccess:handleActionResponse, 
	  onException: handleActionError
	});	
}

function call_vdofunction(vkey, uid) {
	if(document.getElementById('related_dd').value == "RVDOS") {
		getVdos('RVDOS',vkey,uid);
	}
	else if(document.getElementById('related_dd').value == "UVDOS") {
		getVdos('UVDOS',vkey,uid);
	}
}

