﻿
/*purchase*/
var img_buy_purchase_home_off = new Image();
img_buy_purchase_home_off.src = "_images/content/buy/purchase/home_off.jpg";
var img_buy_purchase_home_on = new Image();
img_buy_purchase_home_on.src = "_images/content/buy/purchase/home_on.jpg";
var img_buy_purchase_view_off = new Image();
img_buy_purchase_view_off.src = "_images/content/buy/purchase/view_off.jpg";
var img_buy_purchase_view_on = new Image();
img_buy_purchase_view_on.src = "_images/content/buy/purchase/view_on.jpg";

var purchase_tab_images = new Array ( "imgBuyPurchaseHome", "imgBuyPurchaseView" );
var purchase_tabs = new Array( "img_buy_purchase_home", "img_buy_purchase_view" );
var purchase_tab_content = new Array ( "purchase_tab_content_home", "purchase_tab_content_view" );

function BuyIFrame_TabClick (id, imgSrc, contentId){
	var content_type = 'purchase';
	
	if( contentId.search(/view/i) > -1 )
	{
		BuyIFrame_CreateFinalOptionsList ( 'purchase_tab_content_list' );
	}
	
	BuyIFrame_ResetTabs( content_type );	

	var elem = window.frames['ifrm_tertiary_content'].document.getElementById ( id );	
	elem.src = eval ( imgSrc + ".src" );
	
	var content_elem = window.frames['ifrm_tertiary_content'].document.getElementById ( contentId );
	content_elem.style.display = 'block';
}

function BuyIFrame_ResetTabs ( type ){
	var tab_images;
	var tabs;
	var tab_content;

	if( type == 'purchase' )
	{
		tab_images = purchase_tab_images;
		tabs = purchase_tabs;
		tab_content = purchase_tab_content;
	}
	
	for (var i = 0; i < tab_images.length; i++ )
		{
			var elem = window.frames['ifrm_tertiary_content'].document.getElementById ( tab_images[i].toString( ) );	
			elem.src = eval ( tabs[i].toString( ) + "_off.src" );
			
			var content_elem = window.frames['ifrm_tertiary_content'].document.getElementById ( tab_content[i].toString( ) );	
			content_elem.style.display = 'none';
		}
}
	
function BuyIFrame_GlossaryCategoryClick ( index ){
	var glossary_categories = window.frames['ifrm_tertiary_content'].document.getElementById ( 'hidTerms' ).value.toString( ).split( '|' );	
	//var glossary_categories = new Array ( "1 Month Visit", "11 Month Visit", "5 Month Visit", "Architectural Design (Elevation)", "Closing", "Closing Costs", "Closing Ducuments", "Conventional Mortgage", "Credit Report", "Customer Walk Thru", "CWM", "Earnest money", "FHA (Federal Housing Administration)", "Home Delivery", "Internal Acceptance", "Lot", "Master-planned Community", "Mortgage", "Mortgage Insurance", "Options", "PDO", "QPR 3", "QPR 8", "Rough-in Plumbing", "Sales Contract", "Spec Home", "Standard Features", "Title", "Title Company", "Underwritting", "VA (Veterans Administration)" );
	
	for( var i = 0; i < glossary_categories.length; i++ )
	{
		var category_link = window.frames['ifrm_tertiary_content'].document.getElementById ( 'glossary_category_' + i.toString( ) );
		var tmp_text = category_link.innerHTML.toString();
		
		var desc_container = window.frames['ifrm_tertiary_content'].document.getElementById ( 'glossary_category_description_' + i.toString( ) );
		
		if(i == index)
		{
			category_link.className = 'active';
			category_link.innerHTML = glossary_categories[i].toString( ) + "  >";
			
			desc_container.style.display = 'block';
		}
		else
		{
			category_link.className = '';		
			category_link.innerHTML = glossary_categories[i].toString( );
			
			desc_container.style.display = 'none';
		}
	}	
}

var purchase_categories = 
	new Array ( "On the outside", "On the inside", "In the kitchen", "In the bathroom", "Other considerations", "My lifestyle" );
	
	
function BuyIFrame_PurchaseCategoryClick ( index ){
	for( var i = 1; i < 7; i++ )
	{
		var category_link = window.frames['ifrm_tertiary_content'].document.getElementById ( 'purchase_category_' + i.toString( ) );
		var tmp_text = category_link.innerHTML.toString();
		
		var options_container = window.frames['ifrm_tertiary_content'].document.getElementById ( 'purchase_options_' + i.toString( ) );
		
		if(i == index)
		{
			var str = category_link.innerHTML;
			var cleanStr = str.replace(/&gt;/gi,"")
			
			category_link.className = 'active';
			//category_link.innerHTML = purchase_categories[i-1].toString( ) + "  &gt;";
			category_link.innerHTML = cleanStr  + "  &gt;";
			
			options_container.style.display = 'block';
		}
		else
		{
			var str = category_link.innerHTML;
			var cleanStr = str.replace(/&gt;/gi,"")
			
			category_link.className = '';		
			//category_link.innerHTML = purchase_categories[i-1].toString( );
			category_link.innerHTML = cleanStr;
			
			options_container.style.display = 'none';
		}
	}	
}


var popup_body = '';
function BuyIFrame_CreateFinalOptionsList ( contentId ){
	var purchase_options_1 = "";
	var purchase_options_2 = "";
	var purchase_options_3 = "";
	var purchase_options_4 = "";
	var purchase_options_5 = "";
	var purchase_options_6 = "";

	//loop through all sections
	for( var i = 1; i < 7; i++ )
	{
		//get the number of options in selected section
		var limit = parseInt( window.frames['ifrm_tertiary_content'].document.getElementById ( 'hidden_purchase_options_' + i.toString( ) ).value );
		var values = "";
		//loop through individual options and populate strings
		for( var j = 1; j < limit+1; j++ )
		{
			var chk = window.frames['ifrm_tertiary_content'].document.getElementById ( 'purchase_options_' + i.toString( ) + '_' + j.toString( ) );		
			if( chk.checked ) 
			{
				 values += chk.value.toString( ) + "|";
			} 
		}		
		
		//assign appropriate values to the appropriate variable
		switch( i )
		{
			case 1:
			  purchase_options_1 = values.substring(0, values.length-1);
			  break;    
			case 2:
			  purchase_options_2 = values.substring(0, values.length-1);
			  break;
			case 3:
			  purchase_options_3 = values.substring(0, values.length-1);
			  break;
			case 4:
			  purchase_options_4 = values.substring(0, values.length-1);
			  break;
			case 5:
			  purchase_options_5 = values.substring(0, values.length-1);
			  break;
			case 6:
			  purchase_options_6 = values.substring(0, values.length-1);
			  break;		  
		}		
	}		
	
	//get div container for the final list
	var content_elem = window.frames['ifrm_tertiary_content'].document.getElementById ( contentId );	
	var content_body = "<div id=\"purchase_final_list\" width=100% style=\"overflow:auto;height:215px;margin-top: 15px; padding-left: 5px;\">";
	var elem_body = "<table width=100% cellpadding=2 cellspacing=1><tr><td colspan=2><b>Print your personalized list and bring it with you when you visit Trilogy.</b></td></tr>";
	//loop through values
	for( i = 0; i < purchase_categories.length; i++ )
	{
		elem_body += "<tr><td width=35% valign=top><b>" + purchase_categories[i].toString( ) + "</b></td>";
		elem_body += "<td width=65% valign=top><ul>";
		var values = eval( "purchase_options_" + parseInt( i+1 ).toString( ) );
		var values_array = values.split( "|" );
		if( values_array.length > 0 )
		{
			var ctr = 0;
			for( var j = 0; j < values_array.length; j++ )
			{
				if( values_array[j].toString( ) != "" )
				{
					ctr++;
					elem_body += "<li>" + values_array[j].toString( ) + "</li>";
				}
			}
			
			if( ctr == 0 )
			{
				elem_body += "<li>no option selected</li>";
			}
		}
		else
		{
			elem_body += "<li>no option selected</li>";
		}
		elem_body += "</ul></td></tr>";
	}
	elem_body += "</table>";	
	
	popup_body = elem_body;	
	
	//add button for print
	//elem_body += "";
	
	content_elem.innerHTML = content_body + elem_body + "</div>";
}

function BuyIFrame_PrintFinalPurchaseList( ){
	var print_window= window.open("", "PrintWindow",
	"width=600,height=600,status=no,toolbar=no,menubar=no,scrollbars=1");

	// open document for further output
	print_window.document.open();

	// create document
	print_window.document.write("<html><head><title>On-the-fly");
	print_window.document.write("</title></head><body><center>");
	print_window.document.write(popup_body);
	print_window.document.write("<input type=\"button\" value=\"PRINT LIST\" onclick=\"javascript:window.print();window.close();\" />");
	print_window.document.write("<center></body></html>");

	// close the document - (not the window!)
	print_window.document.close();

}