﻿ function PT_ajaxRequest(url,callback,postParams){var xhr=PT_getXHR();if(xhr==null)return;var isPost=(postParams!=null);xhr.onreadystatechange=function(){PT_XHRStateChangeHandler(xhr,callback);};xhr.open(isPost?"POST":"GET",url,true);if(isPost)xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xhr.send(postParams);}function PT_loadFrameAjax(url,destination,onload,postParams){if(destination!=null&&typeof destination=="string"){destination=document.getElementById(destination);}var callback=function(xhr,status){if(status&&destination!=null){var loadedText=xhr.responseText;destination.innerHTML=loadedText;var newScripts=destination.getElementsByTagName("script");for(var ix=0;ix<newScripts.length;ix++){eval(newScripts[ix].innerHTML);}}if(onload)onload(xhr,status);};PT_ajaxRequest(url,callback,postParams);}function PTButtonCmdAjax(url,destination,onload,cmd,controlList){var postParams="ptButtonCmd="+cmd+"&ptButtonValidate=false";var form=document.getElementById('_pttmf');if(controlList){var controlsToGet="^"+controlList.replace(",","$|^").replace("*",".*")+"$";var controlsRE=new RegExp(controlsToGet,"i");for(var i=0;i<form.elements.length;i++){var el=form.elements[i];if(el.id.search(controlsRE)!=-1){var ctlVal=PT_getControlValue(el);if(ctlVal!=null){postParams+="&"+el.name+"="+ctlVal;}}}}PT_loadFrameAjax(url,destination,onload,postParams);}function PT_XHRStateChangeHandler(xhr,userCallback){if(xhr.readyState!=4)return;userCallback(xhr,xhr.status==200);}function PT_getXHR(){if(window.XMLHttpRequest){try{return new XMLHttpRequest();}catch(e){return null;}}else if(window.ActiveXObject){try{return new ActiveXObject("Microsoft.XMLHTTP");}catch(e){return null;}}}function PT_getControlValue(ctl){switch(ctl.type){case"checkbox":case"radio":if(!ctl.checked)return null;break;case"select-one":return ctl.options[ctl.selectedIndex].value;}return ctl.value;}function PT_ajaxShowAlert(xhr,status){if(status){var loadingDiv=document.createElement("DIV");document.body.appendChild(loadingDiv);loadingDiv.style.position="absolute";loadingDiv.style.top=(document.body.scrollTop+155)+"px";loadingDiv.style.left=(document.body.scrollLeft+100)+"px";loadingDiv.innerHTML=xhr.responseText;}else{alert("Ajax error:"+xhr.statusText);}}var PT_nextUploadFileIndex=0;function PT_ajaxPrepareToUploadFile(parentEl,msgGuid,fileChosenCallback){var frm=document.createElement("form");parentEl.appendChild(frm);frm.method="post";frm.enctype="multipart/form-data";frm.encoding="multipart/form-data";frm.action=PTU_dest;var fileCtl=document.createElement("input");fileCtl.type="file";fileCtl.name="fileCtl";fileCtl.onchange=function(evt){fileChosenCallback(fileCtl);};frm.appendChild(fileCtl);frm.style.margin="0";PT_addHiddenField(frm,"uf_msgGuid",msgGuid);PT_addHiddenField(frm,"ptButtonCmd","cmdUploadFile(uf)");PT_addHiddenField(frm,"ptButtonValidate","false");}function PT_ajaxUploadFile(frm,fileLoadedCallback){var index=PT_nextUploadFileIndex++;var frameName="PTU_frame_"+index;var ifr=document.createElement("iframe");ifr.style.height=0;ifr.style.width=0;document.body.appendChild(ifr);ifr.id=frameName;frames[frames.length-1].name=frameName;frm.target=frameName;var ifrLoaded=function(evt){var ifrDoc=PT_getIFrameDoc(ifr);var resultsDoc=ifrDoc.body.innerHTML;if(resultsDoc.substring(0,6)=="Error:"){fileLoadedCallback(resultsDoc);}else{var results=new Object();results["docSizeKB"]=PT_getAttribute(resultsDoc,"docSize");results["docGuid"]=PT_getAttribute(resultsDoc,"cguid");results["currHeight"]=PT_getAttribute(resultsDoc,"height");results["currWidth"]=PT_getAttribute(resultsDoc,"width");results["mimeType"]=PT_getAttribute(resultsDoc,"mimeType");results["isImage"]=results["mimeType"].substr(0,6)=="image/";results["index"]=index;fileLoadedCallback(null,results);}if(frm&&frm.parentNode)frm.parentNode.removeChild(frm);if(ifr)window.setTimeout("var ifr=document.getElementById('"+ifr.id+"');ifr.parentNode.removeChild(ifr);",0);};if(ifr.addEventListener){ifr.addEventListener("load",ifrLoaded,false);}else{ifr.attachEvent("onload",ifrLoaded);}frm.submit();}function PT_getAttribute(doc,attrName){var re=new RegExp(attrName+'="(.+?)"');var m=re.exec(doc);if(!m||m.length==0)return"";return m[1];}function PT_addHiddenField(frm,name,value){var ctl=document.createElement("input");ctl.type="hidden";ctl.name=name;frm.appendChild(ctl);ctl.value=value;}