var xml1http;
var xml2http;
var xml4http;
var xml5http;
var xml6http;
var xml7http;
var recenthash="";


function insert_swf_with_xml (graphic_select)
{
// alert ("in page_select");
if (graphic_select.length==0)
  {
	display_swfcontent = '<p>Error inserting graphic!</p>';
  	document.getElementById("sidebar1").innerHTML=display_swfcontent;
  	return;
  }
	xml6http=null;
	xml6http=GetXmlHttpObject();

//	var build_pgcontent ="http://animatedsoftware.com/r/Scripts/test1.txt";
	var build_swfcontent ="../r/xml_build_pages/";
 	build_swfcontent += graphic_select;
	build_swfcontent += ".xml";
	/* Send the time  to make a unique call otherwise browser uses cache */
 	build_swfcontent=build_swfcontent+"?date="+ new Date().getTime();
 	build_swfcontent=build_swfcontent+"&pg="+ graphic_select;



if (xml6http!=null)
  {
//	  alert ("ready to open and build content is  " + build_swfcontent);
  xml6http.open("GET",build_swfcontent,true);
 // alert ("opened for " + build_swfcontent);
 
  xml6http.onreadystatechange=insert_swf_Change;
   xml6http.send(null);
  }
else
  {
  alert("Your current browser version does not support XMLHTTP.");
  }

}

function insert_swf_Change()
{
if (xml6http.readyState==4)
  {// 4 = "loaded"
  if (xml6http.status==200)
    {// 200 = OK
    xml6Doc=xml6http.responseXML;
  //	document.getElementById("sidebar1").innerHTML=xml6http.responseText;
	document.getElementById("TimelineOfFirst25Years").innerHTML= xml6Doc.getElementsByTagName("TimelineOfFirst25Years")[0].childNodes[0].nodeValue;
    }
  else
    {
    alert("Problem retrieving XML stateChange content: " + xml6http.status);
    }
  }
}

function change_pg_content(page_select)
{
// alert ("in page_select");
if (page_select.length==0)
  {
	display_content = '<p>Please Contact the Animated Software Company at</p><p>(800) 551-2726</p><p>or</p><p>(760) 720-7261</p>';
  	document.getElementById("sidebar1").innerHTML=display_content;
  	return;
  }
	xml2http=null;
	xml2http=GetXmlHttpObject();

//	var build_pgcontent ="http://animatedsoftware.com/r/Scripts/test1.txt";
	var build_pgcontent ="../r/xml_build_pages/";
 	build_pgcontent += page_select;
	build_pgcontent += ".xml";
	/* Send the time  to make a unique call otherwise browser uses cache */
 	build_pgcontent=build_pgcontent+"?date="+ new Date().getTime();
 	build_pgcontent=build_pgcontent+"&pg="+ page_select;



if (xml2http!=null)
  {
//	  alert ("ready to open and build content is  " + build_pgcontent);
  xml2http.open("GET",build_pgcontent,true);
 // alert ("opened for " + build_pgcontent);
 window.location.hash=page_select;
 recenthash=window.location.hash;
  xml2http.onreadystatechange=state_Change;
  xml2http.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }

}
function change_all_content(page_select)
{
	var build_pgcontent ="http://www.animatedsoftware.com/index.html#";
 	build_pgcontent += page_select;
	 window.location.assign(build_pgcontent);

}

function change_main_content(pageType, main_folder)
{
	var build_pgcontent ="http://www.animatedsoftware.com";
	build_pgcontent	+= main_folder.substring(2);		// strip off the .. part
	build_pgcontent	+= "index.html#";
 	build_pgcontent += pageType;
	 window.location.assign(build_pgcontent);

}

function setMiddlePageFromURL(main_folder) {
//	    alert("Problem retrieving XML main page: " + main_folder);
//	var pageLoc = String(window.location);
	var pageId = window.location.hash;
	var pageType = pageId.substring(1);
	var str_loc = (pageId.indexOf("?", 1));
//	    alert("pageId: " + pageId + " pageType: " + pageType + " main folder: " + main_folder);	
if (str_loc != -1) {
	pageType = pageId.substring(1,str_loc);
}
//	    alert("pageId: " + pageId + " pageType: " + pageType + " main folder: " + main_folder);	
if (pageId == null) {
	pageType ="index";
}
if (pageId == "") {
	pageType ="index";
}
if (pageType == null) {
	pageType ="index";
}
if (pageId == "#") {
	pageType ="index";
}
	chg_middle_pg_content(pageType, main_folder);
}

function chg_old_pg_content(page_select, folder)
{
// alert ("in page_select");
if (page_select.length==0)
  {
	display_content = '<p>Please contact: The Animated Software Company at</p><p>(800) 551-2726</p><p>or</p><p>(760) 720-7261</p>';
  	document.getElementById("sidebar1").innerHTML=display_content;
  	return;
  }
	xml2http=null;
	xml2http=GetXmlHttpObject();

//	var build_pgcontent ="http://animatedsoftware.com/r/Scripts/test1.txt";
	var bld_oldpgcontent = folder;
 	bld_oldpgcontent += page_select;
	bld_oldpgcontent += "index.html";
	/* Send the time  to make a unique call otherwise browser uses cache */
 	bld_oldpgcontent=bld_oldpgcontent+"?date="+ new Date().getTime();
 	bld_oldpgcontent=bld_oldpgcontent+"&pg="+ page_select;



if (xml2http!=null)
  {
//	  alert ("ready to open and build content is  " + bld_pgcontent);
  xml2http.open("GET",bld_oldpgcontent,true);
 // alert ("opened for " + build_pgcontent);
 window.location.hash=page_select;
 recenthash=window.location.hash;
  xml2http.onreadystatechange=state_Old_Content_Change();
  xml2http.send(null);
  }
else
  {
  alert("Browser doesn't appear to support XMLHTTP.");
  }

}
function chg_middle_pg_content(page_select, folder)
{
// alert ("in page_select");
if (page_select.length==0)
  {
	display_content = '<p>Please Contact the Animated Software Co. </p><p>(800) 551-2726</p><p>or</p><p>(760) 720-7261</p>';
  	document.getElementById("sidebar1").innerHTML=display_content;
  	return;
  }
	xml2http=null;
	xml2http=GetXmlHttpObject();

//	var build_pgcontent ="http://animatedsoftware.com/r/Scripts/test1.txt";
	var bld_pgcontent = folder;
 	bld_pgcontent += page_select;
	bld_pgcontent += ".xml";
	/* Send the time  to make a unique call otherwise browser uses cache */
 	bld_pgcontent=bld_pgcontent+"?date="+ new Date().getTime();
 	bld_pgcontent=bld_pgcontent+"&pg="+ page_select;



if (xml2http!=null)
  {
//	  alert ("ready to open and build content is  " + bld_pgcontent);
  xml2http.open("GET",bld_pgcontent,true);
 // alert ("opened for " + build_pgcontent);
 window.location.hash=page_select;
 recenthash=window.location.hash;
  xml2http.onreadystatechange=state_Middle_Content_Change;
  xml2http.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }

}

function state_Change()
{
if (xml2http.readyState==4)
  {// 4 = "loaded"
  if (xml2http.status==200)
    {// 200 = OK
    xml2Doc=xml2http.responseXML;
  //	document.getElementById("sidebar1").innerHTML=xml2http.responseText;
 
//	document.getElementById("sidebar1").innerHTML= xml2Doc.getElementsByTagName("sidebar1")[0].childNodes[0].nodeValue;
//	document.getElementById("flashdropdown_placeholder").innerHTML= xml2Doc.getElementsByTagName("flashdropdown_placeholder")[0].childNodes[0].nodeValue;
	document.getElementById("Center_Title").innerHTML= xml2Doc.getElementsByTagName("Center_Title")[0].childNodes[0].nodeValue;
	document.getElementById("mainContent").innerHTML= xml2Doc.getElementsByTagName("mainContent")[0].childNodes[0].nodeValue;
//	document.getElementById("sidebar2").innerHTML= xml2Doc.getElementsByTagName("sidebar2")[0].childNodes[0].nodeValue;


    }
  else
    {
    alert("Problem retrieving XML stateChange content: " + xml2http.status);
    }
  }
}

function state_Middle_Content_Change()
{
if (xml2http.readyState==4)
  {// 4 = "loaded"
  if (xml2http.status==200)
    {// 200 = OK
    xml2Doc=xml2http.responseXML;
	document.getElementById("mainContent").innerHTML= xml2Doc.getElementsByTagName("mainContent")[0].childNodes[0].nodeValue;
	document.getElementById("seeAlsoBox").innerHTML= xml2Doc.getElementsByTagName("seeAlsoBox")[0].childNodes[0].nodeValue;	
    }
  else
    {
    alert("Problem retrieving XML stateChange content: " + xml2http.status);
    }
  }
}
function state_Old_Content_Change()
{
if (xml2http.readyState==4)
  {// 4 = "loaded"
  if (xml2http.status==200)
    {// 200 = OK
    xml2Doc=xml2http.responseXML;
//	document.getElementById("mainContent").innerHTML= xml2Doc.getElementsByTagName("mainContent")[0].childNodes[0].nodeValue;
    document.getElementById('http').click();	
    }
  else
    {
    alert("Problem retrieving new page: " + xml2http.status + " attempt: " + bld_oldpgcontent);
    }
  }
}

function menu_selection_was_clicked(menu_select)
{
// alert ("in menu_select");
if (menu_select.length==0)
  {
	display_content = '<p>Please Contact the Animated Software Company at</p><p>(800) 551-2726</p><p>or</p><p>(760) 720-7261</p>';
  	document.getElementById("sidebar1").innerHTML=display_content;
  	return;
  }
	xml7http=null;
	xml7http=GetXmlHttpObject();

//	var build_pgcontent ="http://animatedsoftware.com/r/Scripts/test1.txt";
	var build_menu_content ="../r/xml_build_pages/";
 	build_menu_content += menu_select;
	build_menu_content += ".xml";
	/* Send the time  to make a unique call otherwise browser uses cache */
 	build_menu_content=build_menu_content+"?date="+ new Date().getTime();
 	build_menu_content=build_menu_content+"&pg="+ menu_select;



if (xml7http!=null)
  {
//	  alert ("ready to open and build content is  " + build_pgcontent);
  xml7http.open("GET",build_menu_content,true);
 // alert ("opened for " + build_pgcontent);
  window.location.hash=menu_select;
  recenthash=window.location.hash;
  xml7http.onreadystatechange=menu_Change;
  xml7http.send(null);
  }
else
  {
  alert("Your browser doesn't support XMLHTTP.");
  }

}

function menu_Change()
{
if (xml7http.readyState==4)
  {// 4 = "loaded"
  if (xml7http.status==200)
    {// 200 = OK
    xml7Doc=xml7http.responseXML;
  //	document.getElementById("sidebar1").innerHTML=xml2http.responseText;
 
//	document.getElementById("sidebar1").innerHTML= xml2Doc.getElementsByTagName("sidebar1")[0].childNodes[0].nodeValue;
	document.getElementById("flashdropdown_placeholder").innerHTML= xml7Doc.getElementsByTagName("flashdropdown_placeholder")[0].childNodes[0].nodeValue;
	document.getElementById("Center_Title").innerHTML= xml7Doc.getElementsByTagName("Center_Title")[0].childNodes[0].nodeValue;
	document.getElementById("mainContent").innerHTML= xml7Doc.getElementsByTagName("mainContent")[0].childNodes[0].nodeValue;
//	document.getElementById("sidebar2").innerHTML= xml2Doc.getElementsByTagName("sidebar2")[0].childNodes[0].nodeValue;

    }
  else
    {
    alert("Problem retrieving XML stateChange content: " + xml7http.status);
    }
  }
}


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
else
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;

}



function dropdown_handler (drop_select) {
	
var products_menu_contents = '<div id="flashdropdn_products" class = "flashdropdown_area"><ul id="ascobanner_submenus"><li><div id="dropdown_product"           onmouseover="mcancelclosetime()" onmouseout="mclosetime()"><a href="#" onclick="menu_selection_was_clicked (\'product_se\');return false;">More Info: Statistics Explained</a><a href="#" onclick="menu_selection_was_clicked (\'product_aap\');return false;">More Info: All About Pumps</a><a href="#" onclick="menu_selection_was_clicked (\'product_apt\');return false;">More Info: Animated Periodic Table of the Elements</a><a href="#" onclick="menu_selection_was_clicked (\'product_eol\');return false;">More Info: The Heart: The Engine of Life</a><a href="#">Click again to cycle through products</a></div></li></ul></div>';

var buynow_menu_contents = '<div id="flashdropdn_buynow" class = "flashdropdown_area"><ul id="ascobanner_submenus"><li><div id="dropdown_buynow"	onmouseover="mcancelclosetime()" onmouseout="mclosetime()"><a href="#" onclick="menu_selection_was_clicked (\'purchase_se\');return false;">Purchase: Statistics Explained</a><a href="#" onclick="menu_selection_was_clicked (\'purchase_aap\');return false;">Purchase: All About Pumps</a><a href="#" onclick="menu_selection_was_clicked (\'purchase_apt\');return false;">Purchase: Animated Periodic Table of the Elements</a><a href="#" onclick="menu_selection_was_clicked (\'purchase_eol\');return false;">Purchase: The Heart: The Engine of Life</a><a href="#">Click again to cycle through products</a></div></li></ul></div>';
	
var downloads_menu_contents = '<div id="flashdropdn_downloads" class = "flashdropdown_area"><ul id="ascobanner_submenus"><li><div id="dropdown_downloads"	onmouseover="mcancelclosetime()" onmouseout="mclosetime()"><a href="#" onclick="menu_selection_was_clicked (\'download_se\');return false;">Download: Statistics Explained</a><a href="#" onclick="menu_selection_was_clicked (\'download_aap\');return false;">Download: All About Pumps</a><a href="#" onclick="menu_selection_was_clicked (\'download_apt\');return false;">Download: Animated Periodic Table of the Elements</a><a href="#" onclick="menu_selection_was_clicked (\'download_eol\');return false;">Download: The Heart: The Engine of Life</a><a href="#">Click again to cycle through products</a></div></li></ul></div>';


	var build_ddpgaddr ="../r/xml_build_pages/";
 	build_ddpgaddr += drop_select;
	build_ddpgaddr += ".xml";
	
	switch(drop_select){
	case "dropdown_empty":
	document.getElementById("flashdropdown_placeholder").innerHTML= "";
	break;
	case "dropdown_product":
	document.getElementById("flashdropdown_placeholder").innerHTML= products_menu_contents;
	break;
	case "dropdown_buynow":
	document.getElementById("flashdropdown_placeholder").innerHTML= buynow_menu_contents;
	break;
	case "dropdown_downloads":
	document.getElementById("flashdropdown_placeholder").innerHTML= downloads_menu_contents;
	break;
	default:
	document.getElementById("flashdropdown_placeholder").innerHTML= "dd pg missing!";
	}	
	

}



function contact_Ace()
{
	xml1http=GetXmlHttpObject();
if (xml1http==null)
  {
  alert ("Your browser isn't supporting XMLHTTP");
  return;
  }
	var build_contact_content ="../r/contact/contact_acknowledgement.php";
	var fromEmail = document.getElementById("fromEmail").value;
	var Subject = document.getElementById("Subject").value;
	var msgText = document.getElementById("msgText").value;
	var SubjectList = "none";
	for (var i=0; i < document.contactEmail.SubjectList.length; i++)
   {
   if (document.contactEmail.SubjectList[i].checked)
      {
      SubjectList = document.contactEmail.SubjectList[i].value;
      }
   }

   	build_contact_content=build_contact_content+"?fromEmail="+escape(fromEmail)
	+"&Subject="+ escape(Subject)
								+"&SubjectList="+ escape(SubjectList)
								+"&msgText="+ escape(msgText);

	build_contact_content = build_contact_content+"&force_chg="+ new Date().getTime();
	xml1http.onreadystatechange = contactAcknowledgementStateChanged;
	xml1http.open("GET",build_contact_content,true);
	xml1http.send(null);

}


function contactAcknowledgementStateChanged()
{
if (xml1http.readyState==4)
  {
    if (xml2http.status==200)
    {// 200 = OK
	change_pg_content("contact_acknowledgement");
	//document.getElementById("sidebar2").innerHTML= xml1http.responseText;
	}
  else
    {
    alert("Problem retrieving XML contact acknowledgement page: " + xml2http.status);
    }
  }
}

function setPageFromURL()
{
//	alert ("kilroy was here");
	var pageLoc = String(window.location);
//	alert ("kilroy was here: " + pageLoc);	
//	var pageIsIndex = 1;
	var pageId = window.location.hash;
	var pageType = pageId.substring(1);
//	document.getElementById("Center_Title").innerHTML=pageType;
//alert("current value of pg type:" + pageType + "  page id = " + pageId + " pg loc = " + pageLoc);
if (pageId == null) {
	pageType ="company_main";
}
if (pageId == "") {
	pageType ="company_main";
}
if (pageType == null) {
	pageType ="company_main";
}
if (pageId == "#") {
	pageType ="company_main";
}
//alert ("kilroy lives! " + pageLoc);
//alert("current value of pg type:" + pageType + "  page id = " + pageId + " pg loc = " + pageLoc);	
	change_pg_content(pageType);
}

function pollHash ()
{
if (window.location.hash==recenthash){return;}
recenthash=window.location.hash;
setPageFromURL();
}

function pollMiddleHash (main_folder)
{
//if (main_folder != "../statglos/") {
//	alert ('main folder not = "../statglos/": ' + main_folder);
//main_folder = "../statglos/";
//} else {
//	alert ('main folder = "../statglos/": ' + main_folder);
//}
if (window.location.hash==recenthash){return;}
recenthash=window.location.hash;
//setMiddlePageFromURL("../statglos/");
setMiddlePageFromURL(main_folder);
}



