	    
	/* Show Jbox popup for video information section as Share,Embed,Flag tab */
    function vdo_video_info_get(type) {     	
		$("#video_info_text"+type).jqm().jqmShow();
	}

	/* Redirect on url */
	function vdo_video_add_redirect(url) {			
		//window.location = url;
		//window.location.href = url;		
	}
		
	/*Prepend HTML for various Jbox popup for video information section as Share,Embed,Flag tab */	
	function vdo_video_jqm_info_get(video_id,type)	{	
		cur_lang_val 			= $("#cur_lang").val();		
		var	label	= '';
		if(type == '2')
		{
			label	= EMBED_LABEL;
		}
		else if(type == '4')
		{
			label	= FLAG_LABEL;
		}
		else if(type == '5')
		{
			label	= VIEWS_LABEL;
		}

		$.get("/"+cur_lang_val+"/videos/ajax_controller.php?f=vdo_video_info_get", { p1:video_id, p2:type } ,	
			function(data){
				//alert(data)
					if(data) {
								//var html	=	'<div class="jqmWindow box" style="left:50%;top:50%;position:absolute;z-index:9999999;width:400px;text-align:center;border:solid 1px #6699CC;background-color:#E7E7E7;" id="video_info_text'+type+'">'+'<div class="boxHeader" style="height:12px;font-size:11px;width:400px;background-color:#6699CC;padding:0px;"><span style="float:left;color:#FFFFFF;">'+label+'</span><span style="float:right"><a href="#" class="jqmClose" style="color:#FFFFFF;"><b>[X]</b></a></span></div>'+data+'</div>'
								var html	=	'<div class="jqmWindow box" style="left:50%;top:30%;z-index:9999999;width:400px;text-align:center;border:solid 1px #6699CC;background-color:#E7E7E7;" id="video_info_text'+type+'">'+'<div class="boxHeader" style="height:12px;font-size:11px;width:400px;background-color:#6699CC;padding:0px;"><span style="float:left;color:#FFFFFF;">'+label+'</span><span style="float:right"><a href="#" class="jqmClose" style="color:#FFFFFF;"><b>[X]</b></a></span></div>'+data+'</div>'
								$(document.body).prepend(html);
				        		$('#video_info_text'+type).jqm({
			                	overlay:10,
			                	modal: true,
			                	onHide: function(hash){
			                        	hash.w.fadeOut('1000',function(){ hash.o.remove(); });
			                	}
			        	});						
					}   
				}
			);		
	}
	
	/* Called on clicking the download button on video show page to download the video*/
    function vdo_download(video_path) {
    	window.location	= video_path;
    }
   
    /* Save video flag by calling ajax controller function named as vdo_video_flag_save*/
	function vdo_video_flag_save(video_id) {
		cur_lang_val 			= $("#cur_lang").val();
		flag_name 	= $("#flagname").find('option').filter(':selected').val();
		flag_text 	= $("#flagtext").val();
		$.get("/"+cur_lang_val+"/videos/ajax_controller.php?f=vdo_video_flag_save", { p1:video_id, p2:flag_name, p3:flag_text } ,	
			function(data){					
				if(data) {
					vdo_video_flag_added_alert();
					$("#flagtext").val("");
					$("#video_info_text"+4).jqm().jqmHide();
				}  				
			}
		);
	}	
	
	/*trim the string*/
	function trimString (str) {
	  str = this != window? this : str;
	  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
	
	/*this function checks rhc details and give alert message if any of tittle or text for freetext rhc is empty or poll id for poll rhc is mising*/
	function vdo_video_rhc_data_check(list_id,title,text){		
		if($("#"+list_id).length > 0) {
			freetextidset_obj_val = $("#"+list_id).val();
			if(freetextidset_obj_val != "") {				
				freetextidset_obj_val = freetextidset_obj_val.substring(1);				
				if(freetextidset_obj_val.length >= 1) {					
					arr = freetextidset_obj_val.split(",");						
					for(i=0;i<arr.length;i++) {
						
						title_name 	= title+arr[i];						
						if($("#"+title_name).length > 0) {
							value = $("#"+title_name).val();							
							if(trimString(value) == ""){
								if(text != "") {
									alert(RHC_TITLE_MSG);	
								}
								else{
									alert(RHC_POLL_MSG);
								}
								
								return false;
							}
						}	
						if(text != "") {
							desc_name 	= text+arr[i];
							if($("#"+desc_name).length > 0){
								value = $("#"+desc_name).val();							
								if(trimString(value) == ""){
									alert(RHC_TEXT_MSG);
									return false;
								}
							}
						}
						
					}
				}				
			}
		}
		return true;
	}
		
	/*validate add/edit video page*/			
	function vdo_video_add_edit_check_data() {		
		formobj 					= document.video_add_edit;		
		video_title 				= formobj.vdotitle;
		video_nicename				= formobj.txtnicename;
		video_dsec					= formobj.txtdesc;
		video_id					= formobj.video_id;
		video_file					= formobj.video_file;
		category_sel				= formobj.hdn_category_sel;		
		video_author_list			= formobj.hdn_author_list;
		isfeatured					= formobj.isfeatured;
		upload_transactionobj 		= formobj.upload_transaction;
		upload_fileobj				= formobj.upload_file;		
				
		//video file validation
		if(video_id){
			video_id_val = video_id.value;			
			if((video_id_val) == "") {
				if(upload_transactionobj && upload_fileobj){
					upload_transactionobj_val 	= upload_transactionobj.value;
					upload_fileobj				= upload_fileobj.value;
					if(upload_transactionobj_val == "" || upload_fileobj.value == ""){
						vdo_video_add_edit_file_alert();
						return false;
					}
				}				
			}			
		}				
		//video file validation			
		//video title validation
		if(video_title){
			video_title_val = video_title.value;
			if(trimString(video_title_val) == ""){				
				vdo_video_add_edit_title_alert();
				return false;
			}
		}
		
		
		// nicename validation
		if(video_nicename) {			
			if(!vdo_video_nicename_validate(video_nicename,1)) {
				return;
			}

			vdo_unique_nicename_chk(0);

			if($('#hdnnicename_flag').val() == "0") {
				alert(VDO_CREATE_ERR_NICENAME);
				video_nicename.focus();
				return false;
			}
		}		
		
		//video description validation		
		if(video_dsec){
			video_dsec_val = tinyMCE.getContent('txtdesc');
			if((video_dsec_val) == ""){				
				vdo_video_add_edit_desc_alert();
				return false;
			}
		}	
		
		//validation for category page
		if(category_sel){
			category_sel_val = category_sel.value;
			if((category_sel_val) == ""){				
				vdo_video_category_alert();
				return false;
			}
		}
		
		//rhc validation starts here
		if(!vdo_video_rhc_data_check("existingfreetextidset","existfreetexttitle","existfreetextdesc")){
			return false;
		}
		
		if(!vdo_video_rhc_data_check("freetextidset","freetexttitle","freetextdesc")){
			return false;
		}
		
		if(!vdo_video_rhc_data_check("existingpollidset","existpollidinput","")){
			return false;
		}
		
		if(!vdo_video_rhc_data_check("pollidset","pollidinput","")){
			return false;
		}
		//rhc validation ends here
				
		//fetured or not validation
		if(isfeatured){			
			if(!(isfeatured[0].checked || isfeatured[1].checked)) {				
				vdo_video_add_edit_featured_alert();
				return false;
			}
		}		
		
		return true;		
	}
	
	/*
		called on video add/edit submit 
		If video add/edit page data is validated successfully then submit the page and disable the submit button
	*/	
	function vdo_video_add_edit_validate_form() {
		formobj 				= document.video_add_edit;
		video_id				= formobj.video_id;		
		publish_button_top 		= formobj.publish_top;
		publish_button_bot 		= formobj.publish_bot;	
		upload_transactionobj 	= formobj.upload_transaction;
		upload_fileobj			= formobj.upload_file;	
		if(vdo_video_add_edit_check_data()) {			
			//code to check and upload file
			check_upload_test 	= 0;
			if(video_id) {				
				video_id_val 	= video_id.value;			
				if((video_id_val) == ""){								
					check_upload_test = 1;					
				}
				else {					
					if(upload_transactionobj && upload_fileobj) {						
						upload_transactionobj_val 	= upload_transactionobj.value;
						upload_fileobj				= upload_fileobj.value;
						if(upload_transactionobj_val!= "" && upload_fileobj.value != ""){
							check_upload_test = 1;
						}
					}
				}				
				if(check_upload_test == 1){						
					if(upload() === true){
						formobj.submit();			
					}
				}
				else{					
					formobj.submit();
				}
			}
			//code to check and upload file ends here
			if(publish_button_top){
				publish_button_top.disabled = 'disabled';
			}
			if(publish_button_bot){
				publish_button_bot.disabled = 'disabled';
			}		
		}
	}

	/*
		Called when video add/edit action is cancelled
		And it redirect to reffer url(i.e. web page from where user come on this page(add/edit))
		for example it may be video listing,show video page etc.
	*/	
	function vdo_video_add_edit_cancel() {
		referurl = $("#cancelurl").val();
		if(referurl != ""){
			window.location = referurl;
		}
	}
	
	/*Show and hide date range div*/
	function show_date_range(onload_check) {
		onload_check = onload_check || ""		
		formobj = document.frmvideos;
		date_type = document.forms.frmvideos['date_type'].options[document.forms.frmvideos['date_type'].selectedIndex].value;
		if(date_type == 4){
			document.getElementById("date_range_set").style.display ="";	
		}
		else{
			if(formobj.startdate){
				formobj.startdate.value = "";	
			}
			if(formobj.enddate){
				formobj.enddate.value = "";	
			}			
			document.getElementById("date_range_set").style.display ="none";
			//to remove filter button click(auto submit)
			if(onload_check == ""){
				pagereload();		
			}			
		}	
	}
	
	/*Reload the page on sort option drop down changes*/
	function pagereload() {
		formobj 	= document.frmvideos;
		start_date 	= formobj.startdate.value;
		end_date 	= formobj.enddate.value;
		submit 		= 0;
		date_type = document.forms.frmvideos['date_type'].options[document.forms.frmvideos['date_type'].selectedIndex].value;
		if(date_type == 4){
			if(start_date == "" || end_date == ""){
					submit =1;					
					vdo_date_range_alert();
					return false;
			}			
		}
		if(submit == 0){
			formobj.method = "post";
			formobj.action = "";
			formobj.submit();	
		}
		
	}	
	
	// check for unique nice name - makes ajax call
	// flag - to diftingush whether to make hidden ajax call (no message display), or display message (on check nicename avaliablity)
	function vdo_unique_nicename_chk(flag) {
		cur_lang_val = $("#cur_lang").val();
		formobj = document.video_add_edit;

		if(flag == 1) { // validating nicename
			if(!vdo_video_nicename_validate(formobj.txtnicename,2)) {
				return;
			}
		}		
		// if changed nicename is diffrent from old one
		if($('#txtnicename').val() != $('#hdnoldnicename').val()) {
			if(flag == 1) {
				$("#loading_nicename").show();
				$("#nicenamemessage").html("");
			}
			$.get("/"+cur_lang_val+"/videos/ajax_controller.php?f=vdo_nicename_check&rnd="+Math.random(), {p1:$('#txtnicename').val()},
			function(data) {				
				if(data.indexOf("#error#") != -1) {
					if(flag == 1) {
						$("#loading_nicename").hide();
						$("#nicenamemessage").html(VDO_CREATE_ERR_NICENAME);
					}
					$('#hdnnicename_flag').val(0)
				}
				else if(data.indexOf("#success#") != -1) {
					if(flag == 1) {
						$("#loading_nicename").hide();
						$("#nicenamemessage").html(VDO_CREATE_SUC_NICENAME);
					}
					$('#hdnnicename_flag').val(1)
				}
			 });
		}
		else {
			if(flag == 1) {
				$("#nicenamemessage").html(VDO_CREATE_SUC_NICENAME);
			}
		}
	}
	
	// validating nicename for special characters
	// obj_nicename		- nicename field name
	// flag				- flag to alert error or not	
	function vdo_video_nicename_validate(obj_nicename,flag) {
		if(obj_nicename.value == "") {

			if(flag == 1) {
				alert(VDO_NICENAME_VAL);
			}
			else if(flag == 2) {
				$("#nicenamemessage").html(VDO_NICENAME_VAL);
			}
			obj_nicename.focus();
			return false;
		}
		else {
			myRegxp = /^[A-Z\a-z\d\-\_]+$/;  // regular expression for alpha numeric
			if(!(myRegxp.test(obj_nicename.value))) {
				if(flag == 1) {
					alert(VDO_NICENAME_VAL_RES1);
				}
				else if(flag == 2) {
					$("#nicenamemessage").html(VDO_NICENAME_VAL_RES1);
				}
				obj_nicename.focus();
				return false;
			}

			myRegxp = /^[\d]+$/;  // regular expression for alpha numeric

			if((myRegxp.test(obj_nicename.value))) {
				if(flag == 1) {
					alert(VDO_NICENAME_VAL_RES2);
				}
				else if(flag == 2) {
					$("#nicenamemessage").html(VDO_NICENAME_VAL_RES2);
				}
				obj_nicename.focus();
				return false;
			}
		}

		return true;
	}	
	
	// to suggest nicename based on video title
	function vdo_generate_nicename() {
		cur_lang_val = $("#cur_lang").val();
		formobj = document.formArticle;

		if($('#video_id').val() == "" && $('#vdotitle').val() != "") {

			// if changed nicename is diffrent from old one
			$("#loading_nicename").show();
			$("#nicenamemessage").html(VDO_SUGGESTING_NN);

			$.get("/"+cur_lang_val+"/videos/ajax_controller.php?f=vdo_video_nicename_suggest&rnd="+Math.random(), {p1:$('#vdotitle').val()},
			function(data) {				
				tmpresults = data.split("#");
				if(tmpresults[0] == "error") {
					$("#nicenamemessage").html(VDO_SUGGETED_NN_NOT_AVAL_MSG);
					$('#hdnnicename_flag').val(0)
				}
				else {
					$("#nicenamemessage").html(VDO_SUGGETED_NN_AVAL_MSG);
					$('#hdnnicename_flag').val(1)
				}

				if(tmpresults[1] == "") {
					$("#nicenamemessage").html(VDO_SUGGETED_NN_NO_SUGESTIONS);
				}

				$('#txtnicename').val(tmpresults[1]);
				$('#hdnoldnicename').val(tmpresults[2]);

				$("#loading_nicename").hide();

			 });
		}
	}
	
	/*load related video HTML obtained from ajax call to ajaxcontroller*/
	function vdo_video_related_get(video_id,video_title,type) {	
		cur_lang_val = $("#cur_lang").val();		
		cur_page_val = parseInt($("#related_page").val());
		cur_page_val =  cur_page_val + parseInt(type);		
		noof_related_video = parseInt($("#no_of_related_video").val());
		if(cur_page_val >= 0 && noof_related_video > 0 && cur_page_val < noof_related_video){			
			$("#related_page").val(cur_page_val);
			$.get("/"+cur_lang_val+"/videos/ajax_controller.php?f=vdo_video_related_get&rnd="+Math.random(), {p1:video_id,p2:video_title,p3:type,p4:cur_page_val,p5:noof_related_video},
			function(data) {				
				if(data != ""){
					$("#relateddvideo").html(data);
				}
				else{
					cur_page_val = parseInt($("#related_page").val());
					cur_page_val-= parseInt(type);
					$("#related_page").val(cur_page_val);
					//$("#relateddvideo").html("<b>No Records</b>");
					$("#showhiderelatedvideos").hide();
				}
			 }
		 );
		}		
		
		$("#previousrelated").show();
		$("#nextrelated").show();
		if(cur_page_val == 0){
			$("#previousrelated").hide();
		}
		if(cur_page_val == (noof_related_video-1)){
			$("#nextrelated").hide();
		}
	}
	
	/*load same series video HTML obtained from ajax call to ajaxcontroller*/
	function vdo_video_same_series_get(video_id,type) {
		cur_lang_val = $("#cur_lang").val();
		cur_page_val 			= parseInt($("#sameseries_page").val());
		cur_page_val 			=  cur_page_val + parseInt(type);		
		noof_sameseries_video 	= parseInt($("#no_of_same_series_video").val());		
		
		if(cur_page_val >= 0 && noof_sameseries_video > 0 && cur_page_val < noof_sameseries_video){
			$("#sameseries_page").val(cur_page_val);
			$.get("/"+cur_lang_val+"/videos/ajax_controller.php?f=vdo_video_same_series_get&rnd="+Math.random(), {p1:video_id,p2:type,p3:cur_page_val,p4:noof_sameseries_video},
				function(data) {
					
					if(data != ""){
						$("#sameseriesdvideo").html(data);
					}
					else{
						cur_page_val = parseInt($("#related_page").val());
						cur_page_val-= parseInt(type);
						$("#sameseries_page").val(cur_page_val);
						//$("#sameseriesdvideo").html("<b>No Records</b>");
						$("#showhideothervideo").hide();
						
					}
				}
		 	);		 
		}
		$("#previousother").show();
		$("#nextother").show();
		if(cur_page_val == 0){
			$("#previousother").hide();
		}
		if(cur_page_val == (noof_sameseries_video-1)){
			$("#nextother").hide();
		}
	}	
	
	
	function vdo_show_views_jqm(video_id)
	{		
		cur_lang_val 			= $("#cur_lang").val();		
		$("#video_show_top").jqm().jqmShow();
		$.get("/"+cur_lang_val+"/videos/ajax_controller.php?f=vdo_video_info_get", { p1:video_id, p2:5 } ,	
			function(data){
				$('#video_views').html(data);
			}
		);		
	}

	
	function vdo_show_view_prepare()
	{        
		label	= "Views";		

		$(document.body).prepend('<div class="jqmWindow box" style="left:50%;top:30%;z-index:9999999;width:'
		+'400px;text-align:center;border:solid 1px #6699CC;background-color:#E7E7E7;" id="video_show_top">'
		+'<div class="boxHeader" style="height:12px;font-size:11px;width:400px;background-color:#6699CC;padding:0px;">'
		+'<span style="float:left;color:#FFFFFF;">'
		+label+'</span><span style="float:right">'
		+'<a href="#" class="jqmClose" style="color:#FFFFFF;">'
		+'<b>[X]</b></a></span></div>'+'<div align="center" class="boxBody">'+'<div id="video_views"><img src="/media/images/progressbar.gif"></div><br>'+'<br>'+ '</div>'+'</div>');
        $('#video_show_top').jqm({
                overlay:10,
                modal: true,
                onHide: function(hash){
                		$('#video_views').html('<img src="/media/images/progressbar.gif">');
                        hash.w.fadeOut('1000',function(){ hash.o.remove(); });
                }
        });
	}

	/*load same category video HTML obtained from ajax call to ajaxcontroller*/
	function vdo_video_samecat_get(video_id,type) {
		
		cur_video_cat_all_val 	= $("#cur_video_cat_all").val();
		cur_lang_val 			= $("#cur_lang").val();	
		cur_page_val 			= parseInt($("#same_cat_page").val());
		cur_page_val 			=  cur_page_val + parseInt(type);		
		noof_samecat_video 		= parseInt($("#no_of_same_cat_video").val());
		if(cur_page_val >= 0 && noof_samecat_video > 0 && cur_page_val < noof_samecat_video){			
			$("#same_cat_page").val(cur_page_val);
			$.get("/"+cur_lang_val+"/videos/ajax_controller.php?f=vdo_video_samecat_get&rnd="+Math.random(), {p1:video_id,p2:type,p3:cur_page_val,p4:noof_samecat_video,p5:cur_video_cat_all_val},
			function(data) {
				//alert(data)
				if(data != ""){
					$("#samecatvideo").html(data);
				}
				else{
					cur_page_val = parseInt($("#same_cat_page").val());
					cur_page_val-= parseInt(type);
					$("#same_cat_page").val(cur_page_val);					
					$("#showhidesamecatvideos").hide();
				}
			 }
		 );
		}		
		
		$("#previoussameseries").show();
		$("#nextsameseries").show();
		if(cur_page_val == 0){
			$("#previoussameseries").hide();
		}
		if(cur_page_val == (noof_samecat_video-1)){
			$("#nextsameseries").hide();
		}
	}
	
	/*Update video views on clicking player play button */
	function vdo_video_update_views_on_play() {
		var cur_lang_val 	= $("#cur_lang").val();	
		var video_id		= $("#video_id").val();
		//alert("video is : "+video_id+" and language is : "+cur_lang_val);
		$.get("/"+cur_lang_val+"/videos/ajax_controller.php?f=vdo_video_update_views_on_play&rnd="+Math.random(), { p1:video_id } ,	
			function(data){					
				if(data) {
				}  				
			}
		);
	}
