﻿
function validForm(){
		$('zakaz').addEvent('click', function(e){
		var error=0;
			new Event(e).stop();
		
		var isEmpty = new InputValidator('required', {
			errorMsg: function (field){
				
				},
			test: function(field){
				if ((field.get('value') == null) || (field.get('value').length == 0)){
					if($chk(field.get('error')))
						alert( field.get('error') );
					return true;
					}
				return false;	
					
			}
		});
			
			if(isEmpty.test($("fio"))){error=1;	}
			if(isEmpty.test($("text"))){error=1;	}
			
		ph=0;
		if($('phone').value==''){
				if($('mail').value==''){
						error=1; alert($('phone').get('error')); }
				}
		
		
		var uri="ajax.php?action=sendform";
		for(var i=0;i<this.length;i++){
			uri+="&"+this.elements[i].name+"="+this.elements[i].value;
			}
		
		
			if(!error){
				windows = new Element("div",{"id":"windows","class":"loader"});
				windows.inject(document.body);
				windows.style.left=screen.width/2-100+"px";//e.page.x-150+"px";
				windows.style.top=screen.height/2+10+"px";//e.page.y-150+"px";
				
				var req = new Request({url:uri,
				onSuccess: function(txt){/*alert(txt);*/$('answere_request').innerHTML=txt; windows.destroy();} ,
				onFailure: function(){alert("Запрос не удалось выполнить");}
						});	
				//$('sendform').send();
				//window.location.href($('sendform').toQueryString(););
				window.location.href = "/zakaz.form?"+$('sendform').toQueryString();
		
		
				}	
			
			
		});
}



