//dojo.require("dojox.validate.web");
var validKey;
function message(e) {
	dojo.stopEvent(e);
	var mes = dojo.byId("message"),
		name = dojo.byId("messageName"),erName = dojo.byId("errorName"),
		email = dojo.byId("messageMail"),erEmail = dojo.byId("errorMail"),
		text = dojo.byId("messageText"),erText = dojo.byId("errorText"),
		code = dojo.byId("messageCode"),erCode = dojo.byId("errorCode"),erSub = dojo.byId("errorSubmit");
	erSub.style.display = 'none';
	erName.style.display = 'none';
	erEmail.style.display = 'none';
	erCode.style.display = 'none';
	erText.style.display = 'none';
	if(name.value == ''){erName.style.display = '';return}
	if(email.value == ''){erEmail.style.display = '';return}
	if(text.value == ''){erText.style.display = '';return}
	if(code.value == ''){erCode.style.display = '';return}
    var getArgs = {
        url: "message.php",
        form: mes,
        content: { submit: ""}
    }
    var getHandler = dojo.xhrPost(getArgs);
    getHandler.addCallback(function(html){
		if(dojo.trim(html) == '0'){erSub.style.display = '';}
		else if(dojo.trim(html) == '1'){erCode.style.display = '';}
		else{
			alert(html);
			name.value = '';
			email.value = '';
			text.value = '';
			code.value = '';
			var image = dojo.byId('imgCode');
			var srcImage = image.src;
			image.src = '';
			image.src = srcImage;
		}
        return html;
    });
}

function valid(e, t){
	dojo.fixEvent(e);
	dojo.stopEvent(e);
	var f = t['form'], l;
	validKey = 0;
	dojo.query('input[type=text]', f).style('border', 'solid 1px green');
	if(dojo.query('input[type=radio][value=1]', f)[0].checked){
		l = dojo.query('input[type=text]', f);
	}else{
		l = dojo.query('input[type=text]:not([name^=rep])', f);
	}

	l.forEach(function(item){
		item.style.border = 'solid 1px red';
		if(item.value == ''){return;}
		//if(item.name.indexOf('email') >= 0 && !dojox.validate.isEmailAddress(item.value)){return}

		var flags = {
			format: [
				"###-###-####","###-##-####","###-#-####",
				"### ###-##-##","### ##-##-##","### #-##-##",
				"(###) ###-####","(###) ##-####","(###) #-####",
				"(###) ###-##-##","(###) ##-##-##","(###) #-##-##",
				"(###) ### ####","(###) ## ####","(###) # ####",
				"(###) ### ## ##","(###) ## ## ##","(###) # ## ##",
				"### ### ####","### ## ####","### # ####",
				"##########","#########","########"
			]
		};

//neneka_alfa@mail.ru
//345 345-56-56

		//if(item.name.indexOf('tel') >= 0 && !dojox.validate.isNumberFormat(item.value, flags)){return}
		validKey++;
		item.style.border = 'solid 1px green';
	});
	if(validKey == l.length){f.submit();}
}
function step(e, t){
	dojo.fixEvent(e);
	dojo.stopEvent(e);
	var stepNav = dojo.query('.txtblock h5 a');
	stepNav.removeClass('stepCur');
	stepNav.removeClass('sel');
	dojo.addClass(t, 'stepCur');
	dojo.addClass(t, 'sel');
	var tt = dojo._getText(t.href);
	dojo.byId('content1').innerHTML = tt;
}
function sub(e, t){
	dojo.stopEvent(e);
	t.parentNode.parentNode.submit();
}
function viewSub(e, t, k){
	dojo.stopEvent(e);
	var yy = dojo.byId(k);
	var node = dojo.query('.subMenu').concat(dojo.query('.subMenu2'));
	node.forEach(function(item){
		if(item != yy)dojo.addClass(item, 'not');
	})
	var ew = dojo.coords(t,true);
	yy.style.left = ew.x+ew.w+6+'px';
	yy.style.top = ew.y-(18)+'px';
	if(dojo.hasClass(yy, 'not')){dojo.removeClass(yy,'not');}else{dojo.addClass(yy,'not');}
}
function viewSubMenu(e, t, k){
	dojo.stopEvent(e);
	var yy = dojo.byId(k);
	var node = dojo.query('.subMenu').concat(dojo.query('.subMenu2'));
	node.forEach(function(item){
		if(item != yy)dojo.addClass(item, 'not');
	})
	var ew = dojo.coords(t.parentNode, true);
	yy.style.left = ew.x+'px';
	yy.style.top = ew.y+ew.h-(dojo.isKhtml?8:0)+'px';
	if(dojo.hasClass(yy, 'not')){dojo.removeClass(yy,'not');}else{dojo.addClass(yy,'not');}

}
dojo.addOnLoad(function(){


handle = dojo.connect(dojo.body(), 'onclick', function(){
	var node = dojo.query('.subMenu').concat(dojo.query('.subMenu2'));
	node.forEach(function(item){
		dojo.addClass(item, 'not');
	})
});
});
dojo.addOnUnload(function(){
	dojo.disconnect(handle);
});
