var agt=navigator.userAgent.toLowerCase();
var is_fire     = ((agt.indexOf("firefox") != -1) );

function f_(n,d){
  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=f_(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
	
}
function preload_(){
  var d=document; if(d.images){ if(!d.im) d.im=new Array();
    var i,j=d.im.length,a=imgs; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){d.im[j]=new Image; d.im[j++].src=imgn(a[i]);d.im[j]=new Image; d.im[j++].src=imgn(a[i]+'_s');}}
    makepricesel();
    
}
function imgn(s){
	return '/i/tab_'+s+'.gif'
}
function tabc(tt){
	if(curtab!=tt){
		for(i=0;i<imgs.length;i++){
			o1 = f_('b'+imgs[i]);
			o2 = f_('tab'+imgs[i]);
			if(tt == imgs[i]){
				o1.src = '/i/tab_'+tt+'_s.gif'
				o2.style.display='block'
			}else{
				o1.src = '/i/tab_'+imgs[i]+'.gif'
				o2.style.display='none'
			}
		}
		curtab = tt;
	}
return false
}
var wnd;
function wpn(fn,w,h,tit,a,par){
	if(wnd)wnd.close();
	wnd = window.open(" ",'pics','width='+w+', height='+h+par);
	k=wnd.document; 
 	k.writeln("<html><head><title>"+tit+"</title></head><body bgcolor=white marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>");
	if(!a)k.writeln("<a href=# onclick='window.close()'>");
	k.writeln("<img src="+fn+" border=0 alt='"+tit+"'>");
	if(!a)k.writeln("</a>");
	k.writeln("<center></body></html>");
	return false;
}
function dds(){
		
}

var opens = new Array();
var ts = new Array();
var wtime = 300;
var imgs = new Array('swiss')

var opens2 = new Array();
var ts2 = new Array();
var wtime2 = 500;
var imgs2 = new Array('bookform')

function restore_(){
	for(i=1;i<=imgs.length;i++)if(opens["m"+i]){
		ts['m'+i] = setTimeout("clear('m"+i+"')", wtime);
	}
}
function clear(id){
	cnt = id.substring(1);
	clearTimeout(ts[id]);
	if((x =f_(id))!=null)x.style.display='none';
}
function swap_(obj){
	cnt = obj.substring(1);
	clearTimeout(ts["m"+cnt]);
	x1 = f_(obj);
	if((y = f_("m"+cnt))!=null){
		topy = gettop(x1)		
		if(is_fire){
			y.style.top=-10;
			y.style.left=-1;
			y.style.position='absolute'
		}else{
			y.style.top=topy+23;
		}
		y.style.display='block';
	}
	opens["m"+cnt]=1;
}

function onmenu(o){
	cnt = o.id.substring(1);
	clearTimeout(ts["m"+cnt]);
	opens["m"+cnt] = 1 ;
}

function outmenu(o){
	cnt = o.id.substring(1);
	ts["m"+cnt] = setTimeout("clear('m"+cnt+"')", wtime);
}


function restore2_(){
	for(i=1;i<=imgs2.length;i++)if(opens2["b"+i]){
		ts2['b'+i] = setTimeout("clear2('b"+i+"')", wtime2);
	}
}
function clear2(id){
	cnt = id.substring(1);
	clearTimeout(ts2[id]);
	if((x =f_(id))!=null)x.style.display='none';
}
function swap2_(obj){
	cnt = obj.substring(1);
	clearTimeout(ts2["b"+cnt]);
	x1 = f_(obj);
	if((y = f_("b"+cnt))!=null){
		topy = gettop(x1)
		topx = getleft(x1)		
		if(is_fire){
			y.style.top=1;
			y.style.left=1;
			y.style.position='absolute'
		}else{
			y.style.position='absolute'
		}
		y.style.display='block';
	}
	opens2["b"+cnt]=1;
}

function onmenu2(o){
	cnt = o.substring(1);
	clearTimeout(ts2["b"+cnt]);
	opens2["b"+cnt] = 1 ;
}

function outmenu2(o){
	cnt = o.substring(1);
	ts2["b"+cnt] = setTimeout("clear2('b"+cnt+"')", wtime2);
}


function gettop(o){
	var val=0;
	if(o.offsetParent)val=gettop(o.offsetParent);
	return o.offsetTop+val;
}
function getleft(o){
	var val=0;
	if(o.offsetParent)val=getleft(o.offsetParent);
	return o.offsetLeft+val;
}
function swp(ob,wi){
	ob.className = 'bt'+wi+'s';
}
function rst(ob,wi){
	ob.className = 'bt'+wi;
}
function educ(id){
	url = '/education/?ajax&cid='+id;
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = educupdate;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = educupdate;
            req.open("GET", url, true);
            req.send();
        }
    }
}
function educupdate(){
	if (req.readyState == 4) {
        if (req.status == 200) {
			//done
			//alert('done ' + req.responseText);
			o=f_('edulang');
			o.innerHTML = req.responseText;
         }
    }
}

function makepricesel(){
	o1 = f_("pricesel");
	if(o1!=null && o1!=undefined){
		url = '/order/ajax/pricesel/?valuta='+curval;
		//alert(url)
		if (window.XMLHttpRequest) {
	        req = new XMLHttpRequest();
	        req.onreadystatechange = priceupsel;
	        req.open("GET", url, true);
	        req.send(null);
	    } else if (window.ActiveXObject) {
	        isIE = true;
	        req = new ActiveXObject("Microsoft.XMLHTTP");
	        if (req) {
	            req.onreadystatechange = priceupsel;
	            req.open("GET", url, true);
	            req.send();
	        }
	    }
	}
}
function priceupsel(){
	if (req.readyState == 4) {
        if (req.status == 200) {
			o=f_('pricesel');
			o.innerHTML = req.responseText;
			o=f_('valuta');
			changeprice(o)
         }
    }
}

function changeprice(o){
	if(o){
		val = o.options[o.selectedIndex].value
		var col = document.getElementsByTagName("b")
		var loadremote = false;
		for(i=0;i<col.length;i++){
			if(col[i].className=="prc"){
				if(col[i].price==undefined){col[i].price=new Array();col[i].price[val]=''}
				if(col[i].price[val])col[i].innerHTML = col[i].price[val]
				else{
				     loadremote = true
				     col[i].price[curval] = col[i].innerHTML
				}
			}
		}
		if(loadremote){
			url = '/order/ajax/getcurs/?valuta='+val;
			//alert(url)
			if (window.XMLHttpRequest) {
		        req = new XMLHttpRequest();
		        req.onreadystatechange = chprice;
		        req.open("GET", url, true);
		        req.send(null);
		    } else if (window.ActiveXObject) {
		        isIE = true;
		        req = new ActiveXObject("Microsoft.XMLHTTP");
		        if (req) {
		            req.onreadystatechange = chprice;
		            req.open("GET", url, true);
		            req.send();
		        }
		    }
	    }else{
	    	url = '/order/ajax/getcurs/?valuta='+val+'&touch';
			//alert(url)
			if (window.XMLHttpRequest) {
		        req = new XMLHttpRequest();
		        req.onreadystatechange = null;
		        req.open("GET", url, true);
		        req.send(null);
		    } else if (window.ActiveXObject) {
		        isIE = true;
		        req = new ActiveXObject("Microsoft.XMLHTTP");
		        if (req) {
		            req.onreadystatechange = null;
		            req.open("GET", url, true);
		            req.send();
		        }
		    }
	    }
		curval = val;
		f1 = f_('totalrub')
		if(f1!=undefined){
			if(curval=='RUB')f1.style.display='none'
			else f1.style.display='table-row'
		}
	}
}
var valcurs;
function chprice(){
	if (req.readyState == 4) {
        if (req.status == 200) {
			eval(req.responseText);
			//alert(req.responseText);
			var col = document.getElementsByTagName("b")
			for(i=0;i<col.length;i++){
				if(col[i].className=="prc"){
					pr = parseFloat(col[i].oprice);
					//alert(col[i]['attributes'][1]['value']+' '+pr);
					if(col[i]['attributes'][1]!=undefined){
						if(!pr )pr = parseFloat(col[i]['attributes'][1]['value'])
					}
					if(pr){
						ov = col[i].oval;if(!ov)ov = col[i]['attributes'][0]['value']
						//alert(ov)
						if(pr){
							coef = 1.03;
							if(ov==curval)coef =1;
							if(curval.toUpperCase()=="RUB")newpr = pr * remotecurs[ov]
							else newpr = pr * remotecurs[ov]/remotecurs[curval.toUpperCase()]
							newpr = Math.ceil(newpr * coef)
							col[i].innerHTML = newpr + " " + curval 
						}else{
							col[i].innerHTML = "0 " + curval
						}
					}
				}
			}
			if(aftervalchange)eval(aftervalchange)
			
         }
    }
}

function updatetourprice(utof){
	prpe = {SGL:1,DBL:2,TPL:3}
	pricetype=1;
	tourroom = f_('tourroom');if(tourroom)tr = tourroom.options[tourroom.selectedIndex].value;
	tourpeople = f_('tourpeople');if(tourpeople){tr = tourpeople.options[tourpeople.selectedIndex].value;pricetype=2}
	tourvar = f_('tourvar');tv = tourvar.options[tourvar.selectedIndex].value;
	extra =f_('extra');if(extra)ex = extra.checked?1:0;
	if(pricetype==1)baseprice = (people = prpe[tr]) * (oneprice =tprice[tv][tr]);
	if(pricetype==2)baseprice = (people = tr) * (oneprice = tprice[tv]['SGL']);
	
	if(!utof && pricetype==1){
		ex2 = prpe[tr];
		if(!extra.disabled)ex2+=ex;
		updatetouroptionq(ex2)
	}
	if(!utof && pricetype==2)updatetouroptionq(tr)
	if(extra&& ex && tr=='DBL')baseprice+=tprice[tv]['EXTRA'];
	valuto = varval;
	price = priceval(baseprice,varval,curval);
	str = '<b class="prc" id="oprtotal" oprice="'+baseprice+'" oval="'+varval+'"><strong>'+price+' '+curval+'</strong></b> ('+people+' x <b class="prc" id="oprone" oprice="'+oneprice+'" oval="'+varval+'">'+priceval(oneprice,varval,curval)+' '+curval+'</b> за 1 человека';
	if(extra && ex && tr=='DBL')str+=' + <b class="prc" id="oprext" oprice="'+tprice[tv]['EXTRA']+'" oval="'+varval+'">'+priceval(tprice[tv]['EXTRA'],varval,curval)+ ' ' +curval +'</b> за доп.кровать';
	str+=')'
	o=f_('upd1');o.innerHTML=str;
	if(touroptg.length){
		for(i=0;i<touroptg.length;i++){
			o=f_('to'+touroptg[i].idv);
			if(o.checked){o2=f_('toq'+touroptg[i].idv);
			pv = priceval(touroptg[i].price,touroptg[i].valuta,curval);
			price+=pv*parseInt(o2.options[o2.selectedIndex].value)}
		}
	}
	o=f_('prtotal');
	o.innerHTML = price + ' '+curval;
}

function updatetouroptionq(num){
	if(touroptg.length){
		for(i=0;i<touroptg.length;i++){
			o=f_('toq'+touroptg[i].idv);
			o.selectedIndex = num-1;
		}
	}
}

function priceval(price,oldval,newval){
	if(newval!=oldval){
		if(newval=="RUB")newprice = price * valcurs[oldval] * 1.03
		else newprice = price * valcurs[oldval]/valcurs[newval] * 1.03
		newprice = Math.ceil(newprice)
	}else newprice=price
	return newprice	
}

