var centerLoader = '<center>Загрузка...</center>';

function switchLoader(lMode){
	var loader = document.getElementById('loader');
	if (lMode == 'on') {
		loader.style.visibility = 'visible';
		loader.innerHTML = 'Загрузка...';
	}
	if (lMode == 'off') {
		loader.style.visibility = 'hidden';
		loader.innerHTML = '';
	}
}




function getStat() {
	document.getElementById('show_stat').innerHTML = centerLoader;
	var url = '/index.php?'+getFormData('stat_select_form');
	xmlHttp.open('GET', url, true);
	xmlHttp.onreadystatechange = showStat;
	xmlHttp.send(null);
}

function showStat(){
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var response = xmlHttp.responseText;
			document.getElementById('show_stat').innerHTML = response;
		}
	}
}


function swPage(section, title) {
	document.getElementById('page_title').innerHTML = title;
	document.getElementById('action').value = section;
	page = section;
	getStat();
}

function sendForm(formID) {
	switchLoader('on');
	var url = '/index.php?'+getFormData(formID);
	xmlHttp.open('GET', url, true);
	xmlHttp.onreadystatechange = showStat;
	xmlHttp.send(null);
}


function addTracker(formID) {
	var url = '/index.php?' + getFormData(formID);
	xmlHttp.open('GET', url, true);
	xmlHttp.onreadystatechange = showInfo;
	xmlHttp.send(null);
}

function showInfo(){
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var response = xmlHttp.responseText;
			document.getElementById('alerts_wrap').innerHTML = response;
		}
	}
}


function approoveWithdraw(pID) {
	document.getElementById('appr'+pID).innerHTML = 'Обработка...'
	var url = '/index.php?action=admin_payments&approove=1&id='+pID;
	xmlHttp.open('GET', url, true);
	xmlHttp.onreadystatechange = approoveWithdrawDo;
	xmlHttp.send(null);
}
function approoveWithdrawDo(){
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var response = xmlHttp.responseText;
			if (isNaN(response)) {
				alert(response);
				return;
			}
			document.getElementById('appr'+response).innerHTML = 'complete'
		}
	}
}



function selectOption(sID,tracker){
	for (var i=0;i<$(sID).options.length;i++) {
		if ($(sID).options[i].value == tracker) {
			$(sID).selectedIndex = i;
			break;
		}
	}
}


function ShowOrHide(d1, d2) {
  if (d1 != '') DoDiv(d1);
  if (d2 != '') DoDiv(d2);
}
function DoDiv(id) {
  var item = null;
  if (document.getElementById) {
	item = document.getElementById(id);
  } else if (document.all){
	item = document.all[id];
  } else if (document.layers){
	item = document.layers[id];
  }
  if (!item) {
  }
  else if (item.style) {
	if (item.style.display == "none"){ item.style.display = ""; }
	else {item.style.display = "none"; }
  }else{ item.visibility = "show"; }
}

function showWithdrInfo(val){
	if (val == 'Наличными') {
		$('withdraw_description').innerHTML = 'Вывод наличными доступен только в Москве и Санкт-Петербурге';
	} else {
		if (val == 'Другой способ') {
			$('withdraw_description').innerHTML = '<p>Опишите желаемый способ вывода.</p><textarea name="comment" style="width:250px;height:100px;font-size:11px;"></textarea>';
		} else {
			$('withdraw_description').innerHTML = '';
		}
	}
}



