var minLength = 6;
var iterateCount = 3;
function newPWDCheck(newPWD, newPWD2, id){

 if(newPWD == newPWD2){  
	var checkFlag = true;
	checkFlag = newPWDMinLengthCheck(newPWD);
	if(checkFlag){
		checkFlag =  startCharacterCheck(newPWD);
	}
	if(checkFlag){
		checkFlag =  confirmDigitewhidCharacterCheck(newPWD);
	}
	if(checkFlag){
		checkFlag = specialCharacterCheck(newPWD);
	}
	if(checkFlag){
		checkFlag = continuityCharacterCheck(newPWD, iterateCount);
	}
	if(checkFlag){
		if(newPWD == id){
			alert("ID와 패스워드가 같습니다.");
			checkFlag = false;
		}
	}
	
	return checkFlag;		
		
 }else{
 	alert("새로입력된 패스워드가 일치 하지 않습니다.");
	return false; 
 }		
}

function newPWDMinLengthCheck(newPwd){
	if(newPwd == null){
		alert("패스워드를 입력하세요.");
		return false;
	}
	if(newPwd.length < minLength ){
		alert("최소 6자리 이상 입력하세요.");
		return false;
	}
	return true;
}
function startCharacterCheck(newPwd){
	if (((newPwd.charAt(0).toLowerCase()< 'a') || (newPwd.charAt(0).toLowerCase() > 'z'))) {
		alert("패스워드 첫 글자는 문자열('a' ~ 'z')로 시작해야 합니다.");
		return false;
	}
	return true;
}
function confirmDigitewhidCharacterCheck(newPwd){
	for (var i = 0; i < newPwd.length; i++) {
		if ((newPwd.charAt(i)>='0')&&(newPwd.charAt(i)<='9')) {
			break;
		}
		if (i == newPwd.length - 1){
			alert("password는  숫자와 문자 조합해야 합니다.");
			return false;
		}
	}
	for (var i = 0; i < newPwd.length; i++) {
		if ((newPwd.charAt(i)>='a')&&(newPwd.charAt(i)<='z')){
			break;
		}
		if (i == newPwd.lengt - 1){
			alert("password는  숫자와 문자 조합해야 합니다.");
			return false;
		}
	}
	return true;	
		
	
}

function specialCharacterCheck(newPwd){
	for (var i = 0; i < newPwd.length; i++) {
		if ((('0' > newPwd.charAt(i)) || (newPwd.charAt(i) > '9'))
			&& ((newPwd.charAt(i).toLowerCase() < 'a') || (newPwd.charAt(i).toLowerCase() > 'z'))) {
			alert("특수문자(!@*-+?/<>) 사용 불가");
			return false;
		}
	}
	return true;	
}

function continuityCharacterCheck(newPwd){
	var flag = true;
	
	for (var i = 0; i < newPwd.length - (iterateCount - 1); i++) {
		var subPwd = newPwd.substring(i, iterateCount + i);
		flag = continuityPWDIterateCount(subPwd, iterateCount);
		if (!flag) {
			alert("연속된 "+ iterateCount +"개 이상의 문자열은 사용할수 없습니다.");
			return flag;
		}
	} // for
	return flag;
}
function continuityPWDIterateCount(subPwd, iterateCount){
	var ascending = 0;
	var descending = 0;
	var duplicate = 0;
	
	for (var i = 0; i < (iterateCount-1); i++) {
		//오름차순 검증.
		if ((subPwd.charCodeAt(i) - subPwd.charCodeAt(i+1)) == -1) {
			ascending++;
		}
		//내림차순 검증 
		else if ((subPwd.charCodeAt(i) - subPwd.charCodeAt(i+1)) == 1) {
			descending++;				
		}
		//중복검증
		else if ((subPwd.charCodeAt(i) - subPwd.charCodeAt(i+1)) == 0) {
			duplicate++;
			
		}
	} //for

	//오름, 내림, 중복이 되었을때..
	if ((ascending == (iterateCount-1)) || (descending == (iterateCount-1)) || (duplicate == (iterateCount-1))) {			
		return false;
	}
	return true;
}


// 윈도우 리사이즈
function winresizing(fixwidth, fixheight) {
	    window.resizeTo(500, 500);
        
  		if (fixwidth != undefined) {
            width = 500 - (document.body.clientWidth -  fixwidth);
        } else {
            width = 500 - (document.body.clientWidth -  document.body.scrollWidth);
        }
        height = 500 - (document.body.clientHeight -  document.body.scrollHeight);
        windowX = (window.screen.availWidth-width)/2;
        windowY = (window.screen.availHeight-height)/2;
                		
        if(width>screen.availWidth){
            width = screen.availWidth;
            windowX = 0;
        }
        
        if (fixheight != undefined) {
	        if(height>fixheight){
	            height = fixheight;
	        }
	    } else {
	        if(height>screen.availHeight){
	            height = screen.availHeight;
	            windowY = 0;
	        }
	    }
        window.moveTo(windowX,windowY);
        window.resizeTo(width,height);
}