
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");
		for(x=0;x<StatusField.length;x++)
		{	if(StatusField[x] == '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
			{	ThisForm.elements[StatusField[x]].value = Prod[ThisIndex][x];
			}
		}
	}
}


function SwitchProdImg(ThisIndex)
{	var ThisImgUrl;
	if(!ThisIndex){ThisIndex = 0}
	var FieldNameIndex
	FieldNameIndex = GetFieldIndex('ImgMedUrl');
	if(Prod[ThisIndex][FieldNameIndex])
	{	ThisImgUrl = Prod[ThisIndex][FieldNameIndex];
		if(document.images)
		{	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 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 '';
	}
}