///to show login box
function commentTrv(event)
{
	var xcoord = mouseX(event);
	var ycoord = mouseY(event);
	
	$('login_box').style.top = ycoord+'px';
	$('login_box').style.left = 650 +'px'; 
	show_login_box_trv_cmnt();
	document.getElementById('page_name').value = 'view_training_video';
	document.getElementById('action').value = 'comment_icture';
	document.getElementById('login_id').focus();
	location.href="#short_login";
}
function show_login_box_trv_cmnt()
{
	document.getElementById('login_box').style.display='block';
	document.getElementById('login_ajxLoader').style.display='none';
	document.getElementById('login_divErr').innerHTML='';
	document.getElementById('login_id').value='';
	document.getElementById('login_pwd').value='';		
	//document.getElementById('login_id').focus();
}

function reloadCaptcha_trVdo()
{
	document.getElementById("imgCaptcha_trVdo_comment").src="captcha.php?forsec=vtrvcom&"+Math.random();
}
//added for my_purchases page
function showTrVdoDownload(a)
{
		
		//document.getElementById("over3").style.height = document.body.scrollHeight + "px";
		//document.getElementById("over3").style.width = document.body.scrollWidth + "px";
		document.getElementById("divDwnldError").innerHTML = "";		
		document.getElementById("divDownload").style.display='block';
		document.getElementById("hdnVID").value=a;
		document.getElementById("hdntext3").focus();				
			
}
//show download box
function showDownload()
{
		if(document.getElementById("divComment"))
		{
			document.getElementById("divComment").style.display='none';
		}
		if(document.getElementById("divReport"))
		{
			document.getElementById("divReport").style.display='none';
		}
		//document.getElementById("over3").style.height = document.body.scrollHeight + "px";
		//document.getElementById("over3").style.width = document.body.scrollWidth + "px";
		document.getElementById("divDwnldError").innerHTML = "";		
		document.getElementById("divDownload").style.display='block';
		location.href="#trv_dwnld";				
			
}
//show download box
function showDownload_trvdo(a)
{
		//document.getElementById("over3").style.height = document.body.scrollHeight + "px";
		//document.getElementById("over3").style.width = document.body.scrollWidth + "px";
		document.getElementById("divDwnldError").innerHTML = "";		
		document.getElementById("divDownload").style.display='block';
		document.getElementById("hdnVID").value=a;
		location.href="#trv_dwnld";				
			
}

//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("hdnCID").value = cid;
		document.getElementById("hdnTOUID").value = touid;	
		document.getElementById("comment").value = "";			
		location.href="#trv_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('trvdoCommentCapcha').value="";
		//document.getElementById("frmComment").reset();
		location.href="#trv_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_comment(id)
{
	document.getElementById(id).src = imgurl+"/tpl_icon_star_empty.gif";
}
function clearRateType_comment()
{
	document.getElementById('voteProcessthank_comment').innerHTML='';
}
function setRateType_comment(rate_type)
{
	document.getElementById('voteProcessthank_comment').innerHTML=rate_type;
}
function clearRating()
{
	for(i=2; i<=10; i=i+2)
	{
		document.getElementById("img"+i).src = imgurl+"/tpl_icon_star_empty.gif";
	}	
}

// delete comment
function delTrvComment(cid,vid)
{
		var pars = '';
		path = "action_view_training_video.php?actionType=DELETE_COMMENT&cid="+cid+"&vid="+vid;
			
		var myAjax = new Ajax.Request(path, {method: 'post', parameters: pars,
		onSuccess: handleDelTrvCommentResponse
		});	
}

function handleDelTrvCommentResponse(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;
						reloadCaptcha_trVdo();
						rate_comment_view(0);
						closeDivComment();
						//window.location.reload();
				}
				else
				{
						document.getElementById("divErr").innerHTML = data.MESSAGE;
						reloadCaptcha_trVdo();
				}
				$('ajaxLoader1').hide();
		}
}
function handleCommentError(transport)
{
	document.getElementById("divErr").innerHTML = "Error processing: Please try later.";
	reloadCaptcha_trVdo();
	$('ajaxLoader1').hide();
}

// 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_training_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 = data.MESSAGE;
				}
				$('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_training_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_training_video.php';
		$('ajxStatus').hide();
		$('ajxLoader').show();
		$(formObj).request({	
		action:postUrl,
	  method: 'post',
	  parameters: { actionType:'FEATURE'}, 
	  onSuccess:handleActionResponse, 
	  onException: handleActionError
	});	
}

// !!!!!!!!! Download video functions

// hide download box
function closeDownload()
{
	document.getElementById('frmDwnld').reset();
	document.getElementById('divDownload').style.display='none';
	
}
//added for my_purchases page
function download_Video(formObj,postUrl,a,b)
{
		document.getElementById('file_type').value=b;
		$(formObj).request({
		action:postUrl,
	  method: 'post',
	  parameters: { actionType:'DOWNLOAD',file_type:a}, 
	  onSuccess:handleDownloadResponse, 
	  onException: handleDownloadError
	  
	});
}	
// post download request - common function used for download of tr video
function downloadVideo(formObj,postUrl)
{
		$('ajaxDownldLoader').show();
		$(formObj).request({	
		action:postUrl,
	  method: 'post',
	  parameters: { actionType:'DOWNLOAD'}, 
	  onSuccess:handleDownloadResponse, 
	  onException: handleDownloadError
	  
	});
}	
function handleDownloadResponse(transport)
{
		$('ajaxDownldLoader').hide();
		data=transport.responseText.evalJSON();
		if(data.MESSAGE == "PAGE_RELOAD")
				location.reload();
		else
		{
				if(data.STATUS=="SUCCESS")
				{
						closeDownload();
						//header('Content-Disposition: attachment;');
						document.getElementById("frmVideoDwnld").action = data.MESSAGE;
						document.getElementById("frmVideoDwnld").submit();
				}
				else
				{
						document.getElementById("divDwnldError").innerHTML = data.MESSAGE;
				}
		}
}

function handleDownloadError(transport)
{
	$('ajaxDownldLoader').hide();
	document.getElementById("divDwnldError").innerHTML = "Error processing: Please try later.";
	//document.getElementById("divDwnldError").innerHTML = transport.responseText;
}

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);
	}
}

//For related videos in ind training video page
function getVdos(vdotype,vkey,uid)
{
		var pars;
		var myAjax = new Ajax.Request("view_training_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;
}