﻿// JScript 公共方法函数

function redirectURL(sexid,type,strID)//Plist-sexid-style-brand-sort-key-page.html
{
   //var strHref=location.href.toLowerCase();
   var sUrl;
   //alert(strHref);
//   if(strHref.indexOf("plist")>-1)
//   {
//     sUrl=strHref;
//    }
//    else
//    {
//     sUrl="Plist----0--1.html";
//    }
   sUrl="Plist----0--1.html";
   sUrl=SetURLParam("sex",sexid,sUrl);
   sUrl=SetURLParam(type,strID,sUrl);
   sUrl=SetURLParam("key","",sUrl);//清空关键字
   sUrl=SetURLParam("page","1",sUrl);//清空关键字
   location.href=sUrl;
}

//设备URL参数的值，URL格式为Plist-sexid-style-brand-sort-key-page.html
function SetURLParam(type,strID,sUrl)
{
   (!sUrl) && (sUrl = window.location.href);
   //alert(sUrl);
   var myArry=new Array();
   myArray = sUrl.split("-");
   switch (type)
   {
     case "sex":
           myArray[1]=strID;
           break;
     case "style":
           myArray[2]=strID;
           break;
     case "brand":
           myArray[3]=strID;
           break;
     case "sort":
           myArray[4]=strID;
           break;
     case "key":
           myArray[5]=strID;
           break;
     case "page":
           myArray[6]=strID + ".html";
           break;
    }
    sUrl=myArray.join("-");
    return sUrl;
}//end function SetURLParam()

 function rURL(sortValue)
    {
    var strStyleId='<%=strStyleID %>';
    var strBrandId='<%=strBrandID %>';
    var strKey='<%=strKey %>';
    var sUrl="/product/"+strStyleId+"-"+strBrandId+"-"+sortValue+"-"+strKey+"-1.html";    
    location.href=sUrl;
    }


// var sParam = getURLParam("a", "http://w.w.w/?a=1&b=2);
function getURLParam(sName, sUrl)
{
	(!sUrl) && (sUrl = window.location.href);

	sUrl = sUrl.toString();

	var nIndex = sUrl.indexOf("?");

	return (nIndex>=0) ? getParam(sUrl.substr(nIndex+1), sName, "&", "=") : "";

};//end getURLParam

//把传递过来的字符串参数每一个单词头一个字母变成大写其它的为小写
function changeCase(tmpStr) {
    var index;
    var tmpChar;
    var preString;
    var postString;
    var strlen;
    tmpStr = tmpStr.toLowerCase();
    strLen = tmpStr.length;
    if (strLen > 0)//if3
    {
       for (index = 0; index < strLen; index++)  
       {
           if (index == 0)//if2
           {
              tmpChar = tmpStr.substring(0,1).toUpperCase();
              postString = tmpStr.substring(1,strLen);
              tmpStr = tmpChar + postString;
            }
            else 
            {
               tmpChar = tmpStr.substring(index, index+1);
               if (tmpChar == " " && index < (strLen-1))//if1
               {
                   tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
                   preString = tmpStr.substring(0, index+1);
                   postString = tmpStr.substring(index+2,strLen);
                   tmpStr = preString + tmpChar + postString;
                }//end if1
            }//end if2
       }//end for
     }//end if3
  return tmpStr;
}//end function

//获取URL传递的参数 格式cloth.html?id=3&layer=suit
function getQuerystringParam(keyArg,preserveCase){
	var _strQuery = (preserveCase ? location.search : location.search.toLowerCase());
	var _keyArg = (preserveCase ? keyArg : keyArg.toLowerCase());
	var _strVal = "";

	var _regexS = "[\\?&]"+_keyArg+"=([^&#]*)";
  	var _regex = new RegExp(_regexS);

  	var _keyVal = _regex.exec(_strQuery);
  	if (_keyVal != null) _strVal = _keyVal[1];

  	_strVal = unescape(_strVal);
  	return _strVal;
}//end getQuerystringParam()

function removeQueryStringParam(strURL,strParam) {
	var strRegExp =  new RegExp("&"+strParam+"=[^&]*");
	var strRegExp2 =  new RegExp("/?"+strParam+"=[^&]*&");
	var strReplace = new String("");

	
	if (strURL.match(strRegExp)) {
		var newStr = strURL.replace(strRegExp,strReplace);
	} else {
		var newStr = strURL.replace(strRegExp2,strReplace);
	}

	return newStr;
}//end removeQueryStringParam()

//打开一个新窗口
function openWindow(url,width,height,title,left,top,location,resizable,scrollbars,status,toolbar,menubar) {
	width = parseInt(width);
	height = parseInt(height);
	width = (isNaN(width))? brandConst.POPUP_DEFAULT_WIDTH : width;
	height = (isNaN(height))? brandConst.POPUP_DEFAULT_HEIGHT : height;
	title = (title)? title : "popup";
	if (!left) {
		screenWidth = screen.availWidth;
		left = (screenWidth)? Math.max((screenWidth/2 - width/2),0) : 100;
	}
	if (!top) {
		screenHeight = screen.availHeight;
		top = (screenHeight)? Math.max((screenHeight/2 - height/2),0) : 100;
	}
	params = "width=" + width + ",height=" + height + ",left=" +left  + ",top=" + top;
	params += (resizable)? ",resizable=yes" : "";
	params += (scrollbars)? ",scrollbars=yes" : "";
	params += (status)? ",status=yes" : "";
	params += (location)? ",location=yes" : "";
	params += (toolbar)? ",toolbar=yes" : "";
	params += (menubar) ? ",menubar=yes" : "";
	
	windowObj = window.open(url,title,params);
	windowObj.focus();
	return windowObj;
}//end openWindow()

//设置图片路径
function setImgSrc(targetID, strSrc) {//alert("eee");
	if (typeof targetID == "string") var objImg = returnObjById(targetID);
	else if (typeof targetID == "object") var objImg = targetID;
	objImg.setAttribute("src",strSrc);
}//end setImgSrc()

// var sUrl = setURLParam("http://w.w.w/?a=1", "b", "2");

function setURLParam(u, n, v)

{
	u = u.toString();

	n = n.toString();

	v = v.toString().escUrl();

	var r = new RegExp("(^|\\W)"+n+"=[^&]*", "g");

	

	return (u.match(r)) ? u.replace(r, "$1"+n+"="+v) : u+(u.indexOf("?")==-1 ? "?" : "&")+n+"="+v;

};//end setURLParam

// var a = getParam("a=1&b=2", "a", "&", "=");

function getParam(valPairs, sName, elemSep, pairSep)

{

	var xParam = new PARAM(valPairs, elemSep, pairSep);

	return xParam[sName] ? xParam[sName] : "";

};//end getParam



// var sParam = setParam("a=1", "b", "2");
function setParam(valPairs, n, v)

{

	valPairs = valPairs.toString();

	n = n.toString();

	v = v.toString().escUrl();

	var r = new RegExp("(^|\\W)"+n+"=[^&]*", "g");

	return (valPairs.match(r)) ? valPairs.replace(r, "$1"+n+"="+v) : valPairs+(valPairs ? "&" : "")+n+"="+v;

};//end setParam

// var _Prm = new PARAM("a=1&b=2", "&", "="); var a = _Prm["a"]; var b = _Prm["b"]
function PARAM(valPairs, elemSep, pairSep)

{

	if (valPairs)

	{

		var aElem = valPairs.toString().split(elemSep);

		for (var i=0; i<aElem.length; ++i)

		{

			var aPair = aElem[i].split(pairSep);

			(aPair.length>1) && (this[aPair[0]] = unescape(aPair[1]));

		}

	}

};//end PARAM

// 生成 [0, nMax) 的随机整数
function MaskEnd(lWin)

{

	for (var i=0; i<arguments[0].length; ++i)

	{

		try{ PageMaskHide(arguments[0][i]); } catch(e) { }

	}

};


// 判断一个数据是否属于数组中的一个元素
function IsArrIncluded(tag,ArrObj)
{
    var Result=false;    
	for (var i=0; i< ArrObj.length; i++)
	{
	   if(tag==ArrObj[i])
	   {
	     Result=true;
	     break;
	   }
	}
    return Result;
};

        ///图片自适应大小controlID图片Name,限制高度maxHeight,maxWidth
        function FitPic(controlName,maxWidth,maxHeight)
        {
            for(var i=0;i<document.getElementsByName(controlName).length;i++)
            {
                var imageArr=document.getElementsByName(controlName)[i];
                var imageRate = imageArr.offsetWidth / imageArr.offsetHeight; 
                imageArr.style.display="block";
                try
                {
                if(imageArr.offsetWidth > maxWidth)
                {
                    imageArr.style.width=maxWidth + "px";
                    imageArr.style.Height=maxWidth / imageRate + "px";
                }
                
                if(imageArr.offsetHeight > maxHeight)
                {
                    imageArr.style.width = maxHeight * imageRate + "px";
                    imageArr.style.Height = maxHeight + "px";
                }
                }
                catch(err)
                {}
            }
        }
        
//获取样式
function getStyle(oElm, strCssRule){
    var strValue = "";
    if(document.defaultView && document.defaultView.getComputedStyle){
        strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
    }
    else if(oElm.currentStyle){
        strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){return p1.toUpperCase();});
        strValue = oElm.currentStyle[strCssRule];
    }
    return strValue;
}
Math.randomInt = function(nMax) { return parseInt(Math.random()*nMax); };



Array.prototype.find = function(e) { for (var i=0; i<this.length; ++i) { if (this[i]==e) { return i; } } return null; };

Array.prototype.findmul = function(e) { var a = []; for (var i=0; i<this.length; ++i) { if (this[i]==e) { a.push(i); } } return a; };

Array.prototype.find_if = function(fnEQ) { for (var i=0; i<this.length; ++i) { if (fnEQ(this[i])) { return i; } } return null; };

Array.prototype.findmul_if = function(fnEQ) { var a = []; for (var i=0; i<this.length; ++i) { if (fnEQ(this[i])) { a.push(i); } } return a; };

Array.prototype.push_not = function(e) { if (this.find(e)==null) { return this.push(e); } return null; };

Array.prototype.push_not_if = function(e, fnEQ) { if (this.find_if(fnEQ)==null) { return this.push(e); } return null; };

Array.prototype.remove = function(e) { var a = this.findmul(e); for (var i=a.length-1; i>=0; --i) { this.splice(a[i], 1); } return a.length; };

Array.prototype.remove_if = function(fnEQ) { var a = this.findmul_if(fnEQ); for (var i=a.length-1; i>=0; --i) { this.splice(a[i], 1); } return a.length; };

Array.prototype.transform = function(fnOp) { for (var i=0; i<this.length; ++i) { this[i] = fnOp(this[i]); } return this; };



RegExp.showCharSet = /[\x00-\x09\x0B-\x0C\x0E-\x1F\x80-\xFF]/g;



String.prototype.chsetReplace = function() { return this.replace(RegExp.showCharSet , "?"); };

String.prototype.chsetAlert = function(v) { if (!this.chsetCheck()) { alert((v?v+"中":"")+'请不要使用"'+this.match(RegExp.showCharSet).toString()+'"等字符。'); return false; }else{ return true; } };

String.prototype.chsetCheck = function() { return !this.match(RegExp.showCharSet); };

String.prototype.between = function(b, e) { var bp = this.indexOf(b); if (bp==-1) { return (""); } bp += b.length; var ep = this.indexOf(e, bp); if (ep==-1) { return (""); } return this.substr(bp, ep-bp); };

String.prototype.replaceAll = function(s, t) { return this.split(s).join(t); };

String.prototype.asclen = function() { return this.replace(/[\u0100-\uffff]/g, "  ").length; };

String.prototype.asccut = function(n) { var i = 0; while (n>0 && i<this.length) { n -= this.charCodeAt(i)>=256 ? 2 : 1; i += (n>=0); } return this.substr(0, i); };

String.prototype.escHtmlEp = function() { return this.replace(/[&'"<>\/\\\-\x00-\x1f\x80-\xff]/g, function(r){ return "&#"+r.charCodeAt(0)+";" }); };

String.prototype.escHtml = function() { return this.replace(/[&'"<>\/\\\-\x00-\x09\x0b-\x0c\x1f\x80-\xff]/g, function(r){ return "&#"+r.charCodeAt(0)+";" }).replace(/\r\n/g, "<BR>").replace(/\n/g, "<BR>").replace(/\r/g, "<BR>").replace(/ /g, "&nbsp;"); };

String.prototype.escScript = function() { return this.replace(/[\\"']/g, function(r){ return "\\"+r; }).replace(/%/g, "\\x25").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\x01/g, "\\x01"); };

String.prototype.escUrl = function() { return escape(this).replace(/\+/g, "%2B"); };

//String.prototype.escMiniUrl = function() { return this.replace(/[\x00-\xff]/g, escape).replace(/\+/g, "%2B"); };

String.prototype.escMiniUrl = function() { return this.replace(/%/g, "%25"); };

String.prototype.escHrefScript = function() { return this.escScript().escMiniUrl().escHtmlEp(); };

String.prototype.escRegexp = function() { return this.replace(/[\\\^\$\*\+\?\{\}\.\(\)\[\]]/g, function(a,b){ return "\\"+a; }); };

String.prototype.escape = function() { return escape(this); };

String.prototype.unescape = function() { return unescape(this); };

Date.prototype.format = function(v) { var a={"Y":this.getFullYear(), "m":LENFix(this.getMonth()+1, 2), "d":LENFix(this.getDate(), 2), "H":LENFix(this.getHours(), 2), "M":LENFix(this.getMinutes(), 2), "S":LENFix(this.getSeconds(), 2)}; return v.replace(/%[YmdHMS]/g, function(v){ return (a[v.substr(1)]); }); };

// 注:以下所有转义(包括对应的对象方法)都是直接填充模板时使用,不一定适用于属性设置

function escUrl(v) { return v.escUrl(); };

function escHtml(v) { return v.escHtml(); };

function escHtmlEp(v) { return v.escHtmlEp(); };

function escScript(v) { return v.escScript(); };

function escHrefScript(v) { return v.escHrefScript(); };


//************************  判断浏览器类型start  ************************ /

function getBrowserType() 
{ 
var OsObject = ""; 
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE"; 
} 
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
return "Firefox"; 
} 
if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
return "Safari"; 
} 
if(isCamino=navigator.userAgent.indexOf("Camino")>0){
return "Camino"; 
} 
if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
return "Gecko"; 
} 

};//end function  

//*********************************　判断浏览器类型end　*****************************/


//-----------------Cookie操作方法-------------------------------
    function GetCookieVal(offset)
//获得Cookie解码后的值
    {
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1)
            endstr = document.cookie.length;
        return unescape(document.cookie.substring(offset, endstr));
    }


//----------------------------
    function SetCookie(name, value)
//设定Cookie值
    {
        var expdate = new Date();
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        if (expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
        document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
                          +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
                          +((secure == true) ? "; secure" : "");
    }


//-------------------------
    function DelCookie(name)
//删除Cookie
    {
        var exp = new Date();
        exp.setTime (exp.getTime() - 1);
        var cval = GetCookie (name);
        document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
    }


//-----------------------
    function GetCookie(name)
//获得Cookie的原始值
    {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen)
        {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg)
                return GetCookieVal (j);
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return null;
    }
    
    function ShowCate(ListCate,objThis)
    {
        if(document.getElementById(ListCate).style.height=="40px")
        {
            document.getElementById(ListCate).style.height="auto"; 
            objThis.src="/Images/shousuo.gif";    
            objThis.alt="精简";     
            try
            {
                parent.autoSize('mainEditor','nav_Center');
            }
            catch(err)
            {
            }
        }
        else
        {
            document.getElementById(ListCate).style.height="40px";
            objThis.src="/Images/zhangkai.gif";  
            objThis.alt="更多";  
        }
    }
    
   function getElementObjByID(name)
   {
      var returnobj=null;
      returnobj=document.getElementById(name);
      return returnobj;
    }
    
    
function setTab(m,n)
{
 var tli=document.getElementById("tabs_menu"+m).getElementsByTagName("li");
 //var mli=document.getElementById("tabs_main"+m).getElementsByTagName("div");
 
 for(i=0;i<tli.length;i++)
 {
 tli[i].className=i==n?"current":"";
 //mli[i].style.display=i==n?"block":"none";
 document.getElementById("tabs_main_nav_"+i).style.display=i==n?"block":"none";
 }
}



// JScript 文件
function CheckAll(select)
{
    var fm=document.forms[0];
    for (var i=0;i<fm.elements.length;i++)
    {
        var e = fm.elements[i];
           if( e.checked == true )
           e.checked=false;
           else
           e.checked=true;
    }
}
