
// *-------------------------------------------------------------------------
// * iBanknet Widget Tools Javascript 
// *  
// * copyright:  iBanknet.com 
// *             (http://www.ibanknet.com)
// *-------------------------------------------------------------------------

// Does this browser support try-catch?
var tc = false;
try {
    tc = true;
} catch(f) { }

var xmlHttpError = 'XML HTTP Request: OK';  // for trouble shooting
var seltab = '';

// * Get the xmlhttp request object depending on the browser
function get_RequestObject() {
    var objRequest;
    if (window.ActiveXObject) {
        if (tc) {
            try {
                objRequest = new ActiveXObject('Msxml2.XMLHTTP');  // IE 6+
            }
            catch(e) {
                try {
                    objRequest = new ActiveXObject('Microsoft.XMLHTTP');  // IE 5.5
                }
                catch(f) { } 
            }
        } else {
            objRequest = new ActiveXObject('Microsoft.XMLHTTP');  // ? IE 5.0 ?
        }
    } else if (window.XMLHttpRequest) {
        objRequest = new XMLHttpRequest();  // All other browsers, inc. IE 7 and DOM 3
    }
    return objRequest;
} // end get_RequestObject function

// * Get the content using xmlhttp
function do_xmlhttp() {  
  var instname = '';
  var startswith = '';
  var nameField = document.getElementById( "instname" );
  var startswithCheckbox = document.getElementById( "startswith" );
	// set the institution name to search
	if (nameField.value.length > 0) {
		instname = nameField.value;
		instname = instname.replace('&', '%26');
	}

	// add startswith if checked
	if (startswithCheckbox.checked) {
		startswith = '&startswith=true';
	}

	if (seltab == 'News') {
		// do the xmlhttp to get the google news content
		get_googlenews(instname);
	} else if (seltab == 'SEC') {
		// do the xmlhttp to get the sec content  
		get_secfilings(instname, startswith);
	}else {
		// do the xmlhttp to get the ibanknet content  
		get_ibanknetbase(instname, startswith);
	}

} // end do_xmlhttp function


// * Get the ibanknet base content using xmlhttp
function get_ibanknetbase(instname, startswith) {  
  var xmlhttp = get_RequestObject();  // create a new request object
  var tab1html = '';
  var tab1contentdiv = document.getElementById("tab1content");
    // Display loading message before fetching feed.
    tab1content.innerHTML = '<div class="loadingLabel">Search in progress...</div>';

	// do the xmlhttp to get the content  
	xmlhttp.open("GET", "/scripts/ibanknetwidget.aspx?instname=" + instname + startswith,true);
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
		tab1contentdiv.innerHTML = xmlhttp.responseText;
	  }
	}
	xmlhttp.send(null)
} // end get_ibanknetbase function

// * Get the google news content using xmlhttp
function get_googlenews(instname) {  
  var xmlhttp = get_RequestObject();  // create a new request object
  var tab2contentdiv = document.getElementById("tab2content");
    // Display loading message before fetching feed.
    tab2content.innerHTML = '<div class="loadingLabel">Loading...</div>';

	// do the xmlhttp to get the content  
	xmlhttp.open("GET", "/scripts/xmlhttp.asp?instname=" + instname,true);
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
		tab2contentdiv.innerHTML = xmlhttp.responseText;
	  }
	}
	xmlhttp.send(null)
} // end get_googlenews function


// * Get the SEC filings content using xmlhttp
function get_secfilings(instname, startswith) {  
  var xmlhttp = get_RequestObject();  // create a new request object
  var tab3html = '';
  var tab3contentdiv = document.getElementById("tab3content");
    // Display loading message before fetching feed.
    tab3content.innerHTML = '<div class="loadingLabel">Search in progress...</div>';

	// do the xmlhttp to get the content  
	xmlhttp.open("GET", "/scripts/ibanknetwidget.aspx?instname=" + instname + startswith + "&secfilings=true",true);
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
		tab3contentdiv.innerHTML = xmlhttp.responseText;
	  }
	}
	xmlhttp.send(null)
} // end get_secfilings function

