function show(id)
{
	var target = "f"+5;
	var buf = document.getElementById(target);
	buf.style.display = "none";

	for (var i=1; i<=4; i++)
	{
		var target = "f"+i;
		var buf = document.getElementById(target);
		buf.style.display = "none";
		var target = "m"+i;
		var buf = document.getElementById(target);
		buf.style.backgroundColor = "bbbbbb";
		var target = "a"+i;
		var buf = document.getElementById(target);
		buf.style.color = "2d2715";
	}
	var target = "f"+id;
	var buf = document.getElementById(target);
	buf.style.display = "";
	var target = "m"+id;
	var buf = document.getElementById(target);
	buf.style.backgroundColor = "2d2715";	
	var target = "a"+id;
	var buf = document.getElementById(target);
	buf.style.color = "dddddd";
	var img1 = document.getElementById('img1');
	var img4 = document.getElementById('img4');
	var td1 = document.getElementById('td1');
	var td4 = document.getElementById('td4');
	if (id == 1)
	{
		img1.src = "images/flt.gif";
		img4.src = "images/frt.gif";
		td1.style.backgroundColor = "2d2715";
		td4.style.backgroundColor = "bbbbbb";
	}
	if (id == 2)
	{
		img1.src = "images/flt2.gif";
		img4.src = "images/frt.gif";
		td1.style.backgroundColor = "bbbbbb";
		td4.style.backgroundColor = "bbbbbb";
	}
	if (id == 3)
	{
		img1.src = "images/flt2.gif";
		img4.src = "images/frt.gif";
		td1.style.backgroundColor = "bbbbbb";
		td4.style.backgroundColor = "bbbbbb";		
	}
	if (id == 4)
	{
		img1.src = "images/flt2.gif";
		img4.src = "images/frt2.gif";
		td1.style.backgroundColor = "bbbbbb";
		td4.style.backgroundColor = "2d2715";
	}	
}

function mySubmit(mode)
{
	mode = mode || 'simple';
	
	for (var i=1; i<=6; i++)
	{
		var buf = document.getElementById('w'+i);
		buf.style.display = "none";
	}
	var buf = document.getElementById('diverrmes');
	buf.innerHTML = "&nbsp;";

	var city_from = document.getElementById('city_from').value;
	var city_to = document.getElementById('city_to').value;
	var c1 = document.getElementById('c1').value;
	var c2 = document.getElementById('c2').value;
	var phone = document.getElementById('phone').value;
	var mail = document.getElementById('mail').value;
	var price = document.getElementById('price').checked;
	
	JsHttpRequest.query(
		'send.php',
		{'mode': mode, 'city_from': city_from, 'city_to': city_to, 'c1': c1, 'c2': c2, 'phone': phone, 'mail': mail, 'price': price},
		function(result, errors) {
			sendDone(result, mode);
		},
		true
	);
	return false;	
}

function sendDone(result, mode)
{
	var temp = new Array();
	temp = result.split('#');
	if (temp[0]>0)
	{
		var buf = document.getElementById('w'+temp[0]);
		buf.style.display = "";
		var buf = document.getElementById('diverrmes');
		buf.innerHTML = '<img src="images/warning.jpg" width="26" height="18" align="absmiddle">'+temp[1];
	}
	else
	{
		var from = $('#city_from').val();
		var to = $('#city_to').val();
		var dateFrom = $('#c1').val();
		var dateTo = $('#c2').val();
		var price = ($('#price:checked').length?1:0);
		var phone = document.getElementById('phone').value;
		var mail = document.getElementById('mail').value;
		window.location = 'booking?mode='+mode+'&from='+from+'&to='+to+'&dateFrom='+dateFrom+'&dateTo='+dateTo+'&price='+price+'&phone='+phone+'&mail='+mail;
	}
}

function subscribe(id)
{
	var submail = document.getElementById('submail').value;
	JsHttpRequest.query('subscribe.php',{id: id, submail: submail}, 
	function(result, errors) {subscribeDone(result);}, true);
	return false;		
}

function subscribeDone(result)
{
	alert(result);
}

function showNews(id)
{
	var buf = document.getElementById('news'+id);
	var nlink = document.getElementById('nlink'+id);
	var nimg = document.getElementById('nimg'+id);
	if (buf.style.overflow == "")
	{
		buf.style.height = "39px";
		buf.style.overflow = "hidden";
		nlink.innerHTML = "Подробнее";
		nimg.src = "images/arrowr.gif";
	}
	else 
	{
		buf.style.height = "100%";
		buf.style.overflow = "";
		nlink.innerHTML = "Свернуть";
		nimg.src = "images/arrowl.gif";
	}
}

function checkTrip()
{
	var code = document.getElementById('code').value;
	var fam = document.getElementById('fam').value;
	window.open('checktrip?code='+$('#code').val()+'&lastname='+$('#fam').val());

	return false;
}

function getUrlParameterValue(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) {
		return '';
	}
	else {
		return unescape(results[1]);
	}
}



/**
 * sprintf() for JavaScript v.0.4
 *
 * Copyright (c) 2007 Alexandru Marasteanu <http://alexei.417.ro/>
 * Thanks to David Baird (unit test and patch).
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */

function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }

function sprintf () {
  var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
  while (f) {
    if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
    else if (m = /^\x25{2}/.exec(f)) o.push('%');
    else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
      if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
      if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
        throw("Expecting number but found " + typeof(a));
      switch (m[7]) {
        case 'b': a = a.toString(2); break;
        case 'c': a = String.fromCharCode(a); break;
        case 'd': a = parseInt(a); break;
        case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
        case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
        case 'o': a = a.toString(8); break;
        case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
        case 'u': a = Math.abs(a); break;
        case 'x': a = a.toString(16); break;
        case 'X': a = a.toString(16).toUpperCase(); break;
      }
      a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
      c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
      x = m[5] - String(a).length;
      p = m[5] ? str_repeat(c, x) : '';
      o.push(m[4] ? a + p : p + a);
    }
    else throw ("Huh ?!");
    f = f.substring(m[0].length);
  }
  return o.join('');
}

