var timeOutView1;
var timeOutView2;
var timeOutView3;
function validate_video_search()
{
	document.frmsearch.keyword.value = trimAll(document.frmsearch.keyword.value);
	if(document.frmsearch.keyword.value == "")
	{
		alert("Please enter search keyword");
		document.frmsearch.keyword.focus();
		return false;
	}
	/*
	if(document.frmsearch.keyword.value != "")
	{
//		document.frmsearch.cat_id.value = "";
//		document.frmsearch.action = "/z/videos/search-video.php";
	}
	*/
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
		sString = sString.substring(1, sString.length);
	while (sString.substring(sString.length-1, sString.length) == ' ')
		sString = sString.substring(0,sString.length-1);
	return sString;
}
function hideInnerMsg(msgDiv)
{
	if(document.getElementById(msgDiv))
	{
//		document.getElementById(msgDiv).innerHTML = "";
		document.getElementById(msgDiv).style.display = "none";
	}

}
function browse_video(cat_id)
{

	switch(cat_id)
	{
		case -1 :
					keyword = "India";
					break;
		case -2 :
					keyword = "Bollywood India";
					break;
		default :
					keyword = "India";
					break;
	}
	document.frmbrowse.keyword.value = keyword;
	document.frmbrowse.cat_id.value = cat_id;
	document.frmbrowse.action = "/z/videos/search-video.php";
	document.frmbrowse.submit();
}

function video_tag_search(keyword)
{
	document.frmvideo.keyword.value = keyword;
	document.frmvideo.action = "/z/videos/search-video.php";
	document.frmvideo.submit();
}
function getLogin(anchor_link)
{
	window.location.href = '/z/login/login.php?go=' + encodeURIComponent(window.location) + anchor_link;
}
function upload_video(strURL,strParameter,handler,handler_flg)
{
	strParameter = strParameter + "&video_url=" + encodeURIComponent(document.frmupload.video_url.value);
	handler = "handlerdivCheckCanAddVideo('"+ handler + "')";
	xmlhttpPost_makerequest(strURL,strParameter,handler,handler_flg);
}
function report_abuse_video(strURL,strParameter,handler,handler_flg)
{
	xmlhttpPost_makerequest(strURL,strParameter,handler,handler_flg);
}
function showNextPrevVideoPanel(strURL,strParameter,handler,handler_flg)
{
//	document.getElementById(handler+1).style.display = "inline";
	xmlhttpPost_makerequest(strURL,strParameter,handler,handler_flg);
//	document.getElementById(handler+1).style.display = "none";
}
function add_to_my_favorites(strURL,strParameter,handler,handler_flg)
{
//	if(confirm("Are you sure you want to add this video to your favorites? "))
	{
		handler = "handlerdivAddVideoFavorite('"+ handler + "')";
		xmlhttpPost_makerequest(strURL,strParameter,handler,handler_flg);
	}
}
function add_to_my_list(strURL,strParameter,handler,handler_flg)
{
//	if(confirm("Are you sure you want to add this video to your gallery? "))
	{
		handler = "handlerdivAddVideo('"+ handler + "')";
		xmlhttpPost_makerequest(strURL,strParameter,handler,handler_flg);
	}
}
function added_in_list(added_in_list_div_show,added_in_list_div_hide)
{
	document.getElementById(added_in_list_div_show).style.display='inline';
	if(document.getElementById(added_in_list_div_hide))
	document.getElementById(added_in_list_div_hide).style.display='none'; 
	var handlerFun = "hideInnerMsg('"+added_in_list_div_show+"')";
	if(timeOutView3)
		window.clearTimeout(timeOutView3);
	timeOutView3 = window.setTimeout(handlerFun,2000);
}
function handlerdivAddVideoFavorite(handler) 
{
	if(xmlHttpReq.readyState == 4) 
	{
		if(xmlHttpReq.status == 200)
		{
				if(xmlHttpReq.responseText.indexOf("<!--error_login-->") == 0)
				{
					document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
				}
				else if(xmlHttpReq.responseText.indexOf("<!--error-->") == 0)
				{
					document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
				}
				else
				{
					document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
					document.getElementById("add_fav_div").innerHTML = "";
					document.getElementById("in_my_fav_div").style.display = "inline";

					var handlerFun = "hideInnerMsg('"+handler+"')";
					if(timeOutView1)
						window.clearTimeout(timeOutView1);
					timeOutView1 = window.setTimeout(handlerFun,5000);

				}
		}
		else
		{
			alert("Error: While trying to fetch records, please try again later");
		}
	}
	else
	{
		document.getElementById(handler).innerHTML = "<div id=\"\" style=\"height:30px; padding:10 8 10 10px;\" class=\"medium\"><img src=\"/zones-ssi/js-css-images/progress.gif\" border=\"0\" alt=\"Progress...\" align=\"absmiddle\" hspace=\"6\"> Adding to your favorites list.</div>";
	}
}

function handlerdivAddVideo(handler) 
{
	if(xmlHttpReq.readyState == 4) 
	{
		if(xmlHttpReq.status == 200)
		{
				if(xmlHttpReq.responseText.indexOf("<!--error_login-->") == 0)
				{
					document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
				}
				else if(xmlHttpReq.responseText.indexOf("<!--error-->") == 0)
				{
					document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
				}
				else
				{
					document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
					document.getElementById("add_video_div").innerHTML = "";
					document.getElementById("in_my_video_div").style.display = "inline";
					var handlerFun = "hideInnerMsg('"+handler+"')";
					if(timeOutView2)
						window.clearTimeout(timeOutView2);
					timeOutView2 = window.setTimeout(handlerFun,5000);
				}
		}
		else
		{
			alert("Error: While trying to fetch records, please try again later");
		}
	}
	else
	{
		document.getElementById(handler).innerHTML = "<div id=\"\" style=\"height:30px; padding:10 8 10 10px;\" class=\"medium\"><img src=\"/zones-ssi/js-css-images/progress.gif\" border=\"0\" alt=\"Progress...\" align=\"absmiddle\" hspace=\"6\"> Adding to your video gallery.</div>";
	}
}
function delete_video(video_id,video_title,need_confirmation)
{
	if(!need_confirmation || confirm("Are you sure you want to delete this video from your gallery? "))
	{
		var url = "";
		url = "/videos/"+document.frmMyVideo.zonename.value;

		document.frmMyVideo.action_name.value = "delete_my_video";
		document.frmMyVideo.video_id.value = video_id;
		document.frmMyVideo.video_title.value = video_title;
		document.frmMyVideo.action = url;
		document.frmMyVideo.submit();
	}
}
function delete_fav_video(video_id,video_title, need_confirmation)
{
	if(!need_confirmation || confirm("Are you sure you want to remove this video from your favorites list? "))
	{
		var url = "";
		url = "/z/videos/my-favorites-videos.php";
		document.frmMyVideo.action_name.value = "delete_my_fav_video";
		document.frmMyVideo.video_id.value = video_id;
		document.frmMyVideo.video_title.value = video_title;
		document.frmMyVideo.action = url;
		document.frmMyVideo.submit();

	}
}
function handlerdivCheckCanAddVideo(handler) 
{
	if(xmlHttpReq.readyState == 4) 
	{
		if(xmlHttpReq.status == 200)
		{
				if(xmlHttpReq.responseText.indexOf("<!--error_login-->") == 0)
				{
					document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
					window.setTimeout("getLogin('')",2000);
				}
				else if(xmlHttpReq.responseText.indexOf("<!--error-->") == 0)
				{
					document.getElementById(handler).innerHTML = xmlHttpReq.responseText;
				}
				else
				{
					document.frmupload.submit();
				}
		}
		else
		{
			alert("Error: While trying to fetch records, please try again later");
		}
	}
	else
	{
		document.getElementById(handler).innerHTML = "<span id=\"\" style=\"height: 23px; margin: 8 0 2 70px;\" valign=\"middle\" align=\"center\"><img src=\"/zones-ssi/js-css-images/loading.gif\" border=\"0\" alt=\"Loading...\" align=\"absmiddle\"></span>";
	}
}
function frd_keyword_blur(sString)
{
	if(trimAll(sString)=='')
	{
		document.frmTitleSearch.title_keyword.value = 'Enter Video Title';
	}
}

function search_validation()
{
	var title_keyword = document.frmTitleSearch.title_keyword.value;
	if(trimAll(title_keyword) == "Enter Video Title")
	{
		return false;
	}
	if(!(trimAll(title_keyword)))
	{
			document.frmTitleSearch.title_keyword.value = "";
			document.frmTitleSearch.title_keyword.focus();
			return false;
	}
}