var LinkDivActive = 0;
var onDiv;
var timeOnDiv;
var layerRef;
var styleRef;
var showVar;
var hideVar;
var hideDivi;
var showDivi;

if (navigator.appName == "Netscape") {
 layerRef="document.";
 styleRef="";
 showVar="'show'";
 hideVar="'hide'";
 showDivi="''";
 hideDivi="'none'";
} else {
 layerRef="document.all.";
 styleRef=".style";
 showVar="'visible'";
 hideVar="'hidden'";
 showDivi="''";
 hideDivi="'none'";
}

function changeCity(val) {
	if (val=='') document.getElementById('othertourcity').style.display='';
	else document.getElementById('othertourcity').style.display='none';
}

//Divisions Show | Hide
function switchDiv(divn) {
	eval('if ('+layerRef+divn+styleRef+'.visibility == '+hideVar+') {showDiv(divn);} else {hideDiv(divn);}');
}

function shineDiv(divn,className) {
 eval(layerRef+divn+'.className = "'+className+'"');
}

function hideDiv(divn) {
 eval(layerRef+divn+styleRef+'.visibility = '+hideVar);
 eval(layerRef+divn+styleRef+'.display = '+hideDivi);
}
function showDiv(divn) {
 eval(layerRef+divn+styleRef+'.visibility = '+showVar);
 eval(layerRef+divn+styleRef+'.display = '+showDivi);
}

//Link Divisions Stuff
function showLinkDiv(divn) {
 if (timeOnDiv != null) {
  clearTimeout(timeOnDiv);
  hideDiv(onDiv);
 }
 showDiv(divn);
 onDiv = divn;
}

function divTimer() {
 timeOnDiv = setTimeout("divOut()",500)
}

function divOut() {
 if (LinkDivActive == 0) {
  hideDiv(onDiv);
 } 
}

function LinkDivOver() {
 LinkDivActive = 1;
 clearTimeout(timeOnDiv);
}

function LinkDivOut() {
 LinkDivActive = 0;
 timeOnDiv = setTimeout("divOut()",500)
}

function check_form (confirmMsg) {
	var is_confirmed = confirm(confirmMsg);
	return is_confirmed;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
 window.open(theURL,winName,features);
}
function selectPath(startpath,elid,elid1,itemid) {
	itemid=parseInt(itemid);
//	if (itemid>0) {itemid=itemid+'/';}
	var s = showModalDialog(startpath+"?urbanid="+itemid, "", "font-family:Verdana;font-size:12;dialogWidth:50em;dialogHeight:41em");
	if (s) {
		document.getElementById(elid).innerHTML='<img src="../gallery/tumb/'+itemid+'/'+s+'" border=0>';
		document.getElementById(elid1).value=s;
	}
}
function selectPathNew(startpath,elid,elid1,itemid) {
	itemid=itemid;
	var win = window.open(startpath+"?urbanid="+itemid+"&elid="+elid+"&elid1="+elid1, "", "scrollbars=yes,resizable=yes,width=400,height=500,left=150,top=100");
}
function removeItem(remIt) {
	var is_confirmed = confirm('Удалить?');
	if (is_confirmed) {
		location.href=remIt;
	}
}

function open_winiid(url) {
mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=550,height=414');
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//AJAX functions started
var req,ab;
 
function loadXMLDoc(url,functionName) {
	url=url+"&rndseed="+Math.round(Math.random() * 99999999);
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        eval('req.onreadystatechange = '+functionName);
        req.open("GET", url, true);
        req.send(null);
    ab = window.setTimeout("req.abort();", 5000);
     } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            eval('req.onreadystatechange = '+functionName);
            req.open("GET", url, true);
            req.send();
    ab = window.setTimeout("req.abort();", 5000);
         }
    }
}

function stat(n)
{
  switch (n) {
    case 0:
      return "не инициализирован";
    break;
 
    case 1: 
      return "загрузка...";
    break;
 
    case 2: 
      return "загружено";
    break;
 
    case 3: 
      return "в процессе...";
    break;
 
    case 4: 
      return "готово";
    break;
 
    default:
      return "неизвестное состояние";  
  }  
}
function ShowRows(){
	for(a=1;a<50;a++) {
		if (document.getElementById("hideid" + a)) {
			document.getElementById("hideid" + a).style.visibility = "visible";
			document.getElementById("hideid" + a).style.display = "";
		}
	}
	document.all.item("imgp1").style.display = "none";
	document.all.item("imgm1").style.display = "";
}

function HideRows(){
	for(a=1;a<50;a++) {
		if (document.getElementById("hideid" + a)) {
			document.getElementById("hideid" + a).style.visibility = "hidden";
			document.getElementById("hideid" + a).style.display = "none";
		}
	}
	document.all.item("imgp1").style.display = "";
	document.all.item("imgm1").style.display = "none";
}
function ShowRow(a){
	document.getElementById("imgs" + a).style.visibility = "visible";
	document.getElementById("imgs" + a).style.display = "";
	document.all.item("imgp"+a).style.display = "none";
	document.all.item("imgm"+a).style.display = "";
}

function HideRow(a){
	document.getElementById("imgs" + a).style.visibility = "hidden";
	document.getElementById("imgs" + a).style.display = "none";
	document.all.item("imgp"+a).style.display = "";
	document.all.item("imgm"+a).style.display = "none";
}

function orderSubmit() {
	if (document.getElementById('tourpeoplescount') && !parseInt(document.getElementById('tourpeoplescount').value)) {
		alert('Укажите кол-во людей в группе');
		document.getElementById('tourpeoplescount').focus();
		return false;
	}
	if (document.getElementById('tourphone').value.length<=3) {
		alert('Заполните поле "Телефон (с кодом)"');
		document.getElementById('tourphone').focus();
		return false;
	}
	if (document.getElementById('tourname').value.length<=3) {
		alert('Заполните поле "Ваше имя"');
		document.getElementById('tourname').focus();
		return false;
	}
	if (document.getElementById('tourmail').value.length<=3) {
		alert('Заполните поле "Электронная почта"');
		document.getElementById('tourmail').focus();
		return false;
	}
	
	var peoplecount = parseInt(document.getElementById('tourpeoplescount').value);
	if (document.getElementById('pay') && document.getElementById('pay').value=='pay' && peoplecount>itemvoucherscount) {
		alert('Недостаточное количество путевок!');
		document.getElementById('tourpeoplescount').focus();
		return false;
	}
	
	return true;
}

function calcTourCost() {
	var peoplecount = parseInt(document.getElementById('tourpeoplescount').value);
	if (!peoplecount) {
		peoplecount = 1;
		document.getElementById('tourpeoplescount').value = 1;
	}
	
	var tourcost = peoplecount*itemprice;
	var totalcost = Math.ceil(tourcost/0.965);
	var bankcost = totalcost-tourcost;
	
	document.getElementById('tourcost').innerHTML = tourcost+' руб.';
	if (document.getElementById('bankcost')) document.getElementById('bankcost').innerHTML = bankcost+' руб.';
	if (document.getElementById('totalcost')) document.getElementById('totalcost').innerHTML = totalcost+' руб.';
}