// JavaScript Document

//使表格行变色
trMoveColor="#DFDFDF";
//检查为空-》检查单引号
function checkNullQuote(obj,message){
        if(obj.value.length==0){
			alert(message+"不能为空!");
			obj.focus();
			return true;
		}
		var reg=/\'/g;
		var isOddQuote=reg.exec(trimAll(obj.value)); 
		if(isOddQuote){
			alert(message+'中有单引号!');
			obj.focus();
			return true;
		}
		return false;
}
//去掉空格
function trim(str)
{		
       var i = 0;
        var len = str.length;
        if ( str == "" ) return( str );
        j = len -1;
        flagbegin = true;
        flagend = true;
        while ( flagbegin == true && i< len)
        {
           if ( str.charAt(i) == " " )
                {
                  i=i+1;
                  flagbegin=true;
                }
                else
                {
                        flagbegin=false;
                }
        }

        while  (flagend== true && j>=0)
        {
            if (str.charAt(j)==" ")
                {
                        j=j-1;
                        flagend=true;
                }
                else
                {
                        flagend=false;
                }
        }

        if ( i > j ) return ("")

        trimstr = str.substring(i,j+1);
        return trimstr;
}



// 超链接
function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "mainFrame") {
     anchor.target = "mainFrame"; 
   }else if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "rightMain") {
	 anchor.target = "rightMain"; 
   }	   
 } 
} 
window.onload = externalLinks;


function showMDialog(url,width,height)
{
	res = showModalDialog(url, window, 'Dialogwidth:' + width + 'px;Dialogheight:' + height + 'px;status:no;help:no;resizable:yes');
	if(res) {
		Frame.submit();
		alert('');
		return true;
	}
}
function showMDialogRe(url,width,height)
{
	res = showModalDialog(url, window, 'Dialogwidth:' + width + 'px;Dialogheight:' + height + 'px;status:no;help:no;resizable:yes');
	return res;
}

function showMDialogFrame(url,width,height)
{
	showModalDialog(url, window, 'Dialogwidth:' + width + 'px;Dialogheight:' + height + 'px;status:no;help:no;resizable:yes');
}
				 
function closeWin() {
	if(window.event.keyCode==27) {
		window.close();
		return;
	}
}

//-------------------------多项选择select函数开始----------------------------------
//多项选择select函数1：选择函数
function selectMore(from,to,isAll)
{
/*
from:源选择框的name值
to:目标选择框的name值
isAll:是否全部选择
*/
	fromList = eval('document.forms[0].' + from);
	toList = eval('document.forms[0].' + to);
	if (isAll)
	{
		fromListLength=fromList.options.length

		for(i=0;i<fromListLength;i++)
		{
			current=fromList.options[0];
			txt=current.text;
			val=current.value;
			toList.options[toList.length]=new Option(txt,val);
			fromList.options[0]=null;
		}
	}
	else
	{	//	alert(fromList.options.length);
		for (i=0;i<fromList.options.length;i++)
		{
			current=fromList.options[i];
			if (current.selected)
			{
				txt=current.text;
				val=current.value;
				toList.options[toList.length]=new Option(txt,val);
				fromList.options[i]=null;
				i--;
			}
		}
	}
}

//多项选择select函数1：选择函数，用于框架中
function selectMoreFrame(from,to,isAll,framename)
{
/*
from:源选择框的name值
to:目标选择框的name值
isAll:是否全部选择
*/

	if(framename==''){
	   	fromList = eval('parent.document.forms[0].' + from);
	  	toList = eval('document.forms[0].' + to);
	}else{
	  	fromList = eval(framename+'.document.forms[0].' + from);
	  	toList = eval('document.forms[0].' + to);
	}

	if (isAll)
	{
		fromListLength=fromList.options.length

		for(i=0;i<fromListLength;i++)
		{
			current=fromList.options[0];
			txt=current.text;
			val=current.value;
			toList.options[toList.length]=new Option(txt,val);
			fromList.options[0]=null;
		}
	}
	else
	{	//	alert(fromList.options.length);
		for (i=0;i<fromList.options.length;i++)
		{
			current=fromList.options[i];
			if (current.selected)
			{
				txt=current.text;
				val=current.value;
				toList.options[toList.length]=new Option(txt,val);
				fromList.options[i]=null;
				i--;
			}
		}
	}
}




//-------------------------多项选择select函数开始----------------------------------
//多项选择select函数1：选择函数
function selectMore1(from,to,isAll)
{
/*
from:源选择框的name值
to:目标选择框的name值
isAll:是否全部选择
*/

	fromList = eval('document.forms[1].' + from);
	toList = eval('document.forms[1].' + to);
	if (isAll)
	{
		fromListLength=fromList.options.length

		for(i=0;i<fromListLength;i++)
		{
			current=fromList.options[0];
			txt=current.text;
			val=current.value;
			toList.options[toList.length]=new Option(txt,val);
			fromList.options[0]=null;
		}
	}
	else
	{	//	alert(fromList.options.length);
		for (i=0;i<fromList.options.length;i++)
		{
			current=fromList.options[i];
			if (current.selected)
			{
				txt=current.text;
				val=current.value;
				toList.options[toList.length]=new Option(txt,val);
				fromList.options[i]=null;
				i--;
			}
		}
	}
}

//多项选择select函数2：选定函数
//当用户按下提交按钮时，对列出选择的select对象执行全选工作
//让递交至的后台程序能取得相关数据
function selectMore2(to)
{
  toList = eval('document.forms[1].' + to);
  for (i=0;i<toList.length;i++)
  {
     toList.options[i].selected = true;
  }
}

function selectAllx(toList)
{
  for (i=0;i<toList.length;i++)
  {
     toList.options[i].selected = true;
  }
}


//(得到已添加)那个多选框中的所有值
function selectAll(to)
{
	var returnValue = "";

    toList = eval('window.document.forms[1].' + to);
    for (i=0;i<toList.length;i++)
    {
        if (i==toList.length-1)
            returnValue += toList.options[i].value;
        else
            returnValue += toList.options[i].value+",";
    }
	return returnValue;
}

//(得到已添加)那个多选框中的所有显示的值
function selectAllText(to)
{
	var returnValue = "";

    toList = eval('window.document.forms[1].' + to);
    for (i=0;i<toList.length;i++)
    {
        if (i==toList.length-1)
            returnValue += toList.options[i].text;
        else
            returnValue += toList.options[i].text+",";
    }
	return returnValue;
}
//-------------------------多项选择select函数结束------------------

/*********模式对话框************/
function showMDialog(url,width,height)
{
	res = showModalDialog(url, window, 'Dialogwidth:' + width + 'px;Dialogheight:' + height + 'px;status:no;help:no;resizable:yes');
	if(res){
		Frame.submit();
		return true;
	}
}

function showMDialogFrame(url,width,height)
{
	showModalDialog(url, window, 'Dialogwidth:' + width + 'px;Dialogheight:' + height + 'px;status:yes;help:no;resizable:yes');
}

function showMenuMDialogFrame(url,width,height)
{
	showModalDialog(url, window, 'Dialogwidth:' + width + 'px;Dialogheight:' + height + 'px;status:no;help:no;resizable:yes');
}

function showMDialogFrameLess(url,width,height)
{
	showModelessDialog(url, window, 'Dialogwidth:' + width + 'px;Dialogheight:' + height + 'px;status:no;help:no;resizable:yes');
}


/************判断是否为汉字*************/
function isChineseBoolean(s){
	if (s.charCodeAt(0)>0x80)
	{
		return false;
	}
	return true;
}

function chkMail(val) {
	var emailPat=/^(.+)@(.+)$/;
	var matchArray=val.value.match(emailPat);
	if (matchArray==null) {
	 return false;
    }
	return true;
}

function trimAll(data)
{
  var reg=/^ +| +$/g;
  var str=data.replace(reg,"");
  return str;
}

//判断是否为空：
function chkNull(data,msg)
{
	if (trimAll(data.value)=='')
	{
		alert(msg);
		//data.select();
		data.focus();
		return false;
	}
	return true;
}

//动态区域变化
function showProvince(listobj)
{ 

	for(var i=0;i<bid.length;i++)
	{

			var opt = new Option(bname[i],bid[i]) ;
			listobj.options[listobj.options.length] = opt ;
			opt = null ;
	}
    listobj.options[1] =null;
	/*for(var i=0;i<3;i++)
	{

			var opt = new Option(pname[i],pid[i]) ;
			listobj.options[listobj.options.length] = opt ;
			opt = null ;
	}*/
}
function showCity(ppid,listobj)
{
	opt = null ;
	for(var i=0;i<pid.length;i++)
	{
		
		if(pid[i] == ppid)
		{
			var opt = new Option(pname[i],pcid[i]) ;
			listobj.options[listobj.options.length] = opt ;
			opt = null ;
		}
	}
}

function showTown(ppid,listobj)
{

	for(var i=0;i<apid.length;i++)
	{
		if(apid[i] == ppid)
		{
			var opt = new Option(aname[i],acid[i]) ;
			listobj.options[listobj.options.length] = opt ;
			opt = null ;
		}
	}

}

function clearOption(obj)
{
	while(obj.options.length>1)
	{
		obj.options[obj.options.length-1] = null ;
	}
}
function selectedProvince(obj,bid)
{
	for(var i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].value == bid)
		{
			obj.options[i].selected = true ;
			break ;
		}
	}
}
function selectedCity22(obj,pid)
{
	for(var i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].value == pid)
		{
			obj.options[i].selected = true ;
			break ;
		}
	}
}
function selectedCity(listobj,pid,cid)
{
	showCity(pid,listobj) ;
	obj = listobj ;
	for(var i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].value == cid)
		{
			obj.options[i].selected = true ;
			break ;
		}
	}
}
 function get_time()
  {
    var date=new Date();
    var year="",month="",day="",week="",hour="",minute="",second="";
    year=date.getYear();
    month=add_zero(date.getMonth()+1);
    day=add_zero(date.getDate());
    week=date.getDay();
    switch (date.getDay()) {
    case 0:val="星期天";break
    case 1:val="星期一";break
    case 2:val="星期二";break
    case 3:val="星期三";break
    case 4:val="星期四";break
    case 5:val="星期五";break
    case 6:val="星期六";break
      }
    hour=add_zero(date.getHours());
    minute=add_zero(date.getMinutes());
    second=add_zero(date.getSeconds());
	if(timetable)
   		timetable.innerText=" "+year+"年"+month+"月"+day+"日 "+val+" "+hour+":"+minute+":"+second;
  }

  function add_zero(temp)
  {
    if(temp<10) return "0"+temp;
    else return temp;
  }
setInterval("get_time()",1000);

