var paramsName = [];
var pageName = [];
function getAddress()
{
	var fullPath = window.location.pathname;
	for( var i = 1; i<=fullPath.length; i++){
		var  oneChar = fullPath.charAt(fullPath.length-i);
		if (oneChar == "\/" || oneChar == "\\"){
			pageName =  fullPath.substr(fullPath.length-i+1);
			break;
		}
	}

	var fullSearch 	= unescape( document.location.search.substr(1) );

	if( !fullSearch && pageName == 'specifications.html' )
	{
		document.location.href = 'specifications.html?name=flex_c_trac';
	}

	if(fullSearch)
	{
		var allParams 	= fullSearch.split('&');
		var paramsArray = [];

		for(var i=0; i<allParams.length; i++){
			paramsArray[i]	= allParams[i].split('=');
			paramsName[i]	= paramsArray[i][0];

			switch( paramsArray[i][0] )
			{
				case 'name':
								params.name = paramsArray[i][1];
								break;
			}
		}
		isParamsCorrect();		
	}
}

function isParamsCorrect()
{
	var flag = '';
	for(var i=0; i<paramsName.length; i++){

		switch(paramsName[i])
		{
			case 'name':
							for( var propObj in specifications )
							{
								if(propObj == params['name'] )
									flag = '1';
							}
							break;
		}
	}

	if( flag != '1' )
//		alert('error');
		document.location.replace("404.html");			
}

function createFrame(){
//	for example: content/specifications/3x58.html
	var frame = 'content/specifications/' + params.name + '.html';
	window.frames.iframe.location.href = frame;
}


/*
 * -----------------------------------------------------------------
 * Creates list of products and show sublist of current - ?topic=...
 * -----------------------------------------------------------------
*/
function generateSimpleBox(){
	var out = '';

	out += '<table width="180" border="0" cellspacing="0" cellpadding="0" class="boxBg">\n';
	out += '<tr>\n';
	out += '	<td valign="top" width="12" height="14"><img src="img/box_bg_corner_left_top.gif" width="12" height="14"></td>\n';
	out += '	<td class="boxBgTop" width="100%"><img src="img/spacer.gif" width="1" height="1"></td>\n';
	out += '	<td valign="top" width="8" height="14"><img src="img/box_bg_corner_right_top.gif" width="8" height="14"></td>\n';
	out += '</tr>\n';
	out += '<tr>\n';
	out += '	<td class="boxBgLeft" width="12" style="background-image: url(img/box_bg_corner_left.gif)"><img src="img/spacer.gif" width="12" height="1"></td>\n';
	out += '	<td class="boxBgContent" valign="top">\n';
	out += '		<!-- == Box ================== -->\n';
	out += '		<ul class="boxList">\n';

	var header = 'Architectural Specs';
	out += '		<li class="head">\n';
	out += '		<div class="boxHeader" style="cursor:auto"><b>' + header + '</b></div>\n';
	out += '			<ul>\n';

	for (var prop in specifications)
	{
		out += '			<li><a href="specifications.html?name=' + prop + '">' + specifications[prop] + '</a></li>';
	}
	out += '			</ul>';
	out += '		</li>';
	out += '		</ul>';
	/**
	  * 
	  */
	out += '		<ul class="boxList">\n';

	for (var prop in products)
	{
		var header = products[prop][0];
		var items  = products[prop][1];
		out += '		<li class="head">\n';
		out += '		<div onClick="showList(this)" class="boxHeader"><b>' + header + '</b></div>\n';

		out += ( prop == params.topic )
							?'<ul>\n'
							:'<ul style="display:none">\n';

		for( var propItems in items){
			var  label	= items[propItems];
			var  url	= 'products.html?topic=' + prop + '&name=' + propItems.replace('name_','') + '&mode=simple';
			out += '			<li><a href="' + url + '">' + label + '</a></li>';
		}

		out += '			</ul>';
		out += '		</li>';
	}
	out += '		</ul>';
	/**
	  *
	  */
	out += '		<!-- = /Box ================== -->';
	out += '	</td>';
	out += '	<td class="boxBgRight" width="8" style="background-image: url(img/box_bg_corner_right.gif)"><img src="img/spacer.gif" width="1" height="170"></td>';
	out += '</tr>';
	out += '<tr>';
	out += '	<td valign="top" width="12" height="8"><img src="img/box_bg_corner_left_bottom.gif" width="12" height="8"></td>';
	out += '	<td class="boxBgBottom"><img src="img/spacer.gif" width="1" height="1"></td>';
	out += '	<td valign="top" width="8" height="8"><img src="img/box_bg_corner_right_bottom.gif" width="8" height="8"></td>';
	out += '</tr>';
	out += '</table>';
	document.getElementById('jsBoxMenu').innerHTML = out;
}

/*
 * -----------------------------------------------------------------
 * Shows and hides list of products
 * -----------------------------------------------------------------
*/

function generateLinks()
{

//	files/architectural/flex_c_trac.pdf
	var pdfSrc = 'files/specifications/' + params.name + '.pdf';
	document.getElementById('jsLinkPdf').href = pdfSrc;
	document.getElementById('jsLinkPdf').target = '_blank';


}

getAddress();
//window.document.onload = buildOutput;
function buildOutput()
{
	createFrame();
	generateSimpleBox();
	generateLinks();
}
/**
  * right menu extension
  */
function showList(el){
	while (el.nodeName.toUpperCase() != 'UL') {
		el = el.nextSibling;
	}
	var list = el;
	list.style.display = (list.style.display == 'none') ? 'block' : 'none' ;
}