var xmlhttp = null;

function SendTempPass(frm){
	if(frm.id.value.length==0){
		alert("아이디를 입력해주세요");
		frm.id.focus();
		return false;
	}
	if(frm.id_check.value!="Y"){
		alert("가입여부를 확인해주세요");
		//document.getElementById('ChkBtn').focus();
		return false;
	}
	if(frm.email.value.length==0){
		alert("가입시 지정하신 이메일을 입력해주세요");
		frm.email.focus();
		return false;
	}
	if(CheckEmailPolicy(frm.email.value)=="1"){
		alert("이메일 주소의 * 부분을 정확히 입력하세요");
		frm.email.focus();
		return false;
	}else{
		ProcSendPass(frm,'linking_passFindPopup','linking_passSendProcess','linking_passSendPopup');
		return false;
	}
}

function CheckEmailPolicy(mail_addr){
	for (var i = 0; i < mail_addr.length; i++){
		if (mail_addr.indexOf(" ") >= 0 || mail_addr.indexOf("*") >= 0 ){
			return "1";
		}
	}
	return "2";
}

function CheckId(frm,div_name){
	if(window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}

	if(frm.id.value.length==0){
		alert("아이디를 입력해주세요");
		frm.id.focus();
		return false;
	}
	var mode="check_id";
	var id=frm.id.value;
	xmlhttp.open("POST","/proc/login_proc.php",true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == '4'){
			if(xmlhttp.status == 200) {
				var desc=xmlhttp.responseText;
				if(desc=="Error1"){
					alert("올바르지 못한 접근경로 입니다.");
					return false;
				}else if(desc=="Error2"){
					alert("가입되지 않은 아이디 입니다.");
					frm.id.value="";
					frm.id.focus();
					return false;
				}else if(desc=="OK"){
					frm.id.readOnly=true;
					frm.id_check.value="Y";
					document.getElementById(div_name).innerHTML = "<font class='popupInfo' color='#FF4800'>가입여부가 확인 되었습니다.</font>";
					frm.email.focus();
					return false;
				}
			} //End of 200
		} //End of 4
	}
	xmlhttp.send("mode="+mode+"&id="+id);
	return;
}

function HintEmail(frm,div_name){
	if(window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}

	var mode="hint_email";
	var id=frm.id.value;
	xmlhttp.open("POST","/proc/login_proc.php",true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == '4'){
			if(xmlhttp.status == 200) {
				var desc=xmlhttp.responseText;
				if(desc=="Error1"){
					alert("올바르지 못한 접근경로 입니다.");
					return false;
				}else if(desc){
					frm.email.value=desc;
					document.getElementById(div_name).innerHTML = "<font class='popupInfo' color='#FF4800'>* 부분의 이메일 주소를 모두입력</font>";
					frm.email.focus();
					return false;
				}
			} //End of 200
		} //End of 4
	}
	xmlhttp.send("mode="+mode+"&id="+id);
	return;
}

function ProcSendPass(frm,div_name,div_name2,div_name3){
	document.getElementById(div_name).style.display="none";
	document.getElementById(div_name2).style.display="block";

	if(window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}

	var mode="send_pass";
	var id=frm.id.value;
	var email=frm.email.value;
	xmlhttp.open("POST","/proc/login_proc.php",true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == '4'){
			if(xmlhttp.status == 200) {
				var desc=xmlhttp.responseText;
				if(desc=="Error1"){
					alert("올바르지 못한 접근경로 입니다.");
					location.href=location.href;
					return false;
				}else if(desc=="Error2"){
					alert("입력하신 이메일주소가 가입시 입력하신 주소와 다릅니다.");
					document.getElementById(div_name2).style.display="none";
					document.getElementById(div_name).style.display="block";
					return false;
				}else if(desc=="OK"){
					document.getElementById(div_name2).style.display="none";
					document.getElementById(div_name3).style.display="block";
					return false;
				}
			} //End of 200
		} //End of 4
	}
	xmlhttp.send("mode="+mode+"&id="+id+"&email="+email);
	return false;
}
