function ChangeQty(exitBox) {
	lines=new Array();
	lines=document.frmSubmit.os0.value.split("\n");
	for (i=0; i<lines.length; i++)
	{
		var pattern = /^\s{1,}$/;
		if (lines[i].match(pattern) || lines[i]=="")
		{
			lines.splice(i,1);
			i--;
		}
	}
	switch (lines.length)
	{
		case 0: case 1: case 2: case 3:
			if (exitBox=="exitBox") {
				alert ("You must enter at least 4 decals for purchase to continue.");
			}
			document.getElementById("Quantity").selectedIndex=0;
			break;
		case 4:
			document.getElementById("Quantity").selectedIndex=1;
			break;
		case 5:
			document.getElementById("Quantity").selectedIndex=2;
			break;
		case 6:
			document.getElementById("Quantity").selectedIndex=3;
			break;
		case 7:
			document.getElementById("Quantity").selectedIndex=4;
			break;
		case 8:
			document.getElementById("Quantity").selectedIndex=5;
			break;
		case 9:
			document.getElementById("Quantity").selectedIndex=6;
			break;
		case 10:
			document.getElementById("Quantity").selectedIndex=7;
			break;
		default:
			if (exitBox=="exitBox") {
				alert ("You can only have a maximum of 10 decals per roll call.");
			}
			document.getElementById("Quantity").selectedIndex=0;
			break;
	}
	ReadForm(document.frmSubmit);
}
function VerifyForm() {
	if (document.getElementById("Quantity").selectedIndex==0)
	{
		alert("You must select a at least 4 decals but not more than 10.");
		document.getElementById("Quantity").focus();
		return false;
	}
	if (document.getElementById("LogoSize").selectedIndex==0)
	{
		alert("You must select a logo size for the decals.");
		document.getElementById("LogoSize").focus();
		return false;
	}
	if (document.getElementById("LogoColor").selectedIndex==0)
	{
		alert("You must select a logo color for the decals.");
		document.getElementById("LogoColor").focus();
		return false;
	}
	if (document.getElementById("OptionalEffects").selectedIndex>0 && document.getElementById("OptionalEffectsColor").selectedIndex==0)
	{
		alert("You must select a color for the optional effect you chose.");
		document.getElementById("OptionalEffectsColor").focus();
		return false;
	}
	var pattern = /^\d{1,}$/;
	if (!(document.getElementById("MainRollCallQty").value.match(pattern)) || document.getElementById("MainRollCallQty").value<=0)
	{
		alert ("You must enter only numeric characters greater than 0.");
		document.getElementById("MainRollCallQty").focus();
		return false;
	}
}
function getRefToDivMod( divID, oDoc ) {
	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
				y = getRefToDivMod(divID,oDoc.layers[x].document); }
			return y; } }
	if( document.getElementById ) { return oDoc.getElementById(divID); }
	if( document.all ) { return oDoc.all[divID]; }
	return oDoc[divID];
}
function openPerfectPopup(oW,oTitle,oContent) {
	var x = window.open('','windowName','width=500,height=400,resizable=1');
	if( !x ) { return true; }
	x.document.open();
	x.document.write('<html><head><title>'+oTitle+'<\/title><\/head><body>'+
		(document.layers?('<layer left="0" top="0" width="'+oW+'" id="myID">'):('<div style="position:absolute;left:0px;top:0px;display:table;width:'+oW+'px;" id="myID">'))+
		oContent+(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	x.document.close();
	var oH = getRefToDivMod( 'myID', x.document ); if( !oH ) { return false; }
	var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
	x.resizeTo( oW + 200, oH + 200 );
	var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
	if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }
	else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
	else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
	if( window.opera && !document.childNodes ) { myW += 16; }
	x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );
	var scW = screen.availWidth ? screen.availWidth : screen.width;
	var scH = screen.availHeight ? screen.availHeight : screen.height;
	x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2));
	if( x.focus ) { x.focus(); }
	return false;
}
function popImage(imageURL,imageTitle) {
	var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function resizeWinTo() {\n'+
		'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
		'var oH = document.images[0].height, oW = document.images[0].width;\n'+
		'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
		'window.doneAlready = true;\n'+ //for Safari and Opera
		'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
		'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
		'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
		'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
		'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
		'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
		'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
		'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
		'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
		'}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
		'<img src='+imageURL+' alt="Loading image ..." title="" onload="resizeWinTo();">'+
		(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	return false;
}
function ToggleOptionalEffects() {
	if (document.frmSubmit.OptionalEffects.value != "")
	{
		document.frmSubmit.OptionalEffectsColor.disabled = false;
	} else {
		document.frmSubmit.OptionalEffectsColor.selectedIndex = 0;
		ReadForm (frmSubmit);
		document.frmSubmit.OptionalEffectsColor.disabled = true;
	}
	return false;
}
function Dollar (val) {
	// force to valid dollar amount
	var str,pos,rnd=0;
	if (val < .995) { rnd = 1; } // for old Netscape browsers
	str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
	pos = str.indexOf (".");
	if (pos > 0) { str = str.substring (rnd, pos + 3); }
	return str;
}
function ReadForm (obj1) {
	// process un-named selects
	var i,amt,des,obj,pos,val;
	amt = obj1.baseamt.value*1.0;       // base amount
	des = obj1.basedes.value;           // base description
	for (i=0; i<obj1.length; i++) {     // run entire form
		obj = obj1.elements[i];           // a form element
		if (obj.type == "select-one" && obj.name == "") {  // just get un-name selects
			pos = obj.selectedIndex;        // which option selected
			val = obj.options[pos].value;   // selected value
			pos  = val.indexOf ("@");       // price set?
			if (pos > 0) { amt = val.substring (pos + 1)*1.0; }
			pos = val.indexOf ("+");       // price increment?
			if (pos > 0) { amt = amt + val.substring (pos + 1)*1.0; }
			pos = val.indexOf ("%");       // percent change?
			if (pos > 0) { amt = amt + (amt * val.substring (pos + 1)/100.0); }
			if (des.length == 0) {
				des = val;
			} else {
				des = des + ", " + val;    // accumulate value
			}
		}
	}
	obj1.item_name.value = des;
	obj1.amount.value = Dollar (amt);
	if (obj1.tot) { obj1.tot.value = "$" + Dollar (amt); }
}
function doorColorSelect(imgHolder) {
	if (typeof oldDoorColorSelected != 'undefined') {
		oldDoorColorSelected.style.border="solid 1px #000000";
		oldDoorColorSelected.style.margin="7px";
	} else {
		document.getElementById('rcdpBlack').style.border="solid 1px #000000";
		document.getElementById('rcdpBlack').style.margin="7px";
	}
	imgHolder.style.border="double 6px #000000";
	imgHolder.style.margin="2px";
	oldDoorColorSelected=imgHolder;
	doorColor=oldDoorColorSelected.src.split('rcdPreview')[1].split('.')[0];
	pageModify('', doorColor, '')
}
function selectDecalColor(imgHolder) {
	if (typeof oldDecalColorSelected != 'undefined') {
		oldDecalColorSelected.style.border="solid 1px #000000";
		oldDecalColorSelected.style.margin="7px";
	} else {
		document.getElementById('rcvRed').style.border="solid 1px #000000";
		document.getElementById('rcvRed').style.margin="7px";
	}
	imgHolder.style.border="double 6px #000000";
	imgHolder.style.margin="2px";
	oldDecalColorSelected=imgHolder;
	decalColor=oldDecalColorSelected.src.split('rcv')[1].split('.')[0];
	pageModify('', '', decalColor)
}
function addLogoToList(newDecalNumber) {
	DecalText=document.frmSubmit.AddDecalText;
	decalNumberValue=newDecalNumber.value;
	myNewTest=checkFileStatus(decalNumberValue);
	var pattern = /^\d{1,}$/;
	if (myNewTest=="Fail" || decalNumberValue=="" || !decalNumberValue.match(pattern)) {
		PicCritError=('<font color="#FF0000">You must enter a logo # from our <a href="http://www.decalstyling.com/performance_logos.html" target="_blank" style="text-decoration: underline; color: #000000;">Auto & Performance Logos</a><br />to add to the preview. Please try again.</font>');
		document.getElementById("PicError").innerHTML=PicCritError;
		DecalText.value="";
		DecalText.focus();
		return false;
	}
	group=document.getElementById('logoList').childNodes;
	for (x=0; x<group.length; x++) {
		if (group[x].innerHTML == "")
		{
			document.getElementById(group[x].id).innerHTML='<table width=100% border="0" style="padding:0px 0px 0px 0px;"><tr><td valign="middle" align="left"><img id="deleteLogo" class="deleteLogo" src="delete_logo_button.gif" onClick="deleteSelectedLogo(this);"></td><td style="padding-left:5px;"><img id="LogoNumber" src="logos/logo' + DecalText.value + '.png" onload="document.getElementById(' + String.fromCharCode(39) + 'PicError' + String.fromCharCode(39) + ').innerHTML=' + String.fromCharCode(39) + String.fromCharCode(39) + '; " ></td></tr></table>';
			myObj=document.getElementById('logoList');
			myLogoList=myObj.childNodes;
			for (y=0; y<myLogoList.length; y++) {
				if (myLogoList[y].innerHTML !== "") {
					tempLogoNumber=myLogoList[y].innerHTML.split("logos/logo")[1].split(".");
					if (y < 1) {
						logoOrder=tempLogoNumber[0];
					} else {
						logoOrder=logoOrder + "," + tempLogoNumber[0];
					}
				}
			}
			pageModify(logoOrder,'','')

			break;
		} else {
			if (x == group.length-1) {
				PicCritError=('<font color="#FF0000">&nbsp;&nbsp;There is a maximum of 10 decals per roll call. You must remove a decal before you can add a new one.</font>');
				document.getElementById("PicError").innerHTML=PicCritError;
				DecalText.value="";
				DecalText.focus();
				return false;
			}
		}
	}
	DecalText.value="";
	DecalText.focus();
}
function SendDecals() {
	var sendDecalNumbers="";
	sendDecalGroup=document.getElementById('logoList').childNodes;
	for (z=0; z<sendDecalGroup.length; z++) {
		if (sendDecalGroup[z].innerHTML !== "") {
			tempLogoNumber=sendDecalGroup[z].innerHTML.split("logos/logo")[1].split(".");
			if (z < 1) {
				sendDecalNumbers=tempLogoNumber[0];
			} else {
				sendDecalNumbers=sendDecalNumbers + ":" + tempLogoNumber[0];
			}
		}
	}
	if (typeof oldDecalColorSelected == 'undefined') {
		tempDecalColorSelected="Red";
	} else {
		tempDecalColorSelected=oldDecalColorSelected.src.split('rcv')[1].split('.')[0];
	}
	window.location="roll_call_logo_kits.php?DecalNumbers="+sendDecalNumbers+"&DecalColor="+tempDecalColorSelected;
}
function moveLogo() {
	obj=document.getElementById('logoList');
	group=obj.childNodes;
	for (x=0; x<group.length; x++) {
		if (group[x].innerHTML=="")
		{
			for (y=x; y<group.length; y++) {
				if (group[y].innerHTML=="")
				{
					if (y == group.length-1)
					{
						listLogoOrder();
						return false;
					}
				} else {
					group[x].innerHTML=group[y].innerHTML;
					group[y].innerHTML="";
					break;
				}
			}
		}
	}
	listLogoOrder();
}
function listLogoOrder() {
	myLogoList=document.getElementById('logoList').childNodes;
	for (y=0; y<myLogoList.length; y++) {
		if (myLogoList[y].innerHTML !== "") {
			tempLogoNumber=myLogoList[y].innerHTML.split("logos/logo")[1].split(".");
			if (y < 1) {
				logoOrder=tempLogoNumber[0];
			} else {
				logoOrder=logoOrder + "," + tempLogoNumber[0];
			}
		} else if (y == 0 && myLogoList[y].innerHTML == "") {
			logoOrder="";
		}
	}
	if (logoOrder == "") { logoOrder="Empty"; }
	pageModify(logoOrder, '', '');
	DecalText.value="";
	DecalText.focus();
}
function deleteSelectedLogo(imgHolder) {
	imgHolderParent=imgHolder.parentNode;
	while (imgHolderParent.tagName !== "LI") {
		imgHolderParent=imgHolderParent.parentNode;
	}
	document.getElementById(imgHolderParent.id).innerHTML="";

	obj=document.getElementById('logoList');
	group=obj.childNodes;
	for (x=0; x<group.length; x++) {
		if (group[x].innerHTML=="")
		{
			for (y=x; y<group.length; y++) {
				if (group[y].innerHTML=="")
				{
					if (y == group.length-1)
					{
						listLogoOrder();
						return false;
					}
				} else {
					group[x].innerHTML=group[y].innerHTML;
					group[y].innerHTML="";
					break;
				}
			}
		}
	}
}
function pageModify(decalNumbers, doorColor, decalColor) {
	urlAdditions=undefined;
	if (doorColor=="" && typeof currentDoorColor!="undefined") { doorColor=currentDoorColor; }
	if (decalColor=="" && typeof currentDecalColor!="undefined") { decalColor=currentDecalColor; }
	if (decalNumbers=="" && typeof currentDecalNumbers!="undefined") {
		decalNumbers=currentDecalNumbers;
	} else if (decalNumbers=="Empty") {
		decalNumbers="";
		currentDecalNumbers="";
	}
	if (doorColor!="") {
		urlAdditions='?decalDoorColor='+doorColor;
		currentDoorColor=doorColor;
	}
	if (decalNumbers!="") {
		if (typeof urlAdditions=="undefined") { urlAdditions='?'; } else { urlAdditions=urlAdditions+'&'; }
		urlAdditions=urlAdditions+'decalImgList='+decalNumbers;
		currentDecalNumbers=decalNumbers;
	}
	if (decalColor!="") {
		if (typeof urlAdditions=="undefined") { urlAdditions='?'; } else { urlAdditions=urlAdditions+'&'; }
		urlAdditions=urlAdditions+'decalColor='+decalColor;
		currentDecalColor=decalColor;
	}
	if (typeof urlAdditions=="undefined") {
		document.getElementById("previewDoor").src='MergeDoor.php';
	} else {
		document.getElementById("previewDoor").src='MergeDoor.php'+urlAdditions;
	}
}
function checkFileStatus(testFileName) {
	try {
		fileStatus = new XMLHttpRequest();
	} catch(err1) {
		try {
			fileStatus = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (err2) {
			try {
				fileStatus = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (err3) {
				fileStatus = false;
			}
		}
	}
	myRand = parseInt(Math.random()*999999999999999);
	var myURL = "roll_call_file_test.php?testFileName="+testFileName+"&rand="+myRand;
	fileStatus.open("GET", myURL, false);
	fileStatus.send(null);
	if (fileStatus.responseText=="False") {
		return("Fail");
	}
}
function toggleEffects() {
	if (document.getElementById('effectSamples').style.display=='block') {
		document.getElementById('effectSamples').style.display='none';
		document.getElementById('exampleText').innerHTML="see";
	} else {
		document.getElementById('effectSamples').style.display='block';
		document.getElementById('exampleText').innerHTML="hide";
	}
}
