﻿// JScript 文件
/*
' *******************************************
'*     *********************************     *
'*    *                                 *    *
'*    *    乐清市火影企划有限公司       *    *
'*    *                                 *    *
'*    *    电话：0577-61750665          *    *
'*    *    传真：0577-61209588          *    *
'*    *    Q  Q：908677743              *    *
'*    *    网址：www.hiying.cn          *    *
'*    *    E-mail：hiying888@163.com    *    *
'*    *                                 *    *
'*     *********************************     *
' *******************************************
*/
function left(mainStr,lngLen) 
{ 
	if (lngLen>0) return mainStr.substring(0,lngLen)
	else return null
}

function right(mainStr,lngLen) 
{  
 	if (mainStr.length-lngLen>=0 && mainStr.length>=0 && mainStr.length-lngLen<=mainStr.length) 
 		return mainStr.substring(mainStr.length-lngLen,mainStr.length) 
 	else return null  
}

function mid(mainStr,starnum,endnum)
{ 
	if (mainStr.length>=0) return mainStr.substr(starnum,endnum) 
	else return null 
} 

//--------div+css begin-----------//
//div代码
document.write("<div id='divModal'></div>");
document.write("<DIV id='divModalDialog'>");
document.write("<div class='titleBar'>");
document.write("<div class='titleName' id='mytitle'></div>");
document.write("<div class='closeButton' title='关闭'><a href='javascript:closeModel();' style='color:#000;'>×</a></div>");
document.write("</div>");
document.write("<div class='mainBody'>");
document.write("<iframe id='myframe' src='about:blank' marginheight=0 marginwidth=0 width='100%' height='100%' frameborder=0></iframe>");
document.write("</div>");
document.write("</DIV>");

//css代码
document.write("<style>");
document.write("div.titleBar{background: #FFCC33;color:#000;margin: 0px auto;width: 100%;padding:5px;padding-bottom:1px;line-height:18px;border-bottom: #999999 solid 1px;}");
document.write("div.titleName{float:left; font-weight:bold;}");
document.write("div.closeButton{float: right; font-weight:bold;}");
document.write("div.mainBody{margin: auto;}");
document.write("#divModalDialog{border:solid 1px #999999;background:white;POSITION: absolute;left:0px;top:0px;DISPLAY: none;z-index:49;}");
document.write("#divModal{BACKGROUND-COLOR: white; FILTER: alpha(opacity=75); LEFT: 0px; POSITION:absolute; TOP: 0px;}");
document.write("</style>");

//js代码 
function showModel(w,h,url,title)   /*html页面直接调此函数 w-宽度，h-高度，url-链接，title-窗口标题*/
{
    divModalDialog.style.display = "block";
    divModalDialog.style.width=w;
    divModalDialog.style.height=h;
    document.all["myframe"].src=url;
    mytitle.innerHTML=title;
    resizeModal();
    window.onresize = resizeModal;
}

function closeModel()
{
    divModal.style.width = "0px";
    divModal.style.height = "0px";
    divModalDialog.style.display = "none";
    window.onresize = null;
}

function resizeModal()
{
    divModal.style.width = document.body.scrollWidth;
    divModal.style.height = document.body.scrollHeight;
    //divModalDialog.style.left = ((document.documentElement.clientWidth - divModalDialog.offsetWidth) / 2);
	divModalDialog.style.left = ((document.body.clientWidth - divModalDialog.offsetWidth) / 2);
    //divModalDialog.style.top = (document.documentElement.scrollTop+(document.documentElement.clientHeight - divModalDialog.offsetHeight) / 2);
	divModalDialog.style.top = (document.body.scrollTop+(document.body.clientHeight - divModalDialog.offsetHeight) / 2);
    //divModalDialog.style.top = ((document.body.offsetHeight - divModalDialog.offsetHeight) / 2);
        
}
//--------div+css end-----------//

//--------自定义下拉框(开始)--------//
//div代码
document.write('<Div id="divDown">');
document.write('<DIV>');
document.write('<div id="subDown"></div>');
document.write('</DIV>');
document.write('<div id="closeDown" onclick="closeDown();">关闭</div>');
document.write('</Div>');

//css代码
document.write('<style>');
document.write('#divDown{font-size:12px;background-color:#eee;border:solid 1px #8AC930;display:none;position:absolute;padding:3px;}');
document.write('.subDown{cursor:default;padding:3px;padding-right:10px;}');
document.write('#closeDown{cursor:hand;text-align:right;color:blue;margin-top:10px;}');
document.write('</style>');

//js代码
var myid,myhideid;
//id-控件id；str-字符串，以","、"|"(前写入hideId，后写入id)，隔开；keyname-字符查找；hideId-隐藏控件id
//显示下拉框
function showDown(id,str,keyname,hideId)	
{
	if (keyname!=null && keyname!="") keyname=keyname.toUpperCase();
	str=str.toUpperCase();
	var temp=document.getElementById(id);
	var temphide=document.getElementById(hideId);
	var tempstr=str.split('|');
	myid=temp;
	myhideid=temphide;
	
	divDown.style.top=findOffsetTop(temp)+temp.offsetHeight+8;
	divDown.style.left=findOffsetLeft(temp);
	
	subDown.innerHTML="";
	switch(tempstr.length)	//数组判断
	{
		case 2:	
			var tempstr1=tempstr[0].split(',');
			var tempstr2=tempstr[1].split(',');
			var indexkey,tempstr3="",tempstr4="";
			if(keyname!=null && keyname!="")	//字符查找
			{
				for(var i=0;i<tempstr2.length;i++)
				{
					indexkey=tempstr1[i].indexOf(keyname);
					if(indexkey>=0)
					{
						tempstr3+=tempstr2[i]+",";
						tempstr4+=tempstr1[i]+",";
					}
				}
				if(tempstr3!="")
				{
					tempstr3=left(tempstr3,tempstr3.length-1);
					tempstr4=left(tempstr4,tempstr4.length-1);
					tempstr3=tempstr3.split(',');
					tempstr4=tempstr4.split(',');
				}
			}
			else
			{
				if(keyname=="")		//字符查找时，为空则不显示任何文字
				{
					tempstr3="";
					tempstr4="";
				}
				else
				{
					tempstr3=tempstr2;
					tempstr4=tempstr1;
				}
			}
			
			for(var i=0;i<tempstr3.length;i++)
			{
				subDown.innerHTML+='<div class="subDown" onclick="onselecttext(this.text,this.innerText);" text='+tempstr4[i]+' onmouseover="oMouse(this)" onmouseout="oOut(this)">'+tempstr3[i]+'</div>';
			}
		break;
		case 3:	
			var tempstr1=tempstr[0].split(',');
			var tempstr2=tempstr[1].split(',');
			var tempstr3=tempstr[2].split(',');
			var indexkey,tempstr4="",tempstr5="",tempstr6="";
			if(keyname!=null && keyname!="")	//字符查找
			{
				for(var i=0;i<tempstr3.length;i++)
				{
					indexkey=tempstr3[i].indexOf(keyname);
					if(indexkey>=0)
					{
						tempstr4+=tempstr1[i]+",";
						tempstr5+=tempstr2[i]+",";
						tempstr6+=tempstr3[i]+",";
					}
				}
				if(tempstr4!="")
				{
					tempstr4=left(tempstr4,tempstr4.length-1);
					tempstr5=left(tempstr5,tempstr5.length-1);
					tempstr6=left(tempstr6,tempstr6.length-1);
					tempstr4=tempstr4.split(',');
					tempstr5=tempstr5.split(',');
					tempstr6=tempstr6.split(',');
				}
			}
			else
			{
				if(keyname=="")		//字符查找时，为空则不显示任何文字
				{
					tempstr4="";
					tempstr5="";
					tempstr6="";
				}
				else
				{
					tempstr4=tempstr2;
					tempstr5=tempstr1;
					tempstr6=tempstr3;
				}
			}
			
			for(var i=0;i<tempstr4.length;i++)
			{
				subDown.innerHTML+='<div class="subDown" onclick="onselecttext(this.text,this.innerText);" text='+tempstr4[i]+' onmouseover="oMouse(this)" onmouseout="oOut(this)">'+tempstr5[i]+'</div>';
			}
		break;
		default:
			tempstr=tempstr[0].split(',');
			var indexkey,tempstr1="";
			if(keyname!=null && keyname!="")	//字符查找
			{
				for(var i=0;i<tempstr.length;i++)
				{
					indexkey=tempstr[i].indexOf(keyname);
					if(indexkey>=0)
					{
						tempstr1+=tempstr[i]+",";
					}
				}
				if(tempstr1!="")
				{
					tempstr1=left(tempstr1,tempstr1.length-1);
					tempstr1=tempstr1.split(',');
				}
			}
			else
			{
				if(keyname=="") tempstr1="";	//字符查找时，为空则不显示任何文字
				else tempstr1=tempstr;
			}
			
			for(var i=0;i<tempstr1.length;i++)
			{
				subDown.innerHTML+='<div class="subDown" onclick="onselecttext(this.text,this.innerText);" text="" onmouseover="oMouse(this)" onmouseout="oOut(this)">'+tempstr1[i]+'</div>';
			}
		break;
	}
	
	divDown.style.display="block";
}
//关闭下拉框
function closeDown()
{
	subDown.innerHTML="";
	divDown.style.display="none";
}
//选择下拉框的文字
function onselecttext(text,value)
{
	if(myhideid!=null) myhideid.value=text;
	myid.value=value;
	myid.focus();
	closeDown();
}
//控件顶部距离
function findOffsetTop(o)
{
	var t=0;
	if(o.offsetParent)
	{
		while(o.offsetParent)
		{
			t+=o.offsetTop;
			o=o.offsetParent;
		}
	}
	return t;
}
//控件左边距离
function findOffsetLeft(o)
{
	var t=0;
	if(o.offsetParent)
	{
		while(o.offsetParent)
		{
			t+=o.offsetLeft;
			o=o.offsetParent;
		}
	}
	return t;
}

//鼠标经过/离开时的背景颜色的变化
var currentbgcolor,currentcolor;

function oMouse(t)
{
    currentbgcolor=t.style.backgroundColor;
    currentcolor=t.style.color;
    t.style.backgroundColor="#8AC930";
    t.style.color="#fff";
}

function oOut(t)
{
    t.style.backgroundColor=currentbgcolor;
    t.style.color=currentcolor;
}
//--------自定义下拉框(结束)--------//
