function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function showImage(url) {
var help_window = window.open(url,"image_window", "width=636,height=636,resizable=0,scrollbars=0");
help_window.focus();
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3)
	{
	test=args[i+2];
	val=MM_findObj(args[i]);
	if (val)
		{
		nm=val.name;
		if ((val=val.value)!="")
			{
			if (test.indexOf('isEmail')!=-1)
				{
				p=val.indexOf('@');
				if (p<1 || p==(val.length-1)) errors+='Please enter an e-mail address.\n';
				}
			else if (test!='R')
				{
				num = parseFloat(val);
				if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
				if (test.indexOf('inRange') != -1)
					{
					p=test.indexOf(':');
					min=test.substring(8,p);
					max=test.substring(p+1);
					if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
			}
		else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n';
		}
	}
if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}

function checkscript() {
var AttCode=document.forms.PRODProducts.elements['AttributeCode[1]'].value;
if ((AttCode=='SILVER_PLATE')||(AttCode=='BRASS_PLATE')||(AttCode=='BRASS_PLATES'))
	{
	var alphaponly = /^[a-zA-Z\.\s]+$/;
	if (!(document.forms.PRODProducts.elements['AttributeValue[2]'].value.match(alphaponly)) && (document.forms.PRODProducts.elements['AttributeValue[2]'].value!=''))
		{
		alert ("Please use letters and periods only.");
		document.forms.PRODProducts.elements['AttributeValue[2]'].focus();
		return false;
		}
	if ((document.forms.PRODProducts.elements['AttributeValue[2]'].disabled==false) && (document.forms.PRODProducts.elements['AttributeValue[2]'].value==''))
		{
		alert ("Please enter a script for your ID Plate.");
		document.forms.PRODProducts.elements['AttributeValue[2]'].focus();
		return false;
		}
	}
else if (AttCode=='EMBOSS')
	{
	return true;
	}
else if (AttCode=='AMOUNT')
	OKTOGO=false;
	ATT=document.forms.PRODProducts.elements['AttributeValue[1]'];
	ATTtotal=ATT.length;
	for(AMC=0;AMC<ATTtotal;AMC++)
		{
		if (ATT[AMC].checked) OKTOGO=true;
		}
	if (!OKTOGO)
		{
		alert ("Please select an amount for the Gift Certificate.");
		return false;
		}
else return true;
}

function embosspreview() {
	var inital=new Array(document.forms.PRODProducts.elements['EmbossInital[1]'].value,document.forms.PRODProducts.elements['EmbossInital[2]'].value,document.forms.PRODProducts.elements['EmbossInital[3]'].value);
	var useinitals=document.forms.PRODProducts.elements['EmbossPeriods'].checked;
	var initalpreview=document.forms.PRODProducts.elements['AttributeValue[1]'];
	var x=0;

	for(x=0; x<3; x++)
	{
		if (useinitals) {if(inital[x]) inital[x]=inital[x] + '.';}
	}
	initalpreview.value='';
	for(x=0; x<3; x++)
	{
		if (inital[x]) initalpreview.value=initalpreview.value + inital[x];
	}
}

function checkinitals(thisinital) {

var alphaonly = /^[a-zA-Z]+$/;
thisinital.value=thisinital.value.toUpperCase();
if (thisinital.value.match(alphaonly) || thisinital.value=='')
	{
	embosspreview();
	thisinital.select();
	return true;
	}
else
	{
	alert('Please use letters only.');
	thisinital.value='';
	thisinital.focus();
	thisinital.select();
	return false;
	}
}

function openemboss(thisoption){

if (thisoption.value=="Yes")
	{
	document.getElementById("EMBOSSAGREE").style.display='none';
	document.getElementById("EMBOSSTABLE").style.display='';
	embosspreview();
	}
else
	{
	document.getElementById("EMBOSSAGREE").style.display='';
	document.getElementById("EMBOSSTABLE").style.display='none';
	document.forms.PRODProducts.elements['AttributeValue[1]'].value='';
	}

}