/*
HyipMonitor - 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 onContentLoaded(){
	ExploTree(document.body);
}

function Init(){
	if(document.addEventListener)
		document.addEventListener("DOMContentLoaded", onContentLoaded, false);
	else if( document.readyState )
		document.onreadystatechange = function(){
			if( this.readyState == "complete" )
				 onContentLoaded();
		}
}


function hyipCreateLegend(arrValues){
	var arrTitles = ["Started", "Minimum", "Profit/Plans", "Referral", "Status"];
	var arrStatus = ["paying", "not paying", "problems"];
	var arrStyles = ["Paying", "NotPaying", "Problems", "Other"];

	var cItems = arrTitles.length;
	var sTxt;
	var i;

	sTxt = '<table class="Legend"><tr class="Title">';
	for( i = 0; i < cItems; i++ )
		sTxt+= '<td>' + arrTitles[i] + '</td>';
	sTxt+= '</tr><tr class="Value">';

	var cStatus = arrStatus.length;
	var sStatus = arrValues[cItems-1].toLowerCase();
	i = 0;
	while( (i < cStatus) && ( sStatus != arrStatus[i]) )
		i++;

	arrValues[cItems-1] = '<span class="' + arrStyles[i] + '">' + sStatus + '</span>';

	for( i = 0; i < cItems; i++ )
		sTxt+= '<td>' + arrValues[i] + '</td>';
	sTxt+= 	'</tr></table>';

	document.writeln(sTxt);
}

function hyipCreateCell(nVal){
	sStyle = ( nVal < 0 ) ? "Negative" : "Positive";
	return '<td class="' + sStyle + '">' + nVal.toString() + '%</td>';
}

function hyipCreateStats(sCaption, nYear, arrReturns){
	var arrMonths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	var cItems = 12;
	var sTxt;
	var i, j;
	var nTotal;
	var iRet;

	sTxt = '<table class="Stats">'
	if( sCaption && sCaption.length )
		sTxt+=	'<caption>' + sCaption + '</caption>';
	sTxt+= '<tr><th>Year</th>';
	for( i = 0; i < cItems; i++ )
		sTxt+= '<th>' + arrMonths[i] + '</th>';
	sTxt+= '<th>Total</th></tr>';
	for( i = 0; i < arrReturns.length; i++ ){
		sTxt+= 	'<tr><td class="Caption">';
		sTxt+= nYear.toString();
		sTxt+= '</td>';
		nYear++;

		nTotal = 0;
		for( j = 0; j < cItems; j++ ){
			iRet = arrReturns[i][j];
			if( isNaN(iRet) || (iRet.length == 0) )
				sTxt+= '<td> - </td>';
			else{
				nTotal+= iRet;
				sTxt+= hyipCreateCell(iRet);
			}
		}
		nTotal = nTotal.toFixed(2);
		sTxt+= hyipCreateCell(nTotal);
		sTxt+= 	'</tr>';
	}
	sTxt+= '</table>';
	document.writeln(sTxt);
	return;
}
