function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		curtop += obj.offsetTop;
		if(!obj.offsetParent)
			break;
		obj = obj.offsetParent;
		}
	else if(obj.y) curtop += obj.y;
	return curtop;
}


function bannermyTimer(tmp_banner, bannerdelaytime_str, banner_imgs, bannercount, bannerstartimg)
{
	var banner = document.getElementById(tmp_banner).getElementsByTagName('img');
	var bannerdelaytime = bannerdelaytime_str.split(",");
	if ( bannercount > 0 )
	{
		bannerrotateBanner(tmp_banner);
		bannerstartimg = bannerstartimg + 1;
		if (bannerstartimg > banner_imgs) bannerstartimg = 1;
	}
	else bannercount = 1;
	var banner_t = setTimeout("bannermyTimer('" + tmp_banner + "', '" + bannerdelaytime_str + "', " + banner_imgs + ", " + bannercount + ", " + bannerstartimg + ")", Number(bannerdelaytime[bannerstartimg]));
}

function bannersetImagePositions(tmp_banner)
{
	var xpos = findPosX(document.getElementById(tmp_banner));
	var ypos = findPosY(document.getElementById(tmp_banner));
	var banner = document.getElementById(tmp_banner).getElementsByTagName('img');
	for (var i = 0; i < banner.length; i++)
	{
		banner[i].style.top = ypos;
		banner[i].style.left = xpos;
	}
}

function bannerrotateBanner(tmp_banner)
{
	var banner = document.getElementById(tmp_banner).getElementsByTagName('img');
	for (var i = 0; i < banner.length; i++)
	{
		if ( banner[i].style.width > "0px" )
		{
			banner[i].style.width = "0px";
			banner[i].style.height = "0px";
			banner[i].style.visibility ='hidden';
			if ( i+1 >= banner.length )
			{
				banner[i].style.visibility='visible';
				banner[0].style.width = document.getElementById(tmp_banner).style.width;
				banner[0].style.height = document.getElementById(tmp_banner).style.height;
			}
			else
			{
				banner[i].style.visibility='visible';
				banner[i+1].style.width = document.getElementById(tmp_banner).style.width;
				banner[i+1].style.height = document.getElementById(tmp_banner).style.height;
				return true;
			}
		}
	}
}

function bannerSetProp(tmp_banner)
{
	var bannerdelaytime = new Array;
	var bannerdelaytime_str = "";
	var banner_imgs = 0;
	var banner = document.getElementById(tmp_banner).getElementsByTagName('img');
	banner[0].style.width = document.getElementById(tmp_banner).style.width;
	banner[0].style.height = document.getElementById(tmp_banner).style.height;
	banner_imgs = banner.length;
	for (var i = 0; i < banner.length; i++)
		bannerdelaytime[i+1] = (parseInt(banner[i].alt) * 1000);
	bannerdelaytime_str = bannerdelaytime.toString();
	bannersetImagePositions(tmp_banner);
	bannermyTimer(tmp_banner, bannerdelaytime_str, banner_imgs, 0, 1);
}

var TIMER = 5;
var SPEED = 10;
var WRAPPER = 'content';

function pageWidth() { return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null; }

function pageHeight() { return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null; }

function topPosition() { return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0; }

function leftPosition() { return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0; }

// build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(title,message,type,autohide)
{
	if(!type) { type = 'error'; }
	var dialog;
	var dialogheader;
	var dialogclose;
	var dialogtitle;
	var dialogcontent;
	var dialogmask;
	if(!document.getElementById('dialog'))
	{
		dialog = document.createElement('div');
		dialog.id = 'dialog';
		dialogheader = document.createElement('div');
		dialogheader.id = 'dialog-header';
		dialogtitle = document.createElement('div');
		dialogtitle.id = 'dialog-title';
		dialogclose = document.createElement('div');
		dialogclose.id = 'dialog-close'
		dialogcontent = document.createElement('div');
		dialogcontent.id = 'dialog-content';
		dialogmask = document.createElement('div');
		dialogmask.id = 'dialog-mask';
		document.body.appendChild(dialogmask);
		document.body.appendChild(dialog);
		dialog.appendChild(dialogheader);
		dialogheader.appendChild(dialogtitle);
		dialogheader.appendChild(dialogclose);
		dialog.appendChild(dialogcontent);;
		dialogclose.setAttribute('onclick','hideDialog()');
		dialogclose.onclick = hideDialog;
	}
	else
	{
		dialog = document.getElementById('dialog');
		dialogheader = document.getElementById('dialog-header');
		dialogtitle = document.getElementById('dialog-title');
		dialogclose = document.getElementById('dialog-close');
		dialogcontent = document.getElementById('dialog-content');
		dialogmask = document.getElementById('dialog-mask');
		dialogmask.style.visibility = "visible";
		dialog.style.visibility = "visible";
	}
	dialog.style.opacity = .00;
	dialog.style.filter = 'alpha(opacity=0)';
	dialog.alpha = 0;
	var width = pageWidth();
	var height = pageHeight();
	var left = leftPosition();
	var top = topPosition();
	var dialogwidth = dialog.offsetWidth;
	var dialogheight = dialog.offsetHeight;
	var topposition = top + (height / 2) - (dialogheight / 2);
	var leftposition = left + (width / 2) - (dialogwidth / 2);
	dialog.style.top = topposition + "px";
	dialog.style.left = leftposition + "px";
	dialogheader.className = type + "header";
	dialogtitle.innerHTML = title;
	dialogcontent.className = type;
	dialogcontent.innerHTML = message;
	var content = document.getElementById(WRAPPER);
	dialog.timer = setInterval("fadeDialog(1)", TIMER);
	if(autohide)
	{
		dialogclose.style.visibility = "hidden";
		window.setTimeout("hideDialog()", (autohide * 1000));
	}
	else
	{
		dialogclose.style.visibility = "visible";
	}
}

// hide the dialog box //
function hideDialog()
{
	var dialog = document.getElementById('dialog');
	clearInterval(dialog.timer);
	dialog.timer = setInterval("fadeDialog(0)", TIMER);
}

// fade-in the dialog box //
function fadeDialog(flag)
{
	if(flag == null) { flag = 1; }
	var dialog = document.getElementById('dialog');
	var value;
	if(flag == 1) { value = dialog.alpha + SPEED; }
	else { value = dialog.alpha - SPEED; }
	dialog.alpha = value;
	dialog.style.opacity = (value / 100);
	dialog.style.filter = 'alpha(opacity=' + value + ')';
	if(value >= 99)
	{
		clearInterval(dialog.timer);
		dialog.timer = null;
	}
	else if(value <= 1)
	{
		dialog.style.visibility = "hidden";
		document.getElementById('dialog-mask').style.visibility = "hidden";
		clearInterval(dialog.timer);
	}
}

function Dialog(tbl_str)
{
	if (tbl_str == "legal") showDialog("Legal Notices and Terms of Use", legal_content, "success");
	else if (tbl_str == "privacy") showDialog("Privacy Policy", privacy_content, "success");
}

function secBoard(m,n,o,p)
{
	if (m != "") eval("document.getElementById('" + m + "').style.display=\"block\";");
	if (n != "") eval("document.getElementById('" + n + "').style.display=\"none\";");
	if (o != "") eval("document.getElementById('" + o + "').style.display=\"none\";");
	if (p != "") eval("document.getElementById('" + p + "').style.display=\"none\";");
}

function case_menu(w,x,y,z)
{
	if (w != "") eval("document.getElementById('" + w + "').className='menu01'");
	if (x != "") eval("document.getElementById('" + x + "').className='menu02'");
	if (y != "") eval("document.getElementById('" + y + "').className='menu02'");
	if (z != "") eval("document.getElementById('" + z + "').className='menu02'");
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{ sString = sString.substring(1, sString.length); }
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{ sString = sString.substring(0,sString.length-1); }
	return sString;
}

function check_date(sString)
{
	var tmp_str = "";
	var d = new Date(sString);
	if (sString.length == 10)
		if (sString.substr(4,1) == "/")
			if (sString.substr(7,1) == "/") {
				if (String(d.getFullYear()) == sString.substr(0,4))
					if (String(d.getMonth()+101) == "1" + sString.substr(5,2))
						if (String(d.getDate()+100) == "1" + sString.substr(8,2))
							tmp_str = sString;
			}
	return tmp_str;
}

function calendar_pop(txt_id, btn_id)
{
	new Calendar({
	inputField: txt_id,
	dateFormat: "%Y/%m/%d",
	fdow: 0,
	trigger: btn_id,
	onSelect: function() {
	var date = Calendar.intToDate(this.selection.get());
	this.hide();
	}
	});
}

function changeFont(size_str)
{
	var nodes = document.getElementsByTagName('span');
	for(var i = 0; i < nodes.length; i++)
	{
		if(nodes[i].parentNode)
		{
			obj = nodes[i];
			while(1) 
			{
				if(!obj.parentNode)
					break;
				else if (obj.id == "main_content")
				{
					tmp_size = parseInt(nodes[i].style.fontSize);
					if (size_str == "larger")
					{
						if (tmp_size >= 36) nodes[i].style.fontSize = "36pt"
						else nodes[i].style.fontSize = String(tmp_size + 2) + "pt";
					}
					else if (size_str == "smaller")
					{
						if (tmp_size <= 6) nodes[i].style.fontSize = "6pt"
						else nodes[i].style.fontSize = String(tmp_size - 2) + "pt";
					}
					break;
				}
				obj = obj.parentNode;
			}
		}
	}
}

function change_page(tmp_vpage) { document.p_frm.vpage.value = tmp_vpage; document.p_frm.submit(); }

function change_site() { location.assign(document.s_frm.rec_site.options[document.s_frm.rec_site.selectedIndex].value); }

	var arr_file_count = 10;
	var arr_file_head = new Array;
	var arr_file_page = new Array;
	var arr_file_bgpos = new Array;
	var arr_file_q2content = [["","",[["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""]]]];
	var arr_file_q3content = [["","",[["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""]]]];
	var arr_file_q4content = [["","",[["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""],["", "", ""]]]];
	var privacy_content = "";
	var legal_content = "";
	var q4_default_content = "";
	var Subscribe_Login_link = "";
	var total_rec_count = 0;
	var vpage = 0;
	var vlink = "";
	var tmp_title = "";
	var tmp_head = "";
	var tmp_bgpos = "0";
	var tmp_q1content = "";
	var tmp_q2content = "";
	var tmp_q3content = "";
	var tmp_q4content = "";
	var tmp_searchlink = "";
	var tmp_q3head = "";
	var home_q3_1 = "";
	var home_q3_2 = "";
	var home_q3_3 = "";
	var home_q3_4 = "";
	var home_q3_5 = "";
	var tmp_page = "";
	var section_sel = "";
	var geography_sel = "";
	var link_desc_sel = "";
	var result_page = "";

function get_page_value()
{
	for (var i=1; i<=arr_file_count; i++)
	{
		if (((tmp_page).toLowerCase()).indexOf(arr_file_page[i]) > -1)
		{
			tmp_title = arr_file_head[i];
			for (var k=1; k<=14; k++)
			{
				if (arr_file_q2content[0][2][k][0] == vlink)
				{
					if ((arr_file_q2content[0][2][k][1] == "") || ((arr_file_q2content[0][2][k][1]).substr(0,3) == "-- ")) tmp_head = (arr_file_head[i]).replace(/-/g, "");
					else tmp_head = (arr_file_q2content[0][2][k][1]).replace(/-/g, "");
				}
			}
			tmp_bgpos = arr_file_bgpos[i];
			tmp_q2content = arr_file_q2content[0][1];
			if (tmp_q2content != "") tmp_q2content += " ";
			tmp_q2_length = 0;
			for (var j=1; j<=14; j++) 
			{
				if ((arr_file_q2content[0][2][j][1] != "") && ((arr_file_q2content[0][2][j][1]).substr(0,2) != "--"))
					tmp_q2_length++;
			}
			tmp_isend = 0;
			if (tmp_q2_length > 8) 
				tmp_q2content += "<table width='100%'><tr><td valign='top'>";
			for (var j=1; j<=14; j++)
			{
				if ((arr_file_q2content[0][2][j][1] != "") && ((arr_file_q2content[0][2][j][1]).substr(0,2) != "--"))
				{
					if (vlink == arr_file_q2content[0][2][j][0])
						tmp_q2content += "<b>" + arr_file_q2content[0][2][j][1] + "</b><br>"
					else
					{
						if (arr_file_q2content[0][2][j][2] == "")
							tmp_q2content += "<a href=\"" + arr_file_page[i] + "?vlink=" + arr_file_q2content[0][2][j][0] + "\">" + arr_file_q2content[0][2][j][1] + "</a><br>"
						else
							tmp_q2content += "<a href=\"" + arr_file_q2content[0][2][j][2] + "\">" + arr_file_q2content[0][2][j][1] + "</a><br>"
					}
					tmp_isend++;
					if ((tmp_isend == 8) && (tmp_q2_length > 8))
						tmp_q2content += "</td><td align='right' valign='top'>";
				}
			}
			if (tmp_q2_length > 8) 
				tmp_q2content += "</td></tr></table>";
			tmp_q2content += "<br>" + arr_file_q2content[0][0];
			tmp_q3content = arr_file_q3content[0][2][0][1] + arr_file_q3content[0][2][0][0] + arr_file_q3content[0][2][0][2];
			tmp_q4content = arr_file_q4content[0][2][0][1] + arr_file_q4content[0][2][0][0] + arr_file_q4content[0][2][0][2];
		}
	}
}

function show_page_header()
{
	get_page_value();
	document.title = tmp_head + ' - Centre for Asia Private Equity Research';
}

function show_body_header()
{
	var i;
	document.write('<table width="1000" height="80" border="0" align="center" cellpadding="0" cellspacing="0">');
		document.write('<tr>');
			document.write('<td width="190" height="14" rowspan="2" valign="bottom">');
				document.write('<a href="index.php"><img src="images/home_06.jpg" alt="Centre for Asia Private Equity Research" width="190" height="40" vspace="14" border="0" /></a>');
			document.write('</td>');
			document.write('<form name="srarchForm" id="srarchForm" method="post" action="' + result_page + '">');
			document.write('<td valign="bottom" class="top" id="header_id">');
				//document.write(Subscribe_Login_link + '<a href="contact.php">Contact Us</a> | <a href="qa.php">Q & A</a> | ');
				document.write(Subscribe_Login_link + '<a href="contact.php">Contact Us</a> | ');
				document.write('<input onfocus="this.style.color=\'#000000\';this.value=\'\';" name="keyword" type="text" class="txt01" id="keyword" value="Search online publications"/><input name="" type="submit" value="" class="btn01">');
			document.write('</td>');
			document.write('</form>');
		document.write('</tr>');
		document.write('<tr>');
			document.write('<td class="nav" id="header_id2">');
				for (i=3; i<=7; i++)
				{
					if (((tmp_page).toLowerCase()).indexOf(arr_file_page[i]) > -1)
						document.write('<a href="' + arr_file_page[i] + '"><b>' + arr_file_head[i] + '</b></a>');
					else
						document.write('<a href="' + arr_file_page[i] + '">' + arr_file_head[i] + '</a>');
					if (i != 7)
						document.write(' | ');
					if (arr_file_head[i] == "Publications")
						document.write('<a href="http://www.asiape.com/peindex/">Asia PE Index</a> | ');
				}
			document.write('</td>');
		document.write('</tr>');
	document.write('</table>');
}

function show_body_banner()
{
	if (tmp_head == "Home") document.write('<div id="banner">');
	else document.write('<div id="view">');
		document.write('<div id="icon" style="background:url(images/home_13.jpg) no-repeat; background-position:' + tmp_bgpos + 'px 0px;"></div>');
			document.write('<table width="1000" height="218" border="0" align="center" cellpadding="0" cellspacing="0">');
				document.write('<tr>');
					document.write('<td valign="top">');
						document.write(tmp_q1content);
						if (tmp_head == "Home") bannerSetProp("banner03");
					document.write('</td>');
					if (tmp_head == "Home")
					{
						document.write('<td width="316" valign="top"><form name="s_frm">');
							document.write(tmp_q2content);
							bannerSetProp("banner01");
						document.write('</form></td>');
					}
					else
					{
						document.write('<td valign="top" style="background: url(images/adout_05.jpg) no-repeat scroll center top transparent;" id="view_right">');
							document.write('<div class="title02">' + tmp_title + '</div>');
							document.write(tmp_q2content);
						document.write('</td>');
					}
				document.write('</tr>');
			document.write('</table>');
	document.write('</div>');
	if (tmp_head == "Home") document.write('<div id="bar">Welcome to www.asiape.com</div>');
	else document.write('<div id="view_bar"><a href="index.php">Home</a> > <b>' + tmp_head + '</b></div>');
}

function show_body_content()
{
	if (tmp_head == "Home") document.write('<table width="1000" height="320" border="0" align="center" cellpadding="0" cellspacing="0">');
	else document.write('<table width="1000" height="890" border="0" align="center" cellpadding="0" cellspacing="0">');
		document.write('<tr>');
			document.write('<td valign="top">');
				document.write(tmp_q3head);
				document.write('<div class="view_content"><form name="p_frm" method="post" action="' + tmp_searchlink + '">');
					document.write(tmp_q3content);
				document.write('</form></div>');
			document.write('</td>');
			if (tmp_q4content == "")
			{
				document.write('<td id="q4content_id" width="327" align="center" valign="top" style="background:url(images/database_bg.jpg) no-repeat top left; padding-top:5px;">');
					document.write(q4_default_content);
				document.write('</td>');
			}
			else
			{
				document.write('<td id="q4content_id" width="327" align="center" valign="top" style="background:url(images/database_bg.jpg) no-repeat top left;">');
					document.write('<div class="right_txt">');
					if (tmp_head == "Home")
					{
						document.write(tmp_q4content.replace(/<a id='home_q3_5'/, home_q3_5 + "<a id='home_q3_5'"));
						bannerSetProp("banner02");
					}
					else
						document.write(tmp_q4content.replace(/<hr \/>/gi, "<\/div><div class='right_more'><\/div><div class='right_txt'>"));
					document.write('</div>');
				document.write('</td>');
			}
		document.write('</tr>');
	document.write('</table>');
}

function show_body_footer()
{
	var d = new Date();
	document.write('<div id="footer_bg"></div>');
	document.write('<table width="1000" height="62" border="0" align="center" cellpadding="0" cellspacing="0">');
		document.write('<tr>');
			document.write('<td class="footer">Copyright&copy;' + d.getFullYear() + ' <b>Centre for Asia Private Equity Research Ltd</b>. All rights reserved.</td>');
			document.write("<td class='bottom'><a href='javascript:Dialog(\"privacy\");'>Privacy Policy</a> | <a href='javascript:Dialog(\"legal\")'>Legal Notices and Terms of Use</a></td>");
		document.write('</tr>');
	document.write('</table>');
}

