/* text */
if( currLang == "es" ){
	ALERT_TXT_TCA_NUMBER = "Seleccione un n&#250;mero TCA.";	//número
	ALERT_TXT_TTMAC_NUMBER = "Seleccione un n&#250;mero TTMAC.";
	ALERT_TXT_INSTALL_CATEGORY = "Seleccione una Categora de instalacion.";	//instalación.
	RESULTS_HEADER = "Resultados de b&#250;squeda";
	RESULTS_SUBTITLE_TCA = "de N&#250;mero TCA ";
	RESULTS_SUBTITLE_TTMAC = "de N&#250;mero TTMAC ";
	RESULTS_SUBTITLE_CAT = "de ";
	RESULTS_SUBTITLE_ALL = "de Todas las especificaciones";
	RESULTS_TCA_NUMBER = "N&#250;mero TCA";
	RESULTS_TTMAC_NUMBER = "N&#250;mero TTMAC";
	RESULTS_INSTALL_CAT = "Categora de Instalacion: ";
	RESULTS_DOWNLOADS = "Descargas: ";
	
	NO_MATCHES_FOUND = "Lo siento, no se encontraron resultados a su búsqueda. Por favor int&#233;ntelo nuevamente.";
	FILETYPES_NOTICE = "Para ver archivos PDF, descargar e instalar la &#250;ltima versi&#243;n de <a href=\"http://www.adobe.com/products/acrobat/readstep2.html\" target=\"_blank\">Adobe&reg; Reader&reg;</a>."

	var SHOW_DETAILS = '<img src="/images/toggle_plus.gif" width="16" height="11" border="0" alt="Muestre Los Detalles" />Muestre Los Detalles';
	var HIDE_DETAILS = '<img src="/images/toggle_minus.gif" width="16" height="11" border="0" alt="Oculte Los Detalles" />Oculte Los Detalles';
}
else{
	var ALERT_TXT_TCA_NUMBER = "Please select a TCA Number.";
	var ALERT_TXT_TTMAC_NUMBER = "Please select a TTMAC Number.";
	var ALERT_TXT_INSTALL_CATEGORY = "Please select an Installation Category.";
	var RESULTS_HEADER = "Search Results";
	var RESULTS_SUBTITLE_TCA = "for TCA Number ";
	var RESULTS_SUBTITLE_TTMAC = "for TTMAC Number ";
	var RESULTS_SUBTITLE_CAT = "for ";
	var RESULTS_SUBTITLE_ALL = "for All Specifications";
	var RESULTS_TCA_NUMBER = "TCA Number";
	var RESULTS_TTMAC_NUMBER = "TTMAC Number";
	var RESULTS_INSTALL_CAT = "Installation Category: ";
	var RESULTS_DOWNLOADS = "Downloads: ";

	var NO_MATCHES_FOUND = "Sorry, no matches were found. Please try again.";
	var FILETYPES_NOTICE = 'To view PDF files, download and install the latest <a href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank">Adobe&reg; Reader&reg;</a>.';
	
	var SHOW_DETAILS = '<img src="/images/toggle_plus.gif" width="16" height="11" border="0" alt="Show Details" />Show Details';
	var HIDE_DETAILS = '<img src="/images/toggle_minus.gif" width="16" height="11" border="0" alt="Hide Details" />Hide Details';
}

var archSpecWizardForm = document.forms.archSpecWizard;
var tca_select = archSpecWizardForm.elements.tca_number;
var ttmac_select = archSpecWizardForm.elements.ttmac_number;
var tca_options = new Array();
var ttmac_options = new Array();
var tca_hash = new Array();
var ttmac_hash = new Array();

/* constructor 
	dwg not used, but left-in for backwards compatability
*/
function ArchSpec( nodeID, title, tca_number, ttmac_number, install_category, pdf, pdf2, dwg, pdfSize, pdf2Size, dwgSize, jpg, jpgSize, path ){
	this.nodeID = nodeID;
	this.title = title;
	this.tca_number = tca_number;
	this.ttmac_number = ttmac_number;
	this.install_category = install_category;
	this.pdf = pdf;
	this.pdf2 = pdf2;
	this.dwg = dwg;
	this.jpg = jpg;
	this.pdfSize = pdfSize;
	this.pdf2Size = pdf2Size;
	this.dwgSize = dwgSize;
	this.jpgSize = jpgSize;
	this.path = path;
	
	
	if( tca_number.length > 0 && tca_hash[tca_number] == null ){
		tca_options[tca_options.length] = tca_hash[tca_number] = tca_number;	
	}
	if( ttmac_number.length > 0 && ttmac_hash[ttmac_number] == null ){
		ttmac_options[ttmac_options.length] = ttmac_hash[ttmac_number] = ttmac_number;
	}
	this.index = ArchSpec.all.length;
	ArchSpec.all[ this.index ] = this;
	
}

ArchSpec.searchBy = QueryString("searchBy");
ArchSpec.searchValue = QueryString("value");
ArchSpec.all = new Array();


/* go-go-gadget functions */
ArchSpec.find = function( what ){
	if( what == "all" ){
		location.href = "?searchBy=all" + qsLangUser;
	}
	else{
		var selectObj = archSpecWizardForm[what];
		var alertTxt = eval( "ALERT_TXT_" + what.toUpperCase() );
		if( selectObj.selectedIndex == 0 ){  //validate selection
			alert( alertTxt );
			return false;
		}
		location.href = "?searchBy=" + what + "&value=" + selectObj.options[selectObj.selectedIndex].value + qsLangUser;
	}
}



function optionSort( opt1, opt2 ){
	return (opt1.value < opt2.value)? -1 : 1;
}
ArchSpec.writeSelectOptions = function(){
	tca_options.sort();
	tca_select.options.length = 1;
	for( var i=0; i<tca_options.length; i++ ){
		tca_select.options[tca_select.options.length] = new Option(tca_options[i],tca_options[i]);
	}
	
	ttmac_options.sort();
	ttmac_select.options.length = 1;
	for( var i=0; i<ttmac_options.length; i++ ){
		ttmac_select.options[ttmac_select.options.length] = new Option(ttmac_options[i],ttmac_options[i]);
	}
}
ArchSpec.writeResults = function(){
	ArchSpec.writeSelectOptions();
	if( ArchSpec.searchBy ){
		var count = 0;
		var html = ArchSpec.getResultHeadHtml();
		for( var i=0; i<ArchSpec.all.length; i++ ){
			if( ArchSpec.all[i].isMatch() ){
				count++;
				html += ArchSpec.all[i].toHtml();
			}
		}
		html += ArchSpec.getResultFootHtml(count);
		document.getElementById("archSpecResultsDiv").innerHTML = html;
	}
}
ArchSpec.getResultHeadHtml = function(){
	var subtitle;
	switch( ArchSpec.searchBy ){
		case "tca_number" : subtitle = RESULTS_SUBTITLE_TCA + unescape(ArchSpec.searchValue); break;
		case "ttmac_number" : subtitle = RESULTS_SUBTITLE_TTMAC + unescape(ArchSpec.searchValue); break;
		case "install_category" : 
			subtitle = "";
			var opts = archSpecWizardForm.elements.install_category.options;
			for( var i in opts ){
				var o = opts[i];
				if( o && o.value == ArchSpec.searchValue ){
					subtitle = RESULTS_SUBTITLE_CAT + o.text;
					break;
				}
			}
			break;
		default: subtitle = RESULTS_SUBTITLE_ALL;
	}

	return ''
	+ '<p><br></p>' 
	+ '<p class="head">' + RESULTS_HEADER + '<br>' 
	+ '<span class="subtitle">' + subtitle + '</span><br></p>';
}
ArchSpec.prototype.toHtml = function(){
	var  s = '<p class="subhead">' + this.title + '</p>'
	s += '<p>';
	if( this.tca_number ) s += RESULTS_TCA_NUMBER + ': ' + this.tca_number;
	if( this.ttmac_number ){
		s += ' | ' + RESULTS_TTMAC_NUMBER + ': ' + this.ttmac_number + '<br>'
	}
	else{
		s += '<br>';
	}
				
	if( ArchSpec.searchBy != "install_category" ){
		s+= RESULTS_INSTALL_CAT + installCats[this.install_category] + '<br>';
	}
	if( this.path != '' ){
		s += '<a href="' + this.path + '" onclick="ArchSpec.showDetails(this,' + this.index + '); return false;">' + SHOW_DETAILS + '</a> | '
	}
	if( this.pdf != "" || this.pdf2 != "" || this.jpg != "" ) s+= RESULTS_DOWNLOADS;
	if( this.pdf != "" ) s+= '<a href="' + this.pdf + '" target="_blank">PDF</a> <span class="file_data">(' + this.pdfSize + ')</span> ';
	if( this.pdf2 != "" ) s+= '<a href="' + this.pdf2 + '" target="_blank">PDF</a> <span class="file_data">(' + this.pdf2Size + ')</span> ';
	if( this.dwg != "" ) s+= '<a href="' + this.dwg + '" target="_blank">DWG</a> <span class="file_data">(' + this.dwgSize + ')</span> ';
	//if( this.jpg != "" ) s+= '<a href="' + this.jpg + '" target="_blank">JPG</a> <span class="file_data">(' + this.jpgSize + ')</span> ';
	
	s += '</p>'
	+ '<p><img src="/images/pixel_dddbd2.gif" width="543" height="1" border="0" alt="" /></p>'
	+ '<div id="archSpecDetails_' + this.index + '" style="display:none"></div>';
	return s;
}



ArchSpec.getResultFootHtml = function(found){		
	if( ! found ){
		return '<p><img src="/images/pixel_dddbd2.gif" width="543" height="1" border="0" alt="" /></p><p>' + NO_MATCHES_FOUND + '</p>';
	}
	else{
		return '<p class="small">' + FILETYPES_NOTICE + '</p>';
	}
}

ArchSpec.prototype.isMatch = function(){
	return ArchSpec.searchBy != null && ( ArchSpec.searchBy == "all" || this[ArchSpec.searchBy] == ArchSpec.searchValue );
}

function resetOther( what ){
	var selectObj = archSpecWizardForm[what];
	selectObj.selectedIndex = 0;
}

ArchSpec.showDetails = function( a, index ){
	
	
	var spec = ArchSpec.all[index];
	
	if( spec.isOpen ){
		spec.hideDetails();
	}
	else{
		if( ArchSpec.currSpec && spec != ArchSpec.currSpec ){
			ArchSpec.currSpec.hideDetails();	
		}
		ArchSpec.currSpec = spec;
		spec.showDetails(a);
	}
}
ArchSpec.prototype.showDetails = function(a){
	this.link = a;
	this.div = document.getElementById('archSpecDetails_' + this.index);
	
	this.isOpen = true;
	this.link.innerHTML = HIDE_DETAILS;
	this.div.style.display = 'block';
	this.div.innerHTML = '<iframe id="specDetail" src="' + this.path + '" class="archSpecDetail" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" />';
}
ArchSpec.prototype.hideDetails = function(){
	this.link.innerHTML = SHOW_DETAILS;
	this.div.style.display = 'none';
	this.isOpen = false;
	this.div.innerHTML = '';
}

var installCats = new Array();
if( currLang == "es" ){
	installCats['floors_ext_patios_walkways'] = 'Pisos, Exteriores - Patios y pasillos'
	installCats['floors_ext_roof_deck_membrane'] = 'Pisos, Exteriores - Cubierta de techo, Membrana'
	installCats['floors_ext_balcony_deck'] = 'Pisos, Exteriores - Cubierta de balc&#243;n'
	installCats['floors_int_concrete_subfloor'] = 'Pisos, Interiores - Substratos de concreto'
	installCats['floors_int_radiant_heat_concrete'] = 'Pisos, Interiores - Calefacci&#243;n radiante sobre substratos de concreto'
	installCats['floors_int_waterproof_membrane'] = 'Pisos, Interiores - Membrana impermeable'
	installCats['floors_int_wood_subfloor'] = 'Pisos, Interiores - Substratos de madera'
	installCats['floors_int_radiant_heat_wood'] = 'Pisos, Interiores - Calefacci&#243;n radiante sobre Substratos de madera'
	installCats['floors_int_osb_subfloor'] = 'Pisos, Interiores - Substratos de conglomerado de madera (OSB)'
	installCats['floors_int_sound_control'] = 'Pisos, Interiores - Control de sonido'
	installCats['walls_ext_masonry'] = 'Paredes, Exteriores - Alba&#241;iler&#237;a'
	installCats['walls_int_masonry'] = 'Paredes, Interiores - Alba&#241;iler&#237;a'
	installCats['walls_int_solid_backing'] = 'Paredes, Interiores - Refuerzo s&#243;lido'
	installCats['walls_int_masonry_concrete'] = 'Paredes, Interiores - Alba&#241;iler&#237;a o concreto'
	installCats['walls_int_wood_studs_furring'] = 'Paredes, Interiores - Montantes o vigas de madera'
	installCats['walls_int_metal_studs'] = 'Paredes, Interiores -  Montantes de metal'
	installCats['walls_int_wood_metal_studs'] = 'Paredes, Interiores -  Montantes de madera o metal'
	installCats['walls_int_cementitious_backer'] = 'Paredes, Interiores - Unidad de base de cemento'
	installCats['walls_int_cementitious_coated'] = 'Paredes, Interiores - Base de espuma revestida en cemento'
	installCats['walls_int_fire_wood_metal_studs'] = 'Paredes, Interiores a prueba de incendio -  Montantes de madera o metal'
	installCats['bathtub_wood_metal_studs'] = 'Paredes de ba&#241;eras -  Montantes de madera o metal'
	installCats['shower_wood_metal_studs'] = 'Receptores de ducha, Paredes -  Montantes de madera o metal'
	installCats['steam_rooms_membrane'] = 'Saunas, Membrana'
	installCats['ceilings_soffits'] = 'Techos, cielorraso'
	installCats['countertops_wood'] = 'Encimeras, Base de madera'
	installCats['tile_tubs_fountains_curbs'] = 'Ba&#241;eras, fuentes y bordes azulejados'
	installCats['swimming_pools'] = 'Piscinas'
	installCats['rennovation'] = 'Renovaci&#243;n'
}
else{
	installCats['floors_ext_patios_walkways'] = 'Floors, Exterior - Patios and Walkways'
	installCats['floors_ext_roof_deck_membrane'] = 'Floors, Exterior - Roof Deck, Membrane'
	installCats['floors_ext_balcony_deck'] = 'Floors, Exterior - Balcony Deck'
	installCats['floors_int_concrete_subfloor'] = 'Floors, Interior - Concrete Subfloor'
	installCats['floors_int_radiant_heat_concrete'] = 'Floors, Interior - Radiant Heat on Concrete Subfloor'
	installCats['floors_int_waterproof_membrane'] = 'Floors, Interior - Waterproof Membrane'
	installCats['floors_int_wood_subfloor'] = 'Floors, Interior - Wood Subfloor'
	installCats['floors_int_radiant_heat_wood'] = 'Floors, Interior - Radiant Heat Wood Subfloor'
	installCats['floors_int_osb_subfloor'] = 'Floors, Interior - OSB Subfloor'
	installCats['floors_int_sound_control'] = 'Floors, Interior - Sound Control'
	installCats['walls_ext_masonry'] = 'Walls, Exterior - Masonry'
	installCats['walls_int_masonry'] = 'Walls, Interior - Masonry'
	installCats['walls_int_solid_backing'] = 'Walls, Interior - Solid Backing'
	installCats['walls_int_masonry_concrete'] = 'Walls, Interior - Masonry or Concrete'
	installCats['walls_int_wood_studs_furring'] = 'Walls, Interior - Wood Studs or Furring'
	installCats['walls_int_metal_studs'] = 'Walls, Interior - Metal Studs'
	installCats['walls_int_wood_metal_studs'] = 'Walls, Interior - Wood or Metal Studs'
	installCats['walls_int_cementitious_backer'] = 'Walls, Interior - Cementitious Backer Unit'
	installCats['walls_int_cementitious_coated'] = 'Walls, Interior - Cementitious Coated Foam Backer Board'
	installCats['walls_int_fire_wood_metal_studs'] = 'Walls, Interior Fire Rated - Wood or Metal Studs'
	installCats['bathtub_wood_metal_studs'] = 'Bathtub Walls - Wood or Metal Studs'
	installCats['shower_wood_metal_studs'] = 'Shower Receptors, Walls - Wood or Metal Studs'
	installCats['steam_rooms_membrane'] = 'Steam Rooms, Membrane'
	installCats['ceilings_soffits'] = 'Ceilings, Soffits'
	installCats['countertops_wood'] = 'Countertops, Wood Base'
	installCats['tile_tubs_fountains_curbs'] = 'Tile Tubs, Fountains and Curbs'
	installCats['swimming_pools'] = 'Swimming Pools'
	installCats['rennovation'] = 'Renovation'
}
