var OpenMenu=new Array();
var OpenMenu2=new Array();
var Timer=null;
var M$ =  navigator.appName.indexOf("Microsoft")!=-1;
var O$ =  navigator.appName.indexOf("Opera")!=-1;

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

function clearTimer()
  {
   if (Timer)
     {
      clearTimeout (Timer);
      Timer = null;
     }
  }

function setTimer()
  {
   Timer = window.setTimeout('CloseAll(0)', 500);
//   Timer = window.setTimeout('CloseMenu(10)', 0);
   
  }

function ShowMenu(id, left, level, id2)
  {
id1 = document.getElementById(id);
id2 = document.getElementById(id2);
id3 = document.getElementById("i" + id.substr(1));
id4 = document.getElementById("a" + id.substr(1));
   clearTimer();
   //if (IExplorer4)
     return ShowMenuE(id1, left, level, id2, id3, id4);
   //if (Netscape6)
   //  return ShowMenuN(id, left, level);
   return true;
  }

function ShowMenuE(id, left, level, id2, id3, id4)
  {
   //elem = eval (id);
   elem = id;
      elem2 = id2;
   if (OpenMenu[level] && OpenMenu[level]!=elem)
     CloseAll(level);
  // if (document.all.item(id) == null)
   if (id == null)
     return true;
   if (typeof(left) == "number")
   {
     if (document.body.clientWidth - 776 > 0)
       elem.style.pixelLeft = parseInt((document.body.clientWidth-776)/2) + left;
       if (id3) id3.style.pixelLeft = parseInt((document.body.clientWidth-776)/2) + left;
     else
       elem.style.pixelLeft = left;
       if (id3) id3.style.pixelLeft = left;
   }
   id5 = document.getElementById("c" + elem.id.substr(1));
   if (id3)
   {
      if (id5) id5.appendChild(id3);
      id3.style.display = "block";
      id3.style.visibility = "visible";
      id3.style.pixelLeft = elem.style.pixelLeft + 1;
   }
   elem.style.display = "block";
   elem.style.visibility = "visible";
   if (id3)
   {
      id3.style.width = elem.offsetWidth - 1;
      id3.style.height = elem.offsetHeight - 1;
   }
//   elem.style.zIndex = "99";
   elem2.style.display = "none";
   elem2.style.visibility = "hidden";
   if (id4) id4.style.display = "block";
//   window.alert (elem.offsetWidth);
   OpenMenu[level]=elem;
	OpenMenu2[level]=elem2;
   return false;
  }

function ShowMenuN(id, left, level)
  {
   if (OpenMenu[level] && OpenMenu[level]!=id)
     CloseAll(level);
   elem = document.getElementById(id);
   if (elem == undefined)
     return true;
   if (window.innerWidth - 776 > 0)
     elem.style.left = parseInt((window.innerWidth-776)/2) + left;
   else
     elem.style.left = left;
   elem.style.visibility = "visible";
   elem.style.display = "block";
   OpenMenu[level]=id;
   return false;
  }

function CloseMenu(level,delay)
  {
   //if (IExplorer4)
     if (delay)
     {
         clearTimer();
//         Timer = window.setTimeout("CloseMenuE(" + level + ");" ,500);
     }
     else
         return CloseMenuE(level);
   //if (Netscape6)
   //  return CloseMenuN(level);
   return true;
  }

function CloseMenuE(level)
  {
   if (OpenMenu[level])
     {
      OpenMenu[level].style.display = "none";
      OpenMenu[level].style.visibility = "hidden";
      id = document.getElementById("i" + OpenMenu[level].id.substr(1));
      if (id)
      {
          id.style.display = "none";
          document.body.appendChild(id);
      }
      id = document.getElementById("a" + OpenMenu[level].id.substr(1));
      if (id)
          id.style.display = "none";
      OpenMenu2[level].style.display = "block";
      OpenMenu2[level].style.visibility = "visible";
     }
   OpenMenu[level]=null;
   OpenMenu2[level]=null;
  }

function CloseMenuN(level)
  {
   if (OpenMenu[level])
     {
      document.getElementById(OpenMenu[level]).style.visibility = "hidden";
      document.getElementById(OpenMenu[level]).style.display = "none";
     }
   OpenMenu[level]=null;
  }

function CloseAll(level)
  {
   clearTimer();
   for (i=level; i<OpenMenu.length; i++)
     CloseMenu(i);
  }

function GetYPos(elem)
  {
   var pos = elem.offsetTop;
   while (elem.offsetParent != null)
     {
      elem = elem.offsetParent;
      pos += elem.offsetTop;
      if (elem.tagName == 'BODY') break;
     }
   return pos;
  }  

function ScrollTo(which)
  {
   if (document.all.item(which) == null)
     return true;
   var elem = eval(which);
   targetPos=GetYPos(elem);
   docLength=GetYPos(docEndImg);
   if ((docLength-targetPos) > (document.body.clientHeight-Header.offsetHeight))
     document.body.scrollTop = targetPos-Header.offsetHeight;
   else 
     document.body.scrollTop = docLength-document.body.clientHeight;
   CloseAll(0);
   return false;
  }

function ScrollPriceHeader()
  {
   if (document.body.scrollTop>88)
     {
      Header.style.top = document.body.scrollTop-88;
      var i=0;
      while (elem=document.all.item("grouplist"+i++))
        elem.style.top = document.body.scrollTop+34; // ®Ј« ў«Ґ­ЁҐ §¤Ґбм
     }
   else
     {
      Header.style.top = 0;
      var i=0;
      while (elem=document.all.item("grouplist"+i++))
        elem.style.top = 122; // Ё §¤Ґбм в®¦Ґ ®Ј« ў«Ґ­ЁҐ
     }
  }

function ShowHide(elem)
  {
   if (document.getElementById(elem).style.display == "none")
     document.getElementById(elem).style.display = "block";
   else
     document.getElementById(elem).style.display = "none";
  }

  function Show(elem)
  {
	  id1 = findObj(elem);
     id1.style.display = "block";
	 id1.style.visibility = "visible";
  }

  function Hide(elem)
  {
	  	   id1 = findObj(elem);
       id1.style.display = "none";
	   id1.style.visibility = "hidden";
  }

function doLiteOn(obj)
{
obj.style.backgroundImage = "url(i/w6.gif)";
}
function doLiteOff(obj)
{
obj.style.backgroundImage = "url(i/w2.gif)";
}
function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}
function toggle(id)
{
	var tmp = document.getElementById(id);
	if (id)
	{
		if (tmp.style.display == "none") tmp.style.display = "";
		else tmp.style.display = "none";
	}
	return false;
}
function toggle_tag(tag,id)
{
	var tmp = document.getElementsByTagName(tag);
	for (var x = 0; x < tmp.length; x++) if (tmp[x].id == id)
	{
		if (tmp[x].style.display == "none") tmp[x].style.display = "";
		else tmp[x].style.display = "none";
	}
	return false;
}
function toggle_text(elem)
{
	var tmp = elem.getAttribute("ttext");
	if (tmp)
	{
		elem.setAttribute("ttext",elem.innerText,0);
		elem.innerText = tmp;
	}
	return false;
}
function toggle_spo(id,elem)
{
	toggle_tag("TR",id);
	toggle_text(elem);
	return false;
}
function open_tab(elem,val)
{
	tbr = elem.parentNode.parentNode.parentNode;
	tbh = tbr.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetHeight;
	for (x = 0; x < tbr.cells.length; x++) if (tbr.cells[x].firstChild.className == "s1a")
	{
		tbr.cells[x].firstChild.className = "s1p";
		document.getElementById("t_" + tbr.cells[x].firstChild.id.substr(2)).style.display = "none";
	}
	elem.parentNode.className = "s1a";
	document.getElementById("t_" + elem.parentNode.id.substr(2)).style.display = "";
	tbr.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.height = tbh;

	tbr = allSpoOpened();
	setExpandName(tbr[1]);

	tbr = document.getElementById("moreSpo");
	if (tbr) tbr.href = "/ttours/?aerocity=" + val;

	return false;
}
function open_memo(elem)
{
	window.open(elem.href,elem.target ? elem.target : "_ute_memo","width=600,height=550,resizable=yes,toolbar=0,location=0,status=no,menubar=0,directories=0,scrollbars=yes").focus();
	return false;
}
function open_map(id)
{
	tmp = document.getElementById(id);
	if (tmp)
	{
		tmp.style.visibility = "visible";
		tmp.style.display = "block";
	}
	return false;
}
function close_map(id)
{
	tmp = document.getElementById(id);
	if (tmp)
	{
		tmp.style.visibility = "hidden";
		tmp.style.display = "none";
	}
	return false;
}
function open_tourtab(elem)
{
	tbr = elem.parentNode.parentNode;
//	tbh = tbr.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetHeight;
	for (x = 0; x < tbr.cells.length; x++) if (tbr.cells[x].className == "r1a")
	{
		tbr.cells[x].className = "r1p";
		idx = parseInt(tbr.cells[x].id.substr(1,tbr.cells[x].id.length - 2));
		document.getElementById("r" + idx + "l").className = "r1pl";
		document.getElementById("r" + idx + "r").className = "r1pr";
		if (idx > 1) document.getElementById("r" + (idx - 1) + "r").className = "r1pr";
		if (x < tbr.cells.length - 3) document.getElementById("r" + (idx + 1) + "l").className = "r1pl";
		document.getElementById("tt_" + idx).style.display = "none";
	}
	elem.parentNode.className = "r1a";
	idx = parseInt(elem.parentNode.id.substr(1,elem.parentNode.id.length - 2));
	document.getElementById("r" + idx + "l").className = "r1al";
	document.getElementById("r" + idx + "r").className = "r1ar";
	if (idx > 1) document.getElementById("r" + (idx - 1) + "r").className = "r1sr";
	if (elem.parentNode.cellIndex < tbr.cells.length - 3) document.getElementById("r" + (idx + 1) + "l").className = "r1sl";
	document.getElementById("tt_" + idx).style.display = "";
//	tbr.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.height = tbh;
	return false;
}
function open_sem(elem)
{
	window.open(elem.href,elem.target ? elem.target : "_ute_seminar","width=460,height=316,resizable=no,toolbar=0,location=0,status=no,menubar=0,directories=0,scrollbars=no").focus();
	return false;
}
var slo = {};
function getSpo(id,force_open)
{
	var tmp = document.getElementById(id);
	if (tmp)
	{
		if (tmp.className == "smc" || force_open)
		{
			tmp = document.getElementById("sd_" + id.substr(3));
			if (tmp)
			{
				if (tmp.innerHTML || tmp.getAttribute("noContent"))
				{
					tmp.style.display = "";

					document.getElementById(id).className = "smo";
				}
				else
				{
					var dcity = id.substr(id.indexOf("_") + 1);
					tmp = dcity.indexOf("_");
					var cntr = dcity.substr(tmp + 1);
					dcity = dcity.substr(0,tmp);

					if (!slo[dcity + "_" + cntr])
					{
						slo[dcity + "_" + cntr] = true;
						tmp = document.createElement("SCRIPT");
						tmp.src = "/get_spo.php?dc=" + dcity + "&cntr=" + cntr;
						document.body.appendChild(tmp);
						window.setTimeout("slo[\"" + dcity + "_" + cntr + "\"] = false;",20000);
					}
				}
			}
		}
		else
		{
			tmp.className = "smc";

			tmp = document.getElementById("sd_" + id.substr(3));
			if (tmp) tmp.style.display = "none";
		}
	}
	tmp = allSpoOpened();
	setExpandName(tmp[1]);
	return false;
}
function getAllSpo()
{
	var tbr = document.getElementById("atabs");
	if (tbr)
	{
		var tmp = allSpoOpened();
		tmp[0] = document.getElementById("t_" + tmp[0].substr(2));
		if (tmp[0])
		{
			for (var x = 0; x < tmp[0].childNodes.length; x++) if (tmp[0].childNodes[x] && tmp[0].childNodes[x].tagName && tmp[0].childNodes[x].tagName == "DIV")
			{
				if (tmp[0].childNodes[x].firstChild && tmp[0].childNodes[x].firstChild.id && tmp[0].childNodes[x].firstChild.id.substr(0,3) == "sc_") getSpo(tmp[0].childNodes[x].firstChild.id,!tmp[1]);
			}
		}
		setExpandName(!tmp[1]);
	}
	return false;
}
function allSpoOpened()
{
	var ret = new Array(false,false);
	var tbr = document.getElementById("atabs");
	if (tbr)
	{
		for (var x = 0; x < tbr.cells.length; x++) if (tbr.cells[x].firstChild.className == "s1a")
		{
			ret[0] = tbr.cells[x].firstChild.id;
			var tmp = document.getElementById("t_" + ret[0].substr(2));
			if (tmp)
			{
				for (x = 0; x < tmp.childNodes.length; x++) if (tmp.childNodes[x] && tmp.childNodes[x].tagName && tmp.childNodes[x].tagName == "DIV")
				{
					if (tmp.childNodes[x].firstChild && tmp.childNodes[x].firstChild.id && tmp.childNodes[x].firstChild.id.substr(0,3) == "sc_")
					{
						if (tmp.childNodes[x].firstChild.className == "smc")
						{
							ret[1] = false;
							break;
						}
						else ret[1] = true;
					}
				}
			}
			break;
		}
		return ret;
	}
	else return false;
}
function setExpandName(opn)
{
	var tmp = document.getElementById("allSpo");
	if (tmp) tmp.innerHTML = (opn ? "свернуть все" : "развернуть все");
}
function getSpoCntrs(val)
{
	var tmp = document.forms["qs"].elements;
	tmp["cntr"].disabled = true;
	tmp["tn"].disabled = true;
	tmp["tn"].selectedIndex = 0;

	for (var x = tmp["cntr"].length - 1; x >= 0; x--) tmp["cntr"].remove(x);
	for (var x = tmp["tn"].length - 1; x > 0; x--) tmp["tn"].remove(x);

	tmp["dt_from"].value = "";
	tmp["dt_to"].value = "";

	tmp = document.getElementById("dis_cd");
	if (tmp) tmp.style.display = "";

	tmp = document.createElement("SCRIPT");
	tmp.src = "/get_spohdrs.php?dc=" + val;
	document.body.appendChild(tmp);
	return;
}
function getSpoHdrs(el)
{
	el.disabled = true;
	var tmp = el.form.elements["tn"];
	tmp.disabled = true;
	tmp.selectedIndex = 0;

	for (var x = tmp.length - 1; x > 0; x--) tmp.remove(x);

	el.form.elements["dt_from"].value = "";
	el.form.elements["dt_to"].value = "";

	tmp = document.getElementById("dis_cd");
	if (tmp) tmp.style.display = "";

	tmp = el.form.elements["city_dep"];
	for (x = tmp.length - 1; x >= 0; x--) if (tmp[x].checked)
	{
		x = tmp[x].value;
		break;
	}

	if (x > 0 && el.value)
	{
		tmp = document.createElement("SCRIPT");
		tmp.src = "/get_spohdrs.php?dc=" + x + "&cntr=" + el.value;
		document.body.appendChild(tmp);
		return;
	}
	else
	{
		tmp = document.getElementById("dis_cd");
		if (tmp) tmp.style.display = "none";

		el.disabled = false;
		el.form.elements["tn"].disabled = false;
	}
}
function spoDates(val)
{
	var dtfrom = "";
	var dtto = "";

	if (dts)
	{
		if (dts[val])
		{
			dtfrom = dts[val][0];
			dtto = dts[val][dts[val].length - 1];
		}
		else
		{
			dtfrom = dts[0][0];
			dtto = dts[0][1];
		}

		if (dtfrom)
		{
			dtfrom = dtfrom.split("-");
			document.forms["qs"].elements["dt_from"].value = dtfrom[2] + "." + dtfrom[1] + "." + dtfrom[0];
		}
		if (dtto)
		{
			dtto = dtto.split("-");
			document.forms["qs"].elements["dt_to"].value = dtto[2] + "." + dtto[1] + "." + dtto[0];
		}
	}
}
function rollMB(x,i,to)
{
	var els = $("#mb_over" + x + " > div");

	if (els.length > i)
	{
		$(els.get(i > 0 ? i - 1 : els.length - 1)).fadeOut(1100);
		$(els.get(i)).fadeIn(1100);

		i++;
		window.setTimeout("rollMB(" + x + "," + (i >= els.length ? 0 : i) + "," + to + ")",to);

/*	// увеличиваем счетчик просмотров показанного баннера
	$("<script src=/ad.js.php?id="+bannersList[next][0]+"></script>").appendTo("#body");
}*/
	}
}
function openSearch()
{
	var tmp = document.forms["qs"].elements;

	for (var x = tmp["city_dep"].length - 1; x >= 0; x--) if (tmp["city_dep"][x].checked)
	{
		x = tmp["city_dep"][x].value;
		break;
	}
	if (x >= 0 && tmp["cntr"].value)
	{
		x = "?country=" + tmp["cntr"].value + "&departFrom=" + (x == "2412" ? "" : x) + (tmp["tn"].value > 0 ? "&tour=" + tmp["tn"].value : "") + "&dateFrom=" + (tmp["dt_from"].value ? tmp["dt_from"].value.substr(6,4) + "-" + tmp["dt_from"].value.substr(3,2) + "-" + tmp["dt_from"].value.substr(0,2) : "") + "&dateTo=" + (tmp["dt_to"].value ? tmp["dt_to"].value.substr(6,4) + "-" + tmp["dt_to"].value.substr(3,2) + "-" + tmp["dt_to"].value.substr(0,2) : "") + "&target=_top";
		location.href = document.forms["qs"].action + x;
	}
}
function ResizeAllBan()
{
	var www = 0;
	var els = $("#mb_over1 > div");
	if (els.length)
	{
		for (var x = 0; x < els.length; x++)
		{
			if (!www)
			{
				els.get(x).firstChild.rows[0].cells[0].firstChild.style.width = "50px";
				els.get(x).firstChild.rows[0].cells[0].style.width = "";
				els.get(x).firstChild.rows[0].cells[1].style.width = "";
				els.get(x).firstChild.style.width = "";
				els.get(x).style.width = ($("#mb_over1").width() - (M$ ? 15 : 0)) + "px";
				www = els.get(x).offsetWidth;
			}
		}
		if (www) for (x = 0; x < els.length; x++)
		{
			els.get(x).style.width = www + "px";
			els.get(x).firstChild.style.width = www + "px";
			els.get(x).firstChild.rows[0].cells[0].style.width = Math.floor(www * .45) + "px";
			els.get(x).firstChild.rows[0].cells[0].firstChild.style.width = Math.floor(www * .45) + "px";
			els.get(x).firstChild.rows[0].cells[1].style.width = (www - Math.floor(www * .45)) + "px";
		}
	}
	www = 0;
	els = $("#mb_over2 > div");
	if (els.length)
	{
		for (var x = 0; x < els.length; x++)
		{
			if (!www)
			{
				els.get(x).firstChild.rows[0].cells[0].firstChild.style.width = "50px";
				els.get(x).firstChild.rows[0].cells[0].style.width = "";
				els.get(x).firstChild.rows[0].cells[1].style.width = "";
				els.get(x).firstChild.style.width = "";
				els.get(x).style.width = ($("#mb_over2").width() - (M$ ? 20 : 0)) + "px";
				www = els.get(x).offsetWidth;
			}
		}
		if (www) for (x = 0; x < els.length; x++)
		{
			els.get(x).style.width = www + "px";
			els.get(x).firstChild.style.width = www + "px";
			els.get(x).firstChild.rows[0].cells[0].style.width = Math.floor(www * .45) + "px";
			els.get(x).firstChild.rows[0].cells[0].firstChild.style.width = Math.floor(www * .45) + "px";
			els.get(x).firstChild.rows[0].cells[1].style.width = (www - Math.floor(www * .45)) + "px";
		}
	}
	www = 0;
	els = $("#mb_over3 > div");
	if (els.length)
	{
		for (var x = 0; x < els.length; x++)
		{
			if (!www)
			{
				els.get(x).firstChild.rows[0].cells[0].firstChild.style.width = "50px";
				els.get(x).firstChild.rows[0].cells[0].style.width = "";
				els.get(x).firstChild.rows[0].cells[1].style.width = "";
				els.get(x).firstChild.style.width = "";
				els.get(x).style.width = ($("#mb_over3").width() - (M$ ? 20 : 0)) + "px";
				www = els.get(x).offsetWidth;
			}
		}
		if (www) for (x = 0; x < els.length; x++)
		{
			els.get(x).style.width = www + "px";
			els.get(x).firstChild.style.width = www + "px";
			els.get(x).firstChild.rows[0].cells[0].style.width = Math.floor(www * .45) + "px";
			els.get(x).firstChild.rows[0].cells[0].firstChild.style.width = Math.floor(www * .45) + "px";
			els.get(x).firstChild.rows[0].cells[1].style.width = (www - Math.floor(www * .45)) + "px";
		}
	}
}

function open_video(el,v,i,w,h,t)
{
	var tmp = document.getElementById("_vid");
	if (tmp) close_video();

	var so = getPageSize();

	tmp = document.createElement("DIV");
	tmp.style.position = "absolute";
	tmp.style.zIndex = 99999;
	tmp.style.top = 0;
	tmp.style.left = 0;
	tmp.style.width = (so[0]) + "px";
	tmp.style.height = (so[1]) + "px";
	tmp.style.background = "#AAA";
	tmp.style.opacity = ".5";
	tmp.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50)";

	document.body.appendChild(tmp);

	tmp = document.createElement("DIV");
	tmp.style.position = "absolute";
	tmp.style.zIndex = 999999;
	tmp.style.top = (so[5] + Math.floor((so[3] - h) / 2) - 36) + "px";
	tmp.style.left = (so[4] + Math.floor((so[2] - w - 1) / 2) - 10) + "px";
	tmp.style.width = (w + 51) + "px";
	tmp.style.height = (h + 102) + "px";
	tmp.innerHTML = "<div style='border:15px solid #FFF;border-bottom:0;background:#FFF;margin-right:17px;line-height:15px;'><img src='/i/close.gif' alt='закрыть' width=17 height=15 border=0 hspace=0 style='float:right;cursor:pointer;' onClick='javascript:close_video();' tool='no'><b>" + t + "</b></div>";
	tmp.innerHTML += "<div id='_vid' style='width:" + (w + 4) + "px;height:" + (h + 72) + "px;background:#FFF;border:15px solid #FFF;'></div>";

	document.body.appendChild(tmp);

	so = new SWFObject("/workdir/files/Flash/video_megapolus.swf?file=" + v + "&img=" + i, "banner", w + 4, h + 72, "8.0.0.0", "#ffffff");
	so.addParam("allowScriptAccess", "always");
	so.addParam("movie", "/workdir/files/Flash/video_megapolus.swf?file=" + v + "&img=" + i);
	so.addParam("menu", "false");
	so.addParam("quality", "high");
	so.addParam("scale", "noscale");
	so.addParam("salign", "lt");
	so.addParam("wmode", "transparent");
	so.addParam("bgcolor", "#ffffff");
	so.write("_vid");

	return false;
}

function close_video()
{
	var tmp = document.getElementById("_vid");
	if (tmp)
	{
		tmp.parentNode.parentNode.removeChild(tmp.parentNode.previousSibling);
		tmp.parentNode.parentNode.removeChild(tmp.parentNode);
	}

	return false;
}

function  getPageSize(){
       var xScroll, yScroll;

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

/*       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 = window.innerHeight ? window.innerHeight : 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,myLeft,myTop];
}

function resFrm()
{
	window.setTimeout(function(){ top.frames[top.frames.length - 1].window.setAgences(); },200);
}

var wbo = { objectType: 'iframe', width: '990', height: '750' };
var gal_current = false;
function prepare_wherebuy()
{
	document.body.style.overflowX = 'hidden';
	wbo = { objectType: 'iframe', width: '690', height: '750' };
}
function no_new_pg(el)
{
	var tmp = document.getElementById('new-pga-big-img');
	if (tmp && typeof(gal_loaded) == 'boolean' && gal_loaded)
	{
// Новая фотогалерея, вывод карты туда
		if (gal_current)
		{
// Показана карта, надо ее убрать, вывести фото
			tmp.removeChild(tmp.lastChild,true);
			gal_current.style.display = '';
			gal_current = '';

			$('div.corners').get(0).style.display = 'block';

			el.innerHTML = '<span>Отель на карте</span>';
		}
		else
		{
// Показано фото, надо вывести карту
			for (var x = 0; x < tmp.childNodes.length; x++) if (tmp.childNodes[x] && tmp.childNodes[x].tagName && tmp.childNodes[x].tagName == 'LI' && tmp.childNodes[x].className == 'active')
			{
				tmp.childNodes[x].style.display = 'none';
				gal_current = tmp.childNodes[x];
			}
			x = document.createElement('IFRAME');
			x.width = tmp.offsetWidth;
			x.height = tmp.offsetHeight;
			x.border = 0;
			x.style.position = "relative";
			x.style.zIndex = "999";

			x.frameBorder = 0;

			x.setAttribute('scrolling',false);
			x.src = el.href + "&w=" + tmp.offsetWidth + "&h=" + tmp.offsetHeight;
			tmp.appendChild(x);

			$('div.corners').get(0).style.display = 'none';

			el.innerHTML = '<span>Показать фото</span>';
		}
		return false;
	}
	else
	{
		hs.skin.contentWrapper = 
	'<div class="highslide-header" align=right>'+
		'<h2 style="background:0;padding:0;float:left;">' + document.getElementsByTagName('H1')[0].innerHTML + '</h2>'+
		'<span class="highslide-move" style="display:none;">'+
			'<a href="#" onclick="return false"><img alt="Move" border="0" src="/i/or_c.gif" width="15" height="15" hspace="4" /></a>'+
		'</span>'+
		'<a id="cl_icn" href="#" style="text-transform:lowercase;" onclick="return hs.close(this)">закрыть</a>'+
	'</div>'+
	'<div id="agugu" class="highslide-body"></div>';
		window.setTimeout(hs_init,100);
		return true;
	}
}

function setCurrency(curr)
{
	var el = document.getElementsByTagName("SPAN");
	for (var x = 0; x < el.length; x++)
	{
		if (el[x].getAttribute("curr")) el[x].style.display = el[x].getAttribute("curr") == curr ? "" : "none";

		if (el[x].getAttribute("curr_ctrl")) el[x].className = el[x].getAttribute("curr_ctrl") == curr ? "" : "href";
	}
}
var jv_step = -1;
var jv_cur = 0;
var jv_new = 0;
function setJVBlock(el)
{
	if (el.className == "active" || el.className == "first_active" || jv_step >= 0) return;
	jv_step = 0;
	for (var x = 0; x < el.parentNode.rows.length; x++) if (el.parentNode.rows[x].className == "active" || el.parentNode.rows[x].className == "first_active")
	{
		el.parentNode.rows[x].className = (x == 0 ? "first" : "");
		el.className = (el.rowIndex == 0 ? "first_active" : "active");
//		$([el.parentNode.rows[x + 1].cells[0].firstChild.firstChild,el.parentNode.rows[el.rowIndex + 1].cells[0].firstChild.firstChild]).slideToggle(600);
		jv_cur = el.parentNode.rows[x + 1].cells[0].firstChild.firstChild;
		jv_new = el.parentNode.rows[el.rowIndex + 1].cells[0].firstChild.firstChild;
		jv_new.style.height = "0";
		window.setTimeout(jvAnimate,35);
		return;
	}
	jv_step = -1;
}
function jvAnimate()
{
	jv_step++;
	var x = jv_step * 15;
	jv_cur.style.height = (x > 127 ? 0 : (127 - x) + "px");
	jv_cur.firstChild.style.height = (x > 127 ? 0 : (127 - x) + "px");
	jv_new.style.height = (x > 127 ? "127px" : x + "px");
	jv_new.firstChild.style.height = (x > 127 ? "127px" : x + "px");
	if (x < 127)
	{
		if (jv_step == 1) jv_new.parentNode.parentNode.parentNode.style.display = "";
		window.setTimeout(jvAnimate,35);
	}
	else
	{
		jv_cur.parentNode.parentNode.parentNode.style.display = "none";
		jv_step = -1;
	}
}

function newsCatToggle(el)
{
	var d = el.parentNode.parentNode.cells[1].getElementsByTagName("DIV");
	if (d && d[0])
	{
		d = d[0];
		if (d.style.display == "none")
		{
			el.parentNode.parentNode.cells[0].style.backgroundImage = "url('/i/newscat_opened.gif')";
			$(d).slideToggle(800);
		}
		else
		{
			el.parentNode.parentNode.cells[0].style.backgroundImage = "url('/i/newscat_closed.gif')";
			$(d).slideToggle(800);
		}
	}

	return false;
}

function setDs(el,pid,id)
{
	var cd = el.parentNode.parentNode.getElementsByTagName("LI");
	for (var x = 0; x < cd.length; x++) cd[x].firstChild.className = "";
	el.className = "green2";

	var pd = document.getElementById("ds_" + pid);
	if (pd)
	{
		cd = pd.getElementsByTagName("DIV");
		for (x = 0; x < cd.length; x++) if (cd[x].id && cd[x].id.substr(0,3) == "ds_")
			cd[x].style.display = (cd[x].id == "ds_" + id ? "" : "none");
	}

	return false;
}

function setDc(el,pid,id)
{
	var cd = el.parentNode.parentNode.parentNode.getElementsByTagName("LI");
	for (var x = 0; x < cd.length; x++) cd[x].className = "";
	el.parentNode.parentNode.className = "gray";

	var pd = document.getElementById("ds_" + pid);
	if (pd)
	{
		cd = pd.getElementsByTagName("DIV");
		for (x = 0; x < cd.length; x++) if (cd[x].id && cd[x].id.substr(0,3) == "dc_")
			cd[x].style.display = (cd[x].id == "dc_" + id && cd[x].style.display == "none" ? "" : "none");
	}

	return false;
}

function setAgcityBlock()
{
	var l = document.getElementById("agcity_list");
	if (l)
	{
		if (l.style.display == "none")
		{
			var html = "";
			if (ag_arr) for (var x in ag_arr) if (x != ag_city)
				html += "<a href='#' style='background:url(\"/i/top-right.gif\") no-repeat;background-position:0 7px;padding:0 0 0 13px;display:block;' onClick='javascript:return setAgcity(" + x + ");'><u>" + ag_arr[x][0] + "</u></a>";

			x = document.getElementById("agcity_html");
			if (x) x.innerHTML = html;

			l.style.display = "";
			l.style.zIndex = 999999;
			keepAgcityBlock();
		}
		else l.style.display = "none";
	}

	return false;
}

function keepAgcityBlock()
{
	stayPopupIds["agcity_list"] = true;
	window.setTimeout(function() { stayPopupIds["agcity_list"] = false; },100);
}

function setAgcity(ct)
{
	if (ag_arr && ag_arr[ct])
	{
		if (document.images["agcity"]) document.images["agcity"].src = ag_arr[ct][1];
		var x = document.getElementById("agcity_text");
		if (x) x.innerHTML = ag_arr[ct][0];
		x = document.getElementById("agcity_links");
		if (x) x.innerHTML = ag_arr[ct][2];
		x = document.getElementById("wbuy");
		if (x) x.href = ag_arr[ct][3];
		ag_city = ct;

		if (tc_arr[ct])
		{
//			if (tc_city != ct) setTourBlock();
		}
		else
		{
//			if (tc_city != 0) setTourBlock();
		}

		x = new Date();
		x.setTime(x.getTime() + 86400000 * 14);
		set_cookie('mpp-ag-from', ag_city, x, '/', '.megapolus-tours.ru');
		set_cookie('mpp-ag-from', ag_city, x, '/', '.ute.ru');
	}

	var x = document.getElementById("agcity_list");
	if (x) x.style.display = "none";

	return false;
}

function setTourBlock()
{
	if (tc_arr)
	{
		var y = true;
		var z = false;
		for (x in tc_arr)
		{
			if (y)
			{
				z = tc_arr[x];
				z[z.length] = x;
			}
			y = (x == tc_city);
		}

		if (z)
		{
			if (document.images["tourcall"]) document.images["tourcall"].src = z[1];
			y = document.getElementById("tourcall_text");
			if (y) y.innerHTML = z[0];
			tc_city = z[z.length - 1];
			y = document.getElementById("tslink");
			if (y) y.innerHTML = tc_arr[tc_city][2];

			y = new Date();
			y.setTime(y.getTime() + 86400000 * 14);
			set_cookie('mpp-tc-from', tc_city, y, '/', '.megapolus-tours.ru');
			set_cookie('mpp-tc-from', tc_city, y, '/', '.ute.ru');

			if (tc_city && ag_arr[tc_city] && tc_city != ag_city) setAgcity(tc_city);
		}
	}

	return false;
}

function set_cookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + escape(path) : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");

	document.cookie = curCookie;
}

function preLoadImage(imageSrc) {
	var newImage = new Image();
	newImage.src = imageSrc;
	return(newImage);
}

var stayPopupIds = {};
function popups_close()
{
	var d = document.getElementsByTagName("DIV");
	for (var x = 0; x < d.length; x++) if (d[x].getAttribute("popupId"))
	{
		var y = stayPopupIds[d[x].getAttribute("popupId")];
		if (!y) d[x].style.display = "none";
		else if (y == "on") d[x].style.display = "";
	}
}

var eco = { objectType: "iframe", width: "90%", height: "90%", align: "center" };

function setEco()
{
	var x = getPageSize();

	eco["width"] = x[2] - 80;
	eco["height"] = x[3] - 60;
}

function setClick(el)
{
	if (el && typeof(el) == "string") el = document.getElementById(el);
	if (el && el.tagName)
	{
		if (document.createEvent)
		{
			var tmp = document.createEvent("MouseEvents");
			tmp.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 1, el);
			el.dispatchEvent(tmp);
		}
		else if (el.click) el.click();
	}
}

function setNumSuffix(num,s1,s2,s3)
{
	if (num)
	{
		num = new String(num);
		if (num.length == 1) num = "0" + num;
		if (num.length > 2) num = num.substr(num.length - 2);
	}
	else num = "00";
	num = [num.charAt(0),num.charAt(1)];

	if (num[0] == "1")
	{
		return s3;
	}
	else
	{
		if (num[1] == 1) return s1;
		else if (num[1] > 1 && num[1] < 5) return s2;
		else return s3;
	}
}

var msfCurStr = "";
var msfCurCity = ["","",""];
var msfInterval = 1;
var msfRType = "D0";
var msfChild = "5";

function msfCitySelect(el)
{
	if (el.value === el.getAttribute("_def")) el.value = "";
	el.style.color = "#000";
}

function msfCityGetHint(el)
{
	el.style.color = (el.value === msfCurCity[0] ? "#00408E" : "#000");

	if (el.value.length > 1)
	{
		if (el.value === msfCurStr) return;

		msfCurStr = el.value;

		var tmp = document.createElement("SCRIPT");
		tmp.src = "/get_city_hint.js.php?txt=" + msfCurStr;
		document.body.appendChild(tmp);
	}
	else msfCityHideHint(el);
}

function msfCityShowHint(str,arr)
{
	if (str === msfCurStr)
	{
		var tmp = document.getElementById("msfCityHint");

		if (tmp)
		{
			tmp = tmp.firstChild;

			tmp.innerHTML = "";
			for (var x = 0; x < arr.length; x++)
			{
				var y = document.createElement("DIV");
				y.style.padding = "2px";
				y.style.cursor = "pointer";
				y.onmouseover = msfOverHint;
				y.onmouseout = msfOutHint;
				y.onclick = msfCityClickHint;

				y.innerHTML = arr[x][0].replace(new RegExp("(" + str + ")", "gi"), "<span style=\"background:#FFF000;color:#000;\">$1</span>");

				y.setAttribute("_val",arr[x][0]);
				y.setAttribute("_code",arr[x][1]);
				y.setAttribute("_dest",arr[x][2]);

				tmp.appendChild(y);
			}

			if (tmp.innerHTML.length) tmp.parentNode.style.display = "";
			else msfCityHideHint();
		}
	}
}

function msfOverHint(e)
{
	if (!e) e = window.event;
//	alert(e);
	var src = (e.target ? e.target : e.srcElement);

	while(src.tagName != "DIV")
	{
		if (src.parentNode) src = src.parentNode;
		else break;
	}

	for (var x = 0; x < src.parentNode.childNodes.length; x++) if (src.parentNode.childNodes[x].tagName && src.parentNode.childNodes[x].tagName == "DIV")
	{
		src.parentNode.childNodes[x].style.background = "";
		src.parentNode.childNodes[x].style.color = "";
	}
	src.style.background = "#ABC337";
	src.style.color = "#FFF";
}

function msfOutHint(e)
{
	if (!e) e = window.event;
//	alert(e);
	var src = (e.target ? e.target : e.srcElement);

	while(src.tagName != "DIV")
	{
		if (src.parentNode) src = src.parentNode;
		else break;
	}

	for (var x = 0; x < src.parentNode.childNodes.length; x++) if (src.parentNode.childNodes[x].tagName && src.parentNode.childNodes[x].tagName == "DIV")
	{
		src.parentNode.childNodes[x].style.background = "";
		src.parentNode.childNodes[x].style.color = "";
	}
}

function msfCityClickHint(e)
{
	if (!e) e = window.event;
//	alert(e);
	var src = (e.target ? e.target : e.srcElement);

	while(src.tagName != "DIV")
	{
		if (src.parentNode) src = src.parentNode;
		else break;
	}

	var tmp = document.getElementById("msfCityDisplay");
	if (tmp)
	{
		msfCurCity = [src.getAttribute("_val"),src.getAttribute("_code"),src.getAttribute("_dest")];

		tmp.value = msfCurCity[0];

		tmp.style.color = "#00408E";
	}
}

function msfCityHideHint()
{
	var tmp = document.getElementById("msfCityHint");
	if (tmp) tmp.style.display = "none";

	tmp = document.getElementById("msfCityDisplay");
	if (tmp) tmp.style.color = (tmp.value === msfCurCity[0] ? "#00408E" : "#000");
}

function msfCityComplete(el)
{
	if (!el.value)
	{
		el.value = el.getAttribute("_def");
		el.style.color = "#949494";
	}
	else el.style.color = (el.value === msfCurCity[0] ? "#00408E" : "#000");
}

function msfSetInterval()
{
	var tmp = [document.getElementById("msfDateFrom"),document.getElementById("msfDateTo"),document.getElementById("msfInt")];

	if (tmp[0] && tmp[0].innerHTML && tmp[1] && tmp[1].innerHTML && tmp[2])
	{
		msfInterval = 0;

		tmp[0] = tmp[0].innerHTML.split("/");
		tmp[1] = tmp[1].innerHTML.split("/");

		if (tmp[0].length == 3 && tmp[1].length == 3)
		{
			tmp[0] = new Date(tmp[0][2],tmp[0][1] - 1,tmp[0][0]).getTime();
			tmp[1] = new Date(tmp[1][2],tmp[1][1] - 1,tmp[1][0]).getTime();

			if (tmp[0] > 0 && tmp[1] > tmp[0])
			{
				msfInterval = Math.round((tmp[1] - tmp[0]) / 86400000);
			}
		}

		tmp[2].innerHTML = (msfInterval ? msfInterval : "?") + setNumSuffix(msfInterval," ночь"," ночи"," ночей");
	}
}

function msfRTypeShowHint()
{
	var tmp = document.getElementById("msfRTypeHint");

	if (tmp)
	{
		tmp.setAttribute("popupId","");
		tmp.style.display = "";
		window.setTimeout(function() { document.getElementById("msfRTypeHint").setAttribute("popupId","msfRTypeHint"); }, 100);
	}
}

function msfRTypeClickHint(e)
{
	if (!e) e = window.event;
//	alert(e);
	var src = (e.target ? e.target : e.srcElement);

	while(src.tagName != "DIV")
	{
		if (src.parentNode) src = src.parentNode;
		else break;
	}

	var tmp = document.getElementById("msfRTypeDisplay");
	if (tmp)
	{
		msfRType = src.getAttribute("_code");

		tmp.innerHTML = src.innerHTML;
	}

	src.parentNode.parentNode.parentNode.parentNode.parentNode.rows[0].cells[2].style.visibility = (msfRType == "D1" || msfRType == "T1" ? "visible" : "hidden");
	src.parentNode.parentNode.parentNode.parentNode.cells[2].style.visibility = (msfRType == "D1" || msfRType == "T1" ? "visible" : "hidden");
}

function msfChildShowHint()
{
	var tmp = document.getElementById("msfChildHint");

	if (tmp)
	{
		tmp.setAttribute("popupId","");
		tmp.style.display = "";
		window.setTimeout(function() { document.getElementById("msfChildHint").setAttribute("popupId","msfChildHint"); }, 100);
	}
}

function msfChildClickHint(e)
{
	if (!e) e = window.event;
//	alert(e);
	var src = (e.target ? e.target : e.srcElement);

	while(src.tagName != "DIV")
	{
		if (src.parentNode) src = src.parentNode;
		else break;
	}

	var tmp = document.getElementById("msfChildDisplay");
	if (tmp)
	{
		msfChild = src.getAttribute("_code");

		tmp.innerHTML = src.innerHTML;
	}
}

function msfSendForm()
{
	var tmp = document.getElementById("msfCityDisplay");
	if (!msfCurCity[0] || !msfCurCity[1] || !msfCurCity[2] || !tmp || !tmp.value || tmp.value !== msfCurCity[0])
	{
		alert("Выберите город из списка");
		return false;
	}

	tmp = [document.getElementById("msfDateFrom"),document.getElementById("msfDateTo")];
	if (msfInterval < 1 || !tmp[0] || !tmp[0].innerHTML || !tmp[1] || !tmp[1].innerHTML)
	{
		alert("Выберите интервал дат (отъезд позднее прибытия)");
		return false;
	}
	tmp[0] = tmp[0].innerHTML.split("/");
	tmp[0] = tmp[0][2] + "-" + tmp[0][1] + "-" + tmp[0][0];
	tmp[1] = tmp[1].innerHTML.split("/");
	tmp[1] = tmp[1][2] + "-" + tmp[1][1] + "-" + tmp[1][0];

	location.href = "http://agents.megapolus-tours.ru/Default.aspx?pg=HotelRes&UserKey=376371316B2B38322F3369412F4A59376956615A51673D3D&CityCode=" + msfCurCity[1] + "&Destination=" + msfCurCity[2] + "&NumberOfRooms=1&room1_1=" + msfRType + "&age1_1=" + (msfRType == "D1" || msfRType == "T1" ? msfChild : "") + "&age1_2=&room2_1=&age2_1=&age2_2=&room3_1=&age3_1=&age3_2=&CheckIn=" + tmp[0] + "&NumberOfNights=" + msfInterval + "&CheckOut=" + tmp[1] + "&CurrencyCode=RUB&LanguageCode=6&AvailOnly=1&Stars=0&HotelName=";
//	location.href = "http://agents.megapolus-tours.ru/Default.aspx?pg=HotelRes&UserKey=6A47686E61384C786E4B596F2F725243337771724F513D3D&CityCode=" + msfCurCity[1] + "&Destination=" + msfCurCity[2] + "&NumberOfRooms=1&room1_1=" + msfRType + "&age1_1=" + (msfRType == "D1" || msfRType == "T1" ? msfChild : "") + "&age1_2=&room2_1=&age2_1=&age2_2=&room3_1=&age3_1=&age3_2=&CheckIn=" + tmp[0] + "&NumberOfNights=" + msfInterval + "&CheckOut=" + tmp[1] + "&CurrencyCode=RUB&LanguageCode=6&AvailOnly=1&Stars=0&HotelName=";
//	location.href = "http://test.mega.travelbepro.com/?UserKey=47594F314E64354F4B53734D4B6E552B58752F706D4638304C585733596C2F534F71514F667569693276553D&CityCode=" + msfCurCity[1] + "&room_1=" + msfRType + "&age_1=" + (msfRType == "D1" || msfRType == "T1" ? msfChild : "") + "&CheckIn=" + tmp[0] + "&NumberOfNights=" + msfInterval + "&CheckOut=" + tmp[1] + "&CurrencyCode=RUB&LanguageCode=6&AvailOnly=1&Stars=0&HotelName=";
}

function msfMTShowHint()
{
	var tmp = document.getElementById("mtHint");
	if (tmp) tmp.style.visibility = "visible";
}

function msfMTHideHint()
{
	var tmp = document.getElementById("mtHint");
	if (tmp) tmp.style.visibility = "hidden";
}

