<!--
// (c) 2000, 2001, WishWorld. All rights reserved.
// contact: wishworld@wishworld.com

var glPrice; // global price holderh

// fix strings (remove offisive chars)
function fixString(str) {

	var pbDesc = new String(str);
	var j;

	while((j = pbDesc.indexOf("\n")) != -1) {
		pbDesc= "" + (pbDesc.substring(0, j) + " " + pbDesc.substring((j + 1), pbDesc.length));
	}
	while((j = pbDesc.indexOf("\r")) != -1) {
		pbDesc= "" + (pbDesc.substring(0, j) + pbDesc.substring((j + 1), pbDesc.length));
	}
	while((j = pbDesc.indexOf("<")) != -1) {
		pbDesc= "" + (pbDesc.substring(0, j) + pbDesc.substring((j + 1), pbDesc.length));
	}
	while((j = pbDesc.indexOf(">")) != -1) {
		pbDesc= "" + (pbDesc.substring(0, j) + pbDesc.substring((j + 1), pbDesc.length));
	}
	while((j = pbDesc.indexOf("'")) != -1) {
		pbDesc= "" + (pbDesc.substring(0, j) + pbDesc.substring((j + 1), pbDesc.length));
	}

	return pbDesc;
}

// fix strings (remove dollar)
function fixDollar(str) {

	var pbDesc = new String(str);
	var j;

	while((j = pbDesc.indexOf("$")) != -1) {
		pbDesc= "" + (pbDesc.substring(0, j) + " " + pbDesc.substring((j + 1), pbDesc.length));
	}

	return pbDesc;
}

// convert the global price to a string and fix it (xxxx.xx)
function fixPrice() {
	var strPrice = glPrice.toString();
	var iDotLoc = strPrice.indexOf(".");

	if (iDotLoc != -1)
		return strPrice.substring(0, iDotLoc +3);
	else
		return strPrice + ".00";
}

// set the value of glPrice
function setPrice(strPrice) {
	var lPrice = parseFloat(strPrice);
	if (!isNaN(lPrice)) glPrice = lPrice;
}

// parse option strings to see if something changes my price...
function addPrice(str) {
	var lPrice = 0;
	var iPriceLoc = str.indexOf("$");
	var iPlusLoc = str.indexOf("+");

	if (iPriceLoc != -1) { // then I've got a price
		if (iPlusLoc != -1) { // then I've got a plus
			if (iPlusLoc < iPriceLoc) { // I care about it (e.g., + $10.00)
				lPrice = parseFloat(str.substr(iPriceLoc +1));
				if (!isNaN(lPrice)) glPrice += lPrice;
				glPrice += .00001; // fixes the float run
			}
		} // iPlusLoc != 0

		if (lPrice == 0) { // replace the price!
			lPrice = parseFloat(str.substr(iPriceLoc +1));
			if (!isNaN(lPrice)) glPrice = lPrice;
			glPrice += .00001; // fixes the float run
		}
	}

	return str;
}

// get the value of the form element (generic)
function getValue(element) {

	var eType = element.type.toLowerCase();

	if (eType == "select-one") {
		//if (element.selectedIndex > 0) { -- 00Aug18, jrh -- always take value
		var retVal = element[element.selectedIndex].value;
		if (retVal == "") retVal = element[element.selectedIndex].text;
		return addPrice(fixString(retVal));
		//} else
			//return null;
	} else
		return fixString(element.value);
}

// get the value of the form element (generic)
function getValuetext(element) {

	var eType = element.type.toLowerCase();

	if (eType == "select-one") {
		//if (element.selectedIndex > 0) { -- 00Aug18, jrh -- always take value
		var retVal = element[element.selectedIndex].text;
		if (retVal == "") retVal = element[element.selectedIndex].value;
		return addPrice(fixString(retVal));
		//} else
			//return null;
	} else
		return fixString(element.value);
}

// add a multiple option product (inital release for CookieBabyInc)
function addAdvProduct(form, storeCode) {

	// this function reads the form that called it and builds a product list
	// and finishes by calling addProduct()

	var lProd = "|:|"; // local 'product' spec
	var elements = form.elements;
	var eleType, eleName, iColonLoc;
	var lclDesc, lclQty, lclPrice, lclBuyURL, lclF1, lclF2, lclF3;
	var lCustomVal, lProductVal, lprVal;
	var iF1Val, iF2Val, iF3Val;
	var rgF1Val = new Array();
	var rgF2Val = new Array();
	var rgF3Val = new Array();

	// initial values
	lclDesc = lclBuyURL = lclQty = lclPrice = lclF1 = lclF2 = lclF3 = "";
	iF1Val = iF2Val = iF3Val = 0;
	glPrice = 0;
	lProductVal = 0;

	// walk thru form and get 'stuff'
	for(var i = 0; i < elements.length; i++) {
		eleType = elements[i].type.toLowerCase();
		eleName = elements[i].name.toLowerCase();

		// while Microsoft supports 'switch', it may not be available under other browsers.
		// need to use if statements to figure out what I've got.
		if (eleType != "submit") { // don't care about this type

			// get the name and value of the input. I'm looking for specific keywords...
			//   Description == description || desc || name || addName || item || product || describe || itemname
			//   Quantity == quantity || qty || addQty || jac_quantity_input
			//   Price == price || cost || addPrice || price1
			//   BuyURL == buyurl || return
			//   Code == code || f1 || addID || sku || pf_id || product_id || PartNo || id
			//   Color == color || f2 || p1 || AttributeA || color_id
			//   Size == size || f3 || p2 || addSize || AttributeB || size_id
			// it's also possible to have elements named customX. This is special.
			// it's also possible to have elements named product1. This is special.
			// override keywords: wlprice, wlbuyurl, wldesc.

		// Description
			if (eleName == "description" || eleName == "desc" || eleName == "describe" || eleName == "name" || eleName == "product" || eleName == "itemname" || eleName == "addname" || eleName == "wldesc" || eleName == "item") {
				if (eleName == "wldesc") // override
					lclDesc = getValue(elements[i]);
				else if (lclDesc == "")
					lclDesc = getValue(elements[i]);
			} else
		// Quantity
			if (eleName == "quantity" || eleName == "qty" || eleName == "addqty" || eleName == "jac_quantity_input") {
				lclQty = getValue(elements[i]);
			} else
		// Price
			if (eleName == "price" || eleName == "price1" || eleName == "cost" || eleName == "addprice" || eleName == "wlprice") {
				if (eleName == "wlprice") // override
					lclPrice = getValue(elements[i]);
				else if (lclPrice == "" && !glPrice)
					lclPrice = getValue(elements[i]);
				lclPrice = fixDollar(lclPrice);
				setPrice(lclPrice); // set to glPrice value (number);
			} else
		// BuyURL
			if (eleName == "buyurl" || eleName == "return" || eleName == "wlbuyurl") {
				if (eleName == "wlbuyurl") // override
					lclBuyURL = getValue(elements[i]);
				else if (lclBuyURL == "")
					lclBuyURL = getValue(elements[i]);
			} else
		// F1
			if (eleName == "code" || eleName == "f1" || eleName == "id" || eleName == "addid" || eleName == "sku" || eleName == "pf_id" || eleName == "product_id" || eleName == "partno") {
				lclF1 = getValue(elements[i]);
			} else
		// F2
			if (eleName == "color" || eleName == "color_id" || eleName == "attr1" || eleName == "p1" || eleName == "attr_value2" || eleName == "attributea" ) {
				lclF2 = getValue(elements[i]);
				if (eleName == "attr1") lclF2 = getValuetext(elements[i]);
			} else
		// F3
			if (eleName == "size" || eleName == "size_id" || eleName == "attr2" || eleName == "p2" || eleName == "addsize" || eleName == "attr_value1" || eleName == "attributeb" ) {
				lclF3 = getValue(elements[i]);
				if (eleName == "attr2") lclF3 = getValuetext(elements[i]);
			} else
		// {customX}
			if (eleName.substring(0, 6) == "custom") { // e.g., CookieBabyInc and others.
				// find out the number range of this element
				lCustomVal = parseInt(eleName.substr(6));
				if (isNaN(lCustomVal)) lCustomVal = 0;

				if (lCustomVal > 0 && lCustomVal < 21) { // 1..20
					if(eleValue = getValue(elements[i]))
						rgF1Val[iF1Val++] = eleValue;
				} else
				if (lCustomVal > 20 && lCustomVal < 41) { // 21..40
					if(eleValue = getValue(elements[i]))
						rgF2Val[iF2Val++] = eleValue;
				} else
				if (lCustomVal > 40 && lCustomVal < 61) {
					if(eleValue = getValue(elements[i]))
						rgF3Val[iF3Val++] = eleValue;
				}
			} else
		// {productpr}
			if (eleName == "productpr") { // e.g., scnaturals
					eleValue = getValue(elements[i]);
				
					iColonLoc = eleValue.indexOf(":");
					lclDesc = eleValue.substring(0, iColonLoc) + lclDesc;
					lclPrice = parseFloat(eleValue.substr(iColonLoc +1));
					if (!glPrice) setPrice(lclPrice);
					
					lProductVal++;
			} else
		// {productprX}
			if (eleName.substring(0, 9) == "productpr") { // e.g., BornToLove
				// is this 1 or 2? Only accept values from 1
				if (parseInt(eleName.substr(9)) == 1) {
					eleValue = getValue(elements[i]);
				
					iColonLoc = eleValue.indexOf(":");
					lclDesc = eleValue.substring(0, iColonLoc);
					lclPrice = parseFloat(eleValue.substr(iColonLoc +1));
					if (!glPrice) setPrice(lclPrice);
					
					lProductVal++;
				}
			} else
		// {product1[]}
			if (eleName.substring(0, 8) == "product1") { // e.g., ElegantChild
				if (lProductVal++ == 0)
					lclDesc = getValue(elements[i]);
				else {
					if (lProductVal < 6) {
						if(eleValue = getValue(elements[i]))
							rgF1Val[iF1Val++] = eleValue;
					} else
					if (lProductVal > 5 && lProductVal < 10) {
						if(eleValue = getValue(elements[i]))
							rgF2Val[iF2Val++] = eleValue;
					} else
					if(eleValue = getValue(elements[i]))
						rgF3Val[iF3Val++] = eleValue;
				}
			} else
		// {product[]}
			if (eleName == "product[]") { // e.g., BabyMineStore
				if (eleType == "hidden")
					lclDesc = getValue(elements[i]);
				else {  if (lProductVal == 0) 
						lclF1 = getValuetext(elements[i]);
					else if (lProductVal == 1)
						lclF2 = getValuetext(elements[i]);
					else if (lProductVal == 2)
						lclF3 = getValuetext(elements[i]);
					else if (lProductVal == 3) {
						lclF3 += ",";
						lclF3 += getValuetext(elements[i]);
						}
					else if (lProductVal == 4) {
						lclF3 += ",";
						lclF3 += getValuetext(elements[i]);
						}		
					lProductVal++;
				     }
					
			} else
		// {attrX}
			if (eleName.substring(0, 4) == "attr") { // e.g., OrganicBebe
					if(eleValue = getValuetext(elements[i]))
						rgF2Val[iF2Val++] = eleValue;
			} 
		} // !submit
	}

	// check to see if I need to build strings from the rgVal[]'s
	if (rgF1Val.length > 0) {
		if(lclF1 != "") lclF1 += ",";
		lclF1 += rgF1Val.slice(0);
	}
	if (rgF2Val.length > 0) {
		if(lclF2 != "") lclF2 += ",";
		lclF2 += rgF2Val.slice(0);
	}
	if (rgF3Val.length > 0) {
		if(lclF3 != "") lclF3 += ",";
		lclF3 += rgF3Val.slice(0);
	}

	// clean up if needed
	if (lclQty == "") lclQty = "1";
	if (lclPrice == "") lclPrice = "0.00";
	lclPrice = fixPrice();

	if ((lclF3 == "") && (lclF1 != "SNAPPIA") && (lclF1 != "BMMI9001") && (lclF1 != "KUSH9001") && (lclF1 != "FUZZ9006") && (lclF1 != "KUSH9002") && (lclF1 != "LUNA1100") && (lclF1 != "FUZZ9901") && (lclF1 != "FLIP0001") && (lclF1 != "BMMI9901") && (lclF1 != "BABYK991") && (lclF1 != "BUMK2401") && (lclF1 != "BUMK3101") && (lclF1 != "FUZZ9001") && (lclF1 != "KUSH9003") && (lclF1 != "KUSH9005") && (lclF1 != "PAIL0001") && (lclF1 != "KUSH6100") && (lclF1 != "KUSH6101") && (lclF1 != "KUSH6120")) {
		lclF3 = lclF2;
		lclF2 = "";
	}
	

	//Bummis Prints
	if (lclF2 == "Bright Print") lclPrice = "9.95";
	if (lclF2 == "Pastel Print") lclPrice = "9.95";
	//Bumkins Prints
	if ((lclF2 == "Prints") && (lclF1 == "BUMK1202")) lclPrice = "9.75";
	if ((lclF2 == "Prints") && (lclF1 == "BUMK2203")) lclPrice = "13.50";
	//Bumkins Liners
	if ((lclF3 == "Regular") && (lclF1 == "BUMK2302")) lclPrice = "19.00";
	//Kushies Ultra
	if ((lclF3 == "Infant 10-22 lbs.") && (lclF1 == "KUSH2101")) lclPrice = "8.95";
	if ((lclF3 == "Toddler 22-45 lbs.") && (lclF1 == "KUSH2101")) lclPrice = "9.95";
	//Kushies Classic
	if ((lclF3 == "Toddler 22-45 lbs.") && (lclF1 == "KUSH3101")) lclPrice = "8.95";
	//Kushies Basic
	if ((lclF3 == "Toddler 22-45 lbs.") && (lclF1 == "KUSH4101")) lclPrice = "4.75";
	//Proservices AIO
	if ((lclF3 == "Small 9-14 lbs.") && (lclF1 == "PROS2103")) lclPrice = "9.50";
	if ((lclF3 == "Medium 13-25 lbs.") && (lclF1 == "PROS2103")) lclPrice = "9.75";
	if ((lclF3 == "Large 24-35 lbs.") && (lclF1 == "PROS2103")) lclPrice = "10.75";
	//Prorap Classic
	if ((lclF3 == "Extra Large 34-45 lbs.") && (lclF1 == "PROS1102")) lclPrice = "6.50";
	//Fuzzi Bunz
	if ((lclF3 == "Extra Small 4-10 lbs.") && (lclF1 == "FUZZ1202")) lclPrice = "12.95";
	//FB Breast Pads
	if ((lclF2 == "Leakproof White/Ivory Fleece") && (lclF1 == "FUZZ9006")) lclPrice = "10.75";
	//Joey Bunz
	if ((lclF3 == "Medium") && (lclF1 == "BABYK901")) lclPrice = "4.70";
	if ((lclF3 == "Large") && (lclF1 == "BABYK901")) lclPrice = "4.90";
	//Bummi Training Pant
	if ((lclF2 == "Print") && (lclF1 == "BMMI5111")) lclPrice = "11.95";
	//Kissaluvs
	if ((lclF2 == "Colors! Cotton Fleece") && (lclF1 == "KISS2102")) lclPrice = "10.95";
	
	

	lProd += "Desc:" + lclDesc + "|";
	lProd += "qty:" + lclQty + "|";
	lProd += "Price:" + lclPrice + "|";
	lProd += "buyurl:" + lclBuyURL + "|";
	lProd += "F1:" + lclF1 + "|";
	lProd += "F2:" + lclF2 + "|";
	lProd += "F3:" + lclF3 + "|";


	// call addProduct()
	addProduct('JARDINED706',lProd);

	
}

//-->
