// JavaScript Document

var xmlHttp

// onresize for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;	// holds id of currently visible layer

function swapLayers(id) {
  
  id = "lyr" + id; 
  
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
  
}

function showLayer(id) {
	
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

function showColor(gender, design)
{  
	
	xmlHttp=GetXmlHttpObject()
	// calls on the GetXmlHttpObject function to create an XMLHTTP object
	
	if (xmlHttp==null)
 	{
 		alert ("Browser does not support HTTP Request")
 		return
 	}
	var url="tshirts/showcolor.php" // name of processing script
	
	url=url+"?gender="+gender+"&design="+design
	// defines the url (filename) to send to the server
	// adds a parameters to the url with the current content of the form

	url=url+"&sid="+Math.random()
	// adds a random number to prevent the server from using a cached file
	xmlHttp.onreadystatechange=stateChanged 
	// call stateChanged when a change is triggered
	xmlHttp.open("GET",url,true)
	// opens the XMLHTTP object with the given url
	xmlHttp.send(null)
	// sends an HTTP request to the server
	
	}

	function stateChanged() 
	{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 	{ 
 	document.getElementById("color").innerHTML=xmlHttp.responseText
	// generates display of current colors 
 	} 
	}

	function GetXmlHttpObject()
	{
	var xmlHttp=null;
	try
 	{
 	// Firefox, Opera 8.0+, Safari
 	xmlHttp=new XMLHttpRequest();
 	}
	catch (e)
 	{
 	//Internet Explorer
 	try
  	{
  	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  	}
 	catch (e)
  	{
  	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
 	}		
	return xmlHttp;


}
