var agt = navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_opera;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all;


function $(s){
  return document.getElementById(s);
}

function $$(s){
  return document.getElementsByName(s);
}

function trim(s){
   return s.replace(/^\s+|\s+$/g,""); 
}

function is_null(val){
	return (val == "" || val == null || val == "undefined");
}
function str_len(key){
	var l=escape(key),len; 
	len=l.length-(l.length-l.replace(/\%u/g,"u").length)*4;
	l=l.replace(/\%u/g,"uu");
	len=len-(l.length-l.replace(/\%/g,"").length)*2;
	return len;
}

function isMobile(s){
  var m=trim(s);
  if(m.length!=11|| !isNumber(m) || (m.substring(0,2)!='13' && m.substring(0,2)!='15' && m.substring(0,2)!='18')){
     alert("您所填写的手机号码不正确！");
	 return false;
  }
  return true;
}

function isNumber(num){
   if(num=='') return false;
   limitStr="0123456789";
   var s="";
   succ=true;
   for(i=0;i<num.length;i++){
     s=num.charAt(i);
	 if(limitStr.indexOf(s)<0){
       succ=false;
	   break;
	 }
   }
   return succ;
}

function isPhoneNumber(num){
   if(num=='') return false;
   limitStr="0123456789-()";
   var s="";
   succ=true;
   for(i=0;i<num.length;i++){
     s=num.charAt(i);
	 if(limitStr.indexOf(s)<0){
       succ=false;
	   break;
	 }
   }
   return succ;
}

function close(o){
   o.style.disply="none";
}

function getRadioValue(ra){
 va="";
 for(i=0;i<ra.length;i++){
   if(ra[i].checked) va=ra[i].value;
 }
 return va;
}
function replaceStr(s) {
  s=s.replace(/{\*o-o-o\*}/gi,"&");
  s=s.replace(/{\*o-o\*}/gi,"|");
  return s;
}

function getXY(evt){
    evt=evt?evt:(window.event?window.event:null);
    if (is_ie) { // grab the x-y pos.s if browser is IE
       tempX = evt.clientX + document.body.scrollLeft
       tempY = evt.clientY + document.body.scrollTop
    } else { // grab the x-y pos.s if browser is NS
       tempX = evt.pageX+ document.documentElement.scrollLeft
       tempY = evt.pageY+ document.documentElement.scrollTop
    }
	//   alert("document.body.scrollTop="+document.body.scrollTop+ "   document.documentElement.scrollTop="+document.documentElement.scrollTop);
    // catch possible negative values in NS4
    if (tempX < 0){tempX = 10;}
    if (tempY < 0){tempY = 10;}
	return [tempX,tempY];
}

function getXYNoScroll(evt){
    evt=evt?evt:(window.event?window.event:null);
    if (is_ie) { // grab the x-y pos.s if browser is IE
       tempX = evt.clientX ;
       tempY = evt.clientY ;
    } else { // grab the x-y pos.s if browser is NS
       tempX = evt.pageX;
       tempY = evt.pageY;
    }
	//   alert("document.body.scrollTop="+document.body.scrollTop+ "   document.documentElement.scrollTop="+document.documentElement.scrollTop);
    // catch possible negative values in NS4
    if (tempX < 0){tempX = 10;}
    if (tempY < 0){tempY = 10;}
	return [tempX,tempY];
}

function setDivBottom(o){
//   alert("w="+(o.style.width-1)+"  h="+o.style.height);
   $("ifrDIV").style.height=o.style.height;
   $("ifrDIV").style.width=o.style.width;
   $("ifrDIV").style.top=o.style.top;
   $("ifrDIV").style.left=o.style.left;
   $("ifrDIV").style.display="block";
   $("ifrDIV").style.zIndex=o.style.zIndex-1;
}
function clsDivBottom(){
	if($("ifrDIV"))
    $("ifrDIV").style.display="none";
}

function showDiv(o){
  if(!$("ifrDIV")){
    var ifr=document.createElement("iframe");
    ifr.style.position="absolute";
    ifr.style.width=0+"px";
    ifr.style.height=0+"px";
    ifr.style.top=0;
	ifr.style.display="none";
    ifr.frameBorder=0;
    ifr.id="ifrDIV";
    document.body.appendChild(ifr);
  }
  o.style.display="block";
  setDivBottom(o);
}
function hideDiv(o){
   clsDivBottom();
   o.style.display="none";
}

//0：无效手机，1：移动手机，2:联通手机
function cmMobile(m){
  var m0="ss|134|135|136|137|138|139|150|151|152|155|158|157|159|188|ss";
  var m2="ss|130|131|132|133|153|156|189|ss";
  m=m.replace(/^\s+|\s+$/g,""); 
  if(m=='' || !isNumber(m) || m.length!=11){
	 return 0;
  }
  var s=m.substring(0,3);
  if(m0.indexOf("|"+s+"|")>0){
	 return 1;
  }else if(m2.indexOf("|"+s+"|")>0){
     return 2;
  }
}