function ChangeImage(id, src)
{
	var img = document.getElementById(id);
	if(img)
	{
		img.src = src;
	}
}

function SetSymbolsLimit(area_id, str_id)
{
	var area = document.getElementById(area_id);
	var str = document.getElementById(str_id);
	var limit = 1024;
	var cnt = limit - area.value.length;
	
	if(area && str)
	{
		if(area.value.length > limit)
	 	{
	   		area.value = area.value.substr(0, limit);
			return false;
	 	}
		str.innerHTML = cnt;
	}
}

function NewWindow(url) {
	window.open(url, 'win');
	return false;
}

function ShowAllServices(show)
{
	var menu = document.getElementById('all-services-menu');
	var link_hide = document.getElementById('hide-all');
	var link_show = document.getElementById('show-all');
	if(menu)
	{
		if(show)
		{
			menu.className = 'all hide';
			link_hide.style.display = 'block';
			link_show.style.display = 'none';
		}
		else
		{
			menu.className = 'all show';
			link_hide.style.display = 'none';
			link_show.style.display = 'block';
		}
	}	
}

function InsertMediaPlayer(id, width, height, source)
{
	var container = document.getElementById(id);
	if(container)
	{
		var code = '<object width="' + width + '" height="' + height + '"  classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">';
		if(window.navigator.appName == 'Microsoft Internet Explorer')
		{
			code += '<param name="Filename" value="' + source + '">';
			code += '<param name="AutoStart" value="True">';
			code += '<param name="ShowControls" value="True">';
			code += '<param name="ShowStatusBar" value="False">';
			code += '<param name="ShowDisplay" value="False">';
			code += '<param name="AutoRewind" value="True">';
		}
		else
		{
			code += '<embed type="application/x-mplayer2" ';
			code += 'pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" ';
			code += 'width="' + width + '" ';
			code += 'height="' + height + '" ';
			code += 'src="' + source + '" ';
			code += 'filename="' + source + '" ';
			code += 'autostart="True" ';
			code += 'showcontrols="True" ';
			code += 'showstatusbar="False" ';
			code += 'showdisplay="False" ';
			code += 'autorewind="True"> ';
			code += '</embed>';
		}
		code += '</object>';
		
		container.innerHTML = code;
	}
}

function PopupWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function CheckMail()
{
	var img = document.getElementById('icon-mail');
	if(img)
	{
		$.ajax({
			url: 'http://val.ua/check_mail.php',
		  	cache: false,
		  	success: function(response){
		    	if(response != '' && response != '0'){
					img.src = '/public/images/new-mail.gif';
				}
			}
		});
	}
}

function ClearInput(id, def_value)
{
	var input = document.getElementById(id);
	if(input)
	{
		if(input.value == def_value)
		{
			input.value = '';
		}
	}
}

function PhotoPopup(id, offset) 
{
	window.open('/photo.html?id='+id+'&offset='+offset, '', 'width=587,height=750,top=0,resizable=1');
}

function AddComment(input_id, parent_id, citation)
{
	var textarea = document.getElementById('comment');
	var author = document.getElementById('author'+parent_id);
	var comment = document.getElementById('comment'+parent_id);
	
	var replacement = new Array({'search': '<DIV class=citation>', 'repl': '[QUOTE]'}, 
								{'search': '<div class="citation">', 'repl': '[QUOTE]'},
								{'search': '<DIV class="citation">', 'repl': '[QUOTE]'},
								{'search': '</DIV>', 'repl': '[/QUOTE]'},
								{'search': '</div>', 'repl': '[/QUOTE]'},
								{'search': '<SPAN class=username>', 'repl': '[B]'},
								{'search': '<span class="username">', 'repl': '[B]'},
								{'search': '<SPAN class="username">', 'repl': '[B]'},
								{'search': '</SPAN>', 'repl': '[/B]'},
								{'search': '</span>', 'repl': '[/B]'});
	
	if(citation)
	{
		var text = comment.innerHTML;
		
		for(var i = 0; i < replacement.length; i++)
		{
			while(text.indexOf(replacement[i].search) != -1)
			{
				text = text.replace(replacement[i].search, replacement[i].repl);
			}
		}
		
		textarea.value += '[QUOTE]' + '[B]' + author.innerHTML + '[/B]' + '\n' + text + '[/QUOTE]' + '\n';
	}
	else
	{
		textarea.value += '[B]' + author.innerHTML + '[/B]' + '\n';
	}
	
	textarea.focus();
}

window.onload = function(){
	CheckMail();
}