function dCard() {
	var o = document.getElementById('cfio');
	var fio = o.value;

	if (fio == '') {
		alert('Вы не указали фамилию, имя, отчество');
		o.focus();
		return false;
	}


	o = document.getElementById('cphone');
	var phone = o.value;

	if (!isPhone(phone)) {
		alert('Введите телефон в формате XXX XXX XX XX');
		o.focus();
		return false;
	}

	o = document.getElementById('cemail');
	var email = o.value;


        JsHttpRequest.query(
            '/card.php', // backend
            {
                'fio': fio, 
                'phone': phone, 
                'email': email, 
            },

            // Function is called when an answer arrives. 
            function (result, errors) {
                // Write errors to the debug div.
                //document.getElementById("debug").innerHTML = errors;
                // Write the answer.
			//document.getElementById(star0).innerHTML = '';
			if (result['STATUS'] != '') {
				alert(result['STATUS']);
			}
			if (result['N'] > 0) {
				document.getElementById('cardImage').innerHTML = '<center><a href="/card.php?n=' + result['N'] + '" target="_blank"><img src="/card.php?n=' + result['N'] + '" width="400" height="259" alt="дисконтная карта" title="дисконтная карта"></a></center>';
				//document.getElementById('cardSubmit').disabled=true;
				document.getElementById('cardForm').style.visibility='hidden';
				document.getElementById('cardForm').style.display='none';
			}
            },
            true  // do not disable caching
        );
		return false;
}

function isPhone(s) {
	return s.match('^\\s*\\(?\\d\\d\\d\\)?\\s*\\d\\d\\d\\s*\\d\\d\\s*\\d\\d\\s*$');
}



function onlineOrder() {
	var o = document.getElementById('cfio');
	var fio = o.value;

	if (fio == '') {
		alert('Вы не указали фамилию, имя, отчество');
		o.focus();
		return false;
	}


	o = document.getElementById('cphone');
	var phone = o.value;

	if (!isPhone(phone)) {
		alert('Введите телефон в формате XXX XXX XX XX');
		o.focus();
		return false;
	}

	o = document.getElementById('cmetro');
	var metro = o.value;

	if (metro == '') {
		alert('Вы не указали метро');
		o.focus();
		return false;
	}


	o = document.getElementById('cwhat');
	var what = o.value;
	if (what == '') {
		alert('Вы не указали что сломалось');
		o.focus();
		return false;
	}


	o = document.getElementById('cmodel');
	var model = o.value;

	if (model == '') {
		alert('Вы не указали марку');
		o.focus();
		return false;
	}

	o = document.getElementById('ccomments');
	var comments = o.value;


        JsHttpRequest.query(
            '/online.php', // backend
            {
                'fio': fio, 
                'phone': phone, 
                'metro': metro, 
                'what': what, 
                'model': model, 
                'comments': comments, 
            },

            // Function is called when an answer arrives. 
            function (result, errors) {
                // Write errors to the debug div.
                //document.getElementById("debug").innerHTML = errors;
                // Write the answer.
			//document.getElementById(star0).innerHTML = '';
			if (result['STATUS_ERROR'] != '') {
				document.getElementById('results').innerHTML = result['STATUS_ERROR'];
			}
			if (result['STATUS_OK'] != '') {
				document.getElementById('results').innerHTML = result['STATUS_OK'];
				document.getElementById('onlineForm').style.visibility='hidden';
				document.getElementById('onlineForm').style.display='none';
			}
            },
            true  // do not disable caching
        );
		return false;
}
