	var d=document;
	
	
	function userSetPhone(action){
		
		var tel=d.getElementById('frm_reg').tel;
		
		if (action=='in'){
			if (tel.value == 'x xxx xxxxxxx') {
				tel.value = '';
			}
			
		}
		else {
			if (!tel.value) {
				tel.value = 'x xxx xxxxxxx';
			}
		}
	}
	
	function userCheckParamOut(code){
		var frm=d.getElementById('frm_reg');
		var errmsg='';
		if (code=='1'){
				errmsg='Неверный формат Email';
				frm.email.style.backgroundColor='#ff4500';
		}
		
		if (code == '2') {
				errmsg='Неверный формат Телефона';
				frm.tel.style.backgroundColor='#ff4500';
		}
		
		if (code == '3') {
				errmsg='Пользователь с таким адресом Email уже зарегистрирован.';
				frm.email.style.backgroundColor='#ff4500';
		}
		
		if (code == '4') {
			errmsg="&nbsp;";
			frm.submit();
		}
		
		if (code=='5'){
			errmsg="Неправильный антиспам код";
			frm.captcha.style.backgroundColor='#ff4500';
		}
		
		d.getElementById('user_err_msg').innerHTML=errmsg;
	}

	function userCheckParam(){
		var frm=d.getElementById('frm_reg');
		var errmsg='';
		frm.uname.style.backgroundColor='#B9C7EA';
		frm.email.style.backgroundColor='#B9C7EA';
		frm.tel.style.backgroundColor='#B9C7EA';
		frm.address.style.backgroundColor='#B9C7EA';
		frm.pass.style.backgroundColor='#B9C7EA';
		frm.pass2.style.backgroundColor='#B9C7EA';
		

 		if (!frm.uname.value) {
			errmsg='Укажите Ваше имя';
			frm.uname.style.backgroundColor='#ff4500';
		}
		
		if (!errmsg && !frm.email.value){
			errmsg='Укажите Ваш Email';
			frm.email.style.backgroundColor='#ff4500';
		}

		if (!errmsg && (!frm.tel.value || frm.tel.value=='x xxx xxxxxxx')){
			errmsg='Укажите Ваш телефон';
			frm.tel.style.backgroundColor='#ff4500';
		}

		if (!errmsg && !frm.address.value){
			errmsg='Укажите Ваш адрес';
			frm.address.style.backgroundColor='#ff4500';
		}		

		if (!errmsg && !frm.pass.value){
			errmsg='Укажите Пароль';
			frm.pass.style.backgroundColor='#ff4500';
		}		
		
		if (!errmsg && (frm.pass2.value!=frm.pass.value)){
			errmsg='Неправильное подтверждение пароля';
			frm.pass2.style.backgroundColor='#ff4500';
		}

		if (errmsg) {
			d.getElementById('user_err_msg').innerHTML = errmsg;
		}
		else {
			var bufArr=new Array();
			bufArr['telno']=frm.tel.value;
			bufArr['email']=frm.email.value;
			bufArr['captcha']=frm.captcha.value;
			d.getElementById('user_err_msg').innerHTML = 'Проверка параметров';
			req.open(null, '/jscript/common.php', true);
			req.send({
				param: bufArr,
				query: 'checkUserRegParam',
				callback: 'userCheckParamOut'
			})
		}
	}
	
	function userChangeBrandOut(params){		
		var id=params['id'];
		var prod_list=params['prod_list'];
		
		var select=d.getElementById('select_prod_'+id);
		select.options.length=0;
		for (i=0;i<prod_list.length;i++){
			select.options[i]=new Option(prod_list[i]['name'],prod_list[i]['id']);
		}		
		d.getElementById('user_err_msg').innerHTML='';
	}
	
	function userChangeBrand(id){
			d.getElementById('user_err_msg').innerHTML='Обновление данных';
			var arrBuf=new Array();
			arrBuf['cat_id']=d.getElementById('select_cat_'+id).value;			
			arrBuf['brand_id']=d.getElementById('select_brand_'+id).value;
			arrBuf['id']=id;

			req.open(null, '/jscript/common.php', true);
			req.send({
				param: arrBuf,
				query: 'userChangeBrand',
				callback: 'userChangeBrandOut'
			});
	}



	function userChangeCatOut(params){
		var id=params['id'];
		var brand_list=params['brand_list'];
		
		var select=d.getElementById('select_brand_'+id);
		select.options.length=0;
		
		for (i=0;i<brand_list.length;i++){
			select.options[i]=new Option(brand_list[i]['name'],brand_list[i]['id']);
		}
		
		setTimeout("userChangeBrand("+id+")",10);
		
	}
	
	function userChangeCat(id){	
			d.getElementById('user_err_msg').innerHTML='Обновление данных';
			var cat_id=d.getElementById('select_cat_'+id).value;
			var arrBuf=new Array();
			arrBuf['cat_id']=cat_id;
			arrBuf['id']=id;
			
			req.open(null, '/jscript/common.php', true);
			req.send({
				param:arrBuf,
				query: 'userChangeCat',
				callback: 'userChangeCatOut'
			});
	}
	
	function userFormAction(type){
		var frm=d.getElementById('frm_notify');
		frm.p_loaded.value=type;
		frm.submit();
	}
	
	function userRegister(){
		window.location='/user/regi/';
	}
	

	
