/*********************************************************
File Name : script.js
PRODUCT : ezaid 1.2.0 
File Version : 0.1.2
javascript Version : 1.2
Library Info : 
**********************************************************
@author : Ikarus
@contributors : h0a0c0k
@Build Date : 2002.10.11
@Last Modification Date : 2003.04.21
@Description : javascript utils.. - ÁÖ¹Î ¹øÈ£ Ã¼Å©ÇÏ´Â°Í Ãß°¡ 2002.12.7
@Copyright DaZone Tech Inc.
*********************************************************/

function ToLower(arg)
{
     var str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     var str2 = "abcdefghijklmnopqrstuvwxyz";
     return alterString(arg,str1,str2);
}
    
    
function checkJumin(str)
{ 
	//alert(str);
	var jumin  = /^[0-9]{6}-?[0-9]{7}$/; 
	var number = /^[0-9]*$/; 

	var len  = str.length; 
	var a    = ""; 
	var tmp  = ""; 
	var tmp2 = ""; 
	
	for(i=0; i<len; i++)
	{ 
		a = str.substring(i,i+1); 
		
		if(!number.test(a)) continue; 
		
		tmp = str.substring(i,i+14); 
		tmp2 = str.substring(i,i+13); 
		
		if(jumin.test(tmp) || jumin.test(tmp2) )
		{ 
			return false; 
		} 
	}
 
	return true; 
} 
function is_consist_number_str(str)
{
	len = str.length;
	if ( len <= 0 ) 
	{
		return false;
	}
	
	find_other_character = false;
	consist_number_character = true;
	
	for(i=0;i<len;i++)
	{
		chr = str.substring(i, i+1);
		// '0' °ú '9' »çÀÌ¸¦ ¹þ¾î³ª´ÂÁö ¾Ë¾Æ º»´Ù.
		if( chr < '0' || chr > '9' )
		{
			find_other_character = true;
			consist_number_character = false;
			break;
		}
	} // end of for
	
	return consist_number_character;
	
} // end of is_consist_number_str()


function left_trim(str)
{
	len = str.length;
	if ( len <= 0 )
	{
		return str;
	}
	
	idx = -1;
	for(i=0; i<len; i++) 
	{
		if ( str.charCodeAt(i) == 13 || str.charCodeAt(i) == 32 || str.charCodeAt(i) == 10 || str.charCodeAt(i) == 9) 
		{
			continue;
		}
		else
		{
			idx = i;
			break;
		}
	} // end of for()
	
	if ( idx == -1)
	{
		return "";
	}
	else 
	{
		return str.substring(idx, len);
	}
	
} // end of left_trim()


function right_trim(str)
{
	len = str.length;
	if ( len <= 0 )
	{
		return str;
	}
	
	idx = -1;
	for(i=len-1; i>=0; i--) 
	{
		if ( str.charCodeAt(i) == 13 || str.charCodeAt(i) == 32 || str.charCodeAt(i) == 10 || str.charCodeAt(i) == 9) 
		{
			continue;
		}
		else
		{
			idx = i;
			break;
		}
	} // end of for()
	
	if ( idx == -1)
	{
		return "";
	}
	else 
	{
		return str.substring(0, idx+1);
	}
} // end of right_trim()

function trim(str)
{
	if ( str.length <= 0 )
	{
		return str;
	}
	
	str = right_trim(str);
	str = left_trim(str);
	
	return str;
} // end of trim()


function isVaildResidentNumber(regidentNum1, regidentNum2)
{
	if ( trim(regidentNum1).length == 0 || trim(regidentNum2).length == 0 )
		return false;
	if ( !is_consist_number_str(regidentNum1) || !is_consist_number_str(regidentNum1) )
		return false;
	
	socno = regidentNum1 + regidentNum2;
	if(socno == "7002271786193") 
		return false;

	var socnoStr = socno.toString();
    a = socnoStr.substring(0, 1);
    b = socnoStr.substring(1, 2);
    c = socnoStr.substring(2, 3);
    d = socnoStr.substring(3, 4);
    e = socnoStr.substring(4, 5);
    f = socnoStr.substring(5, 6);
    g = socnoStr.substring(6, 7);
    h = socnoStr.substring(7, 8);
    i = socnoStr.substring(8, 9);
    j = socnoStr.substring(9, 10);
    k = socnoStr.substring(10, 11);
    l = socnoStr.substring(11, 12);
    m = socnoStr.substring(12, 13);
	month = socnoStr.substring(2,4);
	day = socnoStr.substring(4,6);
	socnoStr1 = socnoStr.substring(0, 7);
	socnoStr2 = socnoStr.substring(7, 13);

	// ¿ùÀÏ valid check
	if(month <= 0 || month > 12) 
		return false;

	if(day <= 0 || day > 31) 
		return false;

     // ÁÖ¹Îµî·ÏµÞÀÚ¸® Ã¹¹øÂ° ¹øÈ£ À¯È¿¼º Ã¼Å© (1,2,3,4) are only valid
	if(g > 4 || g == 0)
		return false;

	 // ÁÖ¹Îµî·Ï¹øÈ£¿¡ °ø¹éÀÌ µé¾î°¡µµ °¡ÀÔÀÌ µÇ´Â °æ¿ì°¡ ¹ß»ýÇÏÁö ¾Êµµ·Ï
	 if (isNaN(socnoStr1) || isNaN(socnoStr2))
		 return false;

     temp=a*2+b*3+c*4+d*5+e*6+f*7+g*8+h*9+i*2+j*3+k*4+l*5;
     temp=temp%11;
     temp=11-temp;
     temp=temp%10;
    
     if(temp == m)
		return true;
     else
        return false;
} // end of isVaildResidentNumber()

function isCorrectEmailFormat(email)
{
	// regular expression Áö¿ø ¿©ºÎ Á¡°Ë - Explorer 4.0 ÀÌ»ó ºÎÅÍ Áö¿ø.
	var supported = 0;
	if (window.RegExp) 
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) 
			supported = 1;
	}
	if (!supported)
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

	return (!r1.test(str) && r2.test(str));
}

function getScreenSize()
{
	var args = new Array();
	args["width"] = screen.width;
	args["height"] = screen.height;

	return args;
}

function getPopWndCenterPosition(popupWidth, popupHeight)
{
	var args = new Array();
	screenWnd = getScreenSize();
	args["left"] = (screenWnd["width"] - popupWidth) / 2;
	args["top"] = (screenWnd["height"] - popupHeight) / 2;

	return args;

}

function showBookMarkConfirmForm(siteUrl, siteIntroduce)
{
	window.external.AddFavorite(siteUrl, siteIntroduce);
}

function getDaysInMonth(year, month)
{
	monthInDays = new Array();

	monthInDays[0] = 31; //1
	monthInDays[1] = (leapYear(year)) ? 29 : 28; //2
	monthInDays[2] = 31; //3
	monthInDays[3] = 30; //4
	monthInDays[4] = 31; //5
	monthInDays[5] = 30; //6
	monthInDays[6] = 31; //7
	monthInDays[7] = 31; //8
	monthInDays[8] = 30; //9
	monthInDays[9] = 31; //10
	monthInDays[10] = 30; //11
	monthInDays[11] = 31; //12

	return monthInDays[month-1];

}

function leapYear(year) {
	if (year % 4 == 0)
	{
		if (year % 100 == 0)
		{
			if ((year % 400) == 0) return true;
			return false;
		}
		return true;
	}
	return false;
}

function DashDisplay(obj)
{
	obj = eval(obj);
	if ( obj != null ) {
		obj.style.border = "3px dashed #88AAEE";
	}
}

function DashNotDisplay(obj)
{
	obj = eval(obj);
	if ( obj != null ) {
		obj.style.border = "";
	}
}

function IsValidUserIdFormat(id)
{
	if ( trim(id) == "" )
	{
		alert("¾ÆÀÌµð¸¦ ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.");
		return false;
	}

	if ( id.length < 3 || id.length > 15)
	{
		alert("Èñ¸Á ¾ÆÀÌµð´Â 3ÀÚ ÀÌ»ó, 15ÀÚ ÀÌÇÏ·Î ÀÔ·ÂÇÏ¼Å¾ß ÇÕ´Ï´Ù.");
		return false;

	}

	id = id.toLowerCase();

	for(i=0; i < id.length; i++)
	{
		code = id.charCodeAt(i);
		
		if ( !(code >= 48 && code <= 57 || code >= 97 && code <= 122)) 
		{
			alert("Èñ¸Á ¾ÆÀÌµð´Â ¿µ¹®ÀÚ, ¼ýÀÚ·Î ÀÌ·ç¾î Á®¾ß ÇÕ´Ï´Ù.");
			return false;
		}
	}

	return true;
}

function CreateControl(DIV_ID,URL,WIDTH,HEIGHT)
{
	var d = document.getElementById(DIV_ID);
	d.innerHTML =
	'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+WIDTH+'" height="'+HEIGHT+'">' +
	'<param name="movie" value="'+URL+'">' +
	'<param name="quality" value="high">' +
	//'<param name="wmode" value="transparent">'+
	'<embed src="'+URL+'" quality="high" width="'+WIDTH+'" height="'+HEIGHT+'" type="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>' +
	'</object>';
}
