//This script grabs the upcoming_auditions XML file exported from Green Room
//to display the audition calendar on disneyauditions.com
function runTransform(){
if(document.implementation && document.implementation.createDocument){
	// for Mozilla & others

	var xsltProcessor = new XSLTProcessor();
	
	// load the xslt file
	var myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", "transform.xsl", false);
	myXMLHTTPRequest.send(null);
	
	// get the XML document
	xslStylesheet = myXMLHTTPRequest.responseXML;
	xsltProcessor.importStylesheet(xslStylesheet);
	
	// load the xml file
	myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", "news.xml", false);
	myXMLHTTPRequest.send(null);
	
	var xmlSource = myXMLHTTPRequest.responseXML;
	
	//transform
	 var resultDocument = xsltProcessor.transformToFragment(xmlSource, document);
	document.getElementById("xml_results").appendChild(resultDocument);
	
}else if(window.ActiveXObject){
	// for IE
	
	// Load XML
	xml = new ActiveXObject("MSXML2.DOMDocument");
	xml.async = false
	xml.load("news.xml")
	
	// Load XSL
	xsl = new ActiveXObject("MSXML2.DOMDocument");
	xsl.async = false
	xsl.load("transform.xsl")
		
	// Transform
	document.getElementById("xml_results").innerHTML=xml.transformNode(xsl);
}else{
	// Browser unknown
	alert("Browser unknown");
}
}


function runTransformEvents(){
if(document.implementation && document.implementation.createDocument){
	// for Mozilla & others

	var xsltProcessor = new XSLTProcessor();
	
	// load the xslt file
	var myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", "transform_events.xsl", false);
	myXMLHTTPRequest.send(null);
	
	// get the XML document
	xslStylesheet = myXMLHTTPRequest.responseXML;
	xsltProcessor.importStylesheet(xslStylesheet);
	
	// load the xml file
	myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", "events.xml", false);
	myXMLHTTPRequest.send(null);
	
	var xmlSource = myXMLHTTPRequest.responseXML;
	
	//transform
	 var resultDocument = xsltProcessor.transformToFragment(xmlSource, document);
	document.getElementById("xml_results_events").appendChild(resultDocument);
	
}else if(window.ActiveXObject){
	// for IE
	
	// Load XML
	xml = new ActiveXObject("MSXML2.DOMDocument");
	xml.async = false
	xml.load("events.xml")
	
	// Load XSL
	xsl = new ActiveXObject("MSXML2.DOMDocument");
	xsl.async = false
	xsl.load("transform_events.xsl")
		
	// Transform
	document.getElementById("xml_results_events").innerHTML=xml.transformNode(xsl);
}else{
	// Browser unknown
	alert("Browser unknown");
}
}





// Show or Hide auditions based on user selection at the top of the Audition Calendar
function searchAuditions(){
	var strTalent_Type = document.AuditionsForm.talent_type.options[document.AuditionsForm.talent_type.selectedIndex].value;
    var strBusinessUnit = document.AuditionsForm.business_unit.options[document.AuditionsForm.business_unit.selectedIndex].value;

	var currentId
	var elem = document.getElementById('results').elements;
	var recordCount = 0
	
	for(var i = 0; i < elem.length; i++){

		currentId = elem[i].name;
		currentValue = elem[i].value;

		if (currentValue.match(strTalent_Type)!=null&&currentValue.match(strBusinessUnit)!=null){
			document.getElementById('Audition' + currentId).style.display='';
			document.getElementById('AuditionNotes' + currentId).style.display='';
			recordCount = recordCount + 1
		}
		else {
			document.getElementById('Audition' + currentId).style.display='none';
			document.getElementById('AuditionNotes' + currentId).style.display='none';
		}
	}
	if(recordCount==0){
		document.getElementById('noRecords').style.display='';
	}
	else {
		document.getElementById('noRecords').style.display='none';
		}
}

// A workaround for XSL-to-XHTML systems that don't
//  implement XSL 'disable-output-escaping="yes"'.
var is_decoding;
var DEBUG = 0;

function complaining (s) { alert(s);  return s; }

if(!(   document.getElementById && document.getElementsByName))
 throw complaining("Sorry, your browser cannot render this page properly."
  + "  Consider going to getfirefox.com to upgrade.");

function check_decoding () {
  var d = document.getElementById('cometestme');
  if(!d) {
    throw complaining("Can't find an id='cometestme' element?");
  } else if(!('textContent' in d)) {
    // It's a browser with a halfassed DOM implementation (like IE6)
    // that doesn't implement textContent!  Assume that if it's that
    // dumb, it probably doesn't implement disable-content-encoding.

  } else {
    ampy = d.textContent;
    if(DEBUG > 1) { alert("Got " + ampy); }

    if(ampy == undefined) throw complaining("'cometestme' element has undefined text content?!");
    if(ampy == ''       ) throw complaining("'cometestme' element has empty text content?!"    );

    if      (ampy == "\x26"	) { is_decoding =  true; }
    else if (ampy == "\x26amp;" ) { is_decoding = false; }
    else	{ throw complaining('Insane value: "' + ampy + '"!'); }
  }

  var msg =
   (is_decoding == undefined) ? "I can't tell whether the XSL processor supports disable-content-encoding!D"
   : is_decoding ? "The XSL processor DOES support disable-content-encoding"
   : "The XSL processor does NOT support disable-content-encoding"
  ;
  if(DEBUG) alert(msg);
  return msg;
}


function go_decoding () {
//  check_decoding();

  if(is_decoding) {
    DEBUG && alert("No work needs doing -- already decoded!");
    return;
  }

  var to_decode = document.getElementsByName('decodeable');
  if(!( to_decode && to_decode.length )) {
    DEBUG && alert("No work needs doing -- no elements to decode!");
    return;
  }

  var s;
  for(var i = to_decode.length - 1; i >= 0; i--) { 
    s = to_decode[i].textContent;

    if(
      s == undefined ||
      (s.indexOf('&') == -1 && s.indexOf('<') == -1)
    ) {
      // the null or markupless element needs no reworking
    } else {
      to_decode[i].innerHTML = s;  // that's the magic
    }
  }

  return;
}

//
// xsl transform script for the home page (same script as used in the Calendar section)
//
function runTransformHome(){
if(document.implementation && document.implementation.createDocument){
	// for Mozilla & others

	var xsltProcessor = new XSLTProcessor();
	
	// load the xslt file
	var myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", "transform_home.xsl", false);
	myXMLHTTPRequest.send(null);
	
	// get the XML document
	xslStylesheet = myXMLHTTPRequest.responseXML;
	xsltProcessor.importStylesheet(xslStylesheet);
	
	// load the xml file
	myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", "upcoming_auditions_home.xml", false);
	myXMLHTTPRequest.send(null);
	
	var xmlSource = myXMLHTTPRequest.responseXML;
	
	//transform
	 var resultDocument = xsltProcessor.transformToFragment(xmlSource, document);
	document.getElementById("news").appendChild(resultDocument);
	
}else if(window.ActiveXObject){
	// for IE
	
	// Load XML
	xml = new ActiveXObject("MSXML2.DOMDocument");
	xml.async = false
	xml.load("upcoming_auditions_home.xml")
	
	// Load XSL
	xsl = new ActiveXObject("MSXML2.DOMDocument");
	xsl.async = false
	xsl.load("transform_home.xsl")
		
	// Transform
	document.getElementById("news").innerHTML=xml.transformNode(xsl);
}else{
	// Browser unknown
	alert("Browser unknown");
}
}