﻿$(function() {
    $("#ddlcategories").click(function() { GetObj('ddloptions').style.display = ''; });
    $("#ddloptions a").click(function() {
        GetObj('caregories').innerHTML = GetObj('ddlcategories').value = this.innerHTML;
        GetObj('ddloptions').style.display = 'none';
        $.ajax({
            type: "POST",
            url: "/loading/categories.aspx",
            data: "catid=" + this.name,
            success: function(msg) {

                $('#submenu dd').remove();
                $('#caregories').after(msg);
            }
        });
    });
    $('#btnpaintingSearch').click(function() {
        var painting = GetObj("PaintingSearch").value;
        if (painting != 'Ref.No.or Title') {

            self.location.href = '/oil_paintings/oil_painting-' + painting.replace(/(\s)/g, "_") + '.html '; 
        } else { alert("Painting search can not be empty."); }
    });
    $('#btnordertracking').click(function() {

        var painting = GetObj("OrderTracking").value.toLowerCase();
        if (painting != 'order tracking') {
            self.location.href = 'orderDetail.aspx?gl_orderId=' + painting;
        } else { alert("Order Tracking can not be empty."); }
    });
    $('#btnuserlogin').click(function() {
        var msg = '', result = true;
        var username = GetObj('txtEmail').value;
        var password = GetObj('txtPwd').value;
        if (_jsc.regex.isNull(username)) {
            msg += 'User name can not be empty.'; result = false;
        }
        if (_jsc.regex.isNull(password)) {
            msg += 'Password can not be empty.'; result = false;
        }
        if (!result) {
            alert(msg); return false;
        } else {
            $.ajax({
                type: "POST",
                url: "/loading/signin.aspx",
                data: "name=" + username + "&pwd=" + password,
                success: function(msg) {
                if (msg == "error") { alert('Incorrect User Name or Password, please try again!'); }
                    else { location.reload(); } //self.location.href=self.location;}
                }
            });
        }
    });
    $("#favorites").click(function() {
        $.ajax({
            type: "POST",
            url: "/loading/favorites.aspx",
            data: "id=" + GetObj("hidId").value + "&t=" + GetObj("txttitle").innerHTML,
            success: function(msg) {
                switch (msg) {
                    case "0":
                        alert("You are not logged, please login！");
                        break;
                    case "1":
                        alert("Collection success！");
                        break;
                    case "2":
                        alert("Internal Error！");
                        break;
                }
            }
        });
    });
    $("#incart").click(function() {
        $.ajax({
            type: "POST",
            url: "/loading/incart.aspx",
            data: "pid=" + GetObj("hidId").value,
            success: function(msg) {
                switch (msg) {
                    case "0":
                        alert("Add failure, internal error！");
                        break;
                    case "1":
                        self.location.href = "/cart.aspx";
                        break;
                    case "2":
                        self.location.href = "/cart.aspx?theCodeInfo=" + GetObj("spanrefCode").innerHTML;
                        break;
                }
            }
        });
    });
});




function ClearInfo(valueInfo,obj)
{
   if(obj.value==valueInfo)obj.value="";
}


function CheckInfo() {
    var painting = GetObj("PaintingSearch").value;
    if (painting != "Ref.No.or Title") {
        self.location.href = '/oil_paintings/oil_painting-' + painting.replace(/(\s)/g, "_") + '.html '; ;
    } else { alert("Painting search can not be empty."); }

}

function CheckInfo1() {
    var painting = GetObj("PaintingSearch").value;
    if (painting != "Ref.No.or Title") {
        self.location.href = '/dyo_productlist/dyo_painting-' + painting.replace(/(\s)/g, "_") + '.html '; ;
    } else { alert("Painting search can not be empty."); }
}



function urlgotoinfo() { 
self.location.href="/dyo_productlist/dyo_painting-"+GetObj("designSearch").value.replace(/(\s)/g, "_")+".html"
   
}
