/*******************************************************
** 
** FIle name: default.js 
**
** These scripts are used for test only, not for application.
**
** Copyright (c) 2000 - 2003 Guangzhou China
**                    Sharper Wang  <developer@croview.org>
**
** Modified: 2003/09/03 Sharper Wang
**
********************************************************/



/******************************************************
* 鼠标移动函数
******************************************************/
function mOvr(src,clrOver){ 
	if (!src.contains(event.fromElement)) { 
		src.style.cursor = 'hand'; 
		src.bgColor = clrOver; 
	}//if
}//mOver

function mOut(src,clrOut)  { 
	if (!src.contains(event.toElement)) { 
		src.style.cursor = 'default'; 
		src.bgColor = clrOut; 
	}//if
}//mOut


function mClk(src,puserid) { 
		window.location.href=src+ puserid;
	 }




/******************************************************
* Email合法性判断函数
******************************************************/
function isEmail(str) {
  // are regular expressions supported?
	if(str.length>50) return false;
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\.\.)|(@\.)|(^\.)");
	var r2 = new RegExp("^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$");
	return (!r1.test(str) && r2.test(str));
}



/******************************************************
* 数字合法性判断函数
******************************************************/
function isNumber(str) {
	var ValidChars = "0123456789.-";
	var err=0;
	if(str.length>20 || str.length<1) return false;
	
	if ((str.charAt(0)=='0'&&str.charAt(1)!='.')||str.charAt(0)=='.'||ValidChars.indexOf(str.charAt(0)) == -1)
		return false;
	
	for (var i=1; i<str.length; i++) {
		if (ValidChars.indexOf(str.charAt(i)) == -1)
			return false;
		if (str.charAt(i)=='-')
			return false;
		if (str.charAt(i)=='.')
			if(++err>=2) return false;
	} 
	return true;
}


/******************************************************
* 电话号码合法性判断函数
******************************************************/
function isPhone(str) {
	var valid = 1;
	var ValidChars = "0123456789()-+ ";
	if(str.length>20) valid=0;
	for (var i =0; valid!=0&&i < str.length; i++) {
		if (ValidChars.indexOf(str.charAt(i)) == -1) {
			valid = 0;
		} 
	} 
	return valid;
}


/******************************************************
* Cookie设置函数
******************************************************/
function setCookie(name, value, expires, path, domain, secure) {
    var caution = false
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "")
	if (!caution || (name + "=" + escape(value)).length <= 4000)
		document.cookie = curCookie
	else
		if (confirm("Cookie exceeds 4KB and will be cut!"))
			document.cookie = curCookie

}


/******************************************************
* Cookie取值函数
******************************************************/
function getCookie(name) {
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1)
		return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}


/******************************************************
* Cookie删除函数
******************************************************/
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}





/******************************************************
* 检测是否是EMail地址的函数，允许多个地址以';'号分割。
******************************************************/
function checkEmails(email)
{
	if (email.length <= 0) return false;
	var arr_email = email.split(";");
	var i;
	for (i in arr_email)
		if (arr_email[i].length > 0)
			if (chkemail(arr_email[i]) > 0 ) return false;
	return true;
}





/******************************************************
* 返回上一页面，或者关闭窗口的函数
******************************************************/
function close_back()
{
	if (history.length > 0)
		history.back();
	else
		window.close();
}






/******************************************************
* Trim(String src)函数
******************************************************/
function Trim(src){
    for (var i=0; i<src.length; i++) {
        if (src.indexOf(" ")==0){src=src.substring(1,src.length);}
        else {break;}
    }
    for (var j=src.length; j>0; j--) {
        if (src.lastIndexOf(" ")==src.length-1){src=src.substring(0,(src.length-1));}
        else {break;}
    }
    
    return src;
}




/******************************************************
* getCurrentDate()函数
******************************************************/
function getCurrentDate(){
    var now = new Date();
    var yy = now.getYear();
    var mm = now.getMonth()+1;
	var dd = now.getDate();
	if (mm<10){mm="0"+mm;}
	if (dd<10){dd="0"+dd;}
    return yy + "-" + mm + "-" + dd;
}

/******************************************************
* getDateAfterDays(days)函数
******************************************************/
function getDateAfterDays(days){
    var today = new Date();
    var todayInMS = today.getTime();
    var ndayInMS = todayInMS + (days * 24 * 60 * 60 * 1000)
    
    var now = new Date(ndayInMS);
    var yy = now.getYear();
    var mm = now.getMonth()+1;
	var dd = now.getDate();
	if (mm<10){mm="0"+mm;}
	if (dd<10){dd="0"+dd;}
    return yy + "-" + mm + "-" + dd;
}


/******************************************************
* getCurrentDateTime()函数
******************************************************/
function getCurrentDateTime(){
    var now = new Date();
    var yy = now.getYear();
    var mm = now.getMonth()+1;
	var dd = now.getDate();
	var hour = now.getHours();
	var minute = now.getMinutes();
	var second = now.getSeconds();
	if (mm<10){mm="0"+mm;}
	if (dd<10){dd="0"+dd;}
	if (hour<10){hour="0"+hour;}
	if (minute<10){minute="0"+minute;}
	if (second<10){second="0"+second;}
    return yy + "-" + mm + "-" + dd + " "+ hour + ":" + minute + ":" + second ;
}




/******************************************************
* 校验日期的函数(格式1900-1-1)  source 校验的字符窜 
******************************************************/
function checkDate(source) { 
    var str = source; 
    if (str.length == 0) return false; 
    
    var arList = str.split("-") 
    if (arList.length != 3){ return false; } 
    
    var iYear = parseInt(arList[0],10); 
    var iMonth = parseInt(arList[1],10); 
    var iDay = parseInt(arList[2],10); 
    
    if(isNaN(iYear) || isNaN(iMonth) || isNaN(iDay)) {return false;}     
    if (iYear<1900 || iYear>2099){ return false; } 
    if (iMonth>12 || iMonth<1){ return false; } 
    if ((iMonth==1 || iMonth==3 || iMonth==5 || iMonth==7 || iMonth==8 || iMonth==10 || iMonth==12) && (iDay>31 || iDay<1)){ return false; } 
    if ((iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11) && (iDay>30 || iDay<1)){ return false; } 
    
    if (iMonth==2){ 
        if (LeapYear(iYear)){ 
            if (iDay>29 || iDay<1){ return false; } 
        }
        else{ 
            if (iDay>28 || iDay<1){ return false; } 
        } 
    } 
    return true; 
} 

//判断是否闰年 
//参数 intYear 代表年份的值 
//return true: 是闰年 false: 不是闰年 
function LeapYear(intYear) { 
    if (intYear % 100 == 0) { 
        if (intYear % 400 == 0) { return true; } 
    } 
    else { 
        if ((intYear % 4) == 0) { return true; } 
    } 
    return false; 
} 







/******************************************************
* 窗口打开函数
******************************************************/
function openWindow(uUrl,WindowName,uwidth,uheight,Scroll) {

        if (Scroll == "" )
           Scroll ='no'
        if (document.all)
		var xMax = screen.width, yMax = screen.height;
	else
		if (document.layers)
			var xMax = window.outerWidth, yMax = window.outerHeight;
		else
			var xMax = 800, yMax=600;

        var xOffset = (xMax - uwidth)/2, yOffset = (yMax - uheight)/2;   
        
	var features =
	'screenX=' + xOffset +
	',screenY=' + yOffset +
	',top=' + yOffset +
	',left=' + xOffset +
	',width=' + uwidth +
	',height=' + uheight +
	',directories=no'  +
	',location=no'  +
	',menubar=no' +
	',scrollbars='  + Scroll +
	',status=no' +
	',toolbar=no' +
	',Resizable=no';
	
	var newwindow2 = window.open (uUrl, WindowName, features);
        return false;
}



/******************************************************
* 可缩放窗口打开函数
******************************************************/
function openResizableWindow(uUrl,WindowName,uwidth,uheight,Scroll) {

        if (Scroll == "" )
           Scroll ='no'
        if (document.all)
		var xMax = screen.width, yMax = screen.height;
	else
		if (document.layers)
			var xMax = window.outerWidth, yMax = window.outerHeight;
		else
			var xMax = 800, yMax=600;

        var xOffset = (xMax - uwidth)/2, yOffset = (yMax - uheight)/2;   
        
	var features =
	'screenX=' + xOffset +
	',screenY=' + yOffset +
	',top=' + yOffset +
	',left=' + xOffset +
	',width=' + uwidth +
	',height=' + uheight +
	',directories=no'  +
	',location=no'  +
	',menubar=no' +
	',scrollbars='  + Scroll +
	',status=no' +
	',toolbar=no' +
	',Resizable=yes';
	
	var newwindow2 = window.open (uUrl, WindowName, features);
        return false;
}



/******************************************************
* 窗口打开函数（鼠标位置）
******************************************************/
function openFollowedWindow(uUrl,WindowName,uwidth,uheight,Scroll) {

        if (Scroll == "" )
           Scroll ='no'
        if (document.all)

    	mouseX = event.screenX;
    	mouseY = event.screenY;	
        
	var features =
	'screenX=' + mouseX +
	',screenY=' + mouseY +
	',left=' + mouseX +
	',top=' + mouseY +
	',width=' + uwidth +
	',height=' + uheight +
	',directories=no'  +
	',location=no'  +
	',menubar=no' +
	',scrollbars='  + Scroll +
	',status=no' +
	',toolbar=no' +
	',Resizable=no';
	
	var newwindow2 = window.open (uUrl, WindowName, features);
        return false;
}


/******************************************************
* 窗口打开函数，可调整大小的窗口
******************************************************/
function openResizableWindow(uUrl,WindowName,uwidth,uheight,Scroll) {

        if (Scroll == "" )
           Scroll ='no'
        if (document.all)
		var xMax = screen.width, yMax = screen.height;
	else
		if (document.layers)
			var xMax = window.outerWidth, yMax = window.outerHeight;
		else
			var xMax = 800, yMax=600;

        var xOffset = (xMax - uwidth)/2, yOffset = (yMax - uheight)/2;   
        
	var features =
	'screenX=' + xOffset +
	',screenY=' + yOffset +
	',top=' + yOffset +
	',left=' + xOffset +
	',width=' + uwidth +
	',height=' + uheight +
	',directories=no'  +
	',location=no'  +
	',menubar=no' +
	',scrollbars='  + Scroll +
	',status=no' +
	',toolbar=no' +
	',Resizable=yes';
	
	var newwindow2 = window.open (uUrl, WindowName, features);
        return false;
}



/******************************************************
* 对话窗口打开函数（固定位置）
******************************************************/
function openFixedDialog(uUrl,DialogName,uwidth,uheight,uX,uY) {

	var features =
	'dialogWidth:' + uwidth + 'px' +
	';dialogHeight:' + uheight + 'px' +
	';dialogLeft:' + uX +'px' +
	';dialogTop:' + uY + 'px' +
	';center:no;help:no;resizable:no;status:no';
	
	showModalDialog(uUrl,DialogName,features);
        return false;
}



/******************************************************
* 对话窗口打开函数（无返回值）
******************************************************/
function openDialog(uUrl,DialogName,uwidth,uheight) {

	mouseX = event.screenX;
	mouseY = event.screenY;	

	var features =
	'dialogWidth:' + uwidth + 'px' +
	';dialogHeight:' + uheight + 'px' +
	';dialogLeft:' + mouseX +'px' +
	';dialogTop:' + mouseY + 'px' +
	';center:no;help:no;resizable:no;status:no';
	
	showModalDialog(uUrl,DialogName,features);
        return false;
}



/******************************************************
* 鼠标选择对话窗口（返回值）
******************************************************/
function openSelectDialog(uUrl,DialogName,uwidth,uheight,fieldName) {

	mouseX = event.screenX;
	mouseY = event.screenY;	

	var features =
	'dialogWidth:' + uwidth + 'px' +
	';dialogHeight:' + uheight + 'px' +
	';dialogLeft:' + mouseX +'px' +
	';dialogTop:' + mouseY + 'px' +
	';center:no;help:no;resizable:no;status:no';
	
	var result = showModalDialog(uUrl,DialogName,features);
	if (result != null){document.all(fieldName).value=result;}
    return false;
}



/******************************************************
* 鼠标选择对话窗口（追加返回值）
******************************************************/
function appendSelectDialog(uUrl,DialogName,uwidth,uheight,fieldName) {

	mouseX = event.screenX;
	mouseY = event.screenY;	

	var features =
	'dialogWidth:' + uwidth + 'px' +
	';dialogHeight:' + uheight + 'px' +
	';dialogLeft:' + mouseX +'px' +
	';dialogTop:' + mouseY + 'px' +
	';center:no;help:no;resizable:no;status:no';
	
	var result = showModalDialog(uUrl,DialogName,features);
	var orginalValue = document.all(fieldName).value;
	if (orginalValue != null && orginalValue.length>0){orginalValue=orginalValue+',';}
	if (result != null){document.all(fieldName).value=orginalValue+result;}
    return false;
}

