﻿var p_path = location.pathname.split("/");
var p_count = (p_path.length);
var url_name="http://www.wiselife.co.th/";
var js_path;
if (p_count == 2) js_path="";
else if (p_count == 3)	js_path = "../";
else if (p_count == 4)	js_path = "../../";
else if (p_count == 5)	js_path = "../../../";
else js_path = "../../../";
	
function login() {
  //  var p_path = location.pathname.split("/");
   // var p_count = p_path.length;
    var post = 'txt=login&pwd=' + $('#pwd').val() + '&email=' + $('#email').val();
   		p_post = js_path+"back/file_e_commerce.aspx";
   
  /*
  if (p_count == 2)
        p_post = "back/file_e_commerce.aspx";
    else if (p_count == 3) 
        p_post = "../back/file_e_commerce.aspx";
	else if (p_count == 4) 
        p_post = "../../back/file_e_commerce.aspx";
    else if (p_count == 5) 
        p_post = "../../../back/file_e_commerce.aspx";
	else
		p_post = "../../../back/file_e_commerce.aspx";
	*/
    
        $.post(p_post, post, function(result) {
        if (result != 'none') {
            var strdoc = result.split("_P_")
            var user_name = strdoc[0].split("@@@");
            $('#username').html(user_name[1]);
            $('#username').css({ 'color': '#003366', 'text-decoration': 'underline' });
            $('#member_area').html(strdoc[1]);
            //   $('#li_out').remove();
            //  $('#txt_ul #del_all').after("<li id='li_out'><a href='#' onclick='logout_txt()'>ออกจากระบบ</a></li>");
        }
        else {
            alert("ไม่พบรายชื่อสมาชิก กรุณาตรวจสอบอีกครั้ง");
            return false;
        }
    });
}
function show_txt(id) {
    $('#xfoot').css({ 'font-size': '13px', 'font-weigth': 'bold', 'color': 'white' })
    $('#xfoot').html('&nbsp;&nbsp;' + $('#ii_name' + id).val());
}

function load_brand_id(id) { // แสดงชื่อ brand สินค้า และสินค้าในหมวดนั้น
    var iidept = $('#ii_dept' + id).val().split("@@");
    var post = 'txt=brand&dept=' + iidept[0];
    $.post('back/file_process.aspx', post, function(result) {
        var doc_brand = result.split("(@^@)");
        if (doc_brand[1] != 'none') {
            $('#p_brand').show();
            $('#p_brand').html(doc_brand[0]); // brand สินค้า
            $('#show_prod').html(doc_brand[1]); // แสดงสินค้าในหมวดนั้นๆ 10 รายการ
        }
        else {
            alert("ไม่มีสินค้าใหม่หมวดนี้");
        }
        //window.location.href = "#pproduct";
    });

}

function change_pws() { // show pass
    launchCenterN('back/form_allrequest.htm?idd/1', '', 130, 300, 1)
}

function send_mail() {
    post = 'txt=sent&id=999';
    $.post('back/file_e_commerce.aspx', post, function(result) {
        alert(result);
    });
}

function check_login1() {
    post = 'txt=check_login';
    show_window = '';
    $.post('back/file_e_commerce.aspx', post, function(result) {
        if (result != 'none') {
            alert("ยังไม่ได้ ล๊อคอินเข้าสู่ระบบ");
            show_window = '';
            return false;
        }
        else if (result == 'none') {
            load_order();
            return false;

        }
    });
}
function count_ck() { // count จำนวน order
    post = 'txt=count_ck';
    $.post('back/file_e_commerce.aspx', post, function(result) {
        $('#ckcount').html(result);
    });
}

function amount_ck() { // count จำนวน เงิน
    post = 'txt=amount_ck';
    $.post('back/file_e_commerce.aspx', post, function(result) {
        if (result != "") {
            var gamount = parseFloat(result);
            $('#qty_amount').html(gamount.toFixed(2));
        }
    });

}

function load_order() { //ดึงการการที่สั่งซื่อ มาแสดง
  //  var ck_count = $('#ckcount').text();
    // if (ck_count > 0) {
    $('#div_m').remove();
    $('#div_icon').remove();
    $('#div_txt').remove();
  //ar p_path = location.pathname.split("/");
  //  var p_count = p_path.length;

    if (p_count < 3) {
      //  launchCenterN('../form_customerorder.htm?id=999', '', 1000, 970, 1); //900,970
        window.open('form_customerorder.htm?id=999');
       // window.open(url_name+'form_customerorder.htm?id=999');
	    
    }
    else {
       //launchCenterN('form_customerorder.htm?id=999', '', 1000, 970, 1); //900,970
        window.open('form_customerorder.htm?id=999');
       // window.open(url_name+'form_customerorder.htm?id=999');
    }

}
function load_order_guest() { //ดึงการการที่สั่งซื่อ มาแสดง
     // 0=empty 1=website 2=folder 3=filename
    $('#div_m').remove();
    $('#div_icon').remove();
    $('#div_txt').remove();
    if (p_count < 3) {
     //   launchCenterN('../form_customerorder_guest.htm?id=999', '', 1000, 970, 1); //900,970
        window.open(url_name+'form_customerorder_guest.htm?id=999');
        //window.open('form_customerorder_guest.htm?id=999');
    }
    else {
        //launchCenterN('form_customerorder_guest.htm?id=999', '', 1000, 970, 1); //900,970
        //window.open('form_customerorder_guest.htm?id=999');
        window.open(url_name+'form_customerorder_guest.htm?id=999');
        
    }
}
function edit_member() {
    launchCenterN('back/frm_regmember_edit.aspx?e_mail=' + $('#email').val(), '', 650, 900, 1);
}

function load_orderfrmcart(fd,id) {
    $('#div_m').remove();
    $('#div_icon').remove();
    $('#div_txt').remove();
//    d_dept = $('#' + fd + 'dept_id' + id).val();

    var post = 'txt=order_fromcart&dept=' + $('#' + fd + 'fdeptii' + id).val() + '&brand=' + $('#' + fd + 'fvendorii' + id).val() + '&model=' + $('#' + fd + 'i_pid' + id).val() + '&id=' + id;
    var d_dept = $('#' + fd + 'fdeptii' + id).val();

   
  // 	if (d_dept=='d0001' || d_dept=='d0002' || d_dept=='d0003') {
 /*
 if (p_count < 3){
			p_file='back/file_e_commerce.aspx';
	}else{
		 p_file='../back/file_e_commerce.aspx';
		}
	*/
//	var post = 'txt=order_fromcart'
		//  $.post('back/file_e_commerce.aspx', post, function(result) {
		  p_post = js_path+"back/file_e_commerce.aspx";

	   $.post(p_post, post, function(result) {
        if (result != 'err') {
            //     alert(result);
            show_box_order(id, result, d_dept,950,fd);
        }
    });
 
}

function tranfer_form() {
    //  launchCenterN('banktranfer_form.htm', '', 650, 1100, 1)
    window.open("banktranfer_form.htm");
}

function launchCenterN(url, name, height, width, uid) {
    var str = "height=" + height + ",innerHeight=" + height;
    str += ",width=" + width + ",innerWidth=" + width;
    var h1 = height;
    var w1 = width;

    if (window.screen) {
        var ah = screen.availHeight;
        var aw = screen.availWidth;
        var xc = (aw - width) / 2;
        var yc = (ah - height) / 2;

        str += ",left=" + xc + ",screenX=" + xc;
        str += ",top=" + yc + ",screenY=" + yc;
        str += ",toolbar=no,directories=no,status=no,linemenubar=no,scrollbars=no,resizable=no ,modal=yes";
    }

    if (uid == "") {
        alert("ไม่พบรหัสผู้ใช้โปรดตรวจสอบ");
    }
    else {
        var istr = "dialogWidth:" + width + "px; dialogHeight:" + height + "px;dialogLeft:" + xc + "px;dialogTop:" + yc + "px;center:yes;resizable:No;status:No;scroll:No";
        if (window.sList && window.sList.open && !window.sList.closed) {
            sList.close()
        }
        sList = window.showModalDialog(url, name, istr);
        //	sList=window.open(url,name,str)
    }
}

function find_notebook(id) { //แสดง สินค้า
    x_close();
    var b_doc = $('#ii_d' + id).val().split("@@");
    post = 'txt=notebook&dept=' + b_doc[1] + '&brand=' + b_doc[0] + '&loadid=normal'; // แก้ใขการค้นหา
    $.post('back/file_process.aspx', post, function(result) {
        if (result != 'none') {
            $('#show_prod').html(result);
        }
        else {
            alert("ไม่มีสินค้าในหมวดนี้");
        }
    });
}

function load_login_txt(id) { // เช็คการมีอยู่ ของ user
    post = 'txt=check_login_onload';
    if (id == '') {
        f_post = 'back/file_e_commerce.aspx';
    }
    else {
        f_post = '../back/file_e_commerce.aspx';
    }
        $.post(f_post, post, function(result) {
        var strdoc = result.split("_P_")
        var user_name = strdoc[0].split("@@@");
        if (user_name[0] == 'true') { // มี user login
            $('#username').html(user_name[1]);
            $('#username').css({ 'color': '#003366', 'text-decoration': 'underline' });
            $('#member_area').html(strdoc[1]);
           // $('#txt_ul #del_all').after("<li id='li_out'><a href='#' onclick='logout_txt()'>ออกจากระบบ</a></li>");
        }
        else {
            $('#username').remove();
           // $('#li_out').remove();
            $('#member_area').html(result); // ไม่มี ต้อง login ใหม่
        }
    });
}

function logout_txt() {
    post = 'txt=logout';
    $.post('back/file_e_commerce.aspx', post, function(result) {
        var strdoc = result.split("_P_")
        var user_name = strdoc[0].split("@@@");
        $('#username').html(user_name[1]);
        $('#username').css({ 'color': '#003366', 'text-decoration': 'underline' });
        $('#member_area').html(strdoc[1]);
        $('#login_ts').remove();
    });
}

function pass_txt(id) { //ประกาศต่างๆ
    x_close();
    post = 'txt_f=' + id;
    $.post('back/announcement.aspx', post, function(result) {
        if (result != '') {
            window.location.href = "#top";
            var b_txt = result.split("@@@");
            $('#a_add').css({ 'width': '800px', 'margin-left': '5%', 'position': 'absolute', 'z-index': '99', 'display': 'none' });
            $('#a_add').append("<div id='xclose'><b style='cursor:pointer' onclick='x_close()'>XCLOSE&nbsp;&nbsp;</b></div><div id='x_title'></div><div id='x_txt'></div><div id='x_foot'></div>");
            $('#xclose').css({ 'text-align': 'right', 'background-color': '#ABC7C9', 'width': '800px', 'font-family': 'tahoma', 'font-size': '12px', 'margin-right': '3%' });
            $('#x_title').css({ 'background-image': 'url(images/11.jpg)', 'font-family': 'tahoma', 'font-size': '18px', 'color': '#0093D9' });
            $('#x_title').append(b_txt[0]);
            $('#x_txt').css({ 'font-family': 'tahome', 'font-size': '14px', 'color': 'white', 'margin-top': '0px' });
            $('#x_txt').html(b_txt[1]);
            $('#a_add').show("slow");
        }
        else {
            alert("ยังไมมีการเปิดให้บริการในส่วนนี้");
        }
    });
}
function show_img_product() { //เมนู
    x_close();
    post = 'txt=menu';
    $.post('back/file_process.aspx', post, function(result) {
        if (result != '') {
            var doc_value = result.split("@_@");
            window.location.href = "#menu2";
            $('#a_add').css({ 'width': '790px', 'height': doc_value[1] + 'px', 'margin-left': '5%', 'margin-top': '6.5%', 'position': 'absolute', 'z-index': '99', 'display': 'none', 'background-color': 'white', 'filter': 'alpha(opacity=87)' });
            $('#a_add').append("<div id='xclose'><b style='cursor:pointer' onclick='x_close()'>XCLOSE&nbsp;&nbsp;</b></div><div id='x_title'></div><div id='x_txt'></div><div id='xfoot'></div>");
            $('#xclose').css({ 'text-align': 'right', 'background-color': '#004E9B', 'width': '100%', 'height': '20px', 'font-family': 'tahoma', 'font-size': '12px', 'margin-right': '3%', 'color': 'white' });
            $('#x_title').css({ 'margin-left': '2px', 'height': '20px', 'background-color': 'white', 'font-family': 'tahoma', 'font-size': '14px', 'color': 'black', 'text-decoration': 'underline' });
            $('#x_title').append("เลือกหมวดสินค้า");

            $('#x_txt').css({ 'font-family': 'tahome', 'font-size': '14px', 'color': 'white', 'margin-top': '0%' }); // เนื้อหา
            $('#x_txt').html(doc_value[0]);

            $('#xfoot').css({ 'width': '100%', 'height': '100px', 'margin-top': '1.3%', 'font-family': 'tahome', 'font-size': '14px', 'background-color': '#CC3366' }); // ท้าย
            //$('#xfoot').html("ssss");
            $('#a_add').show("slow");
        }
        else {
            alert("ยังไมมีการเปิดให้บริการในส่วนนี้");
        }
    });
}

function x_close() {
    $('#xclose').remove();
    $('#x_title').remove();
    $('#x_title').empty();
    $('#x_txt').remove();
    $('#xfoot').remove();
    $('#x_foot').remove();
    $('#a_add').hide();
    window.location.href = "#top";

}
function screen_productdetail(id) {
    launchCenterN('screen_detail.aspx?id=' + $('#i_pid' + id).val(), '', 670, 990, 1)
}

function launchCenterN(url, name, height, width, uid) {
    var str = "height=" + height + ",innerHeight=" + height;
    str += ",width=" + width + ",innerWidth=" + width;
    var h1 = height;
    var w1 = width;

    if (window.screen) {
        var ah = screen.availHeight;
        var aw = screen.availWidth;
        var xc = (aw - width) / 2;
        var yc = (ah - height) / 2;

        str += ",left=" + xc + ",screenX=" + xc;
        str += ",top=" + yc + ",screenY=" + yc;
        str += ",toolbar=no,directories=no,status=no,linemenubar=no,scrollbars=no,resizable=no ,modal=yes";
    }
    if (uid == "") {
        alert("ไม่พบรหัสผู้ใช้โปรดตรวจสอบ");
    }
    else {
        var istr = "dialogWidth:" + width + "px; dialogHeight:" + height + "px;dialogLeft:" + xc + "px;dialogTop:" + yc + "px;center:yes;resizable:no;scroll:no;status=no;unadorned:yes'";
        if (window.sList && window.sList.open && !window.sList.closed) {
            sList.close()
        }
        sList = window.showModalDialog(url, name, istr);
        //	sList=window.open(url,name,str)
    }
}

function show_detail(fd, id) { // แสดงหน้าการสั้งซื้อ ไปดึงข้อมูลมาแสดง
   var post = 'txt=addnew_ecommerce&dept=' + $('#' + fd + 'fdeptii' + id).val() + '&brand=' + $('#' + fd + 'fvendorii' + id).val() + '&model=' + $('#' + fd + 'i_pid' + id).val() + '&id=' + id;
   var d_dept = $('#' + fd + 'fdeptii' + id).val();
   p_post =js_path+"back/file_e_commerce.aspx";

/*
if (p_count == 2)
        p_post = "back/file_e_commerce.aspx";
    else if (p_count == 3) 
        p_post = "../back/file_e_commerce.aspx";
	else if (p_count == 4) 
        p_post = "../../back/file_e_commerce.aspx";
    else if (p_count == 5) 
        p_post = "../../../back/file_e_commerce.aspx";
	*/
   $.post(p_post, post, function(result) {
   var d_detail = result.split("xxx")
       /*    $('#imain').append("<div id='dd'></div>");
       $('#dd').css({ 'margin': '-15% 0 0 2%', 'position': 'absolute', 'width': '1160px', 'z-index': '5', 'border': '1px solid #CCCCCC', 'background-color': '#BACFD1' });
       $('#dd').html(d_detail[0]);
       $('#amount_total').html(d_detail[1]);
       window.location.href = "#top";
       */
       show_box_order(id, d_detail[0], d_dept, 950, fd);
       //show_box_center(d_detail[0]);
   });
}

function save_cookie(idt) { // สั้งซื้อ
    //รหัสหมวด(0) | brand(1) |รหัสสินค้า(2) |ที่เก็บรูปภาพ(3) |ที่เก็บโลโก้สินค้า(4) |ราคา (5)|จำนวน(6)
    //|ยอดรวม (ราคา * จำนวน)(7) |ชื่อหมวดสินค้า(8)|รายละเอียดของสินค้า(9)
        d_dept = $('#ii_dept').val(); // เช็คหมวดสินค้า
        var sum_amount = (($('#i_price').val()-$('#sp_price').val()) * $('#qty').val()); // ราคาหักส่วนลด
        $('#i_amount').val(sum_amount);    
        var post = 'txt=save_ck&txt_doc=' + $('#ii_dept').val() + '_@@_' + $('#ii_brand').val() + '_@@_' + $('#ii_pid').val() + '_@@_' + $('#ii_imgprod').val();
        post += '_@@_' + $('#ii_imgbrand').val() + '_@@_' + $('#i_price').val() + '_@@_' + $('#qty').val() + '_@@_' + $('#i_amount').val() + '_@@_' + $('#ii_bname').val() + '_@@_' + 'Spec' + '_@@_' + $('#ii_vat').val() + '_@@_' + $('#ii_weight').val() + '_@@_' + $('#sp_price').val(); // 9
 	   p_post = js_path+"back/file_e_commerce.aspx";

		$.post(p_post, post, function(result) {
        var re_doc = result.split("(@_@)");
        if (result == 'done') {
            alert("บันทึกการสั่งซื้้อรายการนี้เรียบร้อย คลิกรายการสั่งซื้ออีกครั้งเพื่อดูรายการที่ปรับปรุงแล้ว");
            count_cookie(); //count cookie
            amount_ck(); //รวมเงิน
            d_close();
        }
        else if (result == 'Error') {
            alert("รายการนี้มีการสั่งซื้อไปแล้ว");
        }
    });
}

function calulate_price() { // คำนวณ ราคาสินค้า
    if ($('#qty').val() == 0 || $('#qty').val() == '') {
        $('#qty').val(1);
    }
    var cur_cal = (($('#i_price').val() - $('#sp_price').val()) * $('#qty').val());
    $('#amount_1').val(cur_cal);
    $('#amount_1').html(cur_cal);
}
function d_close() {
	$('#div_m').remove();
	$('#div_icon').remove();

   // window.location.href = "#pproduct";
   // $('#dd').remove();
}
function del_ck(id) { // ลบ cookie ที่เราเลือก
    var post = 'txt=del_ck&dck=' + $('#delck' + id).val();
    d_dept = $('#dept_id' + id).val(); // เช็คหมวดสินค้า
	//	if (d_dept=='d0001' || d_dept=='d0002' || d_dept=='d0003') {
	   /* 
		if (p_count < 3){
			p_file='back/file_e_commerce.aspx';
		}else{
			p_file='../back/file_e_commerce.aspx';
		}
		*/
		p_post = js_path+"back/file_e_commerce.aspx";
		$.post(p_post, post, function(result) {
        var d_detail = result.split("xxx");
        $('#doc_history').html(d_detail[0]);
        $('#amount_total').html(d_detail[1]);
        count_cookie(); //count cookie
        amount_ck(); // รวมเงิน
    });
}

function del_cookie_all() { // ลบ cookie ทังหมด
    var post = 'txt=del_ck_all';
    $.post('back/file_e_commerce.aspx', post, function(result) {
        var d_detail = result.split("xxx");
        count_cookie(); //count cookie
        amount_ck(); // รวมเงิน
    });
}

function edit_ck(id) {
    var d_detail = $('#delck' + id).val();
    var p_spec = d_detail.split("(@@)");
	$('#pp_model').html(p_spec[2]);
	$('#pp_spec').html(p_spec[10].substring(0, 150) + "<span style='color:red'> (น้ำหนัก = " + p_spec[11] +") </span>");
    $('#iprice').html(p_spec[5]);
    $('#i_price').val(p_spec[5]);
    $('#qty').val(p_spec[6]);
    $('#amount_1').html(p_spec[7]);
    $('#i_amount').html(p_spec[7]);
    $('#p_img').attr('src', p_spec[3]);
    $('#btn_save').attr('value', 'ปรับปรุงรายการซื้อ');
    
     //save to cookie
    $('#ii_dept').val(p_spec[0]);
    $('#ii_brand').val(p_spec[1]);
    $('#ii_pid').val(p_spec[2]);
    $('#ii_imgprod').val(p_spec[3]);
    $('#ii_imgbrand').val(p_spec[4]);
    $('#ii_docspec').val(p_spec[10]);
    $('#ii_vat').val(p_spec[9]);
} 


function count_cookie() {
    var post = 'txt=count_ck'
    $.post('back/file_e_commerce.aspx', post, function(result) {
        $('#ckcount').html(result);
    });
}

function show_cookie_sales() { // show รายการซื่้อ กดจาก cart
    var ck_count = $('#ckcount').text();
    if (ck_count > 0) {
        var post = 'txt=display_cart';
        $.post('back/file_e_commerce.aspx', post, function(result) {
            if (result != "none") {
                $('#imain').append("<div id='dd'></div>");
                $('#dd').css({ 'margin': '-15% 0 0 2%', 'position': 'absolute', 'width': '1160px', 'z-index': '5', 'border': '1px solid #CCCCCC', 'background-color': '#BACFD1' });
                var d_detail = result.split("xxx");
                $('#dd').html(d_detail[0]);
                $('#amount_total').html(d_detail[1]);
            }
            else {
                $('#ckcount').html("0.00");
                $('#qty_amount').html("0.00");
                alert("ไม่พบรายการสั่งซื้อ หรือ ทำรายการเสร็จเรียบร้อยแล้ว");

            }
        });

    }
    else {
        alert("ไม่พบรายการสั่งซื้อ หรือ ทำรายการเสร็จเรียบร้อยแล้ว");
    }

}

function show_box(txt_detail) {
	$('#div_m').remove();
	$('#div_icon').remove();
    $('#menu').append("<div id='div_m' style='position:absolute;margin-left:140px;margin-top:10px;z-index:3;width:900px;height:auto;'></div>");
    $('#div_m').append("<div id='div_icon' style='position:absolute; margin-left:870px;cursor:pointer;margin-top:25px; z-index:8; width:58px; height:58px; top:-46px; left: 19px;'></div>");
	$('#div_icon').html("<img id='img_close' src='images/icon_close.png' width='58' height='58' onclick='div_icon_close()'>");
    $('#div_m').append("<div id='div_txt' style='-moz-border-radius: 5px;position:absolute;margin-left:0px;margin-top:1px;z-index:7;width:900px;height:auto;padding:5px 5px 5px 5px;background-color:#94B355;border:10px solid #3366CC'></div>");
    $('#div_txt').html(txt_detail);
}

function show_box1100(txt_detail,ww,id) {
    $('#div_m').remove();
    $('#div_icon').remove();

    if (id == "1") {
        $('#show_ad').append("<div id='div_m' style='position:absolute;margin-left:-20px;margin-top:10px;z-index:999;width:" + ww + "px;height:auto;'></div>");
        $('#div_m').append("<div id='div_icon' style='position:absolute; margin-left:" + (ww - 20) + "px;cursor:pointer;margin-top:25px; z-index:8; width:58px; height:58px; top:-46px; left: 19px;'></div>");
        $('#div_icon').html("<img id='img_close' src='images/icon_close.png' width='58' height='58' onclick='div_icon_close()'>");
        $('#div_m').append("<div id='div_txt' style='-moz-border-radius: 5px;position:absolute;margin-left:0px;margin-top:1px;z-index:7;width:" + ww + "px;height:auto;padding:5px 5px 5px 5px;background-color:#fff;border:10px solid #3366CC'></div>");

    }
    else {
        $('#menu').append("<div id='div_m' style='position:absolute;left:40%;margin-top:5%;z-index:999;width:" + ww + "px;height:auto;'></div>");
        $('#div_m').append("<div id='div_txt' style='-moz-border-radius: 5px;position:absolute;margin-left:0px;margin-top:1px;z-index:7;width:" + ww + "px;height:auto;padding:5px 5px 5px 5px;background-color:#fff;'></div>");

    }
	$('#div_txt').html(txt_detail);
	window.location = "#9999";
}

function show_box_order(id, txt_detail, deptid,ww,fd) { // แสดงรายการสั่งซื้อสินค้าตำแหน่งตามลำดับสินค้า
	$('#div_m').remove();
	$('#div_icon').remove();
	$('#div_txt').remove();
	var xxp = $('#b_col' + id).val();
	if (xxp == 2)
	    b_id = (id - 1);
	else if(xxp == 3)
	    b_id = (id - 2);
	else
	    b_id = (id);
	var p_top = $('#' + fd + 'xxx' + b_id).position();
		$('#' + fd + 'xxx' + id).append("<div id='div_m' style='-moz-box-shadow: 4px 4px 10px #999999;position:fixed;left:25%;top:25%;z-index:999999;width:" + ww + "px;height:auto;'></div>");

//	  $('#' + fd + 'xxx' + b_id).append("<div id='div_m' style='-moz-box-shadow: 4px 4px 10px #999999;position:absolute;z-index:99;margin-top:95px;margin-left:-150px;width:" + ww + "px;height:auto;font-size:14px;'></div>");
	  $('#div_m').append("<div id='div_icon' style='position:absolute;cursor:pointer;margin-top:40px; z-index:999; width:58px; height:58px; top:-50px; margin-left:"+(ww)+"px;'></div>");
	  $('#div_icon').html("<img id='img_close' src='http://wiselife.co.th/images/icon_close.png' width='58' height='58' onclick='div_icon_close()'>");
      $('#div_m').append("<div id='div_txt' style='-moz-border-radius: 5px;margin-top:1px;z-index:7;width:" + ww + "px;height:auto;padding:5px 5px 5px 5px;background-color:#CCCCCC;border:8px solid #666666'></div>");
      $('#div_txt').html(txt_detail);
}

function order_cal(qty, iprice, amount,amount_txt) {
    if ($('#' + qty).val() == 0 || $('#' + qty).val() == ''){
        $('#' + qty).attr('value', 1);
    }
    var bqty = parseFloat($('#' + qty).val());
    var b_price = parseFloat($('#' + iprice).val());
    cal_amount = (bqty * b_price);
    $('#' + amount).val(cal_amount);
    $('#' + amount_txt).html(cal_amount);
}

function show_box_center(txt_detail) {
    var sc_w = screen.width/7;
    var sc_h = screen.height/1.5;
    $('#div_m').remove();
    $('#div_icon').remove();
    $('#div_txt').remove();
    $('body').append("<div id='div_m' style='-moz-box-shadow: 4px 4px 10px #999999;position:absolute;left:" + sc_w + "px;top:"+sc_h+"px;z-index:3;width:900px;height:auto;'></div>");
    $('#div_m').append("<div id='div_icon' style='position:absolute; margin-left:890px;cursor:pointer;margin-top:-10px; z-index:8; width:58px; height:58px;'></div>");
    $('#div_icon').html("<img id='img_close' src='"+url_name+"images/icon_close.png' width='58' height='58' onclick='div_icon_close()'>");
    $('#div_m').append("<div id='div_txt' style='-moz-border-radius: 5px;position:absolute;margin-left:0px;margin-top:1px;z-index:7;width:900px;height:auto;padding:5px 5px 5px 5px;background-color:#CCCCCC;border:8px solid #666666'></div>");
    $('#div_txt').html(txt_detail);
}


function div_icon_close() {
        $('#div_m').remove();
        $('#img_close').remove();
        $('#div_icon').remove();
        $('#div_txt').remove();
}
function transport_select() {
    var post = 'txt=transport_select';
    $.post('back/file_e_commerce.aspx', post, function(result) {
        show_box_center1(result);
    });
}

function show_box_center1(txt_detail) {
    var sc_w = screen.width / 7;
    var sc_h = screen.height / 2;
    $('#div_m').remove();
    $('#div_icon').remove();
    $('#div_txt').remove();
    $('#menu').append("<div id='div_m' style='-moz-box-shadow: 4px 4px 10px #999999;position:absolute;left:" + sc_w + "px;top:" + sc_w + "px;z-index:3;width:900px;height:auto;'></div>");
    $('#div_m').append("<div id='div_icon' style='position:absolute; margin-left:890px;cursor:pointer;margin-top:-10px; z-index:8; width:58px; height:58px;'></div>");
    $('#div_icon').html("<img id='img_close' src='"+url_name+"images_close.png' width='58' height='58' onclick='div_icon_close()'>");
    $('#div_m').append("<div id='div_txt' style='-moz-border-radius: 5px;position:absolute;margin-left:0px;margin-top:1px;z-index:7;width:900px;height:auto;padding:5px 5px 5px 5px;background-color:#CCCCCC;border:8px solid #666666'></div>");
    $('#div_txt').html(txt_detail);
}

function find_product_form(fd, id) {
    var d_brand = $('#'+fd+'fvendorii' + id).val();
    var d_dept=$('#'+fd+'dept_id'+id).val();
    var post = 'txt=find_product_form&d_brand=' + d_brand + '&deptid=' + d_dept+'&fd='+fd;
    $.post('back/file_e_commerce.aspx', post, function(result) {
        var d_dept = $('#' + fd + 'fdeptii' + id).val();
        show_box_order(id, result, d_dept, 700, fd);
    });

}


function table_select(t_ta,pid){
    $('#t' + pid).attr('value', t_ta);
    $('#ff' + pid).html(t_ta);
    }

    function submit_find_w_brand(fd, brand) { // เลือก แบร์นด์ =1
	    post = 'txt=enter_find&dept=' + $('#ddpt').val() + '&t1=' + $('#t1').val() + '&t2=' + $('#t2').val() + "&d_brand=" + $('#d_brand').val()+'&ibrand='+brand;
	    post += '&t3=' + $('#t3').val() + '&t4=' + $('#t4').val();
	    $.post('back/file_e_commerce.aspx', post, function(result) {
	        if (p_path.length == 2)
	            ppath = p_path[1];
	        else if (p_path.length > 2)
	            ppath = p_path[2];

	        if (result != 'none' && result != '[object XMLDocument]') {
	            if (ppath != "product_show_bydept.aspx") {
	                if (fd == 1)
	                    $('#projector').html(result);
	                else if (fd == 2)
	                    $('#screen').html(result);
	                else if (fd == 12)
	                    $('#sound').html(result);
	            }
	            else {
	                $('#npro').html(result);
	            }
	        }
	        else {
	            alert("ไม่มีข้อมูลสำหรับค้นหา");
	            d_close();
	        }
	    });
	   // location.replace(p_path[2]+"?" + post);	 
  	}

 function show_box_image(txt_detail) {
 var ah = screen.availHeight;
 var aw = screen.availWidth;
 var sc_w = (aw-1000)/2;
 var sc_h = (ah-200)/2;
 var sc_xx = sc_h + 30;
    
    $('#div_m').remove();
    $('#div_icon').remove();
    $('#div_txt').remove();
    $('body').append("<div id='div_m' style='-moz-box-shadow: 4px 4px 10px #999999;position:absolute;left:" + sc_w + "px;top:" + sc_h + "px;z-index:999999;width:1000px;height:auto;'></div>");
    $('#div_m').append("<div id='div_icon' style='position:absolute; margin-left:990px;cursor:pointer;margin-top:-10px; z-index:9999; width:58px; height:58px;'></div>");
    $('#div_icon').html("<img id='img_close' src='"+url_name+"images/icon_close.png' width='58' height='58' onclick='div_icon_close()'>");
    $('#div_m').append("<div id='div_txt' style='-moz-border-radius: 5px;position:absolute;text-align:center;z-index:7;width:1000px;height:auto;padding:5px 5px 5px 5px;background-color:#FFFFFF;border:8px solid #666666'></div>");
    $('#div_txt').html('<img src='+txt_detail+'>');
}

function show_box_image1(txt_detail, fd, id) {
    var ah = screen.availHeight;
    var aw = screen.availWidth;
    var sc_w = (aw - 1400) / 2;
    var sc_h = (ah - 200) / 2;
    var sc_xx = sc_h + 30;
    var p_top = $('#' + fd + 'xxx' + id).position();
    $('#div_m').remove();
    $('#div_icon').remove();
    $('#div_txt').remove();
    $('body').append("<div id='div_m' style='-moz-box-shadow: 4px 4px 10px #999999;position:fixed;left:25%;top:25%;z-index:999999;width:1000px;height:auto;'></div>");
    $('#div_m').append("<div id='div_icon' style='position:absolute; margin-left:990px;cursor:pointer;margin-top:-10px; z-index:9999; width:58px; height:58px;'></div>");
    $('#div_icon').html("<img id='img_close' src='" + url_name + "images/icon_close.png' width='58' height='58' onclick='div_icon_close()'>");
    $('#div_m').append("<div id='div_txt' style='-moz-border-radius: 5px;position:absolute;text-align:center;z-index:7;width:1000px;height:auto;padding:5px 5px 5px 5px;background-color:#FFFFFF;border:8px solid #666666'></div>");
    $('#div_txt').html('<img src=' + txt_detail + '>');
}

function show_box_image_111(id_name) {
    xxx = $(id_name).left;
    var ah = screen.availHeight;
    var aw = screen.availWidth;
    var sc_w = (aw - 600) / 2;
    var sc_h = (ah - 600);
    var sc_xx = sc_h + 30;

    $('#div_m').remove();
    $('#div_icon').remove();
    $('#div_txt').remove();
    $('body').append("<div id='div_m' style='-moz-box-shadow: 4px 4px 10px #999999;position:absolute;left:" + sc_w + "px;top:" + sc_h + "px;z-index:999999;width:650;height:auto;'></div>");
    $('#div_m').append("<div id='div_icon' style='position:absolute; margin-left:630px;cursor:pointer;margin-top:-10px; z-index:9999; width:58px; height:58px;'></div>");
    $('#div_icon').html("<img id='img_close' src='" + url_name + "images/icon_close.png' width='58' height='58' onclick='div_icon_close()'>");
    $('#div_m').append("<div id='div_txt' style='-moz-border-radius: 5px;position:absolute;text-align:center;z-index:7;width:650px;height:auto;padding:5px 5px 5px 5px;background-color:#FFFFFF;border:8px solid #666666'></div>");
    $('#div_txt').html('<img src=' + id_name + '>');
}


function show_box_image250(txt_detail) {
    d_split = txt_detail.split("@@@");
    $('#div_m').remove();
    $('#div_icon').remove();
    $('#div_txt').remove();
    $('body').append("<div id='div_m' style='-moz-box-shadow: 1px 1px 5px #999999;position:fixed;left:40%;top:50%;z-index:999999;width:250px;height:250px;'></div>");
    $('#div_m').append("<div id='div_icon' style='position:absolute; margin-left:230px;cursor:pointer;margin-top:-10px; z-index:9999; width:58px; height:58px;'></div>");
    $('#div_icon').html("<img id='img_close' src='" + url_name + "images/icon_close.png' width='58' height='58' onclick='div_icon_close()'>");
    $('#div_m').append("<div id='div_txt' style='-moz-border-radius: 5px;position:absolute;text-align:center;z-index:7;font-size:40px;width:240px;height:240px;padding:5px 5px 5px 5px;background-image:url(images/bonus_china_newyear.jpg);border:8px solid #666666'></div>");
    $('#div_txt').append("<div id='div_txt1' style='margin-top:10px;font-family:tahoma;color:white;text-decoration:none'></div>");
    $('#div_txt1').html("รับไปเลยส่วนลด " + d_split[0] + "% <br> รหัสส่วนลด " + d_split[1]);
}

function load_game(){
    $.post('back/file_procress_game.aspx', '', function(result) {
        if (result != "NO") {
            show_box_image250(result);
        }
        else {
            alert("ท่านจะต้องรอ 8 ชั่วโมงถึงจะคลิกได้อีกครั้ง หรือ สอบถามได้ที่ 088-289-2100");
        }
    });
}


