function delete_user_pub( id, id2 ){
	if( confirm('Vreti sa stergeti aceasta legatura dintre user si publisher ?')){
		document.location = 'users_publishers.php?action=del&user_pub_id='+id+'&publisher_id='+id2;
	}
}

function delete_user( id ){
	if( confirm('Sunteti sigur ca vreti sa stergeti acest user ?') ){
		document.location = 'users.php?action=del&user_id='+id;
	}
}

function delete_publisher( id ){
	if( confirm('Sunteti sigur ca vreti sa stergeti acest publisher ?') ){
		document.location = 'publishers.php?action=del&publisher_id='+id;
	}
}

function delete_user_publisher( id1, id2 ){
	if( confirm('Sunteti sigur ca vreti sa stergeti acest user ?') ){
		document.location = '?action=user&publisher_id='+id1+'&user_pub_id='+id2;
	}
}

function markErrorField(fieldId){
	
	var inputObj = document.getElementById(fieldId);
	inputObj.style.borderColor = "#B30000";
	inputObj.style.backgroundColor = "#FFBFBF";

}

function markNormalField(fieldId){
	
	var inputObj = document.getElementById(fieldId);
	inputObj.style.borderColor = "#999999";
	inputObj.style.backgroundColor = "#FFFFFF";

}

function add_video() {
	var form = document.addVideoForm;
	
	var valid = true;
	
	if(isNaN(parseInt(form.publisher.value))){
		valid = false;
		markErrorField('publisher');
	}
	else {
		markNormalField('publisher');
	}
	
	if(form.title.value == '') {
		valid = false;
		markErrorField('title');
	}
	else {
		markNormalField('title');
	}
	
	/*if(form.description.value == ''){
		valid = false;
		markErrorField('description');
	}
	else {
		markNormalField('description');
	}
	
	if(form.tags.value == ''){
		valid = false;
		markErrorField('tags');
	}
	else {
		markNormalField('tags');
	}*/
	
	/*if(isNaN(parseInt(form.width.value))){
		valid = false;
		markErrorField('width');
	}
	else {
		markNormalField('width');
	}
	
	if(isNaN(parseInt(form.height.value))){
		valid = false;
		markErrorField('height');
	}
	else {
		markNormalField('height');
	}*/
	
	if(valid == false)
		alert('Completati campurile obligatorii');
		
	return valid;
}

function edit_video() {
	var form = document.editVideoForm;
		
	var valid = true;
	
	/*if(isNaN(parseInt(form.publisher.value))){
		valid = false;
		markErrorField('publisher');
	}
	else {
		markNormalField('publisher');
	}*/
	
	if(form.title.value == '') {
		valid = false;
		markErrorField('title');
	}
	else {
		markNormalField('title');
	}
	
	/*if(form.description.value == ''){
		valid = false;
		markErrorField('description');
	}
	else {
		markNormalField('description');
	}
	
	if(form.tags.value == ''){
		valid = false;
		markErrorField('tags');
	}
	else {
		markNormalField('tags');
	}*/
	
	if(valid == false)
		alert('Completati campurile obligatorii');
		
	return valid;
}

function regenerate() {
	var form = document.editVideoForm;
	if(confirm('Doriti sa regenerati thumnail?')) {
		form.regenerateThumb.value = 'confirmed';
		form.submit();
	}
	return false;
}

function valid_user_add(){
	
	var username = document.getElementById('username').value;
	
	if( username == '' ){
		alert('Va rugam sa introduceti un username valid');
		return false;
	}
	
	return true;
}

function valid_publisher_add(){
	
	var name = document.getElementById('name').value;
	
	if( name == '' ){
		alert('Va rugam sa introduceti un nume valid pentru publisher');
		return false;
	}
	
	return true;
}

function go_to( location ){
	document.location = location;
}

function sta(i){
	var l = document.getElementById('text_fil').value;
	document.location = 'video_statistics.php?id='+i+"&data1="+document.getElementById('startOn').value+
						"&data2="+document.getElementById('stopOff').value+(l.length>0?'&text='+l:'');
}

function chart(i,vid){
	document.location = 'video_charts.php?id='+i+"&data1="+document.getElementById('startOn').value+
						"&data2="+document.getElementById('stopOff').value+'&video_id='+vid;
}

function removeOptions(selectbox,limit)
{
	var i;
	for(i=selectbox.options.length-1;i>=limit;i--)	{
		selectbox.remove(i);
	}
}


//scroller
scrollStep=120

timerLeft=""
timerRight=""

function toLeft(id){
  document.getElementById(id).scrollLeft=0
}

function scrollDivLeft(id){
  clearTimeout(timerRight)
  document.getElementById(id).scrollLeft+=scrollStep
  timerRight=setTimeout("scrollDivLeft('"+id+"')",500)
}

function scrollDivRight(id){
  clearTimeout(timerLeft)
  document.getElementById(id).scrollLeft-=scrollStep
  timerLeft=setTimeout("scrollDivRight('"+id+"')",500)
}

function toRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth
}

function stopMe(){
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
  document.getElementById(id).scrollLeft=0
}

function resetScroll(id){
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
  document.getElementById(id).scrollLeft=0
}


function searchFieldEvent(){
	
	var element = document.searchForm['search_camp[]'];
	var i = element.length-1;
	
	element[i].checked = false;
}

function searchGuidEvent(){
	
	var element = document.searchForm['search_camp[]'];
	
	for ( i=0; i<element.length-1; i++ ) {
	     element[i].checked = false;
	}

}

function checkAll(element) {
	
	for ( i=0; i<element.length; i++ ) {
	     element[i].checked = true;
	}
}

function uncheckAll(element) {
	
	for ( i=0; i<element.length; i++ ) {
	     element[i].checked = false; 
	}
}

function approveComments() {
	
	var form = document.commentsActionForm;
	if(confirm('Approve selected comments?')) {
		form.commentsAction.value = 'approve';
		form.submit();
	}
}

function unapproveComments() {
	
	var form = document.commentsActionForm;
	if(confirm('Unapprove selected comments?')) {
		form.commentsAction.value = 'unapprove';
		form.submit();
	}
}

function deleteComments() {
	
	var form = document.commentsActionForm;
	if(confirm('Delete selected comments?')) {
		form.commentsAction.value = 'delete';
		form.submit();
	}
}

function updateComment(cid) {
	var element = document.getElementById('comment' + cid);
	var formSave = document.updateCommentForm;
	formSave.comment.value = element.value;
	formSave.cid.value = cid;
	formSave.submit();

}

function toggleBlock(name) {
	
	var expanded = document.getElementById(name + 'Expanded');
	var collapsed = document.getElementById(name + 'Collapsed');
	
	if(expanded.style.display != 'none') {
		expanded.style.display = 'none';
		collapsed.style.display = 'block';
	}
	else {
		expanded.style.display = 'block';
		collapsed.style.display = 'none';
	}
}
