<!--
var treatmentTypeId = 0;
var valueId = 0;
var noOfOptions = 0;

function updateSelections(treatTypeId, value, options) {
//	alert("treatmentTypeId: "+treatmentTypeId+"\nvalueId: "+valueId+"\nnoOfOptions: "+noOfOptions)
	if(treatmentTypeId != 0 && valueId != 0 && noOfOptions != 0) { // If there is some previously selected value...
		if(valueId != value) {
			for(var i=0; i<noOfOptions; i++) { // ... then clear the selections
				if(document.getElementById("txtDepVal_"+valueId+"_"+i) != null) {
					document.getElementById("txtDepVal_"+valueId+"_"+i).value = "";
					setTimeout("sndReq_UpdateTreatValueDepOption("+treatmentTypeId+", "+valueId+", "+i+")",5);
//					sndReq_UpdateTreatValueDepOption(treatmentTypeId, valueId, i);
				}
				else
					return;
			}
		}
	}
	// Update the current selections now
	treatmentTypeId = treatTypeId;
	valueId = value;
	noOfOptions = options;
}

function prePopulateValues(type, width, valueId) {
	var str3;
	var tempWidth = width/type;
	var widthString = ""+tempWidth+"";
	var index = widthString.indexOf(".");
	if(index != -1) {
		str1 = widthString.slice(0,index);
		str2 = widthString.slice(index+1);
		str3 = str1+"."+str2.slice(0,3);
	}
	else
		str3 = widthString;
	widthModified = parseFloat(str3);
	if(widthModified * type == width) {
		for(var i=0; i<type; i++) {
			document.getElementById("txtDepVal_"+valueId+"_"+i).value = widthModified;
		}
	}
/*	else {
		for(var i=0; i<type; i++) {
			document.getElementById("txtDepVal_"+valueId+"_"+i).value = "";
		}
	}*/
}

function validateWidths(start, j, end, valueId, widthInt, msg, treatmentTypeId, valueId, mainTab, subTab, source) {
	var totalWidth = 0;
	var regex = "^[0-9]*[.]?[0-9]+$";
	var regex1 = /^[\s]+/g;
	var regex2 = /[\s]+$/g;
	if(source == 1) { // If the source of event for this method call is the click of the radio button...
//		updateSelections(treatmentTypeId, valueId, end);
		for(var i=start; i<end; i=i+1) {
			if(document.getElementById("txtDepVal_"+valueId+"_"+i).value != "")
				sndReq_UpdateTreatValueDepOption(treatmentTypeId,valueId,i);
		}
		sndReq_UpdateTreatValue(treatmentTypeId,"-1");
		document.getElementsByName("rdTreatValues_"+treatmentTypeId).checked = "checked";
		document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoNotCompleteMainTab.gif";
		document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoNotCompleteSubTab.gif";
		document.getElementById("clearSelection").innerHTML = "";
	}
	else 
		if(source == 0) { // If the source of event for this method call is the change of the dependent option in the text box...
			var length = document.getElementsByName("rdTreatValues_"+treatmentTypeId).length;
			for(var i=0; i<length; i++) {
				if(document.getElementsByName("rdTreatValues_"+treatmentTypeId)[i].value == valueId) {
					if(!document.getElementsByName("rdTreatValues_"+treatmentTypeId)[i].checked) // If the radio button is not checked then return the function
						return;
				}
			}
			for(var i=start; i<end; i++) { // For loop to check if the entered value is either an integer or a decimal number and nothing else
				if(document.getElementById("txtDepVal_"+valueId+"_"+i).value != "") {
					if(document.getElementById("txtDepVal_"+valueId+"_"+i).value.replace(regex1,"").replace(regex2,"").match(regex) == null) {
						alert("Please enter only positive numeric data.");
						sndReq_UpdateTreatValue(treatmentTypeId,"-1");
						document.getElementsByName("rdTreatValues_"+treatmentTypeId).checked = "checked";
						document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoNotCompleteMainTab.gif";
						document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoNotCompleteSubTab.gif";
						document.getElementById("clearSelection").innerHTML = "";
						return;
					}
				}
			}
		}
	for(var i=start; i<end; i=i+1) { // Add up all the dependent option values
		if(document.getElementById("txtDepVal_"+valueId+"_"+i).value != "") {
			sndReq_UpdateTreatValueDepOption(treatmentTypeId,valueId,j);
		}
		else
			return;
		totalWidth += parseFloat(document.getElementById("txtDepVal_"+valueId+"_"+i).value);
	}
	if(totalWidth != parseFloat(widthInt)) {
		sndReq_UpdateTreatValue(treatmentTypeId,'-1');
		document.getElementsByName("rdTreatValues_"+treatmentTypeId).checked = "checked";
		document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoNotCompleteMainTab.gif";
		document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoNotCompleteSubTab.gif";
		document.getElementById("clearSelection").innerHTML = "";
		alert(msg);
	}
	else {
		for(var i=start; i<end; i=i+1) // Update all the dependent option values in the database
			sndReq_UpdateTreatValueDepOption(treatmentTypeId,valueId,i);
		sndReq_UpdateTreatValue(treatmentTypeId,valueId);
		sndReq_TreatmentValuePane(treatmentTypeId);
	}
}

function sndReq_UpdateTreatValueFromDimension(treatmentId, newValueId) {
	if (pending == true) {
		alert("System processing...please wait a moment and try again.");
	} else {
		pending = true;
		// Send a request to the server to update its ConfigItem and run compatibility+pricing check
		// Input args:
		// arg[0] = treatmentId
		// arg[1] = new valueId
		var dest = "update_treatment.jsp";
		var queryPost = "arg_0=" + treatmentId + "&arg_1=" + newValueId;
		reqUpdateTreatmentValue = 	createXMLRequestObject();
		reqUpdateTreatmentValue.onreadystatechange = handleResp_UpdateTreatmentFromDimension;
		reqUpdateTreatmentValue.open('post', dest);
		reqUpdateTreatmentValue.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		reqUpdateTreatmentValue.send(queryPost);	
	}
}

function handleResp_UpdateTreatmentFromDimension() {

	
	if(reqUpdateTreatmentValue.readyState == 4){
				
	  testResponse(reqUpdateTreatmentValue);
		var response = reqUpdateTreatmentValue.responseText;
		var update = new Array();
		if(response.indexOf('|' != -1)) {
			update = response.split('|');
		}

		//alert(update[0]+"|"+update[1]+"|"+update[2]+"|"+update[3]+"|"+update[4]+"|"+update[5]+"|"+update[6]+"|"+update[7]);
		
		// Clear the event handler
		pending = false;
		reqUpdateTreatmentValue.onreadystatechange = emptyFunction;
		
		// Determine if we can update the price
		if (update[4] == "true") {
			// we can update the price
			
			// only update the price if we do not have a no charge option
			if (update[7] != "4") { 
				sndReq_UpdatePrice();
			}
							
		} else {
			// we can not update the price
		}			
		
		// Determine if product is complete to add to the cart
		if (update[3] == "true") {
			// can add to the cart
										
		} else {
			// can not add to the cart
			
		}
		
		// determine the status of main tab
		var mainTab = update[7];
		
		if (update[8] == "true") {
			document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoCompleteMainTab.gif";
		} else {
			document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoNotCompleteMainTab.gif";
		}
		
		// determine the status of sub tab
		var subTab = update[9];
		if (update[10] == "true") {
			document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoCompleteSubTab.gif";
		} else {
			document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoNotCompleteSubTab.gif";
		}
				
		sndReq_DimensionPane();			
	} else{
		// waiting for the request
	}	
}

function sndReq_UpdateTreatValueDepOptionFromDimension(treatmentId, valueId, depId) {
	var userValue = "";
	userValue = document.getElementById("txtDepVal_"+ valueId + "_" + depId).value;
	var dest = "update_dependentOption.jsp";
	var queryPost = "treatmentId=" + treatmentId + "&valueId=" + valueId + "&dependentId=" + depId + "&userValue=" + userValue;

	reqUpdateDependentValue = 	createXMLRequestObject();
	reqUpdateDependentValue.onreadystatechange = handleResp_UpdateDependentOptionFromDimension;
	reqUpdateDependentValue.open('post', dest);
	reqUpdateDependentValue.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
	reqUpdateDependentValue.send(queryPost);	
}

function handleResp_UpdateDependentOptionFromDimension() {

	
	if(reqUpdateDependentValue.readyState == 4){

	  testResponse(reqUpdateDependentValue);
				
		var response = reqUpdateDependentValue.responseText;
		var update = new Array();
		if(response.indexOf('|' != -1)) {
			update = response.split('|');
		}

		//alert(update[0]+"|"+update[1]+"|"+update[2]+"|"+update[3]+"|"+update[4]+"|"+update[5]+"|"+update[6]+"|"+update[7]);
		
		// Clear the event handler
		pending = false;
		reqUpdateDependentValue.onreadystatechange = emptyFunction;
		
		// Determine if we can update the price
		if (update[4] == "true") {
			// we can update the price
			
			// only update the price if we do not have a no charge option
			if (update[7] != "4") { 
				sndReq_UpdatePrice();
			}
							
		} else {
			// we can not update the price
		}			
		
		// Determine if product is complete to add to the cart
		if (update[3] == "true") {
			// can add to the cart
										
		} else {
			// can not add to the cart
			
		}
		
		// determine the status of main tab
		var mainTab = update[7];
		
		if (update[8] == "true") {
			document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoCompleteMainTab.gif";
		} else {
			document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoNotCompleteMainTab.gif";
		}
		
		// determine the status of sub tab
		var subTab = update[9];
		if (update[10] == "true") {
			document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoCompleteSubTab.gif";
		} else {
			document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoNotCompleteSubTab.gif";
		}
				
		sndReq_DimensionPane();		
	} else{
		// waiting for the request
	}	
}

function handleResp_UpdateDependentOption() {

	
	if(reqUpdateDependentValue.readyState == 4){
			
	  testResponse(reqUpdateDependentValue);
	  
		var response = reqUpdateDependentValue.responseText;
		var update = new Array();
		if(response.indexOf('|' != -1)) {
			update = response.split('|');
		}

		//alert(update[0]+"|"+update[1]+"|"+update[2]+"|"+update[3]+"|"+update[4]+"|"+update[5]+"|"+update[6]+"|"+update[7]);
		
		// Clear the event handler
		pending = false;
		reqUpdateDependentValue.onreadystatechange = emptyFunction;
		
		treatmentTypeId = update[1];
		valueId = update[2];
		// Determine if we can update the price
		if (update[4] == "true") {
			// we can update the price
			
			// only update the price if we do not have a no charge option
			if (update[7] != "4") { 
				sndReq_UpdatePrice();
			}
							
		} else {
			// we can not update the price
		}			
		
		// Determine if product is complete to add to the cart
		if (update[3] == "true") {
			// can add to the cart
										
		} else {
			// can not add to the cart
			
		}
		
		// determine the status of main tab
		var mainTab = update[7];
		
		if (update[8] == "true") {
			document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoCompleteMainTab.gif";
		} else {
			document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoNotCompleteMainTab.gif";
		}
		
		// determine the status of sub tab
		var subTab = update[9];
		if (update[10] == "true") {
			document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoCompleteSubTab.gif";
		} else {
			document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoNotCompleteSubTab.gif";
		}
				
	} else{
		// waiting for the request
	}	
}


function sndReq_UpdateTreatValueDepOption(treatmentId, valueId, depId) {
	var userValue = "";
	userValue = document.getElementById("txtDepVal_"+ valueId + "_" + depId).value;
	
	var dest = "update_dependentOption.jsp";
	var queryPost = "treatmentId=" + treatmentId + "&valueId=" + valueId + "&dependentId=" + depId + "&userValue=" + userValue;
	
	reqUpdateDependentValue = 	createXMLRequestObject();
	reqUpdateDependentValue.onreadystatechange = handleResp_UpdateDependentOption;
	reqUpdateDependentValue.open('post', dest);
	reqUpdateDependentValue.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
	reqUpdateDependentValue.send(queryPost);	
}

function sndReq_UpdateTreatValue(treatmentId, newValueId) {
	// Send a request to the server to update its ConfigItem and run compatibility+pricing check
	// Input args:
	// arg[0] = treatmentId
	// arg[1] = new valueId
	var dest = "update_treatment.jsp";
	var queryPost = "arg_0=" + treatmentId + "&arg_1=" + newValueId;
	
	reqUpdateTreatmentValue = 	createXMLRequestObject();
	reqUpdateTreatmentValue.onreadystatechange = handleResp_UpdateTreatment;
	reqUpdateTreatmentValue.open('post', dest);
	reqUpdateTreatmentValue.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
	reqUpdateTreatmentValue.send(queryPost);	
}

function handleResp_UpdateTreatment() {

	
	if(reqUpdateTreatmentValue.readyState == 4){

	  testResponse(reqUpdateTreatmentValue);
			
		var response = reqUpdateTreatmentValue.responseText;
		var update = new Array();
		if(response.indexOf('|' != -1)) {
			update = response.split('|');
		}
		
		//alert(update[0]+"|"+update[1]+"|"+update[2]+"|"+update[3]+"|"+update[4]+"|"+update[5]+"|"+update[6]+"|"+update[7]);
		
		// Clear the event handler
		pending = false;
		reqUpdateTreatmentValue.onreadystatechange = emptyFunction;
		
		var treatTypeId = update[1];
		// Determine if we can update the price
		if (update[4] == "true") {
			// we can update the price
			
			// only update the price if we do not have a no charge option
			if (update[7] != "4") { 
				sndReq_UpdatePrice();
			}
			
							
		} else {
			// we can not update the price
		}			
		
		// Determine if product is complete to add to the cart
		if (update[3] == "true") {
			// can add to the cart
		} else {
			// can not add to the cart
		}

		// determine the status of main tab
		var mainTab = update[7];
		
		if (update[8] == "true") {
			document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoCompleteMainTab.gif";
		} else {
			document.getElementById("mainTabStatus_" + mainTab).src= "/smith_noble/images/v3/config/icoNotCompleteMainTab.gif";
		}
		
		// determine the status of sub tab
		var subTab = update[9];
		if (update[10] == "true") {
			document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoCompleteSubTab.gif";
		} else {
			if(document.getElementById("subStatus" + subTab) != null)
				document.getElementById("subStatus" + subTab).src= "/smith_noble/images/v3/config/icoNotCompleteSubTab.gif";
		}
//		sndReq_TreatmentValuePane(treatTypeId);
							
	}else{
		// waiting for the request
	}		
}


function sndReq_TreatmentValuePane(treatTypeId){
	destURL = 'treatment_value_pane.jsp';
	var queryPost = 'typeid=' + treatTypeId;	
	reqTreatmentValuePane = createXMLRequestObject();
	reqTreatmentValuePane.onreadystatechange = handleResponseTreatmentValuePane;
	reqTreatmentValuePane.open('post', destURL);
	reqTreatmentValuePane.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
	reqTreatmentValuePane.send(queryPost);
}

function handleResponseTreatmentValuePane() {
	var update = new Array();	
	var body;
	var selectionPanel;
	
	
	if(reqTreatmentValuePane.readyState == 4){

	  testResponse(reqTreatmentValuePane);
	
		var response = reqTreatmentValuePane.responseText;
		
		if(response.indexOf('|' != -1)) {
				update = response.split('|');
				navHtml = update[0];			
				selectionPanel = update[1];
				body = update[2];
		}
		
		parent.document.getElementById("divOptionPanel").style.display = 'block';	
		parent.document.getElementById("divOptionPanel").style.height = 407;	
		parent.document.getElementById("divOptionPanel").innerHTML = body;
				
		// set selection panel
		parent.document.getElementById("divSelectionPanel").style.display = "block";
		parent.document.getElementById("divSelectionPanel").innerHTML = selectionPanel;
		
		parent.document.getElementById("divNavPanel").style.display = 'block';		
		parent.document.getElementById("divNavPanel").innerHTML = navHtml;
					
		// Clear the event handler
		reqTreatmentValuePane.onreadystatechange = emptyFunction;
	}
}

-->
