// JavaScript Document

/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)

// stig
var storeHistory = "false" // Used to avoid storing the current page in history

/** Our callback to receive history change
     events. */
function historyChange(newLocation, historyData) {
	var locLength = newLocation.length;
	var pageName = newLocation.slice(0, locLength-4);
	var pageExtension = newLocation.slice(locLength-3, locLength);
	//flashProxy.call('loadPage', pageName);
	
	//stig If the pageName is nothing, load the homePage, but don't store it in the history
	if (pageName==""){
	storeHistory="false";
		getPage("home.htm", 'pageContent');
	}
	else{
		getPage(pageName + "." + pageExtension, 'pageContent');
	}
}

function initPage(){
  
	// initialize the DHTML History
	// framework
	dhtmlHistory.initialize();
	
		// subscribe to DHTML history change
		// events
	dhtmlHistory.addListener(historyChange);

		// if this is the first time we have
		// loaded the page...
		if (dhtmlHistory.isFirstLoad()) {		
			getPage('home.htm', 'pageContent');
	}	
}

function getPage(url, containerid){

	window.scrollTo(0, 0);
	document.getElementById(containerid).scrollTop = 0;
		
	//flashToggleActivityIndicator("true");
		
	if (url != ".htm" && storeHistory=="true"){
		dhtmlHistory.add(url, url);
	}
	
	storeHistory="true";
	
	if (url.indexOf("/") >= 0){
		url = url.slice(url.indexOf("/")+1, url.length);
	}
		
	var page_request = false
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	}
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
				catch (e){}
		}
	}
	else{
		return false;
		//flashToggleActivityIndicator("false");
	}
		
	page_request.onreadystatechange=function(){
		loadPageContent(page_request, containerid);
	
		// Change the title back from #Home#Etc...
	document.title = "Welcome to Welded Tube of Canada";
	
	// Hide both the datanew footer and the copyright footer. 
	document.getElementById("dataNetFooter").style.visibility = "hidden"
	document.getElementById("copyrightFooter").style.visibility = "hidden"

	// If we are viewing the aboutUs page, show the datanet footer
	if (url == "aboutUs.htm"){
		document.getElementById("dataNetFooter").style.visibility = "visible"
		document.getElementById("copyrightFooter").style.marginTop = "0px";
	}
	
	// If we are viewing the contact Us page, show the copyright footer
	else if (url == "contactUs.htm"){
		document.getElementById("copyrightFooter").style.visibility = "visible"
		document.getElementById("copyrightFooter").style.marginTop = "-17px";
	}
	
	// Used to ensure that the page remains centered (overcome an iIE7 bug)
	realignPage();
}

if (bustcachevar) //if bust caching of external page
	var bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', url+bustcacheparameter, true)
	page_request.send(null)
}

function loadPageContent(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		document.getElementById(containerid).innerHTML=page_request.responseText;
		
		// If the learnWindow is currently open, close it on page transition
		//closeLearnWindow();
		//flashToggleActivityIndicator("false");
	}
}

function getHelp(url, containerid){
		
	var page_request = false
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	}
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
				catch (e){}
		}
	}
	else{
		return false
	}
	
	page_request.onreadystatechange=function(){
		loadHelpContent(page_request, containerid)
	}

	if (bustcachevar){ //if bust caching of external page
		var bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
		page_request.open('GET', url+bustcacheparameter, true)
		page_request.send(null)
	}
}

function loadHelpContent(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		document.getElementById(containerid).innerHTML=page_request.responseText;
	}
}