function advOpen(openUrl, openWidth, openHeight, openSwitch, openName) {
	var srw = screen ? (screen.width-50)    : 750;
    var srh = screen ? (screen.height-36)   : 564;
    var openScroll  	= "0";
	var documentWrite	= "";
	var	openParameters	= "";
    if ((openWidth>srw) || (openHeight>srh)) {
        openScroll  = "1";
        if (openHeight>srh) { openWidth  = openWidth+16; openHeight = srh-50; }
        if (openWidth>srw)  { openHeight = openHeight+16; openWidth = srw-50; }
    }

    srw     = (srw - openWidth)/2;
    srh     = (srh - openHeight)/5;

  	var UTCstring;
  	Today = new Date();
  	UTCstring = Today.getUTCHours()+Today.getUTCMinutes()+Today.getUTCSeconds()+Today.getTime();

	openName        = openName ? openName : "openPopup"+UTCstring;

    openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars="+openScroll+",titlebar=1,resizable=0";
    switch(openSwitch) {
        case "print":   openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars=1,titlebar=1,resizable=0,menubar=1"; break;
        case "scroll":  openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars=1,titlebar=1,resizable=0"; break;
    }
    var openPopup   = open(openUrl, openName, openParameters);
    return false;
}

function formActivate($formID) {
	// ".form .text"
	$("#"+$formID+" .text, TEXTAREA, .file").bind("blur focus", function(e) {
		switch (e.type) {
			case "blur": $(this).removeClass("act"); break;
			case "focus": $(this).addClass("act"); break;
		}
	  
		return true;
    });
}


$(window).load(function () {
//	run code
//	alert(2);
/*
	$(".form .text").bind("blur focus", function(e) {
		switch (e.type) {
			case "blur": $(this).toggleClass("act", 0); break;
			case "focus": $(this).toggleClass("act", 1); break;
		}
		return true;
    });
*/
	if ($('#simple_example_window').attr('id') != undefined) {
		var pWidth = $('#simple_example_window').parent().width();
		var width = $('#simple_example_window').width() + 10;  
		  var height = $('#simple_example_window').height();    
		 
		$('#simple_example_window').css('left', ((pWidth - width) /2)+'px');
	//	$('#simple_example_window').css('right', ((pWidth - width) /2)+'px'); 
		$('#simple_example_window').css('top', (53 - (height - 20))+'px');      
		
		//$('#simple_example_window').css('width', width+'px');    
		//alert(((pWidth - width) /2)+'px');  
	}

	if (window.initForm) { initForm(); }
//	window.setTimeout("termsClear()", 1000);
/*
*/
});

//$(document).ready(function() {
//	  
//	$('body').bind("keyup", function(e){    
//		if (e.keyCode == 27) {
//			$('#qs').attr('value', "");
//			$('#qs').focus();
//		}
//	});    
//});    


$(window).unload(function () {
	// vse proceduri na vigruzke;
});


function termsClear() {
	if ($("#map_canvas")) {
		$("#map_canvas #copyright SPAN").css({'display':'none'});
	}
}

//function fastLogin() {
//	$("#th_login .TB_TD_body").load("/in_site/tools/ajax/login.php");
//	tb_show(
//		'login',
//		'#TB_inline?width=350&height=350&modal=true&inlineId=th_login', true);
//	return false;
//}  

function fastLogin() {
	closeRegisterForm();
	$("#th_login .TB_TD_body").load("/in_site/tools/ajax/login.php");
	  
	$('#th_login').css({    
					 width: '185px',      
					 top: '37px',   
					 display: 'block',
					 left: '0px',  
					 color:'#000000',	
				 	 position: 'absolute',
					 textAlign: 'left',  					  
					 zIndex: '1000'      
					 });  
	$("#th_login .TB_TD_body").css({width: '165px',height: '180px' });        
	$('#login').css({backgroundColor: '#FFFFFF', color: '#3899CB'});
	$('.fast-login IMG:first').attr('src','/images/login_left_act.gif');    
	return false;
}
 
function registerForm() {
	closeFastLogin();
	$("#th_register .TB_TD_body").load("/in_site/tools/ajax/register.php");    
//	jQuery.get("/in_site/tools/ajax/register.php", '', function(data) { 
		  
//		$("#th_register .TB_TD_body").html(data);
		//pos = $('#register').position(); 
		
	
		$('#th_register').css({    
			 width: '205px',        
			 top: '37px',   
			 display: 'block', 
			 color:'#000000',	
		 	 position: 'absolute',
			 textAlign: 'left',
			 right: '0px',      
			 zIndex:'102'});
		$("#th_register .TB_TD_body").css({width: '165px',height: '180px' }); 
		$('#register').css({backgroundColor: '#FFFFFF', color: '#3899CB'});
		$('.fast-login IMG:last').attr('src','/images/login_right_act.gif');  
		
//	} ); 
	    
	return false;
}

function closeRegisterForm() {
	$('#th_register').css("display","none");
	$('#register').css({backgroundColor: '#3899CB', color: '#FFFFFF'});
	$('.fast-login IMG:last').attr('src','/images/login_right.gif');    
}


function closeFastLogin() {
	$('#th_login').css("display","none");
	$('#login').css({backgroundColor: '#3899CB', color: '#FFFFFF'});
	$('.fast-login IMG:first').attr('src','/images/login_left.gif'); 
}
  
//$('#th_login').click(function(event) {  
//	alert(event.relatedTarget);
//	alert('lololo');      
//});  	


function tryLogout() {
//	jQuery.post("/in_site/tools/ajax/login.php", { logout: 1 }, function($html) { $("#TB_window .TB_TD_body").html($html); }, "html");
	jQuery.post("/in_site/tools/ajax/login.php", { logout: 1 }, function($html) {
//			var $href	= top.document.location.href.split("?");
//			top.document.location.href = top.document.location.href;
//			alert($html);
			top.document.location.href = "/";
	}, "html");
	return false;
}
function tryLogin($form) {
	jQuery.post("/in_site/tools/ajax/login.php", $($form).serialize(), function($html) { $("#th_login .TB_TD_body").html($html); }, "html");  
	return false;
};
function tryRegister($form) {
	jQuery.post("/in_site/tools/ajax/register.php", $($form).serialize(), function($html) { $("#th_register .TB_TD_body").html($html); }, "html");
	return false;
};


function closeHint($id) {  
	
	jQuery.get('/in_site/tools/ajax/beak.php'+($id ? '?close='+$id : '' ) ,'', function (data) {
		//alert('On function');    
		$('#beak').slideUp('slow',function() {
			if (data) {

				$('#beak').html(data);
				  
				$('#beak').slideDown("slow");

			}

		} )

	} );
}

function hintRefresh() {
	
	jQuery.get('/in_site/tools/ajax/beak.php','', function (data) {  
		$('#beak').slideUp('slow',function() {
			
			if (data) {
				$('#beak').html(data);
			 
				$('#beak').slideDown("slow");
	
			}
	
		} );
	});	
}

var $myShop		= false;
   
var gGwidth;
var gGheight;
var gMapCenter;
var gFrom;
var gTo;  

function gload(gwidth, gheight, mapCenter, $from, $to) {
	
	//alert($('#googleScript').attr('id'));          
	if ($('#googleScript').attr('src')==undefined) {    
		gGwidth = gwidth;
		gGheight = gheight;
		gMapCenter = mapCenter;
		gFrom = $from;
		gTo = $to;   
		  
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = linkGoogle ;  
		script.id = 'googleScript';  
		document.getElementsByTagName('head')[0].appendChild(script);    
	} else {
	
		var width = $(window).width();
		var height = $(window).height();
	
		if (width > 1120) {
			gwidth = 1000;
		} else {
			gwidth = width - 120;
		}
	
		if (height > 975) {
			gheight = 800;
		} else {
			gheight = height - 175;
		}
	
		if (mapload(gwidth,gheight,mapCenter)) {
		    tb_show(
		    	'place',
		    	'#TB_inline?width='+(gwidth*1+40)+'&height='+(gheight*1+95)+'&modal=true&inlineId=map_window',
		    	true
		    );
		    if ($from && $to) {
		    	drawRoute($from, $to, 1);
		    }
	
		    showLegend();
	
		}
	}
	return false;
}

function loadMap() {
	
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = '/js/map.js';    
	document.getElementsByTagName('head')[0].appendChild(script);
	 
}
  
