/*
copyright (c)Funnypeople corp.
mman@funnypeople.co.kr
2011-03-08
*/
$.extend({URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/; while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}});

var tmp = new Date();

$(document).ready(function() {

	// 검색어 리셋
	$("#keyword").click(function() { 
		$("#old").val( $(this).val() );
		$(this).val("");
	});

	$("#keyword").bind("blur",function() { 
		if( $(this).val() == "") { $(this).val( 	$("#old").val() ); }
	});

	// 오토키업
	$(".auto_keyup").keypress(function() {
		if( $(this).val().length ==  $(this).attr("maxlength") ) {
			$(this).next().focus();		
		}
	});
	// 마지막 보더 없앰
	$("#snb li:last-child").css("border","none");

	// 콤보박스 예쁘게
    $(".select").sb();

//	var hrefattr;
//	$(".map").find("a").each(function() {
//		hrefattr = $(this).attr("href");
//		$(this).attr("href","#").click(function() {
//			$(".mapLocation").hide();
//			$("#"+hrefattr).show();
//		});
//	});


	// 푸터 유관기관 및 협력의료기관 이동
//	$(".linksite").change(function() {
//		document.location.target = '_blank';
//		document.location.href=$(this).val();
//	});

	// 푸터 유관기관 및 협력의료기관 이동
	$(".linksite").change(function() { $(this).parents().attr("action",$(this).val() ); });



});

// 홈페이지 개선제안 스크롤링
//$(window).scroll(function () { 
//	$("#quickSide").css("top",$(document).scrollTop()+130+"px");
//});


window.searchAction = function() {
	if(  $("#keyword").val().length < 2 || $("#keyword").val() == "통합검색") {
		alert('검색어는 2글자 이상 입력하셔야 합니다.');
		return false;
	}
	return true;
}

window.fnIsIETrueBody = function() {
	// 스크롤된 실제 BODY 위치 출력용
	return $(document).scrollTop();
}

window.flash = function(c,d,e) {
  var flash_tag = "";
  flash_tag = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
  flash_tag +='codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,29,0" ';
  flash_tag +='width="'+c+'" height="'+d+'" >';
  flash_tag +='<param name="wmode" value="transparent">'; 
  flash_tag +='<param name="movie" value="'+e+'">';
  flash_tag +='<param name="quality" value="high">';
  flash_tag +='<embed src="'+e+'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" ';
  flash_tag +='type="application/x-shockwave-flash"  width="'+c+'" height="'+d+'" ></embed></object>'
  document.write(flash_tag);
}

var status;
var status2;

window.yesIdo = function() {
	status2=1;
	$('#login2').submit();
}

window.noIdont = function() {
	alert("회원통합관리 이용약관에 동의하지 않으실 경우\n로그인을 하실 수 없습니다. \n홈페이지로 이동합니다.");
	document.location.href = "http://www.kahp.or.kr/";
}

window.loginAct = function() {

	// 로그인 처리
	if(  !$("#userid").val() ) {
		alert('아이디가 입력되지 않았습니다');
		$("#userid").focus()
		return false;
	}

	if(  !$("#passwd").val() ) {
		alert('비밀번호가 입력되지 않았습니다');
		$("#passwd").focus()
		return false;
	}
	
	if(status != 1) {
	$.ajax( {
		type	: "POST",
		url		: "/login/checkConfirm.php",
		data	: "userid="+ $("#userid").val() + "&passwd=" + $("#passwd").val(),
		async	: false,
		success : function(data) {
			var oj = new String();
			oj = data.split("|");
			if(oj[0] == "error") {
				if(oj[1] == 'confirm') {					
					status = 1;
				} else if(oj[1] == 'needID') {
					status = '존재하지 않는 ID 입니다';
				} else if(oj[1] == 'needPW') {
					status = '아이디와 비밀번호를 다시 확인해주십시오';
				}
			}
		}
	});
	}
	if(status2 == 1) {
		return true;
	} else {
		if(status){
			if(status == 1) {
				$("#login").hide();
				$("#checkConfirm").show();
				return false;
			} else {
				alert(status);
				return false;
			}
		}
	}
}



window.logoutAct = function() {
	// 로그아웃 처리
	$.ajax( {
		type	: "POST",
		url		: "/login/logout.php",
		data	: "tmp="+new Date(),
		async	: true,
		success : function(data) {
			var oj = new String();
			oj = data.split("|");
			alert(oj[0]);
				if(oj[1] ){ document.location.href=oj[1]; }
				else { document.location.href='/'; }
		},
		error : function(data) {
			alert("로그인시스템 오류입니다.");
		}
	});
}

window.needLogin = function() {
	// 로그인 경고창 출력
	alert('로그인이 필요한 기능입니다');
}

window.forget = function() {
	// 아이디/비밀번호 찾기
	var itemPOP = window.open("about:blank", "itemPOP", "toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=no,width=417,height=400,scrollbars=yes"); 
	itemPOP.location.href = "/login/forget.php"; 
	itemPOP.focus();
}

window.openW = function(obj) {
	window.open(obj.value,'','_blank');
}

window.movieplay = function(year,day,sess,host) {
	document.write('<div class="movie"><EMBED pluginspage=http://www.microsoft.com/korea/windows/windowsmedia/ src=mms://media.ilovesea.co.kr/VOD/'+year+'/'+day+'/'+sess+' width=650 height=556 type=video/x-ms-asf-plugin showpositioncontrols="0" showtracker="1" showstatusbar="1" showcontrols="1" displaybackcolor="white" autostart="0" animationatstart="1"></EMBED></div>');
}

window.zipSearch = function(where,type) {
	var zips=window.open('/bin/zip2.php?where='+where+'&type='+type, 'zip', 'width=450, height=300, scrollbars=yes');
}
window.popupE = function() {
	var eprivacy=window.open('/eprivacy.php', '', 'width=395, height=565, scrollbars=yes');
}


/*GNB 메뉴*/
var thisSubmenu;
$(function(){
	var menu = ("#gnb>ul");


	$(menu).children("li").each( function() {
		var item = $(this);


		if ( navigator.userAgent.match(/iPad/i) ||  navigator.userAgent.match(/Android/i) ) {
			$(item).children("a").attr("href","#");
			$(item).click( function() {
				menuOverEffect(item);
			});
		}

		//mouse Action
		$(item).hover( function() {
			menuOverEffect(item);
		}, function() {
			menuOutEffect(item);
		});

		//keyboard Action
		$(item).children("a").focus( function() {
			menuOverEffect(item);
		});
		$(item).children("ul").children("li").children("a:last").blur( function() {
			menuOutEffect(item);
		});

		//Over Event
		function menuOverEffect(target) {
			$(menu).children("li").children("ul").css("visibility","hidden");
			$(target).children("ul").css("visibility","visible");
			$(menu).children("li").removeClass("selected");
			$(target).addClass("selected");
		}

		//Out Event
		function menuOutEffect(target) {
			$(target).children("ul").css("visibility","hidden");
			//$(menu).children("li.selected").children("div").css("visibility","visible");
			$(target).removeClass("selected");
		}
	});


	$(".leftimg")
		.mouseover(function() { $(this).attr("src" , $(this).attr("src").replace("on","off")); })
		.mouseout(function() { 
			if($(this).hasClass("sele") == false) {
				$(this).attr("src" , $(this).attr("src").replace("off","on"));
			}
		});
	
	$("div.quick").click(function() { 
		if($("#quickMenu").css("display") == "none") {
			$.get("/bin/todayPage.php", "", function(data) {
				$("#quickMenu").slideDown('fast').find(".todayPages").html(data);
			});
		} else {
			$("#quickMenu").slideUp('fast');
		}
	});
	
});



/*팝업자동화*/
window.Pop_ups = function(num,width,height){	
	window.open('?pop_load=on&num='+num,'pop_'+num,'width='+width+',height='+height+',scrollbars=no');
}

/* 임시 추가 팝업 자동화 */
window.Pop_ups_tmp = function(num,width,height,left,top){	
	window.open('?pop_load=on&num='+num,'pop_'+num,'width='+width+',height='+height+',left='+left+',top='+top+',scrollbars=no,dependent=no ');
}
/*test  팝업 자동화 */
window.Pop_ups_temp = function(num,width,height,left,top){	
	window.open('?pop_load=on&num='+num,'pop_'+num,'width='+width+',height='+height+',screenX='+left+',screenY='+top+',scrollbars=no,dependent=no,, resizable=no');
}


window.Pop_cookie = function(num){
	if(document.getElementById('pop_cookie_chk').checked == true){
		document.location.href='?pop_cookie=on&num='+num;
	} else {
		self.close();
	}
}
window.Pop_url = function(url){
	opener.document.location.href=url;
}




/* 구글 Analytics */
/*
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-22643226-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
*/

//개인정보보호방침 팝업
function shelter_popup(){
		window.open('http://www.kahp.or.kr/shelter.php', '', 'width=950px, height=800px, scrollbars=yes')
	}


function changePasswd(){
	if( $("#join_pwd_check1").val() == '') {
		alert('비밀번호를 입력해주세요');
		$("#join_pwd_check1").focus();
		return false;
	}

	if(join_pwd_chk != 1) {
		if( $("#join_pwd_check1").val() == '') {
			alert('비밀번호확인을 입력해주세요');
			$("#join_pwd_check1").focus();
			return false;
		}

		if( $("#join_pwd_check1").val() == $("#join_pwd_check2").val()) {
		} else {
			alert('비밀번호가 일치하지 않습니다. 다시 입력해주세요');
			$("#join_pwd_check1").select(); 
			return false;
		}
	}
	if(joinform1.join_pwd_check1.value.length < 8){
			alert("비밀번호는 8자리 이상이여야 합니다1");
			joinform1.join_pwd_check1.focus();
			return false;
		}
	if(joinform1.join_pwd_check1.value.length > 16){
			alert("비밀번호는 16자리 이하이여야 합니다");
			joinform1.join_pwd_check1.focus();
			return false;
		}
	if(!(/[a-zA-Z]/.test(joinform1.join_pwd_check1.value) || (/[0-9]/.test(joinform1.join_pwd_check1.value)) )) {
			alert("영문(대,소문자), 숫자, 특수문자 중 2개의 캐릭터 조합이여야 합니다.");
			joinform1.join_pwd_check1.focus();
			return false;
		}
	if(!(/[0-9]/.test(joinform1.join_pwd_check1.value) || (/[ #\&\+\-%@=\/\\\:;,\.\"\^`~\_|\!\?\*$#<>()\[\]\{\}]/i.test(joinform1.join_pwd_check1.value)) )) {
			alert("영문(대,소문자), 숫자, 특수문자 중 2개의 캐릭터 조합이여야 합니다.");
			joinform1.join_pwd_check1.focus();
			return false;
		}
		
	if (!(/[a-zA-Z]/.test(joinform1.join_pwd_check1.value) || (/[ #\&\+\-%@=\/\\\:;,\.\"\^`~\_|\!\?\*$#<>()\[\]\{\}]/i.test(joinform1.join_pwd_check1.value)) )) {
			alert("영문(대,소문자), 숫자, 특수문자 중 2개의 캐릭터 조합이여야 합니다.");
			joinform1.join_pwd_check1.focus();
			return false;
		}

	return true;
}

