var cityArray = new Array('kharkov','simferopol','sevastopol','yalta');
var cityNamesArray = new Array();
cityNamesArray['kharkov'] = 'Харькове';
cityNamesArray['simferopol'] = 'Симферополе';
cityNamesArray['sevastopol'] = 'Севастополе';
cityNamesArray['yalta'] = 'Ялте';
var ui={};



//функция записывает данные в куки
function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
//функция считывания данных из куки
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	//alert(setStr);
	return(setStr);
}


function getCityFromCookie() {
	ui.city=getCookie('kebcity');
	if (ui.city == 'undefined' || !ui.city || ui.city == '') { 
		document.getElementById('title_sel_city').innerHTML = 'КЕБ такси в вашем городе';
		Effect.Appear('title_sel_city');
	} else {
		document.getElementById('title_sel_city').innerHTML = 'КЕБ такси в ' + cityNamesArray[ui.city];
		Effect.Appear('title_sel_city');
		if (!document.getElementById('new_index_contacts')) { Effect.Appear('new_main_contacts'); }
		else { Effect.Appear('new_index_contacts'); }
		Effect.Appear(ui.city);
	}
}
function selectCity(id) {
	if (!document.getElementById('new_index_contacts')) {
		if (document.getElementById('new_main_contacts').style.display == 'none') { Effect.Appear('new_main_contacts'); }
	} else {
		if (document.getElementById('new_index_contacts').style.display == 'none') { Effect.Appear('new_index_contacts'); }
	}
	for (i = 0; i < cityArray.length; i++) {
		if (cityArray[i] != id) { document.getElementById(cityArray[i]).style.display = 'none'; }		
	}
	Effect.Appear(id);
	ui.city = id;
	document.getElementById('title_sel_city').style.display = 'none';
	document.getElementById('title_sel_city').innerHTML = 'КЕБ такси в ' + cityNamesArray[id];
	Effect.Appear('title_sel_city');
	setCookie('kebcity',id,'Mon 02-Jan-2050 00:00:00 GMT');
}
function getPage(page) {
	if (!ui.city || ui.city == 'undefined' || ui.city == 'null' || ui.city == '') { link = ''; }
	else { link = '-' + ui.city; }
	if (page == 'vacancy' || page == 'contacts') { location.href = page + link + '.php'; } 
	else if ((page == 'services' && (!ui.city || ui.city == 'undefined' || ui.city == 'null' || ui.city == '')) || page == 'about' || page == 'actions') { location.href = page + '.php'; }
	else if (page == 'services') { location.href = 'tariff' + link + '.php'; }
}


function onlineOrderNew() {
	
	new Effect.Appear('online_order_block_new');
	
}
function orderClose() {
	
	new Effect.Fade('online_order_block_new');
	
}
function sendReqNew() {
	link = 'http://www.kebtaxi.com.ua/includes/order.php';
	params = getRequestForm();
	waitLoading('online_order_request');
	var request=new Ajax.Request(
			link,
				{
					parameters: params,
				    evalScripts: false,
					onSuccess: orderRequestRespone
				}
			);/*
	var request=new Ajax.Request(
			link + 'xml/',
			{
				parameters: params,
			    evalScripts: false,
				onSuccess: orderRequestRespone
			}
		);*/
}

function orderRequestRespone(transport) {
	var response=transport.responseText;
	var res = document.getElementById('online_order_request');		
	res.innerHTML = response;
}


function getRequestForm() {
	var oForm = document.forms['onlineorder'];
    var aParams = new Array();
            
	for (var i=0 ; i < oForm.elements.length; i++) {
        var sParam = encodeURIComponent(oForm.elements[i].name);
        sParam += "=";
        sParam += encodeURIComponent(oForm.elements[i].value);
    	aParams.push(sParam);
    } 
            
	aParams.join("&");
	
	return aParams.join("&");
			
}


//Визуализация загрузки---------------
	function waitLoading(id) {
		
		var obj = document.getElementById(id);
	
		obj.innerHTML = '<div class="wait_loading_block"><span class="wait_loading">идет загрузка...</span></div>';
		
	}