

/******************************************************
* 鼠标移动函数
******************************************************/
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;
	 }



/******************************************************
* 数字合法性判断函数
* By ZHH stlily@cheaa.com
******************************************************/

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"
	}
}



/******************************************************
* 窗口打开函数
******************************************************/
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 flag2Name(flag){if (flag=="Y"){document.write("有效");} else {document.write("<font color=red>无效</font>");}}

function flag2YN(flag){if (flag=="Y"){document.write("是");} else {document.write("<font color=red>否</font>");}}

function ratify(flag){if (flag=="Y"){document.write("<font color=blue>已批准</font>");} else if (flag=="N") {document.write("<font color=red>不批准</font>");} else {document.write("<font color=darkgray>未审批</font>");}}

function manyi(flag){if (flag=="0"){document.write("<font color=darkgray>无评论</font>");} else if (flag=="2") {document.write("<font color=red>不满意</font>");} else {document.write("<font color=blue>满意</font>");}}

function flag2Handle(flag){if (flag=="Y"){document.write("<font color=darkgray>已处理</font>");} else {document.write("<font color=blue>未处理</font>");}}

function flag2Delive(flag){if (flag=="Y"){document.write("<font color=darkgray>已配送</font>");} else if (flag=="O") {document.write("<font color=green>配送中</font>");} else {document.write("<font color=blue>未配送</font>");}}


/******************************************************/
function newupload(url) {	
	var win = window.open(url,"upload","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=620,height=200");    	
    win.focus();
}

function doBlink() {
  // Blink, Blink, Blink...
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : ""
}

function startBlink() {
  // Make sure it is IE4
  if (document.all)
    setInterval("doBlink()",1000)

}

function goback() {
	if(window.document.forms[0].Done) {
		window.location=window.document.forms[0].Done.value;
	}
	else if (window.document.forms[0].done) {
		window.location=window.document.forms[0].done.value;
	} 
	else {
		history.go(-1)
	}
}

function fullform() {	
	var myform = document.forms[0];	
	for(var i=0;i<myform.elements.length;i++) {
		var element = myform.elements[i];		
		if (eval("typeof("+"cgi_"+element.name+")")=='undefined') 
			continue;
		var jsvar = eval("cgi_"+element.name);		
		if (element.type=="select-one") {
			for(var j=0;j<element.options.length;j++) {
				var option = element.options[j];
				if (option.value==eval("cgi_"+element.name)) {
					option.selected=true;									
					break;
				}				
			}						
		}			
		else if (element.type=="text") {
				element.value=eval("cgi_"+element.name);
		}
		else if (element.type=="checkbox") {
			     jsvar = jsvar+",";
			 	 if (jsvar.indexOf(element.value+",")>-1) {			 	 	
			 	    element.checked=true;
			 	 }
			 	    
		}
		else if (element.type=="radio") {
			 if (jsvar==element.value)
			    element.checked=true;
		}				
		else if (element.type=="textarea") {
			 element.value=jsvar;
		}
		
	}
	
}


/******************************************************
* 用户名称、口令合法性判断函数
* By Zhh stlily@cheaa.com
******************************************************/
function ChkNamePass(str)
{
	var strLen=str.length;
	var ValidChars = "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	if (strLen>8 || strLen<3) return false;
	for (var i = 0; i < strLen; i++)
	{
		if (ValidChars.indexOf(str.charAt(i)) == -1)
			return false;
	} 
	return true;
}


/******************************************************
* 检测是否是EMail地址的函数
* By Zhh stlily@cheaa.com
******************************************************/
function chkemail(email)
{
	var strEmail;
	var int_Cnt;
	var iAt=0;
	strEmail=email.toUpperCase();
	
	 if (strEmail.indexOf("@") < 1 || strEmail.lastIndexOf('.') < 2 ||
		strEmail.lastIndexOf('.') < strEmail.indexOf("@") || strEmail.lastIndexOf('.')==strEmail.length-1)
																// 没有"@"或者第一个字符就是"@"，
																// 没有“.”或者最后一个字符是"."
																// 或者最后出现的"."比"@"还要前，
		return 1;												// 电子邮件地址错误！

	for ( int_Cnt = 0; int_Cnt < strEmail.length; int_Cnt++ )
	{
		int_a = strEmail.charCodeAt(int_Cnt)
													// 检测帐号是否合法
		if ( int_a < 45 || (int_a == 47) || (int_a > 57 && int_a < 64 ) || (int_a > 90 && int_a != 95 ))
			return int_a;											// 包含了非法字符
		if (int_a == 64)
			if (iAt != 0) return 1;
		else
			iAt ++;

	}
	return 0;
}

/******************************************************
* 检测是否是EMail地址的函数，允许多个地址以'；'号分割。
* By Zhh stlily@cheaa.com
******************************************************/
function checkEmail(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;
}

/******************************************************
* 重新设置窗口的大小和位置的函数
* By Zhh stlily@cheaa.com
******************************************************/
function ReWindow(uwidth,uheight)
{
	var xMax = screen.width, yMax = screen.height;
	var xOffset = (xMax - uwidth)/2, yOffset = (yMax - uheight)/2;   

	self.moveTo(xOffset,yOffset);
	self.resizeTo(uwidth,uheight);
	window.focus();
}

/******************************************************
* 返回上一页面，或者关闭窗口的函数
* By Zhh stlily@cheaa.com
******************************************************/
function close_back()
{
	if (history.length > 0)
		history.back();
	else
		window.close();
}

/******************************************************
* 以隐藏的方式打开窗口的函数
* By Zhh stlily@cheaa.com
******************************************************/
function openWin(url,winName,Scroll)
{
	if (Scroll == "" || Scroll == "no") Scroll = 'no';
	else Scroll = 'yes';
	var features = 'screenX=1,screenY=1,top=1800,left=1800,width=10,height=10,directories=no,location=no,menubar=no,scrollbars=" + Scroll + ",status=no,toolbar=no,Resizable=no';
	window.open (url,winName, features);
	return false;
}

/******************************************************
* 检测表单域中是否含有空格函数
******************************************************/
function isSpace(strName)
{
	var tmpFlag = true;
	strLen = strName.length;
    for (i=0; i<strLen; i++)
    {
        if (strName.charAt(i) != " ")
        {
			tmpFlag = false;
			return tmpFlag;
		}	//if
		//if (tmpFlag == false){ break;}	//if

    }	//for
	return tmpFlag;
}

/*
function is_digital(Item, ItemCaption)
该函数用于检验某一Item是否为数字
Item: 表单中元素名称，或者变量名
isObj:确定变量Email代表一个Item对象还是一个仅仅变量，if true,Item是一个表单中元素名称，否则……
ItemCaption:仅当IsObj = ture时有效,用于出错提示

function check_length(Item, MinLength, MaxLength, ItemCaption)
该函数用于检验某一Item是否长度符合要求
Item: 表单中元素名称，或者变量名
MinLength:最短长度
MaxLength:最大长度
ItemCaption:仅当IsObj = ture时有效,用于出错提示
*/
function check_length(Item, MinLength, MaxLength, ItemCaption)
{
	if ((MinLength == 0) && (MaxLength == 0))
		return true;

	if (MaxLength < MinLength)
	{
		alert("\"check_length\"函数调用错误。");
		return false;
	}

	if ((Item.value.length < MinLength) || (Item.value.length > MaxLength))
	{
		alert(ItemCaption + "长度不符合要求。"); 
		Item.focus();
		return false;
	}
	else
		return true;
}

function is_digital(Item, ItemCaption)
{
	var pattern = /^([0-9])+$/;
	flag = pattern.test(Item.value); 
	if(!flag)
	{
		alert(ItemCaption + "不是数字。"); 
		Item.focus();
		return false;
	}
	else
		return true;
}
/**************************************************
***********检验邮政编码**************************/
function check_postcode(PostCode)
{
	if (!check_length(PostCode, 6, 6, "邮政编码"))
		return false;

	if (!is_digital(PostCode, "邮政编码"))
		return false;
	return true;
}
/************************************************/
function isValidDate( year, month, day )
{
   if (isNumber(year)==false){alert("年份必须是数字");return(false);}
   if (isNumber(month)==false){alert("月份必须是数字");return(false);}
   if (isNumber(day)==false){alert("日期必须是数字");return(false);}

   year  = parseInt(year,10);
   month = parseInt(month,10);
   day   = parseInt(day,10);

   if (( month==4) || (month==6) || (month==9) || (month==11) )
   { if (( day < 1) || (day > 30) )
     { alert( "日期在1 - 30之间" );
       return (false);
     }
   }
   else
   { if ( month!=2 )
     { if ( (day < 1) || (day > 31 ))
       {  alert( "日期在1 - 31之间" );
          return (false);
       }
     }
     else
     { // month == 2
       if ( ( year % 100 ) != 0 && (year % 4 == 0) || ( year % 100 ) == 0 && ( year % 400) == 0 )
       { if ( day > 29 )
         {  alert( "日期在1 - 29之间" );
            return (false);
         }
       }
       else
       { if ( day > 28 )
         { alert( "日期在1 - 28之间" );
           return (false);
         }
       }
     }
   }
 return (true);
}

/*************************************************
*取得当前时间日期函数
*************************************************/
function getriqia()
{
var today = new Date();
var CurYear = today.getFullYear();			// 当前年份 1900-3900
var CurMon = today.getMonth() + 1;				// 当前月份 1-12
var CurDay = today.getDate();
var CurWeekDay = today.getDay();
getriqi=CurYear + "年" + CurMon + "月" + CurDay + "日 星期";
switch (CurWeekDay)
{
	case 0 : getriqi = getriqi + "天"; break;
	case 1 : getriqi = getriqi + "一"; break;
	case 2 : getriqi = getriqi + "二"; break;
	case 3 : getriqi = getriqi + "三"; break;
	case 4 : getriqi = getriqi + "四"; break;
	case 5 : getriqi = getriqi + "五"; break;
	case 6 : getriqi = getriqi + "六"; break;
}
document.write(getriqi);
} 

