﻿var oPopupAlert;

// 상위 aspx에서의 중앙 경고창
function fnShowAlertCenter(obj, popWidth, popHeight, msg ) {
	if (typeof(oPopupAlert) == "undefined") oPopupAlert = window.createPopup();

	var oPopupBody = oPopupAlert.document.body;
	var oContextHTML = "";

	oPopupBody.style.border = "solid black 2px";
	
	oContextHTML += "<div "
	oContextHTML += "style='"
	oContextHTML += "	height: 100%; "
	oContextHTML += "	padding: 5px; "
	oContextHTML += "'>";
	oContextHTML += "<span ";
	oContextHTML += "style='";
	oContextHTML += " height: 100%;";
	oContextHTML += " width: 100%;";
	oContextHTML += "	font:normal 9pt Tahoma; "
//	oContextHTML += "	text-align: left; "
	oContextHTML += " border:0px solid red;";
	oContextHTML += " vertical-align: middle; ";
	oContextHTML += "'><img src='../Images/icon/checked.gif' align='absmiddle'> "+msg+"</span>";
	oContextHTML += "</div>";
    
	oPopupBody.innerHTML = oContextHTML; 

  	var posWidth = obj.clientWidth/2 - popWidth/2;
	var posHeight = obj.clientHeight/2 - popHeight/2 - 20;
	
	oPopupAlert.show(posWidth, posHeight, popWidth, popHeight, obj);
}

// 상위 aspx에서의 경고창
function fnShowAlert(obj, popWidth, msg) {
	if (typeof(oPopupAlert) == "undefined") oPopupAlert = window.createPopup();

	if (typeof(obj.length) == "number" && obj.type != "select-one") {
		obj = obj[0];
	}

	var oPopupBody = oPopupAlert.document.body;
	var oContextHTML = "";

	oPopupBody.style.border = "solid black 2px";
	
	oContextHTML += "<div style='font:normal 9pt Tahoma; text-align: center; padding-top: 5px; padding-bottom: 10px;'>";
	oContextHTML += "<span><img src='../Images/icon/checked.gif' align='absmiddle'> ";
	oContextHTML += msg+"</span>";
//	oContextHTML += "<span style='width: 20; background-color: red; color: white; font-weight: bold;'>?</span>";
	oContextHTML += "</div>";
    
	oPopupBody.innerHTML = oContextHTML; 

	oPopupAlert.show(0, 0, popWidth, 0);
	var realHeight = oPopupBody.scrollHeight;
	oPopupAlert.hide();

	oPopupAlert.show(0, 22, popWidth, realHeight, obj);
}

// 새창 띄우기
function openWindow(szURL, windowName, theWidth, theHeight, etcParam) { 
	var objNewWin;
	var x = theWidth;
	var y = theHeight;

	var sy = window.screen.height / 2 - y / 2 - 70;
	var position1, position2
	szURL1 = szURL.toUpperCase( );

	if (etcParam == 'fix') {
		etcParam = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0";
		var sy = window.screen.height / 2 - y / 2 - 40;
	} else if (etcParam == 'resize') {
		etcParam = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
		var sy = window.screen.height / 2 - y / 2 - 40;
	}
		
	var sx = window.screen.width  / 2 - x / 2;

	if (sy < 0 ) {
		sy = 0;
	}
		
	var sz = ",top=" + sy + ",left=" + sx;

	if (windowName == "newMessageWindow") {
		windowName = new String(Math.round(Math.random() * 100000));
	}
	 
	objNewWin = window.open(szURL,windowName, etcParam + ",width=" + x + ",height=" + y + sz);
}

// E-Mail 형식 체크
function fnEmailValidation(strEmail) {
	var strEmailValue = "";
	
	if(strEmail.indexOf(" ") >= 0) {
		strEmailValue = "EMail에서 공란을 빼주십시요.";	
	} else if((strEmail.length != 0) && (strEmail.search(/(\S+)@(\S+)\.(\S+)/) == -1)) {
		strEmailValue = "EMail 형식이 잘못되었습니다.";	
	} else  if(strEmail.indexOf("/")!=-1 || strEmail.indexOf(";") !=-1) {
		strEmailValue = "EMail 형식이 잘못되었습니다.";	
	} else {
		var varKeyValue = "";
		
		for(i = 0 ; i < strEmail.length ; i++) {
			varKeyValue = strEmail.charCodeAt(i);
			
			if(varKeyValue > 128) {
				strEmailValue = "EMail에는 한글 사용이 불가능합니다.";
				break;
			} else {
				strEmailValue = "OK";
			}
		}
	}
	
	return strEmailValue;
}

// 파일의 확장자 체크
function getFileExtension(filePath) {
	var lastIndex = -1;
	lastIndex = filePath.lastIndexOf('.');
	var extension = "";

	if ( lastIndex != -1 ) 	{
		extension = filePath.substring( lastIndex+1, filePath.len );
	} else {
		extension = "";
	}

	return extension;
}

// Tab
function fnInsertTab(object) {
	var space;
	
	if (event.keyCode==9) {
		object.focus();
		space = "    ";
		object.selection=document.selection.createRange();
		object.selection.text=space;
		event.returnValue = false;  
	}  
}

var theLeft;
var theTop;
function calcWindowLocation(theWidth,theHeight) {
	var objNewWin;
	
	var x = theWidth;
	var y = theHeight;
	
	theLeft = window.screen.width  / 2 - x / 2;
	theTop = window.screen.height / 2 - y / 2 - 20;
}

// 숫자 체크
function fnCheckIsNum() {
	var eCode = String.fromCharCode (event.keyCode);
	
	if (! isNum(eCode)) {
		event.returnValue = false;
	} else {
		event.returnValue = true;
	}	
}

function isNum(str) {
	if (str == '') {
		return false;
	}	

	for (var idx=0;idx < str.length;idx++) {
		if (str.charAt(idx) < '0' || str.charAt(idx) > '9') {
			return false;
		}
	}
	
	return true;
}

