jQuery(document).ready(function () { //在要顯示信箱的地方加上一個class="getmail"的標籤, //如:信箱:載入中,請稍後... mailhead = "service"; mailbody = "bigpine.com.tw"; if ( $(".getmail").length > 0 ) { //如果當前元素存在... setTimeout(function(){ $('.getmail').hide().html(mailhead + '@' + mailbody).fadeIn('slow'); }, 5000); } }); //$(document).ready end //更換驗證碼圖片 function RefreshImage(valImageId) { var objImage = document.images[valImageId]; if (objImage == undefined) { return; } var now = new Date(); objImage.src = objImage.src.split('?')[0] + '?width=80&height=30&characters=5&s=' + new Date().getTime(); } function formatCheck(checkStr,checkType){ if(checkStr!=''&&checkType!=''){ var checkFormat = false; switch(checkType){ case 'username': checkFormat = /^[a-z]{1}[0-9a-z]{5,12}$/ ; break; case 'password': checkFormat = /^[0-9a-zA-Z\~\!\@\#\$\%\^\&\*\(\)\_\-\+\=\|\{\}\[\]\:\;\<\>\,\.\?]{6,12}$/ ; break; case 'birthday': checkFormat= /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/; break; case 'mail': checkFormat= /^([0-9a-zA-Z\.\_\+\-])+\@([0-9a-zA-Z])+\.([0-9a-zA-Z\.\-]+)$/; break; case 'num': checkFormat= /^[0-9]+$/; break; case 'text': checkFormat = /^[^0-9\~\!\@\#\$\%\^\&\*\(\)\_\-\+\=\|\{\}\[\]\:\;\<\>\,\.\?\'\"\`\/\\]+$/ ; break; case 'text2': checkFormat = /^[^\~\!\@\#\$\%\^\&\*\(\)\_\-\+\=\|\{\}\[\]\:\;\<\>\,\.\?\'\"\`\/\\]+$/ ; break; case 'word': checkFormat = /^[^\'\"\`\/\\]+$/ ; break; case 'phone': checkFormat = /^[0-9\-\+]+$/ ; break; default: } return (checkFormat) ? checkFormat.test(checkStr) : false; }else{ return true; } } function lenCheck(checkStr,lenMin,lenMax){ if(lenMin!=-1){ return (checkStr.length >= lenMin && checkStr.length <= lenMax ); }else{ return true; } } function equivalentCheck(checkStr,checkStr2){ return (checkStr == checkStr2); } function checkValue(objItem,objItemMsg,objValue,checkMod,checkMinL,checkMaxL){ if( !lenCheck(objValue,checkMinL,checkMaxL) || !formatCheck(objValue,checkMod) ){ objItemMsg.removeClass('hidden'); return false; }else{ objItemMsg.addClass('hidden'); return true; } } $(function(){ $('a#contactResetBtn').click(function(){ if(confirm('確定重填?')){ var $objForm = $('form#contactForm'); $objForm.find('input:text,textarea').val(''); var $objItemMsg = $('span.errMsg'); $objItemMsg.html('').not('.hidden').addClass('hidden'); } return false; }); $('a#contactSendBtn').click(function(){ var $objItem=null,$objItemMsg=$('span.errMsg');$objItemMsg.addClass('hidden'); $objItem = $('input#name'); if(!checkValue($objItem,$objItemMsg,$objItem.val(),'text2',2,20)){$objItemMsg.html('姓名限制輸入2~20個字元。');alert('姓名限制輸入2~20個字元。');$objItem.focus();return false;} $objItem = $('input#tel'); if(!checkValue($objItem,$objItemMsg,$objItem.val(),'phone',0,40)){$objItemMsg.html('電話限制輸入7~40個字元。');alert('電話限制輸入7~40個字元。');$objItem.focus();return false;} $objItem = $('input#email'); if(!checkValue($objItem,$objItemMsg,$objItem.val(),'mail',5,100)){$objItemMsg.html('E-mail限制輸入5~100個字元、mail格式。');alert('E-mail限制輸入5~100個字元、mail格式。');$objItem.focus();return false;} $objItem = $('input#title'); if(!checkValue($objItem,$objItemMsg,$objItem.val(),'text2',4,20)){$objItemMsg.html('主旨限制輸入4~20個字元。');alert('主旨限制輸入4~20個字元。');$objItem.focus();return false;} $objItem = $('select#classname'); if(!checkValue($objItem,$objItemMsg,$objItem.val(),'text2',1,20)){$objItemMsg.html('類別限制輸入1~20個字元。');alert('類別限制輸入1~20個字元。');$objItem.focus();return false;} $objItem = $('textarea#message'); if(!checkValue($objItem,$objItemMsg,$objItem.val(),'word',20,200)){$objItemMsg.html('諮詢內容限制輸入20~200個字元。');alert('諮詢內容限制輸入20~200個字元。');$objItem.focus();return false;} $objItem = $('input#security_code'); if(!checkValue($objItem,$objItemMsg,$objItem.val(),'text2',5,5)){$objItemMsg.html('驗證碼限制輸入5個字元。');alert('驗證碼限制輸入5個字元。');$objItem.focus();return false;} //alert('驗證格式正確!(目前無法寄出信件!)'); if(confirm('確定送出?')){ var $objForm = $('form#contactForm'); $objItemMsg.html('傳送中...!').removeClass('hidden'); $.ajax({ type: "POST", url: 'ajaxSend.php', data: $objForm.serialize(), dataType: "html", error: function(){$objItemMsg.html('傳送資料時發生錯誤!');}, success: function(msg){ if(msg=='success'){ $objForm.find('input:text,textarea').val(''); $('a.imgCaptchaChange').click(); $objItemMsg.html('成功寄出信件!');alert('成功寄出信件!'); }else if(msg=='errorFormat'){ $objItemMsg.html('輸入了不正確的格式!');alert('輸入了不正確的格式!'); }else if(msg=='error'){ $objForm.find('input#security_code').focus(); $objItemMsg.html('驗證碼錯誤!');alert('驗證碼錯誤!'); }else{ $objItemMsg.html('寄送信件發生錯誤!');alert('寄送信件發生錯誤!'); } } }); } return false; }); }); function openwindow(url,name,iWidth,iHeight){ var url; //網頁位置; var name; //網頁名稱; var iWidth; //視窗的寬度; var iHeight; //視窗的高度; var iTop = (window.screen.availHeight-30-iHeight)/2; //視窗的垂直位置; var iLeft = (window.screen.availWidth-10-iWidth)/2; //視窗的水平位置; window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',status=no,location=no,status=no,menubar=no,toolbar=no,resizable=no,scrollbars=no'); }