// JavaScript Document

/*
 Javascript enabled or not.
 This Function Test Cookie is enabled or not.
 XMLHTTP Object or ActiveX is enabled or not.
*/
var BodyId="mainBody";
function workSpace()
{
	//Test Cookie
	/*var testcookie='jscookietest=valid';
	document.cookie=testcookie;
	if (document.cookie.indexOf(testcookie)==-1) 
	{
		top.location="html/cookieoff.html";
		return false;
	}*/
	
	//Test XMLHTTP
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf('msie')!=-1 && document.all && agt.indexOf('opera')==-1 && agt.indexOf('mac')==-1) 
	{
		eval('var c=(agt.indexOf("msie 5")!=-1)?"Microsoft.XMLHTTP":"Msxml2.XMLHTTP";try{new ActiveXObject(c);}catch(e){top.location="html/noactivex.html";}');
	}
	return true;
}



function preload()
{
	hideLoading();
	if(Object.isFunction(hideGuard)) 
		hideGuard();
	return true;
}


function setToCenter(objDiv)
{
	var mid=parseInt((parseInt($(BodyId).getWidth()) - parseInt(objDiv.getWidth()))/2,10);
	objDiv.setStyle({'left': mid + "px" }); 
}

/* Page Gard */
function showGuard()
{
	/*
	if($("pageGuard")==null)
		$(BodyId).insert({bottom: new Element('DIV', {id: 'pageGuard' })});
		
	$("pageGuard").setStyle({'height': $(BodyId).getHeight() + "px" }); 
	$("pageGuard").show();
	*/
}
function hideGuard()
{
		/*
	if($("pageGuard"))
		$("pageGuard").hide();
	*/
}
/* End Page Gard */


/* Loading */
function showLoading(title)
{
	if(title==null || title=="")
		title="Wait, Loading...";
	
	if($("loading")==null)
	{	
		$(BodyId).insert({bottom: new Element('DIV', {id: 'loading' })});
		
		//new Insertion.Bottom($(BodyId),"<div id='loading'></div>");
		
	}
	
	var content="\
	  <div  class='loading_outer'>\
		<div class='loading_border'>\
			 <b class='loading_top'> <b class='lb1'></b> <b class='lb2'></b> <b class='lb3'></b> <b class='lb4'></b></b>\
		  	 <div class='loading_content'>\
				<div class='loading_text'>"+title  +"</div>\
		     </div>\
			 <b class='loading_bottom'> <b class='lb4'></b> <b class='lb3'></b> <b class='lb2'></b> <b class='lb1'></b> </b>\
		  </div>\
	  </div>";
  	$("loading").innerHTML=content;
	setToCenter($("loading"));
	
		
	$("loading").show();
	//alert("showing....");
}
function hideLoading()
{
	if($("loading"))
		$("loading").hide();
}
/* End Loading */

/* Error Box */
function showError(title, message)
{
	if($("ErrorBox")==null)
	{	
		$(BodyId).insert({bottom: new Element('DIV', {id: 'ErrorBox','class': 'ErrorBox' })});
		setToCenter($("ErrorBox"));
	}
	Dialog.alert("<b>"+title +"</b><br>" + message , 
                 {top: 10, width:500, className: "alphacube", okLabel: "OK" , onOk: hideGuard(), parent:$('ErrorBox')});
}
function hideError()
{
	if($("ErrorBox"))
	{
		$("ErrorBox").innerHTML="";
		$("ErrorBox").hide();
		$("ErrorBox").remove(); 
	}
}


/* End Error Box */


/* Ajax Function */
function showAjaxError(errorCode,errorMessage)
{	
		
	switch(errorCode)
	{
		case 0: 
			errorMessage="Failed to Connect!";
			break;
		case 404: 
			errorMessage="Page not available!";
			break;
		case 500:
			errorMessage="Internal Server Error, indicates that the server encountered something it didn't expect and was unable to complete the request!";
			break;
		default:
			errorMessage="Internal Server Error, Please contact with system administrator.";		
	}
	showError("Internal Error: " + errorCode , errorMessage);
	
}
/* Ajax Function end */