// ###############################################################################//	setQtyInCookie(fieldobject)	// 	Called by: selecting dropdown//    Aden Roper// ###############################################################################function setQtyInCookie( unID , selectedValue, typeToRemove ){	//Set up variables for type of cookie manipulation	if(typeToRemove =="Shade")	// It is either a Shade Card, a Shade or an Ejecta Product	{	SampleRequestCookie = getCookie("SampleRequestCookie");	SampleRequestCookie = rightString(leftString(SampleRequestCookie,"#?#"),"?#?");	icontosplitwith = "#";	startString = "?#?"	endString = "#?#"		cookieName = "SampleRequestCookie";	}	else 	//Must be a brochure these have there own cookie	{	SampleRequestCookie = getCookie("Brochures");	SampleRequestCookie = rightString(leftString(SampleRequestCookie,"~*~"),"*~*");	icontosplitwith = "~";	startString = "*~*"	endString = "~*~"		cookieName = "Brochures";	}			CookieShadesIDsArray = SampleRequestCookie.split(icontosplitwith);		CookieShadesIDsArray.length = CookieShadesIDsArray.length-1;	for ( i=0 ; i < CookieShadesIDsArray.length ; i++) 				{				if( unID == trim(leftString(CookieShadesIDsArray[i] ,"-"))  )				{				CookieShadesIDsArray.splice( i , 1, unID+"-"+selectedValue)				var StringUpdatedArray = CookieShadesIDsArray.join(icontosplitwith)								//Set Cookie				SampleCookieContent = startString;				SampleCookieContent += StringUpdatedArray+icontosplitwith;				SampleCookieContent += endString;					setCookie(cookieName , SampleCookieContent , null , "/" );							return;								}//End For}}// ###############################################################################//	checkRow()// Checks Rown to see if we already have the Item in the Table// ###############################################################################function checkRow(table,toAdd){var oTable = document.getElementById(table);	var oRow;	var nRow1 = 1;											var nRow2 = oTable.rows.length - 1				// Index of last rowfor ( var i=nRow1 ; i<=nRow2 ; i++ ) {oRow = oTable.rows[ i ];oCell1 = oRow.cells[0];					if(document.all){     	     var sDescription	 = rightTrim(leftTrim(oCell1.innerText))			} else{			 var sDescription = rightTrim(leftTrim(oCell1.textContent))			}		if(sDescription == toAdd)		{		return false;		}		else{}	}}// =============================================================================================================// Function: AddTableRow( sItem, sDescription, desTable)// =============================================================================================================// This function adds a row to the HTML tablefunction AddTableRow( sItem, sDescription, desTable, UniqueID, BrochureOrShade) {//alert(sItem+" - "+sDescription+" - "+desTable+" - "+UniqueID+" - "+BrochureOrShade)//var oTable = document.getElementById( "DGVTABLE" );var oTable = document.getElementById( desTable );var n 			= oTable.rows.length - 1;// Put a limit on the number of rows a user can add to the online order tableif ( n > 50 ) {	alert( "A maximum of 50 items may be specified in any one online order\n\nIf you really require more samples please submit separate orders for the extra required." );	return;}var oRow = oTable.insertRow(-1);//var oCell1 = oRow.insertCell(-1);var oCell2 = oRow.insertCell(-1);var oCell3 = oRow.insertCell(-1);var oCell4 = oRow.insertCell(-1);//oCell1.className = "CellItem";//oCell1.innerHTML = sItem;//oRow.idName = UniqueIDoRow.id = UniqueID;oCell2.className = "CellDescription";oCell2.innerHTML = sDescription;oCell3.className = "CellQuantity";oCell3.innerHTML = "<select  class=\"Quantity\" ><option value=1 SELECTED >1<OPTION VALUE=2 >2<OPTION VALUE=3>3<OPTION VALUE=4>4</SELECT>";oCell4.className = "CellOrder";//oCell4.innerHTML = "<input type=button value=remove onClick=\"deleteRow('"+sDescription+"')\"><INPUT TYPE=CHECKBOX  CHECKED ID=CHK" + n + " VALUE=TEST WIDTH=10 HEIGHT=10 >&nbsp;";//oCell4.innerHTML = "<input type=button class=ftsearch value=remove onClick=\"deleteRow('"+sDescription+"')\">&nbsp;";oCell4.innerHTML = "<a class=\"nicehover\" href=\"javascript:void(0);\"><img src=\"/"+PolyflorWebPath+"/buttons/remove.gif\" border=\"0\" width=\"68\" height=\"18\" onClick=\"deleteRow('"+UniqueID+"','"+BrochureOrShade+"')\" ></a>";}// ###############################################################################//	setCookieFromDropdown();// ###############################################################################function setCookieFromDropdown( selectedValue, typeToAdd ){	//Set up variables for type of cookie manipulation	if(typeToAdd =="Shade")	// It is either a Shade Card, a Shade or an Ejecta Product	{	icontosplitwith = "#";	startString = "?#?"	endString = "#?#"		cookieName = "SampleRequestCookie";	SampleRequestCookie = getCookie("SampleRequestCookie");		//Cookie Does Not Exist			if (SampleRequestCookie == '' | SampleRequestCookie == null ) 				{				SampleCookieContent = startString;				SampleCookieContent += selectedValue+"-1"+icontosplitwith;				SampleCookieContent += endString;					setCookie(cookieName , SampleCookieContent , null , "/" );				return;			}			 // Cookie Does Exist			else			{				SampleRequestCookie = rightString(leftString(SampleRequestCookie ,"#?#"),"?#?");							CookieIDsArray = SampleRequestCookie.split(icontosplitwith);					CookieIDsArray.pop(); //removes last blank array element which is not needed.					CookieIDsArray.push(selectedValue+"-1")				var StringUpdatedArray = CookieIDsArray.join(icontosplitwith)								//Set Cookie				SampleCookieContent = startString;				SampleCookieContent += StringUpdatedArray+icontosplitwith;				SampleCookieContent += endString;					setCookie(cookieName , SampleCookieContent , null , "/" );			}		}	else 	//Must be a brochure these have there own cookie - "Brochure"	{		icontosplitwith = "~";		startString = "*~*";		endString = "~*~";			cookieName = "Brochures";		SampleRequestCookie = getCookie("Brochures");				//Cookie Does Not Exist			if (SampleRequestCookie == '' | SampleRequestCookie == null ) 				{				SampleCookieContent = startString;				SampleCookieContent += selectedValue+"-1"+icontosplitwith;				SampleCookieContent += endString;					setCookie(cookieName , SampleCookieContent , null , "/" );				return;			}			 // Cookie Does Exist			else			{				SampleRequestCookie = rightString(leftString(SampleRequestCookie ,"~*~"),"*~*");				CookieIDsArray = SampleRequestCookie.split(icontosplitwith);					CookieIDsArray.pop(); //removes last blank array element which is not needed.					CookieIDsArray.push(selectedValue+"-1")				var StringUpdatedArray = CookieIDsArray.join(icontosplitwith)								//Set Cookie				SampleCookieContent = startString;				SampleCookieContent += StringUpdatedArray+icontosplitwith;				SampleCookieContent += endString;					setCookie(cookieName , SampleCookieContent , null , "/" );			}		}	}// ###############################################################################//	getShadesAjax();//	Picks up shades on the fly via a drop down selection.// ###############################################################################function getShadesAjax(range , fieldToUpdate){	var ajaxRequest;  // The variable that makes Ajax possible!		try{		// Opera 8.0+, Firefox, Safari		ajaxRequest = new XMLHttpRequest();	} catch (e){		// Internet Explorer Browsers		try{		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");		} 		catch (e) {		try{			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");			} 			catch (e){				// Something went wrong				alert("Error, please close and reload your browser.!");				return false;			}		}	}		// Create a function that will receive data sent from the server	ajaxRequest.onreadystatechange = function(){		if(ajaxRequest.readyState == 4){						if(ajaxRequest.responseText == "Error\n")		{		alert("Error, please close and reload your browser.!");		return false;		}						else		{				//var doc = xhr.responseXML;   // Assign the XML file to a var		//var element = doc.getElementsByTagName('root').item(0);   // Read the first element		//document.ajax.dyn.value= element.firstChild.data;    // Assign the content to the form				returnedAjax = ajaxRequest.responseXML.getElementsByTagName('result')[0].firstChild.data;		if(returnedAjax == "0")			{			var oSelect = document.getElementById(fieldToUpdate);		// Handle on keyword field SESelectSwatch			var sSelectSwatch = "--- Select Sample ---";			oSelect.length = 0;			// Add First Value "--- Select Sample ---";			oSelect.options[0] = new Option( sSelectSwatch , sSelectSwatch );			return			}		else{			var AjaxArray = returnedAjax.split( "," );			//document.getElementById(table);				//alert(AjaxArray.length);						var oSelect = document.getElementById(fieldToUpdate);		// Handle on keyword field SESelectSwatch			var sSelectSwatch = "--- Select Sample ---";			oSelect.length = 0;			// Add First Value "--- Select Sample ---";			oSelect.options[0] = new Option( sSelectSwatch , sSelectSwatch );					// Loop through and add each item to the Drop Down list			for ( var i=0 ; i < AjaxArray.length ; i++ ) {				var SwatchName = leftString(trim(AjaxArray[i]),"~");				var SwatchValue = rightString(trim(AjaxArray[i]),"~");				oSelect.options[i+1] = new Option( SwatchName , SwatchValue);			}				} //End 					}				}	}		var thisdate = new Date();	var dominoDBpath = document.location.href.substring(0, document.location.href.indexOf(".nsf")+4)	ajaxRequest.open("GET", dominoDBpath+"/getShadesAjaxLookup!open&range="+range+"&time="+thisdate, true);	ajaxRequest.send(null); }// ###############################################################################//	deleteRow();//	Deletes a Table Row and Updates the Cookie.// ###############################################################################function deleteRow(delrow, typeToRemove){if(typeToRemove =="Shade")	// It is either a Shade Card, a Shade or an Ejecta Product	{	SampleRequestCookie = getCookie("SampleRequestCookie");	icontosplitwith = "#";	startString = "?#?"	endString = "#?#"		cookieName = "SampleRequestCookie";	}	else 	//Must be a brochure these have there own cookie	{	SampleRequestCookie = getCookie("Brochures");	icontosplitwith = "~";	startString = "*~*"	endString = "~*~"		cookieName = "Brochures";	}			var tableRow = document.getElementById( delrow );	// The first parent node points to the TBODY that contains the row.	// Even if one wasn't explicitly added, a TBODY element will be	// added implicitly	var table = tableRow.parentNode.parentNode;	table.deleteRow( tableRow.rowIndex );	SampleRequestCookie = rightString(leftString(SampleRequestCookie , endString ) , startString);	SampleRequestCookieArray = SampleRequestCookie.split(icontosplitwith);		SampleRequestCookieArray.pop(); //removes last blank array element which is not needed.		var theNewCookieArray = removeItems(SampleRequestCookieArray , delrow);	SampleRequestCookie= startString + trim(theNewCookieArray.join(icontosplitwith)) + icontosplitwith +endString 	 //Write the updated cookie	setCookie(cookieName , SampleRequestCookie,null,"/");	}// ###############################################################################//	removeItems(array,value)	// ###############################################################################	function removeItems(array, item) {	var i = 0;	while (i < array.length) 	{		if (leftString( array[i] ,"-") == item) {		array.splice(i, 1);		} 		else		 {i++;}	}	return array;	}	// ###############################################################################//	checkNotAddedToTable()	// ###############################################################################function checkNotAddedToTable(UniqueID, typeToRemove){if(typeToRemove =="Shade")	// It is either a Shade Card, a Shade or an Ejecta Product	{	SampleRequestCookie = getCookie("SampleRequestCookie");	icontosplitwith = "#";	startString = "?#?"	endString = "#?#"		cookieName = "SampleRequestCookie";	}	else 	//Must be a brochure these have there own cookie	{	SampleRequestCookie = getCookie("Brochures");	icontosplitwith = "~";	startString = "*~*"	endString = "~*~"		cookieName = "Brochures";	}			if (SampleRequestCookie == '' | SampleRequestCookie == null ) 				{			return			}	SampleRequestCookie = rightString(leftString(SampleRequestCookie , endString ) , startString);	SampleRequestCookieArray = SampleRequestCookie.split(icontosplitwith);		SampleRequestCookieArray.pop(); //removes last blank array element which is not needed.			var i = 0;	while (i < SampleRequestCookieArray.length) 	{		if (leftString( SampleRequestCookieArray[i] ,"-") == UniqueID) {		//alert("It Is there") 		return false;		} 		else		 {		//alert("nope its not")		i++;		}	}		}// =============================================================================================================// Function: ProcessTable() // =============================================================================================================//// This function process the HTML table containing all the user's selections// Table row 0 is the title row  Item      Description           Qty     Orderfunction ProcessTable() {var oTable = document.getElementById("BrochureTable");			// Handle on HTML tablevar oTable2 = document.getElementById("shadecardtable");			// Handle on HTML tablevar oTable3 = document.getElementById("samplestable");			// Handle on HTML tablevar oTable4 = document.getElementById("ejectatable");			// Handle on HTML tablevar oRow;	var sManual;												// var sLiteratureChoices="";							// List of manual aliases that user has selected e.g. "Corporate"var sLiteratureChoicesUserVersion = "";		//                 "                      e.g. Corporate Brochure|Corporatevar sComments = "";									// Comments - to record quantities orderedvar sCommentsManuals = ""						// Comments - for manuals orderedvar sCommentsShadecards = ""					// Comments - for shadecards orderedvar sCommentsSwatches = ""						// Comments - for swatches orderedvar sCommentsAccessory = ""						// Comments - for accessories orderedvar sShadecards = "";									// List of shadecards that user has selected e.g. Polyflor 2000 PUR ( shadecard )var sSwatchIndex = "";									// a swatch index e.g. 555var sSwatchOrdered = "";							// List of selected swatch indexes e.g. 555#656#123#var iOpeningBrace = 0;var iClosingBrace = 0;var iOpeningBracket = 0;var iClosingBracket = 0;var sSearch = "";var sCode = "";var sColour = "";var family_choices_1_field_output  = ""var specials_field_output  = ""sComments = "Web site - Samples Express Service - User has requested:-" + " ; ";	//START TABLE 1		var nRow1 = 1;													var nRow2 = oTable.rows.length - 1				// Index of last row	for ( var i=nRow1 ; i<=nRow2 ; i++ ) {		oRow = oTable.rows[ i ];		oCell1 = oRow.cells[0];						// Handle on second cell       "     - contains Description e.g. 8080 - Atlantic Blue				oSelect = oRow.cells[1].firstChild;		// Handle on keywrod select       - contains Quantity e.g. 2		var sQuantity		= oSelect.value;				if(document.all){     	     var sDescription	 = rightTrim(leftTrim(oCell1.innerText))			} else{			 var sDescription = rightTrim(leftTrim(oCell1.textContent))			}			// Build up a list of the manuals ordered e.g. Corporate			sLiteratureChoices += GetManualAlias( sDescription ) + ";" ;			// Build up a list of the manuals ordered e.g. Corporate Brochure | Corporate			sLiteratureChoicesUserVersion += sDescription + "|" + GetManualAlias( sDescription ) + ";" ;			// Build up a comment e.g. 'Ordered 2 - Corporate Brochure			sCommentsManuals  += sQuantity + " copy(s) of - " + sDescription + " ; " ;		}			//START TABLE 2	var nRow2 = oTable2.rows.length - 1				// Index of last row		for ( var i=nRow1 ; i<=nRow2 ; i++ ) {		oRow = oTable2.rows[ i ];		oCell1 = oRow.cells[0];						// Handle on second cell       "     - contains Description e.g. 8080 - Atlantic Blue				oSelect = oRow.cells[1].firstChild;		// Handle on keywrod select       - contains Quantity e.g. 2		var sQuantity		= oSelect.value;				if(document.all){     	     var sDescription	 = rightTrim(leftTrim(oCell1.innerText))			} else{			 var sDescription = rightTrim(leftTrim(oCell1.textContent))			}				// Build up a list of the shadecards ordered e.g. Polyflor 2000 PUR			sShadecards += sDescription + "#";			// Build up a comment e.g. 'Ordered 2 - Polyflor 2000 PUR Shade Card			sCommentsShadecards += sQuantity + " copy(s) of - " + sDescription + " ; " ;							specials_field_output += sDescription +","							}	//START TABLE 3	var nRow3 = oTable3.rows.length - 1				// Index of last row		for ( var i=nRow1 ; i <= nRow3 ; i++ ) {		oRow = oTable3.rows[ i ];		oCell1 = oRow.cells[0];						// Handle on second cell       "     - contains Description e.g. 8080 - Atlantic Blue				oSelect = oRow.cells[1].firstChild;		// Handle on keywrod select       - contains Quantity e.g. 2		var sQuantity		= oSelect.value;					if(document.all){     	     var sDescription	 = rightTrim(leftTrim(oCell1.innerText))			} else{			 var sDescription = rightTrim(leftTrim(oCell1.textContent))			}						//Create the output for all shades to add to the FamilyChoices_1 field			//if(i == nRow3){			//family_choices_1_field_output += replaceSubstring(sDescription, "-", " - ", 0)+"|xxx"			//}			//else{			family_choices_1_field_output += replaceSubstring(sDescription, "-", " - ", 0) + "|xxx,"			//}							sSwatchIndex = oRow.id //GetSwatchIndex( sDescription );						sSwatchOrdered += sSwatchIndex + "#";			// Build up a comment e.g. '2 copy(s) - 2020-Atlantic Blue ( Polyflor 2000 PUR )			sCommentsSwatches += sQuantity + " Sample(s) of - " + sDescription + " ; " ;	}	//START TABLE 4	var nRow4 = oTable4.rows.length - 1				// Index of last row		for ( var i=nRow1 ; i<=nRow4 ; i++ ) {		oRow = oTable4.rows[ i ];		oCell1 = oRow.cells[0];						// Handle on second cell       "     - contains Description e.g. 8080 - Atlantic Blue				oSelect = oRow.cells[1].firstChild;		// Handle on keywrod select       - contains Quantity e.g. 2		var sQuantity		= oSelect.value;						if(document.all){     	     var sDescription	 = rightTrim(leftTrim(oCell1.innerText))			} else{			 var sDescription = rightTrim(leftTrim(oCell1.textContent))			}								// Build up a list of the accessories ordered e.g. 562#343#555#			// Note - sDescription is format e.g. Sit On Coving [MC14] (9510-Black)			// Need to reformat as 9510-Black$MC14 - to search for swatch index			iOpeningBrace 		= sDescription.indexOf( "[" );			iClosingBrace 		= sDescription.indexOf( "]" );			iOpeningBracket 	= sDescription.indexOf( "(" );			iClosingBracket 		= sDescription.indexOf( ")" );			sCode 					= sDescription.substring( iOpeningBrace + 1 , iClosingBrace );			sColour 				= sDescription.substring( iOpeningBracket + 1 , iClosingBracket );			sSearch				= sColour + "$" + sCode;// 			alert ("About to search for swatch index using [" + sSearch + "]" );			sSwatchIndex = oRow.id //GetAccessorySwatchIndex( sSearch );						sSwatchOrdered += sSwatchIndex + "#";			// Build up a comment e.g. '2 copy(s) - 2020-Atlantic Blue ( Polyflor 2000 PUR )								sCommentsAccessory += sQuantity + " accessory(s) of - " + sDescription + " ; " ;										//if(i == nRow3){			//family_choices_1_field_output += replaceSubstring(sDescription, "-", " - ", 0)+"|xxx"			//}			//else{				family_choices_1_field_output += replaceSubstring(sSearch, "-", " - ", 0) + " (Ejecta Accessories Range)|xxx,"					//}			}	// Save POLYFLOR manuals/brochures selected by the user in the document		document.forms[0].LiteratureChoices.value = sLiteratureChoices;	document.forms[0].LiteratureChoicesUserVersion.value = sLiteratureChoicesUserVersion;		// Comments - so that POLYFLOR sample request staff can see quantities ordered		var sCR = ";" ;				// Generates a new line		// Add in the manuals that the user has ordered ( if any )		if ( sCommentsManuals != "" ) {		sComments = sComments + sCR + sCR + "Brochures:" + sCR + sCR + sCommentsManuals;	}		// Add in the shadecards that the user has ordered ( if any )		if ( sCommentsShadecards != "" ) {		sComments = sComments + sCR + sCR + "Shadecards:" + sCR + sCR + sCommentsShadecards;	}	// Add in the swatches that the user has ordered ( if any )		if ( sCommentsSwatches != "" ) {		sComments = sComments + sCR + sCR + "Samples:" + sCR + sCR + sCommentsSwatches;	}	// Add in the accessories that the user has ordered ( if any )		if ( sCommentsAccessory != "" ) {		sComments = sComments + sCR + sCR + "Accessory:" + sCR + sCR + sCommentsAccessory;	}	document.forms[0].comments.value = sComments;		// Save POLYFLOR Product Shade cards selected by the user in the document		document.forms[0].AllChosenSampleCodes.value = sShadecards + sSwatchOrdered;	//output shadecards	document.forms[0].Specials.value = specials_field_output 	//output shades	document.forms[0].FamilyChoices_1.value = family_choices_1_field_output} // end function