//JavaScript函数

function confirmdel(confirmMsg,title){
   var is_confirmed = confirm(confirmMsg + '\n' + title);
   return is_confirmed;
}

function closewin(){
	window.close();
	return true;
}

//可变窗口
function newwin(url,iw,ih)
{
	var il = (window.document.body.clientWidth - iw)/2;
	var it = (window.document.body.clientHeight - ih)/2;
	newWindow = window.open(url,"_blank","left="+il+",top="+it+",width="+iw+",height="+ih+",directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,location=no,menubar=no,toolbar=no");
}

//固定窗口
function fixwin(url,iw,ih)
{
	newWindow = window.open(url,"_blank","left=100,top=50,width="+iw+",height="+ih+",directories=no,status=no,scrollbars=no,resizable=no,menubar=no,location=no,menubar=no,toolbar=no");
}

//设置行的颜色
function setPointer(theRow, thePointerColor) {
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }

    var row_cells_cnt   = theRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
        theRow.cells[c].bgColor = thePointerColor;
    }

    return true;
} // end of the 'setPointer()' function

//判断时间格式
function isdate(sDate) {
	var sVal;
	sVal = sdate.substr(4,0) > "1000" && sdate.substr(4,0) < "9999";
	sVal = sVal && sdate.substr(5,4) == "-" && sdate.substr(8,7) == "-";
	sVal = sVal && sdate.substr(7,5) > "00" && sdate.substr(7,5) < "13";
	sVal = sVal && sdate.substr(10,8) > "00" && sdate.substr(10,8) < "32";
	return sVal;
}


//判断是不是数字
function isnumber(theTxt,theCaption,theDot){
	var checkStr = theTxt.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	
	if (arguments.length > 2) { 
		var checkOK = "0123456789";
		theCaption = "[ " + theCaption + " ]只能输入数字。";
	} else {
		var checkOK = "0123456789.。";
		theCaption = "[ "+ theCaption +" ]只能输入数字和小数点。请不要有空格、- 、全角数字和字母等。";
	}
	
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
	  		if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length)  {
	  		allValid = false;
	  		break;
		}
		if (ch == "." || ch == "。") {
	  		allNum += ".";
	  		decPoints++;
		} else {
	  		allNum += ch;
		}
	}
	
	if (!allValid) {
		alert(theCaption);
		theTxt.focus();
		return (false);
	}
	
	if (decPoints > 1) {
		alert("[ "+theCaption+" ]中输入了两个以上小数点。");
		theTxt.focus();
		return (false);
	}
	
	//对高度、冠幅加以限制
	if  (theCaption == "高度" && theTxt.value>0 && theTxt.value<5)	{
		alert("[ "+theCaption+" ]的单位是厘米，所以不能小于5。");
		theTxt.focus();
		return (false);
	}
	
	if  (theCaption == "冠幅" && theTxt.value>0 && theTxt.value<5)	{
		alert("[ "+theCaption+" ]的单位是厘米，所以不能小于5。");
		theTxt.focus();
		return (false);
	}
	
	theTxt.value = checkStr.replace("。",".");
	return (true);
}
function replace_quanjiao(theTxt) {
	var checkStr = theTxt.value;
	checkStr = checkStr.replace(/\０/g,"0");
	checkStr = checkStr.replace(/\１/g,"1");
	checkStr = checkStr.replace(/\２/g,"2");
	checkStr = checkStr.replace(/\３/g,"3");
	checkStr = checkStr.replace(/\４/g,"4");
	checkStr = checkStr.replace(/\５/g,"5");
	checkStr = checkStr.replace(/\６/g,"6");
	checkStr = checkStr.replace(/\７/g,"7");
	checkStr = checkStr.replace(/\８/g,"8");
	checkStr = checkStr.replace(/\９/g,"9");
	theTxt.value = checkStr;
	return true;
}
function replace_space(theTxt) {
	var checkStr = theTxt.value;
	theTxt.value = checkStr.replace(/\ /g,"");
	return true;
}


//隐含、显示层 blnView指是否确定是显示 blnLocate指层显示的位置是否和鼠标有关系 
function ShowPic(Layername,blnView,blnLocate)
{
	Layer = eval(Layername);
	DisplayStatus=Layer.style.visibility;
	
	if (blnView){ DisplayStatus ="hidden"; } else { DisplayStatus ="visible"; } 
	if (blnLocate){ 
		nX = event.clientX; 
		nY = event.clientY + 10;
		if (nX < 3 ){ nX = 3;}
		if (document.body.clientHeight - nY < (Layer.style.pixelHeight+5)){
			nY = event.clientY - (Layer.style.pixelHeight + 5);
		}
	} 
 
	if (DisplayStatus=="hidden"){
		Layer.style.visibility = "visible";
		if (blnLocate){ 
 			Layer.style.left=document.body.scrollLeft+nX;
        	//Layer.style.top=document.body.scrollTop+nY;  
		}
	} else {
		Layer.style.visibility = "hidden";	
	}
 }
  
function dispcatalog() {
	if (document.getElementById("catalog_menu").style.display == "none") {
		document.getElementById("catalog_menu").style.display = "";
	} else {
		document.getElementById("catalog_menu").style.display = "none";
	}
}

//全选
function checkall(form) {
	for (var i = 0; i < form.elements.length; i++){
		var e = form.elements[i];
		if ( e.name != 'chkall') e.checked = form.chkall.checked;
	}
	return true;
}

//选择了几个
function selectednumber(form){
	var number = 0 ;
	for (var i = 0; i < form.elements.length; i++){
		var e = form.elements[i];
		if (e.type == 'checkbox' && e.checked == true) {
			number++;
		}
	}
	return number;
}

//选择了哪几个
function selectedid(form) {
	var selstr = "";
 	for (var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if (e.type == "checkbox" && e.checked && e.name != "chkall") {
			if (selstr != "") {
				selstr += ",";
			} 
			selstr += e.value;
		}
	}
	return selstr;
}


//检查操作
function chkoper(form,theme,operation){
	var selnumber = selectednumber(form);
	var strnote = "您没有选择要" + operation + "的" + theme + "。";
	
	if ( selnumber== 0 ){ 
		alert(strnote);
		return false;
	}
	if ( operation == "删除" ){
		return confirm("真的删除选中的" + theme + "吗?");
	} else {
		return true;
	}
}

//提交操作
function dopost(theformid,opertype,operid,postwin,opernote) {
	var theform = document.getElementById(theformid);
	if (opernote != null && opernote != "") {
		if (opertype == "submit" || opertype == "delete" || opertype == "deletesel") {
			if (!confirm(opernote)) return false;
		} else {
			alert(opernote); 
			return;
		}
	} 

    theform.action = postwin;
	theform.id.value = operid;
	theform.operate.value = opertype;
	theform.submit();
}

//图像改变大小
function ResizeImage(obj, MaxW, MaxH){
    var imageObject;
    if (obj != null) imageObject = obj;
    var state=imageObject.readyState;
	if (state != 'complete') {
        setTimeout("ResizeImage(null,"+MaxW+","+MaxH+")",50);
		return;
    }
    var oldImage = new Image();
    oldImage.src = imageObject.src;
    var dW = oldImage.width; 
	var dH = oldImage.height;
    if (dW > MaxW || dH > MaxH) {
        a = dW/MaxW; 
		b = dH/MaxH;
        if (b > a) a = b;
        dW = dW/a; 
		dH = dH/a;
    }
    if (dW > 0 && dH > 0) {
        imageObject.width = dW;
		imageObject.height = dH;
	}
}

//function String.prototype.trim() {
//function String.prototype.trim() {
//	return this.replace(/(^\s*)|(\s*$)/g,"");
//}
function  trim(str)
{
    for(var  i  =  0  ;  i<str.length  &&  str.charAt(i)=="  "  ;  i++  )  ;
    for(var  j  =str.length;  j>0  &&  str.charAt(j-1)=="  "  ;  j--)  ;
    if(i>j)  return  "";  
    return  str.substring(i,j);  
} 
function writerisk(){
	document.write("以上信息由企业自行提供，该企业负责信息内容的真实性、准确性和合法性。青青花木网对此不承担任何保证责任。为了增强安全性，货前付款等业务（如邮购）建议使用“支付宝”，<a href=\"http://www.alipay.com\" target=\"_blank\">点击查看支付宝介绍</a>。");
	return;
}
function QQlink(qq,picmode){
	document.write("<a href='http://wpa.qq.com/msgrd?V=1&Uin="+qq+"&Site=青青花木网&Menu=yes' target='blank'><img SRC='http://wpa.qq.com/pa?p=1:"+qq+":"+picmode+"' border='0' align='absmiddle' alt='QQ号："+qq+" 点击即时交流'></a>");
	return;
}
function membertype(jb) {
	switch (jb) {
		case "a": usergif = "ypuser.gif";  usertxt = "银牌会员"; break;
		case "b": usergif = "jpuser.gif";  usertxt = "金牌会员"; break;
		case "c": usergif = "lbsuser.gif"; usertxt = "蓝宝石会员"; break;
		case "d": usergif = "zsuser.gif";  usertxt = "钻石会员"; break;
		default:  usergif = ""; break;
	}
	if (usergif == "") {
		document.write("·");
	} else {
		document.write("<a href='/server/member.php' target='_blank'><img src='/img/"+usergif+"'  align='absbottom' border='0' width='21' height='20' alt='"+usertxt+"'></a>");
	}
	return;
}
function dispnav() {
	if (document.getElementById("plist").style.display == "none") {
		document.getElementById("plist").style.display = "";
		document.getElementById("showtxt").style.display = "none";
		document.getElementById("hidetxt").style.display = "";
	} else {
		document.getElementById("plist").style.display = "none";
		document.getElementById("showtxt").style.display = "";
		document.getElementById("hidetxt").style.display = "none";
	}
}
