/************************************************************************************************
Name		- Ajax Loader
Description	- Loading screen, Ajax time keeper and other ajax related functionalities.
Version		- 1.2.2
Author		- Anoop Nair.
Company		- OASIS (part of MKCL).

# COPYRIGHT NOTICE
# Copyright (c) 2005-2009 MKCL, All rights reserved.
# This script may be used and modified free of charge for Non-profit purposes by anyone as long
# as this copyright notice and the comments above are kept in their original form.
************************************************************************************************/

 var LoadScreen_isLoad=false;addOnLoadEvent(function(){LoadScreen_isLoad=true;});function LoadScreen(hideElem,displayText,imageSource){var mainDiv=document.createElement('div');var busyImg=document.createElement('img');var txtSpan=document.createElement('span');var layTab=document.createElement('table');var firstTr=layTab.insertRow(-1);var firstTd=firstTr.insertCell(-1);var secondTd=firstTr.insertCell(-1);firstTd.appendChild(busyImg);secondTd.appendChild(txtSpan);mainDiv.appendChild(layTab);if(LoadScreen_isLoad)document.body.appendChild(mainDiv);else addOnLoadEvent(function(){document.body.appendChild(mainDiv);});mainDiv.style.position='absolute';mainDiv.style.display='none';mainDiv.style.overflow='hidden';layTab.style.margin='0 auto';firstTd.style.textAlign='right';firstTd.style.width='30%';firstTd.style.padding='0';secondTd.style.padding='0';mainDiv.style.verticalAlign='middle';mainDiv.style.border='1px solid #E2D7D7';mainDiv.style.opacity=0.93;mainDiv.style.filter='alpha(opacity=93)';mainDiv.style.zIndex=20;var errhnd=new ErrorHandler('LoadScreen',new Array('RequiredArgumentMissing'),25);var self=this,hidElem,disText,imgSrc=imageSource,lastHideElem;function afterLoad(){var windowHeight=hidElem.offsetHeight;if((busyImg.oldHeight && busyImg.oldHeight> windowHeight)||(!busyImg.oldHeight && busyImg.height> windowHeight)){if(!busyImg.oldHeight)busyImg.oldHeight=busyImg.height;busyImg.height=windowHeight-5;}else if(busyImg.oldHeight){busyImg.height=busyImg.oldHeight;}layTab.style.position='static';var contentHeight=layTab.offsetHeight;if(windowHeight> 0 && windowHeight-contentHeight> 0){layTab.style.position='relative';layTab.style.top=((mainDiv.offsetHeight/2)-(contentHeight/2))+'px';}}function setVisibleSelect(elem,show){if(elem.nodeName.toLowerCase()=='select'){if(show){elem.style.visibility=(elem.loader_visibility? elem.loader_visibility: '');elem.loader_visibility=null;}else{elem.loader_visibility=elem.style.visibility;elem.style.visibility='hidden';}}else{for(var i=0;i<elem.childNodes.length;i++)setVisibleSelect(elem.childNodes[i],show);}};this.displayText=txtSpan.innerHTML;this.setHideElement=function(element){if(typeof(element)=='string')element=document.getElementById(element);hidElem=element;};this.setText=function(displayText,isOnlyForDisplay){if(!isOnlyForDisplay){disText=(displayText? displayText: "Loading");this.displayText=disText;}txtSpan.innerHTML=(displayText? displayText: "Loading");};this.show=function(displayText){if(displayText)this.setText(displayText);if(!hidElem){errhnd.showAlert('"hideElement" is not set.',0,'LoadScreen.show(displayText)');return;}mainDiv.style.display='';var point=GetOffsetPosition(hidElem);mainDiv.style.left=point.offsetX+((hidElem.nodeName.toLowerCase()=='input' || hidElem.nodeName.toLowerCase()=='select')&&(Browser.isChrome || Browser.isFirefox)? 1: 0)+'px';mainDiv.style.top=point.offsetY+((hidElem.nodeName.toLowerCase()=='input' || hidElem.nodeName.toLowerCase()=='select')&&(Browser.isChrome || Browser.isFirefox)? 1: 0)+'px';mainDiv.style.height=(hidElem.offsetHeight-2)+'px';mainDiv.style.width=(hidElem.offsetWidth-2)+'px';mainDiv.style.backgroundColor='white';removeEventHandler(busyImg,'load',afterLoad);addEventHandler(busyImg,'load',afterLoad);if(Browser.isChrome)busyImg.src='';busyImg.src=(imgSrc? imgSrc: "../images/BusyIcon.gif");afterLoad();if(Browser.isIe && Browser.version<7){if(lastHideElem && lastHideElem.nodeName.toLowerCase()!='input')setVisibleSelect(lastHideElem,true);if(hidElem.nodeName.toLowerCase()!='input')setVisibleSelect(hidElem,false);}lastHideElem=hidElem;};this.hide=function(){mainDiv.style.display='none';if(hidElem && hidElem.nodeName.toLowerCase()!='input' && Browser.isIe && Browser.version<7)setVisibleSelect(hidElem,true);lastHideElem=null;};this.setHideElement(hideElem);this.setText(displayText);}function AjaxTimeKeeper(timeOuts,loaderScreen){var errhnd=new ErrorHandler('AjaxTimeKeeper',new Array('ArgumentFormat','RequiredArgumentMissing','InvalidEnvironment','InvalidArgument'),30);if(typeof(AjaxPro)=='undefined' || !AjaxPro.timeoutPeriod){errhnd.showAlert('Either AJAX is not used in this page \r\nOR\r\n'+'\tCorrect version of "AjaxPro.2.dll" is not used(9.2.17.1).',2);return;}if(!(timeOuts && !(timeOuts.propertyIsEnumerable('length'))&& typeof(timeOuts)==='object' && typeof(timeOuts.length)==='number')){errhnd.showAlert('Parameter "timeOuts"(first param)should be an array.',0);return;}if(timeOuts.length< 1){errhnd.showAlert('Parameter "timeOuts"(first param)should contain atleast one timeout value.',0);return;}if(arguments.length==2 && !(loaderScreen && typeof(loaderScreen)==='object' && typeof(loaderScreen.displayText)==='string' && typeof(loaderScreen.setText)==='function')){errhnd.showAlert('Parameter "loaderScreen"(second param)should be a "LoadScreen" object.',0);return;}if(arguments.length> 2)loaderScreen=new LoadScreen(arguments[1],arguments[2],arguments[3]);var self=this,curTimer,actTimer,timerObj,dots;var ajxArgs,ajxFunc,ajxCls;function getDisplayText(){var output='',i=0;if(curTimer==0){output+=loaderScreen.displayText;}else{output+='Retrying';}for(;i< dots;i++)output+='.';for(;i<=3;i++)output+='&nbsp;';output+='('+actTimer+'s)';return output;}function setText(){actTimer--;dots++;if(dots>3)dots=0;if(actTimer< 0)timedOut();else loaderScreen.setText(getDisplayText(),true);}function timedOut(){stopTimer();updateTimer();}function updateTimer(){curTimer++;actTimer=(curTimer>=timeOuts.length? null: timeOuts[curTimer]);if(actTimer){AjaxPro.timeoutPeriod=actTimer* 1000;ajxFunc.apply(ajxCls,ajxArgs);timerObj=setInterval(function(){setText();},1000);actTimer++;setText();}else{stopTimer();loaderScreen.hide();alert('Your internet connectivity seems to be too poor.\r\nServer cannot be reached.'+'\r\nPlease use better connectivity options.');}}function stopTimer(){if(timerObj)clearInterval(timerObj);timerObj=null;}this.loadScreen=loaderScreen;this.start=function(){if(arguments.length< 2){errhnd.showAlert('AJAX expects calling and callback functions.',1);return;}if(typeof(arguments[0])!='string'){alert('Expected calling function name(string)as first argument,found "'+typeof(arguments[0])+'".',0);return;}if(typeof(arguments[arguments.length-1])!='function'){alert('Expected Ajax callback function as last argument,found "'+typeof(arguments[arguments.length-1])+'".',0);return;}try{ajxFunc=eval(arguments[0]);}catch(err){errhnd.showAlert((Browser.isChrome?err:err.message),3);return;}if(typeof(ajxFunc)!='function'){errhnd.showAlert('"'+arguments[0]+'" is not a function.',0);return;}var temp=arguments[0].split('.');ajxCls=eval(temp.slice(0,temp.length-1).join('.'));ajxArgs=Array.prototype.slice.call(arguments).slice(1);loaderScreen.show();curTimer=-1;dots=0;AjaxPro.queue.abort();stopTimer();updateTimer();};this.stop=function(){loaderScreen.hide();stopTimer();};}