/**
 * 자바스크립트 공통 함수 파일
 * 이 파일은 시스템 내에서 공통으로 사용되어 지는 부분에 대한 처리를 위한
 * 함수 모음 파일이다
 *
 * 2009/07/21 created by KDH
 */


/**
 * 우편번호 찾기 창을 띄우는 함수
 * 우편번호를 다시 되받기 위해서는 이 창을 띄우는 화면에서
 * zip1, zip2, address1, address2 이렇게 아이디가 할당되어 있어야 한다.
 */
function postCodeWindow() {
window.open('/postcodes/', 'postCodeWindow', 'width=400, height=350, scrollbars=yes');
}

/**
 * 이메일 자동선택 함수
 * 이메일을 선택하면 해당 입력칸에 자동으로 값이 들어가 지게 하는 함수 이다.
 * @param obj 셀렉트박스 object
 * @param target 아이디를 제외한 이메일 주소를 나타내는 폼의 ID값
 */
function selectedEmailProvider(obj, target) {
    var val = obj.value;
    var target_obj = document.getElementById(target);
    if (val == 'direct_input') {
        target_obj.readOnly = false;
        target_obj.value = '';
        target_obj.focus();
    } else {
        target_obj.readOnly = true;
        target_obj.value = val;
    }
}

/**
 * 이메일 유효성 검사
 */
function validateEmail(str_email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(reg.test(str_email) == false) {
        return false;
    }
    return true;
}

/**
 * 클립보드 복사 함수
 * FF에서도 동작되게 swf를 이용한 것이다
 * http://www.aproxacs.com/24 에서 발췌
 */
function copy_value(inElement) {
    var browserName = navigator.appName;
    if ( browserName.search("Explorer") > 0 ) {
        window.clipboardData.setData('Text', inElement.value)
    } else {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="/img/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
    }
    alert ("다음의 내용이 클립보드로 복사되었습니다.\n\n" + inElement.value );
}

//exchange_mode는 환율배너 플래시일때만 Y값을 넘겨준다
/*
function fnFlashObject(id, path, width, height, flashvars) {
    var m_protocol = document.location.protocol.replace(":","");
    var m_movie = path;
    var m_width = width;
    var m_height = height;
    var m_flashvars = flashvars;
    
    this.wmode = "transparent";
    this.id = "";
    this.quality = "high";
    this.menu = "false";
    this.allowScriptAccess = "sameDomain";

    var html;

    html ="";
    html += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='"+ m_protocol +"://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='" + m_width + "' height='" + m_height + "'";
    if (this.id != "") html += " id='" + this.id + "'";
    html += ">";

    html += "<param name='allowScriptAccess' value='" + this.allowScriptAccess + "' />";
    html += "<param name='movie' value='" + m_movie + "' />";
    html += "<param name='menu' value='" + this.menu + "' />";
    html += "<param name='quality' value='" + this.quality + "' />";
    if (this.wmode != "") html += "<param name='wmode' value='" + this.wmode + "' />";
    if (m_flashvars != "") html += "<param name='FlashVars' value='" + m_flashvars + "' />";

    html += "<embed src='" + m_movie + "' quality='" + this.quality + "' pluginspage='"+ m_protocol +"://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + m_width + "' height='" + m_height + "'";
    html += " allowScriptAccess='" + this.allowScriptAccess + "'";
    if (this.wmode != "") html += " wmode='" + this.wmode + "'";
    if (m_flashvars != "") html += " FlashVars='" + m_flashvars + "'";
    html += " /></object>";
    
    document.getElementById(id).innerHTML = html;
    //document.write(html);
    
}
*/
function fnFlashObject(fid,src,wid,hei,fvs) { 
    var wmd = "transparent";
    this.fPrint = ''; 
    this.Id = document.getElementById(fid); 
    this.Src = src; 
    this.Width = wid; 
    this.Height = hei; 
    this.FlashVars = ( typeof fvs != 'undefined')? fvs :''; 
    this.Wmod = ( typeof wmd != 'undefined')? wmd :''; 
    if(isObject(Id)) { 
        fPrint = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"'; 
        fPrint += ' id="'+Id+'"'; 
        fPrint += ' width="'+Width+'"'; 
        fPrint += ' height="'+Height+'">'; 
        fPrint += '<param name="movie" value="'+Src+'">'; 
        fPrint += '<param name="quality" value="high">'; 
        fPrint += '<param name="allowScriptAccess" value="always" />';
        fPrint += (FlashVars != null) ? '<param name="FlashVars" value="'+FlashVars+'">' : ''; 
        fPrint += (Wmod != null) ? '<param name="wmode" value="'+Wmod+'">' : ''; 
        fPrint += '<embed'; 
        fPrint += ' name="'+Id+'"'; 
        fPrint += ' src="'+Src+'"'; 
        fPrint += (FlashVars != null) ? ' FlashVars="'+FlashVars+'"' : ''; 
        fPrint += (Wmod != null) ? ' wmode="'+Wmod+'"' : ''; 
        fPrint += ' quality="high"'; 
        fPrint += ' pluginspage="http://www.macromedia.com/go/getflashplayer"'; 
        fPrint += ' type="application/x-shockwave-flash"'; 
        fPrint += ' width="'+Width+'"'; 
        fPrint += ' height="'+Height+'"'; 
        fPrint += ' allowScriptAccess="always"></embed>'; 
        fPrint += '</object>'; 
        Id.innerHTML = fPrint; 
    } 
} 

function isObject(a) {
    return (a && typeof a == 'object');
}
