﻿//--------------------------------------------------------------------------
//  MessageBox Event handlers
//--------------------------------------------------------------------------
function toggle(e)
{
   if (e.style.display == "none")
      {e.style.display = "";}
   else
      {e.style.display = "none";}
}

function RemoveMessages(imgPath) 
{
    if (imgPath == null)
    {
        imgPath = "Images/";
    }
        
	removeAllInfoMessagesFromList(imgPath);
	removeAllErrMessagesFromList(imgPath);
	document.getElementById('messageAreaBlock').style.display="none";
}

function switchmsglist(imgPath) 
{
	toggle(document.getElementById('tbl_msgcontentInfo'));
	toggle(document.getElementById('tbl_msgcontentErr')); 
	if (document.getElementById('tbl_msgcontentInfo').style.display == "none") 
	{
		document.getElementById('msgicon').setAttribute("src", imgPath + "msgicn_error.gif");
	}
	else 
	{
		document.getElementById('msgicon').setAttribute("src", imgPath + "msgicn_attention.gif");
	}
 }


function addMessageToList(id, msgtxt, msgtype, imgPath)
{
    if (imgPath == null)
    {
        imgPath = "Images/";
    }
    
	if (document.getElementById('messageAreaBlock').style.display == "none") 
	{ 
		if (document.getElementById('tbl_msgcontentInfo').style.display == "none") switchmsglist(imgPath);
		document.getElementById('messageAreaBlock').style.display = "block";
	}
	var tbl;
	
	switch(msgtype) 
	{
        //InfoType = 0
        //ErrorType = 1
		case 1:
		case '1':
			if (document.getElementById('tbl_msgcontentErr').style.display == "none") switchmsglist(imgPath);
			tbl = document.getElementById('tbl_msgcontentErr');
			break;
		default:
			tbl = document.getElementById('tbl_msgcontentInfo');
			break;
	}

	if (tbl != null) 
	{
		var row = tbl.insertRow(tbl.rows.length);
		row.setAttribute('id', 'msg' + id);
		
		// Image Cell
		var cellLeft = row.insertCell(0);
		var img = document.createElement('img');
		img.setAttribute('src', imgPath + 'bullet_orange.gif');
		cellLeft.appendChild(img);
		cellLeft.vAlign = "top";
		
		// Message Text cell
		var cellRight = row.insertCell(1);
		var txt = document.createTextNode(msgtxt);
		cellRight.setAttribute('width','100%');
		cellRight.appendChild(txt);
	}
}


//RAMessageList Remove Error Message
function removeAllErrMessagesFromList(imgPath) 
{
	try 
	{
		var tbl = document.getElementById('tbl_msgcontentErr');
		var tblsize = tbl.rows.length;
		for ( x = 0; x < tblsize; x++ ) 
		{
			tbl.deleteRow(0);
		}
		if (document.getElementById('tbl_msgcontentInfo').style.display == "none") switchmsglist(imgPath);
	}
	catch (e) {}
}


function removeAllInfoMessagesFromList(imgPath) 
{
	try 
	{
		var tbl = document.getElementById('tbl_msgcontentInfo');
		var tblsize = tbl.rows.length;
		for ( x = 0; x < tblsize; x++ ) 
		{
			tbl.deleteRow(0);
		}
		if (document.getElementById('tbl_msgcontentInfo').style.display == "none") switchmsglist(imgPath);
	}
	catch (e) {}
}


function removeAllMessagesFromList()
{
    try
    {
        removeAllErrMessagesFromList();
        removeAllInfoMessagesFromList();
        document.getElementById('messageAreaBlock').style.display = "none";
    }
    catch (e) {}
}


function removeMessageFromList(id)
{
	removeErrMessageFromList(id);
	removeInfoMessageFromList(id);
}


function removeInfoMessageFromList(id)
{
	try 
	{
		var tbl = document.getElementById('tbl_msgcontentInfo');
		if (tbl != null) 
		{
			var txt = 'msg' + id;
			var row = tbl.rows(txt);
			if (row != null) 
			{
				var idx;
				if (row.length > 0) { idx = row(0).rowIndex	}
				else { idx = row.rowIndex };
				if (idx >= 0) tbl.deleteRow(idx);
			};
		}
	}
	catch(e) {alert(e);}
	
	try 
	{
		if (tbl.rows.length == 0 & document.getElementById('tbl_msgcontentInfo').style.display != "none") {document.getElementById('messageAreaBlock').style.display = "none";}
	}
	catch(e) {}
}


function removeErrMessageFromList(id)
{
	try 
	{
		var tbl = document.getElementById('tbl_msgcontentErr');
		if (tbl != null) {
			var txt = 'msg' + id;
			var row = tbl.rows(txt);
			if (row != null) {
				var idx;
				if (row.length > 0) { idx = row(0).rowIndex	}
				else { idx = row.rowIndex };
				if (idx >= 0) tbl.deleteRow(idx);
				if (tbl.rows.length == 0 & document.getElementById('tbl_msgcontentInfo').style.display == "none") switchmsglist();
			};
		}
	}
	catch(e) { }
}


//code for RAMessageList linked to client side validation objects.
function raValidationSum()
{
	try 
	{
		for (i=0; i<Page_Validators.length; i++) 
		{ 
				removeMessageFromList('val' + i);
		}  

		if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();   
	
		for (i=0; i<Page_Validators.length; i++) 
		{
	       if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
			        addMessageToList('val' + i,Page_Validators[i].errormessage,1);
	       }
		}        
	}
	catch(e) {}
}