function div_update( ta, url ) {
	if( typeof $(ta) == "undefined") {
		var t = top.document.getElementById(ta);
	} else {
		var t = $(ta);
	}
	if( typeof t == "object") {
		new Ajax.Request( url, {
			method: "post",
			onSuccess: function( transport ) {
				t.update(transport.responseText);
			}
		});
	}
}

//HTML CREATE

function Flash(id,url,param,w,h,bg,t){//Flash_Create
	if(!bg) bg = "#FFFFFF";
	if(!t) t = "transparent";
	document.write("\
<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width="+w+" height="+h+" id="+id+">\
<param name='movie' value="+url+" />\
<param name='FlashVars' value="+param+" />\
<param name='wmode' value="+t+" />\
<param name='bgcolor' value="+bg+" />\
<param name='allowScriptAccess' value='always' />\
<param name='quality' value='high' />\
<param name='menu' value='false' />\
<embed src="+url+" width="+w+" height="+h+" name="+id+" bgcolor="+bg+" allowScriptAccess='always' quality='high' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />\
</object>\
	");
}


//HTML CREATE
function move( url ) {
	document.location.href=url;
}

function setCookie(name,value,expire) {
	var expires = new Date();
	expires.setDate(expires.getDate() + expire);
	document.cookie=name + "=" + escape(value) + ((expires == null)? "" : (" ; expires=" + expires.toGMTString())) + ";";
}

function getCookie(name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while(i< clen){
		var j = i + alen;
		if(document.cookie.substring(i,j)==arg){
			var end = document.cookie.indexOf(";",j);
			if(end == -1)
				end = document.cookie.length;
			return unescape(document.cookie.substring(j,end));
		}
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}

function login_frm_check() {
	var frm = document.login_frm;
	div_update("inside_lyr", "inc/login.php?id="+frm.id.value+"&pwd="+frm.pwd.value);
	return false;
}

function member_logout() {
	location.href='/inc/logout.php';
	//div_update("inside_lyr", "inc/logout.php");
}

function num_chk( ta , ta2) {
	var t = ta.value.replace(/[^0-9]/, "");
	ta.value = t;
	if(ta.getAttribute && $(ta2) && ta.value.length == ta.getAttribute("maxlength")) {
		$(ta2).focus();
	}
}
function phone_chk(ta) {
	var t = ta.value.replace(/[^-0-9]/,"");
	ta.value = t;
}

function float_chk( ta ) {
	var t = ta.value.replace(/[^0-9\.]/, "");
	ta.value = t;
}

function alpha_chk( ta ) {
	var t = ta.value.replace(/[^a-zA-Z]/, "");
	ta.value = t;
}

function chk_email_frm(tmp) {
    if(/^[_0-9a-zA-Z-]+(\.[_0-9a-zA-Z-]+)*@[0-9a-zA-Z-]+(\.)+([0-9a-zA-Z-]+)([\.0-9a-zA-Z-])*$/.test(tmp) == false) {
        return false;
    } else {
        return true;
    }
}

function chg_main_img( ta ) {
	var t = document.getElementById("main_img");
	t.src = "data/picture/middle_"+ta;
}

function img_view( uid, stat, num) {
	if( typeof num == "undefined" ) num = 0;
	if(typeof window.pageYOffset == "undefined") {
		to_y = document.body.scrollTop;
	} else {
		to_y = window.pageYOffset;
	}
	if(stat) {
		
		var ta = document.createElement("div");
		ta.setAttribute("id", "main_img_bg");
		ta.style.backgroundColor = "#000000";
		ta.style.position = "absolute";
		ta.style.top = to_y;
		ta.style.left = 0;
		ta.style.filter = "alpha(opacity=60)";
		ta.style.MozOpacity = "0.6";
		ta.style.width = document.body.clientWidth;
		ta.style.height = document.body.clientHeight+10;
		ta.style.zIndex = 10;

		var in_l = $("inside_lyr");
		in_l.parentNode.insertBefore(ta, $("inside_lyr"));
		div_update("inside_lyr", "/inc/main_img_view.php?UID="+uid+"&num="+num);
		in_l.style.zIndex = 15;
		in_l.style.top = 0;
		in_l.style.left = 0;
		in_l.style.display = "inline";
		setTimeout(img_view, 3);
	} else if($("main_img_bg")) {
		var ta = $("main_img_bg");
		var in_l = $("inside_lyr");
		ta.style.top = to_y;
		ta.style.width = document.body.clientWidth;
		ta.style.height = document.body.clientHeight+10;
		in_l.style.top = 0;
		in_l.style.left = 0;
		setTimeout(img_view, 3);
	}
}

function img_view_close() {
	var ta = $("main_img_bg");
	var in_l = $("inside_lyr");
	in_l.innerHTML = "";
	in_l.parentNode.removeChild(ta);
	in_l.style.top=0;
	in_l.style.left=0;
	in_l.style.display="none";
}

function img_view_chg( url ) {
	var ta = $("main_img_view_detail");
	ta.src = "data/picture/"+url;
}

function open_zipcode( ta1, ta2, ta3, ky, tar) {
    if( typeof ky == "undefined" ) ky = "";
	if(typeof tar == "undefined") tar="zipcode_lyr";
    div_update(tar+"_body", "/inc/member_zipcode.php?ta1="+ta1+"&ta2="+ta2+"&ta3="+ta3+"&keyword="+escape(ky)+"&t_lyr="+tar);
    $(tar).style.display = "inline";
}

function zipcode_insert( t1, t2, t3, r1, r2, r3, tar) {
    $(t1).value = r1;
    $(t2).value = r2;
    $(t3).value = r3;
    $(tar+"_body").innerHTML = "";
    $(tar).style.display = "none";
}

function number_format(numstr) {
	var numstr = String(numstr);
	var re0 = /(\d+)(\d{3})($|\..*)/;
	if (re0.test(numstr))
		return numstr.replace(
			re0,
			function(str,p1,p2,p3) { return number_format(p1) + "," + p2 + p3; }
		);
	else
		return numstr;
}

function cal_open_inc( tname , dt, e) {
    var body = document.getElementById("cal_open_body");
    var url = "/config/cal.php?tname="+tname;
    if(dt) url = url + "&" + dt;
    div_update("cal_open_body", url);
    body.style.display = "inline";
    body.style.position = "absolute";
    body.style.left = e.clientX;
    body.style.top = e.clientY;
}

function cal_open_inc2( tname , dt) {
    var body = document.getElementById("cal_open_body");
    var tar = document.getElementById(tname);
    tar.value = dt;
    body.style.display = "none";
}

function catalog_close() {
	var tar=document.getElementById("catalog_view_lyr");
	tar.innerHTML="";
	tar.style.display="none";
}
function catalog_detail_close() {
	var tar=document.getElementById("catalog_view_detail_lyr");
	tar.innerHTML="";
	tar.style.display="none";
}
function open_catalog_detail(uid) {
	var tar = document.getElementById("catalog_view_detail_lyr");
	tar.style.top = 210;
	tar.style.left = Math.ceil((document.body.clientWidth - 900) / 2);
	div_update("catalog_view_detail_lyr", "inc/catalog_view_detail.php?UID="+uid);
	tar.style.display = "inline";
}
function cata_chg(flag, n) {
    
	var o_cate, o_cate2 = "";
	if(flag=="o_cate") {
		o_cate = n;
		o_cate2 = $("o_cate2").value;
	} else {
		o_cate = $("o_cate").value;
		o_cate2 = n;
	}		
		
	div_update("catalog_view_lyr", "inc/catalog_view.php?o_cate="+o_cate+"&o_cate2="+o_cate2);
}

function img_bigView(src, uid) {

	$("imgView").innerHTML = "<IMG SRC=\"data/picture/middle_"+src+"\" border=0 id=\"main_img\" class=a onclick=\"img_view('"+uid+"', true)\">";
}

function sort_product(n, chk){

	var mater = document.getElementById("mater").value;
	var code = document.getElementById("code").value;
	//var hot = document.getElementById("hot").value;
	//var price = document.getElementById("price").value;
	var keyword = document.getElementById("keyword").value;
	var rows = document.getElementById("rows").value;
	var metric = document.getElementById("metric").value;
	var gauges = document.getElementById("gauges").value;

	if(n=="metric") {
		var metric = document.getElementById("metric").value;
		var gauges = "";
	} else if(n=="gauges") {
		var gauges = document.getElementById("gauges").value;
		var metric = "";
	}
	if(rows>20 || n=="rows")
		var rows = "all";

	var tmp = code.substring(0, 2);
	if (chk != 1) {
		if (tmp == "00") 	mater = "";
	} else {
		if (tmp == "00")		code = "";
	}
	
	location.href="sub_list.php?code="+code+"&mater="+mater+"&keyword="+keyword+"&metric="+metric+"&gauges="+gauges+"&rows="+rows;
}

function all_select(obj) { 
    
	var chkFlag = (obj.checked)? true: false; 
    var chkList = document.getElementsByName("id"); 
	var check_value = $("all_check_value").value;

    if(chkList.length > 0) { 
        for (var i=0; i<chkList.length; i++) { 
            chkList[i].checked = chkFlag; 
        } 
		if(chkFlag==true)
		    $("all_value").value = check_value;
		else 
		    $("all_value").value = "";

    } else { 
        alert("no item selected."); 
	    obj.checked = false; 
       return; 
    } 	
} 

function all_check(obj){

	var all_value = $("all_value").value;
            
    if($(obj).checked == true )     
        all_value = all_value + "/"+$(obj).value;
    else {       
        var array = all_value.split( "/" + $(obj).value );  
        all_value = array[0] + array[1];
    }    
    $("all_value").value = all_value;            
}  

function cart_selectDel() {

	var uids = $("all_value").value;

	if(uids=="") 
		alert("no item selected.");
	else
		div_update("inside_lyr","inc/cart_post.php?uids="+uids);
}
