
function setValue(res,divid){clipper_AJAX.setValueToTargetID(unescape(res),divid,'html')}
function clipper_AJAX(){}
clipper_AJAX.initHttpReq=function(){var req;if(window.XMLHttpRequest){req=new XMLHttpRequest();}
if(!req){var activeXList=new Array("Msxml2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP")
for(var i=0;i<activeXList.length&&!req;i++){try{req=new ActiveXObject(activeXList[i]);break;}catch(e){}}}
if(!req){return false;}
return req;}
clipper_AJAX.sendHttpReq=function(url,async,callBackFunction){var req;req=clipper_AJAX.initHttpReq();if(req){if(async==true){req.onreadystatechange=function(){clipper_AJAX.receiveHttpReq(url,async,req,callBackFunction);}}
req.open("GET",url,async);req.send(null);if(async==false){return clipper_AJAX.receiveHttpReq(url,async,req,callBackFunction);}}else{alert("No HttpRequest handler could be created!\n"+"Url:"+url+"");return false;}}
clipper_AJAX.receiveHttpReq=function(url,async,res,callBackFunction){if(res.readyState==4){if(res.status==200){if(callBackFunction==''){return res;}else{clipper_AJAX.returnCallBackFunction(res,callBackFunction);}}else{alert("There was a problem receiving the data!\n"+"Url:"+url+"\n"+"Status:"+res.statusText);return false;}}}
clipper_AJAX.returnCallBackFunction=function(res,callBackFunction){var i;if(callBackFunction==''){alert("There was a problem processing the url data!\n"+"Error:No callBackFunction defined");return false;}
i=callBackFunction.indexOf('(');if(i==-1){callBackFunction=callBackFunction+"(res)";}
i=callBackFunction.indexOf('(');if(eval('window.'+callBackFunction.substring(0,i))){eval(callBackFunction);}else{alert("There was a problem processing the url data!\n"+"Error:function "+callBackFunction+" not defined");return false;}}
clipper_AJAX.include=function(file){var script;var element;script=document.createElement('script');script.src=file;script.type='text/javascript';script.defer=true;element=document.getElementsByTagName('head');element.item(0).appendChild(script);}
clipper_AJAX.setValueToTargetID=function(res,targetID,targetType){var v;var tType;var tID;tType=targetType.toLowerCase();tID=targetID;if(typeof(res.responseText)!="undefined"){v=res.responseText;}else{v=res.toString();}
if(v.length>0&&v.charCodeAt(v.length-1)==10){v=v.slice(0,-1);}
if(tType=="html"||tType=="innerhtml"){var element=document.getElementById(tID);if(element!=null){element.innerHTML=v;}else{alert("There was a problem setting the XML data!\n"+"Error:ID "+tID+" not found on document");return false;}}else if(tType=="field"){var element=document.getElementById(tID);if(element!=null){element.value=v;}else{alert("There was a problem setting the XML data!\n"+"Error:Field "+tID+" not found on document");return false;}}else if(tType=="function"){clipper_AJAX.returnCallBackFunction(v,tID);}else if(tType=="var"){if(typeof(window[tID])!="undefined"){eval(tID+"="+"v");}else{alert("There was a problem setting the XML data!\n"+"Error:var "+tID+" not found on document");return false;}}else if(tType=="alert"){alert(v);}else if(tType=="return"){return v;}else{alert("There was a problem setting the XML data!\n"+"Error:tType "+tType+" not supported");return false;}}
clipper_AJAX.returnValuesInViewByColsNo=function(res,keyValue,keyColNo,returnColsNo,returnMaxEntries,callBackFunction){var resXML;var resVal;if(typeof(res.responseXML)=="undefined"){return false;}
resXML=res.responseXML;resVal=clipper_AJAX.GetValuesInXMLViewByColsNo(resXML,returnColsNo,returnMaxEntries);clipper_AJAX.returnCallBackFunction(resVal,callBackFunction);}
clipper_AJAX.GetValuesInXMLViewByColsNo=function(xmlDoc,sourceColsNo,sourceMaxEntries){var itemsT;var itemT;var colsT;var colT;var colNoArray;var colNoT;var colArrayT;var valueArray;var maxEntries;if(typeof(xmlDoc)=="undefined"||typeof(xmlDoc.getElementsByTagName)=="undefined"){return false;}
if(sourceColsNo!=""){colNoArray=sourceColsNo.split(',')}
if(sourceMaxEntries==""){maxEntries=0;}else{maxEntries=parseInt(sourceMaxEntries);}
itemsT=xmlDoc.getElementsByTagName("viewentry");if(itemsT.length==0){return"";}
valueArray=new Array();for(var i=0;i<itemsT.length;i++){colArrayT=new Array();itemT=itemsT[i];colsT=itemT.getElementsByTagName("text");if(sourceColsNo!=""){for(var j=0;j<colNoArray.length;j++){colT="";colNoT=parseInt(colNoArray[j]);if(typeof(colsT[colNoT])!="undefined"){if(colsT[colNoT].hasChildNodes()){colT=colsT[colNoT].childNodes[0].nodeValue;}}else{alert("There was a problem processing the xml view!\n"+"Error:Col. No. "+colNoT+" not defined in xml view");return false;}
colArrayT[j]=colT;}}else{for(var k=0;k<colsT.length;k++){colT="";if(colsT[k].hasChildNodes()){colT=colsT[k].childNodes[0].nodeValue;}
colArrayT[k]=colT;}}
if(maxEntries==1&&sourceColsNo!=""&&colNoArray.length==1){return colArrayT[0];}else if(maxEntries==1){return colArrayT;}else if(sourceColsNo!=""&&colNoArray.length==1){valueArray[i]=colArrayT[0];}else{valueArray[i]=colArrayT;}}
return valueArray;}
clipper_AJAX.addOptionsToSelectByArray=function(sourceArray,sortValuesByTitle,targetID,addMethod,defaultValues){var TitleArray=new Array();var ValueArray=new Array();if(!clipper_AJAX.isArray(sourceArray)){return false}
clipper_AJAX.splitArrayInTo(sourceArray,TitleArray,ValueArray);clipper_AJAX.uniqSelect(TitleArray,ValueArray);if(sortValuesByTitle==true||sortValuesByTitle=="true"){clipper_AJAX.sortSelect(TitleArray,ValueArray);}
clipper_AJAX.addOptionsToSelect(TitleArray,ValueArray,targetID,addMethod,defaultValues);}
clipper_AJAX.addOptionsToSelect=function(TitleArray,ValueArray,targetID,addMethod,defaultValues){var j;var addM=addMethod.toLowerCase();var selectedArray="";select=document.getElementById(targetID);if(select==null){alert("There was a problem appending the XML data!\n"+"Error:targetID "+targetID+" not found on document");return false;}
if(defaultValues!="undefined"&&defaultValues!=""){selectedArray=defaultValues.split(",");trimArray(selectedArray);}
if(addM=="append"||addM==""){j=select.length;}else if(addM=="replace"){j=0;}else if(addM=="keepfirst"){j=1;}else{j=parseInt(addM);}
for(var i=0;i<TitleArray.length;i++){select.options[j]=new Option(TitleArray[i],ValueArray[i]);if(selectedArray.length!=0&&clipper_AJAX.isInArray(selectedArray,ValueArray[i])){select.options[j].selected=true;}
j++;}
while(select.length>j){select.remove(j);}}
clipper_AJAX.uniqSelect=function(TitleArray,ValueArray){var ValueAT=new Array();var TitleAT=new Array();var j=0;for(var i=0;i<ValueArray.length;i++){if(!clipper_AJAX.isInArray(ValueAT,ValueArray[i])){ValueAT[j]=ValueArray[i];TitleAT[j]=TitleArray[i];j++;}}
for(var k=0;k<ValueAT.length;k++){ValueArray[k]=ValueAT[k];TitleArray[k]=TitleAT[k];}
ValueArray.splice(k,ValueArray.length-k+1);TitleArray.splice(k,TitleArray.length-k+1);}
clipper_AJAX.sortSelect=function(TitleArray,ValueArray){var TitleT;var ValueT;var flag;for(var i=0;i<TitleArray.length;i++){flag=false;for(var j=TitleArray.length-1;j>=i;j--){if(TitleArray[j-1]>TitleArray[j]){TitleT=TitleArray[j-1];ValueT=ValueArray[j-1];TitleArray[j-1]=TitleArray[j];ValueArray[j-1]=ValueArray[j];TitleArray[j]=TitleT;ValueArray[j]=ValueT;flag=true;}}
if(flag==false)
return;}}
clipper_AJAX.splitArrayInTo=function(sourceArray,TitleArray,ValueArray){for(var i=0;i<sourceArray.length;i++){TitleArray[i]=sourceArray[i][0];ValueArray[i]=sourceArray[i][1];}}
clipper_AJAX.getRandomNo=function(){return Math.round(Math.random()*10000);}
clipper_AJAX.isArray=function(v){return v&&typeof v==='object'&&typeof v.length==='number'&&!(v.propertyIsEnumerable('length'));}
clipper_AJAX.isInArray=function(ArrayT,ValueT){for(var i=0;i<ArrayT.length;i++){if(ArrayT[i]==ValueT){return true}}
return false;}
function trimString(str){if(typeof(str)!='string'||str==''){return'';}
while(str.charAt(0)==' ')
str=str.substring(1,str.length);while(str.charAt(str.length-1)==' ')
str=str.substring(0,str.length-1);return str;}
function trimArray(arr){for(var i=0;i<arr.length;i++){arr[i]=trimString(arr[i]);}}
clipper_AJAX.getHttpReq=function(url){var res;res=clipper_AJAX.sendHttpReq(url,false,'');return res;}
clipper_AJAX.getHttpReqText=function(url){var res;var resText;res=clipper_AJAX.sendHttpReq(url,false,'');if(typeof(res.responseText)!="undefined"){resText=res.responseText;}else{resText="";}
return resText;}
clipper_AJAX.getHttpReqXML=function(url){var res;var resXML;res=clipper_AJAX.sendHttpReq(url,false,'');if(typeof(res.responseXML)!="undefined"){resXML=res.responseXML;}else{resXML="";}
return resXML;}
clipper_AJAX.callHttpReq=function(url,callBackFunction){clipper_AJAX.sendHttpReq(url,true,callBackFunction);}
clipper_AJAX.callHttpReqAdv=function(sourceUrl,addRandom,asyncRequest,targetID,targetType){var url=sourceUrl;if(addRandom==true||addRandom=="true"){url=url+"&rdn="+clipper_AJAX.getRandomNo().toString();}
clipper_AJAX.sendHttpReq(url,asyncRequest,'clipper_AJAX.setValueToTargetID(res,"'+targetID+'","'+targetType+'")');}
clipper_AJAX.dbColumn=function(server,dbPath,viewName,columnNumber,dontCache,callBackFunction){var url;if(server!=""){url=server+"/"+dbPath+"/"+viewName;}else{url=dbPath+"/"+viewName;}
clipper_AJAX.lookUpValuesInViewByColsNo(url,"","",columnNumber,"",dontCache,callBackFunction);}
clipper_AJAX.dbLookup=function(server,dbPath,viewName,key,columnNumber,dontCache,callBackFunction){var url;if(server!=""){url=server+"/"+dbPath+"/"+viewName;}else{url=dbPath+"/"+viewName;}
clipper_AJAX.lookUpValuesInViewByColsNo(url,key,"",columnNumber,"",dontCache,callBackFunction);}
clipper_AJAX.lookUpValuesInViewByColsNo=function(viewUrl,keyValue,keyColNo,returnColsNo,returnMaxEntries,addRandom,callBackFunction){var url=viewUrl;url=url+"?ReadViewEntries&PreFormat";if(keyColNo!=""){url=url+"&ResortAscending="+keyColNo.toString();}
if(keyValue!=""){url=url+"&StartKey="+keyValue;url=url+"&UntilKey="+keyValue+"!";}
if(returnMaxEntries!=""&&returnMaxEntries.toString()!="0"){url=url+"&count="+returnMaxEntries.toString();}else{url=url+"&count=9999";}
if(addRandom==true||addRandom=="true"){url=url+"&rdn="+clipper_AJAX.getRandomNo().toString();}
clipper_AJAX.sendHttpReq(url,true,'clipper_AJAX.returnValuesInViewByColsNo(res,"'+keyValue+'","'+keyColNo+'","'+returnColsNo+'","'+returnMaxEntries+'","'+callBackFunction+'")');}
clipper_AJAX.lookUpValueInViewByColNo=function(viewUrl,keyValue,keyColNo,returnColNo,addRandom,targetID,targetType){clipper_AJAX.lookUpValuesInViewByColsNo(viewUrl,keyValue,keyColNo,returnColNo,"1",addRandom,"clipper_AJAX.setValueToTargetID(res,'"+targetID+"','"+targetType+"')");}
clipper_AJAX.addOptionsToSelectByViewColNo=function(viewUrl,keyValue,keyColNo,colTitleNo,colValueNo,sortValuesByTitle,addRandom,targetID,addMethod,defaultValues){var returnColNo;if(colValueNo!=""){returnColNo=colTitleNo.toString()+","+colValueNo.toString();}else{returnColNo=colTitleNo.toString();}
clipper_AJAX.lookUpValuesInViewByColsNo(viewUrl,keyValue,keyColNo,returnColNo,"",addRandom,"clipper_AJAX.addOptionsToSelectByArray(res,'"+sortValuesByTitle+"','"+targetID+"','"+addMethod+"','"+defaultValues+"')");}
