// JavaScript Document
// example of call: <a id="me" href="javascript:grayOut(true,'me',0,0);">Example</a>

var pdata = [];

function grayOut(vis, parentID, dataID, templateID, heightAdjustment, printFeature) {
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 50;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           
        tnode.style.position='absolute';                 
        tnode.style.top='0px';                           
        tnode.style.left='0px';                          
        tnode.style.overflow='hidden';                   
        tnode.style.display='none';                      
        tnode.id='darkenScreenObject';                   
    tbody.appendChild(tnode);                            
    dark=document.getElementById('darkenScreenObject');  
  }
  if (vis) {
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';
	var left = (pageWidth / 2) - 200;
	var pbody = document.getElementsByTagName("body")[0];
    var pnode = document.createElement('div');
		pnode.style.position= 'absolute';                 
        pnode.style.top= elementPosition(document.getElementById(parentID), heightAdjustment)+'px';                         
        pnode.style.left= '0px';                        
		pnode.style.width= pageWidth;
    	pnode.style.height= '200px';
		pnode.style.color= 'black';
		pnode.style.zIndex=zindex + 10;         
		pnode.align='center';
        pnode.id='loadBox';
	pbody.appendChild(pnode);                       
	document.getElementById("loadBox").innerHTML= layout(printFeature);  
	document.getElementById("contentAreaInsert").innerHTML= template(dataID, templateID);
  } else {
    dark.style.display='none';
	var pbody = document.getElementsByTagName("body")[0];
  	var pnode = document.getElementById('loadBox');
  	pbody.removeChild(pnode);
  }
}
function elementPosition(obj, heightAdjustment) {
  var curtop = 0;
  if (obj.offsetParent) {
	curtop = obj.offsetTop;
	while (obj = obj.offsetParent) {
	  curtop += obj.offsetTop;
	}
  }
  if (!heightAdjustment){
	  heightAdjustment = 50;
  }
  if (heightAdjustment == true){ 
  	return 50;
  } else {
  	return curtop - heightAdjustment;
  }
}
function CallPrint(){
	var prtContent = document.getElementById('contentAreaInsert');
	var WinPrint =
	window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
	WinPrint.document.open();
	WinPrint.document.write('<style type="text/css">p,ul,li,a,td,th {font-family: Arial, Helvetica, sans-serif;font-size: 11px;color: #000000;} h1,h2,h3 {font-family: Arial, Helvetica, sans-serif;color: #000000;}</style>'+prtContent.innerHTML);
	WinPrint.document.close();
	WinPrint.focus();
	setTimeout(PrintDelay(WinPrint, prtContent),15000);
}
function PrintDelay(WinPrint, prtContent){
	WinPrint.print();
	WinPrint.close();
	prtContent.innerHTML=strOldOne;
}
function layout(printFeature) {
  if(printFeature){
    var popup = '<table width="662" border="0" cellspacing="0" cellpadding="0"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="580" height="30" background="/site/template/images/popup_box_03.gif" align="right"><a href="#" onClick="CallPrint();" style="color: black;"><img border="0" src="/site/template/images/printer.jpg"/></a></td><td><A HREF="javascript:grayOut(false);"><img src="/site/template/images/popup_box_04.gif" width="82" border="0" height="30" alt="" /></A></td></tr></table></td></tr><tr><td id="contentAreaInsert" background="/site/template/images/popup_box_06.gif" style="color: black; padding: 11px; text-align: left;">&nbsp;</td></tr><tr><td><img src="/site/template/images/popup_box_07.gif" width="662" height="26" /></td></tr></table>';
  } else {
	var popup = '<table width="662" border="0" cellspacing="0" cellpadding="0"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="580" height="30" background="/site/template/images/popup_box_03.gif" align="right"> </td><td><A HREF="javascript:grayOut(false);"><img src="/site/template/images/popup_box_04.gif" width="82" border="0" height="30" alt="" /></A></td></tr></table></td></tr><tr><td id="contentAreaInsert" background="/site/template/images/popup_box_06.gif" style="color: black; padding: 11px; text-align: left;">&nbsp;</td></tr><tr><td><img src="/site/template/images/popup_box_07.gif" width="662" height="26" /></td></tr></table>';
  }
  return popup;
}
function template(dataID, templateID) {
  var template = "";
  switch(templateID){
	  case "Default":
	  	template = pdata[dataID];
		break
	  default:
	  	template = pdata[dataID];
  }
  return template;
}