﻿// JavaScript Document
var GlobalParameter_domain = "http://www.1wholesalecufflinks.com/";
var Validate_User_Url = GlobalParameter_domain + "Logon/Logon_Command.aspx";
var Cookie_User_Logon_Name = "Z_User_State";
var Cookie_User_Logon_Time = "Z_Logon_Time";
var User_User_Logon_State = "FALSE";
var User_Logon_Type_Url = "http://www.1wholesalecufflinks.com/UserInfo/Command/UserInfo.aspx?CC=Logon";


$(document).ready(function()
{	
	User_Logon_State();
	Head_Html_Init();
	init_end_html();
	Bind_Count_Validate();
	Bind_Shopping_Cart();

	Load_Freight_Info();
	Load_Item_Help_Bottom();
	Load_Item_Server();	
	Wholesale_Price_Add_Info();

});

	
function User_Logon_State() {
   
   User_User_Logon_State = $.cookie(Cookie_User_Logon_Name);
   if (User_User_Logon_State == null || User_User_Logon_State == "null") 
	{
		$("#login_state_ok").html("<a href='http://www.1wholesalecufflinks.com/Logon.htm'>Sign in</a> | <a href='http://www.1wholesalecufflinks.com/Register/Register.htm'>Join Free</a> | <a href='http://www.1wholesalecufflinks.com/UserInfo/Order_Manage.aspx'><b>My Account</b></a> | <a href='http://www.1wholesalecufflinks.com/Help/Customer_Service.htm' target='_blank'>Help</a>  ")
	} 
	else 
	{
        $("#hright").html("loading..<img src='http://www.1wholesalecufflinks.com/res3_2/img/v2010520/ajax_loader_1.gif' />");	
        $.ajax({

            url: User_Logon_Type_Url,
            type: 'GET',
            dataType: 'xml',
            timeout: 20000,
            error: function() 
			{
                $("#hright").html("检测用户登陆状态失败...请刷新页面重试.")

            },
            success: function(b) 
			{
				
                Temp_User_Logon_State = $(b).find('Uset_Logon_State').text();
						
                Temp_User_Type = $(b).find('User_Type').text();
                if (Temp_User_Logon_State == "true" || Temp_User_Logon_State == true) 
				{
             
				   $("#login_state_ok").html("<a target='_blank' href='http://www.1wholesalecufflinks.com/UserInfo/User_Center.aspx'><FONT COLOR=RED><b>User Center</b></FONT></a>    |<a href='http://www.1wholesalecufflinks.com/ShoppingCart/MyCart_er.aspx'>My Car</a> | <a href='http://www.1wholesalecufflinks.com/UserInfo/Command/UserInfo.aspx?CC=Logout'>exit</a>  ");
					
				  // $("#hright").html('[ <a href=http://www.1wholesalecufflinks.com>home</a> | <a target="_blank" href="http://www.1wholesalecufflinks.com/UserInfo/User_Center.aspx"><font color=red><b>User_Center</b></font></a> | <a href="http://www.1wholesalecufflinks.com/ShoppingCart/MyCart_er.aspx"><b>mycar</b></a><a href="http://www.1wholesalecufflinks.com/UserInfo/Deposit.aspx">money</a> | <a href="http://www.1wholesalecufflinks.com/UserInfo/Command/UserInfo.aspx?CC=Logout">exit</a> ]')

						
				} 
				else 
				{
						
						$.post("http://www.1wholesalecufflinks.com/UserInfo/Command/UserInfo.aspx", 
					{
						CC: "Logout"
					},
                    function(a) 
					{
                        alert("Your landing effective time is up, please re-login to continue shopping after.");
                        window.location.reload()
                    })
                }
            }
        })
    }
}
	

function init_end_html()
{
	var end_site_map_html=$("#sitemap_html").html();
	var end_site_path="";
	
	if(typeof(G_TC)=="undefined")
	{
		end_site_path="http://www.1wholesalecufflinks.com/fenlei/html/end_html_1.htm";
	}
	else
	{
		end_site_path="http://www.1wholesalecufflinks.com/fenlei/html/end_html_2.htm";
	}
	
	
    		$.ajax(
    		{
	    		url: end_site_path,
	    		type: 'GET',
	    		dataType: 'html',
	    		timeout: 20000,
	    		error: function()
	    		{
	    		},
	    		success: function(html)
	    		{
	    			$("#sitemap_html").before(html);
					$("#sitemap_show").html(end_site_map_html);
					$("#sitemap_html").hide();
	    		}
    		});


}
	

	function Head_Html_Init()
{
	$("#head_t_h").html($("#head_html_div").html());
	$("#head_html_div").hide();
}
	
function Wholesale_Price_Add_Info()
{
	var Price_Info;
	Price_Info=$("#it13").html();
	if(Price_Info.indexOf("批")<0)
	{
		$("#it13").append("<br><span style=' color:#C30;'>向在线客服[<a href='http://www.1wholesalecufflinks.com/Help/Customer_Service.htm' target='_blank'  style='color:#360; text-decoration:underline;' >申请</a>],可浏览批发价</span><br>[<a href='http://www.1wholesalecufflinks.com/Help/huodong.htm' target='_blank'  style='color:#360; text-decoration:underline;'>查看更多获得折扣优惠的方法</a>]");
	}
}

function Bind_Shopping_Cart()
{



	$("#Shopping_Cart").click(function()
	{
		if(User_User_Logon_State=="W" || User_User_Logon_State=="S")
		{
			if(!Items_Count($("#it18").val()))
			{
				alert("Number of commodities can not be more than 999");
				return false;
			}

			if(!Get_Attr())
			{
				//alert("这款饰品有几种不同的属性,您还没有选择.");
				Add_Shopping_Cart();
			}
			else
			{
		//		User_Logon_State();
				Add_Shopping_Cart();
				
			}
		}
		else
		{
			Show_Add_Cart_Return("unknownuser");
		}
	});
	
}




function Add_Shopping_Cart()
{

	
	var Attribute=$("input[@type=radio][@checked]").val();
	var Count=$("#it18").val();
	var Id=_o[0];
	var Url="http://www.1wholesalecufflinks.com/ShoppingCart/Shopping_Cart_Items.aspx?t=Add&id="+Id+"&c="+Count+"&a="+escape(Attribute);
	
	var Item_Type;
	var Cart_Count;
	var Cart_Total;
	

	
	Show_Add_Cart_Return("begin");
    $.ajax(
    {
        url: Url,
        type: 'Get',
        dataType: 'xml',
        timeout: 20000,
        error: function()
        {
		Show_Add_Cart_Return("timeout");
    	},
    	success: function(xml)
    	{
    		Add_Shopping_Cart_Ajax=0;
    		Item_Type=$(xml).find('Item_Type').text();
    		Cart_Count=$(xml).find('Cart_Count').text();
    		Cart_Total=$(xml).find('Cart_Total').text();
    		
    		if(Item_Type=="Succeed")
    		{
			Show_Add_Cart_Return("succeed",Cart_Count,Cart_Total);
    		}
    		else
    		{
		Show_Add_Cart_Return("error");
    		}
    	}
    });
}



function Close_Alert()
{
    $('#add_retuen').hide();
    $('#it21').show();
}

function Show_Add_Cart_Return(Type,Cart_Count,Cart_Total)
{
	

	
		switch (Type)
		{
   			case "begin":
   				$("#add_retuen").html('<img src="http://www.1wholesalecufflinks.com/res3_2/img/ajax_loader_2.gif" width="16" height="16" /> <b>Into shopping cart , please wait</b>').show();
   				$("#it21").hide();
   				break;

   			case "timeout":
   				$("#add_retuen").html('Add shopping cart Error:1,Please Please e-mail us').show();   	
   				$("#it21").show();			
   				break;
   			case "error":
   				$("#add_retuen").html('Add shopping cart Error:2.<br>Please Please e-mail us').show();   	
   				$("#it21").show();	   				
   				break;
   			case "succeed":
   				$("#add_retuen").html('successfully added to your shopping cart.<br>Shopping Cart(<span style="font-size:16px; font-weight:bold;color:#d80808;font-family:Arial;">'+Cart_Count+'</span> style),Total<span style="font-size:12px; font-weight:bold;color:#d80808;font-family:Arial;"> $'+Cart_Total+'</span> <br><a target="_blank" href="http://www.1wholesalecufflinks.com/ShoppingCart/MyCart_er.aspx">[Shopping Cart]</a>&nbsp;<a  href="javascript:Close_Alert();" >[Close]</a>&nbsp;<font color="#858585">[8secs.Auto Close]</font>');   
     				setTimeout("$('#add_retuen').hide();$('#it21').show();",8000);
     				break;
   			case "unknownuser":
   				$("#add_retuen").html('You have not login,<br>Unable to add to Shopping Cart.<br><a target="_blank" href="http://www.1wholesalecufflinks.com/Logon.htm">[Sign In]</a> <a target="_blank" href="http://www.1wholesalecufflinks.com/Register/Register.htm">[Free Registration]</a>').show();   	
      			break;
		}

}




function Get_Attr()
{
	
	if($("input[@type=radio][@checked]").val()==undefined)
	{
		if($("input[@type=radio]").length==1)
		{
			$("input[@type=radio]").attr("checked","checked");
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return true;
	}
}



function Bind_Count_Validate()
{
	$("#it18").change(function() 
	{
		if(!Items_Count($("#it18").val()))
		{
			//有问题
			$("#it18").val("1");
		}
	});
}
	


function Items_Count(str)
{
	var re = /^[0-9]*[1-9][0-9]*$/ ;
    if(re.test(str))
    {
    	if(str>99)
    	{
    		return false;	
    	}
    	else
    	{
    		return true;
    	}
    }
    else
    {
    	return false;	
    }
}


	
	

function Get_Stock()
{


	var HTML_Template='<div class="it17"><div class="it17_1"><input name="Items_Attr" type="radio" class="it17_0" value="$Attr_Title$" /></div><div class="it17_2">$Attr_Title$ <font color="$Show_Style$">( $Attr_State$ )</font></div></div>';
	var HTML_Temp="";
 	var Attr_HTML="";
	var Update_State=false;
	var Attr_Title="";
	var Attr_State="";
    
	Backup_Attr=$("#it16").html();
 	$("#it16").html('<img src="http://www.1wholesalecufflinks.com/res3_2/img/ajax_loader_1.gif" width="16" height="16"> <font color="#d80808">正在更新库存信息,若长时间未响应请刷新...</font>');
    

	$.getJSON("http://www.1wholesalecufflinks.com/ComItemsInfo/GetAttr.aspx?id="+_o[1]+"&jsoncallback=?",function(data)
	{
		$.each(data.Attr, function(i,Attr)
		{
			Attr_Title=Attr.Title;
			Attr_State=Attr.Type;
						
			HTML_Temp=HTML_Template;
			HTML_Temp=HTML_Temp.replace("$Attr_Title$",Attr_Title);
			HTML_Temp=HTML_Temp.replace("$Attr_Title$",Attr_Title);
			HTML_Temp=HTML_Temp.replace("$Attr_State$",Attr_State);

			if(Attr_State=="现货")
			{
				HTML_Temp=HTML_Temp.replace("$Show_Style$","#318806"); 
			}
			else
			{
				HTML_Temp=HTML_Temp.replace("$Show_Style$","#d26767");
			}
			Attr_HTML=Attr_HTML+ HTML_Temp;
		});
		
		$("#it16").html(Attr_HTML);
		
　　 }); 

//	alert(Update_State);
//	alert(Update_State + ":" + Attr_HTML);
/*
	if(Update_State)
	{
		$("#it16").html(Attr_HTML);
	}
	else
	{ 
		$("#it16").html('<font color="#d80808">价格读取超时,请刷新页面</font>');
	}
*/
}
	
	
		

	
	
jQuery.fn.floatdiv=function(location){
		//判断浏览器版本
	var isIE6=false;
	var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 0;
	if(Sys.ie && Sys.ie=="6.0"){
		isIE6=true;
	}
	var windowWidth,windowHeight;//窗口的高和宽
	//取得窗口的高和宽
	if (self.innerHeight) {
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	}else if (document.documentElement&&document.documentElement.clientHeight) {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	return this.each(function(){
		var loc;//层的绝对定位位置
		var wrap=$("<div></div>");
		var top=-1;
		loc=location;
		var str=loc.top;
		str=str.replace("px","");
		top=str;
		if(isIE6)
		{
			if (top>=0)
			{
				wrap=$("<div style=\"top:expression(documentElement.scrollTop+"+top+");\"></div>");
			}else{
				wrap=$("<div style=\"top:expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);\"></div>");
			}
		}
		$("body").append(wrap);
		wrap.css(loc).css({position:"fixed",z_index:"999"});
		if (isIE6)
		{
			
			wrap.css("position","absolute");
			$("body").css("background-attachment","fixed").css("background-image","url(n1othing.txt)");
		}
		$(this).appendTo(wrap);
	});
};
	


jQuery.cookie = function(name, value, options) {

    if (typeof value != 'undefined') {

        options = options || {

};

        if (value === null) {

            value = '';

            options.expires = -1

        }
        var expires = '';

        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {

            var date;

            if (typeof options.expires == 'number') {

                date = new Date();

                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000))

            } else {

                date = options.expires

            }
            expires = '; expires=' + date.toUTCString()

        }
        var path = options.path ? '; path=' + (options.path) : '';

        var domain = options.domain ? '; domain=' + (options.domain) : '';

        var secure = options.secure ? '; secure': '';

        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('')

    } else {

        var cookieValue = null;

        if (document.cookie && document.cookie != '') {

            var cookies = document.cookie.split(';');

            for (var i = 0;

            i < cookies.length;

            i++) {

                var cookie = jQuery.trim(cookies[i]);

                if (cookie.substring(0, name.length + 1) == (name + '=')) {

                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));

                    break

                }

            }

        }
        return cookieValue

    }

};




function Set_Search_TB()
{
    $("#hinp_3").bind("click", function(e)
	{
		if($("#hinp_2").val().length==16)
		{
			//id search
		}
		else
		{
			if($("#hinp_1").val()=="请选择搜索分类")
			{
				alert("您还没有选择左侧的具体分类");
				return false;
			}
			if($("#hinp_2").val()=="")
			{
				alert("请输入要查询的关键词");
				return false;
			}
		}

    });
}
	

function Set_Selectfrom()
{

	
    $("#hinp_bt").click(function() 
	{ 
	
	var bt = $("#hinp_1");
	var bt_offset = bt.offset();
	var bt_y=bt_offset.left;
 	var bt_x=bt_offset.top;
	var IE_Del=0;
	
	$("#selectfrom").css("top",bt_x+26);
	$("#selectfrom").css("left",bt_y-2);
	$("#selectfrom").hide();
	
		if ($("#selectfrom").is(":hidden")) 
		{
			$("#selectfrom").slideDown(); 
		}
		else if ($("#selectfrom").is(":visible")) 
		{
			$("#selectfrom").slideUp();
		}
    });

	
	$("#hinp_1").click(function() 
	{ 
	
	var bt = $("#hinp_1");
	var bt_offset = bt.offset();
	var bt_y=bt_offset.left;
 	var bt_x=bt_offset.top;
	var IE_Del=0;
	
	$("#selectfrom").css("top",bt_x+26);
	$("#selectfrom").css("left",bt_y-2);
	$("#selectfrom").hide();
	
		if ($("#selectfrom").is(":hidden")) 
		{
			$("#selectfrom").slideDown(); 
		}
		else if ($("#selectfrom").is(":visible")) 
		{
			$("#selectfrom").slideUp();
		}
    });
	
}
	
	
function Set_Sub_Div()
{
	$("#max_sub_0").hide();
	$("#max_sub_1").hide();
	$("#max_sub_2").hide();
	$("#max_sub_3").hide();
	$("#max_sub_4").hide();
	$("#max_sub_5").hide();
	$("#max_sub_6").hide();
	$("#max_sub_7").hide();
	
	switch (G_Select_Type)
	{
   		case "c":
			$("#nc13").val("韩国精品区");	
			$("#max_sub_0").show();
			$("#max_sub_1").show();
			$("#max_sub_2").show();
			break;
			
   		case "o":
			$("#nc13").val("韩国大量采购区");	
			$("#max_sub_3").show();
			break;
			

			
   		case "h":
			$("#nc13").val("中国精品韩版服饰区");	
			$("#max_sub_4").show();
			break;

   		case "cyh":
			$("#nc13").val("中国精品女装专区");
			$("#max_sub_5").show();
			break;
			
   		case "china":
			$("#nc13").val("中国商品总汇");
			$("#max_sub_6").show();
			break;		


   		case "korea":
			$("#nc13").val("韩国商品总汇");
			$("#max_sub_7").show();
			break;
	}
}
	

	
function Set_Select_Type(Type_Sre)
{



	switch (Type_Sre)
	{
   		case "c":
			$("#hinp_1").val("韩国精品区");	
			break;
			
   		case "o":
			$("#hinp_1").val("韩国大量采购区");	
			break;
			
   		case "korea":
			$("#hinp_1").val("韩国商品总汇");
			break;
			
   		case "h":
			$("#hinp_1").val("中国精品韩版服饰区");	
			break;

   		case "cyh":
			$("#hinp_1").val("中国精品女装专区");
			break;
			
   		case "china":
			$("#hinp_1").val("中国商品总汇");
			break;			
	}
	
	
	
	switch (Type_Sre)
	{
   		case "韩国精品区":
			G_Select_Type="c";
			$("#hinp_1").val(Type_Sre);	
			$("#swho").val("c");
			break;
			
   		case "韓國精品區":
			G_Select_Type="c";
			$("#hinp_1").val(Type_Sre);	
			$("#swho").val("c");
			break;
			
			
   		case "韩国大量采购区":
			G_Select_Type="o";
			$("#hinp_1").val(Type_Sre);
			$("#swho").val("o");
			break;
			
   		case "韓國大量采購區":
			G_Select_Type="o";
			$("#hinp_1").val(Type_Sre);
			$("#swho").val("o");
			break;
			
   		case "韩国商品总汇":
			G_Select_Type="korea";
			$("#hinp_1").val(Type_Sre);
			$("#swho").val("korea");
			break;
			
   		case "韓國商品總彙":
			G_Select_Type="korea";
			$("#hinp_1").val(Type_Sre);
			$("#swho").val("korea");
			break;	
			
   		case "中国精品韩版服饰区":
			G_Select_Type="h";
			$("#hinp_1").val(Type_Sre);
			$("#swho").val("h");
			break;

   		case "中國精品韓版服飾區":
			G_Select_Type="h";
			$("#hinp_1").val(Type_Sre);
			$("#swho").val("h");
			break;


   		case "中国精品女装专区":
			G_Select_Type="cyh";
			$("#hinp_1").val(Type_Sre);
			$("#swho").val("cyh");
			break;
			
   		case "中國精品女裝專區":
			G_Select_Type="cyh";
			$("#hinp_1").val(Type_Sre);
			$("#swho").val("cyh");
			break;	
			
			
   		case "中国商品总汇":
			G_Select_Type="china";
			$("#hinp_1").val(Type_Sre);
			$("#swho").val("china");
			break;		
			
   		case "中國商品總彙":
			G_Select_Type="china";
			$("#hinp_1").val(Type_Sre);
			$("#swho").val("china");
			break;	
	}
	
	
	$("#selectfrom").slideUp();
}
	
	
	
	


		function menu_get_id(index_value)
		{
			if(index_value=='null')
			{
					menu_s_h('0,1,2'); 
					window.scrollTo((0), (310));
					
			}else
			{
						if(index_value=='c'){menu_s_h('0,1,2'); 		     location.hash ="#m1" ;    window.scrollTo((0), (400));}
						if(index_value=='o'){menu_s_h('3');  		         location.hash ="#m2" ;    window.scrollTo((0), (560));}
						if(index_value=='h'){menu_s_h('4');   		         location.hash ="#m3" ;    window.scrollTo((0), (616));}
						if(index_value=='cyh'){menu_s_h('5');        		 location.hash ="#m4" ;    window.scrollTo((0), (670));}
						if(index_value=='china'){menu_s_h('6');        		 location.hash ="#m5" ;    window.scrollTo((0), (720));}
						if(index_value=='korea'){menu_s_h('7');              location.hash ="#m6" ;    window.scrollTo((0), (775));}
			}
	
			
			
			
		}
		

		function menu_s_h(index_i)
		{
			for(i=0;i<=7;i++)
			{
					if (index_i.indexOf(i)!=-1)
					{
					
						if(document.getElementById('max_sub_'+i).style.display =="block")
						{
								document.getElementById('max_sub_'+i).style.display = "none";
						}else
						{
								document.getElementById('max_sub_'+i).style.display = "block";
						}
						
					}else
					{
						document.getElementById('max_sub_'+i).style.display = "none";
					}
			}
		}


	function Get_info(G_var)/*选择分类及价格*/
	{
			if(G_var=='key')
			{
				document.getElementById('New_Key').className='New_K_Class_Button_F';	
				document.getElementById('New_By').className='New_K_Class_Button';	
				document.getElementById('Html_Str_Info').innerHTML="";	
			
			}else
			{
				document.getElementById('New_Key').className='New_K_Class_Button';	
				document.getElementById('New_By').className='New_K_Class_Button_F';	
				document.getElementById('Html_Str_Info').innerHTML=document.getElementById('sort_select_div').innerHTML;
			
			}
	
	}

function Load_Item_Server()
{
    		$.ajax(
    		{
	    		url: "http://www.1wholesalecufflinks.com/res3_2/html/item_server.htm",
	    		type: 'GET',
	    		dataType: 'html',
	    		timeout: 20000,
	    		error: function()
	    		{
	    		},
	    		success: function(html)
	    		{
	    			$("#i29").html(html);
	    		}
    		});
}


function Load_Item_Help_Bottom()
{
    		$.ajax(
    		{
	    		url: "http://www.1wholesalecufflinks.com/res3_2/html/item_info.htm",
	    		type: 'GET',
	    		dataType: 'html',
	    		timeout: 20000,
	    		error: function()
	    		{
	    		},
	    		success: function(html)
	    		{
	    			$(".i27:last").before(html);
	    		}
    		});
}

	function Load_Freight_Info()
	{
    		$.ajax(
    		{
	    		url: "http://www.1wholesalecufflinks.com/res3_2/html/Freight_Info.htm",
	    		type: 'GET',
	    		dataType: 'html',
	    		timeout: 20000,
	    		error: function()
	    		{
	    		},
	    		success: function(html)
	    		{
	    			$("#freight").html(html);
	    		}
    		});
	}
	
	

