/*layer Group->'process' to show processing layer
                                                       'alert' to show simple alert layer wit a close button
                                                       'alertYesNo' to show simple alert layer wiuth a yes and no button
                                                       'adobe' to show Get adobe acrobat reader layer
idGroup->name of the layer, assign different names to show different layers of same group
stat->true:to show layer
               false: to hide layer
zValue->
                       assign higher value for that layer which should come at the top.Default is 30
msg->text to be displayed in the layer.Use it only for alert and alertYesNo
funtionStringBtn1->function of type string that is to be used on click of YES/close button
funtionStringBtn2->function of type string that is to be used on click of No button only in alertYesNo
*/
//var absPth ="https://qwww211.americanexpress.com/Internet/NGMS/US_en/Images/";//Your path for images here.
var absPth ="images/layers/";
function showLayer(layerGroup,idGroup,stat,zValue,msg,funtionStringBtn1,funtionStringBtn2)
{
if(!funtionStringBtn1)
	funtionStringBtn1="";

if(!funtionStringBtn2)
	funtionStringBtn2="";
	
if(stat)
	{
		if(document.getElementById(idGroup))
			{
			document.body.removeChild(document.getElementById(idGroup));
			}	
			
			if(!zValue)
			{
				zValue=30;
			}
			zValue += 100;
			switch(layerGroup)
			{
				case 'process':
				var popUpDiv = document.createElement('div');
				popUpDiv.setAttribute('id',idGroup);
				popUpDiv.innerHTML =getBlurBackground(idGroup,zValue)+ '<div id="'+idGroup+'Div" style="position:absolute; width:330px; height:300px; border-bottom-color:#C6C1AB; border-bottom-style:solid; border-bottom-width:1px; border-right-color:#C6C1AB; border-right-style:solid; border-right-width:1px; background-color:#FFFFFF; z-index:'+zValue+';" ><div style="border-color:#A19A87; border-width:1px; border-style:solid; width:330px; height:300px; "><div style="padding-left:45px; padding-top:42px;  "><img alt="" title="" src="' + absPth + 'hrd-processing_please.gif" /></div><div style="padding-top:45px;" align="center"><img alt="Processing please wait....." title="" src="' + absPth + 'img-process-anim.gif" /></div></div></div>';
				document.body.appendChild(popUpDiv);
				break;
				
				case 'alert':
				var popUpDiv = document.createElement('div');
				popUpDiv.setAttribute('id',idGroup);
				popUpDiv.innerHTML = getBlurBackground(idGroup,zValue)+'<div id="'+idGroup+'Div" style="position:absolute; width:381px; border-bottom-color:#C6C1AB; border-bottom-style:solid; border-bottom-width:1px; border-right-color:#C6C1AB; border-right-style:solid; border-right-width:1px; background-color:#FFFFFF; z-index:'+zValue+'; border-color:#A19A87; border-width:1px; border-style:solid;"><div><div style="padding-left:2px; padding-right:2px; padding-top:15px; padding-bottom:7px; margin-left:15px; margin-right:15px; " ><span class="W">'+msg+'</span></div></div><div style="padding-top:25px; padding-right:12px; padding-bottom:5px; height:35px;"><a href="javascript:showLayer(\'alert\',\''+idGroup+'\',false,\'\'); '+funtionStringBtn1+' "><img title="close" src="' + absPth + 'btn-close-blue.gif"  alt="Close" align="right"  /></a></div></div>';
				document.body.appendChild(popUpDiv);
				break;

				case 'alertOk':
				case 'alertok':
				case 'alertOK':				
				var popUpDiv = document.createElement('div');
				popUpDiv.setAttribute('id',idGroup);
				popUpDiv.innerHTML = getBlurBackground(idGroup,zValue)+'<div id="'+idGroup+'Div" style="position:absolute; width:381px; border-bottom-color:#C6C1AB; border-bottom-style:solid; border-bottom-width:1px; border-right-color:#C6C1AB; border-right-style:solid; border-right-width:1px; background-color:#FFFFFF; z-index:'+zValue+'; border-color:#A19A87; border-width:1px; border-style:solid;"><div><div style="padding-left:2px; padding-right:2px; padding-top:15px; padding-bottom:7px; margin-left:15px; margin-right:15px; " ><span class="W">'+msg+'</span></div></div><div style="padding-top:25px; padding-right:12px; padding-bottom:5px; height:35px;"><a href="javascript:showLayer(\'alert\',\''+idGroup+'\',false,\'\'); '+funtionStringBtn1+' "><img title="OK" src="' + absPth + 'btn-ok.gif"  alt="OK" align="right"  /></a></div></div>';
				document.body.appendChild(popUpDiv);
				break;	
				
				case 'adobe':
				var popUpDiv = document.createElement('div');
				popUpDiv.setAttribute('id',idGroup);
				popUpDiv.innerHTML =  getBlurBackground(idGroup,zValue)+
				'<div id="'+idGroup+'Div" style="position:absolute; width:381px; border-bottom-color:#C6C1AB; border-bottom-style:solid; border-bottom-width:1px; border-right-color:#C6C1AB; border-right-style:solid; border-right-width:1px; background-color:#FFFFFF; z-index:'+zValue+';">'+
				'<div style="border:#A19A87 1px solid; height:100%;" >'+
				'<div style="height:38px; border-bottom-width:1px; border-bottom-color:#CCCCCC; border-bottom-style:solid;">'+
					'<div align="left" style="float:left; width:199px; padding-top:15px; padding-bottom:12px; margin-left:5px;">'+
						'<img title="" alt="Get Adobe Acrobat Reader" src="' + absPth + 'hdr-getadobe.gif" /></div>'+
					'<div style="float:left; width:160px; padding-top:10px; padding-right:10px; height:100%;" align="right" >'+
						'<a href="javascript:void(0)"><img title="" src="' + absPth + 'icn-x-close.gif" alt="Close" onclick="showLayer(\'adobe\',\''+idGroup+'\',false,\'\'); '+funtionStringBtn1+' " /></a>'+
					'</div></div><div>'+				
					'<div style="padding-left:2px; padding-right:2px; padding-top:7px; padding-bottom:7px; margin-left:15px; " >'+
					'<span class="B">To view this document, you must have Adobe&reg; Reader&reg; installed on your computer. You can download the free software from <a xmlns:xalan="http://xml.apache.org/xslt" target="_blank" href="http://get.adobe.com/reader/">Adobe site</a></span></div>	</div>'+
				'<div style="padding-top:25px; padding-right:12px; padding-bottom:5px; height:35px;">'+
				'<a href="javascript:showLayer(\'adobe\',\''+idGroup+'\',false,\'\'); '+funtionStringBtn1+' "><img src="https://qwww211.americanexpress.com/Internet/NGMS/US_en/DownloadLayers/Images/btn-close-blue.gif" alt="Close" align="right" /></a>'+
				'</div></div>';
				document.body.appendChild(popUpDiv);
				break;

				case 'alertYesNo':
				case 'alertyesno':				
				var popUpDiv = document.createElement('div');
				popUpDiv.setAttribute('id',idGroup);
				popUpDiv.innerHTML = getBlurBackground(idGroup,zValue)+
				'<div id="'+idGroup+'Div"  style="border-bottom:2px; border-right:2px; border-left:1px;  border-top:1px; border-right-color:#A4A4A4; border-right-style:solid; border-left-color:#A4A4A4; border-left-style:solid; border-top-color:#A4A4A4; border-top-style:solid; border-bottom-color:#A4A4A4; border-bottom-style:solid; background:#FFFFFF; color:#CCCCCC; width:200px; padding:0px; margin:0px; display:block; z-index:'+zValue+'; position:absolute;">'+
				'<div id="alertText" style="border:none; background-color:#FFFFFF; padding-top:15px; padding-left:20px; margin-right:5px;" class="W">'+msg+'</div>'+
				'<div id="alertButton" style="border:none; background-color:#FFFFFF; padding-top:20px; padding-left:8px; padding-right:5px; padding-bottom:5px; height:20px;"  >'+				
				'<a href="javascript:showLayer(\'alertYesNo\',\''+idGroup+'\',false); '+funtionStringBtn1+' "><img title="Yes" src="' + absPth + 'btn-yes.gif"  alt="Yes"  style="float:left;"/></a>'+
				'<a href="javascript:showLayer(\'alertYesNo\',\''+idGroup+'\',false);'+funtionStringBtn2+' "><img title="No" src="' + absPth + 'btn-no.gif"  alt="No"   style="float:right;"/></a>'+
				'</div>	</div>';
				document.body.appendChild(popUpDiv);
				break;


				case 'externalLinkNotice':
				case 'externallinknotice':				
 				case 'alertCancelContinue':
				case 'alertcancelcontinue':				
				var popUpDiv = document.createElement('div');
				popUpDiv.setAttribute('id',idGroup);
				popUpDiv.innerHTML = getBlurBackground(idGroup,zValue)+
				'<div id="'+idGroup+'Div"  style="border-bottom:2px; border-right:2px; border-left:1px;  border-top:1px; border-right-color:#A4A4A4; border-right-style:solid; border-left-color:#A4A4A4; border-left-style:solid; border-top-color:#A4A4A4; border-top-style:solid; border-bottom-color:#A4A4A4; border-bottom-style:solid; background:#FFFFFF; color:#CCCCCC; width:380px; padding:0px; margin:0px; display:block; z-index:'+zValue+'; position:absolute;">'+
				'<div id="alertText" style="border:none; background-color:#FFFFFF; padding-top:15px; padding-left:20px;padding-right:15px;" class="W">'+msg+'</div>'+
				'<div id="alertButton" style="border:none; background-color:#FFFFFF; padding-top:20px; padding-left:8px; padding-right:5px; padding-bottom:15px; height:20px;"  >'+				
				'<a href="javascript:showLayer(\'alertCancelContinue\',\''+idGroup+'\',false); '+funtionStringBtn1+' "><img title="Cancel" src="' + absPth + 'btn-cancel.gif"  alt="Cancel"  style="float:left;"/></a>'+
				'<a href="javascript:showLayer(\'alertCancelContinue\',\''+idGroup+'\',false);'+funtionStringBtn2+' "><img title="Continue" src="' + absPth + 'btn-continue.gif"  alt="Continue"   style="float:right;"/></a>'+
				'</div>	</div>';
				document.body.appendChild(popUpDiv);
				break;
                
				
			}		
		showBlock(idGroup,stat,zValue-100);		
		}
	
else {
	try{
		showBlock(idGroup,stat,zValue-100);	   
	}catch(e){}
	}
}

function showBlock(idGroup,stat,zValue)
{
	if(!zValue)
	{
		zValue=30;
	}

	if(stat)
	{
			document.getElementById(idGroup).style.display="block";
			document.getElementById(idGroup).style.zIndex= zValue-1+100;
			document.getElementById(idGroup+"Div").style.top=((iebody().clientHeight - document.getElementById(idGroup+"Div").clientHeight)/2 + iebody().scrollTop )+"px";
			document.getElementById(idGroup+"Div").style.left=(iebody().clientWidth - document.getElementById(idGroup+"Div").clientWidth)/2 +"px";
			document.getElementById(idGroup+"Div").style.zIndex = zValue+100;
			document.getElementById(idGroup+"Div").style.position='absolute';
			document.getElementById(idGroup+"Background").style.position='absolute';
			document.getElementById(idGroup+"Background").style.zIndex = zValue-1+100;
			document.getElementById(idGroup+"Background").style.width= document.body.scrollWidth + "px";
			document.getElementById(idGroup+"Background").style.height= document.body.scrollHeight + "px";			
	}
	else  document.getElementById(idGroup).style.display="none";	

	try{
	if ((vIE() < 7) && (vIE()!=-1) ) 
			getSelectBoxBody(idGroup,stat);			
	
	}catch(e){}
}
 
function vIE(){
return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;
}

function getSelectBoxBody(id,stat)
{
	if(stat)//show i.e hide select
	{
		for(var i=0; i<document.body.childNodes.length;i++)
		{
			if(document.getElementById(id)  ==  document.body.childNodes[i] )
					setSelectBox( document.body.childNodes[i],true,id);
			else setSelectBox( document.body.childNodes[i],false,id);
			
 
			
			if(document.body.childNodes[i].type && document.body.childNodes[i].type=='select-one')
			{
				document.body.childNodes[i].style.visibility =  !stat?"visible":"hidden";
			}
		}
	}
	else
	{
	var dispEle = document.body;
		for(var i=0; i<document.body.childNodes.length;i++)
		{
			
			
			
			if(document.body.childNodes[i].style && document.body.childNodes[i].style.display !="none"  )
				{
					if( document.body.childNodes[i].style.zIndex < document.getElementById(id).style.zIndex )
						{
						if(  dispEle.style  && dispEle.style.zIndex < document.body.childNodes[i].style.zIndex)
							try{
							dispEle = document.body.childNodes[i];
							}catch(e){}
						}
				}
			 
		}
		
		setSelectBox(dispEle,true,id)
	
	}

}

function setSelectBox(pnode,stat,id)
{

	
	for(var i=0; i< pnode.childNodes.length; i++)
		{
		if(!stat && pnode.childNodes[i] == document.getElementById(id) )
			{
			continue;
			}
		if(pnode.childNodes[i].type && pnode.childNodes[i].type=='select-one')
			{
				try{
				pnode.childNodes[i].style.visibility =  stat?"visible":"hidden";
				}catch(e){}
			}
			setSelectBox(pnode.childNodes[i],stat,id)
		}
	 
}

function getBlurBackground(idGroup,zi)
{
	return '<div id="'+idGroup+'Background" class="alertBackgroundBlur" style="z-index:'+(zi-1)+';">&nbsp;</div>';
}

function iebody() //will be called only for Internet explorer.
{
    // Sense the difference between Strict and Quirks mode
    return (document.compatMode != "BackCompat"? document.documentElement : document.body);
}
	function prefetchImages()
		{
			var img= new Image;
				img.src=absPth + "hdr-getadobe.gif";
			img= new Image;
				img.src=absPth + "hrd-processing_please.gif";
			img= new Image;
				img.src=absPth + "img-process-anim.gif";
			img= new Image;
				img.src=absPth + "btn-close-blue.gif";
			img= new Image;
				img.src=absPth + "btn-ok.gif";
			img= new Image;
				img.src=absPth + "icn-x-close.gif";
			img= new Image;
				img.src=absPth + "btn-yes.gif";
			img= new Image;
				img.src=absPth + "btn-no.gif";
			img= new Image;
				img.src=absPth + "hdr-getadobe.gif";
		}

prefetchImages();

