﻿// 팝업윈도우 띄우기
function popwindow(name, url, width, height)
{
  var LeftPosition;
  var TopPosition;
  
  if (screen.width < 1025)
  {
    LeftPosition=0;
    TopPosition=0;
  }
  else
  {
    LeftPosition = (screen.width)?(screen.width - width)/2:100;
    TopPosition = (screen.heigh)?(screen.heigh - height)/2:100;
  }

	window.open(url, name, "left=" + LeftPosition + ";top=" + TopPosition + ",toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no,width=" + width +",height=" + height + ";")
}

function popwindow2(name, url, width, height)
{
  var LeftPosition;
  var TopPosition;
  
  if (screen.width < 1025)
  {
    LeftPosition=0;
    TopPosition=0;
  }
  else
  {
    LeftPosition = (screen.width)?(screen.width - width)/2:100;
    TopPosition = (screen.heigh)?(screen.heigh - height)/2:100;
  }

	window.open(url, name, "left=" + LeftPosition + ";top=" + TopPosition + ",toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=no,width=" + width +",height=" + height + ";")
}

function SetSelect(argObj,argValue)
{
    obj = eval(argObj)
    for(i=0;i<obj.length;i++)
    {
        if(argValue==obj[i].value) {
            obj.selectedIndex = i;
            break;
        }
    }    
}

//flash handle function
function maxActiveX(obj,div,events){
	// generate html code
	// for ie obejct
	var html = '<object ';
	if (!obj.id && !obj.name){
		var r = Math.round(Math.random()*100);
		html += 'id="maxActiveXObject'+r+'" name="maxActiveXObject'+r+'" ';
	} else {
		if (obj.id) html += 'id="'+obj.id+'" ';
		else html += 'id="'+obj.name+'" ';
		if (obj.name) html += 'name="'+obj.name+'" ';
		else html += 'name="'+obj.id+'" ';
	}
	if (obj.type) html += 'type="'+obj.type+'" ';
	if (obj.classid) html += 'classid="'+obj.classid+'" ';
	if (obj.width) html += 'width="'+obj.width+'" ';
	if (obj.height) html += 'height="'+obj.height+'" ';
	if (obj.codebase) html += 'codebase="'+obj.codebase+'" ';
	if (events) {
	    for (var i in events){
		    html += ' '+events[i][0]+'="javascript:'+events[i][1]+'"';
	    }
	}
	
	html += '>\n';
	// append params
	for (var i in obj.param){
		html += '<param name="'+obj.param[i][0]+'" value="'+obj.param[i][1]+'"/>\n';
	}

	// for ns embed
	html += '<embed ';
	if (!obj.id && !obj.name){
		var r = Math.round(Math.random()*100);
		html += 'id="maxActiveXObject'+r+'" name="maxActiveXObject'+r+'" ';
	} else {
		if (obj.id) html += 'id="'+obj.id+'" ';
		if (obj.name) html += 'name="'+obj.name+'" ';
	}
	if (obj.type) html += 'type="'+obj.type+'" ';
	if (obj.width) html += 'width="'+obj.width+'" ';
	if (obj.height) html += 'height="'+obj.height+'" ';
	// append params
	for (var i in obj.param){
		if (obj.param[i]){
			if (obj.param[i][0]=='movie' || obj.param[i][0]=='src'){
				var _src = obj.param[i][1];
			}
			if (obj.param[i][0].toLowerCase()=='flashvars'){
				if (_src){
					var tmpArr = html.split('src="'+_src+'"');
					html = tmpArr[0]+' src="'+_src+'?'+obj.param[i][1]+'" '+tmpArr[1];
				} else {
					obj.param[obj.param.length] = obj.param[i];
				}
			} else {
				html += obj.param[i][0]+'="'+obj.param[i][1]+'" ';
			}
		}
	}
	html += '/>\n';
	html += '</object>';

	var isIE = (document.all)?true:false;
	if (isIE){
		document.getElementById(div).innerHTML = html;		
	} else if (obj.type=='application/x-shockwave-flash' || obj.classid=='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'){
		// ie외의 브라우저에서 activex가 flash인 경우만 노출
		document.getElementById(div).innerHTML = html;		
	}
}
// 한페이지에 한종류의 activeX가 복수개 삽입되는 경우 하단과 같이 function을 만들어서 사용
function maxFlash(src,width,height,div){
	var obj = new Object();
	obj.type = 'application/x-shockwave-flash';
	obj.classid = 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
	obj.codebase = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
	obj.wmode = 'transparent';
	obj.width = width;
	obj.height = height;

	var param = [
		['movie',src],
		['src',src],
		['quality','high'],
		['wmode','transparent'],
		['bgcolor','#FFFFFF'],
		['pluginspage','http://www.macromedia.com/go/getflashplayer'],
	];
	obj.param = param;

	maxActiveX(obj,div);
}

function toggle_checkbox_list(obj_check, obj_value)
{
  if(obj_value.value == "true")
  {
	  obj_value.value = "false";
	  change_checkbox_status(obj_check, false);
  }
	else
	{
		obj_value.value = "true";
		change_checkbox_status(obj_check, true);
	}
}

function change_checkbox_status(obj_check, obj_value)
{
  if(obj_check.checked != null )
  {
		obj_check.checked = obj_value;
	}
	else
	{
		if( obj_check.length )
		{
			for( var i = 0; i< obj_check.length; i++ )
				obj_check[i].checked = obj_value;
		}
	}
}


//Set default value on Select Form Tag
//Usage: SetSelect("document.eForm.ExSelect","Money");
function SetSelect(argObj,argValue)
{
    obj = eval(argObj)
    for(i=0;i<obj.length;i++)
    {
        if(argValue==obj[i].value) {
            obj.selectedIndex = i;
            break;
        }
    }    
}
