// JavaScript Document
var file_uploads = 1;

function showUploadFile()
{
	if(file_uploads<10)
	{
		$(('file_upload_' + file_uploads)).show();
		file_uploads++;
	}
}function showUploadFile2(){	if(file_uploads<5)	{		$(('file_upload_' + file_uploads)).show();		file_uploads++;	}}

function loadWeather()
{
	new Ajax.Request('server/LoadWeather.php',
   		{
        	method: 'post'
    	}
    );	
}

function openSendToFriend()
{
	var html = $('send_to_friend').innerHTML;
	s_alert(html);
}

function openReportBadComment(commentId)

{
	var url = $('pageUrl').value;
	var html = '<div id="report_bad_comment"><form method="post" style="font-size:12px; color:#696969; font-weight:normal; text-align:left;"><span class="blue_title">Съобщи за обиден коментар</span><p>Вашето име:<br><input name="name" type="text" class="form_comment" /></p><p>От (e-mail):<br><input name="from_mail" type="text" class="form_comment" /></p><p>Вашето съобщение: </p><textarea rows="6" cols="25" name="message"></textarea><p><input name="subm" type="button" value="Съобщи" class="btn_send_comment" onclick="reportBadComment();" /></p><input type="hidden" name="url" value="' + url + '#' + commentId + '" /></form></div>';

	s_alert(html);

}


function sendToFriend()
{
	var formData = $('alertDivTxt').getElementsByTagName('form')[0];
	var data = formData.serialize();
	new Ajax.Request(file + '?' + data + '&func=sendToFriend', 
					 { 
						onComplete: function (result) { h_alert(); }
					 }
					);
}

function reportBadComment()

{

	var formData = $('report_bad_comment').getElementsByTagName('form')[0];

	var data = formData.serialize();

	new Ajax.Request(file + '?' + data + '&func=reportBadComment',

					 {

						onComplete: function () { h_alert(); }

					 }

					);

}


function test(h)
{
	$('forum_frame').style.height = h + 'px';
}

function makeEditor(name)
{
	Event.observe(window, 'load', function ()
											{
												var oFCKeditor = new FCKeditor(name);
												oFCKeditor.BasePath = fck;
												oFCKeditor.Width    = 610;
												oFCKeditor.Height   = 340;
												oFCKeditor.ToolbarSet = 'Basic';
												oFCKeditor.ReplaceTextarea();	
											}, false);
}

function showHiddenMenu(lnk)
{
	var ul = (lnk.parentNode).parentNode;
	if(ul)
	{
		var hiddenLI = ul.getElementsByClassName('hidden');
		for(var i=0; i<hiddenLI.length; i++)
		{
			hiddenLI[i].className = '';
		}
		
		(lnk.parentNode).className = 'hidden';
	}
}

function hideLinkIfNecessary()
{
	var nUL = $('main_menu').getElementsByTagName('ul');

	for(var i=0; i<nUL.length; i++)
	{
		try
		{
			var hiddenLI = nUL[i].getElementsByClassName('hidden');
		
			if(hiddenLI.length < 1)
			{
				var lnkLI = nUL[i].getElementsByClassName('show_all_link')[0];
				lnkLI.className = 'hidden';
			}
		}
		catch(err)
  		{
  			/*txt="There was an error on this page.\n\n";
  			txt+="Error description: " + err.description + "\n\n";
  			txt+="Click OK to continue.\n\n";
  			alert(txt);*/
  		}
	}
}


function enlargePic(imgSrc)
{
	var src   = imgSrc;
	var img = $('bigImg');	
	
	var imgPreloader = new Image();
	
	new Effect.Opacity(img, Object.extend(
						{
					   		duration: 0.25, 
							from:1.0, 
							to:0.0,
							afterFinishInternal: function(effect) 
							{
								imgPreloader.src = src;
							}
						})
			);	
	
	// once image is preloaded, appear the image
	imgPreloader.onload = function()
	{
		img.src 	= src;
		new Effect.Appear(img, {duration: 0.25});
	}	
}

function enlargePicture(imgSrc, div)
{
	var src   = imgSrc;
	var img = $(div);	
	
	var imgPreloader = new Image();
	
	new Effect.Opacity(img, Object.extend(
						{
					   		duration: 0.25, 
							from:1.0, 
							to:0.0,
							afterFinishInternal: function(effect) 
							{
								imgPreloader.src = src;
							}
						})
			);	
	
	// once image is preloaded, appear the image
	imgPreloader.onload = function()
	{
		img.src 	= src;
		new Effect.Appear(img, {duration: 0.25});
	}	
}

function defaultArticleFont()
{
	var div  = $('articleDescription');
	var div2 = $('commentsDiv');
	
	if(div) div.style.fontSize   = "12px";
	if(div2) div2.style.fontSize = "12px";
}

function increaseArticleFont()
{
	var div  = $('articleDescription');
	var div2 = $('commentsDiv');
	
	if(div && div.style.fontSize == "")
		div.style.fontSize = "12px";
	
	if(div2 && div2.style.fontSize == "")
		div2.style.fontSize = "12px";
	
	var size = parseInt(div.style.fontSize.replace("px",""));
	div.style.fontSize = (size + 1) + "px";
	div2.style.fontSize = (size + 1) + "px";
}

function decreaseArticleFont()
{
	var div = $('articleDescription');
	var div2 = $('commentsDiv');
	
	if(div.style.fontSize == "")
		div.style.fontSize = "12px";
	
	if(div2.style.fontSize == "")
		div2.style.fontSize = "12px";
		
	var size = parseInt(div.style.fontSize.replace("px",""));
	div.style.fontSize = (size - 1) + "px";
	div2.style.fontSize = (size - 1) + "px";
}

function showPic()
{
	//$('li_pic').className 	  = 'border_right';
	//$('li_video').className   = '';
	
	$('link_pic').className   = 'actve';
	$('link_video').className = '';
	
	$('div_pic').show();
	$('div_video').hide();
}

function showVideo()
{
	//$('li_pic').className 	  = 'border_right';
	//$('li_video').className   = '';
	
	$('link_pic').className   = '';
	$('link_video').className = 'actve';
	
	$('div_pic').hide();
	$('div_video').show();
}

function showWeather()
{
	$('li_weather').className = 'border_left';
	$('li_fixing').className  = '';
	
	$('link_weather').className = 'actve';
	$('link_fixing').className  = '';
	
	$('div_weather').show();
	$('div_fixing').hide();
}

function showFixing()
{
	$('li_weather').className = '';
	$('li_fixing').className  = 'border_right';
	
	$('link_weather').className = '';
	$('link_fixing').className  = 'actve';
	
	$('div_weather').hide();
	$('div_fixing').show();
}

function showArticleComments(tab)
{
	$('commentsDiv').show();		$('addCommentDiv').show();		$('relatedTD').hide();
	$('articleDiv').hide();
	$('galleryDiv').hide();
	$('videosDiv').hide();
	$('article_lnk').className = "";
	$('gallery_lnk').className = "";
	$('video_lnk').className   = "";
	$('comment_lnk').className = "selected";
	
	if (tab != null && tab != '') {
		location.hash = tab;
	} else {
		location.hash = '#comments';
	}

}

function showPhotoComments(tab){	$('commentsDiv').show();	$('comment_lnk').className = "selected";		$('articleDiv').hide();	$('article_lnk').className = "";		if (tab != null && tab != '') {location.hash = tab;} else {location.hash = '#photo_comments';};}

function showArticleGallery()
{
	$('commentsDiv').hide();		$('addCommentDiv').hide();		$('relatedTD').hide();
	$('articleDiv').hide();
	$('galleryDiv').show();
	$('videosDiv').hide();
	$('article_lnk').className = "";
	$('comment_lnk').className = "";
	$('video_lnk').className   = "";
	$('gallery_lnk').className  = "selected";
	
	location.hash = '#gallery';
}


function showArticleDetails()
{
	$('commentsDiv').hide();		$('addCommentDiv').show();		$('relatedTD').show();
	$('articleDiv').show();
	$('galleryDiv').hide();
	$('videosDiv').hide();
	$('article_lnk').className = "selected";
	$('comment_lnk').className = "";
	$('gallery_lnk').className = "";
	$('video_lnk').className   = "";

	location.hash = '#article_overview';
}function showPhotoDetails(){	$('commentsDiv').hide();	$('articleDiv').show();	$('comment_lnk').className = "";	$('article_lnk').className = "selected";	location.hash = '#photo_overview';}

function showArticleVideos()
{
	$('articleDiv').hide();		$('addCommentDiv').hide();		$('relatedTD').hide();
	$('galleryDiv').hide();
	$('commentsDiv').hide();
	$('videosDiv').show();
	$('video_lnk').className   = "selected";
	$('comment_lnk').className = "";
	$('gallery_lnk').className = "";
	$('article_lnk').className = "";
	
	location.hash = '#video';
}


function initAboutDestinationTabs(ad, ev, ss)
{
	var noToShow = true;
	
	if(!ad)
	{
		$('aboutDestinationLink').hide();	
	}
	else
	{
		showAboutDestination();
		noToShow = false;
	}
	
	if(!ev)
	{
		$('showEventsLink').hide();	
	}
	else if(noToShow)
	{
		showEvents();
		noToShow = false;
	}
	
	if(!ss)
	{
		$('showSightsLink').hide();	
	}
	else if(noToShow)
	{
		showSights();
		noToShow = false;
	}
}

function showAboutDestination()
{
	$('showSightsDiv').hide();
	$('showEventsDiv').hide();
	$('aboutDestinationDiv').show();
	
	$('showSightsLink').className = "";
	$('showEventsLink').className = "";
	$('aboutDestinationLink').className = "select_g";
}

function showSights()
{
	$('showSightsDiv').show();
	$('showEventsDiv').hide();
	$('aboutDestinationDiv').hide();
	
	$('showSightsLink').className = "select_g";
	$('showEventsLink').className = "";
	$('aboutDestinationLink').className = "";
}

function showEvents()
{
	$('showSightsDiv').hide();
	$('showEventsDiv').show();
	$('aboutDestinationDiv').hide();
	
	$('showSightsLink').className = "";
	$('showEventsLink').className = "select_g";
	$('aboutDestinationLink').className = "";
}


function openDetailedSearch()
{
	$('det_search').show();
	$('link_det_search').hide();
	$('link_srt_search').show();
}

function openShortSearch()
{
	$('det_search').hide();
	$('link_det_search').show();
	$('link_srt_search').hide();
}

function iWasThere()
{
	$('i_was_there_link').className   = 'selected_was_here';
	$('i_want_go_link').className 	  = '';
	$('my_favourites_link').className = '';
	
	$('i_was_there_div').show();
	$('i_want_go_div').hide();
	$('my_favourites_div').hide();
}

function iWantGo()
{
	$('i_was_there_link').className   = '';
	$('i_want_go_link').className 	  = 'selected_was_here';
	$('my_favourites_link').className = '';
	
	$('i_was_there_div').hide();
	$('i_want_go_div').show();
	$('my_favourites_div').hide();
}

function myFavourites()
{
	$('i_was_there_link').className   = '';
	$('i_want_go_link').className 	  = '';
	$('my_favourites_link').className = 'selected_was_here';
	
	$('i_was_there_div').hide();
	$('i_want_go_div').hide();
	$('my_favourites_div').show();
}

function showPublicProfile()
{
	$('public_profile_link').className = 'selected_tab';
	$('edit_profile_link').className   = '';	
	
	$('public_profile_div').show();
	$('edit_profile_div').hide();	
}

function showEditProfile()
{
	$('public_profile_link').className = '';
	$('edit_profile_link').className   = 'selected_tab';	
	
	$('public_profile_div').hide();
	$('edit_profile_div').show();
}function showProfileCompetition(competitionId, countCompetitions){	$('link_competition'+competitionId).className = 'selected_tab';	$('div_competition'+competitionId).show();	for (var i=1; i<=countCompetitions; i++){		if (i != competitionId) {			$('link_competition'+i).className = '';			$('div_competition'+i).hide();		}	}}

function showLatestPosts()
{
	$('latest_posts_div').show();
	//$('latest_gallery_div').hide();
	$('latest_video_div').hide();
	
	$('latest_posts_link').className = "select_g";
	//$('latest_gallery_link').className = "";
	$('latest_video_link').className = "";
}



function showLatestVideo()
{
	$('latest_posts_div').hide();
	//$('latest_gallery_div').hide();
	$('latest_video_div').show();
	
	$('latest_posts_link').className = "";
	//$('latest_gallery_link').className = "";
	$('latest_video_link').className = "select_g";
}

function showLatestGallery()
{
	$('latest_gallery_div').show();
	$('latest_blog_gallery_div').hide();
	
	$('latest_blog_gallery_link').className = "";
	$('latest_gallery_link').className = "select_g";
}

function showLatestBlogGallery()
{
	$('latest_gallery_div').hide();
	$('latest_blog_gallery_div').show();
	
	$('latest_blog_gallery_link').className = "select_g";
	$('latest_gallery_link').className = "";
}


function dotm_main_info()
{
	$('dotm_main_info_lnk').className = 'select_o';
	$('dotm_galleries_lnk').className = '';	
	$('dotm_previous_lnk').className = '';	
	$('dotm_blog_posts_lnk').className = '';	
	$('dotm_videos_lnk').className = '';	
	
	$('dotm_main_info_div').show();
	$('dotm_galleries_div').hide();
	$('dotm_previous_div').hide();
	$('dotm_blog_posts_div').hide();
	$('dotm_videos_div').hide();
}

function dotm_galleries()
{
	$('dotm_main_info_lnk').className = '';
	$('dotm_galleries_lnk').className = 'select_o';	
	$('dotm_previous_lnk').className = '';	
	$('dotm_blog_posts_lnk').className = '';	
	$('dotm_videos_lnk').className = '';	
	
	$('dotm_main_info_div').hide();
	$('dotm_galleries_div').show();
	$('dotm_previous_div').hide();
	$('dotm_blog_posts_div').hide();
	$('dotm_videos_div').hide();
}

function dotm_previous()
{
	$('dotm_main_info_lnk').className = '';
	$('dotm_galleries_lnk').className = '';	
	$('dotm_previous_lnk').className = 'select_o';	
	$('dotm_blog_posts_lnk').className = '';	
	$('dotm_videos_lnk').className = '';	
	
	$('dotm_main_info_div').hide();
	$('dotm_galleries_div').hide();
	$('dotm_previous_div').show();
	$('dotm_blog_posts_div').hide();
	$('dotm_videos_div').hide();
}

function dotm_blog_posts()
{
	$('dotm_main_info_lnk').className = '';
	$('dotm_galleries_lnk').className = '';	
	$('dotm_previous_lnk').className = '';	
	$('dotm_blog_posts_lnk').className = 'select_o';	
	$('dotm_videos_lnk').className = '';	
	
	$('dotm_main_info_div').hide();
	$('dotm_galleries_div').hide();
	$('dotm_previous_div').hide();
	$('dotm_blog_posts_div').show();
	$('dotm_videos_div').hide();
}

function dotm_videos()
{
	$('dotm_main_info_lnk').className = '';
	$('dotm_galleries_lnk').className = '';	
	$('dotm_previous_lnk').className = '';	
	$('dotm_blog_posts_lnk').className = '';	
	$('dotm_videos_lnk').className = 'select_o';	
	
	$('dotm_main_info_div').hide();
	$('dotm_galleries_div').hide();
	$('dotm_previous_div').hide();
	$('dotm_blog_posts_div').hide();
	$('dotm_videos_div').show();
}

function openArticleTab()
{
	var tab = location.hash;
	if(tab == '#gallery')
	{
		showArticleGallery();
	}
	else if(tab == '#video')
	{
		showArticleVideos();
	}
	else if(tab == '#article_overview')
	{
		showArticleDetails();
	}
	else if(tab.match(/^#comments/i))
	{
		showArticleComments(tab);
	}		else if(tab == '#photo_overview')	{		showPhotoDetails();	}	else if(tab.match(/#photo_comments/i))	{		showPhotoComments(tab);	}
}

function dotm_long_info()
{
	$('short').hide(); 
	$('long').show();
}

function dotm_short_info()
{
	$('short').show(); 
	$('long').hide();
}

function openCalendar(inp)
{
	displayCalendar(inp, "dd.mm.yyyy", inp);
}

function arrangePhotos()
{
	Sortable.create('picUL',
						{
							overlap:'horizontal',
							constraint: false,
							hoverclass:'overArrangePhotos'
						}
					);
}

function saveOrderPhotos()
{
	var data = Sortable.serialize("picUL");
	$('data').value = data;
}

function clickDeletePhotos(li)
{
	if(li.className == 'gallery_table') li.className = 'delete_selected';
	else								li.className = 'gallery_table';
	
}

function serializeDeletedPhotos()
{
	var delLI = $("picUL").getElementsByClassName('delete_selected');
	var sText = "";
	
	for(var i=0; i<delLI.length; i++)
	{
		sText += 'picUL[]=' + (delLI[i].id).substring(4) + '&';
	}
	$('data').value = sText;
}

function saveEverybodyComments(everybody_comments, uid)
{
	new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'saveEverybodyComments',
							everybody_comments: everybody_comments,
							uid: uid
						}, 
						onComplete: function (result) { s_alert(result.responseText); }
					 }
					);	
}

function deleteComment(id)
{
	new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'deleteComment',
							id: id
						}, 
						onComplete: function (result) { if(result.responseText == "done") $('comment_' + id).remove();}
					 }
					);
}

function deletePhotoComment(id)
{
	new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'deletePhotoComment',
							id: id
						}, 
						onComplete: function (result) { if(result.responseText == "done") $('comment_' + id).remove();}
					 }
					);
}

function deleteTravelNotesComment(id)
{
	new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'deleteTravelNotesComment',
							id: id
						}, 
						onComplete: function (result) { if(result.responseText == "done") $('comment_' + id).remove();}
					 }
					);
}

function makeEditableComment(id, lang)
{
	new Ajax.InPlaceEditor('c_text_' + id, file + '?el=text' + lang + '&func=editComment&id=' + id, 
						   		{
									formClassName:'formEdit',
									highlightcolor: '#eeeeee',
									hoverClassName: 'overEdit',
									clickToEditText: 'Редактирай',
									rows:10
								}
						   );	
	
	new Ajax.InPlaceEditor('c_title_' + id, file + '?el=title' + lang + '&func=editComment&id=' + id, 
						   		{
									formClassName:'formEdit',
									highlightcolor: '#eeeeee',
									hoverClassName: 'overEdit',
									clickToEditText: 'Редактирай'
								}
						   );	
}

function makeEditablePhotoComment(id)
{
	new Ajax.InPlaceEditor('c_comment_' + id, file + '?el=comment&func=editPhotoComment&id=' + id, 
						   		{
									formClassName:'formEdit',
									highlightcolor: '#eeeeee',
									hoverClassName: 'overEdit',
									clickToEditText: 'Редактирай',
									rows:10
								}
						   );	
	
	new Ajax.InPlaceEditor('c_title_' + id, file + '?el=title&func=editPhotoComment&id=' + id, 
						   		{
									formClassName:'formEdit',
									highlightcolor: '#eeeeee',
									hoverClassName: 'overEdit',
									clickToEditText: 'Редактирай'
								}
						   );	
}

function makeEditableTravelNotesComment(id)
{
	new Ajax.InPlaceEditor('c_comment_' + id, file + '?el=comment&func=editTravelNotesComment&id=' + id, 
						   		{
									formClassName:'formEdit',
									highlightcolor: '#eeeeee',
									hoverClassName: 'overEdit',
									clickToEditText: 'Редактирай',
									rows:10
								}
						   );	
	
	new Ajax.InPlaceEditor('c_title_' + id, file + '?el=title&func=editTravelNotesComment&id=' + id, 
						   		{
									formClassName:'formEdit',
									highlightcolor: '#eeeeee',
									hoverClassName: 'overEdit',
									clickToEditText: 'Редактирай'
								}
						   );	
}

function rate(rate, article_id, uid)
{
	new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							json		: true,
							func		: 'rateArticle',
							rate		: rate,
							article_id	: article_id,
							uid			: uid
						}, 
						onComplete: function (result) 
						{ 
							var res = eval('(' + result.responseText + ')');
							
							if(res.rate != 0) $('curent_rating').style.width = res.rate + 'px';
							s_alert(res.msg);
							$('rateContainer').hide();
						}
					 }
					);	
}

function ratePhoto(rate, photo_id, user_id) {

	new Ajax.Request(file, 
					 { parameters: 
					 	{
							func		: 'ratePhoto',
							rate		: rate,
							photo_id	: photo_id
						}, 

						onComplete: function (result) {
							if (!user_id) {
								var cookieValue = '';
								if (Get_Cookie('photo_vote')) {
									cookieValue = Get_Cookie('photo_vote') + '/';
								}
								cookieValue += photo_id+'-'+rate;
								Set_Cookie('photo_vote', cookieValue, '365', '/', '', '');
							}
							location.reload();
						}
					 }
					);
}

function rateTravelNotes(rate, travelnotes_id, user_id) {

	new Ajax.Request(file, 
					 { parameters: 
					 	{
							func		: 'rateTravelNotes',
							rate		: rate,
							travelnotes_id	: travelnotes_id
						}, 

						onComplete: function (result) {
							if (!user_id) {
								var cookieValue = '';
								if (Get_Cookie('travelnotes_vote')) {
									cookieValue = Get_Cookie('travelnotes_vote') + '/';
								}
								cookieValue += travelnotes_id+'-'+rate;
								Set_Cookie('travelnotes_vote', cookieValue, '365', '/', '', '');
							}
							location.reload();
						}
					 }
					);
}

function initAjaxIndicator()
{
	Ajax.Responders.register(
	{
  		onCreate: function() 
  		{
    		$('indicator').show();
  		},
  		onComplete: function() 
  		{
    		$('indicator').hide();
  		}
	});
}

function validateAddComment(user_logged)
{
	if(!user_logged)
	{
		//alert('Трябва да сте регистриран за да добавяте коментари!');
		return false;	
	}
	
	if($F('name') == "")	
	{
		alert('Не сте въвели Име');
		$('name').focus();
		return false;
	}
	
	if($F('email') == "")	
	{
		alert('Не сте въвели Email');
		$('email').focus();
		return false;
	}
	
	var Exp1=/^[a-zA-Z0-9\._-]+@+[a-zA-Z0-9\._-]+\.+[a-zA-Z]{2,4}$/;
	if(!(Exp1.exec($F('email'))))
	{
		alert('Моля въведете валиден Email!');
        $('email').focus();
		return false;
	}
	
	if($F('text') == "")	
	{
		alert('Не сте въвели Съдържание на коментара');
		$('text').focus();
		return false;
	}
	
	return true;
}

function validateCompetitionComment()
{	
	if($F('comment') == "")	{
		alert('Не сте въвели съдържание на коментара');
		$('comment').focus();
		return false;
	}
	
	if($F('name') == "") {
		alert('Не сте въвели име');
		$('name').focus();
		return false;
	}

	if($F('email') == "") {
		alert('Не сте въвели email');
		$('email').focus();
		return false;
	}
	
	var Exp1=/^[a-zA-Z0-9\._-]+@+[a-zA-Z0-9\._-]+\.+[a-zA-Z]{2,4}$/;

	if(!(Exp1.exec($F('email')))) {
		alert('Моля въведете валиден email!');
        $('email').focus();
		return false;
	}

	return true;

}

function canRateArticle()
{
	if(!arguments[0])
	{
		if(arguments[1])
		{
			s_alert(arguments[1]);
		}
		else
		{
			s_alert('Регистрирай се!');
		}
		return false;	
	}
}
var current_leading = 1;var num_leading = 3; 
function slide(div, px)
{
	var tbl = $(div);
	
	
	if(tbl.hiddenWidth == null)
	{
		tbl.hiddenWidth = (tbl.getWidth() - (tbl.parentNode).getWidth());
		//alert(tbl.hiddenWidth);
	}
	
	if(tbl.posProperty == null)
	{
		tbl.posProperty = tbl.hiddenWidth;
		//alert(tbl.posProperty);
	}
	
	
	if(tbl.posProperty>=0 && tbl.posProperty<=tbl.hiddenWidth)
	{
		var toMove = null;
		var newPos = null;
		
		if((tbl.posProperty + px) < 0)
		{
			toMove = -tbl.posProperty;
			newPos = 0;
		}
		else if((tbl.posProperty + px) > tbl.hiddenWidth)
		{
			toMove = tbl.hiddenWidth - tbl.posProperty;
			newPos = tbl.hiddenWidth;	
		}
		else
		{
			toMove = px;
			newPos = tbl.posProperty + px;		
		}
		
		new Effect.Move (div, 
					 { 
					 	x     : toMove, 
						y     : 0, 
						mode  : 'relative',
						queue : {position:'front', scope:'one', limit:1},
						afterFinish : function () { tbl.posProperty = newPos; }
					 }
					 );
	}
}

function makeFlashPlayer(playerFile, file)
{
	var s1 = new SWFObject(playerFile, 'single', '670', '480', '7');
	s1.addParam("allowfullscreen", "true");
	s1.addVariable('file', file);
	s1.addVariable('width','670');
	s1.addVariable('height','480');
	s1.addParam("wmode", "transparent");
	s1.write('player1');	
}


function validateSubscribe()
{
	var Exp1=/^[a-zA-Z0-9\._-]+@+[a-zA-Z0-9\._-]+\.+[a-zA-Z]{2,4}$/;
	
	if($('name').disabled)
	{
		error(11);	
		return false;
	}
	
	if($F('name') == "")	
	{
		error(3);
		$('name').focus();
		return false;
	}
	
	if($F('pass') == "")	
	{
		error(5);
		$('pass').focus();
		return false;
	}
	
	if($F('re_pass') == "")	
	{
		error(6);
		$('re_pass').focus();
		return false;
	}
	
	if($F('re_pass') != $F('pass'))	
	{
		error(7);
		return false;
	}
	
	if($('mail').disabled)
	{
		error(12);	
		return false;
	}
	
	if($F('mail') == "")	
	{
		error(4);
		$('mail').focus();
		return false;
	}
	
	
	if(!(Exp1.exec($F('mail'))))
	{
		error(10);
		$('mail').focus();
		return false;
	}
	
	if($('code').disabled)
	{
		error(8);	
		return false;
	}
	
	if($F('code') == "")	
	{
		error(9);
		$('code').focus();
		return false;
	}
	
	if(!$('disclimer').checked)
	{
		error(13);
		$('disclimer').focus();
		return false;
	}
	
	return true;
}

function mailCheck()
{
	if($F('mail') != '')
	{
	  $('mail').disabled = true;
	  new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'mailCheck',
							mail: $F('mail')
						}, 
						onComplete: function (result) {
							$('mail').disabled = false;
							if (result.responseText != "done" ) {
								$('mail').focus();
								$('mail').value = '';
								$('mailError').innerHTML = 'Мейлът се използва!';
								error(2);
							} else {
								$('mailError').innerHTML = '';
							}
						}
					 }
					);
	}
}

function codeCheck()
{
	if($F('code') != '')
	{
	  $('code').disabled = true;
	  new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'codeCheck',
							code: $F('code')
						}, 
						onComplete: function (result) {
							$('code').disabled = false;
							if(result.responseText != "done") {
								$('code').focus();
								$('code').value = '';
								$('codeError').innerHTML = 'Грешен код!';
								error(1);
							} else {
								$('codeError').innerHTML = '';
							}
						}
					 }
					);
	}
}

function nameCheck()
{
	if($F('name') != '')
	{
	  $('name').disabled = true;
	  new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'nameCheck',
							name: $F('name')
						}, 
						onComplete: function (result) {
							$('name').disabled = false;
							if(result.responseText != "done") {
								$('name').focus();
								$('name').value = '';
								$('nameError').innerHTML = 'Името е заето!';
								error(0);
							} else {
								$('nameError').innerHTML = '';
							}
						}
					 }
					);
	}
}

function addUserRelation(id, table)
{
	new Ajax.Request(file, 
	{ 
		parameters: 
		{ 
			func	: 'addUserRelation',
			id		: id,
			table	: table
		}, 
		onComplete: function (result) { 
			s_alert(result.responseText);
		}
	}
	);
}

function removeUserRelation(id, table, lnk)
{
  var li = lnk.parentNode;
  if(li && confirm("Наистина ли искате да изтриете тоз запис?"))
  {
	new Ajax.Request(file, 
	{ 
		parameters: 
		{ 
			func	: 'removeUserRelation',
			id		: id,
			table	: table
		}, 
		onComplete: function (result) 
		{ 
			li.remove();
			alert(result.responseText);
		}
	}
	);
  }
}

function error(num)
{
	if(lang == 'en')
	{
		showErrorMsg( errCodes_en[num].title, errCodes_en[num].content );
	}
	else
	{
		showErrorMsg( errCodes[num].title, errCodes[num].content );
	}
	setTimeout("hideMessages()", 4000);
}


function showErrorMsg() // call : errorMsg( title, content )
{
	var title   = "";
	var content = "";
	
	if(arguments[0]) var title   = arguments[0];
	if(arguments[1]) var content = arguments[1];
	
	$('errTitle').innerHTML   = title;
	$('errContent').innerHTML = content;
	
	new Effect.Appear('errMsg');
}

function hideErrorMsg() // call : errorMsg( title, content )
{
	new Effect.DropOut('errMsg');
}

function showLoginForm()
{
	$('buttonsDiv').hide();
	$('sigInForm').show();
}

function clearField(el, txt)
{
	if(el.value == txt)
	{
		el.value = "";
	}
}


function noteField(el, txt)
{
	if(el.value == "")
	{
		el.value = txt;
	}
}


function hideMessages()
{
	var msgA = document.getElementsByClassName('okmsg');
	for (var i=0; i<msgA.length; i++){
		var div = msgA[i];
		
		new Effect.DropOut(div);	
	}
	
	var msgA = document.getElementsByClassName('errormsg');
	for (var i=0; i<msgA.length; i++){
		var div = msgA[i];
		
		new Effect.DropOut(div);	
	}
}	

function Get_Cookie( check_name )
{
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	
	for ( i = 0; i < a_all_cookies.length; i++ ) {
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )	{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	
	if ( !b_cookie_found )	{
		return null;
	}}
	
function Set_Cookie( name, value, expires, path, domain, secure )
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +( ( path ) ? ";path=" + path : "" ) +( ( domain ) ? ";domain=" + domain : "" ) +( ( secure ) ? ";secure" : "" );
}

function showRate(id, userRating)
{
	var photo = '';
	var rate = '';
	var rating = 0;
	var havePhoto = false;
	
	if (Get_Cookie('photo_vote')) {
		var values = Get_Cookie('photo_vote').split( '/' );
		for ( i = 0; i < values.length; i++ ) {
			var photoCookie = values[i].split('-');
			photo = photoCookie[0];
			rate = photoCookie[1];
			if (photo == id) {
				havePhoto = true;
				break;
			}
		}
	}
	
	if (havePhoto || userRating > 0) {
		$('ratedPhotoText').show();
		$('ratedPhotoStars').show();
		if (userRating > 0) {
			rating = userRating;
		} else {
			if (havePhoto) {
				rating = rate;
			}
		}
		$('curent_rating').style.width = (rating*2 + 1)*3 + rating*16 + 'px';
	} else {
		$('ratePhotoText').show();
		$('ratePhotoStars').show();
	}
}

function showTravelNotesRate(id, userRating)
{
	var travelnotes = '';
	var rate = '';
	var rating = 0;
	var haveTravelnotes = false;
	
	if (Get_Cookie('travelnotes_vote')) {
		var values = Get_Cookie('travelnotes_vote').split( '/' );
		for ( i = 0; i < values.length; i++ ) {
			var travelnotesCookie = values[i].split('-');
			travelnotes = travelnotesCookie[0];
			rate = travelnotesCookie[1];
			if (travelnotes == id) {
				haveTravelnotes = true;
				break;
			}
		}
	}
	
	if (haveTravelnotes || userRating > 0) {
		$('ratedTravelNotesText').show();
		$('ratedTravelNotesStars').show();
		if (userRating > 0) {
			rating = userRating;
		} else {
			if (haveTravelnotes) {
				rating = rate;
			}
		}
		$('curent_rating').style.width = (rating*2 + 1)*3 + rating*16 + 'px';
	} else {
		$('rateTravelNotesText').show();
		$('rateTravelNotesStars').show();
	}
}

Event.observe(window, 'load', function () {setTimeout("hideMessages()", 4000);}, false);

function setNumberLeading(num)
{
	num_leading = num;
}

function setLeadingLink(dir)
{
	var increased = current_leading + dir;
	if(increased<=num_leading && increased>0) {
		current_leading = increased; setLinkClass();
	}
}

function setLinkClass()
{
	var links = $('leadingPaging').getElementsByTagName("a");
	if(links[current_leading-1]) {
		for(var i=0; i<links.length; i++) {
			links[i].className = "";
		}
		links[current_leading-1].className = "active_p";
	}
}

function linkLeading(num)
{
	var px = (current_leading - num)*678;
	current_leading = num;
	slide('leadingContainer', px);
	setLinkClass();
}

function showProfileTravelnotes(competitionId, countCompetitions)

{

	$('link_travel'+competitionId).className = 'selected_tab';
	$('div_travel'+competitionId).show();

	for (var i=1; i<=countCompetitions; i++){
		if (i != competitionId) {
			$('link_travel'+i).className = '';
			$('div_travel'+i).hide();
		}
	}

}