<!-- Hide script from old browsers
/**
 * Shows panel specified by id
 */
var currentPicPosition = 1;
var scrolling = false;
var SlidePicTotalNum = 0;
function movePicRight()
{ 	
	if (!scrolling)
	 {
	  scrolling = true;	  	  
	  currentPicPosition ++;	  	  
	  jQuery('#pictures-list').animate({left: -97*(currentPicPosition-1)}, 150, "linear", function(){
	  		scrolling=false;	  		
	  		if (currentPicPosition+2>=SlidePicTotalNum)
	  		{
		  		rightArrowObj = document.getElementById('rightArrowPic');
		  		rightArrowObj.style.visibility = "hidden";		  		
	  		}
	  		leftArrowObj = document.getElementById('leftArrowPic');
		  	leftArrowObj.style.visibility = "visible";
		  	
		  	document.getElementById('PictureFrom').innerHTML = (currentPicPosition-1)*4+1;
		  	document.getElementById('PictureTo').innerHTML = (currentPicPosition-1)*4+12;
	  });
	  	  
	 }	
}

function movePicLeft()
{ 
	if (!scrolling)
	 {
	  scrolling = true;
	  currentPicPosition --;	  	  	  	  
	  jQuery('#pictures-list').animate({left: -97*(currentPicPosition-1)}, 150, "linear", function(){
	  		scrolling=false;
	  		if (currentPicPosition-1<=0)
	  		{
		  		leftArrowObj = document.getElementById('leftArrowPic');
		  		leftArrowObj.style.visibility = "hidden";		  		
	  		}
	  		rightArrowObj = document.getElementById('rightArrowPic');
		  	rightArrowObj.style.visibility = "visible";
		  	
		  	
		  	document.getElementById('PictureFrom').innerHTML = (currentPicPosition-1)*4+1;
		  	document.getElementById('PictureTo').innerHTML = (currentPicPosition-1)*4+12;
		  	
	  });	  
	 }	
}

function InitPicPosition(position)
{
	currentPicPosition = position;	
	leftArrowObj = document.getElementById('leftArrowPic');
	rightArrowObj = document.getElementById('rightArrowPic');
	rightArrowObj.style.visibility = "visible";
	leftArrowObj.style.visibility = "visible";
	
	
	if (currentPicPosition<=2)
  		leftArrowObj.style.visibility = "hidden";	
  	
  	if (currentPicPosition>=SlidePicTotalNum-1)	  		
		rightArrowObj.style.visibility = "hidden";
		
	if (SlidePicTotalNum<=3)
  		leftArrowObj.style.visibility = "hidden";	
	
	//alert(currentPicPosition +", "+SlidePicTotalNum);
	
	if (currentPicPosition==SlidePicTotalNum)	
		document.getElementById('pictures-list').style.left = "-" + 97*((currentPicPosition)-3) + "px";
	else if (currentPicPosition==SlidePicTotalNum-1)	
		document.getElementById('pictures-list').style.left = "-" + 97*((currentPicPosition)-2) + "px";
	else if (currentPicPosition>=3)
		document.getElementById('pictures-list').style.left = "-" + 97*((currentPicPosition)-2) + "px";		
	
	if(position>1)currentPicPosition = position-1;		
	if(position==SlidePicTotalNum)currentPicPosition = position-2;
	if(SlidePicTotalNum<=3)currentPicPosition = 1;
		
	//document.getElementById('PictureFrom').innerHTML = currentPicPosition;
	//document.getElementById('PictureTo').innerHTML = currentPicPosition+2; 
	jQuery("#PictureFrom").html((currentPicPosition-1)*4+1);
	jQuery("#PictureTo").html((currentPicPosition-1)*4+12);
	
	if (((currentPicPosition-1)*4+12) >= SlidePicTotalNum*4) rightArrowObj.style.visibility = "hidden";
	
}
 
function InitPicSlide()
{	
	leftArrowObj = document.getElementById('leftArrowPic');
	rightArrowObj = document.getElementById('rightArrowPic');	
	leftArrowObj.style.cursor = 'pointer';	
	rightArrowObj.style.cursor = 'pointer';	
	leftArrowObj.onclick = movePicLeft;
	rightArrowObj.onclick = movePicRight;
} 
 
function showPane(id)
{
	var obj;
	if(obj = document.getElementById(id)) obj.style.display='';
}

/**
 * Hides panel specified by id
 */
function hidePane(id)
{
	var obj;
	if(obj = document.getElementById(id)) obj.style.display='none';
}

/**
 * JavaScript validation for terms checkbox in user registration page.
 */
function termsClientValidate(sender, parameter)
{
	if (!parameter)
		return false;
	else
		return true;
}

/**
 * JavaScript validation for gender radio buttons.
 */
function genderClientValidate(sender, parameter)
{
	male = document.getElementById('ctl0_Content_Male');
	female = document.getElementById('ctl0_Content_Female');
	error = document.getElementById('ctl0_Content_ErrorGender');

	if (!male.checked && !female.checked)
	{
		error.style.display = '';
		return false;
	}
	else 
	{
		error.style.display = 'none';
		return true;
	}
}

/**
 * JavaScript validation for birthdate list boxes.
 */
function birthdateClientValidate(sender, parameter)
{
	birthday = document.getElementById('ctl0_Content_BirthDay');
	birthmonth = document.getElementById('ctl0_Content_BirthMonth');
	birthyear = document.getElementById('ctl0_Content_BirthYear');
	error = document.getElementById('ctl0_Content_ErrorBirthDate');
	
	if (birthday.value == '-' || birthmonth.value == '-' || birthyear.value == '-')
	{
		error.style.display = '';
		return false;
	}
	else
	{ 
		error.style.display = 'none';
		return true;
	}
}

/**
 * JavaScript validation for category drop down list.
 */
function categoryClientValidate(sender, parameter)
{
	if (parameter == '-')
		return false;
	else
		return true;
}

function toggleAlbumView(){
	var mode = readCookie('videosDefaultView');
	if(mode == null) createCookie('videosDefaultView', 1, 1);
	else changeClipView(mode);
}

/**
 * Toggle between different view modes.
 * if mode = 2 switches to thumbnails view mode.
 * if mode = 1 switches to normal view mode.
 */
function changeView(mode){
	var el1 = document.getElementById("btn-v1");
	var el2 = document.getElementById("btn-v2");
	
	//Normal view mode
	if(mode==1){
		//We show normal-view div and hide thumbnail-view div
		showPane('normal-view'); 
		hidePane('thumbnail-view');
		el1.className = "btn-view-normal-sel";
		el2.className = "btn-view-thumbs";
		defaultClipView = 1;
		
		//We save the view mode
		createCookie('videosDefaultView', 1, 1)
	} 
	else if(mode == 2) {
		//Now we hide normal-view div and show thumbnail-view div
		hidePane('normal-view'); 
		showPane('thumbnail-view');
		
		el1.className = "btn-view-normal";
		el2.className = "btn-view-thumbs-sel";	
		defaultClipView = 2;
		
		//We save the view mode
		createCookie('videosDefaultView', 2, 1)
	}
}

/**
 * function that creates cookie 
 * first parameter sets cookie name
 * second sets cookie value
 * last parameter sets cookie expiration time
 */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/**
 * Selects all input content
 */
function selectText(textbox)
{
	jQuery("#"+textbox).select();
}

/**
 * Sets video player volume in COOKIE
 */
function setPlayerVolume(volume)
{
	createCookie("playerVolume",volume,1);
}

/**
 * Displays send message panel.
 */
function showSendMessagePanel(userId, errorMsg)
{
	if (userId != '')
		jQuery('#send-message-panel').show('fast');
	else
		showUserRegisteredError(errorMsg, 'message');	
}

/**
 * Selects video search option for search input box.
 */
function searchOptionVideosCheck()
{
	jQuery('#search-videos').attr('className', 'search-option-videos-sel');
	jQuery('#search-users').attr('className', 'search-option-users');
	jQuery('#search-option-field').val('1');
}

/**
 * Selects users search option for search input box.
 */
function searchOptionUsersCheck()
{
	jQuery('#search-videos').attr('className', 'search-option-videos');
	jQuery('#search-users').attr('className', 'search-option-users-sel');
	jQuery('#search-option-field').val('2');
}
 

/**
 * JavaScript validation for terms checkbox in user registration page.
 */
function termsClientValidate(sender, parameter)
{
	if (!parameter)
		return false;
	else
		return true;
}

/**
 * JavaScript validation for gender radio buttons.
 */
function genderClientValidate(sender, parameter)
{
	male = document.getElementById('ctl0_Content_Male');
	female = document.getElementById('ctl0_Content_Female');
	error = document.getElementById('ctl0_Content_ErrorGender');

	if (!male.checked && !female.checked)
	{
		error.style.display = '';
		return false;
	}
	else 
	{
		error.style.display = 'none';
		return true;
	}
}

/**
 * JavaScript validation for birthdate list boxes.
 */
function birthdateClientValidate(sender, parameter)
{
	birthday = document.getElementById('ctl0_Content_BirthDay');
	birthmonth = document.getElementById('ctl0_Content_BirthMonth');
	birthyear = document.getElementById('ctl0_Content_BirthYear');
	error = document.getElementById('ctl0_Content_ErrorBirthDate');
	
	if (birthday.value == '-' || birthmonth.value == '-' || birthyear.value == '-')
	{
		error.style.display = '';
		return false;
	}
	else
	{ 
		error.style.display = 'none';
		return true;
	}
}

/**
 * JavaScript validation for category drop down list.
 */
function categoryClientValidate(sender, parameter)
{
	if (parameter == '-')
		return false;
	else
		return true;
}


/**
 * Called when Thumbnails view button is clicked.
 * Thumbnails button is selected. Normal view button becomes normal
 */
function btnView1Click()
{
	document.getElementById('btn-v1').className = 'btn-view1-sel';
	document.getElementById('btn-v2').className = 'btn-view2';
}

/**
 * Called when Thumbnails view button is clicked.
 * Thumbnails button becomes norlam. Normal view button becomes selected
 */
function btnView2Click()
{
	document.getElementById('btn-v2').className = 'btn-view2-sel';
	document.getElementById('btn-v1').className = 'btn-view1';
}

current_clip_info_id = 'clips-editor-info';

/**
 * Displays selected video highlight list
 */
loadingClipList = false;
function show_current_clip_info(clip_info_id)
{
	if (!loadingClipList)
	{
		if (clip_info_id != current_clip_info_id)
		{
			//showPane(clip_info_id);
			//hidePane(current_clip_info_id);
			jQuery('#'+clip_info_id).show();
			jQuery('#'+current_clip_info_id).hide();
			current_clip_info_id = clip_info_id;
		}
	
		switch (clip_info_id)
		{
			case 'clips-editor-info': type = 1; break;
			case 'clips-recent-info': type = 2; break;
			case 'clips-popular-info': type = 3; break;
			case 'clips-rated-info': type = 4; break;						
		}
		
		loadingClipList = true;
		jQuery('#header-clips-holder').load('modules/ajax_videos_highlight_list.php', {type: type}, function() {
			loadingClipList = false;
		});
	}
}

/**
 * Displays selected video highlight
 */
loadingClip = false;
function select_clip(clip_holder_id, id, type)
{
	if (!loadingClip)
	{
		clip_holder = document.getElementById(clip_holder_id);
	
		switch (current_clip_info_id)
		{
			case 'clips-editor-info' :
				clip_holder.className = 'clip-item-sel-editor';
				break;
			case 'clips-recent-info' :
				clip_holder.className = 'clip-item-sel-recent';
				break;
			case 'clips-popular-info' :
				clip_holder.className = 'clip-item-sel-popular';
				break;
			case 'clips-rated-info' :
				clip_holder.className = 'clip-item-sel-rated';
				break;			
		}
	
		for (i=1; i<=4; i++)
		{
			obj = document.getElementById("clip-item-holder"+i);
			if (obj != clip_holder)
			{
				obj.className = 'clip-item-holder';
			}
		}
		
		loadingClip = true;
		jQuery.ajax({
			type:'POST', 
			url:'modules/ajax_videos_highlight.php', 
			data:'id='+id+'&type='+type, 
			success:function(data) {
				loadingClip = false;
				jQuery('#header-main-clip').html(data);				
			}
		});
	}
}

/**
 * Shows panel specified by id
 */
function showPane(id)
{
	var obj;
	if(obj = document.getElementById(id)) obj.style.display='';
}

/**
 * Hides panel specified by id
 */
function hidePane(id)
{
	var obj;
	if(obj = document.getElementById(id)) obj.style.display='none';
}

/**
 * If videosDefaultView cookie is set, we read it and switch to the a 
 * viewing mode depending on cookie value. Alternatively we set the cookie with view mode 1 - normal view
 */
function toggleClipView(){
	var mode = readCookie('videosDefaultView');
	if(mode == null) createCookie('videosDefaultView', 1, 1);
	else changeView(mode);
}


/**
 * Reads cookie value for cookie name specified by name
 */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/**
 * erase cookie
 */
function eraseCookie(name) {
	createCookie(name,"",-1);
}

/**
 * Hides/shows response videos divs depending on rcont value.
 * Decrements rcont.
 */
var rcont = 1;
function scrollLeftResponse(){
	if(document.getElementById('response-container-'+(rcont-1)) && rcont>1){
		rcont--; 
		hidePane('response-container-'+(rcont+1)); 
		showPane('response-container-'+rcont);
	}
}

/**
 * Hides/shows response videos divs depending on rcont value.
 * Increments rcont.
 */
function scrollRightResponse(){
	if(document.getElementById('response-container-'+(rcont+1)) && rcont<3){
		rcont++;
		hidePane('response-container-'+(rcont-1)); 
		showPane('response-container-'+rcont);
	}
}

/**
 * Ajax script. Loads subvideos into related-videos div
 */
var currentView = "normal";
var lastId;
var subVideosType;
function loadSubVideos(id, type, view, author_id, label){
	jQuery('#related-title').html(label);
	if(currentView != view || subVideosType != type){
		lastId = id;
		subVideosType = type;
		jQuery('#related-videos').load('modules/ajax_get_subvideos.php', {vid: id, type: type, view: view, author_id: author_id});
	}	
}

/**
 * Called when thumbnails or normal view button is clicked in related videos panel 
 * in Video preview page. 
 */
function changeSubVideos(view, author_id){
	if(currentView != view){
		loadSubVideos(lastId, subVideosType, view, author_id);
		currentView = view;
	}
}

/**
 * Ajax script. Loads video comments into comments panel in Video preview page
 */
var currentCommentsPage;
function loadComments(id, page, type){
	jQuery('#comments-holder').load('modules/ajax_get_comments.php', {id: id, page: page, type:type});
	currentCommentsPage = page;
}

/**
 * Shows add comment panel in Video Preview page
 */
function showAddCommentPanel(){
	jQuery('#add-comment-panel').show('slow');
	jQuery('#comment-result').hide('fast');
}

/**
 * Called when add comment button is clicked in Video preview page.
 * First parameter specifies video id.
 * Second specifies the current language.
 * Third parameter specifies the user id.
 * if parent_id = 0 then the comment is nota a response to another comment
 * Alternatively the comment is a response to a comment with id = parent_id 
 */
function addComment(id, parent_id, pid, type){
	if(parent_id == 0){
		var title = jQuery("#comment-title").val();
		var text = jQuery("#comment-text").val();	
	} else {
		var title = jQuery('#comment-title-reply-'+pid).val();
		var text = jQuery('#comment-text-reply-'+pid).val();
	}

	if(title.length == 0) alert('Enter comment title!');
	else if(title.length > 50) alert('Title length must shorter than 50 characters!');
	else if(text.length == 0) alert('Enter comment!');
	else if(text.length > 500) alert('Comment length must shorter than 500 characters!');
	else {
		if(parent_id == 0){
			jQuery("#comment-text").val('');
			jQuery("#comment-title").val('');
		} else {
			jQuery('#comment-title-reply-'+pid).val('');
			jQuery('#comment-text-reply-'+pid).val('');
		}
		jQuery('#comment-result').load('modules/ajax_add_comment.php', {id: id, title: title, text: text, parent_id: parent_id, type: type});
		jQuery("#comment-text").val('');
		jQuery("#comment-title").attr('disabled');
		jQuery("#remaining-symbols").text("500");
	}
}

//Function sets languale constants for reply-form in Video preview page
var labelTitle;
var labelComment;
var labelReply;
var labelCancel;
var labelRemainigChars;
function setReplyFormText(ttitle, tcomment, treply, tcancel, tremain){
	labelTitle = ttitle;
	labelComment = tcomment;
	labelReply = treply;
	labelCancel = tcancel;
	labelRemainigChars = tremain;
}
/**
 * Called when reply link on a comment is clicked 
 */
function replyComment(id, pid, vid, title, type){
	var html = getReplyFormHtml(id, vid, title, pid, type);
	var obj = document.getElementById('comment-reply-'+id);
	obj.innerHTML = html;
	jQuery('#comment-reply-'+id).show();
}

/**
 * Displays reply form
 */
function getReplyFormHtml(id, vid, title, pid, type)
{
	if(type=="pictures") width = 460;
	else width = 290;
	var rForm = 'test';

	var rForm = '<div id="reply-comment-panel">'	+	
					'<div class="bold">'+ labelTitle +':</div>' +
					'<div class="spacer">' +
						'<input type="text" id="comment-title-reply-'+ id +'" Style="width: '+ width +'px;" class="text-box" value="'+ title +'" />'+
					'</div>' +
					'<div class="bold" style="padding-top: 10px;">'+ labelComment +':</div>' +
					'<div class="spacer">' +
						'<textarea id="comment-text-reply-'+ id +'" rows="5" style="width: '+ width +'px; margin-bottom: 10px;" class="text-box" onkeyup="textKeyPress(\'comment-text-reply-'+ id +'\', \'remaining-symbols-'+ id +'\')" ></textarea>' +
					'</div>'+						
					'<div style="float: left;">' +
						'<div class="btn-submit-left"/></div>' +
						'<a href="javascript: void(0);" class="btn-submit" style="width: 50px;" onClick="addComment(\''+ vid +'\', '+ pid +', '+ id +', \''+ type +'\');">'+ labelReply +'</a>'+
						'<div class="btn-submit-right"/></div>' +
					'</div>' +
					'<div style="float: left; width: 10px; height: 15px;">&nbsp;</div>'+
					'<div style="float: left;">' +
						'<div class="btn-submit-left"/></div>' +
						'<a href="javascript: void(0);" class="btn-submit" onClick="jQuery(\'#comment-reply-'+ id +'\').hide()">' + labelCancel + '</a>' +	
						'<div class="btn-submit-right"/></div>' +
					'</div>' +									
					'<div id="remaining-symbols-'+ id +'" style="float: right; font-weight: bold; padding-top: 4px;">500</div>' +
					'<div class="remaining-symbols-text">' + labelRemainigChars + ':</div>' +	
					'<div class="clear" style="margin-bottom:10px"></div>'+				
				'</div>';	
			
	return rForm;	
}

/**
 * Called on onkeyup event in 'add' or 'reply comment' form in Video Preview page
 */
function textKeyPress(fld, tpanel){
	var text = jQuery("#"+fld).val();

	var remainingSymbols=(500-text.length);
	jQuery("#"+tpanel).text(remainingSymbols);
}

/*
 * RATING FUNCTIONS
 */
 
var starGraySrc = 'themes/Main/star-gray.gif';
var starRedSrc = 'themes/Main/star-red.gif';
var starHalfSrc = 'themes/Main/star-half.gif';
var starYellowSrc = 'themes/Main/star-yellow.gif';
var starsClassArray = new Array;
/**
 * Shows gif stars according to value
 */
function showRating(value)
{
	var cl;
	var starId = '';
	var valueStr = ''+value+'';
	
	var v1 = Math.floor(value);
	var v2 = valueStr.charAt(2);
	
	for (i=1; i<=5; i++)
	{
		cl = "star star-fade";
		if (i <= v1) cl = "star star-full";
		if (i == v1+1 && v2 >= 5) cl = "star star-half";
		starsClassArray[i-1] = cl;
		starId = document.getElementById('star'+i);
		starId.className = cl;
	}

}

/**
 * Called on mouse hover over rating star
 */
function ratingOver(id)
{
	var index = id.charAt(4);
	for (i=1; i<=index; i++)
		document.getElementById('star'+i).className = "star star-full";
}

/**
 * Called on mouse out over rating star
 */
function ratingOut(id)
{
	var index = id.charAt(4);
	for (i=1; i<=index; i++)
		document.getElementById('star'+i).className = starsClassArray[i-1];
}

/**
 * Called when users clicks on Favourites button in Video preview page
 * Ajax call to a script that processes information and the result is displayed in action-result div
 */
var addToFavoutites;
function addToFavourites(picture_id){
	if(!addToFavoutites){
		jQuery("#action-result").load('modules/ajax_add_favourites.php', {picture_id: picture_id}, function(){
			resultPanelShow();
		});
		addToFavoutites = true;
	}
}

/**
 * called on onClick event on a rating star
 */
function rate(id, fieldId)
{
	var index = fieldId.charAt(4);
	jQuery("#rating-stars").load('modules/ajax_rate.php', {picture_id: id, rating: index}, function(){
		jQuery("#panel-voted").load('modules/ajax_showrating.php', {id: id});
	});
}
 
var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;

/**
 * Shows action-result div for a several seconds
 */
function resultPanelShow()
{
    // Set the length of the timer, in seconds
    secs = 5;
    StopTheClock();
    StartTheTimer();
    jQuery("#action-result").show('fast');
}

/**
 * Stops timer
 */
function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

/**
 * Starts timer
 */
function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
       	jQuery("#action-result").hide('fast');
    }
    else
    {
        self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}

/**
 * Called on user click on send button in send message panel in Video preview page
 * Ajax call to a script that processes the data and returns the result in action-result div 
 */
sendButtonDisabled = false;
processingAjax = false;
function sendMessage(picture_id, user_id, lang){
	var message_to = jQuery("#message-to").val();
	var message_text = jQuery("#message-text").val();
	
	if(message_to.length == 0) alert('Please enter valid e-mail or username.');
	else if(message_text.length == 0) alert('Please enter your message');
	else if(processingAjax == false) {
		processingAjax = true;
		jQuery("#send-button").attr('disabled', 'disabled');	
		jQuery("#action-result").load('modules/ajax_send_message.php', {picture_id: picture_id, user_id: user_id, lang: lang, to: message_to, text: message_text}, function(){
			processingAjax = false;
			resultPanelShow();
		});
	}
}

/**
 * Called on user click over Inappropriate button in Video preview page
 */
var markedAsInappropriate;
function markAsInappropriate(picture_id){
	if(!markedAsInappropriate)
	{
		jQuery("#action-result").load('modules/ajax_add_inappropriate.php', {picture_id: picture_id}, function(){
			resultPanelShow();
		});	
		markedAsInappropriate = true;
	}
}

/**
 * Called when Add Video repsonse link clicked in Video Preview page
 * or add video clip as a response cliced
 * In the first case displays user videos for selecting a video as a video response.
 * In the second case processes user video selection, 
 * makes ajax script and loads the result in action-result div
 */
var responsePanelLoaded = false;
function addResponse(video_id, show_form){
	if(show_form==1){
		if(!responsePanelLoaded){
			jQuery("#response-panel").load('modules/ajax_add_response.php', {video_id: video_id, show_form: show_form}, function(){
				jQuery("#response-panel").show('fast');
				responsePanelLoaded = true;
			});			
		}	
	} else {
		jQuery("#response-panel").hide();
		var sel = document.getElementById("user-videos");
		if(sel) sel_index = sel.options[sel.selectedIndex].value;	
		jQuery("#action-result").load('modules/ajax_add_response.php', {video_id: video_id, show_form: show_form, sel_index: sel_index}, function(){
			responsePanelLoaded = false;
			window.location.reload();
		});
	}
}

/**
 * Called on user click on subscribe to user in Video preview page or user profile page
 */
var subscribed = false;
function subscribe(user_id, profile_id, lang, panel){
	if(!subscribed && user_id != profile_id)
	{			
		jQuery("#"+panel).load('modules/ajax_subscribe.php', {user_id: user_id, profile_id: profile_id, lang: lang});
	}
}

/**
 * Called onClick event on Inappropriate button in Group preview page 
 */
function markAsUnappropriateGroup(group_id, lang)
{	
	jQuery("#markGroup").hide();
	jQuery("#action-result").load('modules/ajax_add_inappropriate_group.php', {group_id: group_id, lang: lang}, function(){
		jQuery("#action-result").show();
	});
}

/*
 * 
 */
targetFavourites = false;
targetSendMessage = false
function showUserRegisteredError(error, target){
	if(target == "message"){
		if(targetSendMessage) return false;
		targetSendMessage = true;
	}
	else if(target == "favourites"){
		if(targetFavourites) return false;
		targetFavourites = true;
	}
	
	jQuery("#action-result").html(error);
	resultPanelShow();
}

requestInProgress = false;
function markCommentAsSpam(id, type, target_id){
	
	if(!requestInProgress){
		requestInProgress = true;
		jQuery("#comment-result").load('modules/ajax_mark_spam.php', {id: id, type: type, target_id: target_id}, function(){			
			loadComments(target_id, currentCommentsPage, type);
			requestInProgress = false;			
		});	
	}
}

// --------------------------------------------------
// USER PROFILE FUNCTIONS
// --------------------------------------------------

// Shows file upload input
function showUserImageUploadForm()
{
	if (!uploadingImage)
		showPane('user-img-holder');
}

// Hides file upload input
function hideUserImageUploadForm()
{
	hidePane('user-img-holder');
}

// Indicates if file upload is completed
var uploadingImage = false;

// Ajax file upload function
function ajaxFileUpload(userId, userImageDir)
{
	if (jQuery('#fileToUpload').val() != '')
	{
		hideUserImageUploadForm();
		uploadingImage = true;
		
		jQuery("#user-profile-image").html('<img src="themes/Main/loading.gif" border="0" style="margin: 38px 0px 0px 48px;" />');
		
		jQuery.ajaxFileUpload
		(
			{
				url:'modules/ajax_user_image_upload.php?uid='+userId,
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{					
					jQuery('#fileToUpload').val('');
					uploadingImage = false;			
							
					if(typeof(data.error) != 'undefined')
					{
						if(data.error == '')						
						{
							var date = new Date();
							jQuery("#user-profile-image").html('<img src="'+userImageDir+userId+"/C.jpg?"+date.getTime()+'" border="0" />');							
						}
					}
				},
				error: function (data, status, e)
				{
					jQuery('#fileToUpload').val('');
					uploadingImage = false;
					console.info(data);										
				}
			}
		)	
	}
}

// Shows user quote input
function showUserQuoteUpdateForm()
{
	if (!updatingQuote)
	{
		showPane('edit-quote-form'); 
		hidePane('edit-quote');
	}
}

// Hides user quote input
function hideUserQuoteUpdateForm()
{
	showPane('edit-quote'); 
	hidePane('edit-quote-form');
}

// Indicates if update quote request is completed
var updatingQuote = false;

// Updates user quote
function updateUserQuote(uid, div_id, label_update)
{
	updatingQuote = true;
	jQuery('#quote-text').html(label_update);
	hideUserQuoteUpdateForm();
	quote = jQuery('#'+div_id).val();
	jQuery('#quote-text').load('modules/ajax_update_user_quote.php', {uid: uid, quote:quote}, function() {
		//jQuery('#'+div_id).val(jQuery('#quote-text').html());
		updatingQuote = false;
	});
}

function updatePictureTitle (pid, div_id, label_update)
{
	updatingTitle = true;
	jQuery('#title-panel-'+pid).html(label_update);
	hidePane('title-form-'+pid); showPane('title-panel-'+pid);
	title = jQuery('#'+div_id).val();
	
	jQuery('#title-panel-'+pid).load('modules/ajax_update_picture_title.php', {pid: pid, title:title}, function() {		
		updatingTitle = false;
	});
}

function updatePictureDescription(pid, div_id, label_update)
{
	updatingDesc = true;
	jQuery('#desc-panel-'+pid).html(label_update);
	hidePane('desc-form-'+pid); showPane('desc-panel-'+pid);
	desc = jQuery('#'+div_id).val();
	
	jQuery('#desc-panel-'+pid).load('modules/ajax_update_picture_desc.php', {pid: pid, desc:desc}, function() {		
		updatingDesc = false;
	});
}

// Shows user info input
function showUserInfoUpdateForm()
{
	if (!updatingInfo)
	{
		showPane('edit-info-form'); 
		hidePane('edit-info');
	}
}

// Hides user info input
function hideUserInfoUpdateForm()
{
	showPane('edit-info'); 
	hidePane('edit-info-form');
}

// Indicates if update info request is completed
var updatingInfo = false;

// Updates user info
function updateUserInfo(uid, div_id, label_update)
{
	updatingInfo = true;
	jQuery('#info-text').html(label_update);
	hideUserInfoUpdateForm();
	info = jQuery('#'+div_id).val();
	jQuery('#info-text').load('modules/ajax_update_user_info.php', {uid: uid, info:info}, function() {
		//jQuery('#'+div_id).val(jQuery('#info-text').html());
		updatingInfo = false;
	});
}

function cbCheck(check)
{
	var parent = document.getElementById("checkAll");
	var radio;
	var i = 1;
		
	parent.checked = check;
	
	arr = document.getElementById("user-content").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
	{		
		arr[i].checked = check;				
	}
}

var AllowCheckOtherOption=true;
function SetParam(sender,index)
{		
	var numSelected = 0;
		
	arr = document.getElementById("allItems").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;		
		
	if (sender.selectedIndex==index) 
	{
		AllowCheckOtherOption=false;
		if (numSelected>1)
		{
			arr = document.getElementById("allItems").getElementsByTagName('input');		
			for(i=0; i<arr.length; i++) 
				arr[i].checked = false;
		}
	}
	else
	{
		AllowCheckOtherOption=true;		
	}	
	
				
		arr = document.getElementById("allItems").getElementsByTagName('select');	
			for(i=0; i<arr.length; i++) 			
			arr[i].selectedIndex = sender.selectedIndex;
		
}	

function SetMultyParam(sender, index1, index2, index3)
{	
	if (sender.selectedIndex==index1 ) 
	{
		SetParam(sender,index1);
	}
	if (sender.selectedIndex==index2 ) 
	{
		SetParam(sender,index2);
	}	
	
	if (sender.selectedIndex!=index2 &&  sender.selectedIndex!=index1 && sender.selectedIndex!=index3)  SetParam(sender,index2)
	
}

function checkBoxControl(ob)
{	
	var numSelected = 0;
		
	if (!AllowCheckOtherOption)
	{
		arr = document.getElementById("allItems").getElementsByTagName('input');	
		for(i=0; i<arr.length; i++) 
			if (arr[i].checked) numSelected=numSelected+1;
			
		if (numSelected>1)	
		{
			for(i=0; i<arr.length; i++)
				arr[i].checked = false;				
			
		current = document.getElementById(ob);		
		current.checked = true; 
		}
	}	
}

var AllowCheckPrivateCategories = false;
function synchronizePrivateCategories(sender, index)
{
	var numSelected = 0;
		
	arr = document.getElementById("allItems").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;	
			
	if (sender.selectedIndex==0 || sender.selectedIndex==2) 
	{
		AllowCheckPrivateCategories=false;
		if (numSelected>1)
		{
			arr = document.getElementById("allItems").getElementsByTagName('input');		
			for(i=0; i<arr.length; i++) 
				arr[i].checked = false;
		}
	}
	else AllowCheckPrivateCategories=true;	
				
	arr = document.getElementById(index);
	arr.selectedIndex = sender.selectedIndex;
}

function checkPrivateCategories(ob)
{
	var numSelected = 0;
		
	if (!AllowCheckPrivateCategories)
	{
		arr = document.getElementById("allItems").getElementsByTagName('input');	
		for(i=0; i<arr.length; i++) 
			if (arr[i].checked) numSelected=numSelected+1;
			
		if (numSelected>1)	
		{
			for(i=0; i<arr.length; i++)
				arr[i].checked = false;				
			
		current = document.getElementById(ob);		
		current.checked = true; 
		}
	}	
}

function showConfirmGroup(ob, message1, message2)
{	
	var numSelected=0;
	var message ="";
	
	arr = document.getElementById("allItems").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;
	
	if (!numSelected) return false;
	else
	{
		var select = document.getElementById(ob).selectedIndex;
		
		if (select == 0) 
			message = message1; 
		else
			message = message2; 
			
		if(!confirm(message)) 
			return false;
		else 
			return true;
	}
} 

function showConfirmVideoInInapp(ob, message1, message2)
{	
	var numSelected=0;
	var arr;
	var message='';
	arr = document.getElementById("allItems").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;
	
	if (!numSelected) return false;
	else
	{
		var select = document.getElementById(ob).selectedIndex;	
		if (select == 0) 
			message = message1; 
		else
			message = message2; 
			
		if(!confirm(message)) 
			return false;
		else 
			return true;
	}
	
} 

function confirmSpamCommentsAction(ob, message1, message2)
{	
	var numSelected=0;
	var arr;
	
	arr = document.getElementById("allItems").getElementsByTagName('input');	
	for(i=0; i<arr.length; i++) {
		if (arr[i].checked) numSelected=numSelected+1;
		
	}
		
	if (!numSelected) return false;
	else
	{
		var select = document.getElementById(ob).selectedIndex;	
		if (select == 0) 
			message = message1; 
		else
			message = message2; 
			
		if(!confirm(message)) 
			return false;
		else 
			return true;
	}
}

function showConfirmGroupDelete(ob, message1, message2)
{
	var select = document.getElementById(ob).selectedIndex;
	
	var numSelected = 0;
		
	arr = document.getElementById("allItems").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;
	
	if (!numSelected) return false;
	else
	{	
		if (select == 0)
		{ 
		    arr = document.getElementById("allItems").getElementsByTagName('select');		
			numSelected = arr[0].length;
		    if(numSelected==1)
		     message = message1; 
		    else
		     message = message2; 
			if(!confirm(message)) 
				return false;
			else 
				return true;
		}
		else return true;
	}
}

function showConfirmVideoInUserSettings(ob, message)
{	
	var select = document.getElementById(ob).selectedIndex;
	
	var numSelected = 0;
		
	arr = document.getElementById("allItems").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;
	
	if (!numSelected) return false;
	else
	{	
		if (select == 0)
		{	
			if(!confirm(message)) 
				return false;
			else 
				return true;
		}
		else return true;
	}
} 

function showConfirmVideoInResponse(ob, message)
{
	var select = document.getElementById(ob).selectedIndex;
	
	var numSelected = 0;
		
	arr = document.getElementById("allItemsR").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;
	
	if (!numSelected) return false;
	else
	{	
		if (select == 0)
		{	
			if(!confirm(message)) 
				return false;
			else 
				return true;
		}
		else return true;
	}
}

function showConfirmCategoriesDelete(ob, message)
{
	var select = document.getElementById(ob).selectedIndex;
	
	var numSelected = 0;
	
	arr = document.getElementById("allItems").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;
	
	if (!numSelected) return false;
	else
	{	
		if (select == 1)
		{	
			if(!confirm(message)) 
				return false;
			else 
				return true;
		}
		else return true;
	}	
}

function showIfHasChecked()
{	
	var arr = document.getElementById("allItems").getElementsByTagName('input');
	var	numSelected=0;
		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;
	
	if (numSelected) return true;
	else return false; 
}
function confirmVideosInGroupPreview(ob, message)
{
	var numSelected = 0;
	var select = document.getElementById(ob).selectedIndex;
		
	arr = document.getElementById("allItems").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;	
		
	if (!numSelected) return false;
	else
	{	
		if (select == 1)
		{ 			    
			if(!confirm(message)) 
				return false;
			else 
				return true;
		}
		else return true;
	}	
}

function confirmUsersInGroupPreview(ob, message)
{
	var numSelected = 0;
	var select = document.getElementById(ob).selectedIndex;
		
	arr = document.getElementById("allItems").getElementsByTagName('input');		
	for(i=0; i<arr.length; i++) 
		if (arr[i].checked) numSelected=numSelected+1;	
		
	if (!numSelected) return false;
	else
	{	
		if (select == 0)
		{ 			    
			if(!confirm(message)) 
				return false;
			else 
				return true;
		}
		else return true;
	}	
}

function confirmMessage(message){
	if(!confirm(message)) 
		return false;
	else 
		return true;
}

function checkIfIsString(sender)
{		
	var obj = document.getElementById(sender)
	var v = obj.value;
	if (v.length) return true;
	else return false;
}

//Multiselect Control functions
var totalUploadSize = 0;
var fileSizes = new Object();

function fileQueueError(fileObj, error_code, message) {
	try {
		var error_name = "";
		switch(error_code) {
			case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED:
				error_name = "You have attempted to queue too many files.";
			break;
		}

		if (error_name !== "") {
			alert(error_name);
			return;
		}

		switch(error_code) {
			case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
				image_name = "zerobyte.gif";
			break;
			case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
				image_name = "toobig.gif";
			break;
			case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
			case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
			default:
				alert(message);
				image_name = "error.gif";
			break;
		}

		AddImage("images/" + image_name);

	} catch (ex) { this.debug(ex); }

}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function fileDialogComplete(num_files_queued) {
	try {
		if (num_files_queued > 0) {
			var midp = (totalUploadSize / (1024*1024));
			var size = roundNumber(midp, 2) + " MB";
			jQuery('#files-size').html(size);
			jQuery('#files-num').html(swfu.getStats().files_queued);
		}
	} catch (ex) {
		this.debug(ex);
	}
}

var uploadMessage = true;
function fileQueued (fileObj) {
	try {
		var size = Math.round(fileObj.size / 1000);
		if(size > 1024*1024) size = Math.round((size / (1024*1024)), 3) + " MB";
		else size += " KB";
		
		if(uploadMessage){
			uploadMessage = false;
			jQuery('#uploads-holder').html('');
		}
		
		totalUploadSize += fileObj.size;
		fileSizes[fileObj.id] = fileObj.size;
		
		jQuery('#uploads-holder').html(jQuery('#uploads-holder').html()+'' +
		'<div id="ct-' + fileObj.id + '" class="uploads-container">' +
		'<div id="progress-holder-' + fileObj.id + '" class="text-layer" style="display: none;">' +
		'<div id="progress-bar-' + fileObj.id + '" class="up-sel-bck"><div class="uploading"></div></div>'	+
		'</div>' +
		'<div class="text-layer">' +	
		'<div class="txt-fld-1">' + fileObj.name + '</div>' +		
		'<div class="txt-fld-3">' + size + '</div>' +		
		'<a id="del-icon-' + fileObj.id + '" href="javascript: void(0);" class="remove-but" onClick="cancelUpload(\'' + fileObj.id + '\')"></a>' +
		'<div id="success-icon-' + fileObj.id + '" class="upload-success-icon"></div>' +	
		'<div id="fail-icon-' + fileObj.id + '" class="upload-fail-icon"></div>' +	
		'</div>' +	
		'<div class="up-bck"></div>' +	
		'</div>'
		);
	} catch (ex) { this.debug(ex); }
}

function recalculateTotalFilesSize(){
	totalUploadSize = 0;
	
	for(size in fileSizes) 
		totalUploadSize += fileSizes[size];
	return totalUploadSize;
}

function cancelUpload(id){
	try {
		jQuery('#ct-'+id).html(' ');
		jQuery('#ct-'+id).css('display', 'none');
		swfu.cancelUpload(id);
		jQuery('#files-num').html(swfu.getStats().files_queued);
		fileSizes[id] = 0;
		
		recalculateTotalFilesSize();
		var midp = (totalUploadSize / (1024*1024));
		var size = roundNumber(midp, 2) + " MB";
		jQuery('#files-size').html(size);
	}
	catch (ex){}
	
	return false;
}

function uploadStart(){
	try {
		jQuery('#fbrowse-but').hide();
		jQuery('#upload-details').hide();
		jQuery("#upload-progress").show();
		return true;
	} catch (ex) { 
		this.debug(ex); 
		return false;
	}
}

function uploadProgress(fileObj, bytesLoaded) {
	try {
		var percent = Math.ceil((bytesLoaded / fileObj.size) * 100)
		
		jQuery('#del-icon-' + fileObj.id).hide();
		
		if (percent === 100) {
			jQuery('#progress-holder-' + fileObj.id).show();
			jQuery('#progress-bar-' + fileObj.id).css("width", "300px");
		} 
		else {
			jQuery('#progress-holder-' + fileObj.id).show();
			jQuery('#progress-bar-' + fileObj.id).css("width: "+ percent*3 +"px;");
		}
	} catch (ex) { this.debug(ex); }
}

function uploadSuccess(fileObj, server_data) {
	try {
		// upload.php returns the thumbnail id in the server_data, use that to retrieve the thumbnail for display
		jQuery('#success-icon-' + fileObj.id).show();
		jQuery('#progress-bar-' + fileObj.id).css("width", "420px");
		jQuery('#progress-bar-' + fileObj.id).html('');
		
		if(swfu.getStats().files_queued == 0){
			jQuery("#upload-progress").hide();
			jQuery('#upload-success').show();
		}
	} catch (ex) { this.debug(ex); }
}

function uploadComplete(fileObj) {
	try {
		/*  I want the next upload to continue automatically so I'll call startUpload here */
		if (this.getStats().files_queued > 0) {
			this.startUpload();
		} 
	} catch (ex) { this.debug(ex); }
}

function uploadError(fileObj, error_code, message) {
	var image_name =  "error.gif";
	jQuery('#fail-icon-' + fileObj.id).show();
	try {
		switch(error_code) {
			case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
				try {
					var progress = new FileProgress(fileObj,  this.customSettings.upload_target);
					progress.SetCancelled();
					progress.SetStatus("Stopped");
					progress.ToggleCancel(true, this, fileObj.id);
				}
				catch (ex) { this.debug(ex); }
			case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
				image_name = "uploadlimit.gif";
			break;
			default:
				//alert(message);
			break;
		}

		AddImage("images/" + image_name);

	} catch (ex) { this.debug(ex); }

}

function startUpload(){
	var items = document.getElementById("allItems");
	if(!items) return false;
	arr = items.getElementsByTagName('select');  
	var value;
	value = arr[0].options[arr[0].selectedIndex].value;
	
	if (!value){
		alert('Select album before uploading.');
		return false;
 	} else {
		swfu.addSetting("post_params", {"album_id": value, "PHPSESSID": swfu.settings["post_params"]['PHPSESSID']});
		swfu.setPostParams(swfu.settings["post_params"]);
		swfu.startUpload();
	}
}

function togglePrivateAlbums(flag)
{
	if (flag) jQuery("#PrivateAlbum").show();
	else jQuery("#PrivateAlbum").hide();
}
// End hiddingscript from old browsers -->