//페이징
function paging(page, parameter, url) {
	
	$("#page").val(page);

	display_list();
}
// 4~12 입력 길이 체크
function isLength_4_12(input){

	if(input.length < 4 || input.length > 13){
		return "false";
	}else{
		return "true";	
	}
}

// 영문 소문자와 숫자 체크
function isAlphabet(input){
	var chars = "abcdefghijklmnopqrstuvwxyz0123456789"
	
	return containsCharsOnly(input, chars);

	
}
// 문자열 비교
function containsCharsOnly(input, chars){
	
	for(var inx = 0; inx < input.length; inx++){
		
		if(chars.indexOf(input.charAt(inx)) == -1){
			return "false";
		}
	}
	return "true";
	
} 
// 아이디와 비밀번호의 비교
function match_id_pws(id, pws){
	if(id == pws){
		return "true";	
	}else{
		return "false";
	}
} 



// 아이디 중복확인
function check_id(id){

    var url = "/FRONT/manage/check_id/" + id;
   	var data = "";
   
    $.ajax({
        type: "POST",
        url: url,
        data: data,
        dataType: "json",
        success: function(result_data){
        	$("#id_check_msg").hide();
            $("#id_check_flag").hide();
            
            if (result_data) {
                
                $("#id_check_flag").val("0");
                $("#id_check_msg").html("이미  아이디가 사용 중 입니다.").fadeIn('slow');
                
            }else {
            	$("#id_check_flag").val("1");
                $("#id_check_msg").html("사용가능한 아이디입니다.").fadeIn('slow');
            }
           
        }
    });
}


//우편번호검색창 오픈
function search_addr(){
	
	window.open("../address_search", "search_addr", "top=100px, left=100px, height=360px, width=540px, menubar=no, toolbar=no, scrollbars=yes");
	
}
//자동 탭 시작
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
        var keyCode = (isNN) ? e.which : e.keyCode;
        var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
        if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
        var found = false, index = 0;
        while(!found && index < arr.length)
        if(arr[index] == ele)
        found = true;
        else
        index++;
        return found;
}

function getIndex(input) {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
        if (input.form[i] == input)index = i;
        else i++;
        return index;
        }
return true;
}
//자동 탭 끝


// 레이어 팝업 오픈 위치
function getBounds( obj ) { 
	
	var ret = new Object();

	if(document.all) { 
		var rect = obj.getBoundingClientRect(); 
		ret.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft); 
		ret.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop); 
	} else { 
		var box = document.getBoxObjectFor(obj); 
		ret.left = box.x; 
		ret.top = box.y; 
	} 

	return ret; 
}


// 레이어 팝업 오픈
function layer_popup(popupName, width, height, xy_flag, btn_id){
	
	var left = "";
	var top = "";
	if(xy_flag == "1"){
		var obj = getBounds( document.getElementById(btn_id));
		left = obj.left - width;
		top = obj.top - height;
	}else{
		left = screen.width/2 - width/2;
		top = screen.width/2 - height/2;
	}
	
	document.getElementById(popupName).style.left=left;
	document.getElementById(popupName).style.top=top;
	
	document.getElementById(popupName).style.display = 'block';
	
}


// 레이어 드레그 이동 부분 시작
var popup1_down = 0;
var popup2_down = 0;
var popup3_down = 0;
var popup4_down = 0;

var mouseX = 0;
var mouseY = 0;

function popupMouseMove(popupName){
	var x, y;
	x = window.event.clientX - mouseX;
	y = window.event.clientY - mouseY;

	
	var layerObj;
	if (popup1_down || popup2_down || popup3_down || popup4_down) {
		
		layerObj = document.getElementById(popupName);
		layerObj.style.pixelLeft += x;
		layerObj.style.pixelTop += y;
		mouseX = window.event.clientX;
		mouseY = window.event.clientY;
	}
}

function popupMouseClick(popupName){
	
	if (popupName == 'free_request_layer') {
		popup1_down = 1;
		// 레이어 z-index를 바꿔 클릭한 레이어가 먼저 보이도록 함
		document.getElementById('free_request_layer').style.zIndex = "9999";
		document.getElementById('join_request_layer').style.zIndex = "9998";
		document.getElementById('any_question_layer').style.zIndex = "9997";
		document.getElementById('product_layer').style.zIndex = "9996";

	}
	if (popupName == 'join_request_layer') {
		popup2_down = 1;
		document.getElementById('join_request_layer').style.zIndex = "9999";
		document.getElementById('free_request_layer').style.zIndex = "9998";
		document.getElementById('any_question_layer').style.zIndex = "9997";
		document.getElementById('product_layer').style.zIndex = "9996";
	}
	if (popupName == 'any_question_layer') {
		popup3_down = 1;
		document.getElementById('any_question_layer').style.zIndex = "9999";
		document.getElementById('join_request_layer').style.zIndex = "9998";
		document.getElementById('free_request_layer').style.zIndex = "9997";
		document.getElementById('product_layer').style.zIndex = "9996";
		
	}
	if (popupName == 'product_layer') {
		popup4_down = 1;
		document.getElementById('product_layer').style.zIndex = "9999";
		document.getElementById('any_question_layer').style.zIndex = "9998";
		document.getElementById('join_request_layer').style.zIndex = "9997";
		document.getElementById('free_request_layer').style.zIndex = "9996";
		
		
	}
	
	mouseX = window.event.clientX;
	mouseY = window.event.clientY;
}

function popupMouseUp(popupName){
	
	if (popupName == 'free_request_layer') popup1_down = 0;
	if (popupName == 'join_request_layer') popup2_down = 0;
	if (popupName == 'any_question_layer') popup3_down = 0;
	if (popupName == 'product_layer') popup4_down = 0;
}

function popupMouseOut(popupName){
	popup1_down = 0;
	popup2_down = 0;
	popup3_down = 0;
	popup4_down = 0;
}
// 레이어 드레그 이동 부분 끝


//자동 탭 시작
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
      var keyCode = (isNN) ? e.which : e.keyCode;
      var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
      if(input.value.length >= len && !containsElement(filter,keyCode)) {
      input.value = input.value.slice(0, len);
      input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
      var found = false, index = 0;
      while(!found && index < arr.length)
      if(arr[index] == ele)
      found = true;
      else
      index++;
      return found;
}

function getIndex(input) {
      var index = -1, i = 0, found = false;
      while (i < input.form.length && index == -1)
      if (input.form[i] == input)index = i;
      else i++;
      return index;
      }
return true;
}
//자동 탭 끝



function reset_frm(frmId){
    $(frmId).each(function(){
        this.reset();
    });
}

