﻿
/*========================================================================*/
/*
    此JS是通用脚本方法
    日期：2011-7-18
*/
/*========================================================================*/

/*========================================================================*/
//页面参数的获取
function getQuery(name) {
    try{
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = location.search.substr(1).match(reg);
        var value = "";
        if (r != null){
            try{
                value = decodeURI(r[2]);
            }
            catch(e){
                value = escape(r[2]);
            }
        }
        
        return value;
    }
    catch(e){
    }
}
/*========================================================================*/

/*========================================================================*/
//获取当前浏览器
function GetBrowserName(){
	var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
	var isOpera = userAgent.indexOf("Opera") > -1;

	if (isOpera){return "Opera"}; //判断是否Opera浏览器 
	if (userAgent.indexOf("Firefox") > -1){return "FF";} //判断是否Firefox浏览器 
	if (userAgent.indexOf("Safari") > -1){return "Safari";} //判断是否Safari浏览器 
	if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera){return "IE";} ; //判断是否IE浏览器
}

//获取某个框架内的元素对象
function getIframeObj(elmid,_ifrid){
    var ifrid = "iframeTop";
    if(_ifrid){
        ifrid = _ifrid;
    }
    var BrowserName = GetBrowserName();
    var iframeObj = null;
    var elmObj = null;
    if(BrowserName == "FF"){
        iframeObj = getObj(ifrid);
        elmObj = iframeObj.contentDocument.getElementById(elmid);
    }
    else{
        iframeObj = parent.window.frames[ifrid];
        if(iframeObj==null){
            iframeObj = window.frames[ifrid];
        }
        elmObj = iframeObj.document.getElementById(elmid);
    }
    
    return elmObj;       
}

//设置某个框架内的元素对象
function setIframeObj(elmid,value,_ifrid){
    var obj = getIframeObj(elmid,_ifrid);
    if (obj) {
        obj.value = value;
    }
}

//清空某个框架内元素对象值
function clearIframeObjV(elmid,value,_ifrid) {
    var obj = getIframeObj(elmid,_ifrid);
    if (obj) {
        if(value)
            obj.value=value;
        else
            obj.value="";
    }
}
/*========================================================================*/

/*========================================================================*/
//根据元素ID获取元素对象
function getObj(objid) {
    var obj = window.document.getElementById(objid);
    if (obj) {
        return obj;
    }
    else{
        obj = parent.window.document.getElementById(objid);
        return obj;
    }
}

//根据元素ID获取元素对象的值
function getObjV(objid) {
    var value = "";
    var obj = getObj(objid);
    if (obj) {
        value = obj.value;
    }
    return value;
}

//根据元素ID设置元素对象的值
function setObjV(objid,value) {
    var obj = getObj(objid);
    if (obj) {
        obj.value = value;
    }
}

//隐藏元素对象
function hiddenObj(objid) {
    var obj = getObj(objid);
    if (obj) {
         obj.style.display='none';
    }
}

//显示元素对象
function showObj(objid) {
    var obj = getObj(objid);
    if (obj) {
         obj.style.display='';
    }
}

//清空元素对象内容
function clearObj(objid) {
    var obj = getObj(objid);
    if (obj) {
         obj.innerHTML='';
    }
}

//清空元素对象值
function clearObjV(objid,value) {
    var obj = getObj(objid);
    if (obj) {
        if(value)
            obj.value=value;
        else
            obj.value="";
    }
}
/*========================================================================*/

/*========================================================================*/
//根据元素ID获取父页面元素对象
function getParentObj(objid) {
    var obj = parent.getObj(objid);
    if (obj) {
        return obj;
    }
    else{
        obj = parent.window.document.getElementById(objid);
        return obj;
    }
}

//根据元素ID获取父页面元素对象的值
function getParentObjV(objid) {
    var value = "";
    var obj = getParentObj(objid);
    if (obj) {
        value = obj.value;
    }
    return value;
}

//根据元素ID设置父页面元素对象的值
function setParentObjV(objid,value) {
    var obj = getParentObj(objid);
    if (obj) {
        obj.value = value;
    }
}

//隐藏父页面元素对象
function hiddenParentObj(objid) {
    var obj = getParentObj(objid);
    if (obj) {
         obj.style.display='none';
    }
}

//显示父页面元素对象
function showParentObj(objid) {
    var obj = getParentObj(objid);
    if (obj) {
         obj.style.display='';
    }
}

//清空父页面元素对象内容
function clearParentObj(objid) {
    var obj = getParentObj(objid);
    if (obj) {
         obj.innerHTML='';
    }
}

//清空父页面元素对象内容或值
function clearParentObjV(objid,value) {
    var obj = getParentObj(objid);
    if (obj) {
        if(value)
            obj.value=value;
        else
            obj.value="";
    }
}
/*========================================================================*/

/*========================================================================*/
//显示iframe Url 弹出的页面地址，kuan 宽度 gao 高度 title 弹出层标题 tag 用于AJAX更新的标记
function ShowIframe(Url,kuan,gao,title,tag)
{  
    var pop=new Popup({ contentType:1,isReloadOnClose:false,width:kuan,height:gao});
    pop.setContent("contentUrl",Url);
    pop.setContent("title",title);
    pop.build();
    pop.show();
}
/*========================================================================*/

