/*
ExclusiveSoft - Helper functions
version 2.3
*/

function CreateFrame(strTitle, strContent, strWidth, strHeight){
	var oWnd;

	var strTxt = "";
	var fScroll = 1;
	var iScrollbar = 16;

	var oScr = window.screen;
	var iWidth = parseInt(strWidth), iHeight = parseInt(strHeight);
	var ihDelta = oScr.availWidth - iWidth;
	var ivDelta = oScr.availHeight - iHeight;

	if( iWidth ){
		if( ivDelta < 0  )
			iWidth+= iScrollbar;
		else
			fScroll = 0;

		if( ihDelta > 0 )
			strTxt = "width=" + iWidth + ", left=" + ihDelta/2 + ", ";
	}

	if( iHeight ){
		if( ihDelta < 0  ){
			iHeight+= iScrollbar;
			fScroll = 1;
		}
		if( ivDelta > 0 )
			strTxt+= "height=" + iHeight + ", top=" + ivDelta/2 + ", ";
	}

	strTxt+= "directories=0, fullscreen=0, resizable=0, toolbar=0, status=0, menubar=0, scrollbars=" + fScroll;

	oWnd = window.open("", "_blank", strTxt);

	strTxt = '<html>\n<head>\n';
	strTxt+= '<title>'+ strTitle +'</title>\n';
	strTxt+= '</head>\n<body style="margin: 0;">\n';
	strTxt+= strContent;
	strTxt+= '\n</body>\n</html>';
	oWnd.document.writeln(strTxt)
	return false;
}

function ShowImage(strTitle, strImage, iWidth, iHeight)
{

	strTxt = '<img src="' + strImage +'" alt="' + strTitle + '">\n';
	return CreateFrame(strTitle, strTxt, iWidth, iHeight);
}

function ShowFlash(strTitle, strSwf, iWidth, iHeight){
	var strTxt = '', strDims = '';

	if( iWidth )
		strDims = 'width="' + iWidth + '" ';
	else
		strDims = 'width="100%" ';

	if( iHeight )
		strDims+= 'height="' + iHeight + '" ';
	else
		strDims+= 'height="100%" ';

	strTxt = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	strTxt+= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
	strTxt+= strDims + 'id="swf0">\n';
	strTxt+= ' <param name="movie" value="' + strSwf + '">\n';
	strTxt+= ' <param name="menu" value="true">\n';
	strTxt+= ' <param name="quality" value="high">\n';
	strTxt+= ' <embed src="' + strSwf + '" menu="true" quality="high"';
	strTxt+= strDims + 'name="swf0"';
	strTxt+= ' type="application/x-shockwave-flash"';
	strTxt+= ' pluginspace="http://www.macromedia.com/go/getflashplayer">\n';
	strTxt+= ' </embed>\n';
	strTxt+= '</object>';

	return CreateFrame(strTitle, strTxt, iWidth, iHeight);
}

function getFileType(strFileName){
	if( strFileName.length < 1 )
		return null;
	var iPos = strFileName.lastIndexOf(".");
	if( iPos == -1 )
		return "";
	iPos++;
	return strFileName.substr(iPos).toLowerCase();
}

function ShowFile(strTitle, strFileName, iWidth, iHeight){
	var strType;
	strType = getFileType(strFileName);
	if( strType == "swf" )
		return ShowFlash(strTitle, strFileName, iWidth, iHeight);
	else
		return ShowImage(strTitle, strFileName, iWidth, iHeight);
}

function setPageTitle(strTitle){
	top.document.title = strTitle;
}

function SubscribeVisitor(){
	document.all['subscribe'].submit();
	return false;
}

function WriteDpSection(
	strCaption,
	strPath,
	arrTitles,
	arrImages,
	arrWidths,
	arrHeights
){
	var i;
	var strTail, strArgs;

	strPath.replace("\\", "/");
	i = strPath.length-1;
	strTail = strPath.charAt(i);

	if( strTail != "/" )
		strPath+= "/";

	document.writeln('<li>' + strCaption + '<p class="Compact">');
	i = 0;
	while(i < arrTitles.length)
	{
    strArgs = '&nbsp;<a href="" onClick="return ShowFile(';
		strArgs+= "'"+ arrTitles[i] + "', '" +  strPath + arrImages[i] + "'";
		strArgs+= ')">';
		strArgs+= '<img src="'+ strPath + 'tn_' + arrImages[i] + '" ';
		strArgs+= 'width="'+ arrWidths[i] + '" ';
		strArgs+= 'height="' + arrHeights[i] + '" ';
		strArgs+= 'class="Preview" alt="' + arrTitles[i] + '"></a>';
		document.writeln(strArgs);
		i++;
	}
	document.writeln('</p></li>');
}


function WriteDpSectionText(
	strCaption,
	strPath,
	arrTitles,
	arrImages,
	arrWidths,
	arrHeights
){
	var i;
	var strTail, strArgs;

	strPath.replace("\\", "/");
	i = strPath.length-1;
	strTail = strPath.charAt(i);

	if( strTail != "/" )
		strPath+= "/";

	document.writeln('<li>' + strCaption + '<p class="Compact">');
	i = 0;
	while(i < arrTitles.length)
	{
    strArgs = '&nbsp;<a href="" onClick="return ShowFile(';
		strArgs+= "'" + arrTitles[i] + "', '" + strPath + arrImages[i] + "', ";
		strArgs+= arrWidths[i] + ", " + arrHeights[i] + ');">';
		strArgs+= arrTitles[i] + '</a>';
		document.writeln(strArgs);
		i++;
	}
	document.writeln('</p></li>');
}

function WriteShSection(
	strHeader,
	arrTable,
	cColumns
){
	var strLine;
	var i, j;
	var nRowLength;

	if( strHeader.length > 0 ){
		strLine = '<tr>\n<td class="ColHeader" colspan="';
		strLine+= cColumns +'">'+ strHeader +'</td>\n</tr>';
		document.writeln(strLine);
	}
	for( i = 0; i < arrTable.length; i++ ){
		document.writeln('<tr>');
		strLine = '<td class="RowHeader">'+ arrTable[i][0] +'</td>';
		document.writeln(strLine);
		nRowLength = arrTable[i].length;
		for( j = 1; j < nRowLength; j++){
			strLine = '<td>'+ arrTable[i][j] +'</td>';
			document.writeln(strLine);
		}
		nRowLength--;
		for(; j < cColumns; j++){
			strLine = '<td>'+ arrTable[i][nRowLength] +'</td>';
			document.writeln(strLine);
		}
		document.writeln('</tr>');
	}
}
