/*

	WebApp - Web Application for VirtualU

*/

function WebApp()
{
}

/* loading text information */
WebApp.hourglass = '<img src="/static/icons/hourglass.gif" alt="Waiting.." />';

/* assign waiting to div hourglass */
WebApp.pulsate = function(id)
{
	getElement(id).innerHTML = WebApp.hourglass;
}

WebApp.drawNavigator = function(panes)
{
	// onmouseover=\"this.style.border='1px solid #555555'\" onmouseout=\"this.style.border='1px solid #cccccc'\"
	document.write("<table cellpadding=\"0\" cellspacing=\"0\" class=\"themeMenuTab\" style=\"width: 100%\"  >");
	for (i = 0; i < panes.length; i++)
	{
		// skip over the final element with no body
		if (panes[i].length == 0)
			continue;
			
		document.write('<tr ><td style="padding-left: ' + (panes[i][0] * 10 + 3) + 'px" class="themeMenuI' + panes[i][0] + '" ' +  
										' onmouseover="this.style.background=\'url(/static/theme/menu_rollover.png)\'" onmouseout="this.style.background=\'\'" ' + 
										' onclick="document.location=\'' + panes[i][2] + '\'" >');
		
		// begin inner table
		document.write('<table cellspacing="0" cellpadding="0" ><tr>');
		if (panes[i][0] != 0)
		{
			document.write('<td class="themeMenuC32">');
			document.write("<img src=\"/static/icons/glow-arrow.png\" class=\"themeMenuGI\" border=\"0\" alt=\"T\" />");
		}
		else
		{
			document.write('<td class="themeMenuC16">');
		}
		
		document.write("<img src=\"/static/icons/" + panes[i][3] + ".png\" border=\"0\" alt=\"Go\" /></td> ");
		document.write("<td><a href=\"" + panes[i][2] + "\" >" + panes[i][1] + "</a></td>");
		document.write("</tr></table>\n");
		
		// end inner table		
		document.write("</tr></td>");
	}
	document.write("</table>");
}

WebApp.drawPageChanger = function(links, url, clr)
{
	for (i = 0; i < links.length; i++)
	{
		document.write('<td><td style="text-align:right; padding-right: 5px">');
		document.write('<a href="' + url.replace('___bsn___', links[i][0]) + '" style="color: ' +  clr + '">' + links[i][1] + '</a>');
		document.write('</td></tr>');
	}
}

WebApp.doNetworkSelector = function()
{						
	// lookup object and select value
	var e = getElement('themeLoginSelectPopup');
	
	// assign new style
	if (e.style.display == '')
	{
		e.style.display = 'block';
		e.style.top     = '25px';
	}
	else
	{
		e.style.display = '';
	}
}

WebApp.popupUserSearch = function(field)
{
	var obj = ajaxLoad2('/ncp_home/ajax_common.php', 'userSearchPopup', 'showusersearchpopup', { }, true);
	$('userSearchPopup').style.display = '';
}

WebApp.popupUserSearchScan = function()
{
	var name = $('userSearchName').value;
	var obj = ajaxLoad2('/ncp_home/ajax_common.php', 'userSearchPopupResults', 'showusersearchpopupresults', { 'name' : name }, false);
}

//
// 
// main page ajax
//
//

function ajaxLoad(div, method, args, hourglass)
{
	// execute loader
	var obj = new WpciAjaxProcessor(); 
	obj.setCompleter(new AjaxDivLoader(div));

	// use post based method
	args['__ajax_call'] = method;
	obj.addPostData(args);
	obj.execute(document.location);

	// use hourglass?
	if (hourglass == true)
	{
		var od = $(div);
		if (od.nodeName == "DIV")
		{
			//Effect.SlideUp(div, { duration: 0.5 });
		}
		
		$(div).innerHTML = '<img src="/static/icons/hourglass.gif" alt="Waiting.." />';
	}
	
	return obj;
}

function ajaxLoad2(page, div, method, args, hourglass)
{
	// execute loader
	var obj = new WpciAjaxProcessor(); 
	obj.setCompleter(new AjaxDivLoader(div));
	args['__ajax_call'] = method;
	
	obj.addPostData(args);
	obj.execute(page);

	// use hourglass?
	if (hourglass == true)
	{
		$(div).innerHTML = '<img src="/static/icons/hourglass.gif" alt="Waiting.." />';
	}
	
	return obj;
}


function GeneralPopupResizer()
{
	this.onCompleted = function(req)
	{
		popup = $("generalPopup");
		popup.style.marginTop			= (-popup.clientHeight / 2) + "px";
		popup.style.marginLeft		= (-popup.clientWidth / 2) + "px";								
	}
}

function PopupCenterCommand()
{
	this.onCompleted = function(req)
	{
		popup = $("generalPopup");
		popup.style.marginTop			= (-popup.clientHeight / 2) + "px";
		popup.style.marginLeft		= (-popup.clientWidth / 2) + "px";								
	}
}

function PopupAppearCommand()
{
	this.onCompleted = function(req)
	{
		Effect.SlideDown('userPopup', { scaleX : true, duration: 0.3 } ); 
	}
}

function PopupCloseCommand()
{
	this.onCompleted = function(req)
	{
		popup = $("generalPopup");
		popup.style.display = 'none';								
	}
}


function ajaxPopup(method, args, url)
{
	// execute loader
	var obj = new WpciAjaxProcessor(); 
	obj.setCompleter(new AjaxDivLoader("generalPopupInternal"));
	obj.setCompleter(new GeneralPopupResizer());
	
	// check url
	if (typeof(url) == 'undefined')
		url = WebApp.ajax_load_root;
	
	// original arguments plus
	args['__ajax_call'] = method;
	obj.addPostData(args);
	obj.execute(url);
	
	// popup the helper box
	popup = $("generalPopup");
	popup.style.display = '';
	
	// loading box
	$("generalPopupTitle").innerHTML = 'Loading...';
	$("generalPopupInternal").innerHTML = '<img src="/static/icons/hourglass.gif" alt="Waiting.." />';
}

WebApp.closePopup = function()
{
	$("generalPopup").style.display = 'none';
}

WebApp.showNetworkSearch = function(label)
{
	ajaxPopup('networksearch', { 'label' : label }, '/ncp_home/ajax_common.php' );
}

WebApp.showNetworkSearchQuery = function(label, name)
{
	ajaxLoad2('/ncp_home/ajax_common.php', '_popupNS_Box', 'networksearchquery', { 'label' : label, 'name' : name });	
}

WebApp.finishNetworkSearch = function()
{
}