﻿
(function($) {
$(function() {

  $("#box-subscribe").load("http://venagid.ru/js/box-subscribe.txt");
  $("#box-hotel-banner").load("http://venagid.ru/go/hotel/h.php");
  $("#box-hotel-singlepost").load("http://venagid.ru/go/hotel/h3.php");
  $("#box-avia").load("http://venagid.ru/js/box-avia.txt");
  $("#menu-avia").load("http://venagid.ru/js/menu-avia.txt");
  $("#panel-menu").load("http://venagid.ru/js/panel-menu.txt");
  

})
})(jQuery)


// <![CDATA[
var us_msg = {missing: "Не задано обязательное поле: \"%s\"", invalid: "Недопустимое значение поля: \"%s\"", email_or_phone: "Не задан ни email, ни телефон"};
var us_charset = "";
var us_isPopup = false;
function us_setCharset() {
	var d = document;
	var f = d.getElementById('us_form');
	var charset = us_charset ? us_charset : (d.characterSet ? d.characterSet : d.charset);  // http://stackoverflow.com/questions/318831
	f.setAttribute('enctype', 'application/x-www-form-urlencoded; charset=' + charset);
}

function us_onSubmit() {
	function trim(s) {
		return s == null ? '' : s.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	}

	var d = document;
	var f = d.getElementById('us_form');
	if (!f) {
		alert('Internal error: form not found.');
		return false;
	}
	
	var ee, i, e, n, v, r, k;
	var hasEmail = false;
	var hasPhone = false;

	ee = f.getElementsByTagName('input');
	for (i = 0;  i < ee.length;  i++) {
		e = ee[i];
		n = e.getAttribute('name');
		if (!n || e.getAttribute('type') != 'text') {
			continue;
		}

		v = trim(e.value);
		if (v == '') {
			k = e.getAttribute('_required');
			if (k == '1') {
				alert(us_msg['missing'].replace('%s', e.getAttribute('_label')));
				e.focus();
				return false;
			}
			continue;
		}

		if (n == 'email') {
			hasEmail = true;
		} else if (n == 'phone') {
			hasPhone = true;
		}
		
		k = e.getAttribute('_validator');
		r = null;
		switch (k) {
			case null:
			case '':
				break;
			case 'email':
				// TODO Provide regexps from PHP code (added getEmailValidationRegexp_forJavascript() to functions.php).
				r = /^[a-zA-Z0-9_+=-]+[a-zA-Z0-9\._+=-]*@[a-zA-Z0-9][a-zA-Z0-9-]*(\.[a-zA-Z0-9]([a-zA-Z0-9-]+))*\.([a-zA-Z]{2,6})$/;
				break;
			case 'phone':
				r = /^[\d +()\-]{7,32}$/;
				break;
			case 'float':
				r = /^[+\-]?\d+(\.\d+)?$/;
				break;
			default:
				alert('Internal error: unknown validator "' + k + '"');
				e.focus();
				return false;
		}
		if (r && !r.test(v)) {
			alert(us_msg['invalid'].replace('%s', e.getAttribute('_label')));
			e.focus();
			return false;
		}
	}

	if (!hasEmail && !hasPhone) {
		alert(us_msg['email_or_phone']);
		return false;
	}

	return true;
}
function us_onLoad() {
	us_setCharset();
}
// ]]>
