var xmlHttp = createXmlHttpRequestObject();

// Выполнение ассинхронного запроса для получения параметров пользователя
function getRates() {
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == 0 ) {
		xmlHttp.open( 'GET',  '/ajax_php/ajax_rate.php', true );
		
		//alert( lang + '/ajax_php/ajax_corr_passport.php?sel_variant=' + selVariant + '&data=' + data );
		xmlHttp.onreadystatechange = handleRateResponse;
		xmlHttp.send( null );
	}
	else {
		// если соединение занято, повторим запрос через децл времени
		setTimeout( 'getCorrPassport( ' +selVariant+ ', ' +data+ ' )', 100 );
	}
}

// Обработка ответа сервера получения параметров пользователя
function handleRateResponse() {
	if ( xmlHttp.readyState == 4 ) {
		if ( xmlHttp.status == 200 ) {
			xmlResponse = xmlHttp.responseXML;
			xmlRoot = xmlResponse.documentElement;
			
			// отображение
			div_ajax = document.getElementById( 'div_rates' );
			
			if ( xmlRoot.getElementsByTagName( 'response_error' ).item(0).firstChild.data != 0 ) {
				div_ajax.innerHTML = '<br><FONT color=red>' + xmlRoot.getElementsByTagName( 'response_error_text' ).item(0).firstChild.data + '</FONT>';
			}
			else {
				resHTML = "<TABLE border=0 cellpadding=3 cellspacing=0 width=100%>";
				resHTML += "<tr><td height=40 colspan=3 class='green' style='padding-left:10px; color: #006e51; '><strong>Курсы системы </strong></td></tr>";
				
				rates = xmlRoot.getElementsByTagName('rate');
				for ( var counter=0; counter < rates.length; counter++ ) {
					if ( counter % 2 == 0 )
						add_style = "bgcolor='e5f0ed'";
					else add_style = "";
					resHTML += 
						"<tr " + add_style + ">" +
							"<td style='padding-left:10px;'>" + rates.item(counter).getAttribute('curr') + "</td>" + 
							"<td>" + rates.item(counter).getAttribute('buy') + " </td>" + 
							"<td>" + rates.item(counter).getAttribute('sale') + " </td>" + 
						"</tr>";
				}
				resHTML += "</TABLE>";
				div_ajax.innerHTML = resHTML;
			}
		}
		else {
			alert( 'Ошибка при попытке получения сведений о курсах валют: ' + xmlHttp.statusText );
		}
	}
}
