string.prototype.trim = function () { return this.replace(/^\s\s*/, '' ).replace(/\s\s*$/, '' ); } function change_menu_bg(i){ document.getelementbyid('menu_'+i).style.background = '#019be1'; } function change_tab(str,id,total){ for(i = 1; i <= total; i++){ document.getelementbyid(str + i).style.display = 'none'; } document.getelementbyid(str + (parseint(id) + 1)).style.display = 'block'; for(i=0; i < total; i++){ document.getelementbyid("class_title_" + i).style.bordertop = 'none'; document.getelementbyid("class_title_" + i).style.background = 'none'; document.getelementbyid("class_title_" + i).style.color = '#999'; } document.getelementbyid("class_title_" + id).style.bordertop = '2px solid #ff6100'; document.getelementbyid("class_title_" + id).style.color = '#333'; document.getelementbyid("class_title_" + id).style.background = '#ffffff'; } //客户端判断 function check_agent() { var useragentinfo = navigator.useragent; var agents = ["android", "iphone", "symbianos", "windows phone", "ipad", "ipod"]; var flag = 'pc'; for (var v = 0; v < agents.length; v++) { if (useragentinfo.indexof(agents[v]) > 0) { flag = 'mobile'; return flag; break; } } return flag; } //banner切换(三个参数分别为图片地址、宽度、高度。其中图片地址为字符串,用‘|’把单个图片地址连接起来形成的字符串。) function banner_flash( imgurl_str, width, height){ if(imgurl_str.substr(imgurl_str.length-1,1)=='|'){ imgurl_str = imgurl_str.substr(0,imgurl_str.length-1); } if(width == '100%'){ width = document.body.clientwidth; } var focus_width = width; var focus_height = height; var text_height = 0; var swf_height = focus_height + text_height; var pics = imgurl_str; var links = ''; var texts = ''; var flashcode = ''; flashcode = flashcode + ''; flashcode = flashcode + ''; flashcode = flashcode + ''; flashcode = flashcode + ''; flashcode = flashcode + ''; document.write(flashcode); } //表单必填项检查 function check_notnull(id_str,lang){ id_array = id_str.split(','); for( i = 0; i < id_array.length; i++ ){ var str = document.getelementbyid(id_array[i]).value; if(str==""){ if(lang == '_2'){ alert("submit failure required (red * flag) cannot be empty."); }else{ alert("提交失败,必填项(带红*标志的)不能为空。"); } document.getelementbyid(id_array[i]).focus(); return false; } } return true; } //图片重绘 function imagesizeauto(imageobj,iwidth,iheight){ //参数(图片,允许的宽度,允许的高度) var image=new image(); image.src=imageobj.src; if(image.width>0 && image.height>0){ if(image.width/image.height>= iwidth/iheight){ if(image.width>iwidth){ imageobj.style.width = iwidth + 'px'; imageobj.style.height=(image.height*iwidth)/image.width + 'px'; }else{ imageobj.style.width=image.width + 'px'; imageobj.style.height=image.height + 'px'; } var mtop = math.ceil((iheight - imageobj.height)/2); imageobj.style.margintop = mtop + 'px'; }else{ if(image.height>iheight){ imageobj.style.height=iheight + 'px'; imageobj.style.width=(image.width*iheight)/image.height + 'px'; imageobj.style.margin = 'auto'; }else{ imageobj.style.width=image.width + 'px'; imageobj.style.height=image.height + 'px'; imageobj.style.margin = 'auto'; var mtop = math.ceil((iheight - imageobj.height)/2); imageobj.style.margintop = mtop + 'px'; } } } } //图片重绘 function imagesizeauto2(imageobj,iwidth,iheight){ //参数(图片,允许的宽度,允许的高度) var image=new image(); image.src=imageobj.src; if(image.width>0 && image.height>0){ if(image.width/image.height >= iwidth/iheight){ imageobj.style.height = iheight + 'px'; imageobj.style.width = (image.width * iheight)/image.height + 'px'; var mleft = math.ceil((iwidth - imageobj.width)/2); imageobj.style.marginleft = mleft + 'px'; }else{ imageobj.style.width = iwidth + 'px'; imageobj.style.height = (image.height * iwidth)/image.width + 'px'; var mtop = math.ceil((iheight - imageobj.height)/2); imageobj.style.margintop = mtop + 'px'; } } } //图片自动缩小(主要用于产品展示页(pro_content.php)和图片展示页(pic_content.php)) function imagechangewidth(imageobj,widthvalue){ var img = new image(); img.src = imageobj.src; var w = img.width; var h = img.height; var rate = 1; if(img.width > 0 && img.height > 0){ if(w > widthvalue){ rate = w/widthvalue; w = widthvalue; h = h/rate; } imageobj.width = w; imageobj.height = h; } } //在线留言表单 function check_post(){ var not_num_result = check_notnull('name,mobile,title,message_content,code'); if(!not_num_result){return not_num_result;} //姓名必须为汉字 var str = document.getelementbyid("name").value; var result = checkchinese(str); if(!result){ alert("姓名必须为汉字"); return false; } //联系方式是否正确 var str = document.getelementbyid("mobile").value; var result_tel = checktel(str); var result_mobile = checkmobile(str); if(!result_tel && !result_mobile){ alert("联系方式不正确,请填写11位手机号码或者带区号的固定电话号码"); return false; } //验证码是否为数字 var str = document.getelementbyid("code").value; var result = checknum(str); if(!result){ alert("验证码必须为数字"); return false; } return true; } //======================================================================================== //是否全为汉字检查 /*正则表达式判断法 function checkchinese(str){ var reg = new regexp("[\\u4e00-\\u9fff]+","g"); return reg.test(str); } */ //unicode 判断法 function checkchinese(str){ for(i=0; i 255){ return true; }else{ return false; } } } //是否为数字检查 function checknum(str){ var reg = /^[0-9]*$/; var flag = reg.test(str); if(!flag){ return false; }else{ return true; } } /*判断ip的函数*/ function checkip(str){ var pattern=/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/; var flag_ip=pattern.test(str); if(!flag_ip){ return false; }else{ return true; } } /*判断域名的函数*/ function checkdomain(str){ var doname = /^([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)| (io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp))$/; var flag_domain = doname.test(str); if(!flag_domain){ return false; }else{ return true; } } //判断是否为电话号码 function checktel(str){ var reg = /^0[\d]{2,3}-[\d]{7,8}$/; var flag = reg.test(str); if(!flag){ return false; }else{ return true; } } //判断手机号码是否正确 function checkmobile(str){ var reg = /^1[3,5,8]\d{9}$/; var flag = reg.test(str); if(!flag){ return false; }else{ return true; } } //关闭窗口 function closecurrentpage(){ if (navigator.useragent.indexof("msie") > 0) { if (navigator.useragent.indexof("msie 6.0") > 0) { window.opener = null; window.close(); } else { window.open('', '_top'); window.top.close(); } }else if (navigator.useragent.indexof("firefox") > 0) { window.close(); } else { window.opener = null; window.open('', '_self', ''); window.close(); } } //加入购物车 function add_to_cart(id, name, icon){ var ajax; if(window.xmlhttprequest){ ajax = new xmlhttprequest(); }else{ ajax = new activexobject("microsoft.xmlhttp"); } ajax.onreadystatechange = function(){ if(ajax.readystate == 4 && ajax.status == 200){ alert(ajax.responsetext); } } var url = 'simple_cart.php?action=add&infoid=' + id + '&name=' + name + '&icon=' + icon; ajax.open('get',url); ajax.send(); } //移出购物车 function remove_from_cart(id){ var ajax; if(window.xmlhttprequest){ ajax = new xmlhttprequest(); }else{ ajax = new activexobject('microsoft.xmlhttp'); } ajax.onreadystatechange = function(){ if(ajax.readystate == 4 && ajax.status == 200){ alert(ajax.responsetext); document.getelementbyid('line_' + id).style.display = 'none'; } } var url = 'simple_cart.php?action=delete&infoid=' + id; ajax.open('get',url); ajax.send(); }