
function GetFieldIndex(ThisFieldName)
{	var x;
	for(x=0;x<FieldName.length;x++)
	{	if(FieldName[x] == ThisFieldName){	return x	}
	}
}

function OpenStatusWindow()
{	OpenWindow(Magna_BaseUrl+'Product_Status.html'+CurrentStatus,400,150,'DataWindow',50,50)
}

function GetProdStatus(ThisForm,ThisIndex)
{	var x;
	SelectedProdOption = ThisIndex;
	SwitchProdImg(ThisIndex);
	if(Magna_ProdType == 'HG')
	{	var StatusField = new Array("Code","Retail","Status","Shipping","","","Qoh","ShipDate","DS","","ImgMedWidth","ImgMedHeight","ImgHiWidth","ImgHiHeight");
		for(x=0;x<StatusField.length;x++)
		{	if(StatusField[x] == 'Status' && document['Status'])
			{	if(Prod[ThisIndex][x].indexOf('In') != -1)
				{	document['Status'].src= 'images_common/stockbutton_in_off.gif';
					CurrentStatus = '#InStock';
				}
				if(Prod[ThisIndex][x].indexOf('Low') != -1)
				{	document['Status'].src= 'images_common/stockbutton_low_off.gif';
					CurrentStatus = '#LowStock';
				}
				if(Prod[ThisIndex][x].indexOf('Out') != -1)
				{	document['Status'].src= 'images_common/stockbutton_out_off.gif';
					CurrentStatus = '#OutStock';
				}
				if(Prod[ThisIndex][x] == '')
				{	document['Status'].src='images/2ptblank.gif';
					CurrentStatus = '';
				}
			}
			else if(StatusField[x] == 'ImgHiWidth')
			{	Magna_ProdImgHi_Width = Prod[ThisIndex][x];
			}
			else if(StatusField[x] == 'ImgHiHeight')
			{	Magna_ProdImgHi_Height = Prod[ThisIndex][x];
			}
			else if(StatusField[x] == 'DS')
			{	if(Prod[ThisIndex][x] == 'Y')
				{	if(document.getElementById){document.getElementById('DropShipMsg').style.visibility ="visible";}
					else if(document.all){document.all['DropShipMsg'].style.visibility ="visible";}
					else if(document.layers){document.layers['DropShipMsg'].visibility ="visible";}
					document['Status'].src= 'images_common/stockbutton_so_off.gif';
					CurrentStatus = '#SpecialOrder';
					alert('This is a special order item. Extended shipping, shipping restrictions and/or shipment directly from manufacturer might be required.\n\nPlease note expected shipment date.');
				}
				else
				{	if(document.getElementById){document.getElementById('DropShipMsg').style.visibility ="hidden";}
					else if(document.all){document.all['DropShipMsg'].style.visibility ="hidden";}
					else if(document.layers){document.layers['DropShipMsg'].visibility ="hidden";}
				}
			}
			else
			{	if(StatusField[x] != '' && ThisForm.elements[StatusField[x]])
				{ThisForm.elements[StatusField[x]].value = Prod[ThisIndex][x];
				}
			}
		}
	}
}
 
//concept retail
function getDisplayControlXML(thisSwatchList)
{	var xml;
	xml = "<display-control id=\"123\">";
	xml += "<variations active=\"";
	xml += thisSwatchList; //comma separated list
	xml += "\" order=\"sequential\" />";
	xml += "</display-control>";
	return xml;
}

function MagnaVerifyProd(ThisForm)
{	if(ThisForm.elements['ItemId'] && (ThisForm.elements['ItemId'].type == 'hidden' || (ThisForm.elements['ItemId'].selectedIndex > 0)))
	{	if(Magna_ProdType == 'HG')
		{	var itemIndex = 0;
			var prodOptions = '';
			if(ThisForm.elements['ItemId'].type.indexOf('select') != -1)
			{	itemIndex = ThisForm.elements['ItemId'].selectedIndex;
				prodOptions = ' "'+ThisForm.elements['ItemId'].options[itemIndex].text+'" ';
			}
			var prodsOrdered = 1*ThisForm.elements['ItemQty'].value;
			var prodName = ThisForm.elements['MagnaProdName'].value;
			if(Prod[itemIndex][6] <= 0)
			{	return confirm('The '+prodName+prodOptions+' is currently out of stock. The quantity you ordered will be backordered and shipped as soon as we receive them.\n\nClick OK to continue or CANCEL to change your order.')
				
			}
			if(prodsOrdered > Prod[itemIndex][6])
			{	return confirm('The quantity of the '+prodName+prodOptions+' currently available is '+Prod[itemIndex][6]+'. We will ship you as many as we have available and the rest will be placed in backorder status.\n\nClick OK to continue or CANCEL to change your order Qty.')
			}
			if(ThisForm.elements['AddOnItemId'] && ThisForm.elements['AddOnItemId'].selectedIndex == 0)
			{	alert('Please select an option for your gift item!');
				return false;
			}
		}
	}
	else
	{	alert('You did not select any options!');
		return false;
	}
	return true;
}


function SwitchProdImg(ThisIndex)
{	var ThisImgUrl;
	if(!ThisIndex){ThisIndex = 0}
	var FieldNameIndex
	if(window.MagnaCRdisplay)
	{ 	FieldNameIndex = GetFieldIndex('SwatchCode');
		if(Prod[ThisIndex][FieldNameIndex])
		{	selectCategory("VARIATION",Prod[ThisIndex][FieldNameIndex]);
		}
	}
	else
	{	FieldNameIndex = GetFieldIndex('ImgMedUrl');
		if(Prod[ThisIndex][FieldNameIndex])
		{	ThisImgUrl = Prod[ThisIndex][FieldNameIndex];
			FieldNameIndex = GetFieldIndex('ImgMedWidth');
			var ThisImgWidth = Prod[ThisIndex][FieldNameIndex];
			FieldNameIndex = GetFieldIndex('ImgMedHeight');
			var ThisImgHeight = Prod[ThisIndex][FieldNameIndex];
			if(document.getElementById )
			{	document.getElementById('ProdImg').width = ThisImgWidth;
				document.getElementById('ProdImg').height = ThisImgHeight;
				document.getElementById('ProdImg').src = Magna_BaseUrl+ThisImgUrl;
			}
			else if(document.all)
			{	document.all['ProdImg'].width = ThisImgWidth;
				document.all['ProdImg'].height = ThisImgHeight;
				document.all['ProdImg'].src = Magna_BaseUrl+ThisImgUrl;
			}
			else if(document.images && ThisImgUrl)
			{	document.images['ProdImg'].src = Magna_BaseUrl+ThisImgUrl;
			}
		}
	}
}

function DisplayProdImgHi(ThisIndex,ThisImgDescr,ThisImgWidth,ThisImgHeight)
{	var ThisImgUrl;
	if(!ThisImgDescr){ThisImgDescr = Magna_PageTitle;}
	if(!ThisImgWidth){ThisImgWidth = Magna_ProdImgHi_Width;}
	if(!ThisImgHeight){ThisImgHeight = Magna_ProdImgHi_Height;}
	if(!ThisIndex)
	{	ThisIndex = SelectedProdOption;
	}
	var FieldNameIndex;
	FieldNameIndex = GetFieldIndex('ImgHiUrl');
	if(Prod[ThisIndex][FieldNameIndex])
	{	ThisImgUrl = Prod[ThisIndex][FieldNameIndex];
		if(ThisImgUrl && ThisImgWidth && ThisImgHeight)
		{	MakeImageWindow(Magna_BaseUrl+ThisImgUrl,ThisImgDescr,ThisImgWidth,ThisImgHeight);
		}
	}
}


function viewLarger(ThisVpn,ThisSwatchCode,ThisImgDescr,ThisImgWidth,ThisImgHeight)
{	var ThisImgUrl;
	if(!ThisImgDescr){ThisImgDescr = Magna_PageTitle;}
	if(!ThisImgWidth){ThisImgWidth = Magna_ProdImgHi_Width;}
	if(!ThisImgHeight){ThisImgHeight = Magna_ProdImgHi_Height;}
	if(ThisVpn && ThisSwatchCode && ThisImgWidth > 0 && ThisImgHeight > 0)
	{	ThisImgUrl = 'images_product-cr1/customers/c226/'+ThisVpn+'/generated/'+ThisVpn+'_'+ThisSwatchCode+'_'+ThisImgWidth+'x'+ThisImgHeight+'.jpg';
		MakeImageWindow(Magna_BaseUrl+ThisImgUrl,ThisImgDescr,ThisImgWidth,ThisImgHeight);
	}
	else
	{	alert('Missing Data: hi-resolution image could not be referenced');
	}
	
}


function VerifyData(FormName,ReqFields,Delimeter)
{	var	Error = 0;
		j = 0;
		EmptyFields = new Array();
		Required = new Array();
		HumanName = new Array();
		FieldAry = new Array();
		FieldAry = ReqFields.split(Delimeter);
	for(i=0;i<FieldAry.length;i++)
	{	var tempAry = new Array();
		tempAry = FieldAry[i].split("=");
		Required[i] = tempAry[0];
		HumanName[i] = tempAry[1];
	}
		
	for (i=0; i<Required.length; i++)
	{	
		ValueOfField = GetFieldValue(FormName,Required[i]);
		if (ValueOfField == null)	{ValueOfField = ""};
		LengthOfField = ValueOfField.length;
		if (LengthOfField <= 0)
		{	Error++;
			EmptyFields[j] = HumanName[i];
			j++;
		}
	}
	if (Error > 0)
	{	WarnUser(EmptyFields);
		return 0;
	}
	if (Error == 0)
	{	return 1;
	}
}

function WarnUser(ErrorFields)
{	var Message = "The following fields are required:\n\n";
	for (k=0; k<ErrorFields.length;k++)
	{	Message += "	" + ErrorFields[k] + "\n";
	}
	Message += "\nPlease fill them in!";
	alert(Message);
}

function GetFieldValue(FormName,FormField) //CANNOT CHECK RADIO BUTTONS
{	var Q="";
	if(FormName.elements[FormField])
	{	var TypeOfField = FormName.elements[FormField].type;
		var ValueOfField="";
		if (TypeOfField.toLowerCase().indexOf("select") >= 0)
		{	Q =  FormName.elements[FormField].selectedIndex;
			if (Q > 0){ValueOfField = FormName.elements[FormField].options[Q].value}
		}
		else if (TypeOfField.toLowerCase() == "checkbox")
		{	if (FormName.elements[FormField].checked){Q =  FormName.elements[FormField].value}
					ValueOfField =  Q;
					
		}
		else{ValueOfField = FormName.elements[FormField].value}
		return ValueOfField;
	}else{
		return '';
	}
}

var MagnaProdDescrOn = "<a href=\""+MagnaProdUrl+"\"><IMG SRC=\"images/btn_prod_descr-on.gif\" name=\"BtnProdDesc\" id=\"BtnProdDesc\" WIDTH=\"73\" HEIGHT=\"15\" BORDER=\"0\" ></a><IMG SRC=\"images/spacer.gif\" WIDTH=\"2\" HEIGHT=\"2\" BORDER=\"0\">";

var MagnaProdDescrOff = "<a href=\""+MagnaProdUrl+"\"><IMG SRC=\"images/btn_prod_descr-off.gif\" name=\"BtnProdDesc\" id=\"BtnProdDesc\" WIDTH=\"73\" HEIGHT=\"15\" BORDER=\"0\" onMouseOver=\"this.src='images/btn_prod_descr-ovr.gif'\" onMouseOut=\"this.src='images/btn_prod_descr-off.gif'\"></a><IMG SRC=\"images/spacer.gif\" WIDTH=\"2\" HEIGHT=\"2\" BORDER=\"0\">";

var MagnaProdFeatureOn = "<a href=\""+MagnaProdUrl+"/Display/Alt3\"><IMG SRC=\"images/btn_prod_feat-on.gif\" name=\"BtnProdFeat\" WIDTH=\"84\" HEIGHT=\"15\" BORDER=\"0\" ></a><IMG SRC=\"images/spacer.gif\" WIDTH=\"2\" HEIGHT=\"2\" BORDER=\"0\">";

var MagnaProdFeatureOff = "<a href=\""+MagnaProdUrl+"/Display/Alt3\"><IMG SRC=\"images/btn_prod_feat-off.gif\" name=\"BtnProdFeat\" WIDTH=\"84\" HEIGHT=\"15\" BORDER=\"0\" onMouseOver=\"this.src='images/btn_prod_feat-ovr.gif'\" onMouseOut=\"this.src='images/btn_prod_feat-off.gif'\"></a><IMG SRC=\"images/spacer.gif\" WIDTH=\"2\" HEIGHT=\"2\" BORDER=\"0\">";

var MagnaProdSwatchOn = "<a href=\""+MagnaProdUrl+"/Display/Alt2\"><IMG SRC=\"images/btn_prod_swatch-on.gif\" name=\"BtnProdSwatch\" id=\"BtnProdSwatch\" WIDTH=\"62\" HEIGHT=\"15\" BORDER=\"0\" ></a><IMG SRC=\"images/spacer.gif\" WIDTH=\"2\" HEIGHT=\"2\" BORDER=\"0\">";

var MagnaProdSwatchOff = "<a href=\""+MagnaProdUrl+"/Display/Alt2\"><IMG SRC=\"images/btn_prod_swatch-off.gif\" name=\"BtnProdSwatch\" id=\"BtnProdSwatch\" WIDTH=\"62\" HEIGHT=\"15\" BORDER=\"0\" onMouseOver=\"this.src='images/btn_prod_swatch-ovr.gif'\" onMouseOut=\"this.src='images/btn_prod_swatch-off.gif'\"></a><IMG SRC=\"images/spacer.gif\" WIDTH=\"2\" HEIGHT=\"2\" BORDER=\"0\">";

var MagnaProdSpecsOn = "<a href=\""+MagnaProdUrl+"/Display/Alt1\"><IMG SRC=\"images/btn_prod_specs-on.gif\" name=\"BtnProdSpecs\" id=\"BtnProdSpecs\" WIDTH=\"41\" HEIGHT=\"15\" BORDER=\"0\" ></a><IMG SRC=\"images/spacer.gif\" WIDTH=\"2\" HEIGHT=\"2\" BORDER=\"0\">";

var MagnaProdSpecsOff = "<a href=\""+MagnaProdUrl+"/Display/Alt1\"><IMG SRC=\"images/btn_prod_specs-off.gif\" name=\"BtnProdSpecs\" id=\"BtnProdSpecs\" WIDTH=\"41\" HEIGHT=\"15\" BORDER=\"0\" onMouseOver=\"this.src='images/btn_prod_specs-ovr.gif'\" onMouseOut=\"this.src='images/btn_prod_specs-off.gif'\"></a><IMG SRC=\"images/spacer.gif\" WIDTH=\"2\" HEIGHT=\"2\" BORDER=\"0\">";

var MagnaProdEmailOn = "<a href=\""+MagnaProdUrl+"/Display/Alt4\"><IMG SRC=\"images/btn_prod_email-on.gif\" name=\"BtnProdEmail\" id=\"BtnProdEmail\" WIDTH=\"88\" HEIGHT=\"15\" BORDER=\"0\" ></a><br>";

var MagnaProdEmailOff = "<a href=\""+MagnaProdUrl+"/Display/Alt4\"><IMG SRC=\"images/btn_prod_email-off.gif\" name=\"BtnProdEmail\" id=\"BtnProdEmail\" WIDTH=\"88\" HEIGHT=\"15\" BORDER=\"0\" onMouseOver=\"this.src='images/btn_prod_email-ovr.gif'\" onMouseOut=\"this.src='images/btn_prod_email-off.gif'\"></a><br>";