﻿if(top.location != self.location){
	top.location.replace(self.location);
}

//window.onerror = function(){return true;}

$(document).ready(function(){
	if(typeof(menuListCurrId) != 'undefined'){
		$("#menu ul li[menuListCurrId='"+ menuListCurrId +"']").removeClass("blur");
		$("#menu ul li[menuListCurrId='"+ menuListCurrId +"']").addClass("focus");
		$("#menu ul li[menuListCurrId='"+ menuListCurrId +"']").addClass("noncePage");
	} else {
		//$("#menu ul li[menuListCurrId='0']").addClass("noncePage");
	}
	
	$("#menu ul li").hover(function(){
		$(this).addClass("focus");
		$(this).removeClass("blur");
	},function(){
		if($(this).hasClass("noncePage")) {
		} else {
			$(this).addClass("blur");
			$(this).removeClass("focus");
		}
	});
	
	// union
	var source = $.query.get("source");
	var sourcesUnInfo = $.query.get("sourcesUnInfo");
	$.getJSON('/WebServices/v2/union/?action=Set_Cookies&source='+ source +'&sourcesUnInfo='+ sourcesUnInfo,
	function(jsonData){
	});
	
	// 用户登录
	$.getJSON('/WebServices/v2/my/login/?action=global_top_loginbar',
	function(jsonData){
		$("#LoginStatus").html(jsonData.Content);
	});
	
	// 购物车数量
	$.getJSON('/WebServices/v2/shoppingCart/?action=get_total_num',
	function(jsonData){
		$("#shoppingCartNum").html(jsonData.TotalNum);
	});
	
	// 搜索框
	$("div#head div.search form[name='search'] input[name='keyword']").blur(function(){
		if($("div#head div.search form[name='search'] input[name='keyword']").val() == ''){
			$("div#head div.search form[name='search'] input[name='keyword']").val("输入你要找的商品");
		}
	});
	$("div#head div.search form[name='search'] input[name='keyword']").focus(function(){
		$("div#head div.search form[name='search'] input[name='keyword']").val("");
	});
	
	
	// 热门搜索关键字
	$.getJSON('/WebServices/v2/others/proSearch/?action=get_top5',
	function(jsonData){
		$("#HotSearchKeywords").html(jsonData.Content);
	});
	
	/*************销售排行*********************/
	try{
		$($("#usual1 ul li.tabLi span").attr("href")).show();
		$("#usual1 ul li.tabLi span").click(function(){
			$("#usual1 ul li.tabLi").removeClass("c950103");
			$(this).parent().addClass("c950103");
			$(".tab").hide();
			$($(this).attr("href")).show();
		});
		var tabNum = $("#usual1").find(".tab").length;
		for (var j = 1; j<=tabNum; j++) {
			$("#tab"+j+" ul li").eq(0).children(".title").hide()
			$("#tab"+j+" ul li").eq(0).children(".detail").show()
			$("#tab"+j+" ul li").eq(0).css("border","0px");
			
			$("#tab"+j+" ul li").eq(0).children("div").eq(0).height("100px");
			$("#tab"+j+" ul li").eq(0).children("div").eq(0).css("line-height","100px");
			$("#tab"+j+" ul li").eq(0).height("100px");
			$("#tab"+j+" ul li").eq(0).css("line-height","100px");
			
		}
		$(".tab ul li").mouseover(function(){
			var tabId = $(this).parents(".tab").attr("id");
			var numberLi = $("#"+tabId).find("li").length;
			for(i=0; i<numberLi; i++) {
				$("#"+tabId+" ul li").eq(i).children("div").eq(0).height("30px");
				$("#"+tabId+" ul li").eq(i).children("div").eq(0).css("line-height","30px");
				$("#"+tabId+" ul li").eq(i).height("30px");
				$("#"+tabId+" ul li").eq(i).css("line-height","30px");
			}
			$("#"+tabId+" ul li .title").show()
			$("#"+tabId+" ul li .detail").hide()
			$("#"+tabId+" ul li").css("border-bottom","solid 1px #ebebeb");	
										   
			$(this).children(".title").hide()
			$(this).children(".detail").show()
			
			$(this).children("div").eq(0).height($(this).children("div").eq(1).height()+"px");
			$(this).children("div").eq(0).css("line-height",$(this).children("div").eq(1).height()+"px");
			
			$(this).height($(this).children("div").eq(1).height()+"px");
			$(this).css("line-height",$(this).children("div").eq(1).height()+"px");
			
			$(this).css("border","0px");
		});
	}catch(e){}
	/*************销售排行*********************/
	
	//$("select").sSelect();
});

function chkProductSearch(obj){
	if(obj.keyword.value == "" || obj.keyword.value == "输入你要找的商品"){
		alert('请输入关键字!');
		return false;
	}
	return true;
}

function left(mainStr, lngLen){
	if (lngLen>0){
		return mainStr.substring(0, lngLen);
	}else{
		return null;
	}
}

function right(mainStr, lngLen){
	if (mainStr.length - lngLen >= 0 && mainStr.length >= 0 && mainStr.length - lngLen <= mainStr.length){
		return mainStr.substring(mainStr.length - lngLen, mainStr.length);
	}else{
		return null;
	} 
} 

function mid(mainStr, starnum, endnum){
	if (mainStr.length >= 0){
		return mainStr.substr(starnum, endnum);
	}else{
		return null;
	}
}

function getCookie(name){
	var cookieValue = "";
	var search = name +"=";
	if(document.cookie.length > 0){
		offset = document.cookie.indexOf(search);
		if (offset != -1){
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

function setCookie(cookieName, cookieValue, DayValue){
	var expire = "";
	var day_value = 1;
	if(DayValue != null){
		day_value = DayValue;
	}
	expire = new Date((new Date()).getTime() + day_value * 86400000);
	expire = "; expires=" + expire.toGMTString();
	document.cookie = cookieName + "=" + escape(cookieValue) +";path=/"+ expire;
}

function delCookie(cookieName){
	var expire = "";
	expire = new Date((new Date()).getTime() - 1 );
    expire = "; expires=" + expire.toGMTString();
	document.cookie = cookieName + "=" + escape("") +";path=/"+ expire;
	// path=/
}

function Offset(e){
	var t = e.offsetTop;
	var l = e.offsetLeft;
	var w = e.offsetWidth;
	var h = e.offsetHeight;
	while(e = e.offsetParent){
		t += e.offsetTop;
		l += e.offsetLeft;
	}
	return{
		top : t,
		left : l,
		width : w,
		height : h
	}
};

//IE6支持png透明
function correctPNG() {// correctly handle PNG transparency in Win IE 5.5 & 6.
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version >= 5.5) && (document.body.filters)) {
       for(var j=0; j<document.images.length; j++) {
          var img = document.images[j]
          var imgName = img.src.toUpperCase()
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
             var imgID = (img.id) ? "id='" + img.id + "' " : ""
             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
             var imgStyle = "display:inline-block;" + img.style.cssText
             if (img.align == "left") imgStyle = "float:left;" + imgStyle
             if (img.align == "right") imgStyle = "float:right;" + imgStyle
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
             img.outerHTML = strNewHTML
             j = j-1
          }
       }
    }   
}
window.attachEvent("onload", correctPNG);

function gblAddToFavorite(){
	var docTitle = document.title;
	if(docTitle == null){ 
		var tagTitle = document.getElementByTagName("title") 
		if(tagTitle && tagTitle.length >0){ 
		   docTitle = tagTitle[0]; 
		}else{ 
		   docTitle = ""; 
		} 
	}
	
	var thisUrl = top.location.href;
	
	window.external.addFavorite(thisUrl, docTitle)
}

function gblAddToCollection(styleId, colorId, sizeId){
	if(styleId == null || isNaN(styleId)){
		alert('加入失败!');
	}else{
		$.getJSON('/WebServices/v2/my/collection/?action=addTo&styleId=' + styleId +'&colorId=' + colorId +'&sizeId=' + sizeId,
		function(jsonData){
			if (jsonData.error > 0){
				alert(jsonData.message);
			}else{
				if(confirm('已成功加入收藏夹,是否查看?')){
					top.location.href = '/my/collection/'
				}
			}
		});
	}
}

function gblCopyToClipboard(txt){
	if(window.clipboardData){
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", txt);
		alert("复制成功");
	}else if(navigator.userAgent.indexOf("Opera") != -1){
		window.location = txt;
		alert("复制成功");
	}else if(window.netscape){  
		try{
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}catch(e){
			alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
		}
		
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext = txt;
		str.data = copytext;
		trans.setTransferData("text/unicode", str, copytext.length * 2);
		var clipid = Components.interfaces.nsIClipboard;
		if (!clip) return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
		alert("复制成功");
	}    
}
