function checkCookie(name) {
	cookies = document.cookie.split(';');
	var ret = false;
	for (i = 0; i < cookies.length; i++) {
		cookie_ = cookies[i].split('=');
		if (cookie_[0].replace(/(^\s+)?(\s+$)?/, '') == name) {
			ret = true;
			break;
		}
	}
	return ret;
}

function ajaxSubmit(form, url) {
	if ($('activity_indicator') != null) $('activity_indicator').title = 'hidden';
	
	idx = '';
	if (arguments.length >= 4) idx = arguments[3];

	successAction = null;
	if (arguments.length >= 3) successAction = arguments[2];
	
	$('button' + idx).hide();
	$('loader' + idx).show();		
	
	new Ajax.Request(url, {
		parameters: Form.serialize($(form)),
		onComplete: function(t) {
			if ($('activity_indicator') != null) $('activity_indicator').title = '';
			
			$('button' + idx).show();
			$('loader' + idx).hide();
			//status = t.responseText; //.replace(/^\s+|\s+$/g, '');
			//alert(t.responseText);

			if (t.responseText == 'ok' && successAction != null) successAction();
			if (t.responseText != 'ok') alert(t.responseText);
		}
	});
}

function showNotify(str) {
	alert(str);
	/*
	$('notify_text').innerHTML = str;
	Element.setStyle('notify', {top: Math.round((screen.height / 2) - 150) + 'px'});
	Element.setStyle('notify', {left: Math.round((screen.width / 2) - 126) + 'px'});
	location.href = location.href.replace(/#+/, '') + '#';
	Element.setStyle('notify', {display: 'block'});
	new Effect.Highlight('notify', {duration: 3});
	setTimeout('hideNotify()', 4000);*/
}

function hideNotify() {
	if (Element.getStyle('notify', 'display') != 'none')
		new Effect.Fade('notify', {duration:0.5});
}

function preloadImages() {
	var imgs = new Array();
	for (var i = 0; i < arguments.length; i++) {
		imgs[i] = new Image();
		imgs[i].src = arguments[i];
	}
}

function returnEvent(evt) {
	e = (evt) ? evt : (window.event) ? event : null;

	if (e.keyCode) 
		code = e.keyCode;
	else
		if (e.which) 
			code = e.which;

	return code;
}

function nl_valid(msg_ok)
{
	if ($('nl_form_type').value=="coreg")
		url = "/index.php?obj=front&action=nl_coreg";
	else
		url = "/index.php?obj=front&action=nl";
	
	ajaxSubmit('form_nl', url, function() {

		if ($('nl_coreg')!= undefined && $('nl_coreg').checked==true)
		{
			new PopupDiv('/index.php?obj=front&action=nl_coreg&nl_coreg_id='+$('nl_coreg').value);
			return;
		}
		if ($('nl_meteo')!= undefined && $('nl_meteo').checked==true)
		{
			new PopupDiv('/index.php?obj=front&action=meteo_form');
			return;
		}
		else
		{
			alert(msg_ok);
			PopupDiv.hide();
			return;
		}
	})
}
