// Create a object to connect to our web service, different based on
// what browser we need
function GetXmlHttp()
{
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E)
		{
			xmlhttp = false;
		}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest)
	{
		try
		{
			xmlhttp = window.createRequest();
		}
		catch (e)
		{
			xmlhttp=false;
		}
	}
	
	return xmlhttp;
}

function CheckIfCustomFrame(a, b, series, color, quant, type)
{
if (type == 0) 
{
	// Connect to our web service
	var oXmlHttp = GetXmlHttp();
	oXmlHttp.open(
		"POST",
		"/CustomFrame/CustomFrameService.asmx",
		false
	);
	
	oXmlHttp.setRequestHeader("Content-Type", "text/xml");
	oXmlHttp.setRequestHeader("SOAPAction", "http://tempuri.org/CustomFrame/CustomFrameService/IsCustomFrame");
	oXmlHttp.send(" \
		<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \
			xmlns:xsd='http://www.w3.org/2001/XMLSchema' \
			xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
			<soap:Body> \
				<IsCustomFrame xmlns='http://tempuri.org/CustomFrame/CustomFrameService'> \
					<width>" + a + "</width> \
					<length>" + b + "</length> \
				</IsCustomFrame> \
			</soap:Body> \
		</soap:Envelope> \
	");

	// If this is an actual custom frame, head into the custom page, otherwise let them know it's not needed
	if (oXmlHttp.responseXML.documentElement.getElementsByTagName('IsCustomFrameResult')[0].childNodes[0].nodeValue == 'true')
	{
		window.location="CustomFrame/CustomFrame.aspx?series=" + series + "&width=" + a + "&length=" + b + "&color=" + color + "&quant=" + quant + "&type=" + type; 
	}
	else
	{
		alert('A custom frame is not needed for the size you entered');
	}
}
else
{
	window.location="CustomFrame/CustomFrame.aspx?series=" + series + "&width=" + a + "&length=" + b + "&color=" + color + "&quant=" + quant + "&type=" + type; 
}

}

function FillDropDown(series, lst)
{
	// Connect to our web service
	var oXmlHttp = GetXmlHttp();
	var oXmlHttpID = GetXmlHttp();
	var i = 0;

	// Color name	
	oXmlHttp.open(
		"POST",
		"/CustomFrame/CustomFrameService.asmx",
		false
	);
	
	oXmlHttp.setRequestHeader("Content-Type", "text/xml");
	oXmlHttp.setRequestHeader("SOAPAction", "http://tempuri.org/CustomFrame/CustomFrameService/GetSeriesColors");
	oXmlHttp.send(" \
		<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \
			xmlns:xsd='http://www.w3.org/2001/XMLSchema' \
			xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
			<soap:Body> \
				<GetSeriesColors xmlns='http://tempuri.org/CustomFrame/CustomFrameService'> \
					<seriesName>" + series + "</seriesName> \
				</GetSeriesColors> \
			</soap:Body> \
		</soap:Envelope> \
	");
	
	// Color ID
	oXmlHttpID.open(
		"POST",
		"/CustomFrame/CustomFrameService.asmx",
		false
	);
	
	oXmlHttpID.setRequestHeader("Content-Type", "text/xml");
	oXmlHttpID.setRequestHeader("SOAPAction", "http://tempuri.org/CustomFrame/CustomFrameService/GetSeriesColorIDs");
	oXmlHttpID.send(" \
		<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \
			xmlns:xsd='http://www.w3.org/2001/XMLSchema' \
			xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
			<soap:Body> \
				<GetSeriesColorIDs xmlns='http://tempuri.org/CustomFrame/CustomFrameService'> \
					<seriesName>" + series + "</seriesName> \
				</GetSeriesColorIDs> \
			</soap:Body> \
		</soap:Envelope> \
	");
	
	
	for (i = 0; i < oXmlHttp.responseXML.documentElement.getElementsByTagName('GetSeriesColorsResult')[0].childNodes.length; i++)
	{
		lst.options[lst.length] = new Option(oXmlHttp.responseXML.documentElement.getElementsByTagName('GetSeriesColorsResult')[0].childNodes[i].text, 
								oXmlHttpID.responseXML.documentElement.getElementsByTagName('GetSeriesColorIDsResult')[0].childNodes[i].text, false, false);
	}
	
	if (lst.options.length > 0)
	{
		lst.options[0].selected = true;
	}

}

// We need to have two quantity inputs and two hidden fields, one for our 
// server to use and one to submit to 
// the shopping cart.  This function keeps them in sync
function SyncFields(source, destination)
{
	destination.value = source.value;
	
	return true;
}
