//<!--
/*
 * GTAjax.js 
 * @abstract: General-Targeted Ajax 
 * @author: wadelau@gridtask.com,wadelau@gmail.com
 * @since: 2006-2-17 14:04
 * @update: 2006-10-11 19:12
 * @code: 1.91 // a.bc , funcs added b+, errs updated c+ 
 * @NOTICE: DO NOT USE THIS COMMERICALLY WITHOUT AUTHOR'S PAPER AUTHORIZATION
 */
var sRe="";
var iTm=0;
var sTd=0;
var sPtWi="myPOstWIn";
var sUrl="?";
var sMtd="GET";
var iItl=1000;
var isWtRp=false;
var sForm="";
var sFld="";
var sBkCt="";
var nEmt=null;
var wFl=false;
var tErr=new Error();
var nEmt2=null;
var gtFDiv="icld200607232107";
var tBro=navigator.appName;
var myBdTt=null;
var cA=new Array();
var vA=new Array();
vA["sbv"]="Submit";
vA["mul"]=3*60*1000;
vA["ta"]="";
vA["rn"]=" Return ";
vA["ib"]=false;
vA["rdo"]=false;
vA["ic"]=true;
vA["cf"]="";
vA["ff"]=false;
vA["pb"]=true;
vA["bl"]=true;
vA["fft"]="fftag";
function GTAjax(_1){
if(!isWtRp){
_PSD();
sForm=_1;
sRe="";
var _2="";
var _3=false;
_DBG(vA["ib"],"sForm",_1);
try{
var _4=document.forms[sForm];
}
catch(eFNm){
}
if(_4!=null&&typeof _4!="undefined"){
_DBG(vA["ib"],"ta-1",vA["ta"]);
eval("document.getElementById(\""+sForm+"\").onsubmit="+function(){
return false;
});
try{
if(vA["ta"]==""&&vA["rdo"]==false){
var _5="targetarea is empty.";
if(typeof _4!="undefined"){
vA["ta"]=_4.parentNode.getAttribute("id");
}else{
tErr.message=_5;
return _RGT("formElement",tErr);
}
if(typeof vA["ta"]=="undefined"||vA["ta"]==""||vA["ta"]==null){
tErr.message=_5;
return _RGT("formElement1",tErr);
}else{
_DBG(vA["ib"],"ta",vA["ta"]);
}
}
}
catch(e8){
return _RGT("parentArea",e8);
}
try{
sUrl=_4.action;
sMtd=_4.method;
for(var i=_4.elements.length-1;i>=0;i--){
var el=_4.elements[i];
if(el.tagName.toLowerCase()=="select"){
for(var j=0;j<el.options.length;j++){
var op=el.options[j];
if(op.selected){
if(typeof cA[el.name]!="undefined"){
if(!_CFM(sForm,el.name,op.value,cA[el.name])){
return false;
}
}
_2+="&"+encodeURIComponent(el.name)+"="+encodeURIComponent(op.value);
}
}
}else{
if(el.tagName.toLowerCase()=="textarea"){
if(typeof cA[el.name]!="undefined"){
if(!_CFM(sForm,el.name,el.value,cA[el.name])){
return false;
}
}
_2+="&"+encodeURIComponent(el.name)+"="+encodeURIComponent(el.value);
}else{
if(el.tagName.toLowerCase()=="input"){
if(el.type.toLowerCase()=="checkbox"||el.type.toLowerCase()=="radio"){
if(el.checked){
_2+="&"+encodeURIComponent(el.name)+"="+encodeURIComponent(el.value);
}
if(typeof cA[el.name]!="undefined"){
if(!_CFM(sForm,el.name,el.value,cA[el.name])){
return false;
}
}
}else{
if(el.type.toLowerCase()=="file"){
if(typeof cA[el.name]!="undefined"){
if(!_CFM(sForm,el.name,el.value,cA[el.name])){
return false;
}
}
if(el.value!=""&&el.value!=null){
wFl=true;
_DBG(vA["ib"],"fileUpload2",wFl);
if(eval(cA.length)==0){
break;
}
}
}else{
if(el.type.toLowerCase()!="button"&&el.type.toLowerCase()!="submit"){
if(typeof cA[el.name]!="undefined"){
if(!_CFM(sForm,el.name,el.value,cA[el.name])){
return false;
}
}
_2+="&"+encodeURIComponent(el.name)+"="+encodeURIComponent(el.value);
}else{
if(el.type.toLowerCase()=="submit"){
if(el.name){
sFld=el.name;
}else{
sFld=el.id;
}
vA["sbv"]=el.value;
eval("document.getElementById('"+sFld+"').disabled =true");
eval("document.getElementsByName('"+sFld+"').disabled =true");
_SAY(sFld,"Data Collecting",false);
}
}
}
}
}
}
}
}
}
catch(e2){
return _RGT("formElement3",e2);
}
}else{
_DBG(vA["ib"],"handleurl",sForm);
try{
if(vA["ta"]==""&&vA["rdo"]==false){
var _a=document.links;
var _b="";
for(var i=0;i<_a.length;i++){
_b=_a[i].href;
if(_b.indexOf(sForm)>-1){
_4=_a[i];
sUrl=sForm;
break;
}
}
var _5="targetarea is empty.";
if(typeof _4!="undefined"){
vA["ta"]=_4.parentNode.getAttribute("id");
}else{
tErr.message=_5;
return _RGT("formElement2",tErr);
}
if(typeof vA["ta"]=="undefined"||vA["ta"]==""||vA["ta"]==null){
tErr.message=_5;
return _RGT("formElement3",tErr);
}else{
_DBG(vA["ib"],"ta",vA["ta"]);
}
_a=null;
_4=null;
sBkCt=document.getElementById(vA["ta"]).innerHTML;
}else{
if(vA["ta"]!=""){
if(!document.getElementById(vA["ta"])){
tErr.message="cant find target:["+vA["ta"]+"].";
return _RGT("invalidta",tErr);
}
}
}
if(sUrl=="?"){
sUrl=sForm;
}
}
catch(e9){
return _RGT("parentElement",e9);
}
}
if(wFl||vA["ff"]){
try{
_SAY(sFld,"Loading data...",false);
var _c=(new Date).getMilliseconds();
sPtWi=sPtWi+_c;
var _d="<iframe name=\""+sPtWi+"\" id=\""+sPtWi+"\"  "+"style=\"border:0px;width:0px;height:0px\"></iframe>"+"";
var _e=null;
if(document.getElementById(gtFDiv)){
_e=document.getElementById(gtFDiv);
}else{
_DBG(vA["ib"],"iframefail",document.getElementById(gtFDiv).innerHTML);
}
nEmt=document.createElement("div");
nEmt.setAttribute("id","icld"+sPtWi);
_e.appendChild(nEmt);
document.getElementById("icld"+sPtWi).innerHTML=_d;
var _f=document;
var fgt=_f.frames?_f.frames[sPtWi]:_f.getElementById(sPtWi);
fgt.src="about:blank";
_SUB(sForm,sUrl,sPtWi,vA["ib"],vA["ff"]);
isWtRp=true;
sTd=setTimeout("_LOP()",iItl);
_d=null;
_c=null;
_DBG(vA["ib"],"iframeListen","starting");
}
catch(e4){
//return _RGT("fileUpload",e4);
}
}else{
var _11=null;
var _12=false;
_SAY(sFld,"Initiating",false);
try{
if(window.XMLHttpRequest){
_11=new XMLHttpRequest();
_DBG(vA["ib"],"xmlhttp1",_11);
}else{
if(window.ActiveXObject){
try{
_11=new ActiveXObject("Msxml2.XMLHTTP");
_DBG(vA["ib"],"xmlhttp2",_11);
}
catch(e){
try{
_11=new ActiveXObject("Microsoft.XMLHTTP");
_DBG(vA["ib"],"xmlhttp3",_11);
}
catch(e1){
_SAY(sFld,vA["sbv"],true);
vA["ff"]=true;
sTd=setTimeout("_LOP()",iItl);
}
}
}
}
}
catch(e39){
_SAY(sFld,vA["sbv"],true);
vA["ff"]=true;
sTd=setTimeout("_LOP()",iItl);
}
_SAY(sFld,"Communicating",false);
sMtd=sMtd.toUpperCase();
if(_11!=null&&typeof _11!="undefined"){
_SAY(sFld,"Transacting",false);
try{
if(sMtd=="GET"){
if(!vA["ic"]){
var ici=Math.random();
_2+="&ici="+ici;
ici=null;
}
sUrl+=(sUrl.indexOf("?")>0)?"&":"?";
sUrl+=_2;
_11.open(sMtd,sUrl,_12);
if(!vA["ic"]){
_11.setRequestHeader("If-Modified-Since","Sat, 1 Jan 2000 00:00:00 GMT");
}
_2=null;
}else{
_11.open(sMtd,sUrl,_12);
_11.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
_11.setRequestHeader("Accept","text/*");
_11.setRequestHeader("Accept-Language",navigator.language);
}
_DBG(vA["ib"],"sMtd",sMtd+",sUrl: "+sUrl+", sPara:"+_2);
_11.onreadystatechange=function(){
if(_11.readyState==4&&!_3){
_3=true;
sRe=_11.responseText;
}else{
_SAY(sFld,"Loading",false);
_DBG(vA["ib"],"sRe","waiting content....");
}
};
_11.send(_2);
if(sRe==""){
sRe=_11.responseText;
}
}
catch(e3){
_SAY(sFld,vA["sbv"],true);
vA["ff"]=true;
sTd=setTimeout("_LOP()",iItl);
}
_11=null;
}
}
if(_3){
_SAY(sFld,"Loaded Successfully",false);
}
}else{
try{
if(!_f){
var _f=document;
var fgt=_f.frames?_f.frames[sPtWi]:_f.getElementById(sPtWi);
}
var pgt=fgt.document||fgt.contentWindow.document;
sRe=pgt.body.innerHTML;
if(tBro.indexOf("Opera")>-1){
sRe=sRe.replace(/\n{3,}/,"");
}
_DBG(vA["ib"],"sRe",sRe);
if(sRe==""){
if(iTm<vA["mul"]){
iTm+=iItl;
sTd=setTimeout("_LOP()",iItl);
}else{
_DBG(vA["ib"],"connTimeOut","connection timeout");
}
}else{
window.clearTimeout(sTd);
}
}
catch(e7){
if(vA["ib"]){
e7.message+="\nmsg not ready, keep waiting on....\n";
_RPT("accessRe",e7);
}
sTd=setTimeout("_LOP()",iItl);
}
}
if(sRe!=""){
_SAY(sFld,vA["sbv"],true);
try{
if(nEmt2){
if(myBdTt!=null&&typeof myBdTt!="undefined"){
try{
myBdTt.removeChild(nEmt2);
}
catch(erm){
}
}else{
document.body.removeChild(nEmt2);
}
nEmt2=null;
}
if(sFld!=""&&!vA["rdo"]){
if(vA["bl"]){
sBkCt=document.getElementById(vA["ta"]).innerHTML;
sRe+="&nbsp;&nbsp;<a href=\"javascript:goGTAjaxBack('"+vA["ta"]+"');\">"+"<font face=\"Wingdings 3\">@</font>"+vA["rn"]+"</a><br/>&nbsp;";
}
}
if(wFl||vA["ff"]||(!wFl&&!vA["rdo"])){
document.getElementById(vA["ta"]).innerHTML=sRe;
}
_RGT("done",tErr);
return sRe;
}
catch(e5){
return _RGT("finishJob",e5);
}
}else{
if(!isWtRp){
_DBG(vA["ib"],"serverResponse"," emptyValue");
}
}
return sRe;
}
function _LOP(){
GTAjax(sForm);
}
function _DBG(ib,_16,_17){
if(ib){
window.alert("the "+_16+" is: "+_17);
}
}
function _RPT(_18,_19){
try{
var _1a="err@GTAjax: "+_18;
if(_19.name){
_1a+="\n name:"+_19.name+"\n message:"+_19.message;
if(tBro.indexOf("Explorer")!=-1){
_1a+="\n location:"+_19.location;
}
_1a+="\n description:"+_19.description;
}else{
_1a=_19;
}
//window.alert(_1a);
}
catch(rpte){
window.alert("_RPT: "+rpte+", sObj:"+(typeof _19)+", sTag: "+_18);
return false;
}
}
function _SAY(_1b,_1c,_1d){
if(_1b!=null&&typeof _1b!="undefined"&&_1b!=""){
var _1e="....";
if(_1d){
eval("document.getElementById('"+_1b+"').disabled =false");
eval("document.getElementsByName('"+_1b+"').disabled = false");
}
if(_1c!=vA["sbv"]){
_1c+=_1e;
}
eval("document.getElementById('"+_1b+"').value ='"+_1c+"'");
eval("document.getElementsByName('"+_1b+"').value='"+_1c+"'");
}else{
if(_1b==""&&!vA["rdo"]){
}
}
}
function _SUB(_1f,_20,_21,ib,fft){
var _24=null;
if(document.getElementById(_1f)){
_24=document.getElementById(_1f);
}else{
var _25="myff200607251525";
var _26=_25+"_f";
try{
if(!document.getElementById(_25)){
nEmt=document.createElement("div");
nEmt.setAttribute("id",_26);
document.body.appendChild(nEmt);
document.getElementById(_26).innerHTML="<form id=\""+_25+"\" name=\""+_25+"\"></form>";
}
_24=document.getElementById(_25);
}
catch(efrmdiv){
_RGT("postFormInit",efrmdiv);
}
}
_24.lang=navigator.language;
if(wFl){
_24.encoding="multipart/form-data";
}else{
_24.encoding="application/x-www-form-urlencoded";
}
_24.target=_21;
if(_20.indexOf(".htm")>0||_20.indexOf(".txt")>0){
_24.method="GET";
}else{
_24.method="POST";
}
if(fft){
_20+=(_20.indexOf("?")>0)?"&":"?";
_20+=vA["fft"]+"=1";
}
_24.action=_20;
_24.submit();
_DBG(vA["ib"],"_SUB",_1f+":"+_24.method+":"+_20+":"+_21+",ff:["+fft+"]");
_24=null;
}
function _RGT(_27,_28){
if(_27!=""&&_27!="done"){
_RPT(_27,_28);
}
if(_27!="done"){
_SAY(sFld,vA["sbv"],true);
}
if(nEmt2){
if(myBdTt!=null&&typeof myBdTt!="undefined"){
try{
myBdTt.removeChild(nEmt2);
}
catch(erm){
}
}else{
document.body.removeChild(nEmt2);
}
}
iTm=0;
sTd=0;
sUrl="?";
sMtd="GET";
isWtRp=false;
sForm="";
sFld="";
nEmt=null;
wFl=false;
tErr=new Error();
nEmt2=null;
myBdTt=null;
cA=new Array();
vA=new Array();
vA["sbv"]="Submit";
vA["mul"]=3*60*1000;
vA["ta"]="";
vA["rn"]=" Return ";
vA["ib"]=false;
vA["rdo"]=false;
vA["ic"]=true;
vA["cf"]="";
vA["ff"]=false;
vA["pb"]=true;
vA["bl"]=true;
vA["fft"]="fftag";
return false;
}
function goGTAjaxBack(_29){
document.getElementById(_29).innerHTML=sBkCt;
}
function setGTAjax(_2a,_2b){
var _2c=new Array();
_2c["subbtnval"]="sbv";
_2c["maxuploadfiletime"]="mul";
_2c["targetarea"]="ta";
_2c["returnname"]="rn";
_2c["isdebug"]="ib";
_2c["returndataonly"]="rdo";
_2c["iscache"]="ic";
_2c["chkform"]="cf";
_2c["forceframe"]="ff";
_2c["processbar"]="pb";
_2c["backlink"]="bl";
_2c["forceframetag"]="fft";
try{
if(_2a=="chkform"){
if(_2b!=null&&_2b!=""){
var _2d=_2b.split(":",3);
if(_2d[0]!=null&&_2d[0]!=""){
if(_2d[1]==null||_2d[1]==""){
_2d[1]="notvalue=";
}
if(_2d[2]==null||_2d[2]==""){
_2d[2]=" has not expected value.";
}
cA[_2d[0]]=_2d[1]+","+_2d[2];
}
if(cA.length==0){
cA[100]="1";
}
}
}else{
vA[_2c[_2a]]=_2b;
}
if(vA["ff"]&&vA["rdo"]){
tErr.message="rdo cannot be with ff!";
return _RGT("setGTAjax2",tErr);
}
}
catch(e6){
return _RGT("setGTAjax",e6);
}
}
function _PSD(){
var _2e=0;
try{
if(!document.getElementById(gtFDiv)){
var _2f="position:absolute;top:0px;left:0px;z-index:11";
if(vA["ta"]!=""){
myBdTt=document.getElementById(vA["ta"]);
}
nEmt2=document.createElement("div");
nEmt2.setAttribute("id",gtFDiv);
nEmt2.style.cssText=_2f;
if(myBdTt!=null){
myBdTt.appendChild(nEmt2);
}else{
document.body.appendChild(nEmt2);
}
_2e=1;
}
if(vA["pb"]){
var ns=(tBro.indexOf("Netscape")!=-1);
var pX,pY;
pY=ns?pageYOffset:document.documentElement&&document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
var _32="&nbsp;Processing...";
var _33="<div id=\""+gtFDiv+"_x\" style=\"position:absolute;left:0;top:"+pY+";height:"+"20px;background-color:#FFFF99;color:#ff0000;font-size:12pt;font-weight:700;z-index:11\">"+_32+"</div>";
document.getElementById(gtFDiv).innerHTML=_33;
}
}
catch(eDiv){
return _RGT("prcsDiv",eDiv);
}
}
function _CFM(_34,_35,_36,_37){
try{
var _38=_37.split(",",2);
var _39=_38[0];
var _3a=_38[1];
var _3b=0;
var _3c=true;
if(_39.indexOf("+")>-1){
_39=_39.replace("+","");
if(eval(_36.length)==_3b){
_3c=false;
}
}
if(_3c){
if(_39.indexOf("=")>-1){
var _3d=_39.split("=");
_39=_3d[0];
if(_3d[0]==null||_3d==""){
_3d[1]=0;
}
_3b=_3d[1];
}
switch(_39){
case "req":
case "required":
case "notvalue":
if(eval(_36.length)==_3b){
_3c=false;
}
break;
case "maxlength":
case "maxlen":
if(eval(_36.length)>_3b){
_3c=false;
}
break;
case "minlength":
case "minlen":
if(eval(_36.length)<_3b){
_3c=false;
}
break;
case "alnum":
case "alphanumeric":
var _3e=_36.search(/[^A-Za-z0-9]/);
if(_36.length>0&&_3e>=0){
_3c=false;
}
break;
case "num":
case "numeric":
var _3e=_36.search(/[^0-9]/);
if(_36.length>0&&_3e>=0){
_3c=false;
}
break;
case "alphabetic":
case "alpha":
var _3e=_36.search(/[^A-Za-z]/);
if(_36.length>0&&_3e>=0){
_3c=false;
}
break;
case "alnumhyphen":
var _3e=_36.search(/[^A-Za-z0-9\-_]/);
if(_36.length>0&&_3e>=0){
_3c=false;
}
break;
case "email":
if(_36==""||_36.match(/^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/)==null){
_3c=false;
}
break;
case "lt":
case "lessthan":
if(isNaN(_36)||(eval(_36)>=_3b)){
_3c=false;
}
break;
case "gt":
case "greaterthan":
if(isNaN(_36)||(eval(_36)<=_3b)){
_3c=false;
}
break;
case "regexp":
if(_36.length>0){
if(!_36.match(_3b)){
_3c=false;
}
}
break;
default:
_3a="Unpredefined form validate type: "+_39;
_3c=false;
}
}
if(!_3c){
window.alert("Attention: "+_3a);
eval("document."+_34+"."+_35+".style.background='#FFFF99'");
eval("document."+_34+"."+_35+".focus()");
return _RGT("",tErr);
}
return _3c;
}
catch(echk){
return _RGT("formValidate",echk);
}
}
//-->
