﻿// JavaScript Document

/******************************************************
	Wait Message Display Script
	Please include WaitMsg.js in the head section.
	
	Function to show the scroller:
		
	ShowLoad(Scrolltype,ScrollColor,Position,Message,MsgBackColor,MsgClass)
	
	Scrolltype	= "SOLID", "BLOCK", "BARMOV[1-9]"
	Position = 	"AUTO-CENTER-CENTER-PADDING", "AUTO-CENTER-LEFT-PADDING", "AUTO-CENTER-RIGHT-PADDING"
				"AUTO-TOP-LEFT-PADDING", "AUTO-TOP-RIGHT-PADDING", "AUTO-TOP-CENTER-PADDING"
				"AUTO-BOTTOM-LEFT-PADDING", "AUTO-BOTTOM-CENTER-PADDING", "AUTO-BOTTOM-RIGHT-PADDING"
			
				"USER-20-100"
				
********************************************************/
//If you want the back ground disabled make it true, other wise false
var DeisabledBack = true;

/********************************************************
	No need to edit the script below
***********************************************************/

var ScrollLength = 1;
var ScrollGo;
var Message;
var MyPosition;
var gHideSelects = false;
var IsRunning = false;

/*********************************************************************************
	Start of wait message
**********************************************************************************/
function ShowLoadLatest(type,scrollcolor,positions,msg,backcolor,msgclass)
{
    if(!IsRunning)
    {
	    var ObjNew = document.createElement('div');
	    ObjNew.setAttribute("id","LoadMessageCotainer");
    	
	    if(typeof type=="undefined") var type = "BARMOV4";
	    if(typeof scrollcolor=="undefined") var scrollcolor = "#ff9900";
	    if(typeof positions=="undefined") var positions = "AUTO-CENTER-CENTER";
	    MyPosition = positions;
	    var fs = type=="SOLID"? "9" : "10";
    	
	    var fullHeight = getViewportHeightScroll();
	    var fullWidth = getViewportWidthScroll();
    	
	    h = Math.round(fullHeight/2-40);
	    w = Math.round(fullWidth/2-80);
    	
	    //Making the Scroller HTML
	    if (typeof msg=="undefined")
		    txt ='<div id="LPlay" style="position:absolute;z-index: 400;top:'+ h +'px; background-color:#A8C2F2;left:'+ w +'px;width:202px;overflow:hidden"><div id="ScrollBox" style="border:1px solid black;background-color:#FFFFFF; font-family:Verdana; font-size:'+fs+'px; font-weight:bolder; color:'+scrollcolor+';overflow:hidden;width:200px;height:12;"></div></div>';
	    else
		    if(typeof backcolor=="undefined")
			    txt ='<div id="LPlay" style="position:absolute;z-index: 400;;top:'+ h +'px; background-color:#A8C2F2;left:'+ w +'px;width:202px;overflow:hidden"><div id="ScrollBox" style="border:1px solid black;background-color:#FFFFFF; font-family:Verdana; font-size:'+fs+'px; font-weight:bolder; color:'+scrollcolor+';overflow:hidden;width:200px;height:12;"></div><div class="WaitMsgtxt" style="padding:2px">'+msg+'</div></div>';
		    else
			    if(typeof msgclass=="undefined")
				    txt ='<div id="LPlay" style="position:absolute;z-index: 400;;top:'+ h +'px; background-color:'+ backcolor +';left:'+ w +'px;width:202px;overflow:hidden"><div id="ScrollBox" style="border:1px solid black;background-color:#FFFFFF; font-family:Verdana; font-size:'+fs+'px; font-weight:bolder; color:'+scrollcolor+';overflow:hidden;width:200px;height:12;"></div><div class="WaitMsgtxt" style="padding:2px">'+msg+'</div></div>';
			    else
				    txt ='<div id="LPlay" style="position:absolute;z-index: 400;;top:'+ h +'px; background-color:'+ backcolor +';left:'+ w +'px;width:202px;overflow:hidden"><div id="ScrollBox" style="border:1px solid black;background-color:#FFFFFF; font-family:Verdana; font-size:'+fs+'px; font-weight:bolder; color:'+scrollcolor+';overflow:hidden;width:200px;height:12;"></div><div class="'+ msgclass +'" style="padding:2px">'+msg+'</div></div>';

	    ObjNew.innerHTML = txt
	    document.body.appendChild(ObjNew);
    	
	    //Calling the Scroll functions
	    if(type.indexOf("BARMOV")!=-1)
		    eval("StartScroll_BARMOV('"+scrollcolor+"',"+type.substr(6,1)+")");
	    else
		    eval("StartScroll_"+type+"()");
    	
	    addWaitMsgEvent(window, "resize", resizeWaitMsg);
	    if(DeisabledBack) PutMaskForAll();
	    resizeWaitMsg();
	    IsRunning = true;
	}
}


function HideLoad()
{
	clearTimeout(ScrollGo);
	IsRunning = false;
	ScrollLength = 1;
	if(gHideSelects) displaySelectBoxesForWaitMsg();
	if(DeisabledBack) document.body.removeChild(document.getElementById("LoadMessageMask"));
	document.body.removeChild(document.getElementById("LoadMessageCotainer"));
}

function StartScroll_BARMOV(scolor,slength)
{
	eval('StartScroll_BARMOV_F("'+scolor+'",'+slength+')');
}

function StartScroll_BARMOV_F(scolor,slength)
{
	obj = document.getElementById("ScrollBox");
	var txt = '<table width="100%"  border="0" cellspacing="2" cellpadding="0"><tr>';
	for(i=1;i<=22-slength;i++)
	{
		if(i==ScrollLength)
			for(j=0;j<slength;j++)
				txt += '<td height="8" bgcolor="'+scolor+'"></td>';
		else
			txt += '<td height="8"></td>';
	}
	txt += '</tr></table>';
	
	obj.innerHTML = txt;
	window.scrollTo(0,0);
	ScrollLength++;
	if(ScrollLength==23-slength)
	{
		eval('ScrollGo = setTimeout("StartScroll_BARMOV_B(\''+scolor+'\','+slength+')",50)');
		ScrollLength = 21-slength;
	}
	else
		eval('ScrollGo = setTimeout("StartScroll_BARMOV_F(\''+scolor+'\','+slength+')",50)');
}

function StartScroll_BARMOV_B(scolor,slength)
{
	obj = document.getElementById("ScrollBox");
	var txt = '<table width="100%"  border="0" cellspacing="2" cellpadding="0"><tr>';
	for(i=1;i<=22-slength;i++)
	{
		if(i==ScrollLength)
			for(j=0;j<slength;j++)
				txt += '<td height="8" bgcolor="'+scolor+'"></td>';
		else
			txt += '<td height="8"></td>';
	}
	txt += '</tr></table>';
	
	obj.innerHTML = txt;
	window.scrollTo(0,0);
	ScrollLength--;
	if(ScrollLength==0)
	{
		eval('ScrollGo = setTimeout("StartScroll_BARMOV_F(\''+scolor+'\','+slength+')",50)');
		ScrollLength = 2;
	}
	else
		eval('ScrollGo = setTimeout("StartScroll_BARMOV_B(\''+scolor+'\','+slength+')",50)');
}


function StartScroll_BLOCK()
{
	obj = document.getElementById("ScrollBox");
	if(ScrollLength>20)	ScrollLength = 1;
	txt = "";
	for(i=0;i<ScrollLength;i++)
		txt = txt + "&lowast;"
	obj.innerHTML = txt;
	window.scrollTo(0,0);
	ScrollLength++;
	if(ScrollLength==20)
		ScrollGo = setTimeout("StartScroll_BLOCK()",200)
	else
		ScrollGo = setTimeout("StartScroll_BLOCK()",100)
}

function StartScroll_SOLID()
{
	obj = document.getElementById("ScrollBox");
	if(ScrollLength>34)	ScrollLength = 1;
	txt = "";
	for(i=0;i<ScrollLength;i++)
		txt = txt + "&#9608;"
	obj.innerHTML = txt;
	window.scrollTo(0,0);
	ScrollLength++;
	if(ScrollLength==34)
		ScrollGo = setTimeout("StartScroll_SOLID()",200)
	else
		ScrollGo = setTimeout("StartScroll_SOLID()",50)
}

function setMaskSizeForWaitMsg() {
	var gPopupMask = document.getElementById("MessageMask");

	// Determine what's bigger, scrollHeight or fullHeight / width
	var popHeight = getViewportHeightScroll();
	popWidth = getViewportWidthScroll();
	
	gPopupMask.style.height = popHeight + "px";
	gPopupMask.style.width = popWidth + "px";
}
function PutMaskForAll()
{
	var ObjNewMask = document.createElement('div');
	ObjNewMask.setAttribute("id","LoadMessageMask");
	
	// check to see if this is IE version 6 or lower. hide select boxes if so
	// maybe they'll fix this in version 7?
	var ua = navigator.userAgent.toLowerCase();
	isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)); 
	var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
	if (brsVersion <= 6 && isIE) gHideSelects = true;
	if(gHideSelects) hideSelectBoxesForWaitMsg();

	var maskTxt = '<div id="MessageMask" style="position: absolute;z-index: 200;top: 0px;left: 0px;width: 100%;height: 100%;opacity: .4;filter: alpha(opacity=20);';
	maskTxt += 'background-color: #333333;';
	//maskTxt += 'background-repeat: repeat;'
	maskTxt += '"></div>';
	
	ObjNewMask.innerHTML = maskTxt;
	document.body.appendChild(ObjNewMask);
	
	//alert("Test");
	setMaskSizeForWaitMsg();	
}
function resizeWaitMsg()
{
	obj = document.getElementById("LPlay");
	if(obj!=null)
	{
		var POS = findPosition();
		obj.style.top = POS[0]+"px";
		obj.style.left = POS[1]+"px";
		
		if(DeisabledBack) setMaskSizeForWaitMsg();
	}
	return;
}

function findPosition()
{
	var POS = new Array();
	var h,w;
	var myposition = MyPosition.split(/-/);
	var fullHeight = getViewportHeightScroll();
	var fullWidth = getViewportWidthScroll();
	var obj = document.getElementById("LPlay");
	mh = obj.offsetHeight;
	mw = obj.offsetWidth;

	if(myposition[0]=="AUTO")
	{
		//Auto positioned
		switch(myposition[1])
		{
			//Vertical Position CENTER
			case "CENTER" :
							switch(myposition[2])
							{
								//Horizontal Position CENTER
								case "CENTER" :
												POS[0] = Math.round((fullHeight*1 - mh*1)/2);
												POS[1] = Math.round((fullWidth*1 - mw*1)/2);
												break;
								//Horizontal Position LEFT
								case "LEFT" :
												POS[0] = Math.round((fullHeight*1 - mh*1)/2);
												POS[1] = myposition[3];
												break;
								//Horizontal Position RIGHT
								case "RIGHT" :
												POS[0] = Math.round((fullHeight*1 - mh*1)/2);
												POS[1] = Math.round(fullWidth*1 - mw*1 - myposition[3]*1);
												break;
							}
							break;
				
			//Vertical Position TOP
			case "TOP" :
							switch(myposition[2])
							{
								//Horizontal Position CENTER
								case "CENTER" :
												POS[0] = myposition[3];
												POS[1] = Math.round((fullWidth*1 - mw*1)/2);
												break;
								//Horizontal Position LEFT
								case "LEFT" :
												POS[0] = myposition[3];
												POS[1] = myposition[3];
												break;
								//Horizontal Position RIGHT
								case "RIGHT" :
												POS[0] = myposition[3];
												POS[1] = Math.round(fullWidth*1 - mw*1 - myposition[3]*1);
												break;
							}
							break;
			
			//Vertical Position BOTTOM
			case "BOTTOM" :
							switch(myposition[2])
							{
								//Horizontal Position CENTER
								case "CENTER" :
												POS[0] = Math.round(fullHeight*1 - mh*1- myposition[3]*1);
												POS[1] = Math.round((fullWidth*1 - mw*1)/2);
												break;
								//Horizontal Position LEFT
								case "LEFT" :
												POS[0] = Math.round(fullHeight*1 - mh*1- myposition[3]*1);
												POS[1] = myposition[3];
												break;
								//Horizontal Position RIGHT
								case "RIGHT" :
												POS[0] = Math.round(fullHeight*1 - mh*1- myposition[3]*1);
												POS[1] = Math.round(fullWidth*1 - mw*1 - myposition[3]*1);
												break;
							}
							break;
			default:
							POS[0] = Math.round((fullHeight*1 - mh*1)/2);
							POS[1] = Math.round((fullWidth*1 - mw*1)/2);
		}
		
	}
	else if(myposition[0]=="USER")
	{
		//User Defined posioned
		POS[0] = myposition[1];
		POS[1] = myposition[2];
	}
	else
	{
		POS[0] = Math.round((fullHeight*1 - mh*1)/2);
		POS[1] = Math.round((fullWidth*1 - mw*1)/2);
	}
	return POS;
}

function hideSelectBoxesForWaitMsg() {
	
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
}

function displaySelectBoxesForWaitMsg() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}

function getViewportHeightScroll() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidthScroll() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}

function addWaitMsgEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeWaitMsgEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

var objIDMaskOn;

function PutMaskOnMe(objID)
{
	objIDMaskOn = document.getElementById(objID);
	if(objIDMaskOn != null)
	{
		var ObjNewMask = document.createElement('div');
		ObjNewMask.setAttribute("id","LoadMessageMaskOnMe");
	
		var popTop = getposOffset(objIDMaskOn,"top");
		var popLeft = getposOffset(objIDMaskOn,"left");
		
		var popHeight = objIDMaskOn.offsetHeight;
		var popWidth = objIDMaskOn.offsetWidth;
	
		var maskTxt = '<div id="MessageMaskOnMe" style="position: absolute;z-index: 600;top: '+popTop+'px;left: '+popLeft+'px;width: '+popWidth+'px;height: '+popHeight+'px;opacity: .4;filter: alpha(opacity=40);';
		maskTxt += 'background-color: #ffffff;';
		maskTxt += '"></div>';
		
		ObjNewMask.innerHTML = maskTxt;
		document.body.appendChild(ObjNewMask);
	}
}

function RemoveMaskOnMe()
{
	var obj = document.getElementById("LoadMessageMaskOnMe");
	if(obj!=null) document.body.removeChild(obj);
}
