$(".view_list").click(function(){
	var pvId=  $("#propertyValueId").val();
	var currency=$(this).attr("currency");
	if(parseInt(pvId)>0){
		document.location.href="itemQueryViewList_3_"+$("#sort").val()+"_"+pvId+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";			
	}else{
		document.location.href="itemQueryViewList_4_"+$("#sort").val()+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";
	}	
});
$("#pic").click(function(){
	var pvId=  $("#propertyValueId").val();
	if(parseInt(pvId)>0){
	    document.location.href="itemQueryLargePic_3_"+$("#sort").val()+"_"+pvId+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";	
	}else{
	    document.location.href="itemQueryLargePic_4_"+$("#sort").val()+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";
	}	
});
$(".view_pic").click(function(){
	var pvId=  $("#propertyValueId").val();
	var currency=$(this).attr("currency");
	if(parseInt(pvId)>0){
		document.location.href="itemQueryLargePic_3_"+$("#sort").val()+"_"+pvId+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+"_"+currency+".html";			
	}else{
		document.location.href="itemQueryLargePic_4_"+$("#sort").val()+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+"_"+currency+".html";
	}	
});
$("#sort").change(function(){
	var pvId=  $("#propertyValueId").val();
	if(parseInt(pvId)>0){
		document.location.href="itemQuerySort_3_"+$(this).val()+"_"+pvId+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";			
	}else{
		document.location.href="itemQuerySort_9_"+$(this).val()+"_"+pvId+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";
	}
});
$("#keywordsSearch").click(function(){    
	var pvId=  $("#propertyValueId").val();
	if(parseInt(pvId)>0){
		document.location.href="itemSearchPab_3_"+$("#sort").val()+"_"+pvId+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";		
	}else{
		document.location.href="itemSearchPab_6_"+$("#sort").val()+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";
	}

});
$(".myPrice").click(function(){
	var pvId=  $("#propertyValueId").val();
	var currency=$(this).attr("currency");
	if(parseInt(pvId)>0){
		document.location.href="itemQueryPandb_3_"+$("#sort").val()+"_"+pvId+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$(this).text()+"_"+$("#itypeNames").val()+"_"+currency+".html";						
	}else{
		document.location.href="itemQueryPrice_9_"+$("#sort").val()+"_"+$("#itypeId").val()+"_"+$("#keywords").val()+"_"+$(this).text()+"_"+$("#itypeNames").val()+"_"+currency+".html";
	}
});
$("#changePrice").click(
	function(){
		if($("#sort").val()==2){
			$(this).attr("class","price_down");
			changePrice(3);	
		}else{
			$(this).attr("class","price_up");
			changePrice(2);	
		}					
});

function changePrice(sort){
	var pvId=  $("#propertyValueId").val();
	if(parseInt(pvId)>0){
		document.location.href="itemQuerySort_2_"+sort+"_"+pvId+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";

	}else{
		document.location.href="itemQuerySort_8_"+sort+"_"+pvId+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";
	}			
}
$(".brand").click(function(){
	document.location.href="itemQueryBrand_3_"+$("#sort").val()+"_"+$("#itypeId").val()+"_"+$(this).attr("id")+"_"+$("#keywords").val()
	+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";

});	
//$(".buy").click(function(){
//	var url="../detail/displaydetail_"+$(this).parents().parents().find(".photo").attr("id")+".html";
//	window.open(url,"_parent");
//});	
$(".itemtype").click(function(){
	var fatherId =$(this).parents("div").prev().find("a").attr("id");
	var fatherName =$(this).parents("div").prev().find(".itemtypefh").html();
	var id = $(this).attr("id");
	var name = $(this).html();	
	var linkString = fatherId+":"+fatherName+";"+id+":"+name;
	document.location.href="itemQuery_2_"+$(this).attr('id')+"_"+linkString+".html";						
});
$(".itemtypefh").click(function(){
	var fatherId =$(this).parent().parent().find("a").attr("id");
	var fatherName =$(this).html();
	var linkString = fatherId+":"+fatherName;
	document.location.href="itemQuery_1_"+fatherId+"_"+linkString+".html";						
});
$(function(){	
	$(".itemCompareButton").click(function(){	
		var itemCompareIds="";
		$(".list_view :checkbox:checked").each(function(i){  
			itemCompareIds = itemCompareIds+":"+$(this).attr("id");
		});
		document.location.href="itemCompare.html?itemCompareIds="+itemCompareIds;
		itemCompareIds="";
	});
});
$(function(){
	$(".close").click(function(){
		$("#faqdiv").css("display","none");
		return false;
	});			
});	
var sellerId = $("#sellerId").val();
$(".itemPtoto").click(function(){ 	
	var itemId = $(this).attr("id");
	var url = $(this).children().attr("src");
	url = url.replace("100x100","45x45");
	var sellingPrice = $(this).parent("div").next().next().find("span").attr("usdcurrency");
	var item = itemId+"-www.ctoshop.com-"+url+"-www.ctoshop.com-"+sellingPrice+"@www.ctoshop.com@";
	var before = $.cookie(sellerId+"item");
	if(!isExist(itemId,before)){		
		item = before+item;		
		var itemArray = item.split("@www.ctoshop.com@");
		var len = itemArray.length;
		if(len<8){
			$.cookie(sellerId+"item", item, { expires: 1,path: '/' });
		}
		//else{
		//	itemArray.shift();
		//	itemArray.join("@www.ctoshop.com@");
		//	item = itemArray.toString();
		//	$.cookie(sellerId+"item", item, { expires: 1 });
		//}
		//$.cookie("item", item, {expires: 1, path: '/', domain: 'ctoshop.com', secure: true});
	}
});
$(".itemClear").click(function(){ 
	$.cookie(sellerId+"item",null,{ expires: 1,path: '/' });
	location.reload();
});
$(document).ready(function(){
	$(function(){
		var item = $.cookie(sellerId+"item");
		if(item!=null){	
			item = trim(item);
			var itemArray = item.split("@www.ctoshop.com@");
			var len = itemArray.length;
			if(len>0){
				for(var i=0;i<len;i++){
					var item_em = itemArray[i];
					if(null!=trim(item_em)){
						if(item_em!=""){
							var itemEmArray = item_em.split("-www.ctoshop.com-");
							var id = itemEmArray[0];
							if(id.indexOf("null")>-1){
								id = id.substring(4);
							}
							var url = itemEmArray[1];
							var price = ForDight((parseFloat(itemEmArray[2])*parseFloat(currencyValue)),2)+" "+currencyCode;
							var detailurl = "<li id="+id+"><a href='#'><img src="+url+" alt='' /></a>"+price+"</li>";
							detailurl = detailurl.replace("#","./displaydetail_"+id+".html");
							$("#compare ul").append(detailurl);
						}
					}						
				}
			}
		}
	});

	$(function(){
		var items =  $("#compare").text();
		if($.trim(items)==null || items==""){
			$("#itemHistory").hide();
		}else{
			$("#itemHistory").show();
		}
	});		
});
function isExist(id,before){
	if(before!=null){	
		if(before.indexOf(id+"-www.ctoshop.com-")>-1){
			return true;
		}else{
			return false;
		}
	}		
}
function trim(str){ //删除左右两端的空格
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str){ //删除左边的空格
	return str.replace(/(^\s*)/g,"");
}
function rtrim(str){ //删除右边的空格
	return str.replace(/(\s*$)/g,"");
}
$(function(){
	$(".img_class_dis").mouseover(function(e){
		var bigimgurl = $(this).attr("src").replace("100x100","220x220");
		var $tooltip =  $("<div id='tooltip'><div><b><img src='"+bigimgurl+"' alt='' /></b></div><span class='arrow'></span></div>");
		var $img = $(".img_view ul li.list_view .photo");
		var x = 120;
		$("body").append($tooltip);	
		e.pageY = $(this).offset().top;
		e.pageX = $(this).offset().left;
		$("#tooltip")
		.css({
			"top": (e.pageY) + "px",
			"left": (e.pageX  + x) + "px"
		});
	}).mouseout(function(){
		$("#tooltip").remove();
	});
});
var favoriteItemId="";
$(".favorites").click(function(){
	favoriteItemId = $(this).parents().parents().find(".photo").attr("id");
	$.ajax({
		url:"/template/detail/detailcollection.action",
		type:"post",
		dataType:"text",
		data:"itemId="+favoriteItemId,
		error:function(){
		$("#faqdiv").html("加载数据");
	},
	success:function(data){				
		if(data=="false"){
			$("#faqdiv").css("display","block");
			return false;
		}else{
			alert(data);
		}
	}
	});
});	 

function login_other(){		
	if(loginInfo()){
		document.detail_login.action="/template/detail/otherlogin.html?itemId="+favoriteItemId;
		document.detail_login.submit();
	}
}
$("#button2").click(function(){
	var pageformat = /^[1-9]\d*$/;
	var currentpage=$("#currentPage").val().replace(/^\s+|\s+$/g,"");
	var totalpagenumber='${totalPage}';
	var pvId= $("#propertyValueId").val();
	var parameter = "itemQuery_3_"+$("#sort").val()+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
	+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";
	if(parseInt(pvId)>0){
		parameter.join("+'&propertyValueId='+pvId");
	}else{
		document.location.href="itemQuery_9_"+$(this).val()+"_"+$("#itypeId").val()+"_"+$("#keywords").val()
		+"_"+$("#sellingPriceRange").val()+"_"+$("#itypeNames").val()+".html";
	}
	if(currentpage==''||totalpagenumber==0 || currentpage==0){
		return false;
	}else if(!pageformat.test(currentpage)){
		return false;
	}else if(Number(currentpage) > Number(totalpagenumber)){	
		document.location.href = parameter.join(+'&page='+totalpagenumber);
	}else {
		document.location.href = parameter.join(+'&page='+currentpage);		
	}		 	
});
function ExChgClsName(Obj,NameA,NameB){
	var Obj=document.getElementById(Obj)?document.getElementById(Obj):Obj;
	Obj.className=Obj.className==NameA?NameB:NameA;
}
function showMenu(iNo){
	ExChgClsName("Menu_"+iNo,"MenuBox","MenuBox2");
}
function loginInfo(){
	
		var memberEmail=document.getElementById("loginMemberEmail").value.replace(/^\s+|\s+$/g,"");

		if(memberEmail=='' || memberEmail==null){
			document.getElementById("memberEmail_note").innerHTML=false_marker;
		}else if(memberEmail.length>50){
			document.getElementById("memberEmail_note").innerHTML=false_marker;
		}else{
			document.getElementById("memberEmail_note").innerHTML="";
		}
	
		var password=document.getElementById("loginMemberPassword").value.replace(/^\s+|\s+$/g,"");
		if(password=='' || password==null){
			document.getElementById("memberPassword_note").innerHTML=false_marker;
			return false;
		}else if(password.length<6 || password.length>16){
			document.getElementById("memberPassword_note").innerHTML=false_marker;
			return false;
		}else{
			document.getElementById("memberPassword_note").innerHTML="";
			return true;
		}
}
/*
*ForDight(Dight,How):数值格式化函数，Dight要格式化的 数字，How要保留的小数位数。
*这里的方法是先乘以10的倍数，然后去掉小数，最后再除以10的倍数。
*/  
function ForDight(Dight,How){  
   Dight = Math.round(Dight*Math.pow(10,How))/Math.pow(10,How);  
   return Dight;  
}  
