﻿var loop=100;
function divfade() {
  pwmsg.filters.item('Alpha').Opacity = --loop;
  if(loop>0) setTimeout("divfade()", 0.05);
}

//비밀번호변경
function ChangePW(uid){
	params="uid="+uid;
	new poppw.xhr.Request("./ex_pass.php",params,outpw,'POST','view','btnload');
}

function outpw(reqs){
	var out=reqs.responseText;
	//document.getElementById('pwLayer').style.display="block";
	document.getElementById('btnload').style.display="none";
	document.getElementById('pwLayer').style.display="block";
	
	document.getElementById('pwLayer').innerHTML=out;
}
function send_pw_update(uid){
	var pw=document.getElementById('prev_pass').value;
	var npw=document.getElementById('new_pass').value;
	var npwf=document.getElementById('new_pass_f').value;

	var pwlength=pwlenchk(npw);
	
	if(pwlength==false)
	{
		document.getElementById('pwmsg').innerHTML="영문,숫자 조합 6자이상 12자까지 가능";
		return false;
	}

	if(npw==npwf){
		
		params="ue="+uid+"&pw="+pw+"&npw="+npw;
		new poppw.xhr.Request("./ex_pass_act.php",params,outpwact,'POST','view','sendbtnloading');
	}else{
		document.getElementById('pwmsg').innerHTML="확인 비밀번호가 일치하지 않습니다.";

	}
	
}
function outpwact(reqs){
	var out=reqs.responseText;
	var msgout = document.getElementById("pwmsg");

	var sp=out.split(":");
	if (sp[1]=="ok")
	{
		//document.getElementById('pwLayer').style.background-color="0099FF";
		document.getElementById('pwLayer').innerHTML=sp[0];
	}else{
		msgout.innerHTML=sp[0];
	}
}
var poppw = {}; // 패키지 정의
poppw.xhr = {};// 패키지 정의
poppw.xhr.Request = function(url, params, callback, method,mode,loading) { // Request클래스의 생성자. 객체 생성
	this.url = url;
	this.params = params;
	this.callback = callback;
	this.method = method;
	this.loading = loading;
	this.mode = mode;
	this.send();
}
poppw.xhr.Request.prototype = {
		getXMLHttpRequest:function(){
			var xmlreq = false;
			//alert(window.XMLHttpRequest);
			if (window.XMLHttpRequest) {
				xmlreq = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				try {
					xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e1) {
					try {
						xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e2) {

					}
				}
			}
			return xmlreq;
		},
		send:function() {
			this.req = this.getXMLHttpRequest();

			var httpMethod = this.method ? this.method : 'GET';
			if(httpMethod != 'GET' && httpMethod != 'POST' ){
				httpMethod ='GET';
			}	
			var httpParams = ( this.params == null || this.params == '') ?
						null : this.params;

			//file url
			var httpUrl = this.url;
			if (httpMethod == 'GET' && httpParams != null)
			{
				httpUrl = httpUrl + "?" + httpParams+'&time='+new Date();
			}

			//run
			this.req.open(httpMethod, httpUrl, true);
			this.req.setRequestHeader( 'Content-Type','application/x-www-form-urlencoded');
			
			var request = this;
			this.req.onreadystatechange = function(){
				request.processReq.call(request);
			}
			this.req.send(httpMethod == 'POST' ? httpParams : null);
		},
		processReq:function()
			{
			var loadmsg ='';
			var ermsg = '';
			var errormsg='';
			
			if(this.req.readyState==1 || this.req.readyState==2 || this.req.readyState==3)
			{

				if (this.loading){
					loadmsg = "";
					//<img src=/v1/img/ajax-loader.gif>';
					loadmsg+= 'Loading.....';
					
					var _x = (document.body.clientWidth + document.body.scrollLeft) / 2.2;
					var _y = (document.body.clientHeight + document.body.scrollTop) / 2;
					
					var outloading = document.getElementById(this.loading);					
					if(!outloading){
						binData = "<div id='"+this.loading+"' style='position:absolute; "
						binData+= "z-index:1'>"
						binData+='</div>';
						
						document.write(binData);
						outloading = document.getElementById(this.loading);
					}
					outloading.style.visibility = 'visible';
					outloading.style.top = "90px";
					outloading.style.left= _x+"px";
					
					outloading.innerHTML =loadmsg;
				}
			}else if(this.req.readyState==4){

			// only if "OK"
				switch(this.req.status){
					case 200:					
						if(this.callback){
							this.callback(this.req);
						}
						this.hiddenLoadbar();
					break;
					case 403: this.printMsg(''); break;
					case 404: this.printMsg(''); break;						
					case 500: this.printMsg(''); break;
					case 503:
						this.send();
					break;
				}
			}else{
				errormsg += "There was a problem retrieving the 'XMLHttpRequest Object' : "+this.req.status;
				this.printMsg(errormsg);
			}
		},
		hiddenLoadbar : function(){
			var outloading = document.getElementById(this.loading);
			if(outloading){
				outloading.style.visibility = 'hidden';
				outloading.style.top = 0+"px";
				outloading.style.left= 0+"px";
			}
		},
		getParams : function(){
			var pArr=new Array();
			var arr = this.params.split('&');

			for(var i=0;i<arr.length;i++){
				if(arr[i]){
					var kv=arr[i].split('=');
					var k = kv[0];
					var v=kv[1];

					pArr[k] =v;
				}
			}
			return pArr;
		},
		printMsg : function(msg){
		if (this.divid){
			var output = document.getElementById(this.divid);
			output.innerHTML = msg; //msg.replace("/\n/g",'');
			
			this.hiddenLoadbar();
		}
	}
}
