﻿//判断浏览器
function getOs()
{
   if(navigator.userAgent.indexOf("MSIE")>0)return 1;
   if(navigator.userAgent.indexOf("Opera")>0)return 2;
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 3;
   if(isSafari=navigator.userAgent.indexOf("Safari")>0)return 4;   
   if(isCamino=navigator.userAgent.indexOf("Camino")>0)return 5;
   if(isMozilla=navigator.userAgent.indexOf("Gecko")>0)return 6;
   return 0;
}
//返回指定ID的标签
function $()
{
	var elements = new Array();
	for (var i=0;i<arguments.length;i++)
	{
		var element = arguments[i];
		if (typeof element == 'string') element = document.getElementById(element);
		if (arguments.length == 1) return element;
		elements.push(element);
	}
	return elements;
}

//去除字符串首尾空格
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/,"");
}
//显示浮动信息框 参数1:信息标题 参数2:信息内容
function showdiv(title,content,width,height)
{
    //配置窗口的外观
    var divWidth = (width==null)?640:width;
    var divHeight = (height==null)?480:height;
    var pageWidth = getPageSize()[0];
    var pageHeight = getPageSize()[1];
    var windowWidth = getPageSize()[2];
    var windowHeight = getPageSize()[3];
    var windowLeft = document.documentElement.scrollLeft;
    if(windowLeft<=0) windowLeft = document.body.scrollLeft;
    var windowTop = document.documentElement.scrollTop;
    if(windowTop<=0) windowTop = document.body.scrollTop;
        
    //配置窗口的内容
    var html = "";
    if(typeof(content)=="object")
    {
        html = content.innerHTML;
        content.innerHTML = "";
    }
    else if(typeof(content)=="string")
    {
        html = content;
    }
    //初始化窗口参数
    if($('hiddendiv')==null)
    {
        var hiddendivbg = document.createElement("div");
        hiddendivbg.id = "hiddendivbg";
        hiddendivbg.innerHTML = "&nbsp;";
        hiddendivbg.style.width = pageWidth + "px";
        hiddendivbg.style.height = pageHeight + "px";
        document.body.insertBefore(hiddendivbg,null);
        
        var hiddendiv = document.createElement("div");
        hiddendiv.id = "hiddendiv";
        hiddendiv.innerHTML = "&nbsp;";
        hiddendiv.style.width = divWidth + "px";
        hiddendiv.style.height = divHeight + "px";
        hiddendiv.style.left = (windowLeft+(windowWidth-divWidth)/2)+"px";
        hiddendiv.style.top = (windowTop+(windowHeight-divHeight)/2)+"px";
        document.body.insertBefore(hiddendiv,null); 
    }
    else
    {
        $('hiddendivbg').style.width = pageWidth + "px";
        $('hiddendivbg').style.height = pageHeight + "px";
        $('hiddendivbg').style.display = "block";
        
        $('hiddendiv').style.width = divWidth + "px";
        $('hiddendiv').style.height = divHeight + "px";
        $('hiddendiv').style.left = (windowLeft+(windowWidth-divWidth)/2)+"px";
        $('hiddendiv').style.top = (windowTop+(windowHeight-divHeight)/2)+"px";
        $('hiddendiv').style.display = "block";
    }
    $('hiddendiv').innerHTML = "<div id='hiddendivtitle'><span><a href='javascript:hidediv();' title='关闭'>×</a></span>⊙&nbsp;"+title+"</div>";
    $('hiddendiv').innerHTML += "<div style='margin-top:6px'><iframe id='hiddendivframe' frameborder=0 width=100% height="+(divHeight-35)+"px /></div>";
    setTimeout("$('hiddendivframe').src='"+html+"';",500);
}

//显示浮动信息框 参数1:信息标题 参数2:信息内容 参数3:宽度 参数4:高度 参数5:在浮动窗口加入的html代码
function showdivx(title,content,htmlCode,width,height)
{
    //配置窗口的外观
    var divWidth = (width==null)?640:width;
    var divHeight = (height==null)?480:height;
    var pageWidth = getPageSize()[0];
    var pageHeight = getPageSize()[1];
    var windowWidth = getPageSize()[2];
    var windowHeight = getPageSize()[3];
    var windowLeft = document.documentElement.scrollLeft;
    if(windowLeft<=0) windowLeft = document.body.scrollLeft;
    var windowTop = document.documentElement.scrollTop;
    if(windowTop<=0) windowTop = document.body.scrollTop;
        
    //配置窗口的内容
    var html = "";
    if(typeof(content)=="object")
    {
        html = content.innerHTML;
        content.innerHTML = "";
    }
    else if(typeof(content)=="string")
    {
        html = content;
    }
    //初始化窗口参数
    if($('hiddendiv')==null)
    {
        var hiddendivbg = document.createElement("div");
        hiddendivbg.id = "hiddendivbg";
        hiddendivbg.innerHTML = "&nbsp;";
        hiddendivbg.style.width = pageWidth + "px";
        hiddendivbg.style.height = pageHeight + "px";
        document.body.insertBefore(hiddendivbg,null);
        
        var hiddendiv = document.createElement("div");
        hiddendiv.id = "hiddendiv";
        hiddendiv.innerHTML = "&nbsp;";
        hiddendiv.style.width = divWidth + "px";
        hiddendiv.style.height = divHeight + "px";
        hiddendiv.style.left = (windowLeft+(windowWidth-divWidth)/2)+"px";
        hiddendiv.style.top = (windowTop+(windowHeight-divHeight)/2)+"px";
        document.body.insertBefore(hiddendiv,null); 
    }
    else
    {
        $('hiddendivbg').style.width = pageWidth + "px";
        $('hiddendivbg').style.height = pageHeight + "px";
        $('hiddendivbg').style.display = "block";
        
        $('hiddendiv').style.width = divWidth + "px";
        $('hiddendiv').style.height = divHeight + "px";
        $('hiddendiv').style.left = (windowLeft+(windowWidth-divWidth)/2)+"px";
        $('hiddendiv').style.top = (windowTop+(windowHeight-divHeight)/2)+"px";
        $('hiddendiv').style.display = "block";
    }
    $('hiddendiv').innerHTML = "<div id='hiddendivtitle'><span><a href='javascript:hidediv();' title='关闭'>×</a></span>⊙&nbsp;"+title+"</div>";
    $('hiddendiv').innerHTML += "<div style='margin-top:6px'>"+htmlCode+"</div>";
    //隐藏下拉控件
    var sels = document.getElementsByTagName('select'); 
    for (var i = 0; i < sels.length; i++) 
        sels[i].style.visibility = 'hidden';     
    //$('hiddendivframe').src=html;
}



//隐藏浮动信息框
function hidediv()
{
    if($('hiddendiv')!=null)
    {
        $('hiddendiv').style.display = "none";
        $('hiddendivbg').style.display = "none";
    }
    var sels = document.getElementsByTagName('select'); 
    for (var i = 0; i < sels.length; i++) 
        sels[i].style.visibility = 'visible';
}
//关闭浮动信息框并刷新父页面
function closediv(method) {
    if(!window.parent)
    {
        opener=null;
        window.open("","_self");
        window.close();
    }
    window.parent.document.getElementById('hiddendiv').style.display = "none";
    window.parent.document.getElementById('hiddendivbg').style.display = "none";
    
    var sels = document.getElementsByTagName('select'); 
    for (var i = 0; i < sels.length; i++) 
        sels[i].style.visibility = 'visible'; 
    //使用GET方式刷新父页面,用于增加/删除记录
    if(method=="get") {
        var url=window.parent.document.location.href.replace(/[?&]time=0.\d+$/g,'');
        if(url.lastIndexOf("?")>=0)
            url+="&time="+Math.random();
        else
            url+="?time="+Math.random();
        window.parent.document.location.href=url;
    }
    //使用POST方式刷新父页面,用于编辑记录
    if(method=="post")
    {
         //window.parent.document.forms[0].submit();
         window.parent.document.location.href=window.parent.document.location.href;
    }
}
//关闭对话框
function closedialog(idlist)
{
    window.returnValue = idlist;
    window.close();
}
//打开新页面
function openwindow(url)
{
    var win=window.open(url);
}
//得到页面信息
function getPageSize()
{
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY)
    {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight)
    { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    }
    else
    { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight)
    { // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    }
    else if(document.body)
    { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight)
    {
        pageHeight = windowHeight;
    }
    else
    {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth)
    {
        pageWidth = windowWidth;
    }
    else
    {
        pageWidth = xScroll;
    }
    
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}
//注册事件
function regEvent(obj,type,fn)
{
    type=type.replace("on","");
	if (obj.attachEvent)
	{
		obj['e'+type+fn] = fn;
		obj[type+fn] = function() { obj['e'+type+fn](window.event); }
		obj.attachEvent('on'+type,obj[type+fn]);
	}
	else
	    obj.addEventListener(type,fn,false);
}
function clsEvent(obj,type,fn)
{
    type=type.replace("on","");
	if (obj.detachEvent)
	{
		obj.detachEvent('on'+type,obj[type+fn]);
		obj[type+fn] = null;
	}
	else
	    obj.removeEventListener(type,fn,false);
}
function doEvent(obj,type)
{
    type=type.replace("on","");
    if(Client.Engine.name=="ie")
	{
        obj.fireEvent('on'+type);		
	}
    else
    {
        var e = document.createEvent("Events");
        e.initEvent(type, true, false);   
        obj.dispatchEvent(e);
    }
}
//为指定标签添加或删除样式
function removeClassName(el,className) {
	el.className = el.className.replace(className,"").trim();
}
function addClassName(el,className) {
	removeClassName(el,className);
	el.className = (el.className + " " + className).trim();
}
//下拉框控制
function addOption(obj,text,key)
{
    var oOption = new Option(text,key);

    if(getOs()==3)
        obj.appendChild(oOption);
    else
        obj.options.add(oOption);
}
function clearOption(obj)
{
    while(obj.options.length!=0)
    {
        if(getOs()==3)
            obj.remove(0);
        else
            obj.options.remove(0);
    }
}
//客户端验证CheckBoxList
function  CheckBoxListValidator(sender, args)
{
    var flag = false;
    var inarr=$(sender.id.replace("CustomValidator","CheckBoxList")).getElementsByTagName("input");
    for (var i=0; i<inarr.length; i++)
    {
        if(inarr[i].type=="checkbox")
         {
            if(inarr[i].checked==true)    
             {
                 flag = true;
             }
          }
     }
     if (flag)
     {
        args.IsValid = true;
     }
     else
     {
        args.IsValid = false;
     }
}
//得到FckEditor实例
var oEditor;
function FCKeditor_OnComplete(editorInstance)
{ 
    oEditor = editorInstance;
}
//客户端验证FckEditor
function FckEditorValidator(source, arguments)
{
    var value = oEditor.GetXHTML(true);
    if(value=="")
    {
       arguments.IsValid = false;     
    }
    else 
    { 
        arguments.IsValid = true; 
    } 
}

function queren()
{
    return confirm("确定添加吗？");
}
function qrdelete()
{
    return confirm("确定删除吗？");
}

function qrFenPei()
{
    return confirm("确定分配吗？");
}

function qrhuishou()
{
    return confirm("确定回收吗？");
}

function qrzhuanhuan()
{
    return confirm("确定转换吗？");
}

function queren(value)
{
    return confirm("确定"+value+"吗？");
}
