function formURL()
{
new Ajax.Request('/admin/ajaxURL',
  {
    method:'post',
	parameters: { text: $('title_h1').value.toLowerCase() },
    onSuccess: function(transport){
      var response = transport.responseText || "title_h1";
      $('url').value=response.toLowerCase();
    },
    onFailure: function(){ alert('Something went wrong with ajax...') }
  });
}

function check_contacts_form() {
	if(!check_is_empty(document.getElementById('message_text')) || !check_email(document.getElementById('customer_email')))
		{
			if(!check_email(document.getElementById('customer_email')) || !check_is_empty(document.getElementById('message_text')))
			return false;
		}
	else
		return true;	
}

function check_email(email)
{
	var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]", 'i');
	if (!reg.test(email.value)) {
		document.getElementById('email_error').style.display = 'block';
		return false;
	}
	else{
		document.getElementById('email_error').style.display = 'none';
		return true;
	}
}

function check_is_empty(field)
{
	if (field.value=='') {
		document.getElementById('text_error').style.display = 'block';
		return false;
	}
	else{
		document.getElementById('text_error').style.display = 'none';
		return true;
	}
}

// site

function open_window(link,w,h) //opens new window
{
	var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
	newWin = window.open(link,'newWin',win);
	newWin.focus();
}

function open_printable_version(link) //opens new window
{
	var win = "menubar=no,location=no,resizable=yes,scrollbars=yes";
	newWin = window.open(link,'perintableWin',win);
	newWin.focus();
}

function confirmDelete(id, ask, url) //confirm order delete
{
	temp = window.confirm(ask);
	if (temp) //delete
	{
		window.location=url+id;
	}
}

function confirmUnsubscribe() //unsubscription confirmation
{
	temp = window.confirm('{/literal}{$smarty.const.QUESTION_UNSUBSCRIBE}{literal}');
	if (temp) //delete
	{
			window.location="index.php?killuser=yes";
	}
}

function validate() // newsletter subscription form validation
{
	if (document.subscription_form.email.value.length<1)
	{
		alert("{/literal}{$smarty.const.ERROR_INPUT_EMAIL}{literal}");
		return false;
	}
	if (document.subscription_form.email.value == 'Email')
	{
		alert("{/literal}{$smarty.const.ERROR_INPUT_EMAIL}{literal}");
		return false;
	}
	return true;
}

function validate_disc() // review form verification
{
	if (document.formD.nick.value.length<1)
	{
		alert("{/literal}{$smarty.const.ERROR_INPUT_NICKNAME}{literal}");
		return false;
	}
	if (document.formD.topic.value.length<1)
	{
		alert("{/literal}{$smarty.const.ERROR_INPUT_MESSAGE_SUBJECT}{literal}");
		return false;
	}
	return true;
}

function validate_search()
{
	if (document.Sform.price1.value!="" && ((document.Sform.price1.value < 0) || isNaN(document.Sform.price1.value)))
	{
		alert("{/literal}{$smarty.const.ERROR_INPUT_PRICE}{literal}");
		return false;
	}
	if (document.Sform.price2.value!="" && ((document.Sform.price2.value < 0) || isNaN(document.Sform.price2.value)))
	{
		alert("{/literal}{$smarty.const.ERROR_INPUT_PRICE}{literal}");
		return false;
	}
	return true;
}

function _formatPrice( _price )
{			
	_pointIndex = -1;	
	for( i=0; i< _price.length; i++ )
		if ( _price.charAt(i) == '.' )
		{
			_pointIndex = i;
			break;
		}
		if (_pointIndex == -1)
			_price = _price + ".00";
		else if (  _price.length-1 - _pointIndex == 1  )
			_price = _price + "0";

		_res = "";

		i=0;
		for( i=_price.length-1; i >= 0; i-- )
		{
			if ( _price.charAt(i) == '.' )
				break;
			else
				_res = _price.charAt(i) + _res;
		}

		_res = "." + _res;

		i--;
		_digitCounter = 0;
		for( ; i>=0; i-- )
		{
			_digitCounter ++;
			_res = _price.charAt(i) + _res;
			if ( _digitCounter == 3 && i != 0 )
			{
				_res = "," + _res;
				_digitCounter = 0;
			}
					
		}

		return _res;								
	}
