﻿// JScript 文件
//去掉字串左边的空格 
function lTrim(str) 
{ 
if (str.charAt(0) == " ") 
{ 
//如果字串左边第一个字符为空格 
str = str.slice(1);//将空格从字串中去掉 
//这一句也可改成 str = str.substring(1, str.length); 
str = lTrim(str); //递归调用 
} 
return str; 
} 

//去掉字串右边的空格 
function rTrim(str) 
{ 
var iLength; 

iLength = str.length; 
if (str.charAt(iLength - 1) == " ") 
{ 
//如果字串右边第一个字符为空格 
str = str.slice(0, iLength - 1);//将空格从字串中去掉 
//这一句也可改成 str = str.substring(0, iLength - 1); 
str = rTrim(str); //递归调用 
} 
return str; 
} 



//函数名：fucCheckNUM
	//功能介绍：检查是否为数字
	//参数说明：要检查的数字
	//返回值：1为是数字，0为不是数字,-1为空
	function fucCheckNUM(NUM){
		var i,j,strTemp;
		strTemp="0123456789";
		if ( NUM.length== 0){
			return -1;
		}
		for (i=0;i< NUM.length;i++){
			j=strTemp.indexOf(NUM.charAt(i));
			if (j==-1){
				//说明有字符不是数字
				return 0;
			}
		}
		//说明是数字
		return 1;
	}
	
	//函数名：fucCheckNUMByFload
	//功能介绍：检查是否为数字(支持小数)
	//参数说明：要检查的数字
	//返回值：1为是数字，0为不是数字,-1为空
	function fucCheckNUMByFload(val)
	{
	    if (val.length == 0)
	    {
	        return -1;
	    };
	    var xRx = /^\d*\.?\d+$/;
	    if (!xRx.test(val))
	    {
	        return 0;
	    }
	    else
	    {
	        return 1
	    };
	}
//函数名：fucCheckInRange
	//功能介绍：检查是否为数字
	//参数说明：要检查的数字
	//返回值：1为在指定区域内，2小于指定区域,3大于指定区域 0不是数字 
	function fucCheckInRange(lower,upper,Num){
	var result = fucCheckNUM(Num);
		if ( result == 1 ){
			if ( parseInt(Num,10) < parseInt(lower,10)){
				return 2;
			}
			if ( parseInt(Num,10) > parseInt(upper,10)){
				return 3;
			}
			return 1;
		}else if (result == 0 ){
			return 0;
		}else if (result == -1){
			return -1;
		}
		
	}
	
//函数名：UrlEncode 字符串编码
    function UrlEncode(strUrl)
    {
		 return encodeURI(strUrl);
    }
//函数名：UrlDecode 字符串解码
    function UrlDecode(strUrlCoded)
	{
		 return decodeURI(strUrlCoded);
    }
    
/////////////////COOKIE操作//////////////////////////////////////////////////////////
function setCookie (name, value) {  
    var argv = setCookie.arguments;  
    var argc = setCookie.arguments.length;  
    var expires = (argc > 2) ? argv[2] : 23;  
    var expdate = new Date ();
    expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
    var path = (argc > 3) ? argv[3] : null;  
    var domain = (argc > 4) ? argv[4] : null;  
    var secure = (argc > 5) ? argv[5] : false;  
    document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expdate.toGMTString())) + 
    ((path == null) ? "" : ("; path=" + path)) +  
    ((domain == null) ? "" : ("; domain=" + domain)) +    
    ((secure == true) ? "; secure" : "");
}

function getCookie (name) {  
    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 getCookieVal(offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1) endstr = document.cookie.length;
   return unescape (document.cookie.substring(offset, endstr));
}


function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

///////////////////////////////////////////////////////////////////////////////
function bkRestore(obj1,obj2){
	
	obj1.className=obj2;
	
}
function bkSwap(obj1,obj2){
	
	obj1.className=obj2;
	
}

function imgChange(obj,img)
{
	obj.src = img;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
                                  //客户端预览图片
/////////////////////////////////////////////////////////////////////////////////////////////////////////

function DrawImage(ImgD){
   var image=new Image();
   image.src=ImgD.src;
   if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= 140/140){
     if(image.width>140){  
     ImgD.width=140;
     ImgD.height=(image.height*140)/image.width;
     }else{
     ImgD.width=image.width;  
     ImgD.height=image.height;
     }
     ImgD.alt=image.width+"×"+image.height;
     }
    else{
     if(image.height>140){  
     ImgD.height=140;
     ImgD.width=(image.width*140)/image.height;     
     }else{
     ImgD.width=image.width;  
     ImgD.height=image.height;
     }
     ImgD.alt=image.width+"×"+image.height;
     }
    }
   /*else{
    ImgD.src="";
    ImgD.alt=""
    }*/
   } 

function FileChange(Value){
flag=false;
document.images.nowPic.width=0;
document.images.nowPic.height=0;
document.images.nowPic.alt="";
document.images.nowPic.src=Value;
}

function FileChangeExtend(id,value)
{
	curPic = document.getElementById(id);
	flag=false;
	curPic.width=0;
	curPic.height=0;
	curPic.alt="";
	curPic.src=value;
}

function RotatorImage(o)
{
　　 var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+'%';
　　 return false;
}

 //最得对象在浏览者屏幕的位置
function getPos(el,sProp) {
	var iPos = 0
	while (el!=null) {
		iPos+=el["offset" + sProp]
		el = el.offsetParent
	}
	return iPos

}


// ============== 移动项  ========================================================
//移入项
function MoveInItem(objLeft, objRight, limitNum)
{
    var iSelCount = 0;
    var i = 0;
    var icount = 0;
    for(i = 0;i < objLeft.length; i++)
    {
        if (objLeft.options[i].selected)
        {
            iSelCount += 1;
            //判断是否有移动项数量限制
            icount = objRight.length;
            if (limitNum > 0)
            {
                if (icount >= limitNum)
                {
                    alert('只能选择' + limitNum + '项!');
                    return false;
                };
            };
            //判断选中的是否为无效项
            if (objLeft.options[i].value == '')
            {
                alert('您不能对该项操作！');
                return false;
            };
            
            if (icount > 0)
            {
                var j = 0;
                for(j = 0;j < objRight.length; j++)
                {
                    if (objLeft.options[i].value == objRight.options[j].value)
                    {
                        alert('不能添加重复项!');
                        return false;
                    };
                };
            };
            objRight.options[icount] = new Option(objLeft.options[i].text,objLeft.options[i].value);
            objRight.options[icount].selected = true;
        };
    }
    if (iSelCount == 0)
    {
        alert('您没有选中商品！');
    }
};
//移出项
function MoveOutItem(objRight)
{
    var i = 0;
    for(i =0;i < objRight.length; i++)
    {
        if (objRight.options[i].selected)
        {
            objRight.options[i] = null;
            if(objRight.length > 0)
            {
                objRight.options[0].selected = true;
            }
        };    
    };
    return false;
};

//检测两个选择框中是否有相同的项
function CheckSelectedItem(obj1, obj2)
{
    var i = 0;
    for(i=0; i < obj1.length; i++)
    {
        
    };
};
//============   END   ================================================================