// upload ÇÊµå Ãß°¡
function CkImageVal() {
    var oInput = event.srcElement;
    var fname = oInput.value;
        if((/(.jpg|.jpeg|.gif|.png)$/i).test(fname))
          oInput.parentElement.children[0].src = fname;
    else
      alert('Image File Only!!');
}

function AddFile(tblAttFiles)
{
	var ns = (document.getElementById && !document.all)?1:0;
    var objTbl =(ns)?document.getElementById(tblAttFiles):document.all['tblAttFiles'];  
    var objRow = objTbl.insertRow();
    var objCell = objRow.insertCell();
        objCell.innerHTML = "<img src='/_global/_img/no_image.gif' width=95 border=0 align=absbottom>\n" +
          "<input type=file onChange='CkImageVal()' name=upfile[] size=60>";
    document.recalc();
}

function fast_open(url,width,height)
{
	window.open(url,"",'width='+width+',height='+height+',status=no,scrollbars=yes,resizable=yes');  
}

function s_location(url)
{	
	location.href=url;
}


function select_input(input_name,input_value) {
    for ( i = 0 ; i < document.forms.length; i ++ ) {
        for ( j = 0 ; j < document.forms[i].elements.length; j++) {
            with(document.forms[i].elements[j]) {
                if(name == input_name) {
                    if( value == input_value) { checked=true; }
                        else if(type!='radio' && type != 'checkbox') { value=input_value; }
                }
            }
        }
    }
}

var attachments = 0;

function fileAttach(obj) {
if (!obj.value) return;
var id = obj.id;
var no = id.substring("file".length);

sizAdd(no, obj.value);

attachments++;
document.upload_form.attachments.value = attachments;

obj.style.display = "none";

var dvLayer = document.getElementById("attachBtnLayer");
no++;
sHTML = "<span id=attachBtn"+no+"><input type=file name=upfile["+no+"] id=file"+no+" onchange='fileAttach(this)' size='1' style='width: 0px; height: 100px;'></span>";

dvLayer.insertAdjacentHTML("afterEnd", sHTML);
}

function fileDeattach(no) {
var fileObj = document.getElementById("attachBtn"+no);
var sizObj  = document.getElementById("sizAttachment_"+no);

sizObj.innerHTML = "<b style=font-family: Verdana; font-size: 8pt;>"+no+".</b> <span style=font-family: Verdana; font-size: 8pt;>deleted</span>";
fileObj.innerHTML = "";
}

function fileKill() {
var fileObj = document.getElementById("attachBtn"+(attachments+1));
fileObj.innerHTML = "";
}

function sizAdd(no, value) {
var obj = document.getElementById("attachFile");
var sHTML;

sHTML  = "<SPAN ID=sizAttachment_"+no+">";
sHTML += "<b style=font-family: Verdana; font-size: 8pt;><font size=-1>"+no+".</font></b> ";
sHTML += "<SPAN ID=sizAttachment_name_"+no+" style=font-family: Verdana; font-size: 8pt;><font style='font-size:11px'><b>"+value+"</b></font></SPAN> ";
sHTML += "<SPAN ID=sizAttachment_remove_"+no+" style=font-family: Verdana; font-size: 8pt; font-weight: bold; cursor: pointer; onclick=fileDeattach("+no+")> - <font size=-2>Del</font></SPAN>";
sHTML += "</SPAN>";

if (attachments == 0) {
obj.innerHTML = sHTML;
} else {
obj.innerHTML += "<br>"+sHTML;
}
}

// Script from http://www.faqts.com/knowledge_base/view.phtml/aid/5756
// for FireFox :D
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
{
switch (where){
case 'beforeBegin' :
	this.parentNode.insertBefore(parsedNode,this);
	break;
case 'afterBegin':
	this.insertBefore(parsedNode,this.firstChild);
	break;
case 'beforeEnd':
	this.appendChild(parsedNode);
	break;
case 'afterEnd':
	if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
	else this.parentNode.appendChild(parsedNode);
	break;
	}
}

HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
{
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML)
}


HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
{
var parsedText = document.createTextNode(txtStr)
this.insertAdjacentElement(where,parsedText)
}
}


function isNULL(val) {
	if (val.split(' ').join('') == '') return false;
	else return true;
}

function replace123(str1, str2, str3)
{
    var rgexp = new RegExp(str1,"g");
    return (str3.replace(rgexp, str2));
}


function toEntity(strHtml)
{
	return replace123("<","&lt;",strHtml);
}

function calcHeight(FrameName)
{

	if(document.all) 
	{
		var the_height = frames[FrameName].document.body.scrollHeight;
	} 
	else 
	{
		var the_height= document.getElementById(FrameName).contentWindow.document.body.offsetHeight;
	}
	document.getElementById(FrameName).height=the_height;
} 

function addBookmark(title, url){
  if(window.sidebar){ // Firefox
    window.sidebar.addPanel(title, url,'');
  }else if(window.opera){ //Opera
    var a = document.createElement("A");
    a.rel = "sidebar";
    a.target = "_search";
    a.title = title;
    a.href = url;
    a.click();
  } else if(document.all){ //IE
    window.external.AddFavorite(url, title);
  }
}

function CartAdd(state,s_num,mode,f)
{
	f.cart_state.value=state;		
	f.action = "/?_dir=common_process&_f=shopcart_db&s_num="+s_num+"&mode="+mode+"&count="+f.count.value;
	f.submit();
	return;
}

function _CartRe(i,v)
{
	var re_count_v = eval("document.re.re_count_"+i+".value");
	location="/?_dir=common_process&_f=shop_cartlist&mode=re&re_count="+re_count_v+"&re_o_num="+v;
}
function _CartDel(v)
{
	document.location.href="/?_dir=common_process&_f=shop_cartlist&mode=del&re_o_num="+v;
}
function money_point(str)
{ 
	str = parseInt(str,10);
	str = str.toString().replace(/[^-0-9]/g,'');
	while(str.match(/^(-?\d+)(\d{3})/))
	{
		str = str.replace(/^(-?\d+)(\d{3})/, '$1,$2');
	}
	return str;
}

function display_t_message(t,m,width,height)
{
	document.write("<center><table cellpadding='4' width='"+width+"' style='margin:5 0 0 0;border:1px solid #A7A772;padding:2px;background-color:#FFFFD9;'><tbody><tr><td width='5' valign='top'></td><td valign='top'><p><b>"+t+"</b><br>"+m+"</p></td></tr></tbody></table></center>");
}

function check_bg(bool,id)
{
	if(bool)
	{
		document.getElementById(id).style.cssText='background:#FFFFCC';
	}
	else
	{
		document.getElementById(id).style.cssText='background:#ffffff';

	}
}

function mcheck(oElement,form_name){
	
	var len = form_name.mck.length;
	var chkArr = form_name.mck;
	var boolv =  oElement.checked;
	for(var i=0;i<len;i++)
	{
		chkArr[i].checked = boolv;		
		if(chkArr[i].value != 'on')
		{
			var idc = 'bg_'+chkArr[i].value;
			check_bg(boolv,idc);
		}
	}
}

function round(elm, bgcolor, border, mode) {
  var top = document.createElement('div'); top.style.cssText = 'height:5px';
  var bottom = document.createElement('div');bottom.style.cssText = 'height:5px';
  var temp = document.createElement('div'); temp.setAttribute('id', 'template');
  var border2 = (border) ? ";border-left:2px solid "+border+";border-right:2px solid "+border : "";
  var border1 = (border) ? ";border-left:1px solid "+border+";border-right:1px solid "+border : "";
  var bgcolor2 = (bgcolor) ? ";background:"+bgcolor : "";
  var bgcolor1 = (border) ? ";background:" + border : (bgcolor) ? ";background:" + bgcolor : "";

  var top_r = new Array(), bottom_r =new Array();
  var box = elm.cloneNode(true);
  for (i=1; i < 5 ;i++ )
  { top_r[i] = document.createElement('div')}

  top_r[1].style.cssText = 'overflow:hidden;margin:0px 5px;height:1px' + bgcolor1;
  top_r[2].style.cssText = 'overflow:hidden;margin:0px 3px;height:1px' + border2 + bgcolor2;
  top_r[3].style.cssText = 'overflow:hidden;margin:0px 2px;height:1px' + border1 + bgcolor2;
  top_r[4].style.cssText = 'overflow:hidden;margin:0px 1px;height:2px' + border1 + bgcolor2;

 
  for (i=1; i < 5 ;i++ ) {
    if (mode!='bottom') { top.appendChild(top_r[i]);temp.appendChild(top); }
    bottom_r[i] = top_r[i].cloneNode(true);    
  }

  temp.appendChild(box);
  box.style.cssText =  border1 + bgcolor2;
  var clear = document.createElement('div');clear.style.cssText = 'clear:both';
  temp.appendChild(clear);
  temp.appendChild(bottom);

  if (mode!='top') {
    for (i=4; i > 0 ;i-- ) {
      bottom.appendChild(bottom_r[i]);
    }
  }
  elm.parentNode.replaceChild(temp, elm);
} 
