function fashioncraftCleanText( text ) {
	return njwfCleanText( text.replace( / /g, "" ).replace( /-/g, "" ).replace( /%20/g, "" ).replace( /'/g, "" ).replace( /\(/g, "" ).replace( /\)/g, "" ).toLowerCase() );
}
function njwfCleanText( text ) {
	return text.replace( /\$/g, "" ).replace( /\./g, "" ).replace( /\(/g, "" ).replace( /\)/g, "" ).replace( /\+/g, "" ).replace( /([0-9]+)/g, "" ).replace( /&amp;/g, "" ).replace( /&/g, "" );
	//return text.replace( /$/g, "" ).replace( /\./g, "" ).replace( /(/g, "" ).replace( /)/g, "" ).replace( /\+/g, "" );
}

function fashioncraftAlert( data ) { alert( data ); }
function jqueryAlert( data ) { jQuery("body").append("<br>" + data); }

function fashioncraftLabels( layout, backgroundTopColor, borderBottomColor, pattern, patternColor, design, font, textLine1, textLine2, textLine3, textLine1Color, textLine2Color, quantity, validate, labelType, tagsOrStickers ) {
	//alert("pattern color = " + patternColor + "\r\ndesign = " + design);
	jQuery("form[name='orderform']").attr("id","FCorderformID");
	var transferTo = "FCorderformID";  /* optional, enter ID of element you want the transfer animation to move to
													* leave blank if you do not want to trigger the transfer animation  */ 
	var formToSubmit = "FCorderformID"; /* optional, enter ID of form you want to be automatically submitted when
													* shopper clicks "Add to cart"
													* leave blank if you do not want to submit the form */
	if ( jQuery("select option:ciContains('soft royal')").length > 1 ) {
		//alert(jQuery("select option:contains('Soft Royal')").length);
		var borderMenu = jQuery(jQuery("select option:ciContains('soft royal')")[1]);
		var bgMenu = jQuery(jQuery("select option:ciContains('soft royal')")[0]);
	} else {
		var borderMenu = jQuery(jQuery("select option:ciContains('soft royal')")[0]);
		var bgMenu = borderMenu;
	}
	var borderColorID = borderMenu.parent().attr("id"); // ID of your border color dropdown menu
	var backgroundColorID = bgMenu.parent().attr("id"); // ID of your background color dropdown menu
	var patternID = jQuery("select option:ciContains('argyle')").parent().attr("id"); // ID of your pattern dropdown menu
	var patternColorID = jQuery("select option:ciContains('mocha'):last").parent().attr("id"); // ID of your pattern color dropdown menu
	var designID = jQuery("select option:ciContains('coconut palm tree')").parent().attr("id"); // ID of your design dropdown menu
	var fontID = jQuery("select option:ciContains('handwritten')").parent().attr("id"); // ID of your font dropdown menu
	
	
	if ( jQuery("select option:ciContains('black')").length ) {
		var textColorMainMenuOffset = -1;
		var textColorTwoMenuOffset = 0;
	}
	var line1ColorMenu = jQuery(jQuery("select option:ciContains('black')")[jQuery("select option:ciContains('black')").length + textColorMainMenuOffset]);
	//jQuery("body").append("<br>total menus containing 'black' = " + jQuery("select option:contains('Black')").length );
	var line2ColorMenu = jQuery(jQuery("select option:ciContains('black')")[jQuery("select option:ciContains('black')").length + textColorTwoMenuOffset]);
	var line1ColorID = line1ColorMenu.parent().attr("id"); // ID of your color dropdown menu for text line 1
	var line2ColorID = line2ColorMenu.parent().attr("id"); // ID of your color dropdown menu for text line 1 and 2
	//jQuery("body").append("<br>line1ColorID = " + line1ColorID );
	//jQuery("body").append("<br>line2ColorID = " + line2ColorID );
	
	
	
	var layoutMenu = jQuery(jQuery("select option:ciContains('a')")[0]);
	var layoutID = layoutMenu.parent().attr("id"); // ID of your layout dropdown menu
	
	var prodOptionText = jQuery("input[type=text][name*='product_options']");
	//jQuery("body").append("<br>found text options: " + prodOptionText.length);
	var textOption1 = prodOptionText[0];
	var textOption2 = prodOptionText[1];
	var textOption3 = prodOptionText[2];
	
	var line1ID = jQuery(textOption1).attr("id"); // ID of your text line 1 field
	var line2ID = jQuery(textOption2).attr("id"); // ID of your text line 2 field
	var line3ID = jQuery(textOption3).attr("id"); // ID of your text line 3 field
	var quantityID = "product_avail"; // ID of your quantity field
	
	
	var tagsOrStickersMenu = jQuery(jQuery("select:ciContains('tags'):ciContains('stickers')")[0]);
	var tagsOrStickersID = tagsOrStickersMenu.attr("id"); // ID of your quantity field
	// designMap not currently in use
	designMap = {
		"022":{"a":"General Fleur de Lis","b":"general-fleur-de-lis"},
		"022B":{"a":"General Fleur de Lis (reversed)","b":"general-fleur-de-lis-reversed"},
		"058":{"a":"Coconut Palm Tree","b":"coconut-palm-tree"},
		"064":{"a":"Eiffel Tower","b":"eiffel-tower"},
		"065":{"a":"Thatch Umbrella","b":"thatch-umbrella"},
		"081":{"a":"Winter Snowflake","b":"winter-snowflake"},
		"082":{"a":"Starfish","b":"starfish"},
		"083":{"a":"Martini","b":"martini"},
		"098":{"a":"Vegas","b":"vegas"},
		"241":{"a":"Elegant Gift","b":"elegant-gift"},
		"244":{"a":"Black Shoe","b":"black-shoe"},
		"076":{"a":"Noah's Ark","b":"noah's-ark"},
		"006":{"a":"Baby Text (regular)","b":"baby-text-regular"},
		"007":{"a":"Baby Text (reverse)","b":"baby-text-reverse"},
		"008":{"a":"Baby with Bib","b":"baby-with-bib"},
		"008D":{"a":"Baby with Bib D","b":"baby-with-bib-d"},
		"066":{"a":"New Babies with Stork","b":"new-babies-with-stork"},
		"066B":{"a":"New Babies with Stork (B)","b":"new-babies-with-stork-b"},
		"067":{"a":"BW Happy Baby","b":"bw-happy-baby"},
		"067B":{"a":"BW Happy Baby (reverse) (B)","b":"bw-happy-baby-reverse-b"},
		"068":{"a":"Baby Booties","b":"baby-booties"},
		"069":{"a":"Quack Quack","b":"quack-quack"},
		"070":{"a":"Baby Peas in Pod","b":"baby-peas-in-pod"},
		"070D":{"a":"Baby Peas in Pod (B)","b":"baby-peas-in-pod-b"},
		"071":{"a":"Shower Umbrella (brown)","b":"shower-umbrella-brown"},
		"072":{"a":"Soft Blocks","b":"soft-blocks"},
		"073":{"a":"Queen of Jungle","b":"queen-of-jungle"},
		"074":{"a":"King of Jungle","b":"king-of-jungle"},
		"075":{"a":"Monkey","b":"monkey"},
		"077":{"a":"Jungle","b":"jungle"},
		"130":{"a":"It's a Boy","b":"it's-a-boy"},
		"131":{"a":"It's a Girl","b":"it's-a-girl"},
		"136":{"a":"Yellow Prints","b":"yellow-prints"},
		"137":{"a":"Blue Prints","b":"blue-prints"},
		"138":{"a":"Pink Prints","b":"pink-prints"},
		"143":{"a":"Blue Bear","b":"blue-bear"},
		"144":{"a":"Pink Bear","b":"pink-bear"},
		"145":{"a":"Blue Bear 2","b":"blue-bear-2"},
		"146":{"a":"Pink Bear 2","b":"pink-bear-2"},
		"147":{"a":"Yellow Bear","b":"yellow-bear"},
		"017":{"a":"General Cake and Candles","b":"general-cake-and-candles"},
		"028":{"a":"General Sweet Sixteen","b":"general-sweet-sixteen"},
		"029":{"a":"Graduate (regular)","b":"graduate-regular"},
		"030":{"a":"Graduate (reverse)","b":"graduate-reverse"},
		"089":{"a":"Balloons","b":"balloons"},
		"151":{"a":"Sweet 15","b":"sweet-15"},
		"152":{"a":"Sweet 16","b":"sweet-16"},
		"161":{"a":"Twentyfive Champagne","b":"twentyfive-champagne"},
		"162":{"a":"Fourty Champagne","b":"fourty-champagne"},
		"163":{"a":"Fifty Champagne","b":"fifty-champagne"},
		"178":{"a":"Pink 16 Flourish","b":"pink-16-flourish"},
		"179":{"a":"Pink 15 Flourish","b":"pink-15-flourish"},
		"180":{"a":"Grey 25 Flourish","b":"grey-25-flourish"},
		"181":{"a":"Maroon 40 Flourish","b":"maroon-40-flourish"},
		"182":{"a":"Gold 50 Flourish","b":"gold-50-flourish"},
		"189":{"a":"Handbag","b":"handbag"},
		"237":{"a":"Butterfly Quince Anos","b":"butterfly-quince-anos"},
		"238":{"a":"Butterfly Sweet 16","b":"butterfly-sweet-16"},
		"239":{"a":"Cake 15","b":"cake-15"},
		"240":{"a":"Cake 16","b":"cake-16"},
		"242":{"a":"Cup","b":"cup"},
		"243":{"a":"Mocha Cupcake","b":"mocha-cupcake"},
		"048":{"a":"Religious Angel","b":"religious-angel"},
		"049":{"a":"Religious Cross","b":"religious-cross"},
		"078":{"a":"Communion Girl","b":"communion-girl"},
		"079":{"a":"Communion Boy","b":"communion-boy"},
		"080":{"a":"Madonna and Child","b":"madonna-and-child"},
		"122":{"a":"Star of David","b":"star-of-david"},
		"124":{"a":"Chalice","b":"chalice"},
		"125":{"a":"Ornate Cross","b":"ornate-cross"},
		"126":{"a":"Plain Cross","b":"plain-cross"},
		"170":{"a":"Blue Simple Cross","b":"blue-simple-cross"},
		"171":{"a":"Pink Simple Cross","b":"pink-simple-cross"},
		"172":{"a":"Grey Simple Cross","b":"grey-simple-cross"},
		"212":{"a":"Little Angel","b":"little-angel"},
		"012":{"a":"Beach Seashell","b":"beach-seashell"},
		"014":{"a":"Fall Leaves","b":"fall-leaves"},
		"016":{"a":"General Butterfly","b":"general-butterfly"},
		"033":{"a":"Love Big Heart Little Heart","b":"love-big-heart-little-heart"},
		"034":{"a":"Love Bride and Groom","b":"love-bride-and-groom"},
		"037":{"a":"Champagne Glasses (regular)","b":"champagne-glasses-regular"},
		"038":{"a":"Champagne Glasses (reverse)","b":"champagne-glasses-reverse"},
		"039":{"a":"Love Double Hearts (regular)","b":"love-double-hearts-regular"},
		"040":{"a":"Love Double Hearts (reverse)","b":"love-double-hearts-reverse"},
		"043":{"a":"Love Ring","b":"love-ring"},
		"044":{"a":"Love Text (regular)","b":"love-text-regular"},
		"045":{"a":"Love Text (reverse)","b":"love-text-reverse"},
		"046":{"a":"Love Wedding Cake Chocolate","b":"love-wedding-cake-chocolate"},
		"047":{"a":"Love Wedding Cake White","b":"love-wedding-cake-white"},
		"059":{"a":"Love Birds in Golden Jewel","b":"love-birds-in-golden-jewel"},
		"087":{"a":"Cherry Blossom","b":"cherry-blossom"},
		"101":{"a":"License Plate","b":"license-plate"},
		"104":{"a":"Love","b":"love"},
		"107":{"a":"Lucky in Love","b":"lucky-in-love"},
		"109":{"a":"Engagement Ring","b":"engagement-ring"},
		"110":{"a":"SWAK","b":"swak"},
		"113":{"a":"Shower of Happiness","b":"shower-of-happiness"},
		"118":{"a":"Penguins","b":"penguins"},
		"119":{"a":"White Love Birds","b":"white-love-birds"},
		"121":{"a":"Two Hearts Become One","b":"two-hearts-become-one"},
		"127":{"a":"Two Hearts","b":"two-hearts"},
		"198":{"a":"Elegant Wedding Bells","b":"elegant-wedding-bells"},
		"233":{"a":"Mr and Mrs","b":"mr-and-mrs"},
		"233B":{"a":"Mr and Mrs (B)","b":"mr-and-mrs-b"},
		"234":{"a":"Eat Drink Be Married","b":"eat-drink-be-married"},
		"235":{"a":"Dress and Tux Hangers","b":"dress-and-tux-hangers"},
		"236":{"a":"Silhouettes","b":"silhouettes"}
	}
	
	
	/******* DO NOT EDIT BELOW THIS LINE *********/
	/*alert( "received the following:\r\n" +
		  "layout = " + layout + "\r\n" +
		  "backgroundTopColor = " + backgroundTopColor + "\r\n" +
		  "borderBottomColor = " + borderBottomColor + "\r\n" +
		  "pattern = " + pattern + "\r\n" +
		  "patternColor = " + patternColor + "\r\n" +
		  "design = " + design + "\r\n" +
		  "font = " + font + "\r\n" +
		  "textLine1 = " + textLine1 + "\r\n" +
		  "textLine2 = " + textLine2 + "\r\n" +
		  "textLine3 = " + textLine3 + "\r\n" +
		  "textLine1Color = " + textLine1Color + "\r\n" +
		  "textLine2Color = " + textLine2Color + "\r\n" +
		  "quantity = " + quantity + "\r\n" +
		  "validate = " + validate + "\r\n" +
		  "tagsOrStickers = " + tagsOrStickers + "\r\n" +
		  "ok to continue"
	);*/
	layout = layout.replace( /version /, "");
	switch ( layout ) {
	case "A":
		layout = "Layout A";
		break;
	case "B":
		layout = "Layout B";
		break;
	}
	// backgroundTopColor is always the background color OR top color (depending on layout)
	// borderBottomColor is always the border color OR bottom color (depending on layout)
	

	var missingData = "";
	if ( validate ) {
		// check that all data has a value, otherwise they missed something
		if ( layout == "" || layout == null ) {
			missingData += "- Choose Your Layout (Step 1)\r\n"; // this should never happen
		}
		if ( backgroundTopColor == "" || backgroundTopColor == null ) {
			if ( layout == "A" ) {
				missingData += "- Choose Your Border Color (Step 2)\r\n";
			} else {
				missingData += "- Choose Your Top Color (Step 2)\r\n";
			}
		}
		if ( borderBottomColor == "" || borderBottomColor == null ) {
			if ( layout == "A" ) {
				missingData += "- Choose Your Background Color (Step 3)\r\n";
			} else {
				missingData += "- Choose Your Bottom Color (Step 3)\r\n";
			}
		}
		if ( pattern == "" || pattern == null ) {
			missingData += "- Choose Your Pattern (Step 4)\r\n";
		}
		if ( patternColor == "" || patternColor == null ) {
			missingData += "- Choose Your Pattern Color (Step 4)\r\n"; // this should never happen, defaults to black
		}
		if ( design == "" || design == null ) {
			missingData += "- Choose Your Design (Step 5)\r\n";
		}
		if ( font == "" || font == null ) {
			missingData += "- Choose Your Font (Step 6)\r\n"; // this should never happen, defaults to script
		}
		if ( textLine1 == "" || textLine1 == null ) {
			missingData += "- Enter Your Text Line 1 (Step 6)\r\n";
		}
		if ( textLine1Color == "" || textLine1Color == null ) {
			missingData += "- Choose Your Text Line 1 Color (Step 6)\r\n"; // this should never happen, defaults to black
		}
		if ( textLine2 == "" || textLine2 == null ) {
			missingData += "- Enter Your Text Line 2 (Step 6)\r\n";
		}
		if ( textLine2Color == "" || textLine2Color == null ) {
			missingData += "- Choose Your Text Line 2 Color (Step 6)\r\n"; // this should never happen, defaults to black
		}
		if ( ( textLine3 == "" || textLine3 == null ) && labelType != "circular" ) {
			missingData += "- Enter Your Text Line 3 (Step 6)\r\n";
		}
		if ( quantity == "" || quantity == null ) {
			missingData += "- Enter Your Desired Quantity\r\n";
		}
	}
	if ( missingData != "" ) {
		// they missed something, alert a message and stop
		alert( "Please Complete the Following Steps Before Adding to Cart:\r\n" + missingData );
	} else {
		/* we have our data, now fill in the form fields
		* it would have been nice to use this style:
		* jQuery("#" + layoutID).val( layout );
		* for all dropdown menus, however we can't be certain the values will be exactly
		* what we specify. Sometimes ecommerce systems append their own data here
		* but the text that shows up in each menu can be exactly what we specify, so
		* we have to compare against that
		* hence the loops below */
		
		if ( jQuery("#" + layoutID).length ) {
			jQuery("#" + layoutID + " option").each(function(i){
				//alert( "comparing '" + fashioncraftCleanText(jQuery(this).html()) + "' to '" + fashioncraftCleanText(layout) + "'" );
				if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(layout) ) {
					jQuery(this).attr( "selected", "selected" ); /* select the right option*/
				} else {
					jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
				}
			});
		}
		
		if ( jQuery("#" + backgroundColorID).length ) {
			jQuery("#" + backgroundColorID + " option").each(function(i){
				if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(backgroundTopColor) ) {
					jQuery(this).attr( "selected", "selected" ); /* select the right option*/
				} else {
					jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
				}
			});
		}
		
		if ( jQuery("#" + borderColorID).length ) {
			jQuery("#" + borderColorID + " option").each(function(i){
				if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(borderBottomColor) ) {
					jQuery(this).attr( "selected", "selected" ); /* select the right option*/
				} else {
					jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
				}
			});
		}
		
		if ( jQuery("#" + patternID).length ) {
			jQuery("#" + patternID + " option").each(function(i){
				if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(pattern) ) {
					jQuery(this).attr( "selected", "selected" ); /* select the right option*/
				} else {
					jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
				}
			});
		}
		
		if ( jQuery("#" + patternColorID).length ) {
			jQuery("#" + patternColorID + " option").each(function(i){
				if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(patternColor) ) {
					jQuery(this).attr( "selected", "selected" ); /* select the right option*/
				} else {
					jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
				}
			});
		}
		
		if ( jQuery("#" + designID).length ) {
			jQuery("#" + designID + " option").each(function(i){
				//if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(designMap[String(design)]["a"]) || fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(designMap[String(design)]["b"]) ) {
				//jQuery("body").append( "<br>comparing '" + fashioncraftCleanText(jQuery(this).html()) + "' to '" + fashioncraftCleanText(design) + "'" );
				if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(design) ) {
					//jQuery("body").append( "... MATCH FOUND" );
					//jQuery("body").append( "... menu ID = '" + designID + "'" );
					jQuery(this).attr( "selected", "selected" ); /* select the right option*/
				} else {
					jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
				}
			});
		}
		
		if ( jQuery("#" + fontID).length ) {
			jQuery("#" + fontID + " option").each(function(i){
				if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(font) ) {
					jQuery(this).attr( "selected", "selected" ); /* select the right option*/
				} else {
					jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
				}
			});
		}
		
		if ( jQuery("#" + line1ColorID).length ) {
			jQuery("#" + line1ColorID + " option").each(function(i){
				if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(textLine1Color) ) {
					jQuery(this).attr( "selected", "selected" ); /* select the right option*/
				} else {
					jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
				}
			});
		}
		
		if ( labelType != "circular" ) { 
			if ( jQuery("#" + line2ColorID).length ) {
				jQuery("#" + line2ColorID + " option").each(function(i){
					if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(textLine2Color) ) {
						jQuery(this).attr( "selected", "selected" ); /* select the right option*/
					} else {
						jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
					}
				});
			}
		}
		
		jQuery("#" + line1ID).val( textLine1 );
		jQuery("#" + line2ID).val( textLine2 );
		if ( labelType != "circular" ) { jQuery("#" + line3ID).val( textLine3 ); }
		if ( quantity ) { jQuery("#" + quantityID).val( quantity ); }
		
		if ( tagsOrStickers ) {
			if ( jQuery("#" + tagsOrStickersID).length ) {
				jQuery("#" + tagsOrStickersID + " option").each(function(i){
					if ( window.fashioncraftDebug ) { jQuery("body").append( "<br>comparing '" + fashioncraftCleanText(jQuery(this).html()) + "' to '" + fashioncraftCleanText(tagsOrStickers) + "'" ); }
					if ( fashioncraftCleanText(jQuery(this).html()) == fashioncraftCleanText(tagsOrStickers) ) {
						jQuery(this).attr( "selected", "selected" ); /* select the right option*/
					} else {
						jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
					}
				});
			}
		}
		
		if ( transferTo != "" && jQuery("#" + transferTo).length ) {
			transferOptions = { to: "#" + transferTo, className: 'ui-effects-transfer' };
		}
		
		if ( jQuery(transferOptions["to"]).length ) {
			jQuery("#fashioncraftLabelsPopup").effect( "transfer", transferOptions, 500, function(){
				if ( formToSubmit != "" ) {
					jQuery("#" + formToSubmit).submit();
				}
			});
			jQuery("#fashioncraftLabelsPopup").dialog( "close" );
		} else {
			jQuery("#fashioncraftLabelsPopup").dialog( "close" );
			if ( formToSubmit != "" && jQuery("#" + formToSubmit).length ) {
				jQuery("#" + formToSubmit).submit();
			}
		}
	}
} // function fashioncraftLabels( data ) {
	
if ( jQuery ) {
	jQuery(document).ready(function(){
		
		//lets do a case-insensitive version of contains (see http://stackoverflow.com/questions/187537/is-there-a-case-insensitive-jquery-contains-selector)
		jQuery.expr[':'].ciContains = function(a,i,m){
			return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
		};
		
		jQuery("head").append("<link rel=\"stylesheet\" href=\"/fashioncraftLabels/style.css\" type=\"text/css\">");
		if ( jQuery(".fashioncraftLabelsLink").length ) {
			jQuery(".fashioncraftLabelsLink").click(function(event){
				event.preventDefault();
				if ( jQuery("#fashioncraftLabelsPopup").length ) {
					jQuery("#fashioncraftLabelsPopup").load( jQuery(this).attr( "href" ) ).dialog( "open" );
				} else {
					jQuery("body").append( "<div id=\"fashioncraftLabelsPopup\" title=\"Design Your Label\" style=\"display: none;\"></div>");
	
					jQuery("#fashioncraftLabelsPopup").load( jQuery(this).attr( "href" ), function(){
						jQuery(this).dialog({
							height: 640,
							width: 920
						});
					});
				}			
				return false;
			});
		}
	});
}

function setCookieID() {
	// sets a cookie that will be used to identify this user later
}

















