/*********
 *
 * JScript for Akrostal
 * Author: Trol InterMedia
 *
 *********/


function DEBUG(Text){
	if( document.getElementById('DEBUG') )
		document.getElementById('DEBUG').innerHTML += Text+'<br />';
}

function new_window(url, name, width, height){
  if( !name ) name = 'new_window';
  if( !width ) width = 640;
  if( !height ) height = 480;
  var top = Math.round((screen.height-height)/2);
  var left = Math.round((screen.width-width)/2);
  window.open(url, name,'width=' + width + ',height=' + height + ',top='+top+',left='+left+',resizable=yes,scrollbars=yes,menubar=no');
}

/****************/

function AjaxRequest(Id, URL, Vars, Method){
  if( $(Id) ){
		$(Id).innerHTML = '';
		$(Id).addClass('loading');
    if( !Method ) Method = 'get';
    if( !Vars ) Vars = '';
    new Request({'url':URL, 'method':Method,
      'onSuccess': function(Text,Xml){ $(Id).set('html', Text); },
      'onFailure': function(){ $(Id).set('text', URL); }
    }).send(Vars);
		$(Id).removeClass('loading');
  }
}

function Ajax_AddToCard(Id, URL, Vars, Method, Function){
  if( $(Id) ){
		$(Id).innerHTML = '';
		$(Id).addClass('loading');
    if( !Method ) Method = 'get';
    if( !Vars ) Vars = '';
    new Request({'url':URL, 'method':Method,
      'onSuccess': function(Text,Xml){
					$(Id).set('html', Text);
					if( Function )
						Function.run();
			},
      'onFailure': function(){
				$(Id).set('text', URL);
  		}
    }).send(Vars);
		$(Id).removeClass('loading');
  }
	else{
		alert(Id+' not found');
	}
}

/*********/

function map_show(Url){
	if( $('cms_map_popup') ){
		var Obj = $('cms_map_popup');
		var BaseUrl = (document.location.href).replace(/(http:\/\/[^\/]+\/).*/, '$1');
		Url = Url.replace(' ', '');

		//alert(BaseUrl+Url.replace(' ', '')+'?ajax=map');
		//if( Url.indexOf('Polska')==-1 ){
		if( !Url.match(/^.+Polska\/$/) ){
			Obj.setStyle('opacity', 0);
			Obj.removeClass('HIDE');
			Obj.set('html', '<div class="message">wczytuję...</div>');
			new Fx.Tween(Obj, { duration:400 }).start('opacity',0,1);
			new Request({'url':BaseUrl+Url+'?ajax=map', 'method':'get',
				'onSuccess': function(Text,Xml){
					Obj.set('html', Text);
				},
				'onFailure': function(){ Obj.set('text', BaseUrl+Url); }
			}).send();
		}
		else{
			document.location.href = BaseUrl+Url;
		}
	}
}

/**********/

//var Page = new Array();
document.addEvent('domready', function(){
	//if( $('flash_map') ){
	//	$('flash_map').addEvent('mousemove', function(e){
	//		Page[0] = e.page.x-506;;
	//		Page[1] = e.page.y-699;
	//	});
	//}
});
