/*** Functions ***/

function removeValue(node, value)
{
	// Set internal globals
	var node = node;
	var value = value;

	if(node.value == value)
	{
		node.value = '';
	}

	node.onblur = function()
	{
		if(node.value == '')
		{
			node.value = value;
		}
	}
}

function checkboxes(parameters)
{	LoadContent._page=0;
	if(parameters.uncheckAll)
	{
		var checks = parameters.uncheckAll.getElementsByTagName('LI');

		for(i in checks)
		{
			if(checks[i].className)
			{
				checks[i].className = '';
			}
		}
	}

	if(parameters.check)
	{
		parameters.check.parentNode.className = 'active private';
	}

	if(parameters.checkUn)
	{
		parameters.checkUn.parentNode.className = parameters.checkUn.parentNode.className == 'active private' ? '' : 'active private';
	}

	if(parameters.uncheck)
	{
		parameters.checkUn.parentNode.className = parameters.checkUn.parentNode.className == 'active private' ? '' : 'active private';
	}

	if(parameters.uncheckFirst)
	{
		parameters.uncheckFirst.getElementsByTagName('LI')[0].className = '';
	}
}

function radioButtons(parameters){
	LoadContent._page=0;
	var checks = parameters.uncheckAll.getElementsByTagName('LI');

	for(i in checks){
		if(checks[i].className){
			checks[i].className = '';
		}
	}
	if(parameters.check)
	{
		parameters.check.parentNode.className = 'active private';
	}

}

function changeFontSize(nodePlus, nodeMinus)
{
	this.changeNode = $('content-inner');
	this.nodePlus = nodePlus;
	this.nodeMinus = nodeMinus;

	if(!this.nodePlus || !this.nodeMinus || !this.changeNode)
	{
		return false;
	}

	this.size = {
		0: .9,
		1: 1,
		2: 1.1
	};
	this.currentStep = 1;

	this.changeFont = function(node, action) {
		if(action == 'plus' && this.size[this.currentStep + 1])
		{
			this.currentStep++;
			this.changeNode.style.fontSize = this.size[this.currentStep] + 'em';
		}
		else if(action == 'minus' && this.size[this.currentStep - 1])
		{
			this.currentStep--;
			this.changeNode.style.fontSize = this.size[this.currentStep] + 'em';
		}
		return false;
	}

	this.nodePlus.each(function(node) {
		node.onclick = this.changeFont.bind(this, node, 'plus');
	}.bind(this));

	this.nodeMinus.each(function(node) {
		node.onclick = this.changeFont.bind(this, node, 'minus');
	}.bind(this));
}

function d(string)
{
	if(window.console && window.console.log)
	{
		console.log(string);
	}
	else
	{
		var debugElement = document.getElementById('site_debug');

		if(!debugElement)
		{
			var debugElement = document.createElement('DIV');
			debugElement.id = 'site_debug';
			document.body.appendChild(debugElement);
		}

		debugElement.innerHTML = '<div style="padding: 2px; border-bottom: 1px solid #D7D7D7; background: #FFFFFF; color: #000088">' + string + '</div>' + debugElement.innerHTML;
	}
}

/*** Behaviour ***/

if(Prototype.Browser.IE)
{
	IEversion = parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE") + 5));
	Prototype.Browser.IE6 = (IEversion == 6) ? true : false;
	Prototype.Browser.IE7 = (IEversion == 7) ? true : false;
}

Event.observe(window, 'load', function() {
	// Font size changer
	new changeFontSize($$('.page_tools .font_plus'), $$('.page_tools .font_minus'));

	$$('.text_field').each(function(node){
		Element.insert(node, {bottom: '<span></span>'})
	});

	$$(".show_send_to_friend").each(function(elem){
		elem.observe('click', function(){
			$('send-to-friend').appear();
		});
	});
	if($('close-send-to-friend')){
		$('close-send-to-friend').observe('click', function(){
			$('send-to-friend').fade();
		});
	}

	if($('submit_send_to_friend')){
		$('submit_send_to_friend').observe('click', function(){
			var err = 0;
			$F('your_name') == '' ? err = 1 : '';
			$F('your_email') == '' ? err = 1 : '';
			$F('his_name') == '' ? err = 1 : '';
			$F('his_email') == '' ? err = 1 : '';
			$F('message') == '' ? err = 1 : '';
			if(err == 1){
				alert(lng_error_fill_all);
			}else{
				console.log(stf_url);
				new Ajax.Request(stf_url,
				{
					method: 'post',
					parameters: {
									your_name: $F('your_name'),
									your_email: $F('your_email'),
									his_name: $F('his_name'),
									his_email: $F('his_email'),
									message: $F('message'),
									url: window.location.href
								},
					onSuccess: function(transport){
						if(transport.responseText == 'OK')
							alert("Success!");
//							$('send-to-friend').setStyle({display: 'none'});
						else{
							alert("Something went wrong! \n"+transport.responseText);
						}
					}

				});

			}
		});
	}
});