// © 20-20 Technologie Inc. 2015 
// All Rights Reserved
function reload() {
   resizeWidth(document.getElementById("rightFrame"),300,0);
   resizeWidth(document.getElementById("topFrame"),0,0);
   resizeWidth(document.getElementById("bottomFrame"),0,0);
   resize(document.getElementById("centerFrame"),0,0,50,50);
   resize(document.getElementById("centerFrame2"),0,0,50,50);
   resize(document.getElementById("features"),0,0,50,50);
}

function resize(node,w0,w1,h0,h1) {  
   resizeWidth(node,w0,w1);
   resizeHeight(node,h0,h1);
}

function resizeWindow()
{
   var cnode2=document.getElementById("centerFrame2");	
   resizeWidth(document.getElementById("rightFrame"),300,0);
   resizeWidth(document.getElementById("topFrame"),0,0);
   resizeWidth(document.getElementById("bottomFrame"),0,0);
	if(cnode2.style.display=="none"){
		var width = document.getElementById("centerFrame").parentNode.offsetWidth - 0 - 0;
		if (width < 5) width = 5;
		document.getElementById("centerFrame").style.width = width + "px";
        document.getElementById("centerFrame2").style.display = "none";	

        var height = document.getElementById("centerFrame").parentNode.offsetHeight - 0 - 0;
        if (height < 5) height = 5;
        document.getElementById("centerFrame").style.height = height-100 + "px";
	    document.getElementById("centerFrame2").style.display = "none";	
	}else{
	   var w = document.getElementById("centerFrame").parentNode.offsetWidth/2;	        
	   document.getElementById("centerFrame").style.width = w + "px";	
	   w = document.getElementById("centerFrame2").parentNode.offsetWidth/2-200;
	   w = document.getElementById("centerFrame2").parentNode.offsetWidth/2;
       document.getElementById("centerFrame2").style.width = w + "px"; 	

	    var H = document.getElementById("centerFrame").parentNode.offsetHeight / 2;
	    document.getElementById("centerFrame").style.height = H + "px";
	    H = document.getElementById("centerFrame2").parentNode.offsetHeight/ 2 - 200;
	    H = document.getElementById("centerFrame2").parentNode.offsetHeight / 2;
	    document.getElementById("centerFrame2").style.height = H + "px";
	}  
}
function normButton(node) {
   node.className = "normButton";
}

function negButton(node) {
   node.className = "negButton";
}

function negMenu(node) {
   node.className = "negHamb";
   for (var i = 0; i < node.childNodes.length; i++) {
      node.childNodes[i].className = "negBar";
   }
}

function normMenu(node) {
   node.className = "normHamb";
   for (var i = 0; i < node.childNodes.length; i++) {
      node.childNodes[i].className = "normBar";
   }
}

function resizeWidth(node,w0,w1) {
   var width = node.parentNode.offsetWidth - w0 - w1;
   if (width < 5) width = 5;
   node.style.width = width + "px";
}

function resizeHeight(node,h0,h1) {
   var height = node.parentNode.offsetHeight - h0 - h1;
   if (height < 5) height = 5;
   node.style.height = height + "px";
}

function switchDisplayMode(node) {
   if (node == null || node.innerHTML.indexOf("optname3") != -1) return;
   for (var i = 0; i < node.childNodes.length; i++) {
      var current = node.childNodes[i].className.charAt(node.childNodes[i].className.length-1);
      var next = "2";
      if (current == "2") next = "1";
      node.childNodes[i].className = node.childNodes[i].className.replaceSubstr("grid"+current,"grid"+next);
      node.childNodes[i].innerHTML = node.childNodes[i].innerHTML.replaceSubstr("optionImage"+current,"optionImage"+next);
      node.childNodes[i].innerHTML = node.childNodes[i].innerHTML.replaceSubstr("optname"+current,"optname"+next);
   }
}

function switchColors(node) {
	
   var classes = node.className.split(" ");
   var currentGrid = "";
   for (var i = 0; i < classes.length; i++) {
      if (classes[i].indexOf("grid") != -1) currentGrid = classes[i].charAt(classes[i].length-1);
   }
   switch (node.status) {
      case "0" : 
         if (node.focus == "1") {
            node.className = node.cni;
         }
         else {
            node.className = node.cn;
         }
         break;
      
      case "2" : 
         node.className = node.cns;
         break;
      
      case "3" : 
         node.className = node.cne;
         break;
   }
   if (currentGrid != "") node.className += ' grid' + currentGrid;
}

function printFeatures() {   	  		
   var date=new Date();	 
   var head = window.frames["print_frame"].document.getElementsByTagName("head")[0];   
   var link = window.frames["print_frame"].document.createElement("link");
   link.setAttribute("rel", "stylesheet")
   link.setAttribute("type", "text/css")
   link.setAttribute("media", "Print") ;
   link.setAttribute("href", "GSVPrintStyle.css")
   head.appendChild(link);
   var isprintable="true";
   var content = '<div id="header"></div></div></div><div id="container"><div id="leftPrintFrame"><table width="100%"><tr><td width="70%"><div align="left" id="manuf" ><image id="manuflogo" src="printlogo.png"></image></div> </td><td><div align="right" valign="top">'+date.toLocaleDateString("en-US")+'</div></td></tr></table><br><div id="textblock1">Thank you for your interest in Ideal cabinetry..</div><br><div id="textblock2">Please review and confirm your selections As listed in Styles & Pricing</div><br><div><table id="table1" CELLSPACING="0" CELLPADDING="10"; >';
   var feature="";
   var pFeature="";
   var count = 0;   
   var children = document.getElementById("features").childNodes;
	for (var i = 0; i < children.length; i++){				
		 if (children[i].className == "feature" || children[i].className == "ChildFeature" ) {
			isprintable=children[i].isPrintable;
			feature=children[i].innerHTML;			
			if(children[i].type==undefined) continue;
			if(isprintable=="false"){
				continue;
			}else{
				isprintable="true";
			}		
			pFeature=feature;
			if ((count%3) == 0)	{
				content += '<tr>';
			}   
			content += '<td class="tablecell">';
			count = count + 1;
			content +=feature;
		 } else {
			if(feature=="")	{
				var isprintable=children[i].isPrintable;
				if(isprintable=="false"){
					continue;
				}else{
					isprintable="true";
				}	
				feature=pFeature;
				if ((count%3) == 0)	{
					content += '<tr>';
				}   
				content += '<td class="tablecell" >';
				count = count + 1;
				content += feature;
			}
			if(isprintable=="false"){
				continue;
			}
			for (var j = 0; j < children[i].childNodes.length; j++) {
				if (children[i].childNodes[j].className != "deleteButton") {
					if (children[i].childNodes[j].src != null && children[i].childNodes[j].src != "") {
						content += '<br><image class="selectedPrintOptionImage" src="'+ children[i].childNodes[j].src +'"></image>';
					}
					else {
						content +=  '<br>' + children[i].childNodes[j].innerHTML ;
					}
				}		
			}
			content+='</td>';			
			feature="";
		 }		 
	}
   content += '<br></table></div><br><div id="textblock3">Disclaimer: Images shown here are a representation of your selections, not an exact rendition.</div>';
 content +='<br><br><br><div id="line"><hr noshade size="3"></div><br><div><b>Customer Signature</b></div></div></div>';   
   window.frames["print_frame"].document.body.innerHTML = content;   
   window.frames["print_frame"].window.focus();
   window.frames["print_frame"].window.print();
}     

function showMenu() {
   var menu = document.getElementById("menu");
   menu.style.display = "inline";
}

function hideMenu() {
   var menu = document.getElementById("menu");
   menu.style.display = "none";
}

function negMenuEntry(node) {
   node.className = "menuEntryOver";
}

function normMenuEntry(node) {
   node.className = "menuEntry";
}

String.prototype.replaceSubstr = function(oldsub, newsub) {
   var index = this.indexOf(oldsub);
   if (index == -1) return this;
   var prec = this.substring(0,index);
   var aft = this.substring(index + oldsub.length);
   return prec + newsub + aft;
}

