﻿/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();
    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

// doAJAXCall : Generic AJAX Handler, used with XHConn
// Author : Bryce Christensen (www.esonica.com)
// PageURL : the server side page we are calling
// ReqType : either POST or GET, typically POST
// PostStr : parameter passed in a query string format 'param1=foo&param2=bar'
// FunctionName : the JS function that will handle the response

var doAJAXCall = function (PageURL, ReqType, PostStr, FunctionName) {

	// create the new object for doing the XMLHTTP Request
	var myConn = new XHConn();

	// check if the browser supports it
	if (myConn)	{
	    
	    // XMLHTTPRequest is supported by the browser, continue with the request
	    myConn.connect('' + PageURL + '', '' + ReqType + '', '' + PostStr + '', FunctionName);    
	} 
	else {
	    // Not support by this browser, alert the user
	    alert("XMLHTTP not available. Try a newer/better browser, this application will not work!");   
	}
}

// launched from button click 
/*
var getMessage = function () {
	
	// build up the post string when passing variables to the server side page
	var PostStr = "";
	
	// use the generic function to make the request
	doAJAXCall('/includes/ajax/serversidetest.asp', 'POST', '', showMessageResponse);
}

// The function for handling the response from the server
var showMessageResponse = function (oXML) { 
    
    // get the response text, into a variable
    var response = oXML.responseText;
    
    // update the Div to show the result from the server
	document.getElementById("responseDiv").innerHTML = response;
};
*/

				var getMessage = function (th,wdiv,sortby,id,typerole,typeroleid)
                {
					
					// build up the post string when passing variables to the server side page
					var PostStr = "";
					//alert(th);
					// use the generic function to make the request

                    /* up and down arrow here
                    spana9,spanb9,spanc9
                    */
				        var previousInnerText = new String(); 
                        

                        var spana = document.getElementById('spana'+th); 
                        var spanb = document.getElementById('spanb'+th); 
                        var spanc = document.getElementById('spanc'+th); 

						//m_oIFrame.style.display = 'block';
						if (sortby == 'category')
						{
                            /*
						      if ((spanc.style.display == 'none')) 
						      { 
						        spanc.style.display = 'block'; 
                                spanc.innerHTML='<img border="0" src="/images/nxsarrowdown.gif" width="11" height="7" alt="" />';
						      } else { 
						        spanc.style.display = 'none'; 
                                spanc.innerHTML='<img border="0" src="/images/nxsarrowup.gif" width="11" height="7" alt="" />';
						      } 
                            */
                                spanc.style.display = 'none';
                                spanc.innerHTML='<span style="color:#000;">Work Category</span><br/><img border="0" src="/images/nxsarrowup.gif" width="11" height="7" alt="" />';
                                //spana.style.display = 'none';
                                //spanb.style.display = 'none';

                                spanc.style.display = 'block';

                                //sortby = 'item_code';
                                previousInnerText = '<a onclick="javascript:getMessage(\''+th+'\',\''+wdiv+'\',\'item_code\',\''+id+'\',\''+typerole+'\',\''+typeroleid+'\');" href="#div'+th+'">Catalogue No</a>';
                                //alert(previousInnerText);
                                spanb.style.display = 'none';
                                spanb.innerHTML = previousInnerText;
						        spanb.style.display = 'block'; 

                                //sortby = 'title';
                                previousInnerText = '<a onclick="javascript:getMessage(\''+th+'\',\''+wdiv+'\',\'title\',\''+id+'\',\''+typerole+'\',\''+typeroleid+'\');" href="#div'+th+'">Album Title</a>';
                                spana.style.display = 'none';
                                spana.innerHTML = previousInnerText;
						        spana.style.display = 'block'; 

						}
                        //th=='3' && 
                        if (sortby == 'item_code')
                        {
                                //spanb.innerHTML='<img border="0" src="/images/nxsarrowup.gif" width="11" height="7" alt="" />';
                                spanb.style.display = 'none';
                                spanb.innerHTML='<span style="color:#000;">Catalogue No</span><br/><img border="0" src="/images/nxsarrowup.gif" width="11" height="7" alt="" />';

                                //spana.style.display = 'none';
                                //spanc.style.display = 'none';
						        spanb.style.display = 'block'; 

                                //sortby = 'title';
                                previousInnerText = '<a onclick="javascript:getMessage(\''+th+'\',\''+wdiv+'\',\'title\',\''+id+'\',\''+typerole+'\',\''+typeroleid+'\');" href="#div'+th+'">Album Title</a>';
                                spana.style.display = 'none';
                                //alert(previousInnerText);
                                spana.innerHTML = previousInnerText;
						        spana.style.display = 'block'; 

                                //sortby = 'category';
                                previousInnerText = '<a onclick="javascript:getMessage(\''+th+'\',\''+wdiv+'\',\'category\',\''+id+'\',\''+typerole+'\',\''+typeroleid+'\');" href="#div'+th+'">Work Category</a>';
                                spanc.style.display = 'none';
                                spanc.innerHTML = previousInnerText;
						        spanc.style.display = 'block'; 
                        }

                        if (sortby == 'title')
                        {
                                //spana.innerHTML='<img border="0" src="/images/nxsarrowup.gif" width="11" height="7" alt="" />';
                                spana.style.display = 'none';
                                spana.innerHTML='<span style="color:#000;">Album Title</span><br/><img border="0" src="/images/nxsarrowup.gif" width="11" height="7" alt="" />';
                                //spanb.style.display = 'none';
                                //spanc.style.display = 'none';
						        spana.style.display = 'block'; 

                                //sortby = 'item_code';
                                previousInnerText = '<a onclick="javascript:getMessage(\''+th+'\',\''+wdiv+'\',\'item_code\',\''+id+'\',\''+typerole+'\',\''+typeroleid+'\');" href="#div'+th+'">Catalogue No</a>';
                                spanb.style.display = 'none';
                                //alert(previousInnerText);
                                spanb.innerHTML = previousInnerText;
						        spanb.style.display = 'block'; 

                                //sortby = 'category';
                                previousInnerText = '<a onclick="javascript:getMessage(\''+th+'\',\''+wdiv+'\',\'category\',\''+id+'\',\''+typerole+'\',\''+typeroleid+'\');" href="#div'+th+'">Work Category</a>';
                                spanc.style.display = 'none';
                                spanc.innerHTML = previousInnerText;
						        spanc.style.display = 'block'; 
                        }

						switch(th){
                        //classical artist
						case '1':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse1);
						break

                        //non-classical artist
						case '2':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse2);
						break

                        //choirs
						case '10':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse10);
						break

                        //conductors
						case '9':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse9);
						break

                        //ensembles
						case '11':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse11);
						break

                        //orchestras
						case '12':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse12);
						break

                        //readers
						case '42':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse42);
						break

                        //arrangers
						case '7':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse7);
						break

                        //authors
						case '5':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse5);
						break

                        //classical composers
						case '3':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse3);
						break

                        //lyricists
						case '6':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse6);
						break

                        //non classical composers
						case '4':
						doAJAXCall('/callnxsperformer.asp?sortby='+sortby+'&id='+id+'&typeroleid='+typeroleid+'&typerole='+typerole, 'POST', '', showMessageResponse4);
						break

						}
					
					//doAJAXCall('/includes/ajax/ServerSideTest.asp', 'POST', '', showMessageResponse);

				}

				// The function for handling the response from the server
				var showMessageResponse1 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv1").innerHTML = response;
				};

				var showMessageResponse2 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv2").innerHTML = response;
				};

				var showMessageResponse10 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv10").innerHTML = response;
				};

				var showMessageResponse9 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv9").innerHTML = response;
				};

				var showMessageResponse11 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv11").innerHTML = response;
				};

				var showMessageResponse12 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv12").innerHTML = response;
				};

				var showMessageResponse42 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv42").innerHTML = response;
				};

				var showMessageResponse7 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv7").innerHTML = response;
				};

				var showMessageResponse5 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv5").innerHTML = response;
				};

				var showMessageResponse3 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv3").innerHTML = response;
				};

				var showMessageResponse6 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv6").innerHTML = response;
				};

				var showMessageResponse4 = function (oXML) { 
				    // get the response text, into a variable
				    var response = oXML.responseText;
				    // update the Div to show the result from the server
					document.getElementById("responseDiv4").innerHTML = response;

				};
