//==============================================================
// Common JavaScript
//==============================================================
// FileName : common.js
// Last update : 2004-11-08
//==============================================================

//==============================================================
// Check Empty Filed & Process That...
//==============================================================

function empty_proc(obj, msg)
{
	if(obj.value.trim() == "")
	{
		alert(msg);
		obj.value = "";
		obj.focus();

		return true;
	}

	return false;
}

//==============================================================
// °ø¹éÀ» ¾ø¾Ö´Â ÇÔ¼ö
//==============================================================
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function openWindow(theURL,winName,features) 
{ //v2.0
  window.open(theURL,winName,features);
}

//=======================================================================================================
/// Æ¯Á¤ °³¼öÀÇ °ªÀÌ µé¾î¿À¸é Æ÷Ä¿½º ³Ñ°ÜÁÖ±â
//=======================================================================================================

function sendFocus(source, target, number)
{
	if(source.value.length >= number)
		target.focus();
}

//=======================================================================================================
/// ÇÑ±Û ÀÔ·Â Ã¼Å©
//=======================================================================================================

function checkKorean(str)
{
	 var j = 0;
	 var CodeNum;

	for(i = 0; i < str.length; i++)
	{
		CodeNum = str.charCodeAt(i);

		if(CodeNum < 128)
		{
			j = j + 1;				
		}	
	}

	if(j > 0)
		return false;
	else
		return true;
}

//=======================================================================================================
/// ÇØ´ç ÇÊµå¸¦ ºñ¿î´Ù.
//=======================================================================================================

function setEmpty(obj)
{
	obj.value = "";
	obj.focus();
}

//=======================================================================================================
/// ÁÖ¹Îµî·Ï¹øÈ£ Ã¼Å©
//=======================================================================================================

function checkResident(resident1, resident2)
{
	var chk =0;

	for (var i = 0; i <=5 ; i++)
	{
		chk = chk + ((i % 8 + 2) * parseInt(resident1.substring(i, i + 1)));
	}

	for (var i = 6; i <= 11 ; i++)
	{
		chk = chk + ((i % 8 + 2) * parseInt(resident2.substring(i-6, i-5)));
	}

	chk = 11 - (chk % 11);
	chk = chk % 10;

	if (chk != resident2.substring(6, 7))
		return false;
	else
		return true;
}

//=======================================================================================================
/// Check_Email
//=======================================================================================================

function check_email(email)
{
	var atsym = email.indexOf("@");
	var period = email.indexOf(".");
	var space = email.indexOf(" ");
	var length = email.length -1;

    if((atsym < 1)||(period <=atsym+1)|| (period==length)|| (space != -1))
	{
		return false;
	}

	return true;
}

//=======================================================================================================
/// GetCookie
//=======================================================================================================

function getCookie(name)
{
	var nameOfCookie = name + "=";
	var x = 0;

	while (x <= document.cookie.length)
	{
		var y = (x + nameOfCookie.length);

		if (document.cookie.substring(x, y) == nameOfCookie) 
		{
			if((endOfCookie = document.cookie.indexOf(";", y)) == -1)
				endOfCookie = document.cookie.length;
				
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}

		x = document.cookie.indexOf(" ", x) + 1;

		if(x == 0)
			break;
	}

	return "";
}

//=======================================================================================================
/// SetCookie
//=======================================================================================================

function setCookie(name, value, expiredays)
{
	var todayDate = new Date();
	
	todayDate.setTime(todayDate.getTime() + (1000*30*24*60*60));

	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

//=======================================================================================================
/// checkRadio
//=======================================================================================================

function checkRadio(oRadio, strMessage)
{
	for(var i = 0; i < oRadio.length; i++)
		if(oRadio[i].checked)
			return true;

	alert(strMessage);

	return false;
}

//===========================================================================
// checkNumber
//===========================================================================

function checkNumber(nNumber)
{ 
    var anum=/(^\d+$)|(^\d+\.\d+$)/ ;

    if (anum.test(nNumber))
        return true; 
    else 
        return false; 
}

//===========================================================================
// bluring
//===========================================================================

function bluring(){
if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus();
}
document.onfocusin=bluring;

function TxtCheck(key, CtlName, TextMask)
{
	if((key > 47&&key < 58)||(key > 95 && key <106)) 
	{
		if(CtlName.value.length < TextMask.length) 
		{ 
			var aa = CtlName.value + String.fromCharCode(key);

			if(key > 47 && key < 58) 
			{
				var zz = aa.charAt(aa.length-1);
			}
			else if(key > 95 && key < 106)
			{	
				switch(key)
				{
					case 96: zz = '0'; break; case 97: zz = '1'; break;
					case 98: zz = '2'; break; case 99: zz = '3'; break;
					case 100: zz = '4'; break; case 101: zz = '5'; break;
					case 102: zz = '6'; break; case 103: zz = '7'; break;
					case 104: zz = '8'; break; case 105: zz = '9'; break;
				}
			}

			if(TextMask.charAt(aa.length-1) == '#') 
				CtlName.value = CtlName.value + zz;
			else 
				CtlName.value = CtlName.value + TextMask.charAt(aa.length-1) +zz;
			
			return false;
		}
	}
	else if(key == 8 || key == 9 || key == 13) 
		return ; 
	
	return false;
}

function onlyNumber1()
{
	if(((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 45))
		event.returnValue=false;
}

function onlyNumber()
{
	if((event.keyCode < 48) || (event.keyCode > 57))
		event.returnValue=false;
}


//===========================================================================
// È°¼º, ºñÈ°¼º ¼³Á¤
//===========================================================================

function showObject(Obj,Boolen)
{
	if(Boolen){					//È°¼ºÈ­
		Obj.disabled = false;
		Obj.style.background = "#ffffff";
	}
	else{						//ºñÈ°¼ºÈ­
		Obj.disabled = true;
		Obj.style.background = "#dddddd";
	}
}

//==========================================================================
// ÀÌ¹ÌÁö °ü·ÃÇÔ¼öµé....
//==========================================================================

function resizeImageAll(oNode)
{
	imageFind(oNode);

	oNode.style.display = "block";
}

function imageFind(oNode)
{
	if(oNode == undefined) {
		return ;
	}

	if(oNode.tagName == "IMG") {
		resizeImage(oNode);
	} else if(oNode.all.length == 0) {
		return ;
	}

	for(var i = 0; i < oNode.all.length; i++) {
		imageFind(oNode.all[i]);
	}
}

function resizeImage(oNode)
{
	var oImage = new Image();
	oImage.src = oNode.src;

	var maxWidth = 610;
	var maxHeight = 500;

	var nWidth = oImage.width;
	var nHeight = oImage.height;
	var nNewW = nWidth;
	var nNewH = nHeight;

	if(nWidth > maxWidth) {
//		if(nWidth > nHeight) {
			nNewW = maxWidth;
			nNewH = Math.round((nHeight * nNewW) / nWidth);
//		} else {
//			nNewH = nHeight;
//			nNewW = Math.round((nNewH * nWidth) / nHeight);
//		}
	}

	oNode.width = nNewW;
	oNode.height = nNewH;
	oNode.style.cursor = "hand";
	//oNode.onclick = function() { imageClick(this); };
}

function imageClick(oNode)
{
	window.open("/zoom.php?img=" + oNode.src, "", "");
}

//===========================================================================
// »ö»óÇ¥ ¶ç¿ò
//===========================================================================

function SetColorTable(Obj)
{
	var color = showModalDialog("ColorChart.html",0,"dialogHeight=186px;dialogWidth=236px; scrollbars=no; status=0; help=0");

    if(color != null){
		Obj.value = color;
	}
}

//===========================================================================
// ÀÔ·ÂµÈ °ªÀÌ ID·Î »ç¿ëµÉ ¼ö ÀÖ´Â °æ¿ì¿¡ true¸¦ ¸®ÅÏÇÑ´Ù.
//===========================================================================

function isID(obj)
{ 
	var str = obj.value;

	if(str.length == 0)
		return false;

	str = str.toUpperCase();
	if(!('A' <= str.charAt(i) && str.charAt(i) <= 'Z'))
		return false;

	for(var i=1; i < str.length; i++) {
		if(!(('A' <= str.charAt(i) && str.charAt(i) <= 'Z') ||
			('0' <= str.charAt(i) && str.charAt(i) <= '9') ||
			(str.charAt(i) == '_')))
			return false;
	}
	return true;
}





//===========================================================================
// ÇÃ·¡½¬ ÆÐÄ¡
//===========================================================================


function setEmbed() 
{ 
  var obj = new String; 
  var parameter = new String; 
  var embed = new String; 
  var html = new String; 
  var allParameter = new String; 
  var clsid = new String; 
  var codebase = new String; 
  var pluginspace = new String; 
  var embedType = new String; 
  var src = new String; 
  var width = new String; 
  var height = new String; 

    
  this.init = function( getType , s ,w , h ) { 
      
      if ( getType == "flash") 
      { 

        clsid = "D27CDB6E-AE6D-11cf-96B8-444553540000";        
        codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"; 
        pluginspage = "http://www.macromedia.com/go/getflashplayer"; 
        embedType = "application/x-shockwave-flash"; 
      } 
      /* type Ãß°¡ 
      else if ( ) 
      { 
      } 
      */ 
            
      parameter += "<param name='movie' value='"+ s + "'>\n";  
      parameter += "<param name='quality' value='high'>\n";    
      
      src = s; 
      width = w; 
      height = h; 
  } 
  
  this.parameter = function( parm , value ) {      
      parameter += "<param name='"+parm +"' value='"+ value + "'>\n";        
      allParameter += " "+parm + "='"+ value+"'"; 
  }  
  
  this.show = function() { 
      if ( clsid ) 
      { 
        obj = "<object classid=\"clsid:"+ clsid +"\" codebase=\""+ codebase +"\" width='"+ width +"' height='"+ height +"'>\n"; 
      } 
      
      embed = "<embed src='" + src + "' pluginspage='"+ pluginspage + "' type='"+ embedType + "' width='"+ width + "' height='"+ height +"'"+ allParameter +" ></embed>\n"; 
      
      if ( obj ) 
      { 
        embed += "</object>\n"; 
      } 
      
      html = obj + parameter + embed; 
      
      document.write( html );  
  } 
  
}

function zoom2_gongu(File,Width,Height)
{
	window.open("zoom_product.php?idx="+File,"","scrollbars=no,width="+Width+",height="+Height+",top=50,left=200");
}




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_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_findObj(n, d) { //v3.0
  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); 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 MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

