﻿// JScript File

    
    function saveRating(date,rating,statusCtrlID,uid,iid,working){
        var stat = document.getElementById(statusCtrlID);
        
        stat.innerHTML = "Saving..";
        stctrl = statusCtrlID;
        stctrl2 = working;
        
        var dt = document.getElementById(date);
        var r = document.getElementById(rating);
        var w = document.getElementById(working);
        w.style.display="block";
       makeRequest('GetTriggs.asmx/TTWSSaveIssue?IssueDate=' + dt.value + '&IssueRating=' + r.value + '&UserID=' + uid + '&IssueID=' + iid + '','GET','issueSaved');
        
    }
    

var ipi=0;
 function readyCall(key,findit){
    //alert(key);
            
        if (trimAll(findit)==""){DeleteTableRows("sug");stillcheck=true;return;}
        if (key==13){addIt();stillcheck=true;}
        if (key==8){//backspace key      
            //alert("setting tru");   
            stillcheck=true;         
            makeRequest('GetTriggs.asmx/TTWSGetSuggestions?PersonID=' + ipi + '&FindIt=' + findit,'GET','alertContents');
            
            }
        if (key>31 && key<128){
            if (key!=39 && key!=38 && key!=40 && key!=37){
               // alert(stillcheck);
                if (stillcheck){
                //alert("checking");
                makeRequest('GetTriggs.asmx/TTWSGetSuggestions?PersonID=' + ipi + '&FindIt=' + findit,'GET','alertContents')
                document.forms(0).trigID.value="0";
                }
            }
          }
    }
    
   function avail(un){
        var lbl = document.getElementById('lblAvailable');
        if (un.length<2){
            lbl.innerHTML = 'Must be at least 2 characters.';
            return false;
        }
        makeRequest('GetTriggs.asmx/TTWSUserNameIsAvailable?UserName=' + un,'GET','loadAvailableResponse')
   }

   function makeRequest(url,GET_or_POST,jsfunc_handler) {
   // url=location of request on server  
   // get_or_post=just getting something (GET) posting something (POST) like name=value&anothername=othervalue&so=on 
   // jsfunc_handler is the js function on the calling page that will handle the response
   // declare the Request object in the calling page - var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        
        if (GET_or_POST=='POST'){
        //alert('here');
       // http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        }
        //alert('here' + jsfunc_handler);
        http_request.onreadystatechange = eval(jsfunc_handler);
        http_request.open(GET_or_POST, url, true);
        http_request.send(null);

    }

