/**
 * :tabSize=2:indentSize=2:noTabs=true:
 * :folding=explicit:collapseFolds=1:
*/

var disClose = false;

//{{{ checkFieldText()
function checkFieldText(elem, svalidator, smessage) {
  
  if (elem.value.match(svalidator)) return true;
  
  alert(smessage);
  elem.focus();
  return false;
  
}
//}}}

//{{{ fixPNG()
function fixPNG(element) {
  
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
    
    var src;
    
    if (element.tagName=='IMG') {
    
      if (/\.png$/.test(element.src)) {
        src = element.src;
		  	element.src = "/images/spacer.gif";
		  }
		
    } else {
        
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      
      if (src) {
			
        src = src[1];
			
        element.runtimeStyle.backgroundImage="none";
      }
    }
		
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	}
} 
//}}}

//{{{ showMap()
function showMap(w, h) {
  
  var tmp = getPageSize();
  
  $_j('#auth_div').css({display: 'block', visibility: 'visible', height: tmp[1] + 'px'});
  
  $_j('#bg_popup').css({display: 'block', visibility: 'visible', height: tmp[1] + 'px'});
  
  $_j('#block_map').css({top: '100px', width: w + 'px', height: h + 'px', left: Math.floor(($_j('#auth_div').width() - w) / 2) + 'px'});
  
  $_j('#shadow_page').css({opacity: 0.75, height: tmp[1] + 'px' });
  
  $_j('#bg_popup').css({ opacity: 0 });
  
  drawHTML(h);
  
  return false;
}
//}}}

//{{{ closeMap()
function closeMap() {
  
  if (disClose) {
    
    setTimeout(function() { disClose = false; }, 500);
    
  } else {
    
    $_j('#auth_div').css({display: 'none', visibility: 'hidden'});
    $_j('#bg_popup').css({display: 'none', visibility: 'hidden'});
    
  }
  
  //return false;
  
}
//}}}

//{{{ getPageSize()
function  getPageSize(){
       var xScroll, yScroll;

       if (window.innerHeight && window.scrollMaxY) {
               xScroll = document.body.scrollWidth;
               yScroll = window.innerHeight + window.scrollMaxY;
       } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
               xScroll = document.body.scrollWidth;
               yScroll = document.body.scrollHeight;
       } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
               xScroll = document.documentElement.scrollWidth;
               yScroll = document.documentElement.scrollHeight;
       } else { // Explorer Mac...would also work in Mozilla and Safari
               xScroll = document.body.offsetWidth;
               yScroll = document.body.offsetHeight;
       }

       var windowWidth, windowHeight;
       if (self.innerHeight) { // all except Explorer
               windowWidth = self.innerWidth;
               windowHeight = self.innerHeight;
       } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
               windowWidth = document.documentElement.clientWidth;
               windowHeight = document.documentElement.clientHeight;
       } else if (document.body) { // other Explorers
               windowWidth = document.body.clientWidth;
               windowHeight = document.body.clientHeight;
       }

       // for small pages with total height less then height of the viewport
       if(yScroll < windowHeight){
               pageHeight = windowHeight;
       } else {
               pageHeight = yScroll;
       }

       // for small pages with total width less then width of the viewport
       if(xScroll < windowWidth){
               pageWidth = windowWidth;
       } else {
               pageWidth = xScroll;
       }
       
       return [pageWidth,pageHeight,windowWidth,windowHeight];
}
//}}}

//{{{ changePlace()
function changePlace(lat, lng, zoom) {
  
  if (GBrowserIsCompatible()) {
    
    map = new GMap2($_j('#geo_map').get(0));
    map.enableScrollWheelZoom();
    map.enableDoubleClickZoom();
    map.setCenter(new GLatLng(lat, lng),  zoom);
    map.addControl(new GLargeMapControl3D());
    map.addControl(new GMapTypeControl());
    
  }
  
}
//}}}

//{{{ drawHTML()
function drawHTML(h) {
  
  var req = new JsHttpRequest();
  
  req.onreadystatechange = function() {
      
    if (req.readyState == 4) {
      
      if (req.responseJS) {
        
        $_j('#block_map').empty().append(req.responseJS.htmlContent); 
        
      }
    }
  }

  
  req.caching = false;
  req.open('POST', '/rs/geo_fly/', true);
  req.send({t_height: h});
  
}
//}}}

//{{{ notClose()
function notClose() { disClose = true; }
//}}}


