var clipBoardMsgTimerId = null;

function setClipboard(divtag, msgtag, errMsg, doneMsg){
	var ua        = navigator.userAgent.toLowerCase(); 
	var is_pc_ie  = ( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ) );

	if(clipBoardMsgTimerId != null) {
		clearTimeout(clipBoardMsgTimerId);
	}

	var blogText = document.getElementById(divtag).value;
	if(blogText == null || blogText == "") {
		if(errMsg != null) {
			alert(errMsg);
			return;
		}
	}
	if(document.getElementById('scriptEmbedSwf') == null) {
		var scriptEmbedSwf = document.createElement('div');
		scriptEmbedSwf.id = 'scriptEmbedSwf';
		scriptEmbedSwf.width = '0';
		scriptEmbedSwf.height = '0';
		document.getElementsByTagName('body')[0].appendChild(scriptEmbedSwf);
	}
	if (is_pc_ie) {
		copytext = document.getElementById(divtag).createTextRange();
		copytext.execCommand("Copy");
	}else{
		document.getElementById('scriptEmbedSwf').innerHTML = "";
		var swf = "<embed src='/flash/setClipboard.swf' FlashVars='code="+encodeURIComponent(document.getElementById(divtag).value)+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
		document.getElementById('scriptEmbedSwf').innerHTML = swf;
	}
	if(doneMsg != null) {
		var msg = document.getElementById(msgtag);
		msg.innerHTML = doneMsg;
		clipBoardMsgTimerId = setTimeout(function() { msg.innerHTML = ""; }, 3*1000);
		//alert(doneMsg);
	}
	//document.getElementById(divtag).value = '';
}
