﻿//gb2312编码方式会导致IE6的JS错误
//具体操作：更改好了后，保存时按如下步骤：
//文件-高级保存选项-编码（unicode-UTF-8带签名）
function ShoworDisplay(divid)
{var s=document.getElementById(divid);
if(s.style.display=='none'){s.style.display='block';}else{s.style.display='none'}
}

function rblValue(id)
{
//返回RadioButtonList选中的文本值,
//☆.net2.0通用,由于考虑到横排和竖排的情况,以及设置了RepeatColumns情况下,遍历cell的个数为佳
var r=document.getElementById(id).rows.length
var l=0;
for(var c=0;c<r;c++)
{l=l+document.getElementById(id).rows[c].cells.length}
//alert(l);
for(var i=0;i<l;i++)
{
var rn=id+"_"+i;
if(g(rn)!=null&&document.getElementById(rn).checked)
{
return document.getElementById(rn).value
}
}
return ""
}

function cklLabelfor(id)
{//返回CheckBoxList选中的Text
//关键在于获取该CheckBox后一个DOM，后一个DOM就是其关联的label，在C#里设置的Text也显示在label里
var r=document.getElementById(id).rows.length
var l=0;var sarray=new Array();
for(var c=0;c<r;c++)
{l=l+document.getElementById(id).rows[c].cells.length}
for(var i=0;i<l;i++)
{
var rn=id+"_"+i;
if(g(rn)!=null&&document.getElementById(rn).checked)
{sarray.push(document.getElementById(rn).nextSibling.innerHTML);}
}
return sarray;
}
//判断一组单选框是否有选中
  function check_radiolist(name)
  {var radio_list=document.getElementsByName(name);
  for(var i=0;i<radio_list.length;i++){if(radio_list[i].checked){return radio_list[i].value||radio_list[i].id}}
  return ""}
//----遮蔽层
function showPopWindow(maskID, msgID,rewardID) 
{
  var os=document.getElementById("hidOrderState").value;
    if(os=="5")//如果是赏金任务 
    {
        var grayBackground = document.getElementById(maskID);
        var popWindow = document.getElementById(rewardID);
        grayBackground.style.display='block';
        popWindow.style.display='block';
        var top=100;//document.documentElement.scrollTop+
        popWindow.style.top=top+'px';
    }
    else//为代练
    {
        var grayBackground = document.getElementById(maskID);
        var popWindow = document.getElementById(msgID);
        grayBackground.style.display='block';
        popWindow.style.display='block';
        var top=200;//document.documentElement.scrollTop+
        popWindow.style.top=top+'px';
    }
}
function closePopWindow(maskID, msgID, isPrice) 
{
  var grayBackground = document.getElementById(maskID);
  var popWindow = document.getElementById(msgID);
	if(isPrice == '1') 
	{var inputPrice = document.getElementById('inputPrice'); // 提醒中的输入框
	var txtOnePrice = document.getElementById('txtOnePrice'); // 表单中的输入框
	txtOnePrice.value = inputPrice.value;}
	grayBackground.style.display='none';
	popWindow.style.display='none';
}
function checkAnswer(obj, closeDiv) {
  var closePopButton = document.getElementById('closePopButton');
  var inputPriceDiv = document.getElementById(closeDiv);
  if (obj.value=='1') {
	closePopButton.disabled = false;
	inputPriceDiv.style.display = 'block';
  } else {
	  closePopButton.disabled = true;
	  inputPriceDiv.style.display = 'none';
  }
}
//------遮蔽层结束
//神奇遮蔽层加中间文本层，前面一个参数为中间文本层，后面一个参数为石灰层
function ShowFullScreen(divid,showid)
    {
    var s=document.getElementById(divid);
    var w=document.getElementById(showid);
    if((s!=null)&&(w!=null))
    {
    if(s.style.display=='none')
    {s.style.display='block';w.style.display='block';
    s.style.height=document.documentElement.clientHeight+'px';
    s.style.width=document.documentElement.clientWidth+'px';
    s.style.top=document.documentElement.scrollTop+'px';
    w.style.height=document.documentElement.scrollHeight+'px';
    w.style.width=document.documentElement.scrollWidth+'px';
//    document.getElementById("hidRecieveID").value=pid;
//    alert(document.getElementById("hidRecieveID").value);
    }else{s.style.display='none';w.style.display='none'}
    }
    }
    //---JS右下提示框
        var trueheight=0;var Invoke=0;var changeheight=0
        function showtip(name)
        {var tip=document.getElementById(name);
        if(tip!=null)
        {if(tip.style.display=='none')
        {tip.style.position='absolute';tip.style.zIndex='1000';tip.style.overflow="hidden";
        tip.style.display='block';
        if(tip.style.height==""){tip.style.height='200px';}
        if(tip.style.width==""){tip.style.width='200px';}
        trueheight=parseInt(tip.style.height);
        tip.style.height='0px';
        Invoke=setInterval("tipmoveup('"+name+"')",10);//调整速度修改参数
        }
        else{tip.style.display='none';clearInterval(Invoke);}}}//alert(Invoke)
        function tipmoveup(name)
        {
        var tip=document.getElementById(name);
        var tiptop=document.documentElement.scrollTop+document.documentElement.clientHeight-changeheight;
        tip.style.top=tiptop+'px';
        var tipleft=document.documentElement.scrollLeft+document.documentElement.clientWidth-parseInt(tip.style.width)-10;
        tip.style.left=tipleft+'px';
        if(changeheight<=trueheight)
        {tip.style.height=changeheight+'px';
        changeheight=changeheight+2;//调整精度修改这里
        }}
        //---JS右下提示框结束
        
//JS判断输入字符长度
    function truewordlength(st)
    {var l=st.length;var china=0;var english=0;
    for(var i=0;i<l;i++){if(st.charCodeAt(i)>255){china+=2;}else{english+=1;}}
    return china+english;
    }
    
    //判断客户端浏览器
    function CheckNavigatorMes()
    {
    if((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0))
    {return "MSIE"}
    if(navigator.userAgent.indexOf('Firefox') >= 0)
    {return "Firefox"}
    if(navigator.userAgent.indexOf('Opera') >= 0)
    {return "Opera"}
    return ""
    }
    //根据传入的URL地址重新更新QuestString，建议questValue若为中文，用escape()转换下
    function SetQuestUrl(url,questname,questValue)
    {
    var s=url;var q=questname + "=" + questValue;
    if(s.search(/\?/)>=0)
    {var forsearch=new RegExp(questname+'=\.*&?',"i");var x_forsearch=new RegExp(questname+'=\.*&',"i");
    if(s.search(forsearch)>=0){if(s.search(x_forsearch)>=0){s=s.replace(x_forsearch,q+'&')}
    else{s=s.replace(forsearch,q)}}
    else{s=s+'&'+q}}
   else{s=s+'?'+q;}
   return s;
   }
   //获取URL地址的QuestString
   function GetQuestValue(url,questname)
    {var v='';var q=url.replace(/.*\?/,"").split("&");
    var forsearch=new RegExp(questname+'=',"i"); 
    for(var i=0;i<q.length;i++)
    {
    if(q[i].search(forsearch)>=0)
    {v=q[i].replace(forsearch,"")}
    }
    return v;
    }
   function containsDOM (container, current) //遍历判断current是否为container的子元素
   {var isParent = false;
  while (current != null && !isParent)
   {isParent = (container == current);
    current = current.parentNode;}
  return isParent;}
  function IsonMouseEnter(element,evt)//判断鼠标是否进入该元素（包括子元素）
  {var obj=null;
  if(evt.fromElement){obj=evt.fromElement}
  else if(evt.relatedTarget){obj=evt.relatedTarget;}
  return !containsDOM(element,obj)
  }
  function IsonMouseLeave(element,evt)//判断鼠标是否离开该元素（包括子元素）
  {var obj=null;
  if(evt.toElement){obj=evt.toElement}
  else if(evt.relatedTarget){obj=evt.relatedTarget;}
  return !containsDOM(element,obj)
  }
      function addDOMLoadEvent(func) //网上摘录的，声明在DOM加载完成后执行的func方法，而摈弃window.onload=func()的语句（不需要等待img等完全加载后才触发）
      {
    if (!window.__load_events) {
       var init = function () {
           // quit if this function has already been called
           if (arguments.callee.done) return;
      
          // flag this function so we don't do the same thing twice
           arguments.callee.done = true;
      
           // kill the timer
           if (window.__load_timer) {
               clearInterval(window.__load_timer);
              window.__load_timer = null;
           }
          
          // execute each function in the stack in the order they were added
           for (var i=0;i < window.__load_events.length;i++) {
               window.__load_events[i]();
           }
           window.__load_events = null;
      };
   
       // for Mozilla/Opera9
       if (document.addEventListener) {
           document.addEventListener("DOMContentLoaded", init, false);
       }
       //for IE -maoxu
      else if((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0))
      {	
		window.__load_timer=setInterval(function()
		{
		try {
			// If IE is used, use the trick by Diego Perini
			// http://javascript.nwbox.com/IEContentLoaded/
			document.documentElement.doScroll("left");
			init();}
		catch( error ) {}
		},10)
      }
//       // for Internet Explorer
//       /*@cc_on @*/
//       /*@if (@_win32)
//           document.write("<scr"+"ipt id=__ie_onload defer src=//0><\/scr"+"ipt>");
//           var script = document.getElementById("__ie_onload");
//           script.onreadystatechange = function() {
//               if (this.readyState == "complete") {
//                   init(); // call the onload handler
//               }
//           };
//       /*@end @*/
      
       // for Safari
      else if (/WebKit/i.test(navigator.userAgent)) { // sniff
           window.__load_timer = setInterval(function() {
               if (/loaded|complete/.test(document.readyState)) {
                   init(); // call the onload handler
               }
           }, 10);
       }
      
       // for other browsers
       else{window.onload = init;}
      
       // create event function stack
       window.__load_events = [];
    }
    // add function to event stack
    window.__load_events.push(func);
 }
     function Validator_mainLoad(json_v)//验证主方法
    {
    Validator_Source=json_v;
    //定义方法
    this.ShowOnfocus=function(i)//获得焦点操作
    {
    var v=Validator_Source[i];
    var tip=document.getElementById(v.tipid);
    tip.innerHTML=(v.onfocus)?v.onfocus:v.onshow,tip.className="onFocus";
    }
    this.Validator_regex=function(v,inputv,customF,causevaild)//验证
    {var answer=false;
    if(causevaild){
    if(eval(causevaild))
    {if(customF){answer=eval(customF)}
    else{answer=(new RegExp(v)).test(inputv);}}
    else{answer=true;}}
    else{answer=true}
    return answer}
    this.ShowValidatorResult=function(val,tipObj,oncorrect,onerror)//验证结果显示操作
    {
    if(val){
    tipObj.innerHTML=(oncorrect)?oncorrect:"正确";
    tipObj.className="onCorrect";
    }
    else{
    tipObj.className="onError";
    tipObj.innerHTML=(onerror)?onerror:"错误";
    }
    return val;
    }
    
    this.ShowOnValidator_regex=function(i,totalcheck)
    {
    var v=Validator_Source[i];
    var inputObj=document.getElementById(v.inputid);
    var check=ShowValidatorResult(Validator_regex(v.functionName.org1,inputObj.value,v.functionName.customF,v.functionName.causevaild),document.getElementById(v.tipid),v.oncorrect,v.onerror);
    if(!check&&totalcheck)//若需要弹alert和foucs行为
    {
    if(Validator_Source[0].isShowMes){var mes="";if(v.onerror){mes=v.onerror}else if(v.onfocus){mes=v.onfocus}else if(v.onshow){mes=v.onshow};alert(mes)}
    if(Validator_Source[0].isfocus){inputObj.focus()}
    }
    return check;
    }
    var fm=Validator_Source[0];
    var thisform=fm.formid?document.getElementById(fm.formid):null;
    var checkarray=new Array();
    //遍历注册方法
    for(var i=1;i<Validator_Source.length;i++)
    {
    var v=Validator_Source[i];
    var isvalid=false;
    var tip=document.getElementById(v.tipid);
    var inputObj=document.getElementById(v.inputid)
    if(tip!=null&&inputObj!=null)
    {
    tip.innerHTML=v.onshow;
    tip.className="onShow";
    inputObj.setAttribute("json",i);
    inputObj.onfocus=function(){
    ShowOnfocus(this.getAttribute("json"));
    }
    switch(v.functionName.fn)
    {
    case 'Validator_regex':
    checkarray.push("ShowOnValidator_regex("+i+",true)");
    inputObj.onblur=function()
    {
    var v=this.getAttribute("json");
    ShowOnValidator_regex(v,false);
    }
    break
    default:
    }
    }
    }
    if(!fm.Nosubmit&&thisform!=null)thisform.onsubmit=function (){return eval(checkarray.join("&&"))}
    }
    function g(id)//懂的入
    {return document.getElementById(id);}
    function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
function ShowCheckResult(val,inputObj,tipObj,oncorrect,onerror,istotalcheck)//验证结果显示操作
    {
    if(val){
    if(tipObj!=null){tipObj.innerHTML=oncorrect;
    tipObj.className="onCorrect";}
    }
    else{
    if(tipObj!=null){tipObj.className="onError";
    tipObj.innerHTML=onerror;}
    if(istotalcheck){alert(onerror);inputObj.focus();}
    }
    return val;
    }
    function Check_regex(v,inputv)//验证
    {return (new RegExp(v)).test(Trim(inputv))}
    //去空格
    function Trim(v)
    {return v.replace(new RegExp("(^\\s*|\\s*$)","gm"),"")}
    
    
    
    
    function isInteger( str ){
    str = Trim(str);
    if(str=="")//空的话不验证
    {
    return true;
    }
    var regu = /^[-]{0,1}[0-9]{1,}$/;
    return regu.test(str);
    }
    
    function   HtmlEncode(text)   
      {   
              return   text.replace(/&/g,   '&amp').replace(/\"/g,   '&quot;').replace(/</g,   '&lt;').replace(/>/g,   '&gt;');   
      }
      
      function   HtmlDecode(text)   
      {   
              return   text.replace(/&amp;/g,   '&').replace(/&quot;/g,   '\"').replace(/&lt;/g,   '<').replace(/&gt;/g,   '>');   
      }


function Validator_regex(v,inputv)//验证
    {return (new RegExp(v)).test(StringTrim(inputv))}

    function StringTrim(v)
    {return v.replace(new RegExp("(^\\s*|\\s*$)","gm"),"")}