function isnumber(v_check,bit_alert){
	if(v_check.length<1){
		return false;
	}else{
		for (var i=0; i < String(v_check).length; i++){
			var oneChar = String(v_check).substring(i,i+1);
			if ((oneChar < "0" || oneChar > "9" ) && oneChar !="-" && oneChar !=".") {
				if (bit_alert=true){alert("仅接受数字、负号和小数点！");}
				return false;
			}
		}
		return true;
	}
}

function isint(v_check,bit_alert){
	if (v_check.length<1){
		return false;
	}else{
		for (var i=0; i < String(v_check).length; i++){
			var oneChar = String(v_check).substring(i,i+1);
			if (oneChar < "0" || oneChar > "9" ) {
				if (bit_alert=true){alert("仅接受数字字符！");}
				return false;
			}
		}
		return true;
	}
}

function ismobile(v_check,bit_alert){
	var v_len = v_check.length;
	var reg = /^1[358]{1}[0-9]{9}$/;
	if (v_len<11){
		if (bit_alert=true){alert("手机号码缺位！");}
		return false;
		}
	if (v_len>11){
		if (bit_alert=true){alert("手机号码多位,外地手机无须输入“0”！");}
		return false;
		}
	if (reg.test(v_check)==false) {
		if (bit_alert=true){alert("手机号码仅接受'13','15','18'开头全数字！");}
		return false;
		}
	return true;
}

function istel(v_check,bit_alert){
	if (ismobile(v_check,bit_alert)){
		return true;
	}else{
		for (var i=0; i < String(v_check).length; i++){
   			var oneChar = String(v_check).substring(i,i+1)
     		if ((oneChar < "0" || oneChar > "9" ) && (oneChar !="-" || oneChar !="*")) {
	   			if (bit_alert=true){alert("仅接受数字字符和“-”，“*”！");}
				return false;
			}
		}			
	   return true;
	}
}


var delivery=new Date();
var timenow=String(delivery.getYear())+"-"+String(delivery.getMonth()+1)+"-"+String(delivery.getDate());
var timenextY=String(delivery.getYear()+1)+"-"+String(delivery.getMonth()+1)+"-"+String(delivery.getDate());  

function isdate(nYear, nMonth, nDay)
{
	if ((nMonth > 12) || (nMonth < 1) || (nDay < 1) || (nDay > 31))
	{
		alert("输入月份或日期有误！")
		return false;
	} else	{
		switch (nMonth){
			case 4 : 
			case 6 : 
			case 9 : 
			case 11 :
			{
				return (nDay < 31);
				break;
			}
			case 2 :
			{
				if (0 == nYear%4)
				{
					if ((0 == nYear%100) && (0 != nYear%400))
					{
						return (nDay < 29);
					}
					else
					{
						return (nDay < 30);
					}
				}
				return (nDay < 29);
				break;
			}
		}
	}
}

function checkdate(v_check,bit_alert){
	var v_error = "日期有误！"		//yyyy-mm-dd
	var v_length = v_check.length;
  	
	if (v_length <8 || v_length>10 )	{
		if (bit_alert=true){alert (v_error+"位数,正确格式YYYY-MM-DD");}
		return(false);
	} else	{
		for (var i=0; i < String(v_check).length; i++){
			var oneChar = String(v_check).substring(i,i+1)
			if ((oneChar < "0" || oneChar > "9" ) && oneChar !="-") {
				if (bit_alert=true){alert (v_error+"格式");}
				return(false);
			}
		}
	}
	var arrDate = v_check.split("-");
	var v_year = arrDate[0];
	var v_month = arrDate[1];
	var v_day = arrDate[2];
	if ((parseInt(v_year,10) > 2050) || (parseInt(v_year,10) < 1850))
	{
		if (bit_alert=true){alert (v_error+"年份");}
		return(false);
	}

	if (false == isdate(parseInt(v_year,10), parseInt(v_month,10), parseInt(v_day,10)))
	{
		if (bit_alert=true){alert (v_error+v_check+v_month);}
		return(false);
	}
	return (true);
}

function isemail(v_check,bit_alert){
	var v_length = v_check.length;
	var nCount = 0;
    var v_error = "电子邮箱输入有误！";
	if (v_length < 3){
		if (bit_alert=true){alert (v_error);}
		return(false);
	}

	if (('@' == v_check.substring(0,1)) || ('.' == v_check.substring(0,1)))	{
		if (bit_alert=true){alert (v_error);}
		return(false);
	}

	for (i=1;i<=v_length;i++){
		var d=v_check.substring(i-1,i);
		if (d == '@')
		{
			nCount++ ;
		}
    	}
    	
	if (nCount != 1){
		if (bit_alert=true){alert (v_error);}
		return(false);
	}

	nCount = 0;
	for (i=1;i<=v_length;i++){
		var d=v_check.substring(i-1,i);
		if (nCount >0){
			if (d == '.') nCount++;
		}else{
			if (d == '@') nCount = 1;
		}
    	}

	if (nCount == 1){
		if (bit_alert=true){alert (v_error);}
		return(false);
    	}
	return(true);  
}

function randomChar(l) {
	var x="0123456789poiuytrewqasdfghjklmnbvcxzQWERTYUIOPLKJHGFDSAZXCVBNM";
	var tmp="";
	for(var i=0;i< l;i++) {
		tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);
	}
	return tmp;
}

function checknull(v_check,bit_alert){
	var str=Trim(v_check);
	if(str.length==0){
		if (bit_alert=true){alert("不能为空！");}
		return false;
	}else{
		return true;
	}
}

function showdetail(o_table,e_tr,url,win_target){
	var a ="#FFFFFF" ; var b = "#F5F5F5" ; var c = "#FFFFCC" ; var d = "#FFFF84";
	if (url.length>4){parent.document.getElementById(win_target).src = url;}
	var k = document.getElementById(o_table).getElementsByTagName("tr");
	for (var i=0; i<k.length; i++){
		if (e_tr==k[i]){
			k[i].style.backgroundColor =d;
		}else{
			k[i].style.backgroundColor =(k[i].sectionRowIndex%2==0)?a:b;	
		}
	}		
}

function showspan(v_bit,show_sp,hidd_sp){
	if (v_bit){
		document.getElementById(show_sp).style.display="";
		if (hidd_sp!=""){
			document.getElementById(hidd_sp).style.display="none";
		}
	}else{
		document.getElementById(show_sp).style.display="none";
		if (hidd_sp!=""){
			document.getElementById(hidd_sp).style.display="";
		}
	}	
}

function listTable(o_name){
	var k = document.getElementById(o_name).getElementsByTagName("tr");
	for (var i=0; i<k.length; i++){
		k[i].style.backgroundColor =(k[i].sectionRowIndex%2==0)?"#FFFFFF":"#F5F5F5";		
	}	
}

function openwin(url,v_width,v_height,bit_dialog) { 
　　var width, height;
	if (isint(v_width,false)){width = v_width;}else{width=screen.availWidth;}
	if (isint(v_height,false)){height = v_height;}else{height=screen.availHeight;}
	//alert(width+","+height);
	var v_d = "dialogHeight:"+height+ "px;dialogWidth:"+width+"px;center:yes";
	var v_str = "width=" + width + ", height= " + height + ", top=" + (screen.availHeight-height)/2 + ", left=" + (screen.availWidth-width)/2 + ", toolbar =no, menubar=no, scrollbars=yes, location=no, status=no"; //写成一行
	//alert(url);
	if (bit_dialog){
		window.showModalDialog(url,"",v_d);			
	}else{
		window.open(url,"",v_str);		
	}
}

function autoiframeheight(o_id){
	var iframeid=document.getElementById(o_id); //iframe id
	if (iframeid){
		if (iframeid && !window.opera){		//ff or opera
			if (iframeid.contentDocument && iframeid.contentDocument.body.offsetHeight){
				iframeid.height = iframeid.contentDocument.body.offsetHeight+25;				
			}else if(iframeid.Document && iframeid.Document.body.scrollHeight){
				iframeid.height = iframeid.Document.body.scrollHeight;
			}
		}
	}
}

function autoiframewidth(o_id){
	var iframeid = document.getElementById(o_id);
	if (iframeid){
		if (iframeid && !window.opera){
			if (iframeid.contentDocument && iframeid.contentDocument.body.offsetWidth){
				iframeid.width = iframeid.contentDocument.body.offsetWidth;				
			}else if(iframeid.Document && iframeid.Document.body.scrollWidth){
				iframeid.width = iframeid.Document.body.scrollWidth;				
			}
		}
	}
}

function setiframeheight(o_id,maxHeight){
	var iframeid = document.getElementById(o_id); //iframe id
	var maxH;
	if (isint(maxHeight,false)){
		maxH = maxHeight;
	}else{
		maxH = $(document).height();
	}
	if (iframeid){
		if (iframeid && !window.opera){		//ff or opera
			if (iframeid.contentDocument && iframeid.contentDocument.body.offsetHeight){
				iframeid.height = maxH>iframeid.contentDocument.body.offsetHeight+25?iframeid.contentDocument.body.offsetHeight+25:maxH;
			}else if(iframeid.Document && iframeid.Document.body.scrollHeight){
				iframeid.height = maxH>iframeid.Document.body.scrollHeight+30?iframeid.Document.body.scrollHeight+30:maxH;
			}
		}
	}
}

function setiframewidth(o_id,maxWidth){
	var iframeid = document.getElementById(o_id); //iframe id
	var maxW;
	if (isint(maxWidth,false)){
		maxW = maxWidth;
	}else{
		maxW = $(document).width();
	}
	if (iframeid){
		if (iframeid && !window.opera){		//ff or opera, google
			if (iframeid.contentDocument && iframeid.contentDocument.body.offsetWidth){
				iframeid.width = maxW;				
			}else if(iframeid.Document && iframeid.Document.body.scrollWidth){		//ie
				iframeid.width = maxW-25;				
			}
		}
	}
}
