/*
UI Center 박한얼

- id와 name이 없을 경우는 daumActiveXObject[0~99]로 임의로 생성
- id와 name중 하나만 값을 넣을 경우, id와 name을 같은 값으로 설정
- id와 name의 값을 모두 지정한 경우, 해당값으로 설정
- width와 height를 지정하지 않은 경우는 100%를 기본값으로 설정
- codebase를 지정하지 않은 경우는 empty string으로 설정
- activeX에 필요한 파라미터는 한쌍의 배열로 name과 value를 지정

ex)
----------------------------------------------------------------
<div id="activeXControl"></div>
<script type="text/javascript" src="activeX.js"></script>
<script type="text/javascript">

var obj = new Object();
obj.classid = 'CLSID:A00B2A53-60D9-4477-ADA3-60490770C5E0';
obj.id = 'FileUpload';
obj.name = 'FileUpload';
obj.width = '100%';
obj.height = '126';
obj.codebase = '/hanmail-ax/hanmail.cab#version=1,0,0,21';

var param = [
	['PID','30476'],
	['ActionTime','20060123161002'],
	['BIG_UploadURL','/Mail-bin/bigfile_attach.cgi'],
	['BIG_PrecheckURL','/Mail-bin/bigfile_precheck.cgi'],
	['BIG_ServerName','bigmail21.mail.daum.net'],
	['MaxNormalSize','200480000'],
	['MinBigFileSize','20480000'],
	['MaxFileCount','10'],
	['BIG_ExpireDay','7'],
	['Normal_ServerName','premium65.daum.net'],
	['Normal_UploadURL','/Mail-bin/attach_mail.frame_ax.cgi'],
];

obj.param = param;
daumActiveX(obj,'activeXControl');

</script>
----------------------------------------------------------------

* version history

- 1.0
  ; object, embed 태그를 js로 삽입
  ; ie의 경우 object 태그로, 이외의 경우 embed 태그로 activex 삽입

- 1.1
  ; 모질라의 경우 swf에 파라미터를 전달할 경우 flashvars를 src.swf?var=aaa로 값 전달 할 수 있도록 변경.

- 1.2
  ; IE에서 오랜시간 동안 '페이지 로딩 중...'으로 표시되는 문제 해결
  ; 모질라에서 wmode=transparent 안되던 문제 해결

- 1.3
  ; MS에서 제시한 구현방법대로 했을 경우 이미 설치된 ActiveX의 경우에는 문제가 없으나,
    아직 설치되지 않은 ActiveX의 경우 '설치하시겠습니까?'라는 창이 뜨지 않고, x-box로 표시되는 문제 해결.

- 1.4
  ; onerror, onmouseover 등의 이벤트 핸들링에 대한 코드 추가.

- 1.5
  ; ie 외 브라우저에서 flashvars 전달 오류 수정

----------------------------------------------------------------

* 새로운 버젼 적용 방법

- daumActiveX 함수만 최근 버젼으로 교체.
*/

function daumActiveX(obj,div){
	// generate html code
	// for ie obejct
	var html = '<object ';
	if (!obj.id && !obj.name){
		var r = Math.round(Math.random()*100);
		html += 'id="daumActiveXObject'+r+'" name="daumActiveXObject'+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+'" ';
	// append events
	for (var i in obj.events){
		if (obj.events[i]){
			html += obj.events[i][0]+'="'+obj.events[i][1]+'" ';
		}
	}
	// end of object tag
	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="daumActiveXObject'+r+'" name="daumActiveXObject'+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];
			}
			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;
	}
	else document.getElementById(div).innerHTML = html;
}

// 한페이지에 한종류의 activeX가 복수개 삽입되는 경우 하단과 같이 function을 만들어서 사용
function daumFlash(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;
	daumActiveX(obj,div);
}

function activex(obj,div){
		try{	
			var isIE = (document.all) ? true:false;
		
			if(isIE == true){
				var obj_tag = "";
				obj_tag = obj_tag + "<object id='" + obj.id + "' width=" + obj.width + " height=" + obj.height + " classid= '" + obj.classid + "' codebase='" + obj.codebase + "'>\r\n";
				for(var i=0;i<obj.param.length;i++){
					if (obj.param[i]){									
						obj_tag = obj_tag + "<param name='"+obj.param[i][0]+"' value='"+obj.param[i][1]+"'>\r\n";							
					}
				}				
				obj_tag = obj_tag + "</object>";
								
				document.write(obj_tag);				
			} else {		
				if(obj.type == "application/x-shockwave-flash" || obj.classid == "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"){
					var embed_tag = "";
					
					embed_tag = "<embed ";	
									
					for(var i=0;i<obj.param.length;i++){
						if (obj.param[i]){	
							embed_tag += obj.param[i][0]+"='"+obj.param[i][1]+"' ";						
						}
					}
													
					embed_tag += "name='"+obj.name+"' ";
					embed_tag += "width='"+obj.width+"' ";
					embed_tag += "height='"+obj.height+"' ";
					embed_tag += "type='application/x-shockwave-flash' ";
					embed_tag += "pluginspage='http://www.macromedia.com/go/getflashplayer'>";
					embed_tag += "</embed>";			

					document.write(embed_tag);
				}				
			}	
		}catch(e){ }		
	}

function dic_flash(name,src,width,height,div){	
		try{	
		        var obj = new Object();
	
			obj.id = name;
			obj.name = name;
			
			obj.type = "application/x-shockwave-flash";
			obj.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
			obj.codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0";
			   
			obj.width = width;
			obj.height = height;
			
			var isIE = (document.all) ? true:false;
			
			if(isIE == true){	        	        
				var param = [
					["movie",src],
					["wmode","transparent"],
					["quality","high"],
					["menu","false"]
				];
			} else {			
				var param = [
					["src",src],
					["wmode","transparent"],
					["quality","high"],
					["bgcolor","#FFFFFF"],
					["menu","false"]
				];			
			}
		        
		        obj.param = param;				      		        
						
			activex(obj,div);        
	        }catch(e){ }
	}
