//库名:stdlib.js
//说明:javascript常用函数库,运行调试版本时,请把DEBUG变量的值改为true,发布程序时,
//请把DEBUG变量的值该为false
//最新更新日期：am 8:58,11.5.1999

//库中现有函数:
//  check_empty,check_email,check_url, SSgoselected,newwindow,home,goHist


//变量定义


DEBUG=false;



//函数定义

/***************************************************************/


//  函数名:check_empty
//  功能:检查文本是否为空
//  假定条件:无
//  入口:
//    参数一:  
//      <1>参数名:text
//      <2>参数类型:string
//      <3>参数意义:要进行判空的字符串
//  出口:若text为空,则返回false,否则,返回true
//  产生影响:无

function check_empty(text) {
         return (text.length > 0); // returns false if empty
        }
/***************************************************************/	



//  函数名:check_email
//  功能:检查email地址是否合法
//  假定条件:无
//  入口:
//    参数一:  
//      <1>参数名:address
//      <2>参数类型:string
//      <3>参数意义:要进行合法性检查的email地址
//  出口:若address不合法,则返回false,否则,返回true
//  产生影响:无

function check_email(address) {
	  if ((address == "")
	    || (address.indexOf ('@') == -1)
	    || (address.indexOf ('.') == -1))
	      return false;
	  return true;
        }

/***************************************************************/


//  函数名:check_url
//  功能:检查url地址是否合法
//  假定条件:无
//  入口:
//    参数一:  
//      <1>参数名:address
//      <2>参数类型:string
//      <3>参数意义:要进行合法性检查的url地址
//  出口:若address不合法,则返回false,否则,返回true
//  产生影响:无
	
function check_url(address) {
	  if ((address == "")
	    || (address.indexOf ('http:\/\/') == -1)
	    || (address.indexOf ('.') == -1))
	      return false;
	  return true;
	}

/***************************************************************/


//  函数名:SSgoselected
//  功能:根据下拉式选择框中选中的选项在某个窗口中调入页面
//  假定条件:下拉式选择框中的各项值中放有该项被选中时发生链接的url地址
//  入口:
//    参数一:
//      <1>参数名:listname
//      <2>参数类型:string
//      <3>参数意义:进行操作的下拉式选择框名称,要求连表单名提供
//    参数二:  
//      <1>参数名:target
//      <2>参数类型:string
//      <3>参数意义:打开页面所在的窗口的名称
//  出口:无
//  产生影响:无

/***************************************************************/


function SSgoselected(listname,target){
         //trim left blank and right blank of listname
         while (listname.charAt(0)==" ") listname=listname.substr(1,listname.length-1);
         while (listname.charAt(listname.length-1)==" ") listname=listname.substr(0,listname.length-1);
         

         //check listname
         if (listname==""||listname==null) {
         	if (DEBUG) alert('error in SSgoselected of stdlib.js:listname can not be blank or null');
         	return -1;}

         // make listname uniform
          if (listname.indexOf('document.')==-1) listname='document.'+listname;
          
        //check uniform listname
         if (eval(listname)==null) {
         	if (DEBUG) alert('error in SSgoselected of stdlib.js:invalid listname reference');
         	return -1;}

         //check target
         if (target==null) target='_self';

         selindex=eval(listname+'.selectedIndex');
         domain=eval(listname+'.options['+selindex+'].value');

          //check selected option's domain url address
         if (!check_url(domain)){
         	if (DEBUG) alert('error in SSgoselected of stdlib.js:the '+selindex+' option value is not a valid domain url address ');
         	return -1;}

	 window.open(domain,target);
	}

/***************************************************************/


//  函数名:newwindow
//  功能:在指定窗口中打开一个页面
//  假定条件:无
//  入口:
//    参数一:
//      <1>参数名:domain
//      <2>参数类型:string
//      <3>参数意义:要打开的页面的url地址
//    参数二:
//      <1>参数名:width
//      <2>参数类型:int
//      <3>参数意义:打开窗口的宽度(以象素点计算),缺省为600
//    参数三:
//      <1>参数名:height
//      <2>参数类型:int
//      <3>参数意义:打开窗口的高度(以象素点计算),缺省为400
//  出口:无
//  产生影响:无

function newwindow(domain,width,height){
	    //width and height valid check
          if (DEBUG&&(width<=0||height<=0))  
             alert('error in openwindow of stdlib.js:width or height can not be negative or zero');

           //check domain url address 
          if (DEBUG&&(!check_url(domain))) alert('error in openwindow of stdlib.js:domain url address is invalid');
          if (width==null||height==null)
              window.open(domain,'_blank','resizable')
          else
              window.open(domain,'_blank','resizable,width='+width+',height='+height);
        }

/***************************************************************/


//  函数名:home
//  功能:返回主页
//  假定条件:无
//  入口:无
//  出口:无
//  产生影响:无

function home(){
          domain = "http:\/\/" + document.location.hostname;
           //check domain url address 
          if (DEBUG&&(!check_url(domain))) alert('error in openwindow of stdlib.js:domain url address is invalid');
          window.open(domain,'_top');
        }

/***************************************************************/


//  函数名:goHist
//  功能:翻页
//  假定条件:无
//  入口:
//    参数一:  
//      <1>参数名:n
//      <2>参数类型:int
//      <3>参数意义:当n>0,向前翻n页;当n<0,向后翻n页
//  出口:无
//  产生影响:无

function goHist(n) {
          history.go(n);     
	}

