function popUpWindow(URLStr, width, height)
{
	if(width >= screen.width)
		width = 'full';
	if(height >= screen.height)
		height = 'full';

	if(width == "full")
		width = window.screen.availWidth;
	else
		var left = Math.round((screen.width - width) / 2);
	if(height == "full")
		height = window.screen.availHeight;
	else
		var top = Math.round((screen.height - height) / 2);

	popUpWin = open(URLStr, 'adsbxc_ss', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.opener.name="1A2B3C4D";
}

function submit_form()
{
	var url = $('main_form').readAttribute('action') + '?' + $('main_form').serialize();
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
		form_responce_handler(transport.responseText);
	  }
	});
	return false;
}

function submit_form_ext(form_id)
{
	if (undefined !== form_id) {
		var url = $(form_id).readAttribute('action') + '?' + $(form_id).serialize();
		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(transport) {
			form_responce_handler(transport.responseText);
		  }
		});
	}
	return false;
}

function form_responce_handler(responceText) {
	if (responceText) {
		var errors = responceText.split('|');
		//top.$("error_message").setStyle({display: "none"});
		$("error_message").setStyle({display: "none"});
		//top.$("error_message_cont").innerHTML = "";
		$("error_message_cont").innerHTML = "";
		if (errors[0] == 'true') {
			if (errors[1] != undefined) {
				if ((errors[1] == 'code') && (errors[2] != undefined)) {
					eval(errors[2]);
				} else {
					top.tb_remove();top.document.location.href = errors[1];
				}
			} else {
				top.tb_remove();top.document.location.reload();
			}
		} else {
			//hide_messages_block();
			push_errors(errors);
			show_messages_block();

			//var new_height = top.$("TB_iframeContent").getHeight()+$("error_message").getHeight();
			//top.$("TB_iframeContent").setStyle({height: new_height+"px"});
			//top.TB_HEIGHT =new_height;
			//top.tb_position();
			//$("error_message").setStyle({display: "block"});
			//$('error_message_underground').setStyle({ height: $('error_message_container').getStyle('height') });
		}
	}

}

function push_errors(errors) {
	errors.each(function(s){
		$('error_message_cont').innerHTML += s + "<br/>";
	});
}

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function show_messages_block(notice) {
	//$("error_message").setStyle({position: "absolute", zIndex: "200"});
	$("error_message").setStyle({display: "block"});
	//new Effect.Pulsate($("error_message"), {duration: 1});
	if (notice == true) {
//		$("error_message_head").removeClassName("message_head");
//		$("error_message_cont").removeClassName("message_cont");
//		$("error_message_head").innerHTML = "Note:";
//		$("error_message_head").addClassName("note_message_head");
//		$("error_message_cont").addClassName("note_message_cont");
	} else {
//		$("error_message_head").removeClassName("note_message_head");
//		$("error_message_cont").removeClassName("note_message_cont");
//		$("error_message_head").innerHTML = "Error:";
//		$("error_message_head").addClassName("message_head");
//		$("error_message_cont").addClassName("message_cont");
	}
}

function hide_messages_block(quick) {
	if (quick != undefined) {
		//top.$("error_message").setStyle({display: "none"});
		$("error_message").setStyle({display: "none"});
		$("error_message_cont").innerHTML = "";
	} else {
		//new Effect.Shrink(top.$("error_message"));
		new Effect.SwitchOff($("error_message"), {afterFinish: function(f){$("error_message_cont").innerHTML = "";}});
	}
	//top.$("error_message_cont").innerHTML = "";
	//$("error_message_cont").innerHTML = "";
}

function cancel_operation() {
	top.tb_remove();
	hide_messages_block(1);
}