﻿var d=document;
//////////////////////
var dm={};
dm.triml = function(str) { 
return str.replace(/^[ \t\n\r]+/g, "");
}
dm.trimr = function(str) {
return str.replace(/[ \t\n\r]+$/g, "");
}
dm.trim = function(str)//去除空格
{
    return dm.trimr(dm.triml(str));
}
dm.getint = function(str,min,rv)//或者大于MIN的整数,否者返回rv
{
    if(!str.match(/^-?d*$/) && parseInt(str)>parseInt(min))
        return parseInt(str,10);
    else
        return rv       ;
}
dm.swichhidden = function(s1,s2)//互换两者的隐藏状态
{
    if(document.getElementById(s1).style.display=="none")
    {
        document.getElementById(s2).style.display="none";
        document.getElementById(s1).style.display="";        
    }
    else
    {
        document.getElementById(s1).style.display="none";
        document.getElementById(s2).style.display="";
    }
}
///////////////////////////////

dm.getscroll_y = function()
{
    var rv; 
    if (typeof window.pageYOffset != 'undefined')
    { 
       rv = window.pageYOffset; 
    } 
    else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') { 
       rv = document.documentElement.scrollTop; 
    } 
    else if (typeof document.body != 'undefined') { 
       rv = document.body.scrollTop; 
    } 
    return rv;
}
document.write("<script type='text/javascript' src='js/prototype1602.js'></script>");
dm.gettrueleft= function(element)
{
    if(element.style.left)
        return parseInt(element.style.left,10);
    else
        return Position.cumulativeOffset(element)[0]-Position.realOffset(element)[0]+document.documentElement.scrollLeft;   
}
dm.gettruetop= function(element)
{
    if(element.style.top)
        return parseInt(element.style.top,10);
    else
        return Position.cumulativeOffset(element)[1]-Position.realOffset(element)[1]+document.documentElement.scrollTop;    
}
////////////////////////////////////////////////////////////////////////////////////////
window.onload=function()
{
    $A(document.getElementsByTagName("textarea")).each(function(item)
    {
        Event.observe(item, 'focus', function(){item.select();item.style.backgroundColor="#eef";}); 
        Event.observe(item, 'blur', function(){item.style.backgroundColor="";}); 
    }
    );
    $A(document.getElementsByTagName("input")).each(function(item)
    {
        if(item.type=="button" || item.type=="submit" || item.type=="reset" )
        {
            item.className="button";
            Event.observe(item, 'mouseover', function(){item.className="button1";});
            Event.observe(item, 'mouseout', function(){item.className="button";});
        }
        else if(item.type=="text" || item.type=="password")
        {
            Event.observe(item, 'focus', function(){item.select();item.style.backgroundColor="#eef";});
            Event.observe(item, 'blur', function(){item.style.backgroundColor="";});
        }
        else if(item.type=="checkbox")
        {
            item.style.borderWidth="0px";
        }
        if(item.type=="text")
        {
            if(item.onclick && item.onclick.toString().indexOf("addinput")!=-1)
            {
                item.style.backgroundImage="url('ico1/078.gif')";
                item.style.backgroundRepeat="no-repeat";
                item.style.backgroundPosition="right";
            }
        }
    }
    );
}
//////////文本数字选择框///////////
var selectinputint=null;
var isselectinputintxiaoshi=false;
function addinputint(s,cmd)
{
    s.select();
    selectinputint=s;
    isselectinputintxiaoshi=false;
    var arrstring="0,1,2,3,4,5,6,7,8,9,10,15,20,30,35";
    var innerhtml="";
    arrstring.split(",").each(function(item)
    {
        innerhtml+="<a href='#d' onclick='selectinputint.value="+item+";eval(\""+cmd+"\");'>"+item+"</a>&nbsp;";
    }        
    );
    if(!$("inputintdiv"))
    {
        var newdiv=document.createElement("div"); 
        newdiv.innerHTML=innerhtml;  
        newdiv.id="inputintdiv";
        newdiv.style.position="absolute";
        newdiv.style.left="0px";
        newdiv.style.top="0px";
        newdiv.style.backgroundColor="#ffffff";
        newdiv.style.border="solid 1px #000000";
        newdiv.style.display="none";
        Event.observe(newdiv, 'blur', function(){isselectinputintxiaoshi=true;setTimeout('if(isselectinputintxiaoshi)$("inputintdiv").style.display="none"',700);});
        Event.observe(newdiv, 'focus', function(){isselectinputintxiaoshi=false;});
        document.body.appendChild(newdiv);   
    }
    else
    {
        $("inputintdiv").innerHTML=innerhtml; 
    }
    Event.observe(s, 'blur', function(){isselectinputintxiaoshi=true;setTimeout('if(isselectinputintxiaoshi)$("inputintdiv").style.display="none"',700);});
    Event.observe(s, 'focus', function(){isselectinputintxiaoshi=false;});
    $("inputintdiv").style.left=(dm.gettrueleft(s)-100)+"px";
    $("inputintdiv").style.top=(dm.gettruetop(s)+20)+"px";
    $("inputintdiv").style.display="";
}
///////////////文本选择框//////////////////////
var selectinput=null;
var isselectinputxiaoshi=false;
var selectitem="";
function addinput(s,cmd,arr)
{
    s.select();
    selectinput=s;
    isselectinputxiaoshi=false;
    if(!$("inputdiv"))
    {
        var newdiv=document.createElement("div");         
        newdiv.id="inputdiv";
        newdiv.className="divgundong";
        newdiv.style.position="absolute";        
        newdiv.style.height="180px";        
        newdiv.style.left="0px";
        newdiv.style.top="0px";
        newdiv.style.backgroundColor="#ffffff";
        newdiv.style.border="solid 1px #000000";
        newdiv.style.display="none";
        newdiv.style.zIndex="10001";
        Event.observe(newdiv, 'blur', function(){isselectinputxiaoshi=true;setTimeout('if(isselectinputxiaoshi)$("inputdiv").style.display="none"',700);});
        Event.observe(newdiv, 'focus', function(){isselectinputxiaoshi=false;});
        document.body.appendChild(newdiv);   
    }
    var innerhtml="";
    arr.each(function(item)
    {
        selectitem=item;
        innerhtml+="<div style='padding-left:7px;padding-top:5px;padding-right:5px;' onmouseover=\"this.style.backgroundColor='#ddffdd'\" onmouseout=\"this.style.backgroundColor='#ffffff'\" onclick='selectitem=\""+item+"\";selectinput.value=\""+item+"\";eval(\""+cmd+"\");$(\"inputdiv\").style.display=\"none\";'><img src='images/ico1.gif'>&nbsp;<a href='#d'>"+item+"</a></div>";
    }
    );
    Event.observe(s, 'blur', function(){isselectinputxiaoshi=true;setTimeout('if(isselectinputxiaoshi)$("inputdiv").style.display="none"',700);});
    Event.observe(s, 'focus', function(){isselectinputxiaoshi=false;});
    $("inputdiv").innerHTML=innerhtml;  
    $("inputdiv").style.width=s.getDimensions().width+"px";
    if(dm.gettrueleft(s)+parseInt($("inputdiv").style.width)>document.body.offsetWidth-5)
    {
    $("inputdiv").style.left=(document.body.offsetWidth-parseInt($("inputdiv").style.width)-5)+"px";
    }
    else
    {
    $("inputdiv").style.left=dm.gettrueleft(s)+"px";
    }
    $("inputdiv").style.top=(dm.gettruetop(s)+20)+"px";
    $("inputdiv").style.display="";
}
function addinput1(s,cmd,arr)
{
    s.select();
    selectinput=s;
    isselectinputxiaoshi=false;
    if(!$("inputdiv"))
    {
        var newdiv=document.createElement("div");         
        newdiv.id="inputdiv";
        newdiv.className="divgundong";
        newdiv.style.position="absolute";
        newdiv.style.height="180px";        
        newdiv.style.left="0px";
        newdiv.style.top="0px";
        newdiv.style.backgroundColor="#ffffff";
        newdiv.style.border="solid 1px #000000";
        newdiv.style.display="none";
        newdiv.style.zIndex="10001";
        Event.observe(newdiv, 'blur', function(){isselectinputxiaoshi=true;setTimeout('if(isselectinputxiaoshi)$("inputdiv").style.display="none"',700);});
        Event.observe(newdiv, 'focus', function(){isselectinputxiaoshi=false;});
        document.body.appendChild(newdiv);   
    }
    var innerhtml="";
    arr.each(function(item)
    {        
        innerhtml+="<div style='padding-left:7px;padding-top:5px;padding-right:5px;' onmouseover=\"this.style.backgroundColor='#ddffdd'\" onmouseout=\"this.style.backgroundColor='#ffffff'\" onclick='selectitem=\""+item+"\";eval(\""+cmd+"\");$(\"inputdiv\").style.display=\"none\";'><img src='images/ico1.gif'>&nbsp;<a href='#d'>"+item+"</a></div>";
    }
    );
    Event.observe(s, 'blur', function(){isselectinputxiaoshi=true;setTimeout('if(isselectinputxiaoshi)$("inputdiv").style.display="none"',700);});
    Event.observe(s, 'focus', function(){isselectinputxiaoshi=false;});
    $("inputdiv").innerHTML=innerhtml;
    $("inputdiv").style.width="120px";
    if(dm.gettrueleft(s)+parseInt($("inputdiv").style.width)>document.body.offsetWidth-5)
    {
    $("inputdiv").style.left=(document.body.offsetWidth-parseInt($("inputdiv").style.width)-5)+"px";
    }
    else
    {
    $("inputdiv").style.left=dm.gettrueleft(s)+"px";
    }
    $("inputdiv").style.top=(dm.gettruetop(s)+20)+"px";
    $("inputdiv").style.display="";
}
/////////////
function adddiv(s,arr,url,cmd,target)
{
    if(!$("linkdiv"))
    {
        var newdiv=document.createElement("div");         
        newdiv.id="linkdiv";
        newdiv.style.position="absolute";     
        newdiv.style.left="0px";
        newdiv.style.top="0px";
        newdiv.style.backgroundColor="#ffffff";
        newdiv.style.border="solid 1px #000000";
        newdiv.style.display="none";
        Event.observe(newdiv, 'mouseout', function(){isselectinputxiaoshi=true;setTimeout('if(isselectinputxiaoshi)$("linkdiv").style.display="none"',300);});
        Event.observe(newdiv, 'mouseover', function(){isselectinputxiaoshi=false;});
        Event.observe(newdiv, 'focus', function(){isselectinputxiaoshi=false;});
        document.body.appendChild(newdiv);  
    }
    var innerhtml="";
    if(target=="" || !target)
        target="_self";
    for(var i=0;i<arr.length;i++)
    {
        innerhtml+="<div style='padding-left:7px;padding-top:5px;padding-right:5px;' onmouseover=\"this.style.backgroundColor='#ddffdd'\" onmouseout=\"this.style.backgroundColor='#ffffff'\" onclick='selectitem=\""+arr[i]+"\";eval(\""+cmd+"\");$(\"linkdiv\").style.display=\"none\";'><img src='images/ico1.gif'>&nbsp;<a href='"+url[i]+"' target='"+target+"'>"+arr[i]+"</a></div>";
    }
    Event.observe(s, 'mouseout', function(){isselectinputxiaoshi=true;setTimeout('if(isselectinputxiaoshi)$("linkdiv").style.display="none"',300);});
    Event.observe(s, 'mouseover', function(){isselectinputxiaoshi=false;});
    $("linkdiv").innerHTML=innerhtml;
    $("linkdiv").style.width="100px";
    if(dm.gettrueleft(s)+parseInt($("linkdiv").style.width)>document.body.offsetWidth-5)
    {
    $("linkdiv").style.left=(document.body.offsetWidth-parseInt($("linkdiv").style.width)-5)+"px";
    }
    else
    {
    $("linkdiv").style.left=dm.gettrueleft(s)+"px";
    }
    $("linkdiv").style.top=(dm.gettruetop(s)+20)+"px";
    $("linkdiv").style.display="";
}
////////////////////////////////////
window.onerror=function()
{
    return false;
}

////////////////////////////////////
function updiv(mingcheng,maxcount,maxsize,filetypes)
{
    var rv="<span><img src='ico1/147.gif'><a href='#d'>我要添加</a></span>";
    rv+="<span style='margin-left:-5.2em;' id='"+mingcheng+"span'><span><input type='file' name='"+mingcheng+"' size='1' style='filter:alpha(opacity:0);-moz-opacity:0; ' onchange='updivchange(this,\""+mingcheng+"\",\""+filetypes+"\","+maxcount+");'></span></span>"
    rv+="<span><small>(最大个数:" + maxcount + ",小于" + maxsize + "KB)</small></span>";  
    rv+="<div style='display:none;' id='"+mingcheng+"div'></div>";
    return rv;
}
function updivchange(s,mingcheng,filetypes,maxcount)
{
    var file=s.value;
    var filetype=file.substring(file.lastIndexOf(".")).toLowerCase();
    if(filetypes.indexOf(filetype)!=-1)
    {
        var iscunzai=false;
        var controls=document.forms[0][mingcheng];
        for(var i=0;i<controls.length-1;i++)
        {
            if(controls[i].value==file)
            {
                iscunzai=true;
                break;
            }
        }
        if(controls.length>maxcount)
        {
            alert("最多只能上传最多"+maxcount+"个文件");
        }
        else if(!iscunzai)
        {
            $(mingcheng+'div').style.display='';
            var newdiv=document.createElement('div');
            newdiv.style.border='solid 1px #eeeeff';
            newdiv.style.backgroundColor='#f3fff3';
            newdiv.innerHTML=file+"<img src='ico1/184.gif' onclick='updivremove(this,\""+mingcheng+"\",\""+file.replace(/\\/g,"\\\\")+"\");'>";
            $(mingcheng+'div').appendChild(newdiv);
            for(var i=0;i<$(mingcheng+'span').childNodes.length;i++)
            {
                $(mingcheng+'span').childNodes[i].style.display='none';
            }
            newdiv=document.createElement('span');
            newdiv.innerHTML="<input type='file' name='"+mingcheng+"' size='1' style='filter:alpha(opacity:0);-moz-opacity:0;' onchange='updivchange(this,\""+mingcheng+"\",\""+filetypes+"\","+maxcount+");'>";
            $(mingcheng+'span').appendChild(newdiv);
        }
        else
        {
            alert("该文件已经存在了");
        }
    }
    else
    {
        alert("只能上传"+filetypes+"的格式");
    }
}
function updivremove(s,mingcheng,file)
{
    var controls=document.forms[0][mingcheng];
    for(var i=0;i<controls.length;i++)
    {
        if(controls[i].value==file)
        {
            var control=controls[i];
            control.parentNode.parentNode.removeChild(control.parentNode);
        }
    }
    s.parentNode.parentNode.removeChild(s.parentNode);
}
///////////////////////////////////

function getcookieval(offset)
//获得Cookie解码后的值
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function setcookie(name, value)
//设定Cookie值
{
var expdate = new Date();
var argv = setcookie.arguments;
var argc = setcookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}
function delcookie(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = getcookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function getcookie(name)
//获得Cookie的原始值
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return getcookieval (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}