//*************************************
//PNG
//************************************* 
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 = "http://pro-okna.com/images/global/1x1.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')";
	}
}



//*************************************
//Cookie
//*************************************
function FixCookieDate(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)date.setTime(date.getTime() - skew);
}

function getCookieVal (offset) {
var endstr = document.cookie.indexOf(";", offset);
if (endstr == -1) endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) {
var arg = name + "=";
var cval = document.cookie;

tmp_pos = cval.indexOf(arg);
if (tmp_pos == -1) return "";
 
tmp_str = cval.substr(tmp_pos);

tmp_pos1 = tmp_str.indexOf("=")+1;
tmp_pos2 = tmp_str.indexOf(";");

if (tmp_pos2 > -1)
  ret_val = tmp_str.substring(tmp_pos1, tmp_pos2);
 else
   ret_val = tmp_str.substring(tmp_pos1);

return unescape(ret_val);
}

function SetCookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

function DelCookie(name,path,domain) {
if(GetCookie(name)) {
    document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "");
  }
}


    
//*************************************
//Карта сайта
//*************************************
var ttXpos = 0, ttYpos = 0;
var ttXadd = 10, ttYadd = 0;
var ttDisplay = 0, ttHoldIt = 0;

function showMap(e)
 {
 	var info_obj = document.getElementById("sitemap");
 	var shell_obj = !document.getElementById("shell") ? document.getElementById("main") : document.getElementById("shell");
 	
 	var divHeight = 464;
    var divWidth = 650;
 	
 	if (e)
 	 {
	    if ( typeof( event ) != 'undefined' ) {
	        ttXpos = event.x;
	        ttYpos = event.y;
	    } else {
	        ttXpos = e.pageX;
	        ttYpos = e.pageY;
	    }
 	 }
 	 else
 	  {
 	  	 ttXpos = Math.floor((document.body.offsetWidth - divWidth) / 2);
 	  	 ttYpos = 100;
 	  }
 	
    var plusX=0, plusY=0, docX=0, docY=0;
    
    if (navigator.appName.indexOf("Explorer")!=-1) {
        if (document.documentElement && document.documentElement.scrollTop) {
            plusX = document.documentElement.scrollLeft;
            plusY = document.documentElement.scrollTop;
            docX = document.documentElement.offsetWidth + plusX;
            docY = document.documentElement.offsetHeight + plusY;
        } else {
            plusX = document.body.scrollLeft;
            plusY = document.body.scrollTop;
            docX = document.body.offsetWidth + plusX;
            docY = document.body.offsetHeight + plusY;
        }
    } else {
        docX = shell_obj.clientWidth;
        docY = shell_obj.clientHeight;
    }

    ttXpos = ttXpos + plusX;
    ttYpos = ttYpos + plusY;

    if ((ttXpos + divWidth) > docX)
        ttXpos = ttXpos - (divWidth + (ttXadd * 2));
    if ((ttYpos + divHeight) > docY)
        ttYpos = ttYpos - (divHeight + (ttYadd * 2));        
    
    if (window.Modalbox)
 	  Modalbox.show(info_obj, {title: 'Карта сайта', left: (ttXpos + ttXadd), top: (ttYpos + ttYadd), overlayOpacity: .40, slideDownDuration: .0, slideUpDuration: .0 });
 }
 
function openNextMapPage(obj)
 {
 	var expdate = new Date();
    FixCookieDate(expdate);
    expdate.setTime(expdate.getTime() + 1000*3600);
    
    //var domain_pref = document.domain.replace(/\./g, "");
    
    SetCookie("showmap", "1", expdate, "/");
 	
 	location.href = obj.href;
 }
 
function restoreMap()
 {
 	cookie_val = GetCookie("showmap");
 	
 	if (cookie_val != "")
 	 {
 	    DelCookie("showmap", "/");
 	    showMap();
 	 }   
 }

if (window.addEventListener) {
	window.addEventListener("load", restoreMap, false);
} else {
	window.attachEvent("onload", restoreMap);
}
 


//*************************************
//Tooltip
//************************************* 
	document.observe("dom:loaded", function() {
		
		//Проверка существования элемента подсказки
		if (!$("ttip")) return false;	
		
		//Появление подсказки для панели навигации
  		var last = null;
  		
  		$(document.body).observe("mouseover", function(event){
	   		if (last)
	   		 {
  				$("ttip").setStyle({ display: "none" });
  				last = null;
	   		 }	
  		});
  		
  		$("ttip").observe("mouseover", function(event){
  			Event.stop(event);
  		});
  		
  		$(document.body).select("div.graphnav").each(function(navpanel, index) {
  		
	  		navpanel.setStyle({ position: "relative" });
	  		
	  		left_panel = navpanel.select("div.left")[0];
	  		
	  		if (left_panel)
	  		 {
		  		left_panel.select("a").each(function(obj, index) {
				   c_img = obj.select("img")[0];
				   
				   if (c_img)
				    {
					   c_img.observe("mouseover", function(event){
					   		if (this != last)
					   		 {
						   		$("ttip").setStyle({ display: "none" });
						   		
						   		c_dim = this.positionedOffset();
						   		$("ttip").clonePosition(navpanel, { offsetLeft: c_dim[0]+5, offsetTop: c_dim[1]-41, setWidth: false, setHeight: false });
						   		
						   		$("ttip_link").innerHTML = this.adjacent("span")[0].innerHTML;
						   		$("ttip_link").href = this.ancestors()[0].readAttribute('href');
						   		$("ttip_title").innerHTML = this.readAttribute('longdesc');
						   		
						   		$("ttip_app").setStyle({ left: "30px", rigth: "auto" });
						   		$("ttip_app").childElements()[0].show();
						   		$("ttip_app").childElements()[1].hide();
						   		
						   		$("ttip").setStyle({ display: "block" });
						   		last = this;
					   		 }
					   		 
					   		Event.stop(event); 	
					   });
				    }  
				});
	  		 }
	
		   right_panel = navpanel.select("div.right")[0];	
			
		   if (right_panel)
		    {
			   right_panel.select("a").each(function(obj, index) {
				   c_img = obj.select("img")[0];
				   
				   if (c_img)
				    {
					   c_img.observe("mouseover", function(event){
					   		if (this != last)
					   		 {
						   		$("ttip").setStyle({ display: "none" });
						   		
						   		$("ttip_link").innerHTML = this.adjacent("span")[0].innerHTML;
						   		$("ttip_link").href = this.ancestors()[0].readAttribute('href');
						   		$("ttip_title").innerHTML = this.readAttribute('longdesc');
						   		
						   		$("ttip_app").setStyle({ left: "auto", right: "30px" });
						   		$("ttip_app").childElements()[0].hide();
						   		$("ttip_app").childElements()[1].show();
						   		
						   		c_dim = this.positionedOffset();
						   		ttip_width = $("ttip").getWidth();
						   		$("ttip").clonePosition(navpanel, { offsetLeft: c_dim[0]-ttip_width+41, offsetTop: c_dim[1]-41, setWidth: false, setHeight: false });
						   		
						   		$("ttip").setStyle({ display: "block" });
						   		last = this;
					   		 }
					   		 
					   		Event.stop(event); 	
					   });
				    }  
				});
		    }
  		});		
	});


	
//*************************************
//Прочие функции
//************************************* 
function goURL(url)
 {
 	window.open(url, "_blank");
 }
 
function goToPage(url)
 {
 	location.href = url;
 } 

function getEmail(start, end)
 {
 	document.write("<a href='mailto:"+start+"@"+end+"'>"+start+"@"+end+"</a>");
 }
