﻿/***********************************************************************
功能：公共 Javascript 调用
***********************************************************************/

//自定义弹出窗口
//路径，窗口名，窗口设置参数，left位置，right位置
function OpenWinSelf(theURL,winname,opt,moveToLeft,moveToTop)
{ 
		pop=window.open(theURL,winname,opt);
		if(OpenWinSelf.arguments.length>=3)
		{
		    try{pop.moveTo(moveToLeft,moveToTop);}catch(e){}
		}
}

//弹出窗口
//路径，窗口名，窗口宽，窗口高
function sunupWin(url,name,w,h){

    OpenWinSelf(url,name,"width=" + w + ",height=" + h + ",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=on",(screen.width-w)/2,(screen.height-h)/2);
}

//弹出窗口有菜单栏
//路径，窗口名，窗口宽，窗口高
function openPringWin(url,name,w,h){
    sunupWin(url,name,"width=" + w + ",height=" + h + ",toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,location=no,status=no",(screen.width-w)/2,(screen.height-h)/2);
}

//弹出网页对话框
//路径，状态栏，窗口宽，窗口高，传值
function openWinDialog(url,scr,w,h,value)
{
	var Tform;
	var theValue;
	if(!value){value="";}
	eval("Tform='dialogWidth:"+w+"px;dialogHeight:"+h+"px;status:"+scr+";scrollbars=no;help:no'");	
	theValue=window.showModalDialog(url,value,Tform);
	return theValue;
}


function MouseOver(arg){arg.className='MoveOver';}
function MouseOut(arg){arg.className='Link';}


//调用XMLHTTP
function getXMLHTTP(pURL,pStr){
    try{
        var xmlhttp = new ajaxActiveXObject();
        xmlhttp.open("POST", pURL, false);
	    xmlhttp.send("<root>"+pStr+"</root>");
	    var sendXML=null; //alert(sendXML);
        if(xmlhttp.readyState==4){
            if(xmlhttp.status==200){
                sendXML=xmlhttp.responseText;
            }
        }
	    return sendXML;
    }catch(e){return e.description}
}

//建立XMLHTTP对象
function ajaxActiveXObject() 
{
	var request = null;
	if (window.XMLHttpRequest) { 
        request = new XMLHttpRequest(); 
    }else if (window.ActiveXObject) {
	    try{request = new ActiveXObject('Msxml2.XMLHTTP');}
	    catch(e1){
		    try{request = new ActiveXObject('Microsoft.XMLHTTP');}catch(e2){}
	    }
	}
	return request;
}



//替换字符串
function ReplaceStr(vStr,theStr,theReplaceStr)
{	
	var theValue=vStr;
	if (theStr!=theReplaceStr && theReplaceStr!="")
	{
		while(theValue.indexOf(theStr)!=-1)
		{
			theValue=theValue.replace(theStr,theReplaceStr);
		}
	}
	return theValue;
}

//将字符串替换成网页字符
function TransText(sTmp)
{
    var ns = "";
    ns = sTmp.replace("&", "&amp;");
    ns = ReplaceStr(ns, "<", "&lt;");
    ns = ReplaceStr(ns, ">", "&gt;");
    ns = ReplaceStr(ns, "\r", "<br>");
    ns = ReplaceStr(ns, "	", "&quot;");
    ns = ReplaceStr(ns, " ", "&nbsp;");
    return ns;
}

//网页字符替换成字符串
function Text2Html(Str1)
{
    var ns = "";
    ns = Str1.replace("&amp;", "&");
    ns = ReplaceStr(ns, "&lt;", "<");
    ns = ReplaceStr(ns, "&gt;", ">");
    ns = ReplaceStr(ns, "<br>", "\r");
    ns = ReplaceStr(ns, "&quot;", "	");
    ns = ReplaceStr(ns, "&nbsp;", " ");
    return ns;
}

//得到文件路径
 function GetfilePath(filePath,s){
    var n
    if(s){
        n=filePath.lastIndexOf("\\")
    }else{
        n=filePath.lastIndexOf("/")
    }
    
    var tmpstr=filePath.substring(0,n+1);
    return tmpstr;
 }
 
 //得到文件名
 function GetfileName(filePath,s){
    var tmpstr
    if(s){
        tmpstr=filePath.split("\\");
    }else{
        tmpstr=filePath.split("/");
    }
    var n=tmpstr.length;
    return tmpstr[n-1];
}

//得到文件扩展名
function GetFileExtension(filePath,s){
    var tmpstr=filePath.split(".");
    var n=tmpstr.length;
    return "."+tmpstr[n-1];
}


//判断IP
 function chkIP(sIP){
	var TheValue=sIP;
	var ss = TheValue.split(".");
	if (ss.length!=4) return false; 
	if(isNaN(ss[3])||ss[3]=='') return false; 
	
	for(i=0;i<=3;i++){
	    if(isNaN(ss[i])) return false; 
	    if(!(ss[i]>=0 && ss[i]<=255)) return false;
	}
	return true;
}

//判断整数
function isInt(Num){
    var opt=false
    if(Num!="" && Num!=null){
        if(!isNaN(Num)){
            if(Num==parseInt(Num)){
                opt=true;
            }
        }
    }
    return opt;
}

//四舍五入
function round(Num,n){
    var s=Num;
    if(!isNaN(Num)){
        if(n==0 || n==null){
            s=Math.round(Num);
        }else{
            s=Math.round(Num*Math.pow(10,n))/Math.pow(10,n);
        }
    }
    return s;
}