﻿// JScript 文件

function getID(id){
    return window.document.getElementById?window.document.getElementById(id):null;
}

function fn_stringCut(strTemp,n){
	var i,sum,r_str;
	sum = 0;
	r_str = "";
	for(i=0;i<strTemp.length && sum<n;i++)
	{
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			sum=sum+1;
		else
			sum=sum+2;
		r_str += strTemp.substring(i,i+1);
	}
	return r_str;
 
}

function fn_js_CtrlImges(img,w,h){
    var iW = w;
    var iH = h;
    var oW = img.width;
    var oH = img.height;

    if(img.width>iW && img.height>iH){
        if(oW/iW > oH/iH){
	        img.width = iW;
	        img.height = parseInt(iW/oW * oH);
        }
        else{
	        img.height = iH;
	        img.width  = parseInt(iH/oH * oW);
        }
        return true;
    }
    if(oW>iW){
        img.width = iW;
        img.height = parseInt(iW * (oH/oW));
    }else if(oH>iH){
        img.height = iH;
        img.width  = parseInt(iH * (oW/oH));
    }
    return true;
}


function fn_ImgReload(Panle){
    Panle = Panle.replace("T","Tbl");
    var Imgs = document.getElementById(Panle).getElementsByTagName("img");
    var lens = Imgs.length;
    for(var i=0;i<lens;i++){
        Imgs[i].src = Imgs[i].src;
    }
}
        

function setOutHTML(obj,HTML){
	ReELE(obj).outerHTML = HTML;
}

function setInHTML(obj,HTML){
	ReELE(obj).innerHTML = HTML;
}

function trim(str){
	var sStr = new String(str);
	sStr = sStr.replace(/(^\s*)|(\s*$)/,"");
	return sStr;
}

//onpropertychange
function fn_checkInput(regx){
    var src = event.srcElement;
    var regx = new RegExp(regx);
    if(regx.test(src.value)){
        src.value=src.value.replace(regx,'');
    }
}

function   addOption(objSelectNow,txt,val)   
{   
//    ///使用W3C标准语法为SELECT添加Option   
//	var objOption = document.createElement("OPTION");   
//	objOption.setAttribute("text",txt); 
//	objOption.setAttribute("value",val);   
//	objOption.setAttribute("index",val);   
//	objSelectNow.options.add(objOption);

    objSelectNow.options.add(new Option(txt,val));
    
}

//全角字符转半角字符
function toDBC(Str) {   
    var DBCStr = "" ;      
    for (var i= 0 ; i<Str.length; i++){   
      var c = Str.charCodeAt(i);   
      if (c ==  12288 ) {   
          DBCStr += String.fromCharCode(32 );   
          continue ;   
      }
       
      if  (c >  65280  && c <  65375 ) {   
          DBCStr += String.fromCharCode(c - 65248 );   
          continue ;   
      }   
      
        DBCStr += String.fromCharCode(c);   
     }   
     return  DBCStr;   
} 
    

function GetCookie(name)
{
	var cookieString   = new   String(document.cookie);
	var cookieHeader   = name+"="; 
	var beginPosition  = cookieString.indexOf(cookieHeader);
	if (beginPosition != -1){ 
		var cstr = cookieString.substring(beginPosition + cookieHeader.length);
		if(cstr.indexOf(";")== -1){
			return   cstr;
		}
		else{
			return cstr.substring(0,cstr.indexOf(";"));
		}
	}
	else
		return   "NoLogin";
}

function fn_open_newWinD(docName,height,width){
        if(height == null){
            window.open(docName);
        }else{
		    var left = (window.screen.availWidth-width)/2;
		    window.open (docName, "newwindow", "height="+height+", width="+width+",top=250,left="+left+" toolbar =no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
		}
}



function createXMLHttpObject()
{
    var xmlObj = null;
    if (window.XMLHttpRequest) { 
        xmlObj = new XMLHttpRequest();
        if (xmlObj.overrideMimeType) {
             xmlObj.overrideMimeType('text/xml');
        }
    }else if (window.ActiveXObject){ // IE
        try {
             xmlObj = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
            try {
                xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){}
        }
    }
    return xmlObj;
}



function killerror() {
	return true;
}

window.onError = killerror;

function isEmail(ctl) {
    return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(ctl.value);
}

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.len=function() {
    var str=this;
    if (str.length==0) return 0;
    return str.replace(/[^\x00-\xff]/g,"aa").length;
}
