//alert(navigator.appName);
function BIGFOTO(xg_id, xid, mode)
{
	W=window.open("/misc/galery_image.php?g_id="+xg_id+"&id="+xid+"&mode="+mode,"b_ph","width=1020,height=800,left=0,top=0,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
}
function Search()
{
	document.Search.submit();
}
function createRequestObject() 
{
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer") ro = new ActiveXObject("Microsoft.XMLHTTP");
    else ro = new XMLHttpRequest();
    return ro;
}

var http = createRequestObject();
function goAjax(url)
{
//	alert(url);
    http.open("get", url);
   	http.onreadystatechange = handleResponse;
    http.send(null);
}
function handleResponse()
{
    if(http.readyState == 4)
	{
        var response = http.responseText;
        var update = new Array();
        if(response.indexOf('|' != -1)) 
		{
            update = response.split('|');
			length_=update.length;
			for (i=0; i<=length_; i=i+2)
			{
//				alert(update[i]+"-"+update[i+1])
				if (document.getElementById(update[i])) document.getElementById(update[i]).innerHTML = update[i+1];
			}
        } 
    }
}
function AllPhotos(id, mode, lang, event)
{
	document.getElementById("allphotos").innerHTML="";
	url="/misc/photos.php?g_id="+id+"&mode="+mode+"&lang="+lang;
	goAjax(url);

	if (!event) event=window.event;
	coorY=event.clientY;
	var pW = getPageSize();
	var x = document.body.clientWidth;
	var y = document.body.scrollTop;
	document.getElementById("overlay").style.width = x+"px";
	document.getElementById("overlay").style.height = pW[1]+"px";
	document.getElementById("overlay").style.display = "inline";

	WidthPhotos=x-500;
	TopPhotos=coorY+y-300;
//	alert(TopPhotos+"-"+coorY+"-"+y)
//	document.getElementById("allphotos").style.top = TopPhotos+"px";
	document.getElementById("allphotos").style.left = "235px";
	document.getElementById("allphotos").style.width = "700px";
	document.getElementById("allphotos").style.display = "inline";
//	document.getElementById("flash").style.display = "none";
}
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 // Explorer Mac...would also work in Explorer 6 Strict, 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;

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function Resize(event)
{
	if (document.getElementById("overlay").style.display=="inline")
	{
		var pW = getPageSize();
		document.documentElement.scrollLeft = 10000; // Определяем размер скролла
		var x = document.documentElement.scrollLeft+document.body.clientWidth;;
		document.documentElement.scrollLeft = 0; // И возвращаем скроллер обратно в ноль

		document.getElementById("overlay").style.width = x+"px";
		document.getElementById("overlay").style.height = pW[1]+"px";
	}
}
///////////////////////////////////////////////////////////////////////////
function hides()
{
	document.getElementById("overlay").style.display="none";
	document.getElementById("allphotos").style.display="none";		
	document.getElementById("flash").style.display="inline";		
}
function Search2(mode)
{
	id=document.getElementById(mode).value;
	url="/misc/search.php?mode="+mode+"&id="+id;
	goAjax(url);
}
function Search4(mode)
{
	id=document.getElementById(mode).value;
	url="/misc/search_detail.php?mode="+mode+"&id="+id;
	goAjax(url);
}
function Search3(mode, id)
{
	flag=false;
	if (mode=="o2" || mode=="s2")
	{
		if (document.TourOrder.name.value=="")
		alert("Введите имя");
		else flag=true;
		if (document.TourOrder.phone.value=="")
		alert("Введите контактный телефон");
		else flag=true;
	}
	if (mode=="o3") {document.TourOrder.tour_id.value=id; flag=true; document.TourOrder.action="/order/";}
	if (flag) document.TourOrder.submit();

	if (mode=="o" || mode=="s")
	{
		document.Searchtour.mode.value=mode;
		document.Searchtour.submit();
	}
}

function Order()
{
	flag=1;
	if (document.Avia.secondname.value=='')
	{
		alert('Не заполнено поле "Фамилия"');
		document.Avia.secondname.focus();
		flag=0;
		return;
	}
	if (document.Avia.name.value=='')
	{
		alert('Не заполнено поле "Имя"');
		document.Avia.name.focus();
		flag=0;
		return;
	}
	if (document.Avia.country.value=='')
	{
		alert('Не заполнено поле "Страна"');
		document.Avia.country.focus();
		flag=0;
		return;
	}
	if (document.Avia.numberman.value=='')
	{
		alert('Не заполнено поле "Общее количество человек"');
		document.Avia.numberman.focus();
		flag=0;
		return;
	}
	if (document.Avia.numberman.value=='')
	{
		alert('Не заполнено поле "Количество человек"');
		document.Avia.numberman.focus();
		flag=0;
		return;
	}
	if (document.Avia.phone.value=='')
	{
		alert('Не заполнено поле "Контактный телефон"');
		document.Avia.phone.focus();
		flag=0;
		return;
	}
	if (flag==1)
	{
		document.Avia.sent.value=1;
		document.Avia.submit();
	}
}

function Sort(order, direct)
{
	document.Sorts.order.value=order;
//	document.Sorts.direct.value=direct;
	document.Sorts.submit();
}

function Selects(id, num)
{
	select=document.getElementById(id);
	document.getElementById("sel_div"+num).innerHTML=select.options[select.selectedIndex].text;
}

function SearchCruise()
{
	document.SearchCruise.submit();
}
function OnFocus(always, object, mode)
{
	if (mode==1)
	{
		if (object.value==always) object.value="";
	}
	else
	{
		if (object.value=="")
		{
			object.value=always;
		}
	}
}
