// PopUp
function popup(mypage, myname, w, h, resize, scrollable){

	var win_left = (screen.width - w) / 2;
	var win_top = (screen.height - h) / 2;
	
	winprops = 'width=' + w + ',height=' + h + ',left=' + win_left + ',top=' + win_top + ',resizable=' + resize + ',scrollbars=' + scrollable + ',statusbar=1,toolbar=0,location=0,menubar=0,directories=0';
	win = window.open(mypage,myname,winprops);
	
	if (parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}

}



/*
* trim function
*/
String.prototype.trim = function(){
	return this.replace(/^\s+|\s+$/, '');
};


/*
* preload image function
*/
Prototype.preloadImages = function(){
	for (var i=0, images=[]; src=arguments[i]; i++){
		images.push(new Image());
		images.last().src = src;
	}
};







function showE(element){
	$(element).show();
}

function hideE(element){
	if ($(element).style.display != "none") $(element).style.display = "none";
}

function showHideE(element){
	$(element).style.display = ($(element).style.display == "none") ? "block" : "none";
}



//var reloadnum = function(){
  //$('captcha').src = '/captcha.php?num=' + Math.ceil(100000 * Math.random());
//}





/*
* event observe
*/
Event.observe(window, 'load', function(){
	Prototype.preloadImages(
		'/theme/pix/box-02.gif',
		'/theme/pix/menu-over.png',
		'/theme/pix/menu-space.png',
		'/theme/pix/icon-disk.gif'
	);
});






/*
// ajax menu
function ajaxmenu(url){
	
	$('contentprogress').show();
	
  new Ajax.Request(url, {
  	method: 'get',
  	onSuccess: ajaxmenuSuccess,
  	onFailure: ajaxmenuFailure
  });
	
	return false;
}

function ajaxmenuSuccess(response){
	//if (response.status == 200) alert("Success: " + response.status);
	$('contentprogress').hide();
	var container = $('maincontent');
	var content = response.responseText;
	container.update(content);
}

function ajaxmenuFailure(response){
	//alert("Failure: " + response.status);
	container.update('<h1>Page not found!</h1>');
}
*/





/*
* Ajax menu
* 
* @param url string
* 
*/
function ajaxmenu(url){
	
	$('menuprogress').show();
	
	var myAjax = new Ajax.Updater('maincontent', url, {
		method: 'post',
		onComplete: function(){
			$('menuprogress').hide();
		},
		//onSuccess: function(){
			//alert(response.status);
		//},
		onFailure: function(response){
			alert('Failure! Status: ' + response.status);
		}
	});
	
	return false;
	
}




/*
* contact_form_onsubmit()
* 
* controller: contact
* template: template.index.php
* function: form submit
* 
*/
function contact_form_onsubmit(){
	
	if ($('from_email').value == '' || $('subject').value == '') return false;
	
	var bodytext = $('body').value;
	bodytext = bodytext.trim();
	bodytext = bodytext.replace(/(\.|-|\?| )*/ig, '');
	
	
	if (bodytext.length){
		
		
		$('submit').disabled = true;
		$('submit').value = 'Küldés folyamatban...';
		$('progress').style.height = $('wrapper').offsetHeight + 'px';
		$('progress').show();
		
		
		var myAjax = new Ajax.Request($('contact_form').action, { 
			method: 'post', 
			parameters: Form.serialize('contact_form'),
			onComplete: function(response){
				//alert(response.status);
				$('progress').hide();
				$('submit').value = 'Küldés';
				$('submit').disabled = false;
				$('message').show();
				if (response.responseText == 'ok'){
					Field.clear('from_email');
					Field.clear('subject');
					Field.clear('body');
					$('message').innerHTML = '<span class="green">Köszönjük a levelét!</span>';
				}
				else {
					$('message').innerHTML = response.responseText;
				}
				// hide message
				setTimeout(function(){
					$('message').hide();
				}, 5000);
			},
			onSuccess: function(response){
				//alert(response.status);
			},
			onFailure: function(response){
				//alert(response.status);
				$('progress').hide();
				$('submit').value = 'Küldés';
				$('submit').disabled = false;
				$('message').innerHTML = 'Status: ' + response.status + ' Text: ' + response.responseText;
				$('message').show();
			}
		});
		
		
	}//end length
	
	return false;

}



