var pageLoaded = false;
var ShowEmailCountLoaded = "0";

// GoToUrl(URL)
// PageLoaded()
// setSECLoaded()

function ShowLogin()
{
	var show_login = document.createTextNode("Show login");
	var hide_login = document.createTextNode("Hide login");
	var elem = document.getElementById('ShowLogin');
	var data = document.getElementById('LoginData');
	var sbox = document.getElementById('search_bottom_r');
	
	if (data.style.display == 'none')
	{
		data.style.display = 'block';
		sbox.style.display = 'none';
		elem.replaceChild(hide_login, elem.childNodes[0]);
	}
	else
	{
		data.style.display = 'none';
		sbox.style.display = 'block';
		elem.replaceChild(show_login, elem.childNodes[0]);
	}
}

function ShowHelp()
{
	var show_help = document.createTextNode("Show help");
	var hide_help = document.createTextNode("Hide help");
	var help = document.getElementById('help_on_search');
	
	if (help.style.display == 'none')
	{
		help.style.display = 'block';
		// elem.replaceChild(hide_login, elem.childNodes[0]);
	}
	else
	{
		help.style.display = 'none';
		// elem.replaceChild(show_login, elem.childNodes[0]);
	}
}

function CheckSearchForm()
{
	str = new String(document.forms['SearchForm'].q.value);
	
	// Trim whitespaces from the begin
	while (str.substr(0,1) == ' ')
		str = str.substr(1);
	
	// Trim whitespaces from the end
	while (str.substr(str.length-1) == ' ')
		str = str.substr(0, str.length-1);
	
	document.forms['SearchForm'].q.value = str;
	
	if (str.length <= 2)
	{
		alert("Search string has to be at least 3 characters long!");
		return false;
	}
	
	return true;
}

function ShowLength(From, To)
{
	To.value = From.value.length;
}

function setECLoaded()
{
	ShowEmailCountLoaded = "1";
};

function PageLoaded(Page)
{
	pageLoaded = true;
/*	ShowEmailCount = document.ShowEmailCount;
//	if (ShowEmailCountLoaded == "1" && Page == "results/inc_results.php")
	if (Page == "results/inc_results.php" && document.ShowEmailCount)
	{
		alert("JEI!");
	}
	else if (Page == "results/inc_results.php")
	{
		alert("DAMN!\nState: " + document.applets['ShowEmailCount'] + "\nPage: " + Page);
		setTimeout("PageLoaded('" + Page + "');", 2000);
	}
*/
}

function GoToUrl(URL)
{
	if (URL == "---" || URL == "" || URL.toUpperCase() == "UNDEFINED")
		return false;
	
	if (URL.substr(0,1) == 1)
	{
		win = window.open(URL.substr(2), "", "");
		win.focus();
	}
	else
		location.href = URL.substr(2);
	
	return true;
}


function ShowAd(Ad, Link)
{
	var win = window.open("", "Ad", "toolbars=0, scrollbars=1, resizable=1");
	
	sx = screen.width;
	sy = screen.height;
	hx = sx / 2; hy = sy / 2;
	win.outterwidth = sx; win.outterheight = sy;
	win.resizeTo(sx, sy-50);
	win.moveTo(0,0);
	
	win.document.write('<html>\n');
	win.document.write('<head>\n');
	win.document.write('<title>Finlandexports.com - Ad</title>\n');
	win.document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n');
	win.document.write('</head>\n');
	win.document.write('<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\n');
	win.document.write('<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">\n');
	win.document.write('<tr>\n');
	win.document.write('<td align="center" valign="middle" height="20">\n');
	win.document.write('<center>&laquo;&nbsp;<a href="javascript:window.close();" style="color: #000000; font: 11px Verdana, Arial Helvetica; text-decoration: none;">Close this window</a>&nbsp;&raquo;</center>\n');
	win.document.write('</td>\n');
	win.document.write('</tr>\n');
	win.document.write('<tr>\n');
	win.document.write('<td align="center" valign="middle">\n');
	win.document.write('<a href="' + Link + '" target="_blank">\n');
	win.document.write('<img src="' + Ad + '" border="0" />\n');
	win.document.write('</a>\n');
	win.document.write('</td>\n');
	win.document.write('</tr>\n');
	win.document.write('<table>\n');
	win.document.write('</body>\n');
	win.document.write('</html>\n');
	win.focus();
}


function ShowMedia(i,params) /* show some media */ {
	URL = '/compmed/'+i+'/media.html';
	if (params != null) 
		URL += "?"+params;
	window.open(
		URL,
		null,
    	'height=600,width=700,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes'
		);
	return false;
	}	
