/*
Copyright (C) 2008 ZZEE TOOLS Corp. All rights reserved.
This code may not be copied by any means or used in third party websites or software products.
*/

function ZZEEAJAX(){this.debug=false;this.reqObj=function(){try{if(window.XMLHttpRequest){return new XMLHttpRequest();}else{return new ActiveXObject("Microsoft.XMLHTTP");}}catch(e){return false;}};this.parse=function(r){if(r&&r.length){if(this.debug){alert(r);}if(r.substr(0,2)=='/*'){r=r.substring(2,r.length-2);}return eval('('+r+')');}else{return false;}};this.post=function(url,buf){var r;try{r=this.reqObj();if(!r){return false;}r.open("POST",url,false);r.setRequestHeader("Content-Type","text/plain");r.send(buf);if(r.status!=200){return false;}return this.parse(r.responseText);}catch(e){return false;}};}function App(){var T=this;var CRLF="\r\n";var ui=new ZZEEUI();T.getUI=function(){return ui;};var ajax=new ZZEEAJAX();var M='';var P='';var divMethodSelection;var divForm;var divMethodName;var divMethodHint;var divMethodForm;var divIniHelp;var divResultHelp;var divAnotherHint;var button;var box;var F;var bCopy=null;T.errorMessage=function(text,caption,type){if(!type){type=MB_OK|MB_ICONERROR;}if(!caption){caption="Error occurred";}var mb=new ZZEEMessageBox(text,caption,type);if(!mb){return false;}mb.ui=ui;mb.iconDir='zzeejs/';mb.show();};T.init=function(){divMethodSelection=ui.id('divMethodSelection');divForm=ui.id('divForm');divMethodName=ui.id('divMethodName');divMethodHint=ui.id('divMethodHint');divMethodForm=ui.id('divMethodForm');divIniHelp=ui.id('divIniHelp');divResultHelp=ui.id('divResultHelp');divAnotherHint=ui.id('divAnotherHint');button=ui.id('button');F=ui.id('form');box=F.text;bCopy=ui.id('bCopy');};function setElementValue(e,v){var t=e.tagName.toLowerCase();var i,L;if(t=='input'){if(e.type=='text'){e.value=v;}else if(e.type=='checkbox'){e.checked=v;}}else if(t=='select'){e.selectedIndex=-1;L=e.length;for(i=0;i<L;i++){if(e.options[i].value==v){e.selectedIndex=i;break;}}}}function getElementValue(e){var t=e.tagName.toLowerCase();if(t=='input'){if(e.type=='text'){return e.value;}else if(e.type=='checkbox'){return e.checked;}}else if(t=='select'){if(e.selectedIndex<0){return false;}return e.options[e.selectedIndex].value;}}function convertValue(t,v){if(t=='int'){return ui._parseInt(v);}else if(t=='bool'){return(v?1:0);}return v;}T.selectMethod=function(i){var x,a,L,n,e,p,z,j;if(!(i in METHODS)){T.errorMessage("This operation is not supported.");return;}M=i;x=METHODS[M];ui.remChildren(divMethodName);ui.text(divMethodName,x[0]);ui.remChildren(divMethodHint);try{divMethodHint.innerHTML=x[2];}catch(e){}if(P!==''){divIniHelp.style.display='none';}else{divIniHelp.style.display='block';}a=x[1];L=a.length;if(L){divMethodForm.style.display='block';i=ui.id('if.'+x[3]);if(!i){T.errorMessage("Unknown error");return;}n=i.cloneNode(true);ui.remChildren(divMethodForm);divMethodForm.appendChild(n);n.style.display='block';for(i=0;i<L;i++){p=a[i];z=p[2];e=F[p[2]];if(e){setElementValue(e,(U[z]!==null)?U[z]:p[5]);}}}else{ui.remChildren(divMethodForm);divMethodForm.style.display='none';}divForm.style.display='block';divMethodHint.style.display='block';divIniHelp.style.display='block';divMethodSelection.style.display='none';box.focus();window.scrollTo(0,0);};T.convert=function(){P=M;var x=METHODS[M],a=x[1],L=a.length,i,e,p,v,c='',r,b;b=box.value;if(!b.length){T.errorMessage("Please paste some text to the box","Text is missing",MB_ICONWARNING);return;}if(b.length>BUF_MAX_SIZE){b.length=BUF_MAX_SIZE;i=WINSOFT?"":"\nFree Windows version allows a much bigger buffer.";T.errorMessage("Maximum size allowed for text ("+BUF_MAX_SIZE+" bytes) is exceeded.\n"+i+"\nText has been truncated. Please try again now.\nPro version allows to change files of any size directly on disk.","Max size is exceeded",MB_ICONWARNING);return;}for(i=0;i<L;i++){p=a[i];e=F[p[2]];if(!e){return;}v=getElementValue(e);if(p[3]){r=new RegExp(p[4],'i');if(!r.test(v)){T.errorMessage("Value of field \""+p[1]+"\" is incorrect or missing","Field is missing",MB_ICONWARNING);return;}}v=convertValue(p[0],v);U[p[2]]=v;if(c!==''){c+='&';}c+=p[2]+'='+encodeURIComponent(v);}v='c.php?m='+M+'&'+c;r=ajax.post(v,b);if(r===false){T.errorMessage(WINSOFT?"System error occurred":"Server connection error. Please re-try again in a couple of minutes.");return;}if(!r.r){if(r.m&&r.m.length){T.errorMessage(r.m);}else{T.errorMessage("Unknown error");}return;}v=r.t;box.value=v;divMethodForm.style.display='none';divMethodHint.style.display='none';divIniHelp.style.display='none';c='Below is the result of the operation.';if(window.clipboardData){window.clipboardData.setData("Text",v);c+=" The result has already been copied to the clipboard. Now you can paste it to another program. ";}else{box.select();c+=" You need to right-click on the text below and select Copy in the menu to copy result to the clipboard.";}ui.remChildren(divResultHelp);ui.text(divResultHelp,c);if(window.clipboardData){if(bCopy){i=bCopy.cloneNode(1);if(i){divResultHelp.appendChild(i);}}}divResultHelp.style.display='block';divAnotherHint.style.display='block';};T.another=function(){divResultHelp.style.display='none';divAnotherHint.style.display='none';divForm.style.display='none';divMethodSelection.style.display='block';};T.again=function(){box.value='';T.another();};T.paste=function(){box.value=window.clipboardData.getData("Text");};T.copy=function(){window.clipboardData.setData("Text",box.value);};T.go=function(){T.convert();return false;};}var ZZEEApp=new App();
