
var windows = (navigator.appVersion.indexOf("Win")!=-1);
var ie = (navigator.appName.indexOf("xplorer") > 0);


function pop_models(cat){
	var drop = document.quoteForm.product;
	drop.options.length = 0;
	drop.disabled = false;
	var c = 1;
	drop[0] = new Option('Select a product:',0);
	for(var m in product_options){
		if(product_options[m]["category"] == cat){
			drop[c] = new Option(product_options[m]["name"],m);			
			c++;
		}			
	}
	document.getElementById("options_and_features").style.display = "none";
	document.getElementById("prod_photo").style.display = "none";
	document.getElementById("current_model").style.display = "none";
	document.getElementById("prodsecondary").style.display = "none";
}


function force_load(id){
	var cats = document.quoteForm.category.options;
	var opts = document.quoteForm.product.options;
	var force_cat = product_options[id]["category"];
	
	for(var o = 0; o < cats.length; o++){
		if(cats[o].getAttribute("value") == force_cat){
			document.quoteForm.category.selectedIndex = o;	
			pop_models(force_cat);				
		}
	}	
	for(var o = 0; o < opts.length; o++){
		if(opts[o].getAttribute("value") == id){
			document.quoteForm.product.selectedIndex = o;
			document.quoteForm.product.focus();					
		}
	}	
	load_model(id);
}

function load_model(id){

	document.getElementById("upsells").style.display = 'none';
	document.getElementById("options_and_features").style.display = "block";
	document.getElementById("prod_photo").style.display = "block";
	document.getElementById("current_model").style.display = "block";
	document.getElementById("prodsecondary").style.display = "block";	
	
	cur_prod = product_options[id]["name"];
	cur_photo = product_options[id]["photo"];
	cur_id = id;

	//update the photo
	document.getElementById("prod_photo").innerHTML = '<img src="' + cur_photo + '" />';

	//create standard configuration
	var view = document.getElementById("options_and_features");
		view.innerHTML = "";
	//create upselling view
	var upsell = document.getElementById("upsells");
		upsell.innerHTML = "";

 if(product_options[id]["configurable"]	== "Yes" || product_options[id]["configurable"]	== "By Letter"){
		
	if(windows && ie){ 
		tbl   = document.createElement("<table width=\"600\" cellspacing=\"5\">");
		ftbl = document.createElement("<table width=\"600\" cellspacing=\"5\" class=\"standard_features\">");
		utbl  = document.createElement("<table width=\"600\" cellspacing=\"5\">");
	} else {
		tbl = document.createElement("table");  utbl = document.createElement("table");  ftbl = document.createElement("table");		
		tbl.setAttribute("cellspacing","5"); 	utbl.setAttribute("cellspacing","5"); ftbl.setAttribute("cellspacing","5");	
		tbl.setAttribute("width","600"); 		utbl.setAttribute("width","600");   ftbl.setAttribute("width","600");
		ftbl.setAttribute("class","standard_features");
	}
	
	view.appendChild(ftbl);
	
	if(windows && ie){
		steptwo  = document.createElement("h2");											
	} else {
		steptwo = document.createElement("h2");
	}
	steptwo.innerHTML = "<br />Step 2: <span class=\"h2alt\">Select desired product options</span>";
	
	view.appendChild(steptwo);
	
	
	view.appendChild(tbl);
	upsell.appendChild(utbl);
	tbody = document.createElement("tbody");	
	fbody = document.createElement("tbody");
	ubody = document.createElement("tbody");	
	
	tbl.appendChild(tbody);
	utbl.appendChild(ubody);
    ftbl.appendChild(fbody);

	tbl = tbody;
	utbl = ubody;
    ftbl = fbody;

		///FEATURES
			
			

		if(windows && ie){
			row  = document.createElement("<tr class=\"standard_features\">");
			desc = document.createElement("<td colspan=\"3\">");	
											
		} else {
			row = document.createElement("tr");	
			row.setAttribute("class","standard_features");
			desc = document.createElement("td");
			desc.setAttribute("colspan","3");					
		}
		var sf = document.createElement("strong");
		sf.innerHTML = "<p class=\"subhead\">Standard (Included) Features:</p>";
		
		ftbl.appendChild(row);
		desc.appendChild(sf);
		row.appendChild(desc);
		

	for(var f = 0; f < product_options[id]["features"].length; f++){
			row = document.createElement("tr");			
			ftbl.appendChild(row);			
			if(windows && ie){
					desc = document.createElement("<td valign=\"top\">");
					more = document.createElement("<td valign=\"top\" width=\"30\">");
					bullet = document.createElement("<td valign=\"top\" class=\"bullets\" width=\"15\">");
				}else{
					desc = document.createElement("td");
					more = document.createElement("td");
					bullet = document.createElement("td");
					more.setAttribute("valign", "top");
					desc.setAttribute("valign", "top");
					more.setAttribute("width","30");
					bullet.setAttribute("valign", "top");
					bullet.setAttribute("class", "bullets");
					bullet.setAttribute("width","15");
					
				}
				
			desc.innerHTML = product_options[id]["features"][f]["name"];
			bullet.innerHTML = '<img src="/images/bullet.gif" />';	
			if(product_options[id]["features"][f]["more"] != ""){
				more.innerHTML = '<a href="javascript:void(0);" onclick="more_win(\''+ product_options[id]["features"][f]["more"] + '\',event);"><img src="/images/help_icon.gif" border="0" /></a>';
			}	
			row.appendChild(more);
			row.appendChild(bullet);
			row.appendChild(desc);			
		
	}

 //configurable options
	row = document.createElement("tr");			
	tbl.appendChild(row);			
	if(windows && ie){
			desc = document.createElement("<td colspan=\"3\">");										
		} else {
			desc = document.createElement("td");
			desc.setAttribute("colspan","3");					
		}
	
	if(product_options[id]["options"].length > 0) 
		//desc.innerHTML = "<br /><h2>Step 2: <span class=\"h2alt\">Select desired product options</span></h2>";
		//row.appendChild(desc);
	
	//CONFIG OPTIONS
		var cat = "";		
		for(var f = 0; f < product_options[id]["options"].length; f++){
		 		category = product_options[id]["options"][f]["category"];
				if(category!=cat){ 					
					cat = category;					
						var t_row = document.createElement("tr");							
						if(windows && ie){
							 t_hd = document.createElement("<td colspan=\"3\">");																		
						} else {
							t_hd = document.createElement("td");
							t_hd.setAttribute("colspan","3");												
						} 		
						t_hd.innerHTML = "<p class=\"subhead\">" + cat + " options:</p>";
						tbl.appendChild(t_row);		
						t_row.appendChild(t_hd);
				}
				atbl = tbl;
				row = document.createElement("tr");
				atbl.appendChild(row);
				
				if(windows && ie){
					check_cell = document.createElement("<td valign=\"top\" width=\"15\">");									
				}else{
					check_cell = document.createElement("td");
					check_cell.setAttribute("valign","top");
					check_cell.setAttribute("width","15");
				}
				if(windows && ie){
					check_box  = document.createElement("<input _title=\""+product_options[id]["options"][f]["name"]+"\" _part=\""+product_options[id]["options"][f]["append"]+"\" value=\""+product_options[id]["options"][f]["id"]+"\" name=\"opt_" + product_options[id]["options"][f]["id"] + "\" type=\"checkbox\">");
				}else{	
					check_box  = document.createElement("input");
					check_box.setAttribute("name","opt_" + product_options[id]["options"][f]["id"]);
					check_box.setAttribute("_title",  product_options[id]["options"][f]["name"]);
					check_box.setAttribute("value",  product_options[id]["options"][f]["id"]);
					check_box.setAttribute("_part", product_options[id]["options"][f]["append"]);
					check_box.setAttribute("type","checkbox");
				}
				check_box.onclick = function(){ check_all_logic(id, this, cat); }
					
				if(windows && ie){
					desc = document.createElement("<td id=\"txt_"+product_options[id]["options"][f]["id"]+"\">");
					more = document.createElement("<td width=\"30\">");			
				}else{
					desc = document.createElement("td");
					more = document.createElement("td"); more.setAttribute("width","30");
					desc.setAttribute("id","txt_" + product_options[id]["options"][f]["id"]);		
				}	
				desc.innerHTML = product_options[id]["options"][f]["name"];
				if(product_options[id]["options"][f]["more"] != ""){
					more.innerHTML = '<a href="javascript:void(0);" onclick="more_win(\''+ product_options[id]["options"][f]["more"] + '\',event);"><img src="/images/help_icon.gif" border="0" /></a>';
				}else{
					more.innerHTML = "";
				}
				row.appendChild(more);
				row.appendChild(check_cell);
				check_cell.appendChild(check_box);
				row.appendChild(desc);			
				
			}
   		
/**********************  upsl. ****************************/

			atbl = utbl;
	if(product_options[id]["upsells"].length > 0){
	   //ADDED MESSAGE
		var t_row = document.createElement("tr");							
				if(windows && ie){
					t_hd = document.createElement("<td colspan=\"3\">");																		
				} else {
					t_hd = document.createElement("td");
					t_hd.setAttribute("colspan","3");												
				} 				
				// t_hd.innerHTML = "<p style=\"font-weight:normal;font-size:15px;color:#C20000;padding:0;\">" + cur_prod + " has been added to your quote list.</p><br />";
			
				
				atbl.appendChild(t_row);		
				t_row.appendChild(t_hd);

		

		//PRINT OTHER ITEMS TO CONSIDER
				var t_row = document.createElement("tr");							
				if(windows && ie){
					t_hd = document.createElement("<td colspan=\"3\">");																		
				} else {
					t_hd = document.createElement("td");
					t_hd.setAttribute("colspan","3");												
							} 				
				t_hd.innerHTML = "<h2>Other Items to consider:</h2>";
				atbl.appendChild(t_row);		
				t_row.appendChild(t_hd);
	
			var cat = "";	
			var upsells = false;
			for(var f = 0; f < product_options[id]["upsells"].length; f++){
					upsells = true;
					category = product_options[id]["upsells"][f]["category"];
					if(category!=cat){ 					
						cat = category;					
							var t_row = document.createElement("tr");							
							if(windows && ie){
								 t_hd = document.createElement("<td colspan=\"3\">");																		
							} else {
								t_hd = document.createElement("td");
								t_hd.setAttribute("colspan","3");												
							} 				
							t_hd.innerHTML = "<strong>" + cat + ":</strong>";
							atbl.appendChild(t_row);		
							t_row.appendChild(t_hd);
					}
					
					row = document.createElement("tr");
					atbl.appendChild(row);
					
					if(windows && ie){
						check_cell = document.createElement("<td width=\"15\" valign=\"top\">");									
					}else{
						check_cell = document.createElement("td");
						check_cell.setAttribute("valign","top");
						check_cell.setAttribute("width","15");			
					}
					if(windows && ie){
						check_box  = document.createElement("<input _title=\""+product_options[id]["upsells"][f]["name"]+"\" append=\""+product_options[id]["upsells"][f]["append"]+"\" value=\""+product_options[id]["upsells"][f]["id"]+"\" name=\"ups_" + product_options[id]["upsells"][f]["id"] + "\" pid=\""+product_options[id]["upsells"][f]["upsell"]+"\" type=\"checkbox\">");					
					}else{	
						check_box  = document.createElement("input");
						check_box.setAttribute("name","ups_" + product_options[id]["upsells"][f]["id"]);
						check_box.setAttribute("_title",  product_options[id]["upsells"][f]["name"]);
						check_box.setAttribute("value",  product_options[id]["upsells"][f]["id"]);
						check_box.setAttribute("append", product_options[id]["upsells"][f]["append"]);
						check_box.setAttribute("index", f);
						check_box.setAttribute("type","checkbox");
					}									
					check_box.onclick = function(){  toggle_upsell(this); }
					if(windows && ie){
						desc = document.createElement("<td id=\"tx_"+product_options[id]["upsells"][f]["id"]+"\">");
						more = document.createElement("<td width=\"15\">");			
					}else{
						desc = document.createElement("td");				
						more = document.createElement("td");
						more.setAttribute("width","15");
						desc.setAttribute("id","txt_" + product_options[id]["upsells"][f]["id"]);		
					}	
					desc.innerHTML = product_options[id]["upsells"][f]["name"];
					if(product_options[id]["upsells"][f]["more"] != ""){
						more.innerHTML = '<a href="javascript:void(0);" onclick="more_win(\''+ product_options[id]["upsells"][f]["more"] + '\',event);"><img src="/images/help_icon.gif" border="0" /></a>';
					}else{
						more.innerHTML = "";
					}
					row.appendChild(more);
					row.appendChild(check_cell);
					check_cell.appendChild(check_box);
					row.appendChild(desc);			
					
				}
		//ADD TO LIST BUTTON
			var t_row = document.createElement("tr");							
				if(windows && ie){
					t_hd = document.createElement("<td colspan=\"3\">");																		
				} else {
					t_hd = document.createElement("td");
					t_hd.setAttribute("colspan","3");												
				} 				
				t_hd.innerHTML = '<input type="button" class="formButton" value="Add To List" onclick="add_upsells()" />';
				atbl.appendChild(t_row);		
				t_row.appendChild(t_hd);

	}
			
	get_config(id);	

	}else{
		// LIST OUT MODELS FOR SECTIONS
		//document.getElementById("current_model").innerHTML = "";
		view.innerHTML = "<strong>Select a model/version:</strong> &nbsp;"; 
		if(windows && ie){
			opts = document.createElement("<select id='model' onchange='if(this.selectedIndex>0)set_model(this)'>");
		}else{
			opts = document.createElement("select");
			opts.setAttribute("onchange","set_model(this)");
		}
		opts.className = 'formText';
		view.appendChild(opts);
		if(windows && ie){
			o = document.createElement("<option value=''>");
		}else{
			o = document.createElement("option");				
		}		
		o.innerHTML = "Select model:";	
		opts.appendChild(o);
		for(var f = 0; f < product_options[id]["models"].length; f++){
			if(windows && ie){
				o = document.createElement("<option value='"+product_options[id]["models"][f]["model_name"]+"'>");
			}else{
				o = document.createElement("option");
				o.setAttribute("value",product_options[id]["models"][f]["model_name"]);
			}				
			o.innerHTML = product_options[id]["models"][f]["model_name"];
			opts.appendChild(o);
		}
	}
	 document.getElementById("prodsecondary").style.display = 'block';
	 document.getElementById("quant").style.display = "block";

	document.getElementById("add_product").value = "Add To List";
	document.getElementById("add_product").style.display = "block";
	document.getElementById("add_product").onclick=addit;
}

////LOGIC CHECKS

function check_all_logic(prod_id, option, cat){
	check_logic(prod_id, option, cat);
	//return;
	for(var e = 0; e < document.quoteForm.elements.length; e++){
			 if( ! document.quoteForm.elements[e].disabled && document.quoteForm.elements[e].checked)
				check_logic(prod_id, document.quoteForm.elements[e], cat);	
		}
}

function check_logic(prod_id, option, cat){

	var name = option.getAttribute("name");
	var opt = name.split("_");
	var id = opt[1];

	// excludes
	var _exc = product_options[prod_id]["exclude"][id].toString();
	var exc = _exc.split(",");	

	var _inc = product_options[prod_id]["include"][id].toString();
	var inc = _inc.split(",");

	//check to see if checking
	if(!option.checked){ //reverse logic		
		if(_inc!="")
			for(var i =0; i < inc.length; i++){	
				if (document.quoteForm.elements["opt_" + inc[i]]) {
					document.quoteForm.elements["opt_" + inc[i]].disabled = false;
					document.quoteForm.elements["opt_" + inc[i]].checked = false;
				}
				if (document.getElementById("txt_" + inc[i])) {	
					document.getElementById("txt_" + inc[i]).style.color = '#000';
				}
			}			
		if(_exc!="")
			for(var i =0; i < exc.length; i++){				
				if (document.quoteForm.elements["opt_" + exc[i]]) {
					document.quoteForm.elements["opt_" + exc[i]].disabled = false;
				}
				if (document.getElementById("txt_" + exc[i])) {	
					document.getElementById("txt_" + exc[i]).style.color = '#000';
				}
			}
	} else {
		if (_inc != "") {
			for(var i =0; i < inc.length; i++){
				if (document.quoteForm.elements["opt_" + inc[i]]) {
					document.quoteForm.elements["opt_" + inc[i]].checked = true;
					document.quoteForm.elements["opt_" + inc[i]].disabled = true;
				}
				if (document.getElementById("txt_" + inc[i])) {
					document.getElementById("txt_" + inc[i]).style.color = '#666';
				}
			}
		}
		if (_exc != "") {
			for(var i = 0; i < exc.length; i++){
				if (document.quoteForm.elements["opt_" + exc[i]]) {
					document.quoteForm.elements["opt_" + exc[i]].checked = false;
					document.quoteForm.elements["opt_" + exc[i]].disabled = true;
				}
				if (document.getElementById("txt_" + exc[i])) {	
					document.getElementById("txt_" + exc[i]).style.color = '#000';
				}
			}
		}
	}
	get_config(prod_id, cat, option);
}

var cur_prod = null;
var cur_model = null;
var cur_id = null;
var quote_list = [];

function get_config(id, cat, option){			
	if(product_options[id]["configurable"] == "Yes"){
		var checks = [];
		var int_title = "";
		if(option) int_title = option.getAttribute("_title");
		for(var e = 0; e < document.quoteForm.elements.length; e++){
				if(document.quoteForm.elements[e].checked){
					checks.push(document.quoteForm.elements[e].value);
					
				}
		}
		checks.sort(); // sort the checks so we can build an ordered comma separated string
		var config = checks.join(",");
		var configs = product_options[id]["conf_list"].split("||");
		
		var matched = false;
		for(var f = 0; f < configs.length; f++){
			var data = configs[f].split("|");
			if (data.length > 1) {
				// order the array and store it in a comma separated string
				var array1 = data[0].split(",");
				array1.sort();
				var string1 = array1.join(",");
				if(string1 == config) {
					matched = data[1];
				}
			}
		}
		if(cat == "Integration"){			
			 if(config.length > 0){
				cur_model = int_title; 
				document.getElementById("add_product").disabled = false;
				document.getElementById("current_model").innerHTML = "<br /><br /><h2>Model: <span class=\"h2alt\">" + product_options[id]["models"][0]["model_name"] + " w/" + int_title + "</span></h2><br />";
				
				document.getElementById("modelnum").innerHTML = "<p style=\"font-weight:normal;font-size:15px;color:#C20000;padding:0;\">" + product_options[id]["models"][0]["model_name"] + " w/" + int_title + " has been added to your quote list.</p>";
				
			} else {
				document.getElementById("add_product").disabled = true;
				document.getElementById("current_model").innerHTML = "<br /><br /><h2>Please select an option above.</span></h2>";
			}			
			return;
		}
		if(matched != " "){
			 document.getElementById("current_model").innerHTML = "<br /><br /><h2>Model: <span class=\"h2alt\">" + matched + "</span></h2><br />";
			 document.getElementById("add_product").disabled = false;
			 document.getElementById("prodsecondary").style.display = 'block';
			 document.getElementById("quant").style.display = "block";
			 
			 document.getElementById("modelnum").innerHTML = "<p style=\"font-weight:normal;font-size:15px;color:#C20000;padding:0;\">" + matched + " has been added to your quote list.</p>";
			 
			 cur_model = matched;
		} else{			
			document.getElementById("current_model").innerHTML = "<br /><br /><h2>Please select an option above.</span></h2><br />";
			document.getElementById("add_product").disabled = true;
			document.getElementById("prodsecondary").style.display = 'none';
			document.getElementById("quant").style.display = "none";
			cur_model = "";
		}
	} else {

		var config = product_options[id]["base_letter"] + letters.join("");
		document.getElementById("current_model").innerHTML = "<br /><br /><h2>Model: <span class=\"h2alt\">" + config + "</span></h2><br />";
		document.getElementById("add_product").disabled = false;
		
		document.getElementById("modelnum").innerHTML = "<p style=\"font-weight:normal;font-size:15px;color:#C20000;padding:0;\">" + config + " has been added to your quote list.</p>";
		
		
		cur_model = config;		
	}
}
function set_model(sel){
 	 document.getElementById("add_product").disabled = false;
 	 cur_model = sel.value;
}


function addit(){
	//TODO: update hidden field for passing on to contact information, validate.

	var q = document.quoteForm.qty.value;
	var checks = [];
	for(var e = 0; e < document.quoteForm.elements.length; e++){
			if(document.quoteForm.elements[e].checked){
				var tit = document.quoteForm.elements[e].getAttribute("_title");
				if(document.quoteForm.elements[e].getAttribute("_part") && document.quoteForm.elements[e].getAttribute("_part") != ""){
					tit += " Part Number: " + document.quoteForm.elements[e].getAttribute("_part");
				}
				checks.push(tit);
			}
	}
	var opts = checks.join("$$");
	var prod = { 
		product:cur_prod,
		model:cur_model,
		optns:opts,
		qty:q
	};
	
	quote_list.push(prod);
	document.getElementById("request_results").style.display = "block";
	document.getElementById("continue_btn").disabled = false;

	//reset stuff..
	document.getElementById("product").selectedIndex = 0;
	document.getElementById("add_product").disabled = true;
	document.getElementById("current_model").innerHTML = "";
	document.quoteForm.qty.value  = 1;
 	var view = document.getElementById("options_and_features");
		view.innerHTML = "";
	
	var list = document.getElementById("product_list");
	if(list.innerHTML == "(no products added yet)") {list.innerHTML = "";}

	var prod_add = cur_model == "" && cur_model !== null ? cur_prod : cur_prod + ", " + cur_model;
  list.innerHTML += "<div>(" + q + ") " + prod_add + " <a style='cursor:pointer;' href='javascript:void(0);' onclick='removeit(this,"+quote_list.length+")'>[remove]</a></div>";
	document.getElementById("upsells").style.display = 'block';
	document.getElementById("modelnum").style.display = 'block';
	
	if (product_options[cur_id]["upsells"].length == 0) {
		//document.getElementById("upsells").innerHTML = "<p style=\"font-weight:normal;font-size:15px;color:#C20000;padding:0;\">" + cur_prod + " has been added to your quote list.</p><br /><br />";
		document.getElementById("modelnum").style.display = "block";
	} 

	document.getElementById("prodsecondary").style.display = 'none';	
	document.getElementById("continue_okay").style.display = 'block';
	document.getElementById("rq_text").style.display = 'none';
	document.getElementById("selections").style.display = 'none';
	document.getElementById("configbutton").style.display = 'inline';
	window.scrollTo(0,0);	
	save_list();
}

function save_list(){
	var save = [];
	for(var q = 0; q < quote_list.length; q++){
		save.push(quote_list[q]["product"]+",,"+quote_list[q]["model"]+",,"+quote_list[q]["optns"]+",,"+quote_list[q]["qty"]);
	}	
	var save_str = save.join("||");	
	var handlers = { onData:function(data){  save_id = data; }  }
	var req = new Request(handlers);

	if(save_id != "")
		req.send("save_config.php?id="+save_id+"&save=" + save_str);
	else
		req.send("save_config.php?save=" + save_str);
}

function do_submit(fo){
	 for(var q = 0; q < quote_list.length; q++){
		if(windows && ie){
			prod = document.createElement("<input type='hidden' name='products[]' value='"+quote_list[q]["product"]+"' />");
			mdls = document.createElement("<input type='hidden' name='models[]' value='"+quote_list[q]["model"]+"' />");
			opts = document.createElement("<input type='hidden' name='options[]' value='"+quote_list[q]["optns"]+"' />");
			qtys = document.createElement("<input type='hidden' name='amounts[]' value='"+quote_list[q]["qty"]+"' />");
		} else {
			prod = document.createElement("input");
			prod.setAttribute("type",'hidden');
			prod.setAttribute("name",'products[]');
			prod.setAttribute("value",quote_list[q]["product"]); 
			mdls = document.createElement("input");
			mdls.setAttribute("type",'hidden');
			mdls.setAttribute("name",'models[]');
			mdls.setAttribute("value",quote_list[q]["model"]); 
			opts = document.createElement("input");
			opts.setAttribute("type",'hidden');
			opts.setAttribute("name",'options[]');
			opts.setAttribute("value",quote_list[q]["optns"]); 
			qtys = document.createElement("input");
			qtys.setAttribute("type",'hidden');
			qtys.setAttribute("name",'amounts[]');
			qtys.setAttribute("value",quote_list[q]["qty"]); 
		}
		fo.appendChild(prod);
		fo.appendChild(mdls);
		fo.appendChild(opts);
		fo.appendChild(qtys);
	}
	fo.submit();
}

var upsells = new Array();
function toggle_upsell(opt){
var index = opt.getAttribute("index");
var title = opt.getAttribute("_title");
var part = opt.getAttribute("append");
	if(opt.checked){
		var prod = { 
			product:title,
			model:part,
			optns:" ",
			qty:1
		};
	 	upsells.push(prod);
	}else{
		for(var u = 0 ; u < upsells.length; u++){		
		  if(upsells[u]["product"] == title)	
				upsells = upsells.splice(u,1);
		}
	}

}

function add_upsells(){
	
	
	document.getElementById("continue_btn").disabled = false;

	//reset stuff..
	document.getElementById("category").selectedIndex = 0;
	document.getElementById("product").selectedIndex = 0;
	
	document.quoteForm.qty.value  = 1;
 	var view = document.getElementById("options_and_features");
		view.innerHTML = "";
	
	var list = document.getElementById("product_list");
	if(list.innerHTML == "(no products added yet)") list.innerHTML = "";	

	 for(var u = 0 ; u < upsells.length; u++){				
	    quote_list.push(upsells[u]);
		var model = upsells[u].model == "" ? "" : ", " + upsells[u].model + " ";
		list.innerHTML += "<div>(" + 1 + ") " + upsells[u].product + model + " <a style='cursor:pointer;' href='javascript:void(0);' onclick='removeit(this,"+quote_list.length+")'>[remove]</a></div>" ;
	}

	//document.getElementById("upsells").innerHTML = "<h2>Optional product(s) have been added to your quote list.</h2><br /><br />";
	document.getElementById("modelnum").innerHTML = "<p style=\"font-weight:normal;font-size:15px;color:#C20000;padding:0;\">Optional product(s) have been added to your quote list.</p><br /><br />";	
	
	document.getElementById("upsells").style.display = "none";
	
	document.getElementById("add_product").value = "Add Another Product" 
	document.getElementById("add_product").onclick=reset_quote;
	document.getElementById("add_product").disabled = false;
	
	document.getElementById("request_results").style.display = "block";

	upsells = new Array();		
	window.scrollTo(0,0);	
	save_list();
		
}


function removeit(node, index){
	node.parentNode.parentNode.removeChild(node.parentNode);
	quote_list.splice(index-1,1);	
	if(quote_list.length == 0){
		document.getElementById("product_list").innerHTML = "(no products added yet)";
		document.getElementById("request_results").style.display = "none";
		//document.getElementById("continue_okay").style.display = 'none';
		document.getElementById("continue_btn").disabled = true;
	}
	save_list();
}


// Pulled this in from the old BioTek code -bkniaz
function EventInfo(e, cancel){
		if (!e) var e = window.event;		
	
		if (e.target) this.source = e.target;
		else if (e.srcElement) this.source = e.srcElement;
		if (this.source.nodeType == 3)
			this.source = this.source.parentNode;
			
		if (e.pageX || e.pageY) {
			this.xmouse = e.pageX;
			this.ymouse = e.pageY;
		}
		else if (e.clientX || e.clientY) {
			this.xmouse = e.clientX + document.body.scrollLeft;
			this.ymouse = e.clientY + document.body.scrollTop;
		}		
		if(cancel){
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();
		}	
}



function more_win(msg, event){
	var ei = new EventInfo(event, true);
	
	var popupcontainer = document.createElement("div");
		popupcontainer.style.position = 'relative';

	
	var popup = document.createElement("div");
		popup.innerHTML = msg + "<br />";
		popup.style.position = 'absolute';
		popup.style.border = '1px solid #000';
		popup.style.padding = '20px';
		popup.style.backgroundColor = '#FFF';
		popup.style.width = '250px';		
		popup.style.top  = '0px';
		popup.style.left = '0px';
		
		popupcontainer.appendChild(popup);		
		ei.source.parentNode.parentNode.appendChild(popupcontainer);

	var cls = document.createElement("a");
	    cls.style.display = 'block';
		cls.href = '#';
		cls.innerHTML = "[x]";		
		cls.style.color = "#0065a5";		
		cls.style.position = 'absolute';
		cls.style.top = '5px';
		cls.style.right = '7px';
		//cls.style.cursor = "pointer";		
		cls.onclick = function(e){  
				var ei = new EventInfo(e, true);
				ei.source.parentNode.parentNode.removeChild(ei.source.parentNode);
				return false;
		}
		popup.appendChild(cls);
		
}

function reset_quote(){	
	document.getElementById("add_product").value = "Add To List" 
	document.getElementById("selections").style.display = 'block';
	document.getElementById("prodsecondary").style.display = 'none';
	document.getElementById("prod_photo").style.display = 'none';
	document.getElementById("upsells").style.display = 'none';
	
	document.getElementById("modelnum").style.display = 'none';
	
	document.getElementById("quant").style.display = 'none';
	document.getElementById("configbutton").style.display = 'none';
	document.quoteForm.category.selectedIndex = 0;
	
	document.quoteForm.product.options[0] = new Option('Please select a category first');
	document.quoteForm.product.selectedIndex = 0;
	document.quoteForm.product.disabled = true;
	

}

