function njwfGlasswarefashioncraftCleanText( text ) {
	//$("body").append("<br>FC cleaning " + text );
	return text.replace( / /g, "" ).replace( /-/g, "" ).replace( /%20/g, "" ).toLowerCase();	
}
function njwfGlasswareCleanText( text, removeNumbers ) {
	//$("body").append("<br>NJWF cleaning " + text );
	//$("body").append("... type = " + typeof( removeNumbers ) );
	if ( typeof( removeNumbers ) == "undefined" ) {
		removeNumbers = 1;
	}
	var result = text.replace( /\$/g, "" ).replace( /\./g, "" ).replace( /\(/g, "" ).replace( /\)/g, "" ).replace( /\+/g, "" ).replace( /&amp;/g, "" ).replace( /&/g, "" );
	
	if ( removeNumbers ) {
		result = result.replace( /([0-9]+)/g, "" );
	}
	
	return result;
	//return text.replace( /$/g, "" ).replace( /\./g, "" ).replace( /(/g, "" ).replace( /)/g, "" ).replace( /\+/g, "" );
}

function FashioncraftGlassware(line1,line2,date,font,glass_image,design,quantity,color) {
	//$("body").append("<br>design = " + design);
	$("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 = "";
	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 */
	
	var designID = $("select option:contains('Double Signature Hearts')").parent().attr("id");
	var colorID = $("select option:contains('Autumn gold')").parent().attr("id");
	if ( !$("#" + colorID).length ) {
		colorID = $("select option:contains('Autumn Gold')").parent().attr("id");
	}
	var fontID = $("select option:contains('Arial')").parent().attr("id");
	// font menu is not quite right, fix it, or fix font
	if ( $("select option:contains('English 11 Vivace BT')").length && font == "English111 Vivace BT" ) {
		//$("select option:contains('English 11 Vivace BT')").text("English 111 Vivace BT");
		font = "English 11 Vivace BT";
	}
	var prodOptionText = $("input[type=text][name*='product_options']");
	//$("body").append("<br>found text options: " + prodOptionText.length);
	var textOption1 = prodOptionText[0];
	var textOption2 = prodOptionText[1];
	var textOption3 = prodOptionText[2];
	
	//$("body").append("text 1 = " + typeof(textOption1));
	var textOption1ID = $(textOption1).attr("id");
	var textOption2ID = $(textOption2).attr("id");
	var textOption3ID = $(textOption3).attr("id");
	
	//$("body").append("<br>design ID = '" + designID + "'<br>color ID = '" + colorID + "'<br>font ID = '" + fontID + "'" );
	//$("body").append("<br>text 1 ID = '" + textOption1ID + "'<br>text 2 ID = '" + textOption2ID + "'<br>text 3 ID = '" + textOption3ID + "'" );

	
	/******* DO NOT EDIT BELOW THIS LINE *********/
	
	/* 2010-03-12: stopped passing full path
	* passing file name instead 
	design = design.split( "/" ); // no longer needed as we are not passing the full path, just the file name
	design = design[design.length-1].split( "." )[0];*/
	design = design.split( "." )[0];
	var designMap = new Array();
	designMap["25th-anniversary"] = "A_001";
	designMap["50th-anniversary"] = "A_002";
	designMap["amor"] = "A_003";
	designMap["amor-classic"] = "A_004";
	designMap["angel"] = "A_005";
	designMap["angel-2"] = "A_006";
	designMap["a-toast"] = "A_007";
	designMap["antique-key"] = "A_008";
	designMap["autumn"] = "A_009";
	designMap["autumn-breeze-leaves"] = "A_010";
	designMap["autumn-pair-leaves"] = "A_011";
	designMap["autumn-single-leaf"] = "A_012";
	designMap["baby-bib"] = "B_001";
	designMap["baby-bottle"] = "B_002";
	designMap["baby-carriage"] = "B_003";
	designMap["baby-crawling"] = "B_004";
	designMap["baby-crib"] = "B_005";
	designMap["baby-on-board"] = "B_006";
	designMap["baby-on-board-2"] = "B_007";
	designMap["baby-on-board-3"] = "B_008";
	designMap["baby-feet"] = "B_009";
	designMap["baby-pacifier"] = "B_010";
	designMap["baby-rocking-horse"] = "B_011";
	designMap["baby-rubber-duck"] = "B_012";
	designMap["baby-shoe"] = "B_013";
	designMap["baby-stork"] = "B_014";
	designMap["baby-teddy-bear-1"] = "B_015";
	designMap["baby-teddy-bear-2"] = "B_016";
	designMap["ballet"] = "B_017";
	designMap["balloons"] = "B_018";
	designMap["baseball"] = "B_019";
	designMap["basketball"] = "B_020";
	designMap["bet-on-love"] = "B_021";
	designMap["bride-and-groom-signature"] = "B_022";
	designMap["bride-and-groom-love"] = "B_023";
	designMap["bride-and-groom-modern"] = "B_024";
	designMap["bride-&-groom-silhouette"] = "B_025";
	designMap["bun-in-oven"] = "B_026";
	designMap["butterfly"] = "B_027";
	designMap["calla-lilly"] = "C_001";
	designMap["castle"] = "C_002";
	designMap["castle-2"] = "C_003";
	designMap["celebrate"] = "C_004";
	designMap["25-champange"] = "C_005";
	designMap["40-champange"] = "C_006";
	designMap["50-champange"] = "C_007";
	designMap["cherry-blossom"] = "C_008";
	designMap["claddah"] = "C_009";
	designMap["communion"] = "C_010";
	designMap["corset"] = "C_011";
	designMap["chandelier"] = "C_012";
	designMap["cross"] = "C_013";
	designMap["crown"] = "C_014";
	designMap["cupid"] = "C_015";
	designMap["damask"] = "D_001";
	designMap["double-happiness"] = "D_002";
	designMap["double-signature-hearts"] = "D_003";
	designMap["dove"] = "D_004";
	designMap["dragonfly"] = "D_005";
	designMap["engagement-ring"] = "E_001";
	designMap["engagement-ring-2"] = "E_002";
	designMap["fall-for-love"] = "F_001";
	designMap["fan-white"] = "F_002";
	designMap["film"] = "F_003";
	designMap["fleur-di-lis"] = "F_004";
	designMap["flourish-15"] = "F_005";
	designMap["flourish-16"] = "F_006";
	designMap["flourish-21"] = "F_007";
	designMap["flourish-25"] = "F_008";
	designMap["flourish-40"] = "F_009";
	designMap["flourish-50"] = "F_010";
	designMap["football"] = "F_011";
	designMap["forever-in-love"] = "F_012";
	designMap["four-leaf-clover"] = "F_013";
	designMap["glam-girl"] = "G_001";
	designMap["glass-slipper"] = "G_002";
	designMap["golf"] = "G_003";
	designMap["good-fortune"] = "G_004";
	designMap["graduation"] = "G_005";
	designMap["graduation-books-with-year"] = "G_006";
	designMap["graduation-with-year"] = "G_007";
	designMap["graduate-boy"] = "G_008";
	designMap["graduate-girl"] = "G_009";
	designMap["handbag"] = "H_001";
	designMap["happy-anniversary"] = "H_002";
	designMap["happy-bar-mitzvah"] = "H_003";
	designMap["happy-birthday"] = "H_004";
	designMap["happy-couple"] = "H_005";
	designMap["heart-bow"] = "H_006";
	designMap["heart-car"] = "H_007";
	designMap["heart-burst"] = "H_008";
	designMap["hearts-two"] = "H_009";
	designMap["horseshoe"] = "H_010";
	designMap["its-a-boy"] = "I_001";
	designMap["its-a-girl"] = "I_002";
	designMap["kissing-fish"] = "K_001";
	designMap["koi-fish"] = "K_002";
	designMap["las-vegas"] = "L_001";
	designMap["las-vegas-2"] = "L_002";
	designMap["last-fling-before-the-ring"] = "L_003";
	designMap["license-plate"] = "L_004";
	designMap["like-milk-and-cookies"] = "L_005";
	designMap["lol-computer"] = "L_006";
	designMap["love"] = "L_007";
	designMap["love-banner"] = "L_008";
	designMap["love-beyond-measure"] = "L_009";
	designMap["love-birds"] = "L_010";
	designMap["love-blooms"] = "L_011";
	designMap["love-dice"] = "L_012";
	designMap["love-heart"] = "L_013";
	designMap["love-rocks"] = "L_014";
	designMap["love-travels"] = "L_015";
	designMap["martini"] = "M_001";
	designMap["moon-and-the-stars"] = "M_002";
	designMap["music"] = "M_003";
	designMap["night-on-the-town"] = "N_001";
	designMap["nuestra-boda"] = "N_002";
	designMap["ornate-cross"] = "O_001";
	designMap["ornament"] = "O_002";
	designMap["pagoda"] = "P_001";
	designMap["paris"] = "P_002";
	designMap["peace"] = "P_003";
	designMap["peace-sign"] = "P_004";
	designMap["piano"] = "P_005";
	designMap["piece-of-cake"] = "P_006";
	designMap["penguins"] = "P_007";
	designMap["perfect-pair"] = "P_008";
	designMap["present"] = "P_009";
	designMap["prom"] = "P_010";
	designMap["religious-boy"] = "R_001";
	designMap["religious-girl"] = "R_002";
	designMap["retired-at-last"] = "R_003";
	designMap["rose"] = "R_004";
	designMap["sassy-high-heel"] = "S_001";
	designMap["scribble-wine"] = "S_002";
	designMap["sea-shell"] = "S_003";
	designMap["seasons-autumn-ornament"] = "S_004";
	designMap["seasons-winter-ornament"] = "S_005";
	designMap["sheep"] = "S_006";
	designMap["showers-of-happiness"] = "S_007";
	designMap["showers-of-happiness-2"] = "S_008";
	designMap["single-signature-heart"] = "S_009";
	designMap["s'more"] = "S_010";
	designMap["snowflake"] = "S_011";
	designMap["snowflake-stamp"] = "S_012";
	designMap["snowman"] = "S_013";
	designMap["soccer"] = "S_014";
	designMap["star-of-david"] = "S_015";
	designMap["sugar-and-spice"] = "S_016";
	designMap["swak"] = "S_017";
	designMap["swans"] = "S_018";
	designMap["sweet-15-crown"] = "S_019";
	designMap["sweet-16-crown"] = "S_020";
	designMap["sweet-quinceañera-heart"] = "S_021";
	designMap["sweet-16-heart"] = "S_022";
	designMap["sweet-15-shoe"] = "S_023";
	designMap["sweet-16-shoe"] = "S_024";
	designMap["sweet-things"] = "S_025";
	designMap["tea-time"] = "T_001";
	designMap["torah"] = "T_002";
	designMap["torah-2"] = "T_003";
	designMap["tropical-paradise"] = "T_004";
	designMap["tropical-paradise-drink"] = "T_005";
	designMap["two-peas-in-a-pod"] = "T_006";
	designMap["wedding-bells"] = "W_001";
	designMap["wedding-cake"] = "W_002";
	designMap["wedding-cake-stamp"] = "W_003";
	designMap["were-engaged"] = "W_004";
	designMap["windy-silhouette"] = "W_005";
	designMap["wine-country"] = "W_006";
	designMap["wine-glasses"] = "W_007";
	designMap["xxxooo"] = "X_001";
	designMap["xoxo-xoxo"] = "X_002";
	designMap["ying-yang"] = "Y_001";
	// new designs
	designMap["a-lovely-toast"] = "A_013";
	designMap["baby-blocks"] = "B_028";
	designMap["baby-shoes"] = "B_029";
	designMap["baby-shower"] = "B_030";
	designMap["baby-shower-2"] = "B_031";
	designMap["baby-shower-bear"] = "B_032";
	designMap["baby-shower-carriage"] = "B_033";
	designMap["bride-groom-bear"] = "B_034";
	designMap["chai"] = "C_016";
	designMap["cheers"] = "C_017";
	designMap["congratulations"] = "C_018";
	designMap["cruise"] = "C_019";
	designMap["directors-chair"] = "D_006";
	designMap["doves"] = "D_007";
	designMap["drama"] = "D_008";
	designMap["eat-drink-and-be-married"] = "E_003";
	designMap["fireworks"] = "F_014";
	designMap["first-communion"] = "F_015";
	designMap["ganesha"] = "G_010";
	designMap["i-love-you"] = "I_003";
	designMap["just-married"] = "J_001";
	designMap["mardi-gras"] = "M_004";
	designMap["prayer"] = "P_011";
	designMap["seasons-greetings"] = "S_026";
	designMap["skull-and-crossbones"] = "S_027";
	designMap["baseball-silhouette"] = "S_028";
	designMap["baseball-woman-silhouette"] = "S_029";
	designMap["football-silhouette"] = "S_030";
	designMap["man-guitar"] = "S_031";
	designMap["woman-guitar"] = "S_032";
	designMap["ice-hockey-silhouette"] = "S_033";
	designMap["roller-hockey-silhouette"] = "S_034";
	designMap["running-man-silhouette"] = "S_035";
	designMap["running-woman-silhouette"] = "S_036";
	designMap["skateboard-silhouette"] = "S_037";
	designMap["skiier-silhouette"] = "S_038";
	designMap["thank-you"] = "T_007";
	designMap["wine-glasses-2"] = "W_008";
	designMap["young-love"] = "Y_002";
	// monograms etc
	designMap["noDesign"] = "noDesign";
	designMap["monogram3"] = "mono_3L";
	designMap["monogram1-d"] = "mono_1LD";
	designMap["monogram1-nd"] = "mono_1LND";
	// replaced designs
	designMap["o_003"] = "O_003";
	designMap["k_003"] = "K_003";
	designMap["f_016"] = "F_016";

	var transferOptions = new Array();
	transferOptions["className"] = "ui-effects-transfer";
	if ( transferTo != "" && $("#" + transferTo).length ) {
		transferOptions["to"] = "#" + transferTo;
	}
	if ( color == "Fusicha" ) {
		color = "Fuischa";
	} else if ( color == "" || color == "null" ) {
		color = "Black";
	}
	
	//transferOptions = { to: "#" + transferTo, className: 'ui-effects-transfer' };
	//$("#po1239").val( designMap[design] );
	
	if ( $("#" + designID).length ) {
		$("#" + designID).children("option").each(function(i){
			//$("body").append("<br>testing if '" + njwfGlasswareCleanText(njwfGlasswarefashioncraftCleanText(jQuery(this).html()),0) + "' = '" + njwfGlasswareCleanText(njwfGlasswarefashioncraftCleanText(design),0) + "'");
			if ( njwfGlasswareCleanText(njwfGlasswarefashioncraftCleanText(jQuery(this).html()),0) == njwfGlasswareCleanText(njwfGlasswarefashioncraftCleanText(design),0) ) {
				//$("body").append("...MATCH");
				jQuery(this).attr( "selected", "selected" ); /* select the right option*/
			} else {
				//$("body").append("...no match");
				jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
			}
		});
	}
	//$("body").append("<br>font = '" + font + "'");
	//$("#" + colorID).val( color );
	
	if ( $("#" + colorID).length ) {
		$("#" + colorID).children("option").each(function(i){
			//$("body").append("<br>testing if '" + njwfGlasswareCleanText(njwfGlasswarefashioncraftCleanText(jQuery(this).html())) + "' = '" + njwfGlasswarefashioncraftCleanText(color) + "'");
			if ( njwfGlasswareCleanText(njwfGlasswarefashioncraftCleanText(jQuery(this).html())) == njwfGlasswarefashioncraftCleanText(color) ) {
				jQuery(this).attr( "selected", "selected" ); /* select the right option*/
			} else {
				jQuery(this).removeAttr( "selected" ); /* deselect the current option*/
			}
		});
	}
	
	
	$("#" + fontID).val( font );
	$("#" + textOption1ID).val( line1 );
	if ( line2 != "null" && $("#" + textOption2ID).length ) { $("#" + textOption2ID).val( line2 ); }
	$("#" + textOption3ID).val( date );
	$("#product_avail").val( quantity );
	if ( $(transferOptions["to"]).length ) {
		$("#fashioncraftGlasswarePopup").effect( "transfer", transferOptions, 500, function(){
			if ( formToSubmit != "" ) {
				//$("#" + formToSubmit).submit();
			}
		});
		$("#fashioncraftGlasswarePopup").dialog( "close" );
	} else {
		$("#fashioncraftGlasswarePopup").dialog( "close" );
		if ( formToSubmit != "" && $("#" + formToSubmit).length ) {
			//$("#" + formToSubmit).submit();
		}
	}
} // function FashioncraftGlassware(line1,line2,date,font,glass_image,design,quantity,color) {

jQuery(document).ready(function(){
	jQuery("head").append("<link rel=\"stylesheet\" href=\"/fashioncraftGlassware/advanced/style.css\" type=\"text/css\">");
	if ( jQuery(".fashioncraftGlasswareLink").length ) {
		jQuery(".fashioncraftGlasswareLink").click(function(event){
			event.preventDefault();
			if ( jQuery("#fashioncraftGlasswarePopup").length ) {
				jQuery("#fashioncraftGlasswarePopup").load( jQuery(this).attr( "href" ) ).dialog( "open" );
			} else {
				jQuery("body").append( "<div id=\"fashioncraftGlasswarePopup\" title=\"Design Your Glassware\" style=\"display: none;\"></div>");
				jQuery("#fashioncraftGlasswarePopup").load( jQuery(this).attr( "href" ), function(){
					jQuery(this).dialog({
						height: 640,
						width: 840
					});
				});
			}			
			return false;
		});
	}
});
