  var ajscript=true;
  function getconn() {
                var xmlhttp=false;
                try{xmlhttp=new XMLHttpRequest();} catch(e)
                {try{xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");} catch(e)
                {try{xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} catch(e1)
                {try{xmlhttp = window.createRequest();} catch(e2)
                {xmlhttp=false;}}}}
                return xmlhttp;
        }
   function hidediv(divName)
    {
        var subobj=document.getElementById(divName);
        subobj.innerHTML="";
        subobj.style.visibility="hidden";
        subobj.style.left=subobj.style.top=0;
    }
   function getpos(w, ot){return (w.offsetParent)? w[ot]+this.getpos(w.offsetParent,ot) : w[ot]}
   function getFormData(fname)
      {
     //alert(fname);
        var fdata = document.forms[fname].action;
        fdata += (fdata.indexOf("?")!=-1)? "&":"?";
        for (var j=0;j<document.forms[fname].elements.length;j++)
           {
             var el = document.forms[fname].elements[j];
             if(el.type=="radio") { for (var m=0;m<el.length;m++) if(el[m].checked) fdata+=el.name+"="+el[m].value+"&";}
             else if((el.type!="checkbox")||((el.type=="checkbox")&&(el.checked==true))) fdata+=el.name+"="+escape(el.value)+"&";
           }
        if((fdata.charAt(fdata.lenght-1)=="?")||(fdata.charAt(fdata.lenght-1)=="?")) fdata=fdata.slice(0,fdata.lenght-1);
        return fdata.replace(/\n/g,'<br>');
      }

 /*
  link could be a direct link to a page or name of the form within current page
  params have this format : DivName, X,Y,Width,Height,Align type, AnchorName
  DivName is mandatory , the rest is optional.
   Align Types:
    1= top,left - window
    2= top,left - ankhor
 */
   function getpage(link,params,loadmessage,loadbody,prehdr,posthdr) {
//     alert("link:"+link);
      if (loadmessage === undefined ) loadmessage="loading...";
      for (var i=0;i<document.forms.length;i++) // check if link is a form name
      {//  alert(document.forms[i].name);
      if (link==document.forms[i].name)link = getFormData(link);}//if so, get all data from the form and create get link for ajax popup
      link += ((link.indexOf("?")!=-1)? "&":"?")+"rnd="+new Date().getTime();
      var pp=params.split(",");
      var divName=pp[0];
      var req = getconn();
      if (req) {
           link += "&ajax=OK";
           var subobj=document.getElementById(divName);

           if ( pp[1] !== undefined )
             {
            if(pp[5]!==undefined)
               {
                 var xyTop=0; var xyLeft=0;
                 if (pp[5]==2) // position is relative to anchor , not window (ankhor must be supplied)
                  {
                   var anchorobj=document.getElementById(pp[6]);
                   xyTop=getpos(anchorobj,"offsetTop");
                   xyLeft=getpos(anchorobj,"offsetLeft");
                  }
                 if(pp[1]!==undefined) subobj.style.left=''+(parseInt(pp[1])+parseInt(xyLeft))+"px";
                 if(pp[2]!==undefined) subobj.style.top=''+(parseInt(pp[2])+parseInt(xyTop))+"px";
                 if(pp[3]!==undefined) subobj.style.width=pp[3]+"px";
                 if(pp[4]!==undefined) subobj.style.height=pp[4]+"px";
               }
             }
           var gr="";
           if(link.indexOf("nogray")==-1) gr="grayOut(false);"
           var preht="<table id=zzpop border=0 width=100% height=100%><tr><td valign=middle align=center>";
           var postht="</td></tr><tr><td align=right height=22><a href='javascript:{hidediv(\""+divName+"\");"+gr+"}'><img border=0 src='/js/closelabel.gif'></a></td></tr></table>";

           if (loadbody === undefined )   subobj.innerHTML=preht+"<img src='/js/loading.gif'><br><br><small>"+loadmessage+"</small>"+postht;
           else subobj.innerHTML=loadbody;

           subobj.style.visibility="visible";
           req.onreadystatechange = function() {
               if (req.readyState == 4) {
                  if (req.status == 200) {
                    if(link.indexOf("nogray")==-1) grayOut(true,{'zindex':'499'});
                    if (prehdr=== undefined)
                     subobj.innerHTML=preht+req.responseText+postht;
                    else
                     subobj.innerHTML=prehdr+req.responseText+posthdr;
                  } else {
                      alert("There was a problem while using XMLHTTP:\n" + req.statusText);
            }}}
  //         alert(link);
            req.open("GET",link, true);
            req.send(null);
            }
      else document.location.href=link;
      //return false;
        }
