var IE = (navigator.appName.indexOf("Microsoft")>-1);
var IE6 = IE&&(navigator.userAgent.indexOf("MSIE 6")>-1);
var IE7 = IE&&(navigator.userAgent.indexOf("MSIE 7")>-1);
var IE8 = IE&&(navigator.userAgent.indexOf("MSIE 8")>-1);
var safari = (navigator.appName.indexOf("Netscape")>-1)&&(navigator.userAgent.indexOf("Safari")>-1);
var opera = (navigator.appName.indexOf("Opera")>-1);

/*엔터 이벤트 제어*/
$.fn.onEnterEvent = function(type, objString){
	$(this).keypress(function(){
		if(event.keyCode == 13){
			// 다음 필드로 이동
			if(type == '1'){
				$('#' + objString).focus();
			//폼전송
			}else if(type == '2'){
				$('#' + objString).click();
			}
		}
	});
}


$.chkSSN = function(obj1, obj2){

	var count =0;
	for (var i = 0; i <=5 ; i++) {
		count = count + ((i%8+2) * parseInt($("input[name*='" +obj1+ "']").val().substring(i,i+1)));
	}

	for (var i = 6; i <=11 ; i++) {
			count = count + ((i%8+2) * parseInt($("input[name*='" +obj2+ "']").val().substring(i-6,i-5)));
	}

	count = 11 - (count %11);
	count = count % 10;

	if (count != $("input[name*='" +obj2+ "']").val().substring(6,7)) {
		return false;
	}else{
		return true;
	}
}

$.fn.alphanumeric = function(p) {
 p = $.extend({ ichars: "!@#$%^&*()+=[]\\\';,/{}|\":<>?~`.-_ ", nchars: "", allow: "" }, p);
 return this.each( function() {

  if (p.nocaps) p.nchars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if (p.allcaps) p.nchars += "abcdefghijklmnopqrstuvwxyz";
  s = p.allow.split('');
  for ( i=0;i<s.length;i++) if (p.ichars.indexOf(s[i]) != -1) s[i] = "\\" + s[i];
  p.allow = s.join('|');
  var reg = new RegExp(p.allow,'gi');
  var ch = p.ichars + p.nchars;
  ch = ch.replace(reg,'');

  $(this).keypress( function (e) {
   if (!e.charCode) k = String.fromCharCode(e.which);
	else k = String.fromCharCode(e.charCode);
   if (ch.indexOf(k) != -1) e.preventDefault();
   if (e.ctrlKey&&k=='v') e.preventDefault();

  });

  $(this).bind('contextmenu',function () {return false});
 });
};


//숫자만 가능하게(점, 콤마 불가)
$.fn.numeric = function(p) {
 this.css("ime-mode", "disabled");
 var az = "abcdefghijklmnopqrstuvwxyz";
 az += az.toUpperCase();
 p = $.extend({ nchars: az }, p);
 return this.each( function() { $(this).alphanumeric(p); });
};

//문자/2byte문자만 가능하게(공백, 숫자 불가)
$.fn.alpha = function(p) {
 var nm = "1234567890";
 p = $.extend({ nchars: nm }, p);
 return this.each( function() { $(this).alphanumeric(p); });
};

//숫자/문자/2byte문자/공백만 가능하게
$.fn.alphanumericWithSpace = function(p) {
 var nm = "";
 p = $.extend({ nchars: nm, allow: " " }, p);
 return this.each( function() { $(this).alphanumeric(p); });
};

//숫자/문자/가능하게
$.fn.alphanumericWithSpace2 = function(p) {
 this.css("ime-mode", "disabled");
 var nm = "";
 p = $.extend({ nchars: nm }, p);
 return this.each( function() { $(this).alphanumeric(p); });
};

//문자만 가능하게(숫자, 2byte문자, 공백 불가)
$.fn.alphaAsciiOnly = function(p) {
 this.css("ime-mode", "disabled");
 var nm = "1234567890";
 p = $.extend({ nchars: nm }, p);
 return this.each( function() { $(this).alphanumeric(p); });
};

//숫자만 가능하게(점, 콤마 가능)
$.fn.decimal = function(p) {
 this.css("ime-mode", "disabled");
 var az = "abcdefghijklmnopqrstuvwxyz";
 az += az.toUpperCase();
 p = $.extend({ nchars: az, allow: ".,"}, p);
 return this.each( function() { $(this).alphanumeric(p); });
};

//숫자만 가능하게(점만 가능)
$.fn.onlyfloat = function(p) {
	 this.css("ime-mode", "disabled");
	 var az = "abcdefghijklmnopqrstuvwxyz";
	 az += az.toUpperCase();
	 p = $.extend({ nchars: az, allow: "."}, p);
	 return this.each( function() { $(this).alphanumeric(p); });
	};

//maxlength 만큼 옮기면 다음으로 이동
$.fn.nextFocus = function(nextobj, maxlength) {
	var nextEObj = '#' + nextobj
	$(this).keyup(function(){
		var nowValue = $(this).val();
		var length = nowValue.length;

		if(length >= maxlength){
			if($(nextEObj)){
				$(nextEObj).focus();
			}
		}
	});
}

function trim(str){
	//정규 표현식을 사용하여 화이트스페이스를 빈문자로 전환
	str = str.replace(/^s*/,'').replace(/s*$/, '');
	return str; //변환한 스트링을 리턴.
}

function familySite(){
	var selBefore = $('.family');
	var sliding = $('#familygroup');
	var slidingLink = sliding.find('ul');
	var slidingA = selBefore.find('a');
	sliding.css('display','none');
	sliding.slideUp();

	selBefore.click(function(){
		sliding.slideToggle("slow");
		slidingA.toggleClass("on");
	});
}

function pop(url,name,w,h){
	window.open(url,name,'width='+w+',height='+h+',scrollbars=no, status=no')
}

// activeX 일반 플래쉬 투명 속성 추가
function flash(url, width, height){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+width+'" height="'+height+'" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id=ShockwaveFlash1>'
	// 서로다른 도메인에서도 플래쉬에서 자바스크립트를 호출할 수 있도록 해준다
	+'<param name="scale" value="noscale"/>'
	+'<param name="salign" value="t"/>'
	+'<param name="allowScriptAccess" value="always"/>'
	+'<param name="movie" value="'+url+'"/>'
	+'<param name="quality" value="high"/>'
	+'<param name="wmode" value="transparent"/>'
	+'<embed src="'+url+'" quality="high" scale="noscale" pluginspage="https://www.macromedia.com/go/getflashplayer" width="'+width+'" height="'+height+'" type="application/x-shockwave-flash" wmode="transparent"></embed>'
	+'</object>');
}


function openPop(param, gubun, formObj)
{
	// gubun 을 중심으로 popUpWin 값을 세팅하고 호출한다.
	switch(gubun) {
	case 'adminRight':
		// 관리자 권한 부여...
		popUpWin("/hynix-admin-mng/site-mng/admin-permission-list.jsp" + param, gubun, 400, 700, 0, 0, "yes", "no", true);
		break;
	case 'POP_AGREE':
		// 시험 응시생 추가
		popUpWin("/popup/pop_examinee_agree.html" + param, gubun, 700, 470, 0, 0, "no", "no", true);

		break;
	default:
	}
}

/**
 * 팝업창을 띄운다.
 *
 * @param urlWin 경로
 * @param winName 팝업명
 * @param widthWin 팝업의 폭
 * @param heightWin 팝업의 높이
 * @param topWind 팝업의 상단위치
 * @param leftWin 팝업의 좌측위치
 * @param scrollbarsWin 스크롤(yes, no, auto)
 * @param resizableWin 리사이즈(yes, no)
 * @param centerFlag 팝업창 중앙위치(true, false)
 */
function popUpWin(urlWin, winName, widthWin, heightWin, topWind, leftWin, scrollbarsWin, resizableWin, centerFlag)
{
	var x;
	var y;

	var nameWin = (winName != null && winName.length > 0) ? winName : 'winPop1';

	nameWin += getYear() + getMonth() + getDay() + getHour() + getMinute() + getSecond() + getMillisecond();

	if(centerFlag == true)
	{
		x = (screen.availWidth - widthWin) / 2;
		y = (screen.availHeight - heightWin) / 2;
	}
	else
	{
		x = leftWin;
		y = topWind;
	}

	var _popWindObj = window.open(urlWin, nameWin, 'top='+y+',left='+x+',width='+widthWin+",height="+heightWin+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollbarsWin+',resizable='+resizableWin+',copyhistory=no');
	_popWindObj.focus();
}

/**
 * 팝업창을 띄운다. (폼을 submit 한다)
 *
 * @param urlWin 경로
 * @param winName 팝업명
 * @param widthWin 팝업의 폭
 * @param heightWin 팝업의 높이
 * @param topWind 팝업의 상단위치
 * @param leftWin 팝업의 좌측위치
 * @param scrollbarsWin 스크롤(yes, no, auto)
 * @param resizableWin 리사이즈(yes, no)
 * @param centerFlag 팝업창 중앙위치(true, false)
 * @param formObj 폼 객
 */
function popUpWinSumit(urlWin, winName, widthWin, heightWin, topWind, leftWin, scrollbarsWin, resizableWin, centerFlag, formObj)
{
	var x;
	var y;

	var nameWin = (winName != null && winName.length > 0) ? winName : 'winPop2';

	nameWin += getYear() + getMonth() + getDay() + getHour() + getMinute() + getSecond() + getMillisecond();

	if(centerFlag == true)
	{
		x = (screen.availWidth - widthWin) / 2;
		y = (screen.availHeight - heightWin) / 2;
	}
	else
	{
		x = leftWin;
		y = topWind;
	}

	var _popWindObj = window.open('', nameWin, 'top='+y+',left='+x+',width='+widthWin+",height="+heightWin+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollbarsWin+',resizable='+resizableWin+',copyhistory=no');

	formObj.target = nameWin;
	formObj.action = urlWin;
	formObj.submit();

	_popWindObj.focus();
}

/**
 * 년도 4자리를 얻는다
 */
function getYear()
{
	var today = new Date();

	return today.getFullYear().toString();
}

/**
 * 월 2자리를 얻는다
 */
function getMonth()
{
	var today = new Date();

	if((today.getMonth() + 1) < 10)
	{
		return ('0' + (today.getMonth() + 1));
	}
	else
	{
		return (today.getMonth() + 1).toString();
	}
}

/**
 * 일 2자리를 얻는다.
 */
function getDay()
{
	var today = new Date();
	var d = '';

	if(today.getDate() < 10)
	{
		return ('0' + today.getDate());
	}
	else
	{
		return today.getDate().toString();
	}
}

/**
 * 요일정보를 얻는다.
 */
function getWeek()
{
	var today = new Date();
	var week = "";

	if(parseInt(today.getDay()) == 0)
	{
		week = "일";
	}
	else if(parseInt(today.getDay()) == 1)
	{
		week = "월";
	}
	else if(parseInt(today.getDay()) == 2)
	{
		week = "화";
	}
	else if(parseInt(today.getDay()) == 3)
	{
		week = "수";
	}
	else if(parseInt(today.getDay()) == 4)
	{
		week = "목";
	}
	else if(parseInt(today.getDay()) == 5)
	{
		week = "금";
	}
	else if(parseInt(today.getDay()) == 6)
	{
		week = "토";
	}

	return week;
}


/**
 * 년월일을 구부자로 분리하여 얻는다
 *
 * @param gubun 구분자
 */
function getDate(gubun)
{
	if(gubun != null && gubun != '')
	{
		return (getYear() + gubun + getMonth() + gubun + getDay());
	}
	else
	{
		return (getYear() + "" + getMonth() + "" + getDay());
	}
}

/**
 * 0~23 사이의 시간정보 2자리를 얻는다.
 */
function getHour()
{
	var today = new Date();

	if(today.getHours() < 10)
	{
		return ('0' + today.getHours());
	}
	else
	{
		return today.getHours().toString();
	}
}


/**
 * 0~59 사이의 분정보 2자리를 얻는다.
 */
function getMinute()
{
	var today = new Date();

	if(today.getMinutes() < 10)
	{
		return ('0' + today.getMinutes());
	}
	else
	{
		return today.getMinutes().toString();
	}
}

/**
 * 0~59 사이의 초정보 2자리를 얻는다.
 */
function getSecond()
{
	var today = new Date();

	if(today.getSeconds() < 10)
	{
		return ('0' + today.getSeconds());
	}
	else
	{
		return today.getSeconds().toString();
	}
}

/**
 * 100분의 1초 3자리를 얻는다.
 */
function getMillisecond()
{
	var today = new Date();
	var ms = today.getMilliseconds().toString();

	if(ms.length == 0)
	{
		return '000';
	}
	else if(ms.length == 1)
	{
		return ('00' + ms);
	}
	else if(ms.length == 2)
	{
		return ('0' + ms);
	}
	else
	{
		return ms;
	}
}

function downFile(url){
	location.href = url;
}

function link(url){
	location.href = '/apply/apply01.jsp';
}

// Flash publishing with Cross Browsing
function swfprint(furl,fwidth,fheight,transoption)	{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ fwidth +'" height="' + fheight +'" align="middle">');
	document.write('<param name="movie" value="'+ furl +'"/>');
	if (transoption == "t")	{
		document.write('<param name="wmode" value="transparent"/>');
	} else if	(transoption == "o")	{
		document.write('<param name="wmode" value="opaque"/>');
	}
	document.write('<!-- Hixie method -->');
	document.write('<!--[if !IE]> <-->');
	document.write('<object type="application/x-shockwave-flash" data="'+ furl +'" width="'+ fwidth +'" height="' + fheight +'"');
	if (transoption == "t")	{
		document.write(' wmode="transparent"');
	} else if	(transoption == "o")	{
		document.write(' wmode="opaque"');
	}
	document.write('></object>');
	document.write('<!--> <![endif]-->');
	document.write('</object>');
}

// 2011-06-05 meta.jsp, meta_main.jsp 에 있던 것을 옮김
function openLayer( layer_nm, flag )
{
	var layer_obj = document.getElementById(layer_nm);

	if( flag == "on" )
	{
		layer_obj.style.display= "";
		//main_frame.location.reload();
	}
	else
	{
		layer_obj.style.display= "none";
	}
}

function popopen(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function showLayer(id){
	$("#"+id).show();
}

function hideLayer(id){
	$("#"+id).hide();
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*
	open popup : openPopup("url", { width:400, height:500, scroll:0, top:100, left:100, name:"name_popup" });
*/
function openPopup( url, option )
{
	var obj_option = option == null ? {} : option;

	if(url					==	null)	url					=	"";
	if(obj_option.width		==	null)	obj_option.width	=	window.screen.availWidth;
	if(obj_option.height	==	null)	obj_option.height	=	window.screen.availHeight;
	if(obj_option.scroll	==	null)	obj_option.scroll	=	0;
	if(obj_option.top		==	null)	obj_option.top		=	(window.screen.availHeight - obj_option.height)/2;
	if(obj_option.left		==	null)	obj_option.left		=	(window.screen.availWidth  - obj_option.width)/2;
	if(obj_option.name		==	null)	obj_option.name		=	"";
	if(obj_option.errMsg	==	null)	obj_option.errMsg	=	"Please disable popup blocking!";

	var newWindow = window.open( url, obj_option.name, "width=" + obj_option.width + ",height=" + obj_option.height + ",scrollbars=" + obj_option.scroll + ",toolbar=0,menubars=0,locationbar=0,historybar=0,statusbar=0,resizable=0,left=" + obj_option.left + ",top=" + obj_option.top + ",channelmode=no,titlebar=no", false );

	if( !newWindow )
	{
		alert( obj_option.errMsg );
		return false;
	}
	newWindow.focus();

	return newWindow;
}

function datecheck(startDate ,endDate){//YYYYMMDD 06-03-24 오진호
var X;
X=new Date();
var Y=(X.getFullYear()*100+X.getMonth()+1)*100+X.getDate();
 if (parseInt(Y)>=startDate && parseInt(Y)<=endDate) {
 	return true;
 }
 else return false;
}

//2011-06-17 CLEANTYPE 설정
function openClearTypeMsg( language )
{
	if( readCookie("ctf110617") == 1 )
	{
		return false;
	}
	
	var lang = language;
	var str = "";

	switch( lang )
	{
		

		case "en" : // ie6이면서 영문 컨텐츠 인 경우
			str = "";
			break;

		case "ch_sa" : // ie6이면서 중문 간체 컨텐츠 인 경우
			str = "";
			break;

		case "ta" : // ie6이면서 중문 번체 컨텐츠 인 경우
			str = "";
			break;

		case "ja" : // ie6이면서 일문 컨텐츠 인 경우
			str = "";
			break;

		default :
			break;
	}

	if( str != "" )
	{
		openPopup(str, { width:400, height:294, scroll:0, name:"cleantype", top:10, left:10 });
	}
}

//2011-06-17 IE 6 이하 인 경우 팝업
function noMoreIE6( language ){
	if( readCookie("ie6110617") == 1 )
	{
		return false;
	}

	var lang = language;
	var str = "";

	switch( lang ){
		case "ko" :
			str = "/ko/popup/pop_ieinstall.jsp";
			break;

		case "en" :
			str = "";
			break;

		case "ch_sa" :
			str = "";
			break;

		case "ta" :
			str = "";
			break;

		case "ja" :
			str = "";
			break;
			
		default :
			break;
	}

	if( str != "" ){
		openPopup(str, { width:400, height:290, scroll:0, name:"ie6", top:10, left:420 });
	}
}

function winopenqualitymonitoring() {
		window.open("http://semicon.hynix.com/qa_login.asp?caller=hynix","qualitymonitoring","scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,width=200,height=200,left=0,top=0");
}

function popup120215() {
	if( readCookie("popup120215") == 1 )
	{
		return false;
	}
	window.open("/ko/popup/popup120215.jsp","popup120215","scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,width=404,height=297,left=10,top=10");
}

function popup110711() {
	if( readCookie("popup110711") == 1 )
	{
		return false;
	}
	window.open("http://www.hynix.com/ko/popup/popup110711.jsp","popup110711","scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,width=570,height=294,left=10,top=10");
}

function popup110720() {
	if( readCookie("popup110720") == 1 )
	{
		return false;
	}
	window.open("http://www.hynix.com/ko/popup/popup110720.jsp","popup110720","scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,width=400,height=260,left=10,top=10");
}

function popup110831() {
	if( readCookie("popup110831") == 1 )
	{
		return false;
	}
	window.open("http://www.hynix.com/ko/popup/popup110831.jsp","popup110831","scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,width=400,height=260,left=830,top=10");
}

function popup110909() {
	if( readCookie("popup110909") == 1 )
	{
		return false;
	}
	window.open("/en/popup/popup110909.jsp","popup110909","scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,width=330,height=4005,left=10,top=10");
}

function popup111107() {
	if( readCookie("popup111107") == 1 )
	{
		return false;
	}
	window.open("/ko/popup/popup111107.jsp","popup111107","scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,width=577,height=294,left=420,top=10");
}

function popup120221e() {
	if( readCookie("popup120221e") == 1 )
	{
		return false;
	}
	window.open("/en/popup/popup120221.jsp","popup120221e","scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,width=404,height=300,left=10,top=10");
}
