// GoodNews


var	strSYSNAME   = "GoodNews";
var strSYSTITLE  = "GoodNews";
var intMAXLENGTH = 4000;
var intPOPUPMARGINWIDTH  = 26;
var intPOPUPMARGINHEIGHT = 20;
var intTIMEOUTSETCURSOR  = 7000;
var strHLPDESCJS = "½Ã½ºÅÛ ´ã´çÀÚ¿¡°Ô ¹®ÀÇÇÏ½Ê½Ã¿À.\nÀÌ¸ÞÀÏ: webmaster@goodnews.or.kr";
var strERRDESCJS = "½Ã½ºÅÛ ³»ºÎ ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù. (0x80000001)\n" + strHLPDESCJS;

var strFORMATDATE = "^\\d{4}(0|1)\\d(0|1|2|3)\\d$";


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function goMessage()
{   
    w=open('/community/asp/main/message/rmessage.asp?fwhere=club','message','width=740,height=510,scrollbars=yes'); 
	w.focus()
}
function goLoginuser(schcode)
{
	w=open('/community/asp/club/loginuser.asp?schcode='+schcode,'loginuser','width=360,height=400,scrollbars=yes'); 
	w.focus();	
}

function View_Cap(id){
	if(id)
	{
		var url='http://club.catholic.or.kr/capsule/default.asp?userId='+id;
		window.open (url, '','left=100,top=100,width=870,height=615');
		
	}
}

function getForm(strForm)
{
	if(strForm==null)
	{
		if(document.forms.length!=0) return document.forms(0);
	}
	else
		if(document.forms(strForm)!=null) return document.forms(strForm);
	return null;
}



function checkSelected(strName, strItem, intIndex, intSubIndex, strForm)
{
	var objForm, objSelect;

	if(typeof(intIndex)=="string" && intSubIndex==null && strForm==null)
	{
		strForm  = intIndex;
		intIndex = null;
	}
	else if(typeof(intSubIndex)=="string" && strForm==null)
	{
		strForm     = intSubIndex;
		intSubIndex = null;
	}
	if(intSubIndex==null) intSubIndex = 0;

	if(typeof(intSubIndex)=="number")
	if((objForm=getForm(strForm))!=null)
	if((objSelect=objForm.elements(strName, intSubIndex))!=null)
	if(objSelect.tagName=="SELECT")
	if(objSelect.selectedIndex==-1 || objSelect.selectedIndex==intIndex)
	{
		prvAlertCheck(strItem, "À»", " ¼±ÅÃÇÏ½Ê½Ã¿À.");
		objSelect.focus();
		return false;
	}
	else
		return true;
	alert(strERRDESCJS);
	return false;
}



function checkRequired(strName, strItem, intMinSize, intSubIndex, strForm)
{
	var objForm, objInput;

	if(typeof(intMinSize)=="string" && intSubIndex==null && strForm==null )
	{
		strForm    = intMinSize;
		intMinSize = null;
	}
	else if(typeof(intSubIndex)=="string" && strForm==null)
	{
		strForm     = intSubIndex;
		intSubIndex = null;
	}
	if(intMinSize==null)  intMinSize  = 0
	if(intSubIndex==null) intSubIndex = 0

	if(typeof(intMinSize)=="number" && typeof(intSubIndex)=="number")
	if((objForm=getForm(strForm))!=null)
	if((objInput=objForm.elements(strName, intSubIndex))!=null)
	if(objInput.tagName=="INPUT" && (objInput.type=="text" || objInput.type=="password"))
	if(LTrim(objInput.value)=="")
	{
		if(strItem!=null) prvAlertCheck(strItem, "À»", " ÀÔ·ÂÇÏ½Ê½Ã¿À.");
		objInput.focus();
		objInput.select();
		return false;
	}
	else
	{
		if(objInput.value.length>=intMinSize) return true;
		prvAlertCheck(strItem, "Àº", " "+intMinSize.toString()+"ÀÚ ÀÌ»óÀÔ´Ï´Ù.");
		objInput.focus();
		objInput.select();
		return false;
	}
	alert(strERRDESCJS);
	return false;
}



function checkTextArea(strName, strItem, blnRequired, strForm)
{
	var objForm, objTextArea;

	if((objForm=getForm(strForm))!=null)
	if((objTextArea=objForm.elements(strName))!=null)
	if(objTextArea.tagName=="TEXTAREA")
	{
		var intSize = intMAXLENGTH, objSize;
		if((objSize=objTextArea.getAttribute("maxLength"))!=null)
			if(!isNaN(objSize)) intSize = parseInt(objSize);

		var strTextArea = objTextArea.value;
		if(blnRequired && LTrim(strTextArea)=="")
		{
			prvAlertCheck(strItem, "À»", " ÀÔ·ÂÇÏ½Ê½Ã¿À.");
			objTextArea.focus();
			objTextArea.select();
			return false;
		}

		var intLength = strTextArea.length;
		if(intLength>intSize)
		{
			prvAlertCheck(strItem, "ÀÌ", " " + intLength.toString() + "±ÛÀÚÀÔ´Ï´Ù.\n" + intSize.toString() + "±ÛÀÚ¸¦ ÃÊ°úÇÒ ¼ö ¾ø½À´Ï´Ù.");
			objTextArea.focus();
			objTextArea.select();
			return false;
		}
		return true;
	}
	alert(strERRDESCJS);
    return false;
}




function checkFormat(strName, strItem, strType, blnRequired, intMinSize, intSubIndex, strForm)
{
	var objForm, objInput;


	if(typeof(strType)=="boolean")
	{
		strForm     = intSubIndex;
		intSubIndex = intMinSize;
		intMinSize  = blnRequired;
		blnRequired = strType;
		strType     = null;
	}
	if(typeof(intMinSize)=="string" && intSubIndex==null && strForm==null )
	{
		strForm    = intMinSize;
		intMinSize = null;
	}
	else if(typeof(intSubIndex)=="string" && strForm==null)
	{
		strForm     = intSubIndex;
		intSubIndex = null;
	}
	if(intMinSize==null)  intMinSize  = 0
	if(intSubIndex==null) intSubIndex = 0

	if(typeof(intMinSize)=="number" && typeof(intSubIndex)=="number")
	if((objForm=getForm(strForm))!=null)
	if((objInput=objForm.elements(strName, intSubIndex))!=null)
	if(objInput.tagName=="INPUT" && (objInput.type=="text" || objInput.type=="file"))
	{
		if(strType==null)
		{
			if((strType=objInput.className)==null)
			{
				alert(strERRDESCJS);
				return false;
			}
			switch(strType=Trim(strType.toUpperCase().replace(new RegExp("REQUIRED", "g"), "")))
			{
				case "DATE":
				case "TELNO":
					break;
				default:
					alert(strERRDESCJS);
					return false;
			}				
		}

		var strValue = objInput.value;
		if(LTrim(strValue)=="")
			if(blnRequired==true)
			{
				var strMessage;
				if(objInput.type=="text")
					strMessage = "ÀÔ·Â";
				else
					strMessage = "¼±ÅÃ";
				prvAlertCheck(strItem, "À»", " " + strMessage + "ÇÏ½Ê½Ã¿À.");
				objInput.focus();
				objInput.select();
				return false;
			}
			else
				return true;
		else if(objInput.value.length<intMinSize)
		{
			prvAlertCheck(strItem, "Àº", " " +intMinSize.toString()+"ÀÚ ÀÌ»óÀÔ´Ï´Ù.");
			objInput.focus();
			objInput.select();
			return false;
		}

		var strPattern;
		switch(strType=strType.toUpperCase())
		{
			case "CURRENCY":
				strPattern = "^-?\\d+$";
				break;
			case "DATE":
				strPattern = strFORMATDATE;
				break;
			case "DIGITS":
				strPattern = "^\\d+$";
				break;
			case "EMAIL":				
				strPattern = "^\\w+(\\.\\w+)*@(\\w|-)+(\\.(\\w|-)+)+$";
				break;
			case "FILENAME":
				strPattern = "^[A-Za-z]:(\\\\[^.\\\\/:*?\"<>|][^\\\\/:*?\"<>|]*)+$";
				break;
			case "NUMBER":
				strPattern = "^\\s*(\\d+(,\\d{3})*\.?)?\\s*$";
				break;
			case "TELNO":
				strPattern = "^\\d{2,4}-\\d{3,4}-\\d{4}$";
				break;
			case "WORD":
				strPattern = "^\\w+$";
				break;
			default:
				alert(strERRDESCJS);
				return false;
		}
		if(checkRegExp(strValue, strPattern))
		{
			switch(strType)
			{
				case "DATE":
					if(IsDate(strValue)) return true;
					break;
				default:
					return true;
			}
		}
		var strExample = "";
		switch(strType)
		{
			case "DATE":
				strExample = " (ÀÔ·Â ¿¹: 20031231)";
				break;
			case "TELNO":
				strExample = " (ÀÔ·Â ¿¹: 012-345-6789)";
				break;
		}
		prvAlertCheck(strItem, "À»", " È®ÀÎÇÏ½Ê½Ã¿À." + strExample);
		objInput.focus();
		objInput.select();
		return false;
	}
	alert(strERRDESCJS);
    return false;
}


function checkRegExp(strText, strPattern, blnIgnoreCase)
{
	var strFlags = "i";
	if(blnIgnoreCase==false) strFlags = "";

	return (new RegExp(strPattern, strFlags)).test(strText);
}


function checkRadioChecked(strName, strItem, strForm)
{
	var objForm, objElements;

	if((objForm=getForm(strForm))!=null)
	if(objForm.elements(strName)!=null)
	{
		objElements = objForm.elements;
		for(var lngLoop=0;lngLoop<objElements.length;lngLoop++)
			if(	objElements(lngLoop).name==strName &&
				objElements(lngLoop).tagName=="INPUT" &&
				objElements(lngLoop).type=="radio" &&
				objElements(lngLoop).checked) return true;
		for(lngLoop=0;lngLoop<objElements.length;lngLoop++)
			if(	objElements(lngLoop).name==strName &&
				objElements(lngLoop).tagName=="INPUT" &&
				objElements(lngLoop).type=="radio")
			{
				prvAlertCheck(strItem, "À»", " ¼±ÅÃÇÏ½Ê½Ã¿À.");
				objElements(lngLoop).focus();
				return false;
			}
	}
	alert(strERRDESCJS);
	return false;
}


function checkCheckboxChecked(strName, strItem, strForm)
{
	var objForm, objElements;

	if((objForm=getForm(strForm))!=null)
	if(objForm.elements(strName)!=null)
	{
		objElements = objForm.elements;
		for(var lngLoop=0;lngLoop<objElements.length;lngLoop++)
			if(	objElements(lngLoop).name==strName    &&
				objElements(lngLoop).tagName=="INPUT" &&
				objElements(lngLoop).type=="checkbox" &&
				objElements(lngLoop).checked) return true;
		for(lngLoop=0;lngLoop<objElements.length;lngLoop++)
			if(	objElements(lngLoop).name==strName    &&
				objElements(lngLoop).tagName=="INPUT" &&
				objElements(lngLoop).type=="checkbox")
			{
				prvAlertCheck(strItem, "À»", " ¼±ÅÃÇÏ½Ê½Ã¿À.");
				objElements(lngLoop).focus();
				return false;
			}
	}
	alert(strERRDESCJS);
	return false;
}


function setRadioChecked(strName, strValue, strForm)
{
	var objForm, objElements;

	if((objForm=getForm(strForm))!=null)
	if(objForm.elements(strName)!=null)
	{
		objElements = objForm.elements;
		for(var lngLoop=0;lngLoop<objElements.length;lngLoop++)
			if(	objElements(lngLoop).name==strName &&
				objElements(lngLoop).tagName=="INPUT" &&
				objElements(lngLoop).type=="radio" &&
				objElements(lngLoop).value==strValue)
				return (objElements(lngLoop).checked = true);
	}
	alert(strERRDESCJS);
	return false;
}



function getRadioValue(strName, strForm)
{
	var objForm, objElements;

	if((objForm=getForm(strForm))!=null)
	if(objForm.elements(strName)!=null)
	{
		objElements = objForm.elements;
		for(var lngLoop=0;lngLoop<objElements.length;lngLoop++)
			if(	objElements(lngLoop).name==strName &&
				objElements(lngLoop).tagName=="INPUT" &&
				objElements(lngLoop).type=="radio" &&
				objElements(lngLoop).checked==true)
				return objElements(lngLoop).value;
	}
	alert(strERRDESCJS);
	return false;
}



function focusSelect(strName, strMessage, intSubIndex, strForm)
{
	var objForm, objElement;

	if(typeof(strMessage)=="number" && strForm==null)
	{
		strForm     = intSubIndex;
		intSubIndex = strMessage;
		strMessage  = null;
	}
	else if(typeof(intSubIndex)=="string" && strForm==null )
	{
		strForm     = intSubIndex;
		intSubIndex = null;
	}
	if(intSubIndex==null) intSubIndex = 0

	if((objForm=getForm(strForm))!=null)
	if((objElement=objForm.elements(strName, intSubIndex))!=null)
	{
		if(strMessage!=null) alert(strMessage);
		objElement.focus();
		objElement.select();
		return false;
	}
	alert(strERRDESCJS);
	return false;
}



function prvAlertCheck(strItem, strPostPos, strText)
{
	if(strItem==null)
	{
		alert(strERRDESCJS);
		return;
	}


	var lngLength = strItem.length;

	switch(strItem.substr(lngLength-1,1))
	{
		case ".":
			strPostPos = "";
			strText = "";
			break;
		case "-":
			switch(strPostPos)
			{
				case "À»":
					strPostPos = "¸¦";
					break;
				case "ÀÌ":
					strPostPos = "°¡";
					break;
				case "Àº":
					strPostPos = "´Â";
			}
			strItem = strItem.substr(0, lngLength-1);
	}
	if(strText==null) strText = "";
	alert(strItem + strPostPos + strText);
}


function setCursor(strCursor)
{
	var winTop = top;
	try
	{
		var objDoc = winTop.document;
	}
	catch(e)
	{
		winTop = self;
	}

	
	winTop.document.body.style.cursor = strCursor;


	if(winTop.frames.length==0) return;


	var objElements = winTop.document.all;
	for(var lngLoop=0;lngLoop<objElements.length;lngLoop++)
		if((objElements(lngLoop).tagName=="FRAME" || objElements(lngLoop).tagName=="IFRAME")
			&& objElements(lngLoop).src!="")
			switch(winTop.frames(objElements(lngLoop).name).document.readyState)
			{
				case "complete":
				case "interactive":
					if(winTop.frames(objElements(lngLoop).name).document.body!=null)
						winTop.frames(objElements(lngLoop).name).document.body.style.cursor = strCursor;
					break;
			}

}

/*
function setCursor(strCursor)
{
	top.document.body.style.cursor = strCursor;

	if(top.frames.length==0) return;


	var objElements = top.document.all;
	for(var lngLoop=0;lngLoop<objElements.length;lngLoop++)
		if((objElements(lngLoop).tagName=="FRAME" || objElements(lngLoop).tagName=="IFRAME")
			&& objElements(lngLoop).src!="")
			switch(top.frames(objElements(lngLoop).name).document.readyState)
			{
				case "complete":
				case "interactive":
					if(top.frames(objElements(lngLoop).name).document.body!=null)
						top.frames(objElements(lngLoop).name).document.body.style.cursor = strCursor;
					break;
			}
}
*/


function CDate(objValue)
{
	var dtmDate;

	switch(typeof(objValue))
	{
		case "object":
			if(objValue.constructor.toString().indexOf("Date()")<0) return;
			dtmDate = objValue;
			break;
		case "string":
		case "number":
			dtmDate = new Date(objValue);
			if(isNaN(dtmDate)) dtmDate = null;
			break;
		default:
			dtmDate = null;
	}
	return dtmDate;
}



function IsDate(objValue)
{
	switch(typeof(objValue))
	{
		case "object":
			if(objValue.constructor.toString().indexOf("Date()")>=0) return true;
			break;
		case "string":
			if(checkRegExp(objValue, strFORMATDATE))
			{
				var dtmDate = new Date(objValue.substr(4, 2)+"/"+Right(objValue, 2)+"/"+Left(objValue, 4));
				if(objValue==dtmDate.getFullYear().toString()+Right("0"+(dtmDate.getMonth()+1).toString(), 2)+Right("0"+dtmDate.getDate().toString(), 2))
					return true;
			}
			break;
	}
	return false;
}



function FormatDate(objValue)
{
	var dtmDate;
	if((dtmDate=CDate(objValue))==null) return "";

	return dtmDate.getFullYear().toString() + "-" + Right("0"+(dtmDate.getMonth()+1).toString(), 2) + "-" + Right("0"+dtmDate.getDate().toString(), 2)
}



function Left(strValue, intLength)
{
	if(strValue==null) return "";
	return strValue.substr(0, intLength);
}



function Right(strValue, intLength)
{
	if(strValue==null) return "";
	return strValue.substr(strValue.length-intLength);
}



function Trim(strString)
{
	if(strString==null) return "";
	return LTrim(RTrim(strString));
}



function LTrim(strString)
{
	if(strString==null) return "";
	return strString.replace(new RegExp("^\\s+"), "");
}



function RTrim(strString)
{
	if(strString==null) return "";
	return strString.replace(new RegExp("\\s+$"), "");
}

function cmdBlink()
{
       var objBlink = document.all.tags("BLINK");
			         
       for (var i=0; i < objBlink.length; i++)
	       objBlink[i].style.visibility = objBlink[i].style.visibility == ""?"hidden":"";			            
} 
			       
function goBlink()
{ 
  if (document.all)
	   setInterval("cmdBlink()", 500);
}

/* <TR>¿¡ highlight ÁÖ±â */

function TR_onmouseover(objTR)
{
	if(objTR==null) return;

	with(objTR)
	{
		if(objTR.select!=null && select!="true" || currentStyle.backgroundColor!=currentStyle.selectcolor)
		{
			style.backgroundColor = currentStyle.highlight;
			setColorTable(objTR, setColorRows(objTR, currentStyle.highlight), currentStyle.highlight);
		}

		if(onclick==null) return;
		style.cursor = "hand";
	}
}



function TR_onmouseout(objTR)
{
	if(objTR==null) return;

	with(objTR)
	{
		if(objTR.select!=null && select!="true" || currentStyle.backgroundColor!=currentStyle.selectcolor)
		{
			style.backgroundColor = currentStyle.bgcolor;
			setColorTable(objTR, setColorRows(objTR, currentStyle.bgcolor), currentStyle.bgcolor);
		}

		if(onclick==null) return;
		style.cursor = "auto";
	}
}



function TR_onclick(objTR)
{
	if(objTR==null) return;

	with(objTR)
	{	
		if(tagName!="TR") return;


		var objTRs = parentElement.rows;

		for(var lngLoop=0;lngLoop<objTRs.length;lngLoop++)
			if(	lngLoop!=rowIndex &&
				objTRs(lngLoop).select!=null && 
				objTRs(lngLoop).select=="true" )
				objTRs(lngLoop).style.backgroundColor = currentStyle.bgcolor;

		if(objTR.select!=null && select=="true")
		{
			style.backgroundColor = currentStyle.selectcolor;
			setColorTable(objTR, setColorRows(objTR, currentStyle.selectcolor), currentStyle.selectcolor);
		}
	}
}



function setColorRows(objTR, strColor)
{
	if(objTR==null) return;

	with(objTR)
	{	
		if(tagName!="TR") return;


		var intRowGroup;
		var strRowGroup = parentElement.parentElement.rowGroup;
		if(strRowGroup!=null && strRowGroup!="" && !isNaN(strRowGroup) && (intRowGroup=parseInt(strRowGroup))>1)
			;
		else
			intRowGroup = 1;


		var intIndex, intCount = 0, lngLoop, objTRs = parentElement.rows;
		for(lngLoop=0;lngLoop<objTRs.length;lngLoop++)
			if(objTRs(lngLoop).className=="")
				if(lngLoop==rowIndex)
				{
					intIndex = intCount;
					break;
				}
				else
					intCount++;

		intCount = 0;
		var intGroup = Math.floor(intIndex/intRowGroup), intTemp;
		for(lngLoop=0;lngLoop<objTRs.length;lngLoop++)
			if(objTRs(lngLoop).className=="")
			{
				if(lngLoop!=rowIndex)
				{
					intTemp = Math.floor(intCount/intRowGroup);
					if(intGroup==intTemp)
						objTRs(lngLoop).style.backgroundColor = strColor;
					else if(intGroup < intTemp)
						break;
				}	
				intCount++;
			}
	}
	return intIndex;
}



function setColorTable(objTR, intIndex, strColor)
{
	if(objTR==null) return;

	with(objTR)
	{	
		if(intIndex==null) return;

		var strTable, objTable;
		if((strTable=parentElement.parentElement.link)==null) strTable = "";
		if((objTable=document.all(strTable, 0))==null) return;


		var intGroup = Math.floor(intIndex/intRowGroup), intCount = 0, lngLoop, objTRs = objTable.rows, intTemp;
		for(lngLoop=0;lngLoop<objTRs.length;lngLoop++)
			if(objTRs(lngLoop).className=="highlight")
			{
				intTemp = Math.floor(intCount/intRowGroup);
				if(intGroup==intTemp)
					objTRs(lngLoop).style.backgroundColor = strColor;
				else if(intGroup < intTemp)
					break;
				intCount++;
			}
	}
}

function HTMLEncode(strHTML)
{
    return strHTML.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

