var swap=0;
$(document).ready(function(){
    $( "#dialog" ).dialog({
        autoOpen: false,
        show: "blind",
        hide: "explode"
        });
    $( "#help" ).click(function() {
        $( "#dialog" ).dialog( "open" );
        return false;
        });
    });
function checkLeadingZeros(numberValue){
    var decimalMask1=/^\d{1,3}/;
    var decimalMask2=/\/{1}\d{1,2}/;
    var decimalMask3=/ {1}Êê{1}\d{1,2}/;
    if(numberValue.search(decimalMask2)!==-1){
        };
    if(numberValue.search(decimalMask3)!==-1){
        };
    return true;};
function checkNumber(numberValue){
    var numberMask=/^\d{1,3}[[ÀÁÂÃÄÅ¨ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäå¸æçèéêëìíîïðñòóôõö÷øùúûüýþÿ]|[\/{1}\d{1,2}]]?[ {1}Êê{1}\d{1,2}]?[ {1}Ññ{1}Òò{1}Ðð{1}]?$/;
    if(numberValue.search(numberMask)==-1){
        return false;}
    else{
        return checkLeadingZeros(numberValue);};};
function initParams(){
        var myForm=document.getElementById("myForm");
        myForm.method='post';
		myForm.submit();};
function enter(){
    var select5=document.getElementById("select5");
    var select6=document.getElementById("select6");
    if(select5.selectedIndex!=0 && select6.selectedIndex!=0){
        if(select5.selectedIndex>select6.selectedIndex){
            swap=select5.selectedIndex;
            select5.selectedIndex=select6.selectedIndex;
            select6.selectedIndex=swap;};};
    var select7=document.getElementById("select7");
    var select8=document.getElementById("select8");
    if(select7.selectedIndex!=0 && select8.selectedIndex!=0){
        if(select7.selectedIndex>select8.selectedIndex){
            swap=select7.selectedIndex;
            select7.selectedIndex=select8.selectedIndex;
            select8.selectedIndex=swap;};};
    var select9=document.getElementById("select9");
    var select10=document.getElementById("select10");
    if(select9.selectedIndex!=0 && select10.selectedIndex!=0){
        if(select9.selectedIndex>select10.selectedIndex){
            swap=select9.selectedIndex;
            select9.selectedIndex=select10.selectedIndex;
            select10.selectedIndex=swap;};};
    if(select6.selectedIndex!=0){
        if((select7.selectedIndex>select5.selectedIndex && select7.selectedIndex>select6.selectedIndex) || (select8.selectedIndex>select5.selectedIndex && select8.selectedIndex>select6.selectedIndex)){
            alert('Ýòàæ êâàðòèðû íå ìîæåò áûòü áîëüøå ýòàæíîñòè äîìà!');
            return false;};};
    var select11=document.getElementById("select11");
    var select12=document.getElementById("select12");
    if(select11.selectedIndex!=0 && select12.selectedIndex!=0){
        if(select11.selectedIndex>select12.selectedIndex){
            swap=select11.selectedIndex;
            select11.selectedIndex=select12.selectedIndex;
            select12.selectedIndex=swap;};};
    var select13=document.getElementById("select13");
    var select14=document.getElementById("select14");
    if(select13.selectedIndex!=0 && select14.selectedIndex!=0){
        if(select13.selectedIndex>select14.selectedIndex){
            swap=select13.selectedIndex;
            select13.selectedIndex=select14.selectedIndex;
            select14.selectedIndex=swap;};};
    var select15=document.getElementById("select15");
    var select16=document.getElementById("select16");
    if(select15.selectedIndex!=0 && select16.selectedIndex!=0){
        if(select15.selectedIndex>select16.selectedIndex){
            swap=select15.selectedIndex;
            select15.selectedIndex=select16.selectedIndex;
            select16.selectedIndex=swap;};};
    var select17=document.getElementById("select17");
    var select18=document.getElementById("select18");
    if(select17.selectedIndex!=0 && select18.selectedIndex!=0){
        if(select17.selectedIndex>select18.selectedIndex){
            swap=select17.selectedIndex;
            select17.selectedIndex=select18.selectedIndex;
            select18.selectedIndex=swap;};};
    if(select14.selectedIndex!=0 && select15.selectedIndex!=0){
        if(select14.selectedIndex<select15.selectedIndex){
 			alert('Îáùàÿ ïëîùàäü íå ìîæåò áûòü ìåíüøå æèëîé ïëîùàäè!');
            return false;};};
    if(select14.selectedIndex!=0 && select17.selectedIndex!=0){
        if(select14.selectedIndex<select17.selectedIndex){
 			alert('Îáùàÿ ïëîùàäü íå ìîæåò áûòü ìåíüøå ïëîùàäè êóõíè!');
            return false;};};
    if(select14.selectedIndex!=0 && select15.selectedIndex!=0 && select17.selectedIndex!=0){
        if(select14.selectedIndex<(select15.selectedIndex+select17.selectedIndex)){
 			alert('Îáùàÿ ïëîùàäü íå ìîæåò áûòü ìåíüøå ñóììû æèëîé ïëîùàäè è ïëîùàäè êóõíè!');
            return false;};};
   	number=document.getElementById('number');
	if(!number.value || number.value=='Ëþáîé'){
		initParams();}
	else{
        number.value=number.value.toLowerCase();
		if(!checkNumber(number.value)){
			alert('Ââåä¸í íåêîððåêòíûé íîìåð äîìà!');
			number.value='Ëþáîé';
			number.focus();
			return false;}
		else{
			initParams();};};};
window.onload=function(){
    window.resizeTo(1024,768);
    window.resizable='no';
    window.scrollbars='no';
	var body_=document.getElementById('body_');
	body_.style.visibility='visible';};
