﻿// JScript File

function ShowInCentre(Xwidth,Yheight,divid) { 
// First, determine how much the visitor has scrolled 

    var scrolledX, scrolledY; 
    if( self.pageYoffset ) { 
        scrolledX = self.pageXoffset; 
        scrolledY = self.pageYoffset; 
    } else if( document.documentElement && document.documentElement.scrollTop ) { 
        scrolledX = document.documentElement.scrollLeft; 
        scrolledY = document.documentElement.scrollTop; 
    } else if( document.body ) { 
        scrolledX = document.body.scrollLeft; 
        scrolledY = document.body.scrollTop; 
    } 

// Next, determine the coordinates of the center of browser's window 

    var centerX, centerY; 
    if( self.innerHeight ) { 
        centerX = self.innerWidth; 
        centerY = self.innerHeight; 
    } else if( document.documentElement && document.documentElement.clientHeight ) { 
        centerX = document.documentElement.clientWidth; 
        centerY = document.documentElement.clientHeight; 
    } else if( document.body ) { 
        centerX = document.body.clientWidth; 
        centerY = document.body.clientHeight; 
    } 

// Xwidth is the width of the div, Yheight is the height of the 
// div passed as arguments to the function: 
    var leftoffset = scrolledX + (centerX - Xwidth) / 2; 
    var topoffset = scrolledY + (centerY - Yheight) / 2; 
// the initial width and height of the div can be set in the 
// style sheet with display:none; divid is passed as an argument to // the function 
    var o=document.getElementById(divid); 
    var r=o.style; 
    r.position='absolute'; 
    r.top = topoffset + 'px'; 
    r.left = leftoffset + 'px'; 
    r.display = "block"; 
} 


 function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function serializeXml(oNode) {
   var oSerializer = new XMLSerializer();
   return oSerializer.serializeToString(oNode);
   }
   function ampFix(val_in){
       sz = new String(val_in);
       sz = sz.replace(/&/g,"%26");
       sz = sz.replace(/'/g,"%27");
       sz = sz.replace(/=/g,"%3D");
       sz = sz.replace(/\+/g,"%2B");
       return sz
   }
   function showWait(){
       if (document.getElementById('processingMenu') != null ){
        if (processingMenu.style.visibility != 'visible'){
            processingMenu.style.visibility = 'visible'; 
            processingMenu.style.clip='rect(auto auto auto auto)';
            ShowInCentre(150,100,'processingMenu');
            try{
                ListBoxHide(1,'processingMenu')
            }catch (error) {   
            }
        }
    } 
   }
   
  function hideWait(){
       if (document.getElementById('processingMenu') != null ){
        if (processingMenu.style.visibility != 'hidden'){
            processingMenu.style.visibility = 'hidden'; 
            processingMenu.style.clip='rect(0 auto 0 auto)';
            try{
                document.getElementById('IFrameBlock').style.clip = 'rect(0 auto 0 auto)';
            }catch (error) {   
            }
        }
    } 
   }

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
   var obj
   var uqid  
    stack = 0;
function AutoCompleteJava(obj,objname){
    stack++; 
    compname = obj + '_1'
    object2 = document.getElementById(compname);
    objname2 = objname;
    obj2 = obj;
    try{
    document.getElementById('WAF_SUBFORMNAME').value='';
    }catch (error) {}
    setTimeout("AutoCompleteJavaSub(obj2,objname2,object2,obj)", 1250);
}

function AutoCompleteJavaSub(obj,objname,object,obj2){
   if(stack == 1) {
    object.blur;
    object.focus;
    }
    stack--;

  try{
   document.getElementById('ISQUICK').value='0';
   document.getElementById('ISQUICK').value='1';
   sz = obj.replace(/_z_/g,"_") ;
   origdiv = document.getElementById(sz + '_1');
   DisplayDiv = sz + 'displaydiv';
   document.getElementById(DisplayDiv).style.posLeft = findPosX(document.getElementById(sz + '_1'));
   document.getElementById(DisplayDiv).style.top = findPosY(origdiv.parentNode) + 16;
   document.getElementById(DisplayDiv).style.clip = 'rect(auto auto auto auto)';
      obj = document.forms[0];
   uqid = objname;
   getAllFormInput2();
   //getAllFormInput(document.forms[0],objname);
   document.getElementById('ISQUICK').value='0';
  }catch (error) {   
   }
   }
   
   
   
   
   function getAllFormInput(obj2,uqid2) {
   obj = obj2;
   uqid = uqid2;

   if (navigator.appName == 'Microsoft Internet Explorer'){
   setTimeout("showWait()",100); 
   }
  // setTimeout("showWait()",1000); 


   setTimeout("getAllFormInput2()",1000); 
  // setTimeout("hideWait()",2000);
   if (navigator.appName == 'Microsoft Internet Explorer') {
   setTimeout("hideWait()",1000); 
   }
   }
   
   function getAllFormInput2() {
   //Show Processing 
try {
   
    var cn=document.body.className; 
   document.body.className="question"; 
   document.body.className=cn; 
   
   usingIE = true;
      var getstr = "&";
      //Get elements from the form
      var elements = document.getElementsByTagName('input');
      for (var i = 0; i < elements.length; i++) {
           if (elements.item(i).type == "radio" || elements.item(i).type == "checkbox" ) {
               if (elements.item(i).checked) {
                  getstr += elements.item(i).name + "=" + ampFix(elements.item(i).value) + "&";
               }
            } else {
                if (elements.item(i).value != ''){
                    getstr += elements.item(i).name + "=" + ampFix(elements.item(i).value) + "&";
                }
            }
      }
      var elements = document.getElementsByTagName('SELECT');
      for (var i = 0; i < elements.length; i++) {
        try{
            if (elements.item(i).options[elements.item(i).selectedIndex].value != ''){
                getstr += elements.item(i).name + "=" + ampFix(elements.item(i).options[elements.item(i).selectedIndex].value) + "&";
            }
        }catch(error){}
      }
      var elements = document.getElementsByTagName('textarea');
      for (var i = 0; i < elements.length; i++) {
      
        if (elements.item(i).value != ''){
            tasz = elements.item(i).value;
            k = 0;
            while (tasz.length > 0){
            sm = tasz.substring(0,1000);
            if (k > 9) {
            getstr += 'zZaReAZz' + k + elements.item(i).name + "=" + ampFix(sm) + "&";
            } else {
            getstr += 'zZaReAZz0' + k + elements.item(i).name + "=" + ampFix(sm) + "&";
            }
            tasz = tasz.substring(1000);
            k = k + 1
            }
        }
      }
      //make request(s)
      var xmlHttp=makeRequest();
      while (getstr.length > 1900){
          //find 800 find nearest &
          loc = getstr.indexOf("&",500);
          
          //if no & found
          if (loc == -1){
            loc = 500
          }
          
          //trim those characters
          tmpstr = getstr.substring(0,loc);
        
        if(navigator.userAgent.indexOf('Safari') > 10){
            xmlHttp = new XMLHttpRequest();
            xmlHttp.overrideMimeType('text/html');
            xmlHttp.open('GET', "form.aspx?AJAXAPPEND=True" + tmpstr, false);
            xmlHttp.send(null);
        }else{
          xmlHttp.open("POST", "form.aspx?AJAXAPPEND=True" + tmpstr, false);
          if (window.ActiveXObject){
            xmlHttp.send(null);
	      } else {
	        xmlHttp.send('');
	      }
          }
          getstr = getstr.substring(loc);
      }
      if(navigator.userAgent.indexOf('Safari') > 10){
        xmlHttp = new XMLHttpRequest();
        xmlHttp.overrideMimeType('text/html');
        xmlHttp.open('GET', "form.aspx?bustcache=" + new Date().getTime() + "&AJAX=True&uqid=" + uqid + getstr, false);
        xmlHttp.send(null);
        xmlDocument= document.implementation.createDocument("","",null);
        sz = new String(xmlHttp.responseText);
        usingIE = false;
      }else{
      xmlHttp.open("POST", "form.aspx?bustcache=" + new Date().getTime() + "&AJAX=True&uqid=" + uqid + getstr, false);
      if (window.ActiveXObject){
         xmlHttp.send(null);
	  } else {
	    xmlHttp.send('');
	  }

    //sz= xmlHttp.responseText;
   if (window.ActiveXObject)
  {
  xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
  xmlDocument.async=false;
  xmlDocument.loadXML(xmlHttp.responseText);
  }
// code for Mozilla, etc.
else if (document.implementation &&
document.implementation.createDocument)
  {
  xmlDocument= document.implementation.createDocument("","",null);
  xmlDocument.load(xmlHttp.responseText);
  sz = new String(xmlHttp.responseText);
  usingIE = false;
  //xmlDocument.onload=getmessage();
  }
else
  {
  alert('Your browser cannot handle this script');
  }
	  }

    sz = new String(xmlHttp.responseText);
if (xmlHttp.responseText.substring(0,45) == '<HTML><body onLoad=\"top.location=\'login.aspx?'){
window.top.location = "login.aspx"
}

    sz = sz.replace(/<br>/g,"<br/>");
    //alert(sz);
    //receive XML feedback
    t1 = sz.replace(/zzaMpersand/g,"&" );
    var dom = parse(t1);
    if (dom.length==undefined){ 
    t1 = sz.replace(/zzaMpersand/g,"&amp;" );
    var dom = parse(t1);
    }
    if (dom.length!=0){ 
    //For each message
    for (var i = 0; i < dom.childNodes[0].childNodes.length; i++) 
    {
    if (usingIE == false){
    s = new String('');
    }
    //if there are no child nodes
    if (dom.childNodes[0].childNodes[i].childNodes.length==0){
        if (usingIE) {
        try{
            document.all(dom.childNodes[0].childNodes[i].attributes[0].nodeValue).innerHTML = dom.childNodes[0].childNodes[i].text;
           } catch (error){
           }
        }else{
        try{
        document.getElementById(dom.childNodes[0].childNodes[i].attributes[0].nodeValue).innerHTML = dom.childNodes[0].childNodes[i].nodeValue;
        } catch (error){
           }
        }
        }
        //there are child nodes
    else{
        //assemble XML nodes
        s = new String('');
        for (var j = 0; j < dom.childNodes[0].childNodes[i].childNodes.length; j++) {
        if (usingIE) {
            s = s + dom.childNodes[0].childNodes[i].childNodes[j].xml;
            }else{
            s = s + serializeXml(dom.childNodes[0].childNodes[i].childNodes[j])
            }
        }
        s = s.replace(/zzSELECT/g,"SELECT");
        s = s.replace(/checked=\"\"/g,"checked");
        s = s.replace(/NOWRAP=\"\"/g,"NOWRAP");
        s = s.replace(/DiSaBlEd=\"\"/g,"DISABLED");
        s = s.replace(/ReAdOnLy=\"\"/g,"ReAdOnLy");
        s = s.replace(/SELECTED=\"\"/g,"SELECTED");
        s = s.replace(/<br>/g,"<br/>");
        s = s.replace(/zzaMpersand/g,"&");
        s = s.replace(/zyaMpersand/g,"&");
        s = s.replace(/zz zz/g,"&nbsp;");
        //get the document element that relates to this node element
        var parentElement = document.getElementById(dom.childNodes[0].childNodes[i].attributes[0].nodeValue);
        
        //get the type of action to perform
        var actionType = dom.childNodes[0].childNodes[i].attributes[1].nodeValue;

        //if the action is delete then delete the rows accordingly
        if (actionType == 'SDELETE'){
        try {
               var parentElement = document.getElementById(dom.childNodes[0].childNodes[i].attributes[0].nodeValue + '_table');
               for (var j = 0; j < parentElement.tBodies.length; j++) {
                    while (parentElement.tBodies[j].rows.length > 0){
                        parentElement.tBodies[j].deleteRow(0);
                    }
                }
                } catch (error) {
                
                }
        }else{ //it is not a delete
        
            if (parentElement != null){ 
            try {
                if (usingIE == true) {
                    if (actionType == 'AUTO'){ 
                    
                        document.getElementById(dom.childNodes[0].childNodes[i].attributes[0].nodeValue).innerHTML = s ;
                    } 
                    else 
                    {
                        if(actionType == 'SETVAL'){ 
                         document.getElementById(dom.childNodes[0].childNodes[i].attributes[0].nodeValue).value = s ;
                        } 
                        else 
                        {
                            if (s.substring(s.length-1) == ' '){
                                document.all(dom.childNodes[0].childNodes[i].attributes[0].nodeValue).innerHTML = s.substring(0,s.length-1) + '&nbsp;';
                            }
                            else
                            {
                                document.all(dom.childNodes[0].childNodes[i].attributes[0].nodeValue).innerHTML = s;
                            }
                        }
                    }
                }
                else
                {
                    document.getElementById(dom.childNodes[0].childNodes[i].attributes[0].nodeValue).innerHTML = s ;
                    try {
                    document.getElementById(dom.childNodes[0].childNodes[i].attributes[0].nodeValue + '_table').innerHTML = '' ;
                    }
                     catch (e) {}
                }
            }
            catch (e) {
                // IE fails unless we wrap the string in another element.
               parentElement.innerHTML = '';

                var parentElement = document.getElementById(dom.childNodes[0].childNodes[i].attributes[0].nodeValue);
                var wrappingDiv = document.createElement('div');
                wrappingDiv.innerHTML = s;
                parentElement.appendChild(wrappingDiv);
                
                var parentElement1 = document.getElementById(dom.childNodes[0].childNodes[i].attributes[0].nodeValue + '_table');
            }
        }else{
            var parentElement = document.getElementById(dom.childNodes[0].childNodes[i].attributes[1].nodeValue);
                if (parentElement != null){
                    parentElement.innerHTML = '';
                    var wrappingDiv = document.createElement('div');
                    wrappingDiv.innerHTML = s;
                    parentElement.appendChild(wrappingDiv);     
                    }
                }
            }
        }
        }
   }
   try{
   document.getElementById('WAF_ROWNUMBER').value = '';
   document.getElementById('WAF_SUBFORMNAME').value = '';
   }
   catch (error) {   
   }
   }
   catch (error) {
   }
}

function parse(xml) {
    var dom;
    try {
        dom = new ActiveXObject("Microsoft.XMLDOM");
        dom.async = false;
        dom.loadXML(xml);
    } catch (error) {
        try {
            var parser = new DOMParser();
            dom = parser.parseFromString(xml, "text/xml");
            delete parser;
        } catch (error2) {
            if (debug)
                alert("XML parsing is not supported.");
        }
    }
    return dom;
}

         