var ur_sts="1";

function clr_frm(){
	document.regs.reset();
	document.getElementById("c_img").innerHTML="<img src='/nums.php?rinds="+Math.random()+"' width=130 height=40>";
}

function chk_frm(){
	var tmp_str,strrr;
	shw_w_img();
	
	with(document.regs){
		if(u_sts.value=="0"){
			var chk_elm=["login","pass","pass2","fio","mail","cnt","u_sts","p_adr","p_num","p_dt","p_issue","p_valid","res"];
		}else{
			var chk_elm=["login","pass","pass2","fio","mail","cnt","u_sts","res"];
		}
		for(var i=0;i<chk_elm.length;i++){
			if(elements[chk_elm[i]].value==""){
				alert(lang_pack['js_msg1']);
				elements[chk_elm[i]].focus();
				document.getElementById("wht_img").style.display="none";
				return false;
			}
			
			if(elements[chk_elm[i]].name=="login"||elements[chk_elm[i]].name=="pass"||elements[chk_elm[i]].name=="pass2"){
				tmp_str=elements[chk_elm[i]].value;
				if(chk_prm('0',tmp_str)==false){
					alert(lang_pack['js_msg2']);
					elements[chk_elm[i]].focus();
					document.getElementById("wht_img").style.display="none";
					return false;
				}
			}
		}
		if(pass.value!=pass2.value){
			alert(lang_pack['js_msg3']);
			pass2.focus();
			document.getElementById("wht_img").style.display="none";
			return false;
		}
		
		if(u_sts.value!="0"){
			tmp_str="";
			for(var i=0;i<chk_elm.length;i++){
				if(elements[i].name!="pass2"){
					tmp_str+="<"+elements[chk_elm[i]].name+">"+elements[chk_elm[i]].value+"</"+elements[chk_elm[i]].name+">";
				}
			}
			strrr="<cats>"+tmp_str+"</cats>";
			makePOSTRequest("/chk_xml.php?act=reg"+"&ridss="+Math.random(), "xmls="+strrr,alertContents1,'text/plain');
		}else{
			if(document.snd_file.file.value==""){
				alert(lang_pack['js_msg92']);
				document.getElementById("wht_img").style.display="none";
				return false;
			}else{
				if(ofert_s.checked==false){
					alert(lang_pack['js_msg93']);
					ofert_s.focus();
					document.getElementById("wht_img").style.display="none";
					return false;
				}
				chk_img_pass();
			}
		}
	}
	
}

function chk_prm(wht,chkstr){
	var res;
	switch(wht){
		case '0':
			var pattern=/^[a-z0-9_]{6,}$/i;
		break;
	}	
	tmpstr=chkstr;
	res=pattern.exec(chkstr);
	if(res==null){
		return false;
	}else{
		return true;
	}
}

function alertContents1() {
    if (http_request.readyState==4){ 
        if (http_request.status==200){ 
			document.getElementById("wht_img").style.display="none";
			var err_lst= new Array(lang_pack['js_msg4'],lang_pack['js_msg5'],lang_pack['js_msg6'],lang_pack['js_msg7'],lang_pack['js_msg2'],lang_pack['js_msg8']);
			var tmpstr=http_request.responseText;
			var tmp_arr;
			tmp_arr=tmpstr.split("<!--err-->");
			if(tmp_arr[1]!=undefined){
				alert(err_lst[tmp_arr[1]]);
				if(tmp_arr[1]=='2'){
					document.getElementById("c_img").innerHTML="<img src='/nums.php?rinds="+Math.random()+"' width=130 height=40>";
				}
			}else{
				var pattern=/^get_img-[0-9]+$/i;
				var res=pattern.exec(http_request.responseText);
				if(ur_sts=='0' && res!=null){
					ur_sts='1';
					var tmp_str=http_request.responseText;
					tmp_str=tmp_str.split("-");
					if(parseInt(tmp_str[1])!=0){
						with(document.snd_file){
							shw_w_img();
							action="/chk_xml.php?act=chek_img&do="+parseInt(tmp_str[1])+"&ridss="+Math.random();
							submit();
						}
					}else{
						alert(lang_pack['js_msg9']);
						document.getElementById("wht_img").style.display="none";
					}					
				}else{
					document.getElementById("cnts").innerHTML=http_request.responseText;
					document.getElementById("wht_img").style.display="none";
				}
			}
        }else{
            alert(lang_pack['js_msg9']);
			document.getElementById("wht_img").style.display="none";
        }
    }
}

function opt_sts_chng(){
	var elmnts=['passp_dt','offert_chk','frm_upload'];
	var sts_display= document.regs.u_sts.value=='0' ? 'block' : 'none';
	for(var i=0;i<elmnts.length;i++){
		document.getElementById(elmnts[i]).style.display=sts_display;
	}
	if(sts_display=="block"){
		var pos=getElementPosition("upload_spacer");
		with(document.getElementById("frm_upload").style){
			top=pos.top+"px";
		}
	}
}

function chk_img_pass(){
	with(document.snd_file){
		action="/chk_xml.php?act=chek_img&ridss="+Math.random();
		submit();
	}
}

function chk_img_answer(answer,prn){
	if(answer=='0'){
		with(document.regs){
			var tmp_str=new String();
			var chk_elm=["login","pass","pass2","fio","mail","cnt","u_sts","p_adr","p_num","p_dt","p_issue","p_valid","res"];
			for(var i=0;i<chk_elm.length;i++){
				tmp_str+="<"+elements[chk_elm[i]].name+">"+elements[chk_elm[i]].value+"</"+elements[chk_elm[i]].name+">";
			}
			tmp_str="<cats>"+tmp_str+"</cats>";
			ur_sts="0";
			shw_w_img();
			makePOSTRequest("/chk_xml.php?act=reg&ridss="+Math.random(), "xmls="+tmp_str,alertContents1,'text/plain');
		}
	}else{
		if(prn){
			document.getElementById("cnts").innerHTML=answer;
		}else{
			alert(answer);
		}
		document.getElementById("wht_img").style.display="none";
	}
}
