function bbsLogin(pname){
	try{
		var uid = document.getElementById("bbsUserId").value;
		var pwd = document.getElementById("bbsUserPwd").value;
		if(uid==""){
			alert("请输入用户名");
			return;
		}
		if(pwd==""){
			alert("请输入用户密码");
			return;
		}
        jwf_ajax.sendData(pname,"post","action=login&userId="+uid+"&password="+pwd);
        var res = jwf_ajax.getIniValue("res");
        if(res=="1"){
        	document.getElementById("loginDiv").innerHTML = "";
        }else{
        	alert("用户或密码不正确");
        }
    }catch(e){
        alert(e.message);
    }
}
/**
 * The Method used by pay button of order
 * Don't change or delete it
 */
function payOrder(currencyold,amountold,currencynew,amountnew){
    var ys;
    ys = false;
    if(currencyold!=currencynew){
       if(confirm("在线支付温馨提示：\r\n您的当前订单货币"+currencyold+"需要转换成网关货币"+currencynew+"进行支付,\r\n当前订单金额:"+amountold+currencyold+",\r\n转换订单金额:"+amountnew+currencynew+",\r\n确定要继续吗")){
       	   ys = true;
       }
    }else{
       if(confirm("确定要在线支付吗")){
    	ys = true;
       }
    }
    if(ys){
    	document.forms[0].action = document.getElementById("form_payonline").value;
    	document.forms[0].target = "_blank";
		document.forms[0].submit();
	}
}
/**
 * The Method used by refund button of order
 * Don't change or delete it
 */
var refundWin;
function closeRefundWin(){
	refundWin.reset();
}
var refund_currencyold,refund_amountold,refund_ordercode,refund_amountnew;
function openRefundWin(ordercode,currencyold,amountold){
	refund_ordercode = ordercode;
	refund_currencyold = currencyold;
	refund_amountold = amountold;
	refundWin = new dialog();
	refundWin.open("/comm/refundTips.jsp?oldamt="+refund_amountold+"&amt=refundAmount&reason=refundReason&callback=refundOrder","auto","订单退款",600,400);
	refundWin.position(80,50);
}
/**
 * 此方法为回调方法，不要直接调用
 */
function refundOrder(){
  var ys;
  ys = false;
  refund_amountnew = document.getElementById("refundAmount").value;
  
  if(confirm("确定要退款吗")){
	    closeRefundWin();
	    try{
	    	var reason = document.getElementById("refundReason").value;
	    	var act = document.forms[0].action==""?document.location:document.forms[0].action;
	    	var data = "action=refund&amt="+refund_amountnew+"&ordercode="+refund_ordercode+"&reason="+reason;
	    	data=encodeURI(data);
	        data=encodeURI(data); //两次，很关键
	        jwf_ajax.sendData(act,"post",data);
	        document.forms[0].action = document.getElementById("form_payonline").value;
	  	    document.forms[0].target = "_blank";
			document.forms[0].submit();
		}catch(e){
		    alert(e.message);
		}
	}
}
function dateDiff(sDate1, sDate2){  //sDate1和sDate2是2002-12-18格式
       var aDate, oDate1, oDate2, iDays;
       aDate = sDate1.split("-");
       oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);  //转换为12-18-2002格式
       aDate = sDate2.split("-");
       oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
       iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24);  //把相差的毫秒数转换为天数
       return iDays;
 }   
function strToDate(str)
{
  var arys= new Array();
  arys=str.split('-');
  var myDate=new Date();
  var m = arys[1];
  myDate.setFullYear(arys[0],(m - 1),arys[2]);	 
  return myDate;
}
/*第一种形式 第二种形式 更换显示样式*/
var cur_tabpage_no = 1;
function setTab(name,cursel,n){
	for(var i=1;i<=n;i++){
		var menu=document.getElementById(name+i);
		var con=document.getElementById("con_"+name+"_"+i);
		if(i==cursel){
		  cur_tabpage_no = i;
		  menu.className="hover";
		  con.style.display="block";
		}else{
		  menu.className="";
		  con.style.display="none";
		}		
	}
}

function printdiv(printpage)
{
	var headstr = "<html><head><title></title><META http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body>";
	var footstr = "</body>";
	var newstr = document.getElementById(printpage).innerHTML;
	if(document.documentElement){
		var windowUrl = 'about:blank';
		var WinPrint = window.open(windowUrl,'','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0,menubar=0');
		 WinPrint.document.write(headstr+newstr+footstr);
		 WinPrint.focus();
		 WinPrint.print();
		 WinPrint.document.close();		
	}else{
		var oldstr = document.body.innerHTML;
		document.body.innerHTML = headstr+newstr+footstr;
		window.print(); 
		document.body.innerHTML = oldstr;
	}
	
	return false;
} 
function isChinese(temp,message) 
{ 
  var re = /[^\u4e00-\u9fa5]/; 
  if(re.test(temp)) return false; 
  else{
    if(message!=null&&message!=""){
      alert(message);
    }
    return true; 
  }
} 

function addOne(list1, list2) {//list1--->list2
	list1 = eval(list1);
	list2 = eval(list2);
	for (var i = 0; i < list1.options.length; i++) {
		if ((list1.options[i].selected == true) && (!exist(list2, list1.options[i].value))) {
			list2.add(document.createElement("OPTION"));
			list2.options[list2.options.length - 1].value = list1.options[i].value;
			list2.options[list2.options.length - 1].text = list1.options[i].text;
		}
	}
	for (var i = 0; i < list2.options.length; i++) {
		for (var j = 0; j < list1.options.length; j++) {
			if (list2.options[i].value == list1.options[j].value) {
				list1.options[j] = null;
			}
		}
	}
}
function addAll(list1, list2) {//list1--->>list2
	list1 = eval(list1);
	list2 = eval(list2);
	for (var i = 0; i < list1.options.length; i++) {
		if (!exist(list2, list1.options[i].value)) {
			list2.add(document.createElement("OPTION"));
			list2.options[list2.options.length - 1].value = list1.options[i].value;
			list2.options[list2.options.length - 1].text = list1.options[i].text;
		}
	}
	for (var i = 0; i < list2.options.length; i++) {
		for (var j = 0; j < list1.options.length; j++) {
			if (list2.options[i].value == list1.options[j].value) {
				list1.options[j] = null;
			}
		}
	}
}
function removeOne(list1, list2) {//list1<---list2
	list1 = eval(list1);
	list2 = eval(list2);
	for (var i = 0; i < list2.options.length; i++) {
		if ((list2.options[i].selected == true) && (!exist(list1, list2.options[i].value))) {
			list1.add(document.createElement("OPTION"));
			list1.options[list1.options.length - 1].value = list2.options[i].value;
			list1.options[list1.options.length - 1].text = list2.options[i].text;
		}
	}
	for (var i = 0; i < list1.options.length; i++) {
		for (var j = 0; j < list2.options.length; j++) {
			if (list1.options[i].value == list2.options[j].value) {
				list2.options[j] = null;
			}
		}
	}
}
function removeAll(list1, list2) {//list1<<---list2
	list1 = eval(list1);
	list2 = eval(list2);
	for (var i = 0; i < list2.options.length; i++) {
		if (!exist(list1, list2.options[i].value)) {
			list1.add(document.createElement("OPTION"));
			list1.options[list1.options.length - 1].value = list2.options[i].value;
			list1.options[list1.options.length - 1].text = list2.options[i].text;
		}
	}
	for (var i = 0; i < list1.options.length; i++) {
		for (var j = 0; j < list2.options.length; j++) {
			if (list1.options[i].value == list2.options[j].value) {
				list2.options[j] = null;
			}
		}
	}
}
function setIdForInSql(hiddenId, cbId) {
	var allId = document.getElementById(hiddenId).value;
	if (cbId.checked == true) {
		if (allId == "") {
			allId = "'" + cbId.value + "'";
		} else {
			allId += ",'" + cbId.value + "'";
		}
		document.getElementById(hiddenId).value = allId;
	} else {
		var ar_allid = allId.split(",");
		var sid = "";
		for (var i = 0; i < ar_allid.length; i++) {
			if (ar_allid[i] != cbId.value) {
				if (sid == "") {
					sid = "'" + ar_allid[i] + "'";
				} else {
					sid += ",'" + ar_allid[i] + "'";
				}
			}
		}
		document.getElementById(hiddenId).value = sid;
	}
}
function trim(inputString) {
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length - 1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length - 1);
		ch = retValue.substring(retValue.length - 1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) {
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length); // Again, there are two spaces in each of the strings
	}
	return retValue;
}
function showDialog(url)   
{   
   if(document.all) //IE   
   {        
   openDialog(url,800,600,"");   
   }   
   else   
   {   
     //modelessDialog可以将modal换成dialog=yes   
   var feature ="width=800,height=600,menubar=no,toolbar=no,location=no,";   
   feature+="scrollbars=yes,status=no,modal=yes";     
   window.open(url,null,feature);   
   }   
} 
function openSelect(dlgTarget, WINwidth, WINheight) {
	var str = "roomcodes.jsp?PageUrl=" + dlgTarget;
	var retval = openDialog(str, WINwidth, WINheight);
	return retval;
}
function openDialog(dlgTarget, WINwidth, WINheight, Argument) {
	var showX = event.screenX - event.offsetX;
	var showY = event.screenY - event.offsetY + 20;
	var newWINwidth = WINwidth; // + 4 + 18;
	retval = window.showModalDialog("../comm/pubSelect.jsp?url=" + dlgTarget + "", Argument, "dialogWidth:" + newWINwidth + "px; dialogHeight:" + WINheight + "px; dialogLeft:" + showX + "px; dialogTop:" + showY + "px; status:no; directories:yes;scrollbars:yes;Resizable=no;");
	return retval;
}
function openCalendar(fieldName) {
	var WINwidth = 201;
	var WINheight = 210;
	var deltaX = 16;
	var deltaY = 18;
	var showX = event.screenX - event.offsetX - WINwidth + deltaX;
	var showY = event.screenY - event.offsetY + deltaY;
	var newWINwidth = WINwidth; // + 4 + 18;
	var dlgTarget = "CalendarDlg.htm";
	retval = window.showModalDialog("" + dlgTarget + "", "", "dialogWidth:" + newWINwidth + "px; dialogHeight:" + WINheight + "px; dialogLeft:" + showX + "px; dialogTop:" + showY + "px; status:no; directories:yes;scrollbars:no;Resizable=no;");
	if (retval != null) {
		fieldName.value = retval;
	} else {
                //alert("canceled");
	}
}
function convertNaN(v) {
	if (trim(v).toUpperCase() == "NaN".toUpperCase() || v == null || trim(v) == "") {
		return "0";
	}
	return v;
}
function format(expr, decplaces) {
	var str = "" + Math.round((expr) * (Math.pow(10, decplaces)));
  //var str = ""+Math.round(expr*(Math.pow(10,decplaces)));
	if (trim(str).toUpperCase() == "NaN".toUpperCase() || str == null || trim(str) == "") {
		return "";
	} else {
		while (str.length <= decplaces) {
			str = "0" + str;
		}
		var decpoint = str.length - decplaces;
		if (decplaces == 0) {
			return str.substring(0, decpoint);
		} else {
			return str.substring(0, decpoint) + "." + str.substring(decpoint, str.length);
		}
	}
}
function onlyDigit() {
	if (!(((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) || (window.event.keyCode == 13) || (window.event.keyCode == 46) || (window.event.keyCode == 45))) {
		window.event.keyCode = 0;
	}
}
function getAppName() {
	var ipAddr = document.location.pathname;
	var pos1, pos2;
	pos1 = ipAddr.indexOf("/");
	pos2 = ipAddr.indexOf("/", 1);
	return ipAddr.substring(pos1, pos2);
}
function moveUp(el) {
	var index = el.selectedIndex;
	if ((index < 1) || (index == -1)) {
		return;
	}
	var tmp = el.item(index - 1);
	var opt = document.createElement("OPTION");
	opt.text = tmp.text;
	opt.value = tmp.value;
	el.remove(index - 1);
	el.add(opt, index);
	el.selectedIndex = index - 1;
}
function moveDown(el) {
	var index = el.selectedIndex;
	if ((index > el.length - 2) || (index == -1)) {
		return;
	}
	var tmp = el.item(index + 1);
	var opt = document.createElement("OPTION");
	opt.text = tmp.text;
	opt.value = tmp.value;
	el.remove(index + 1);
	el.add(opt, index);
	el.selectedIndex = index + 1;
}
function selectAll(list) {
	for (var i = 0; i < list.options.length; i++) {
		list.options[i].selected = true;
	}
}
function unSelectAll(list) {
	for (var i = 0; i < list.options.length; i++) {
		list.options[i].selected = false;
	}
}
function validDate(str) {//correct :YYYY/MM/DD
	if (str == "") {
		return false;
	}
	var pattern = /^((\d{4})|(\d{2}))-(\d{1,2})-(\d{1,2})$/g;
	if (!pattern.test(str)) {
		return false;
	}
	var arrDate = str.split("-");
	if (parseInt(arrDate[0], 10) < 100) {
		arrDate[0] = 2000 + parseInt(arrDate[0], 10) + "";
	}
	var date = new Date(arrDate[0], (parseInt(arrDate[1], 10) - 1) + "", arrDate[2]);
	if (date.getYear() == arrDate[0] && date.getMonth() == (parseInt(arrDate[1], 10) - 1) + "" && date.getDate() == arrDate[2]) {
		return true;
	} else {
		return false;
	}
}
function compareDate(a, b) {
	var parse = function (s) {
		return Date.parse(s.replace(/-/g, "/"));
	};
	return parse(b) > parse(a);
}
function selectTableAll(tableId) {
	var tableObj = null;
	if (tableId != null) {
		tableObj = document.getElementById(tableId);
	} else {
		tableObj = window.event.srcElement.parentElement.parentElement.parentElement.parentElement;
		if (tableObj.tagName.toUpperCase() != "TABLE") {
			tableObj = null;
		}
	}
	if (tableObj != null) {
		for (var i = 1; i < tableObj.rows.length; i++) {
			var checkbox = tableObj.rows[i].cells[0].children[0];
			if (!checkbox.disabled) {
				if (event.srcElement.checked) {
					checkbox.checked = "true";
				} else {
					checkbox.checked = "";
				}
			}
		}
	}
}
function clearTableAll(tableId) {
	var tableObj = document.getElementById(tableId);
	if (tableObj != null) {
		for (var i = 1; i < tableObj.rows.length; i++) {
			var checkbox = tableObj.rows[i].cells[0].children[0];
			if (!checkbox.disabled) {
				checkbox.checked = "";
			}
		}
		var topCheck = document.getElementById("allbox");
		topCheck.checked = "";
	}
}
function isSelected(gvId) {
	var tableObj = document.getElementById(gvId);
	if (tableObj == null) {
		return false;
	}
	for (var i = 1; i < tableObj.rows.length; i++) {
		if (tableObj.rows[i].cells[0].children[0].checked == true) {
			return true;
		}
	}
	return false;
}
function ValidateEmail(str) {
	var ret = false;
	if (typeof (str) != "undefined") {
		if (/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(str)) {
			ret = true;
		}
	}
	return ret;
}
function submitPage(pageUri, cid) {
	var action = cid == "" ? "add" : "save";
	document.forms[0].action = pageUri + "?action=" + action;
	document.forms[0].submit();
}
function submitForm(pageUri, action) {
	document.forms[0].action = pageUri + "?action=" + action;
	document.forms[0].submit();
}
function validateForm(frm) {
	for (var i = 0; i < frm.elements.length; i++) {
		var el = frm.elements[i];
		if (el.type == "text" || el.type == "select-one" || el.type == "textarea" || el.type == "hidden" || el.type == "password" || el.type == "checkbox") {
			if (el.title && el.title != "" && el.value == "" && el.currentStyle.display !="none") {
				alert(el.title);
				if (el.type != "hidden") {
					el.focus();
				}
				return false;
			}
		}
	}
	return true;
}
function sel(selAll) {
	var dels = document.getElementsByName("keyid");
	if (selAll.checked) {
		for (var i = 0; i < dels.length; i++) {
			dels[i].checked = "true";
		}
	} else {
		for (var i = 0; i < dels.length; i++) {
			dels[i].checked = "";
		}
	}
}
function checkNum() {
	if (event.keyCode < 45 || event.keyCode > 57 || event.keyCode == 46) {
		event.returnValue = false;
	}
}
function checkFloat() {
	if (!(((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) || (window.event.keyCode == 13) || (window.event.keyCode == 46) || (window.event.keyCode == 45))) {
		window.event.keyCode = 0;
	}
}
function setCodeForInSql(hiddenId, cbId) {
	var allId = document.getElementById(hiddenId).value;
	if (cbId.checked == true) {
		if (allId == "") {
			allId = cbId.value;
		} else {
			allId += "," + cbId.value;
		}
		document.getElementById(hiddenId).value = allId;
	} else {
		var ar_allid = allId.split(",");
		var sid = "";
		for (var i = 0; i < ar_allid.length; i++) {
			if (ar_allid[i] != cbId.value) {
				if (sid == "") {
					sid = ar_allid[i];
				} else {
					sid += "," + ar_allid[i];
				}
			}
		}
		document.getElementById(hiddenId).value = sid;
	}
}

//browers image
function setimg(img1, fimg, oldimg, ah) {
	document.getElementById(img1).src = document.getElementById(oldimg).src;
	document.getElementById(ah).href = document.getElementById(oldimg).src;
	if (document.getElementById(fimg).value != "") {
		document.getElementById(img1).src = document.getElementById(fimg).value;
		document.getElementById(ah).href = document.getElementById(img1).src;
	}
}

//修改密码，判断密码
function checkPwd() {
	var keyid = document.getElementById("ukeyid").value;
	if (keyid == "") {
		var pwd = document.getElementById("pwd").value;
		var confirmPwd = document.getElementById("confirm").value;
		if (!(pwd == "")) {
			if (!(confirmPwd == "")) {
				if (confirmPwd == pwd) {
					return true;
				} else {
					alert("\u5bc6\u7801\u548c\u786e\u8ba4\u5bc6\u7801\u5fc5\u987b\u76f8\u540c!");
				}
			} else {
				document.getElementById("confirm").focus();
				alert("\u8bf7\u8f93\u5165\u786e\u8ba4\u5bc6\u7801!");
			}
		} else {
			document.getElementById("pwd").focus();
			alert("\u8bf7\u8f93\u5165\u5bc6\u7801!");
		}
		return false;
	}
	return true;
}
//清除数字前后的空格
function trim(str){
  var regExp=/^\s*(.*?)\s*$/;
  return str.replace(regExp, "$1");
} 
//判断输入的是否是数字
function checkNaN(number) {
	var num = document.getElementById(number);
	var numValue = trim(num.value);
	//判断如果是数字
	if (isNaN(numValue)) {
		alert("\u8bf7\u8f93\u5165\u6570\u5b57\uff01");
		num.focus();
		return false;
	}
	return true;
}
//判断用户输入的只能是数值类型的
function checkNaNF(number) {
	var num = trim(document.getElementById(number).value);
	//判断是数字
	var regExp = /^[\d\.]{1,}$/;
	if (!regExp.test(num)) {
		alert("\u8bf7\u8f93\u5165\u6570\u503c\uff01");
		document.getElementById(number).focus();
		return false;
	}
	return true;
}


//判断用户帐户是否已经存在
function checkno() {
	var userids = document.getElementById("userids").value;
	var users = userids.split(",");
	var userid = document.getElementById("userid").value;
	var flag = false;
	if (userid != "") {
		for (var i = 0; i < users.length; i++) {
			if (userid == users[i]) {
				flag = true;
				alert("\u5bf9\u4e0d\u8d77,\u6b64\u5e10\u53f7\u5df2\u7ecf\u5b58\u5728!");
				document.getElementById("userid").focus();
				break;
			}
		}
		if (!flag) {
			document.getElementById("username").focus();
			alert("\u606d\u559c\uff0c\u6b64\u5e10\u53f7\u53ef\u7528!");
		}
	} else {
		alert("\u8bf7\u8f93\u5165\u5e10\u53f7!");
	}
}
//正则表达式判断,只能输入数字,字符串,和中文
function regNoSplit(data){
	if(data!=""){
		var reg = new RegExp("^[A-Za-z0-9\u4E00-\u9600]+$");
		return reg.test(data);
	}
	return true;
}
function getNewVerifycode(imgid,srv,skey){
	document.getElementById(imgid).src = srv+"?sessionkey="+skey+"&1="+Math.random();
}
String.prototype.replaceAll  = function(s1,s2){    
  return this.replace(new RegExp(s1,"gm"),s2);    
}
