/* =================== /* Program : Ajax Commucator Version : 1.7 Author : Neil Yuming Kuo @ Jaby Group [http://jaby.heyxu.com] Website : http://match.heyxu.com/user/neil or http://neil.heyxu.com Email : neilbaby.k at gmail.com /* =================== */ var ProcessTimer; var StepChecker=-1; var http_request = false; var Executing = false; var RequestQueue=[]; var RequestCache=[]; var RequestCacheName=""; var TryTime = 3; var RequestData=false; var AjaxFileBoxSelectedID=''; if (window.ActiveXObject)var OperSystem = 'IE'; //ie if (window.XMLHttpRequest)var OperSystem = 'MF'; //Mozilla and firefox,Safari,... document.write(''); document.write(''); document.write(''); document.write(''); document.write(''); /* Upload form ------ */ function InitAjaxFileBox(submit_link,condition){ AjaxFileBoxSelectedID=''; //only way to set innerHTML by object name (ie,mf) AjaxFileBox.document.charset ='big5'; AjaxFileBox.document.body.innerHTML="
"; } function AjaxChoiseFileObj(evt,obj_id){ var AjaxFileBoxForm = AjaxFileBox.document.getElementById('AjaxFileBoxForm'); if(!AjaxFileBoxForm)return false; var evt = evt||window.event; var frm = document.getElementById('AjaxFileBox'); var obj = AjaxFileBox.document.getElementById(obj_id); if(AjaxFileBoxSelectedID==''){ obj.style.top='0px'; obj.style.left='-25px'; frm.style.width='20px'; frm.style.height='20px'; } else if(AjaxFileBoxSelectedID!=obj_id){ var a=AjaxFileBox.document.getElementById(AjaxFileBoxSelectedID); a.style.top='100px';a.style.left='100px'; obj.style.top='0px';obj.style.left='-25px'; } AjaxFileBoxSelectedID=obj_id; frm.style.left=evt.clientX-10+document.body.scrollLeft; frm.style.top=evt.clientY-15+document.body.scrollTop; } /* Upload form File-Add */ function AjaxAddFile(file_id,func){ var AjaxFileBoxForm = AjaxFileBox.document.getElementById('AjaxFileBoxForm'); if(!AjaxFileBoxForm)return false; if(AjaxFileBoxForm.childNodes[file_id])return true; //alert(AjaxFileBoxForm.childNodes); //if(AjaxFileBoxForm.children==undefined){alert('IE supported only');return false;} //if(AjaxFileBoxForm.children(file_id))return true; var oinput = AjaxFileBox.document.createElement('input'); oinput.setAttribute('type','file'); oinput.setAttribute('id',file_id); oinput.setAttribute('name',file_id); oinput.style.position='absolute'; oinput.style.left='100px'; oinput.style.top='100px'; oinput.style.cursor='pointer'; oinput.size='1'; oinput.onreadystatechange=func; oinput.onchange =func; var d = AjaxFileBoxForm.appendChild(oinput); } /* Upload form File-Add */ function AjaxRemoveFile(file_id){ var AjaxFileBoxForm = AjaxFileBox.document.getElementById('AjaxFileBoxForm'); var ochild = AjaxFileBox.document.getElementById(file_id); if(ochild!=null) AjaxFileBoxForm.removeChild(ochild); } /* LoadBox----------- */ function ShowLoadBox(sw){ if(sw==0)var frid='AjaxLoadBox'; if(sw==1)var frid='AjaxUploadBox'; var AjaxLoadBox = document.getElementById(frid); var Img = document.getElementById("BoxImg"); AjaxLoadBox.style.top = (document.body.clientHeight/2)-(AjaxLoadBox.offsetHeight/2)+(document.body.scrollTop)-Math.floor(gBrowser.imgHeight(Img)/2); AjaxLoadBox.style.left = (document.body.clientWidth/2)-(AjaxLoadBox.offsetWidth/2)+(document.body.scrollLeft)-Math.floor(gBrowser.imgWidth(Img)/2); AjaxLoadBox.style.display = 'block'; showDiv(frid,'Help'+frid,true); } function CloseLoadBox(sw){ if(sw==0)var frid='AjaxLoadBox'; if(sw==1)var frid='AjaxUploadBox'; var AjaxLoadBox = document.getElementById(frid); AjaxLoadBox.style.display = 'none'; showDiv(frid,'Help'+frid,false); } /* Request ---------- */ function AjaxRequestSilence(iUrl,iParam){return AjaxHandle(0,1,iUrl,iParam);} function AjaxRequest(iUrl,iParam){return AjaxHandle(0,0,iUrl,iParam);} function AjaxHandle(iQueue,iSilence,iUrl,iParam){ //escape(?); if(!iQueue)RequestQueue[RequestQueue.length] = [iSilence,iUrl,iParam]; if(Executing ||RequestQueue.length<1)return true; Executing = true; iSilence = RequestQueue[0][0]; iUrl = RequestQueue[0][1]; iParam = RequestQueue[0][2]; RequestQueue = RequestQueue.slice(1); // caching or not RequestCacheName=""; for(var x=0;x0){ TryTime--; http_request.send(RequestData); ProcessTimer = setTimeout(Response,2000); } else{ http_request.abort(); // alert('回應碼:['+http_request.readyState+']\n連線請求無回應,請重試一次\n如果一直出現這個訊息請試著按 Ctrl + R 重新載入畫面。\nRequesting No Responsed! please retry again.\nIf this message is still appear,try to press Ctrl+R to fix it.'); AjaxRequestDone(1); return false; } break; case 1: // Loading case 2: // Loading done case 3: // Exchange break; case 4: // Ok switch(http_request.status){ default: //alert('錯誤碼:['+ http_request.status+']\n連線請求失敗,請重試一次\n如果一直出現這個訊息請試著按 Ctrl + R 重新載入畫面。\nRequesting failed! please retry again.\nIf this message is still appear,try to press Ctrl+R to fix it.'); AjaxRequestDone(1); break; case 200: var input = http_request.responseText.split("\n.\n"); if(input[0]!= 'AjaxResponse'){ alert(input); alert('連線請求失敗\n。\nRequesting failed!'); AjaxRequestDone(1); return false; } var content = input[5]!=null?input[5].split("\n~\n"):""; //debug var AjaxDebug=document.getElementById('AjaxDebug'); if(input[4]!=undefined && input[4]!=''){ AjaxDebug.style.display='block'; AjaxDebug.style.top = document.body.scrollTop+10; AjaxDebug.innerHTML = 'Debug Monitor:
'+input[4]; }else AjaxDebug.style.display='none'; if(RequestCacheName){ RequestCache[RequestCache.length]=[RequestCacheName,input[1],input[2],input[3],content]; } if(input[1]=='')AjaxResponse(input[2],input[3],content); else eval(input[1]+'(input[2],input[3],content);'); //eval('AjaxResponse(input[2],input[3],content)'); //AjaxResponse(input[1],input[2],content); AjaxRequestDone(0); //eval('AR(1,2,3);'); //alert(http_request.responseText); break; } break; } return true; } /* if(http_request.readyState<4 && StepChecker ==http_request.readyState){ AjaxRequestDone(1); alert('錯誤碼:'+http_request.readyState+'\n連線請求無回應,請重試一次\n如果一直出現這個訊息請試著按 Ctrl + R 重新載入畫面。\nRequesting No Responsed! please retry again.\nIf this message is still appear,try to press Ctrl+R to fix it.'); http_request.abort(); return false; }*/ //alert(StepChecker + ':' + http_request.readyState + ' Timer:' + ProcessTimer); /*StepChecker = http_request.readyState; alert(StepChecker + http_request.status);*/ function showDiv(sDivID,helpfr, bState) { var oDiv = document.getElementById(sDivID); var oIframe = document.getElementById('AjaxMask'); /* try { var oIframe = document.getElementById(helpfr); oIframe.scrolling = 'no'; } catch (e) { var oIframe = document.createElement('iframe'); //oIframe.src = '_share/html/mask.htm.php'; var oParent = oDiv.parentNode; oIframe.id = helpfr; oParent.appendChild(oIframe); }*/ oIframe.frameborder = 0; oIframe.style.position = 'absolute'; oIframe.style.top = 0; oIframe.style.left = 0; oIframe.style.display = 'none'; if (bState) { oDiv.style.display = 'block'; //oIframe.style.top = document.body.scrollTop; //oIframe.style.left = document.body.scrollLeft; //oIframe.style.width = document.body.clientWidth; //oIframe.style.height = document.body.clientHeight; oIframe.style.top = '0px'; oIframe.style.left = '0px'; oIframe.style.width = document.body.scrollWidth; oIframe.style.height = document.body.scrollHeight; oIframe.style.background = '#000000'; oIframe.style.zIndex = oDiv.style.zIndex - 1; oIframe.style.display = 'block'; gBrowser.opacity(oIframe,60); } else { oIframe.style.display = 'none'; oDiv.style.display = 'none'; } }