	var block=0;

// !!!!!!! RATING PROCESS

function fxRate(vkey, rate, idToHide, idToShow, vid) {
	cp.call(baseurl + 'ajax/myajaxphp.php', 'process_data', return_data, rate,
			vid);
	hideMe(idToHide);
	showMe(idToShow);
}

function return_data(restul) {

	// Collect the number of BLUE star
	var cnt = restul.getElementsByTagName('trate').item(0).firstChild.data;
	hideMe('idViewVoteResult');
	if (cnt != 'exist') {
		// # Show the vote
		var x = document.getElementById('idVoteView');
		x.innerHTML = restul.getElementsByTagName('tvote').item(0).firstChild.data;

		if (cnt > 6) {
			cnt = 6;
		} else if (cnt < 0) {
			cnt = 0;
		}

		blank_star = 6 - cnt;

		var x = document.getElementById('tblViewResult').rows[0].cells;

		for (i = 0; i < cnt; i++) {
			x[i].innerHTML = '<img src=' + imgurl + '/tpl_icon_star_full.gif>';
		}

		for (j = cnt; j < 5; j++) {
			x[j].innerHTML = '<img src=' + imgurl + '/tpl_icon_star_empty.gif>';
		}
	} else {
		var x = document.getElementById('voteProcessthank').innerHTML = "<FONT COLOR=#FF0000 >Вы уже голосовали</FONT>";
	}

	return false;
}
// RATING PROCESS END

// VIEW VOTE
function viewVote(pollId) {
	cp.call(baseurl + '/ajax/myajaxphp.php', 'view_vote', return_view_vote,
			pollId);
}
function return_view_vote(result) {
	var xx;
	if (1) {
		count = result.getElementsByTagName('count').item(0).firstChild.data;
		for (var ii = 0; ii < count; ii++) {

			var vv = 'A1' + ii;
			var pp = 'P1' + ii;

			vv = result.getElementsByTagName(vv).item(0).firstChild.data;
			pp = result.getElementsByTagName(pp).item(0).firstChild.data;

			// # Generate Voring table
			var tt = document.getElementById('tblViewVoteResult').insertRow(0);
			var y = tt.insertCell(0);
			var z = tt.insertCell(1);
			y.innerHTML = vv;
			z.innerHTML = pp + '%';

			if (vv == "") {
				break;
			}
		}
		insertInToTable('tblViewVote', 0, 0, 'Current vote status');
	}

}

// !!!!!!!! SEND COMMENT PROCESS

function fxSendComments(idToHide, commentId, uid, vid) {
	comment_value = document.getElementById(commentId).value;
	if (comment_value == '') {
		alert(' Comment box is empty !!');
	} else {
		hideMe(idToHide);
		cp.call(baseurl + '/ajax/myajaxphp.php', 'process_comments',
				return_comment_response, comment_value, uid, vid);
	}

}

function return_comment_response(restul) {

	msg_number = restul.getElementsByTagName('a').item(0).firstChild.data;
	if (msg_number == 0) {
		showMe('divComResult2');
	} else if (msg_number == 1) {
		showMe('divComResult1');
	} else {
		showMe('divComResult3');
	}
}
// END

// RECENT VIEW PROCESS
var current_position = 4;
function recentview(amount, flag) {

	gflag = "viewrecent";
	if (flag == 'next') {
		var start = current_position
		current_position = current_position + amount;
		var end = current_position;
		if (dbreport != '1') {

		}

		sql = "SELECT VID, title, viewtime, vkey from watch_video where viewtime<>'0000-00-00 00:00:00' order by viewtime desc limit "
				+ start + " , " + end;
		executeDB(sql);
		// alert(sql);
		if (dbreport < 0) {
			end = current_position;
			current_position = current_position - amount;
			start = current_position;
			alert("End");

		}
	}

	if (flag == 'prev') {
		var end = current_position;
		current_position = current_position - amount;
		var start = current_position;

		if (start < 0) {
			start = amount;
			end = start + amount;
			alert("End");
		}

		sql = "SELECT VID, title, viewtime, vkey from watch_video where viewtime<>'0000-00-00 00:00:00' order by viewtime desc limit "
				+ start + " , " + end;
		executeDB(sql);
	}
}
// END

function pollAnsBox(myID) {
	Me = document.getElementById(myID);
	if (Me.value == "") {
		Me.style.background = "#3366FF";

	} else {

		Me.style.background = "#FFFFFF";
		xy = Me.value;
		for (i = 0; i < Me.value; i++) {
			var x = document.getElementById('tblViweAnsBox').insertRow(0);
			var y = x.insertCell(0);
			var z = x.insertCell(1);
			y.innerHTML = 'Answer ' + (xy - i);
			z.innerHTML = '<INPUT TYPE=text SIZE=40 NAME=voteAnsBox' + i
					+ ' ID=voteAnsBox' + i
					+ ' onBlur=txtBoxValidation(voteAnsBox' + i
					+ ', #EAEAEA,#FF0033) >';
		}
	}

}

// ## Delete row of a Tabile
function delteRow() {
	var x = document.getElementById('tblViweAnsBox').rows.length - 1;

	for (var i = x; i >= 0; i--) {
		document.getElementById('tblViweAnsBox').deleteRow(i);
	}
}

function fxvalidation() {
	var flag = true;
	var x = document.getElementById('tblViweAnsBox').rows.length - 1;

	// ## Question text
	flag = txtBoxValidation('txtQtn', '#EAEAEA', '#FF0033');

	// ## Questin qty
	flag = txtBoxValidation('txtPollAnsQty', '#EAEAEA', '#FF0033');

	for (i = x; i >= 0; i--) {
		targetID = 'voteAnsBox' + i;
		if (document.getElementById(targetID).value == "") {
			txtBoxValidation(targetID, '#EAEAEA', '#FF0033');
			flag = false;
			break;
		}

	}

	return flag;
}

function fxShowAccInfo(a, b) {
	showMe(a);
	hideMe(b);
}

function fxReportVideo(hidediv, uid, vid) {
	if (uid == '0') {
		hideMe(hidediv);
		showMe('reportVideoLogin');
	} else {
		showMe('reportVideoBox');

	}
}

function fxFeatureVideo(uid, vid) {
	if (uid == '0') {
		hideMe('featureVideoSuccess');
		hideMe('featureVideoFailed');
		showMe('featureVideoLogin');
	} else {
		cp.call(baseurl + '/ajax/myajaxphp.php', 'featureVideo',
				featureVideoResponse, uid, vid);
	}
}

function featureVideoResponse(feature_result) {
	var feature_response_id = feature_result
			.getElementsByTagName('featureVideoMessage').item(0).firstChild.data;
	if (feature_response_id == '0') {
		hideMe('featureVideoFailed');
		hideMe('featureVideoLogin');
		showMe('featureVideoSuccess');
	} else {
		hideMe('featureVideoSuccess');
		hideMe('featureVideoLogin');
		showMe('featureVideoFailed');
	}
}

function fxReportVideo(uid, vid) {
	if (uid == '0') {
		hideMe('reportVideoSuccess');
		hideMe('reportVideoFailed');
		showMe('reportVideoLogin');
	} else {
		cp.call(baseurl + '/ajax/myajaxphp.php', 'reportVideo',
				reportVideoResponse, uid, vid);
	}
}

function reportVideoResponse(report_result) {
	var report_response_id = report_result
			.getElementsByTagName('reportVideoMessage').item(0).firstChild.data;
	if (report_response_id == '0') {
		hideMe('reportVideoFailed');
		hideMe('reportVideoLogin');
		showMe('reportVideoSuccess');
	} else {
		hideMe('reportVideoSuccess');
		hideMe('reportVideoLogin');
		showMe('reportVideoFailed');
	}
}

function fxAddFavorite(hidediv, uid, vid, vuid) {
	hideMe(hidediv);
	if (uid == '0') {
		hideMe('addToFavLink');
		hideMe('addToFavSuccess');
		hideMe('addToFavFailed');
		hideMe('addToFavAlready');
		hideMe('addToFavOwner');
		showMe('addToFavLogin');
	} else {
		cp.call(baseurl + '/ajax/myajaxphp.php', 'addToFavorites',
				addToFavoritesResponse, uid, vid, vuid);
	}
}

function addToFavoritesResponse(fav_result) {
	var fav_response_id = fav_result.getElementsByTagName('addFavMessage')
			.item(0).firstChild.data;
	if (fav_response_id == '2') {
		hideMe('addToFavLink');
		hideMe('addToFavSuccess');
		hideMe('addToFavFailed');
		hideMe('addToFavLogin');
		hideMe('addToFavOwner');
		showMe('addToFavAlready');
	} else if (fav_response_id == '0') {
		hideMe('addToFavLink');
		hideMe('addToFavFailed');
		hideMe('addToFavAlready');
		hideMe('addToFavLogin');
		hideMe('addToFavOwner');
		showMe('addToFavSuccess');
	} else {
		hideMe('addToFavLink');
		hideMe('addToFavSuccess');
		hideMe('addToFavAlready');
		hideMe('addToFavLogin');
		hideMe('addToFavOwner');
		showMe('addToFavFailed');
	}
}

function pollAnsBox($num) {
	alert($num);
}

function showRelatedVideos() {
	var tabRelatedVideos = document.getElementById('tabRelatedVideos');
	var tabUservideos = document.getElementById('tabUserVideos');
	tabUservideos.className = "";
	tabRelatedVideos.className = "tabactive";
	hideMe('userVideos');
	showMe('relatedVideos');
}

function showUserVideos() {
	var tabRelatedVideos = document.getElementById('tabRelatedVideos');
	var tabUservideos = document.getElementById('tabUserVideos');
	tabRelatedVideos.className = "";
	tabUservideos.className = "tabactive";
	hideMe('relatedVideos');
	showMe('userVideos');
}
function rate(id) {
	var i = 10;
	while (i > 0) {
		if (id >= i) {
			document.getElementById("rate_" + i).className = "yes_rate";
		} else {
			document.getElementById("rate_" + i).className = "no_rate";
		}
		i = i - 2;
	}
}

function rate_out() {

	id = ratevalue;
	var i = 10;
	while (i > 0) {
		if (id >= (i - 0.5)) {
			document.getElementById("rate_" + i).className = "still_rate";
		} else if (id >= (i - 1.5)) {
			document.getElementById("rate_" + i).className = "still_rate_h";
		} else {
			document.getElementById("rate_" + i).className = "no_rate";
		}
		i = i - 2;
	}
}
function UserMenu(id) {

	var menu = new Array();

	menu[0] = '<a href="http://www.tnu.in.ua/forum/member.php?u=' + id
			+ '">Профиль на форуме</a>';
	menu[1] = '<a href="http://www.tnu.in.ua/forum/private.php?do=newpm&amp;u='
			+ id + '">Отправить сообщение</a>';
	menu[2] = '<a href="http://www.tnu.in.ua/watch/users/' + id
			+ '/videos">Видео пользователя</a>';
	menu[3] = '<a href="http://www.tnu.in.ua/watch/users/' + id
			+ '/favorites">Избранное пользователя</a>';
	menu[4] = '<a href="http://www.tnu.in.ua/watch/users/' + id
			+ '/with">Отметили на видео</a>';

	return menu;
};

function clean_search() {
	document.getElementById('search_input').value = '';
}

function put_search() {
	if (document.getElementById('search_input').value == '') {
		document.getElementById('search_input').value = 'Поиск видео';
	}
}

function del_video() {
	var answer = confirm("Вы уверены, что хотите удалить видео?")
	if (answer) {
		document.removeVideoForm.submit();
	}
}
function edit_video() {
	document.editVideoForm.submit();
}
function AddNote() {
block=0;
	var friendlisting = "";
	var friendsArray = [];
	document.getElementById('search_user').value="";
	document.getElementById("load_put").style.display = "block";
	document.getElementById('show_userlist').style.display = 'block';
	document.getElementById("all_title").style.display = "none";
	document.getElementById("friend_title").style.display = "block";
	var ajax = new dle_ajax();
	ajax.requestFile = 'http://www.tnu.in.ua/engine/ajax/global_ajax.php?do=get_friends';
	ajax.onCompletion = function() {
		eval(ajax.response);
		for (i = 0; i < friendsArray.length; i++) {
			var yes = '';
			for (ii = 0; ii < puArray.length; ii++) {
				if (puArray[ii] == friendsArray[i]['id']) {
					yes = 'style="display:none;"';
				}
			}

			friendlisting += '<div ' + yes + ' id="users_'
					+ friendsArray[i]['id'] + '">';
			friendlisting += '<input onclick="addfriend('
					+ friendsArray[i]['id']
					+ ');"  type="checkbox"><label id="user_pit_i_'
					+ friendsArray[i]['id'] + '">' + friendsArray[i]['name']
					+ '</label>';
			if (friendsArray[i]['name'] == 'Я') {
				friendlisting += '<hr/>';
			}
			friendlisting += '</div>';
			if (friendsArray.length==0) {
			userlisting="Нет друзей";
		}
		}
		document.getElementById("load_put").style.display = "none";
		document.getElementById("newedit").innerHTML = friendlisting;
	};
	ajax.sendAJAX();
}
function CloseNote() {
	document.getElementById('show_userlist').style.display = 'none';
	document.getElementById("newedit").innerHTML = '';
}

function addfriend(id) {
block=0;
	var ajax = new dle_ajax();
	document.getElementById("load_put").style.display = "block";
	ajax.requestFile = 'http://www.tnu.in.ua/engine/ajax/global_ajax.php?do=put_users&id='
			+ id
			+ '&vid='
			+ document.getElementById("VID_for_put").value
			+ '&username='
			+ document.getElementById('user_pit_i_' + id).innerHTML;
	ajax.onCompletion = function() {
		eval(ajax.response);
		document.getElementById("load_put").style.display = "none";
	};
	ajax.sendAJAX();
}

function del_from_put(id) {
	var ajax = new dle_ajax();
	document.getElementById("load_put").style.display = "block";
	ajax.requestFile = 'http://www.tnu.in.ua/engine/ajax/global_ajax.php?do=del_users&id='
			+ id + '&vid=' + document.getElementById("VID_for_put").value;
	ajax.onCompletion = function() {
		eval(ajax.response);
		document.getElementById("load_put").style.display = "none";
	};
	ajax.sendAJAX();
}

function my_new_true(id) {
block=0;
	var ajax = new dle_ajax();
	document.getElementById("panel_" + id).innerHTML = '<div class="loading"><img border="0" src="http://www.tnu.in.ua/watch/images/loader.gif"/></div>';
	ajax.requestFile = 'http://www.tnu.in.ua/engine/ajax/global_ajax.php?do=my_new_true&id='
			+ id;
	ajax.onCompletion = function() {
		eval(ajax.response);
	};
	ajax.sendAJAX();
}
function my_new_delete(id) {
	var answer = confirm("Вы уверены, что хотите удалить?")
	if (answer) {
		var ajax = new dle_ajax();
		document.getElementById("panel_" + id).innerHTML = '<div class="loading"><img border="0" src="http://www.tnu.in.ua/watch/images/loader.gif"/></div>';
		ajax.requestFile = 'http://www.tnu.in.ua/engine/ajax/global_ajax.php?do=my_new_delete&id='
				+ id;
		ajax.onCompletion = function() {
			eval(ajax.response);
		};
		ajax.sendAJAX();
	}
}

function get_user() {
	var user = document.getElementById('search_user').value;
	var len = user.length;
	var userArray=[];
	var yes="";
	var userlisting="";
	document.getElementById("newedit").innerHTML = '';
	if (len >= 2) {
		if (block==0) {
	document.getElementById("load_put").style.display = "block";
		document.getElementById("friend_title").style.display = "none";
		document.getElementById("all_title").style.display = "block";
		block=1;
		document.getElementById("search_user").style.display = "none";
		var ajax = new dle_ajax();
		ajax.requestFile = 'http://www.tnu.in.ua/engine/ajax/global_ajax.php?do=get_user&username=' + user;
		ajax.onCompletion = function() {
			eval(ajax.response);
			for (i = 0; i < userArray.length; i++) {
				var yes = '';
			for (ii = 0; ii < puArray.length; ii++) {
				if (puArray[ii] == userArray[i]['id']) {
					yes = 'style="display:none;"';
				}
			}
			
			userlisting += '<div '+yes +' id="users_'
					+ userArray[i]['id'] + '">';
			userlisting += '<input onclick="addfriend('
					+ userArray[i]['id']
					+ ');"  type="checkbox"><label id="user_pit_i_'
					+ userArray[i]['id'] + '">' + userArray[i]['name']
					+ '</label>';
			userlisting += '</div>';
			block=0;
			document.getElementById("search_user").style.display = "inline";
		}
		
		if (userArray.length==0) {
			userlisting="Нет пользователей";
			block=0;
			document.getElementById("search_user").style.display = "inline";
		}
		document.getElementById("newedit").innerHTML = userlisting;
		document.getElementById("load_put").style.display = "none";
		};
		ajax.sendAJAX();
	}
}
}
