/* $id : user.js 4865 2007-01-31 14:04:10z paulgao $ */ /* * * 修改会员信息 */ function useredit() { var frm = document.forms['formedit']; var email = frm.elements['email'].value; var msg = ''; var reg = null; var passwd_answer = frm.elements['passwd_answer'] ? utils.trim(frm.elements['passwd_answer'].value) : ''; var sel_question = frm.elements['sel_question'] ? utils.trim(frm.elements['sel_question'].value) : ''; if (email.length == 0) { msg += email_empty + '\n'; } else { if ( ! (utils.isemail(email))) { msg += email_error + '\n'; } } if (passwd_answer.length > 0 && sel_question == 0 || document.getelementbyid('passwd_quesetion') && passwd_answer.length == 0) { msg += no_select_question + '\n'; } for (i = 7; i < frm.elements.length - 2; i++) // 从第七项开始循环检查是否为必填项 { needinput = document.getelementbyid(frm.elements[i].name + 'i') ? document.getelementbyid(frm.elements[i].name + 'i') : ''; if (needinput != '' && frm.elements[i].value.length == 0) { msg += '- ' + needinput.innerhtml + msg_blank + '\n'; } } if (msg.length > 0) { alert(msg); return false; } else { return true; } } /* 会员修改密码 */ function editpassword() { var frm = document.forms['formpassword']; var old_password = frm.elements['old_password'].value; var new_password = frm.elements['new_password'].value; var confirm_password = frm.elements['comfirm_password'].value; var msg = ''; var reg = null; if (old_password.length == 0) { msg += old_password_empty + '\n'; } if (new_password.length == 0) { msg += new_password_empty + '\n'; } if (confirm_password.length == 0) { msg += confirm_password_empty + '\n'; } if (new_password.length > 0 && confirm_password.length > 0) { if (new_password != confirm_password) { msg += both_password_error + '\n'; } } if (msg.length > 0) { alert(msg); return false; } else { return true; } } /* 会员绑定手机 */ function bindmobile() { var frm = document.forms['formbindmobile']; var mobile = frm.elements['mobile'].value; var verifycode = frm.elements['verifycode'].value; var msg = ''; var reg = null; if (mobile.length == 0) { msg += '手机号不能为空!\n'; } if (mobile.length != 11) { msg += '手机号必须为11位!\n'; } if (verifycode.length == 0) { msg += '验证码不能为空!\n'; } if (verifycode.length != 6) { msg += '验证码必须为6位!\n'; } if (msg.length > 0) { alert(msg); return false; } else { return true; } } /* * * 对会员的留言输入作处理 */ function submitmsg() { var frm = document.forms['formmsg']; var msg_title = frm.elements['msg_title'].value; var msg_content = frm.elements['msg_content'].value; var msg = ''; if (msg_title.length == 0) { msg += msg_title_empty + '\n'; } if (msg_content.length == 0) { msg += msg_content_empty + '\n' } if (msg_title.length > 200) { msg += msg_title_limit + '\n'; } if (msg.length > 0) { alert(msg); return false; } else { return true; } } /* * * 会员找回密码时,对输入作处理 */ function submitpwdinfo() { var frm = document.forms['getpassword']; var user_name = frm.elements['user_name'].value; var email = frm.elements['email'].value; var errormsg = ''; if (user_name.length == 0) { errormsg += user_name_empty + '\n'; } if (email.length == 0) { errormsg += email_address_empty + '\n'; } else { if ( ! (utils.isemail(email))) { errormsg += email_address_error + '\n'; } } if (errormsg.length > 0) { alert(errormsg); return false; } return true; } //互亿无线代码 /* * * 会员找回密码时,对输入作处理 */ function submitpwdmobileinfo() { var frm = document.forms['getpasswordbymobile']; var user_name = frm.elements['user_name'].value; var mobile = frm.elements['mobile'].value; var errormsg = ''; if (user_name.length == 0) { errormsg += user_name_empty + '\n'; } if (mobile.length == 0) { errormsg += mobile_address_empty + '\n'; } else { if ( ! (utils.ismobile(mobile))) { errormsg += mobile_address_error + '\n'; } } if (errormsg.length > 0) { alert(errormsg); return false; } return true; } //互亿无线代码 /* * * 会员找回密码时,对输入作处理 */ function submitpwd() { var frm = document.forms['getpassword2']; var password = frm.elements['new_password'].value; var confirm_password = frm.elements['confirm_password'].value; var errormsg = ''; if (password.length == 0) { errormsg += new_password_empty + '\n'; } if (confirm_password.length == 0) { errormsg += confirm_password_empty + '\n'; } if (confirm_password != password) { errormsg += both_password_error + '\n'; } if (errormsg.length > 0) { alert(errormsg); return false; } else { return true; } } /* * * 处理会员提交的缺货登记 */ function addbooking() { var frm = document.forms['formbooking']; var goods_id = frm.elements['id'].value; var rec_id = frm.elements['rec_id'].value; var number = frm.elements['number'].value; var desc = frm.elements['desc'].value; var linkman = frm.elements['linkman'].value; var email = frm.elements['email'].value; var tel = frm.elements['tel'].value; var msg = ""; if (number.length == 0) { msg += booking_amount_empty + '\n'; } else { var reg = /^[0-9]+/; if ( ! reg.test(number)) { msg += booking_amount_error + '\n'; } } if (desc.length == 0) { msg += describe_empty + '\n'; } if (linkman.length == 0) { msg += contact_username_empty + '\n'; } if (email.length == 0) { msg += email_empty + '\n'; } else { if ( ! (utils.isemail(email))) { msg += email_error + '\n'; } } if (tel.length == 0) { msg += contact_phone_empty + '\n'; } if (msg.length > 0) { alert(msg); return false; } return true; } /* * * 会员登录 */ function userlogin() { var frm = document.forms['formlogin']; var username = frm.elements['username'].value; var password = frm.elements['password'].value; var msg = ''; if (username.length == 0) { msg += username_empty + '\n'; } if (password.length == 0) { msg += password_empty + '\n'; } if (msg.length > 0) { alert(msg); return false; } else { return true; } } function chkstr(str) { for (var i = 0; i < str.length; i++) { if (str.charcodeat(i) < 127 && !str.substr(i,1).match(/^\w+$/ig)) { return false; } } return true; } function check_password( password ) { if ( password.length < 6 ) { $("#password1").parent().removeclass("params_success"); $("#password1").parent().addclass("params_error"); document.getelementbyid('password_notice').innerhtml = password_shorter; } else { $("#password1").parent().removeclass("params_error"); $("#password1").parent().addclass("params_success"); document.getelementbyid('password_notice').innerhtml = ""; //zhouhuan } } function check_conform_password( conform_password ) { password = document.getelementbyid('password1').value; if ( conform_password.length < 6 ) { $("#conform_password").parent().removeclass("params_success"); $("#conform_password").parent().addclass("params_error"); document.getelementbyid('conform_password_notice').innerhtml = password_shorter; return false; } if ( conform_password != password ) { $("#conform_password").parent().removeclass("params_success"); $("#conform_password").parent().addclass("params_error"); document.getelementbyid('conform_password_notice').innerhtml = confirm_password_invalid; } else { $("#conform_password").parent().removeclass("params_error"); $("#conform_password").parent().addclass("params_success"); document.getelementbyid('conform_password_notice').innerhtml = ""; //zhouhuan } } function is_registered( username ) { var submit_disabled = false; var unlen = username.replace(/[^\x00-\xff]/g, "**").length; if ( username == '' ) { document.getelementbyid('username_notice').innerhtml = msg_un_blank; var submit_disabled = true; } if ( !chkstr( username ) ) { document.getelementbyid('username_notice').innerhtml = msg_un_format; var submit_disabled = true; } if ( unlen < 3 ) { document.getelementbyid('username_notice').innerhtml = username_shorter; var submit_disabled = true; } if ( unlen > 14 ) { document.getelementbyid('username_notice').innerhtml = msg_un_length; var submit_disabled = true; } if ( submit_disabled ) { document.forms['formuser'].elements['submit'].disabled = 'disabled'; return false; } ajax.call( 'user.php?act=is_registered', 'username=' + username, registed_callback , 'get', 'text', true, true ); } function registed_callback(result) { if ( result == "true" ) { $("#username").parent().removeclass("params_error"); $("#username").parent().addclass("params_success"); document.getelementbyid('username_notice').innerhtml = ""; //zhouhuan document.forms['formuser'].elements['submit'].disabled = ''; } else { $("#username").parent().removeclass("params_success"); $("#username").parent().addclass("params_error"); document.getelementbyid('username_notice').innerhtml = msg_un_registered; document.forms['formuser'].elements['submit'].disabled = 'disabled'; } } function checkemail(email) { var submit_disabled = false; if (email == '') { document.getelementbyid('email_notice').innerhtml = msg_email_blank; submit_disabled = true; } else if (!utils.isemail(email)) { document.getelementbyid('email_notice').innerhtml = msg_email_format; submit_disabled = true; } if( submit_disabled ) { document.forms['formuser'].elements['submit'].disabled = 'disabled'; return false; } ajax.call( 'user.php?act=check_email', 'email=' + email, check_email_callback , 'get', 'text', true, true ); } function check_email_callback(result) { if ( result == 'ok' ) { $("#email").parent().removeclass("params_error"); $("#email").parent().addclass("params_success"); document.getelementbyid('email_notice').innerhtml = ""; //zhouhuan document.forms['formuser'].elements['submit'].disabled = ''; } else { $("#email").parent().removeclass("params_success"); $("#email").parent().addclass("params_error"); document.getelementbyid('email_notice').innerhtml = msg_email_registered; document.forms['formuser'].elements['submit'].disabled = 'disabled'; } } /* * * 处理注册用户 */ function register() { var frm = document.forms['formuser']; var username = utils.trim(frm.elements['username'].value); var email = frm.elements['email'].value; var password = utils.trim(frm.elements['password'].value); var confirm_password = utils.trim(frm.elements['confirm_password'].value); var checked_agreement = frm.elements['agreement'].checked; var msn = frm.elements['extend_field1'] ? utils.trim(frm.elements['extend_field1'].value) : ''; var qq = frm.elements['extend_field2'] ? utils.trim(frm.elements['extend_field2'].value) : ''; var home_phone = frm.elements['extend_field4'] ? utils.trim(frm.elements['extend_field4'].value) : ''; var office_phone = frm.elements['extend_field3'] ? utils.trim(frm.elements['extend_field3'].value) : ''; var mobile_phone = frm.elements['extend_field5'] ? utils.trim(frm.elements['extend_field5'].value) : ''; var passwd_answer = frm.elements['passwd_answer'] ? utils.trim(frm.elements['passwd_answer'].value) : ''; var sel_question = frm.elements['sel_question'] ? utils.trim(frm.elements['sel_question'].value) : ''; var msg = ""; // 检查输入 var msg = ''; if (username.length == 0) { msg += username_empty + '\n'; } else if (username.match(/^\s*$|^c:\\con\\con$|[%,\'\*\"\s\t\<\>\&\\]/)) { msg += username_invalid + '\n'; } else if (username.length < 3) { //msg += username_shorter + '\n'; } if (email.length == 0) { msg += email_empty + '\n'; } else { if ( ! (utils.isemail(email))) { msg += email_invalid + '\n'; } } if (password.length == 0) { msg += password_empty + '\n'; } else if (password.length < 6) { msg += password_shorter + '\n'; } if (/ /.test(password) == true) { msg += passwd_balnk + '\n'; } if (confirm_password != password ) { msg += confirm_password_invalid + '\n'; } if(checked_agreement != true) { msg += agreement + '\n'; } if (msn.length > 0 && (!utils.isemail(msn))) { msg += msn_invalid + '\n'; } if (qq.length > 0 && (!utils.isnumber(qq))) { msg += qq_invalid + '\n'; } if (office_phone.length>0) { var reg = /^[\d|\-|\s]+$/; if (!reg.test(office_phone)) { msg += office_phone_invalid + '\n'; } } if (home_phone.length>0) { var reg = /^[\d|\-|\s]+$/; if (!reg.test(home_phone)) { msg += home_phone_invalid + '\n'; } } if (mobile_phone.length>0) { var reg = /^[\d|\-|\s]+$/; if (!reg.test(mobile_phone)) { msg += mobile_phone_invalid + '\n'; } } if (passwd_answer.length > 0 && sel_question == 0 || document.getelementbyid('passwd_quesetion') && passwd_answer.length == 0) { msg += no_select_question + '\n'; } for (i = 4; i < frm.elements.length - 4; i++) // 从第五项开始循环检查是否为必填项 { needinput = document.getelementbyid(frm.elements[i].name + 'i') ? document.getelementbyid(frm.elements[i].name + 'i') : ''; if (needinput != '' && frm.elements[i].value.length == 0) { msg += '- ' + needinput.innerhtml + msg_blank + '\n'; } } if (msg.length > 0) { alert(msg); return false; } else { return true; } } /* * * 用户中心订单保存地址信息 */ function saveorderaddress(id) { var frm = document.forms['formaddress']; var consignee = frm.elements['consignee'].value; var email = frm.elements['email'].value; var address = frm.elements['address'].value; var zipcode = frm.elements['zipcode'].value; var tel = frm.elements['tel'].value; var mobile = frm.elements['mobile'].value; var sign_building = frm.elements['sign_building'].value; var best_time = frm.elements['best_time'].value; if (id == 0) { alert(current_ss_not_unshipped); return false; } var msg = ''; if (address.length == 0) { msg += address_name_not_null + "\n"; } if (consignee.length == 0) { msg += consignee_not_null + "\n"; } if (msg.length > 0) { alert(msg); return false; } else { return true; } } /* * * 会员余额申请 */ function submitsurplus() { var frm = document.forms['formsurplus']; var surplus_type = frm.elements['surplus_type'].value; var surplus_amount = frm.elements['amount'].value; var process_notic = frm.elements['user_note'].value; var payment_id = 0; var msg = ''; if (surplus_amount.length == 0 ) { msg += surplus_amount_empty + "\n"; } else { var reg = /^[\.0-9]+/; if ( ! reg.test(surplus_amount)) { msg += surplus_amount_error + '\n'; } } if (process_notic.length == 0) { msg += process_desc + "\n"; } if (msg.length > 0) { alert(msg); return false; } if (surplus_type == 0) { for (i = 0; i < frm.elements.length ; i ++) { if (frm.elements[i].name=="payment_id" && frm.elements[i].checked) { payment_id = frm.elements[i].value; break; } } if (payment_id == 0) { alert(payment_empty); return false; } } return true; } /* * * 处理用户添加一个红包 */ function addbonus() { var frm = document.forms['addbouns']; var bonus_sn = frm.elements['bonus_sn'].value; if (bonus_sn.length == 0) { alert(bonus_sn_empty); return false; } else { var reg = /^[0-9]{10}$/; if ( ! reg.test(bonus_sn)) { alert(bonus_sn_error); return false; } } return true; } /* * * 合并订单检查 */ function mergeorder() { if (!confirm(confirm_merge)) { return false; } var frm = document.forms['formorder']; var from_order = frm.elements['from_order'].value; var to_order = frm.elements['to_order'].value; var msg = ''; if (from_order == 0) { msg += from_order_empty + '\n'; } if (to_order == 0) { msg += to_order_empty + '\n'; } else if (to_order == from_order) { msg += order_same + '\n'; } if (msg.length > 0) { alert(msg); return false; } else { return true; } } /* * * 订单中的商品返回购物车 * @param int orderid 订单号 */ function returntocart(orderid) { ajax.call('user.php?act=return_to_cart', 'order_id=' + orderid, returntocartresponse, 'post', 'json'); } function returntocartresponse(result) { alert(result.message); } /* * * 检测密码强度 * @param string pwd 密码 */ function checkintensity(pwd) { var mcolor = "#fff",lcolor = "#fff",hcolor = "#fff"; var m=0; var modes = 0; for (i=0; i=48 && t <=57) { chartype = 1; } else if (t>=65 && t <=90) { chartype = 2; } else if (t>=97 && t <=122) chartype = 4; else chartype = 4; modes |= chartype; } for (i=0;i<4;i++) { if (modes & 1) m++; modes>>>=1; } if (pwd.length<=4) { m = 1; } switch(m) { case 1 : lcolor = "2px solid red"; mcolor = hcolor = "2px solid #dadada"; break; case 2 : mcolor = "2px solid #f90"; lcolor = hcolor = "2px solid #dadada"; break; case 3 : hcolor = "2px solid #3c0"; lcolor = mcolor = "2px solid #dadada"; break; case 4 : hcolor = "2px solid #3c0"; lcolor = mcolor = "2px solid #dadada"; break; default : hcolor = mcolor = lcolor = ""; break; } if (document.getelementbyid("pwd_lower")) { document.getelementbyid("pwd_lower").style.borderbottom = lcolor; document.getelementbyid("pwd_middle").style.borderbottom = mcolor; document.getelementbyid("pwd_high").style.borderbottom = hcolor; } } function changetype(obj) { if (obj.getattribute("min") && document.getelementbyid("ecs_amount")) { document.getelementbyid("ecs_amount").disabled = false; document.getelementbyid("ecs_amount").value = obj.getattribute("min"); if (document.getelementbyid("ecs_notice") && obj.getattribute("to") && obj.getattribute('fee')) { var fee = parseint(obj.getattribute("fee")); var to = parseint(obj.getattribute("to")); if (fee < 0) { to = to + fee * 2; } document.getelementbyid("ecs_notice").innerhtml = notice_result + to; } } } function validate_vcode(code){ var filter = new object; filter.code = code; ajax.call('user.php?is_ajax=1&act=ajax_validate_vcode', filter, validate_vcode_result, 'get', 'json') } function validate_vcode_result(result){ var vcode_tip = document.getelementbyid("vcode_tip"); var sms_get = document.getelementbyid("get_sms"); var vcode = document.getelementbyid("vcode"); if(result.content =='succ'){ sms_get.removeattribute("disabled"); vcode.style.display ='none'; sms_get.style.backgroundcolor = '#ff7142'; }else{ sms_get.setattribute("disabled","disabled"); vcode_tip.style.display = ''; vcode_tip.innerhtml = '* 验证码错误'; vcode_tip.style.color = 'red'; } } function send_sms(type) { if(wait == 120){ var btn = document.getelementbyid("get_sms"); btn.value = '发送中'; var filter = new object; filter.mobile = document.getelementbyid("username").value; ajax.call('user.php?act=ajax_validate_sms', filter, send_result, 'post', 'json'); } } function send_sms(){ if(wait == 120){ var btn = document.getelementbyid("get_sms"); btn.value = '发送中'; var filter = new object; filter.mobile = document.getelementbyid("username").value; ajax.call('user.php?act=ajax_validate_sms', filter, send_result, 'post', 'json'); } } function send_result(result) { var btn = document.getelementbyid("get_sms"); if (result.content == 'succ'){ document.getelementbyid("sms_tip").style.display='none'; time(btn); }else{ btn.value = '重新发送'; document.getelementbyid("sms_tip").style.display=''; document.getelementbyid("sms_tip").innerhtml='* '+result.content; } } var wait = 120; function time(btn){ if (wait===0) { btn.value = "获取验证码"; document.getelementbyid("vcode_input").value = ''; document.getelementbyid("vcode").style.display=''; document.getelementbyid("captcha").src='captcha.php?'+math.random(); wait = 120; }else{ btn.setattribute("disabled","disabled"); btn.style.backgroundcolor="#d2d2d2"; btn.style.cursor="default"; if(wait == 120){ btn.value ="发送成功"; }else{ btn.value = wait + "秒后重试"; } wait = wait-1; settimeout(function(){ time(btn); },1000); } } function rep_validate_code(code){ var filter = new object; filter.code = code; ajax.call('user.php?is_ajax=1&act=ajax_validate_vcode', filter, rep_validate_code_result, 'get', 'json') } function rep_validate_code_result(result){ var vcode_tip = document.getelementbyid("vcode_tip_reg"); var sms_get = document.getelementbyid("get_sms_rep"); var vcode = document.getelementbyid("vcode_rep"); if(result.content =='succ'){ vcode.style.display='none'; vcode_tip.style.display ='none'; sms_get.removeattribute("disabled"); sms_get.style.backgroundcolor = '#ff7142'; }else{ sms_get.setattribute("disabled","disabled"); vcode_tip.style.display = ''; vcode_tip.innerhtml = '* 验证码错误'; vcode_tip.style.color = 'red'; } } function rep_send_sms(){ if(wait == 120){ var filter = new object; filter.mobile = document.getelementbyid("username").value; var reg = /^1[34578]\d{9}$/; if (!reg.test(filter.mobile)) { alert(mobile_phone_invalid); return false; } var btn = document.getelementbyid("get_sms_rep"); btn.value = '发送中'; /* 找回密码要验证当前手机号是否是注册的 */ filter.action = document.forms['sms_repassword'].elements['act'].value; /* 已经输入过验证码 输入内容验证不通过 不用重新输入验证码 比如手机号输入错误 返回提示后 不刷新页面 验证码是不显示出来让会员重新输入 不重新输入 会员输入正确手机号后 会报验证码错误*/ if (document.getelementbyid("sms_tip_rep").style.display != 'none') { filter.no_need_vcode = 'true'; } ajax.call('user.php?act=ajax_validate_sms', filter, send_result_rep, 'post', 'json'); } } function send_result_rep(result){ var btn = document.getelementbyid("get_sms_rep"); if (result.content == 'succ'){ document.getelementbyid("sms_tip_rep").style.display='none'; time_rep(btn); }else{ btn.value = '重新发送'; document.getelementbyid("sms_tip_rep").style.display=''; document.getelementbyid("sms_tip_rep").innerhtml='* '+result.content; } } function time_rep(btn){ if (wait===0) { btn.value = "获取验证码"; document.getelementbyid("vcode_input_rep").value = ''; document.getelementbyid("vcode_rep").style.display=''; document.getelementbyid("captcha_rep").src='captcha.php?'+math.random(); wait = 120; }else{ btn.setattribute("disabled","disabled"); btn.style.backgroundcolor="#d2d2d2"; btn.style.cursor="default"; if(wait == 120){ btn.value ="发送成功"; }else{ btn.value = wait + "秒后重试"; } wait = wait-1; settimeout(function(){ time_rep(btn); },1000); } } function check_sms_form(){ var username = document.getelementbyid('username').value; var sms_code = document.getelementbyid('sms_code').value; var msg = ''; if(!username){ msg += '手机号不能为空' + '\n'; } if(!sms_code){ msg += '短信验证码不能为空' + '\n'; } if(msg.length > 0){ alert(msg); return false; } return true; } function calresult() { var amount = document.getelementbyid("ecs_amount").value; var notice = document.getelementbyid("ecs_notice"); reg = /^\d+$/; if (!reg.test(amount)) { notice.innerhtml = notice_not_int; return; } amount = parseint(amount); var frm = document.forms['transform']; for(i=0; i < frm.elements['type'].length; i++) { if (frm.elements['type'][i].checked) { var min = parseint(frm.elements['type'][i].getattribute("min")); var to = parseint(frm.elements['type'][i].getattribute("to")); var fee = parseint(frm.elements['type'][i].getattribute("fee")); var result = 0; if (amount < min) { notice.innerhtml = notice_overflow + min; return; } if (fee > 0) { result = (amount - fee) * to / (min -fee); } else { //result = (amount + fee* min /(to+fee)) * (to + fee) / min ; result = amount * (to + fee) / min + fee; } notice.innerhtml = notice_result + parseint(result + 0.5); } } }