function remove_children(ideal, lenny)
		       {var jim = document.getElementById(ideal);
					      if(jim.hasChildNodes())
								  {
									 while(jim.childNodes.length > lenny)
									    {jim.removeChild(jim.lastChild);}
									}
					 } 
					 
                     
function isMSIE() 
         {
          var brow = navigator.appName;
          if(brow == "Microsoft Internet Explorer")
             {
              return true;
             }
          else
            {
             return false;
            }
         
         }                    

function isArray(obj)
           {
					   return(typeof(obj.length)=="undefined")?false:true;
					}

function get_by_id(id)					
					{
					 var gbi = document.getElementById(id);
					 return gbi;
					}

function append_child(chld, arr)
               {
							  for(i=0; i<arr.length; i++)
								       {
											  chld.appendChild(arr[i]);
											 } 
							 }
							 
function create_text_node(text)
          {
					 var ctn = document.createTextNode(text);
					 return ctn;
					}							 
							 
function create_select(name, opp_arr)
              {
							try
                               {
                                var cs = document.createElement('<select name="'+name+'" id="'+name+'">');
                               }
                             catch(e)
                               {
                                
                               }
                               if(!cs)
                                {
                                var cs = document.createElement('select');
							       cs.setAttribute("name", name );   	
										 cs.setAttribute("id", name );
                                 }	
							 
							      /*for(i=0; i<opp_arr.length; i++)
										      {
													 var opt_val = document.createElement('option'); 
													    opt_val.setAttribute("value", opp_arr[i]);
													 var text_val =  document.createTextNode(opp_arr[i]);
													 
													  opt_val.appendChild(text_val);
													 cs.appendChild(opt_val);
													}*/
                                                    alert(cs);
										return cs;			 
							}
							
							
							
function create_elements(tx_num, els_arr, name, type)
             {
						 
					function yep()
					        {
									 for(x=0; x<tx_num.length; x++)
									   {
										  if(i==tx_num[x])
											   {
												  return true;
												 }
											 
										 }
									}	 
						 
						  var ce = new Array();
							
							if(tx_num != null && isArray(tx_num))
							    {
									
									
									 for(i=0; i<els_arr.length; i++)
							   {
								  var yepper = yep();
									var name1 = name+els_arr[i];
								
								 
						       if(yepper == true)
									    {
											 ce[i]=document.createTextNode(els_arr[i]);
											}
										else
										  {
											 if(els_arr[i] == 'img')
											    {
													 var new_img = new Image();
													 new_img.setAttribute("name", name1);
													 new_img.setAttribute("id", name1);
													 ce[i]= new_img;
													}
											
											else
											 {
											 var new_el = document.createElement(els_arr[i]);
											     new_el.setAttribute("name", name1);
													 new_el.setAttribute("id", name1);
													 if(type == 'checkbox' || type == 'text' || type == 'password' || type == 'radio' || type == 'button' || type == 'submit')
													   {
														  new_el.setAttribute("type", type); 
														 }
											 
											   ce[i]=new_el;
												 
											}	
						      }
							 }
							}
							
						 else
						   {
						  for(i=0; i<els_arr.length; i++)
							   {
								  var name1 = name+els_arr[i];
								 
						       if(i == tx_num)
									    {
											 ce[i]=document.createTextNode(els_arr[i]);
											}
										else
										 {
										 if(els_arr[i] == 'img')
											    {
													 var new_img = new Image();
													 new_img.setAttribute("name", name1);
													 new_img.setAttribute("id", name1);
													 ce[i]= new_img; 
													}
													
											else		
										  {
										  
										 
											 var new_el = document.createElement(els_arr[i]);
											     new_el.setAttribute("name", name1);
													 new_el.setAttribute("id", name1);
													 if(type == 'checkbox' || type == 'text' || type == 'password' || type == 'radio' || type == 'button' || type == 'submit')
													   {
														  new_el.setAttribute("type", type);
														 }
											 
											   ce[i]=new_el;
											}	
						      }
								 }
							 }
								 
								 return ce;	
						 }	
						 
function get_select_val(sel)
                {
								 val = document.getElementById(sel).options[document.getElementById(sel).options.selectedIndex].value;
								 return val;
								}					 						
							
function imgo()
          {
					 remove_children('view_img',0);
					 
					 var get_img = '';
					 var mult;
					 
					 var eles_arr = ['img', 'br','br','PROFILE','br'];
                     var eles_arr2 = ['img', 'br'];
					 var text = 3;
					
					 img = get_select_val("door_type");
					 theImg = img.substring(img.indexOf('_')+1, img.lastIndexOf('_'));
                     theMult = img.substring(img.lastIndexOf('_')+1);
                     theMult = parseFloat(theMult);
                     floatMult = theMult.toFixed(2);
					 
							 get_img = 'http://www.decore.com/media/94_214/'+theImg+'.jpg';
                             get_pro = 'http://www.decore.com/media/profiles/225_40/'+theImg+'p.gif';
							 mult = floatMult;
												
								var the_eles = create_elements(text, eles_arr, 'image', 'good');
							    var the_eles2 = create_elements(text, eles_arr2, 'image', 'good');
                                
							      the_eles[0].setAttribute("src", get_img);
                                  the_eles2[0].setAttribute("src", get_pro);
										var divo = get_by_id('view_img');
										
										append_child(divo,the_eles);
                                        
                                        append_child(divo,the_eles2);
										
							return mult;			
					}						
							 

function door_list_func()
           {
					 remove_children('p3',0);
					 
					 var mat_val = document.getElementById('mat_val').options[document.getElementById('mat_val').options.selectedIndex].value;
					 
					 
					 if(mat_val == "W")
					    {
							 var pop_arr = ['ADD STYLE _r_e','ARTESIA 3/4 _406_100','CENTURY 3/4 _405_107', 'EL DORADO 3/4 _824_107', 'EMBASSY 3/4 _224_100', 'EMERSON 3/4 _109_100',
                                            'AUGUSTINE 3/4 _389_114', 'ARIES 3/4 _93_100','BROOKHURST 3/4 _90_107','PRELUDE 3/4 _92_100',
                                            'BEL AIR 3/4 _581_114', 'COLORADO 7/8 _894_128', 'DELAWARE 7/8 _538_114', 'HIGHPOINTE 3/4 _379_128', 'PINNACLE 3/4 _378_128',
                                            'PONDEROSA 3/4 _839_114', 'PROVIDENCE 7/8 _537_107', 'RIDGEVIEW 3/4 _579_128', 'SARATOGA 7/8 _594_107', 'SOLANA 3/4 _589_121',
                                            'WOODHAVEN 3/4 _578_121', 'ARIZONA 3/4 _940_100', 'ASPEN 7/8 _19_100', 'AUBURN 3/4 _832_107', 'CASCADE 3/4 _858_114', 
                                            'DANISH 7/8 _33_100', 'DURANGO 3/4 _834_107', 'FLAGSTAFF 3/4 _835_107', 'MAVERICK 7/8 _895_107', 'NEVADA 3/4 _898_107',
                                            'PARKER 3/4 _352_114', 'REDONDO 3/4 _409_107', 'SHAKER 3/4 _831_100', 'STUDIO 3/4 _351_107', 'CABRILLO 7/8 _115_124',
                                            'EASTON 7/8 _114_124', 'EUROPEAN 3/4 _78_124', 'FALLBROOK 3/4 _592_107', 'RICHMOND 3/4 _71_100', 'TALBOT 7/8 _113_124', 
                                            'VALENCIA 3/4 _81_107', 'YUKON 3/4 _891_107','ELDRIDGE 7/8 _360_107','BRIGHTON 7/8 _560_114','ORLANDO 7/8 _15_100',
                                            'AMBASSADOR 7/8 _540_121','CATALINA 7/8 _51_114','CONSTITUTION 7/8 _547_107','DIPLOMAT 7/8 _598_114','HAYES 3/4 _348_107',
                                            'HUDSON 3/4 _548_114','TERRACINA 3/4 _390_107','MONTEREY 7/8 _88_107','SHEFFIELD 7/8 _69_107','MANHATTAN 7/8 _63_114',
                                            'NORMANDIE 7/8 _67_107','TUSCANY 3/4 _590_107','WINDSOR 3/4 _70_100','SHELDON 7/8 _838_114','RANCHERO 7/8 _23_107',
                                            'ISLANDER 7/8 _82_100','DAVENPORT 3/4 _852_128','CAMDEN 3/4 _836_107','VERMONT 7/8 _596_114','WILMINGTON 7/8 _541_107',
                                            'BRUNSWICK 7/8 _597_107','CONNECTICUT 7/8 _595_100','ADOBE 3/4 _830_100','REVERE 3/4  _800_107','HERITAGE 3/4 _805_107',
                                            'MALIBU 7/8 _50_107','RAMONA 7/8 _21_100','LINCOLN 3/4  _802_107','CARDINAL 3/4 _430_107','RANGER 3/4 _432_100',
                                            'PATRIOT 3/4 _820_107','LIBERTY 3/4 _810_107','LEXINGTON 3/4 _825_107','LEXINGTON 3/4 _825_107','COLONIAL 3/4 _815_107',
                                            'FREEDOM 3/4 _260_107','HILLSBORO 3/4 _270_107','FIESTA 3/4 _850_100','MISSION 3/4 _840_100','COUGAR 3/4 _240_100',
                                            'EAGLE 3/4  _902_100','HAWK 3/4 _903_107','FALCON 3/4 _904_107','BRONCO 3/4 _905_100','TAURUS 3/4 _906_100',
                                            'MUSTANG 3/4 _907_100',
                                            'RHODE ISLAND 7/8 _837_100'];//left off I finished trad (next start victorian)
							     pop_arr.sort();
								
                               // var door_list = create_select('door_type',0);	 
							 var door_list = document.createElement('select');
							       door_list.setAttribute("name", "door_type" );	
										 door_list.setAttribute("id", "door_type" );	
                                         var msie = isMSIE();
                                         if(msie)
                                          {
                                          door_list.setAttribute("onchange", function(){exo(); imgo();});
                                          }
                                        else
                                        {
										 door_list.setAttribute("onchange", "exo(); imgo()" );
                                        }
										 
										 for(i=0; i<pop_arr.length; i++)
										      {
                                                   var endo = pop_arr[i].indexOf('_');
                                                   var popSub = pop_arr[i].substring(0, endo);
                                                   var popOptVal = pop_arr[i].substring(endo);
                                                        
													 var opt_val = document.createElement('option'); 
													    opt_val.setAttribute("value", pop_arr[i]);
													 var text_val =  document.createTextNode(popSub);
													 
													 opt_val.appendChild(text_val);
													 door_list.appendChild(opt_val);
													 
													} 
													
													var text_door = document.createTextNode('Choose Your Door Style');
													var br1 = document.createElement('br');
													var para = document.getElementById('p3');
													var alel = [text_door,br1,door_list];
													
													    append_child(para,alel);
															//para.appendChild(br1);
													    //para.appendChild(door_list);
							}

					 } 

function exo()
           {
					 
					 remove_children('p4',0);
					 remove_children('p5',0);
						
						var eles = ['If you would like glazing on the doors','br','Check this box. ','input'];
						var nodes = [0,2];
						
						var other_eles = create_elements(nodes,eles,'second','checkbox');
												
						
						var child1 = get_by_id('p4');
						append_child(child1,other_eles);
						
						//now the button to calculate
						
						var but = ['input'];
						var nodes2 = null;
						
						var more_eles = create_elements(nodes2, but, 'third', 'button'); 
						
						   more_eles[0].setAttribute("value", "CALCULATE");
                           var msie = isMSIE();
                           if(msie)
                             {
                              more_eles[0].setAttribute("onclick", function(){calc_it();});
                             }
                           else
                             {
							 more_eles[0].setAttribute("onclick", "calc_it()");
                             }
							 
						var child2 = get_by_id('p5');	 
						
						    append_child(child2, more_eles);
						
						
						
					 }

function calc_it()
          {
					
					var multo = imgo();
                    
					
					var door = get_select_val("door_type");
                    var endo = door.indexOf('_');
                    var door = door.substring(0, endo);
					
					 var linft = get_by_id('lin_ft');
					     linft = linft.value;
						var check = get_by_id('secondinput');
						
							 
							 if(check.checked == true)
							   {
								   var price = linft * parseFloat(multo);
									 
									     price = parseFloat(price) + (parseFloat(price) * parseFloat(.08));
                                         price = price.toFixed(2);
											  var pf = 'The price to reface '+linft+' feet of cabinets <br>with the '+door+' door (with Glaze) is <br><font size="4pt" color="#FFFF00"> $'+price+'</font>';
								 }
							else
							   {
							    var price = linft * parseFloat(multo);
                                price = price.toFixed(2);
									 var pf = 'The price to reface '+linft+' feet of cabinets <br>with the '+door+' door is <br><font size="4pt" color="#FFFF00"> $'+price+'</font>';
							   }	
								 							 
								 get_by_id('p6').innerHTML = pf;						 
								 
					}




function getCookie(nm)
         {
				  var cook =  document.cookie ;
					
					var st;
					
					
					var sch = nm + "=";
					var end;
					st = cook.indexOf(sch);
					
					st += sch.length;
					end = cook.indexOf(";",st);
					
					if(end != -1)
					    {
					     var end2 = cook.indexOf(";",st);
							}
					else
					    {
							 return false;
							}		 
					var bob2 =  cook.substring(st,end2);
					return bob2;
					
				 }				 

function setCookie(nm,val)
         {
				  document.cookie = nm + "=" + val;
				 }
				 
var cook_is = getCookie('count_boy');

       if(!cook_is)
			    {
					 setCookie('count_boy', 1);
					}				 
					
//............below this is the counter........................It must be cut from this page
//...........Naw below this is now for the calculator page................................


//....first function is if they choose wood.......................





