﻿// JScript 文件
function $(){return document.getElementById(arguments[0]);}

//获取当前的getkeycode
function getkeycode(event) {
    return window.event ? window.event.keyCode : event.which;
}
//获取当前的getkeycode

//功能：checkbox的全选和全部取消（牟）
//参数：(当前checkid,特征的开始位置，特征的结束位置,相同特征的字符串)
//eg：<input id="mycheck" type="checkbox" onclick="checkSelectOrClearAll(this.checked,0,5,'Check');" />
function checkSelectOrClearAll(state,startC,endC,charList) {
  if(endC-startC!=charList.length){alert('(checkSelectOrClearAll) Math Worry！')}//检查调用是否正确
  
  var checkbox = document.getElementsByTagName("input");
  var mycheck_val = state;
  for(var i=0;i<checkbox.length;i++) {
    if(checkbox[i].id.substring(startC,endC) === charList) {
       checkbox[i].checked = mycheck_val;
    }
  }
}

//功能：获取指定特征Check选中后的值的字符串列表（牟）
//参数：(特征的开始位置，特征的结束位置,相同特征的字符串)
//return：valueList(1,2,3,4,5)没有返回("")
//eg：<input type="button" value="搞好了，提交....." onclick="getCheckedIdlist(0,5,'Check');" />
function getCheckedIdlist(startC,endC,charList){
  if(endC-startC!=charList.length){alert('(getCheckedIdlist) Math Worry！')}//检查调用是否正确
  
  var checkbox = document.getElementsByTagName("input");
  var getIDList = "";
  for(var i=0;i<checkbox.length;i++) {
    if(checkbox[i].checked === true && checkbox[i].id.substring(startC,endC)===charList){
      getIDList += checkbox[i].value+",";
    }
  }
  if(getIDList.length>0)
    getIDList=getIDList.substring(0,getIDList.length-1);
  return getIDList;
}

//功能：IsWorryInfo禁止用户输入错误信息(只能是数字或是字母)（牟）
//参数：(当前要验证的ID)
function IsWorryInfo(id) {
  var thisKey = window.event.keyCode;
  if(!((thisKey>=65 && thisKey<=90) || (thisKey>=97 && thisKey<=122 ) || (thisKey>=48 && thisKey<=57))) {
    var thisValue = document.getElementById(id).value;
    document.getElementById(id).value = thisValue.substring(0,thisValue.length-1);
  }
}

//该项设置样式对各个浏览器兼容（牟）
function setStyle(id,style){
    var $S=document.getElementById(arguments[0]);
    $S.setAttribute("style",style);
    $S.style.cssText=style;
}
function setClass(id,classVal){
    $(id).setAttribute("className", classVal);
    $(id).setAttribute("class", classVal);
}

//添加到收藏夹
function MYAddFavorite(){window.external.AddFavorite(this.location,document.title);}

//获取指定名称的cookie的值
function getCookie(objName){
    var arrStr = document.cookie.split("; ");
    for(var i = 0;i < arrStr.length;i ++){
        var temp = arrStr[i].split("=");
        if(temp[0] == objName) return unescape(temp[1]);
    } 
}

//添加cookie
function addCookie(objName,objValue,objHours){
    var str = objName + "=" + escape(objValue);
    if(objHours > 0){//为0时不设定过期时间，浏览器关闭时cookie自动消失
        var date = new Date();
        var ms = objHours*3600*1000;
        date.setTime(date.getTime() + ms);
        str += "; expires=" + date.toGMTString();
    }
    document.cookie = str;
}

//去掉重复的数据(使用标准","作为数据分割符)
function delIsThereArray(objValue){
    var arr=objValue.split(",");
    var retval="";
    var state=false;
    for(var i=0;i<arr.length-1;i++){
        for(var j=i+1;j<arr.length;j++){
            if(arr[i]==arr[j])
                state=true;
        }
        if(!state) retval+=arr[i]+",";
        if(i>arr.length-3) retval+=arr[i+1];
        state=false;
    }
    return retval;
}

//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
function delCookie(name){
    var date = new Date();
    date.setTime(date.getTime() - 10000);
    document.cookie = name + "=a; expires=" + date.toGMTString();
}

//设置指定的图片压缩
function onloadImg(img,width,height){
    var s1 = width/height;
    var s2 = img.offsetWidth/img.offsetHeight;
    if(s1>s2)
    { 
        img.height = img.offsetHeight>height?height:img.offsetHeight;
    }
    else 
    {
        img.width = img.offsetWidth>width?width:img.offsetWidth;
    }
}

//删除ParaVal的值
function DelParaValue(objName){
    try{
        var array=document.URL.split("?");
        var retUrl=array[0]+"?";
        array=array[1].split(",");

        for(var i=0;i<array.length;i++)
        {
            var temp = array[i].split("=");
            if(temp[0]!=objName){
                retUrl+=temp[0]+"="+temp[1];
                retUrl+= i<array.length-1?",":"";
            }
        }
        if(retUrl.substring(retUrl.length-1,retUrl.length)=="?")
            retUrl = retUrl.substring(0,retUrl.length-1)
            
        if(retUrl.substring(retUrl.length-1,retUrl.length)==",")
            retUrl = retUrl.substring(0,retUrl.length-1);
            
        return retUrl;
    }
    catch(ex){return document.URL;}
}

//设置ParaVal的值
function SetParaValue(objName,objValue)
{
    var array=document.URL.split("?");
    var retUrl=array[0]+"?";
    array=array[1].split(",");
    for(var i=0;i<array.length;i++)
    {
        var temp = array[i].split("=");
        retUrl+=temp[0]+"=";
        retUrl+=temp[0] == objName?objValue:temp[1];
        retUrl+= i<array.length-1?",":"";
    }
    return retUrl;
}

//获取ParaVal的值，如果不存在，返回一个undefined
function GetParaValue(objName){
    var array=document.URL.split("?");
    if(array.length==2)
    {
        array=array[1].split(",");
        for(var i=0;i<array.length;i++)
        {   
            var temp = array[i].split("=");
            if(temp[0] == objName) return unescape(temp[1]);
        }
    }
}

//yyyy-MM-dd将yyyy-mm-dd或是yyyy-m-d获取指定的数据。
function getdateparse()
{
    switch(arguments[0])
    {
        case "yyyy": return parseInt(arguments[1].substring(0,4));
        case "mm":
            var yy=arguments[1].substring(arguments[1].indexOf("-")+1,arguments[1].indexOf("-",6));
            if(yy.length==2 && yy.substring(0,1)=="0"){yy=yy.substring(1,2);}
            return parseInt(yy);
        case "dd":
            var dd=arguments[1].substring(arguments[1].indexOf("-",6)+1,arguments[1].length);
            if(dd.length==2 && dd.substring(0,1)=="0"){dd=dd.substring(1,2);}
            return parseInt(dd);
        default:
             return parseInt(arguments[1].substring(0,4));
            break;
    }
}