	/*Always run code. To remove frames if present. Prevents other, possibly malicious, sites from opening this site inside a frame on their site!*/
	if (self != parent) parent.location.href = self.location.href;

	function MM_openBrWindow(theURL,winName,features) { //v2.0
		window.open(theURL,winName,features);
		}

	function MM_findObj(n, d) 
		{ 
			var p,i,x;  if(!d) d=document; 
			if((p=n.indexOf("?"))>0&&parent.frames.length) {
			if(parent.frames[n.substring(p+1)]){
			d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}}
			if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
			for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
		}
	
	function MM_swapImage() 
		{ 
			var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
			if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
		}
	
	function MM_swapImgRestore() 
		{
			var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
		}

	function MM_preloadImages() 
		{ 
			var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
			var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
		}

	function dm(msgStr) 
		{
			window.status = msgStr;
			document.returnValue = true;
		}

	function dm1() 
		{
			window.status = "";
			document.returnValue = true;
		}

		function SetFocus(ctl)
		{ 
			if (ctl!="")
			{	if (document.getElementById)
				{
					var d=document.getElementById(ctl);
				}
				else
				{	if (document.all || document.layers)
					var d=eval('document.forms[0].'+ctl);
				}
				if (d!=null)
				{
					d.focus();
				}
			}	
		}
		
//Section for Modal Dialog simulation
	var ctlImage
	var ctlForm
	var winModalWindow
	

	function IgnoreEvents(e)
	{
		return false
	}

	function ShowWindow(link,width,height,scroll)
	{ 
		if (document.layers) 
			{
				window.top.captureEvents(Event.CLICK|Event.FOCUS)
			}
			
		var y=0
		var x=0
		
		if (window.outerWidth)
			{
			x=((window.outerWidth-width)/2)+window.screenX
			y=((window.outerHeight-height)/2)+window.screenY
			}
		else
			{
			x=((document.body.clientWidth-width)/2)+window.screenLeft
			y=((document.body.clientHeight-height)/2)+window.screenTop
			}
		window.onclick=IgnoreEvents
		window.onfocus=HandleFocus
		
		
		if (scroll == true) 
		    winModalWindow = window.open(link,"ModalChild",	"width=" + width + ",height=" + height + ",top=" + y + ",left=" + x + ",dependent=yes,toolbars=no,scrollbars=yes,status=yes,resizable=yes")
		else
		    winModalWindow = window.open(link,"ModalChild",	"width=" + width + ",height=" + height + ",top=" + y + ",left=" + x + ",dependent=yes,toolbars=no,scrollbars=no,status=no,resizable=no")
		winModalWindow.focus()
	}

	function HandleFocus()
	{ 
		window.setTimeout("HandleFocus2()", 50);
		return false
	}
	
	function HandleFocus2()
	{
		if (winModalWindow)
			{
				if (!winModalWindow.closed)
					{
						winModalWindow.focus()
					}
				else
					{
						if (document.layers) 
							{
								window.top.releaseEvents(Event.CLICK|Event.FOCUS)
							}
						window.top.onfocus=null
					}
			}
		return false
	}
	var ctl;
	var ctlParent;
	var ctlPathDisplay1;
	var ctlPathDisplay2;
	var ctlDisplayOrder
	function GetParentUI(Link, ctlName, ctlParentName, oPath1, oPath2, ParentUIID, ExcludeUIID, ItemType, oDisplayOrder, ShowAll)
	{
		ctl= MM_findObj(ctlName);
		ctlParent= MM_findObj(ctlParentName);
		ctlPathDisplay1 = MM_findObj(oPath1); 
		ctlPathDisplay2 = MM_findObj(oPath2); 
		ctlDisplayOrder = MM_findObj(oDisplayOrder); 
		ShowWindow(Link + '?ParentUIID=' + ParentUIID + '&ExcludeUIID=' + ExcludeUIID + '&ItemType=' + ItemType + '&ShowAll=' + ShowAll, 350,420,  true)
	}
	
	function GetUI(Link, ctlName, ctlParentName, oPath, ParentUIID, ExcludeUIID, ItemType, oDisplayOrder, ShowAll, PartID, GroupID)
	{
		ctl= MM_findObj(ctlName);
		ctlParent= MM_findObj(ctlParentName);
		ctlPathDisplay = MM_findObj(oPath); 
		ctlDisplayOrder = MM_findObj(oDisplayOrder); 
		ShowWindow(Link + '?ParentUIID=' + ParentUIID + '&ExcludeUIID=' + ExcludeUIID + '&ItemType=' + ItemType + '&ShowAll=' + ShowAll + '&PartID=' + PartID + '&GroupID=' + GroupID, 350,420,  true)
	}
	
	function ReturnTrans()
    {
		document.forms(0).submit();
    } 
	
	function SetParent(sParent, sParentType, sPath, sDisplayOrder)
    {
		ctl.value = sParent;
		if(ctlParent)ctlParent.value = sParentType;
		ctlPathDisplay1.innerText = sPath;
		if (ctlPathDisplay2!=null)ctlPathDisplay2.innerText = sPath;
		if (ctlDisplayOrder!=null)ctlDisplayOrder.value=sDisplayOrder;
			
    }

	
	function GetDate(Link, CtrlName,time,bShowExpiry)    
    {  
		ctl = MM_findObj(CtrlName);
		if (time==1)
			ShowWindow(Link + 'Calendar.aspx?bShowExpiry=' + bShowExpiry + '&sDate=' + ctl.value + '&time=' + time,300,320,false)
		else
			ShowWindow(Link + 'Calendar.aspx?bShowExpiry=' + bShowExpiry + '&sDate=' + ctl.value ,300,300,false)
    } 
      
    function SetDate(sDate,bShowExpiry)
    {
		ctl.value = sDate;
		if (bShowExpiry)
		{
			if (showExpiryEffect && bShowExpiry)
				showExpiryEffect(ctl);
		}
    }

    function FindInternalLink(PagePath, CtrlName, cssPath,Find)    
    {  
		var popupHeight=350
		var popupWidth=340
		
		ctl = MM_findObj(CtrlName);
		ShowWindow(PagePath + '/FindContact.aspx?Find=' + Find + '&cssPath=' + cssPath,popupWidth,popupHeight,false)
    } 
      
    function SetInternalLink(sName,iContactID)
    {
		var orgid  = ctl.id;
		ctl.value = iContactID;
		ctl = MM_findObj(ctl.id + ':Display');
		ctl.innerHtml = sName;
		ctl = MM_findObj(orgid + ':ContactName');
		ctl.value = sName;
		document.forms(0).submit();
    }
    
    function SetContact(sName,iContactID)
    {
		var ctlhd
		var ctlProcess
		
		ctlhd = MM_findObj(ctl.id + "hd");
		ctlhd.value = sName;
		
		ctlProcess = MM_findObj(ctl.id + "Process");
		if (ctlProcess!=null)
				{
				ctlProcess.value = 1;
				}
		
		ctl = MM_findObj(ctl.id + "ID");
		ctl.value = iContactID;
		
		document.forms(0).submit();
		if (ctlProcess!=null)
				{
				ctlProcess.value = 0;
				}
		
    }
    
    function FindContact(CtrlName, Find)    
    {  
		var popupHeight=450
		var popupWidth=340
		ctl = MM_findObj(CtrlName);
		ShowWindow('FindContact.aspx?Find=' + Find,popupWidth,popupHeight,false)
    } 
    
    
	// New functions added for Reporting functionality...
	function GetReportDate(CtrlName,time)    
    {  
		ctl = MM_findObj(CtrlName);
		if (time==1)
			ShowWindow('../calendar.aspx?bShowExpiry=0&sDate=' + ctl.value + '&time=' + time,300,320,false)
		else
			ShowWindow('../calendar.aspx?bShowExpiry=0&sDate=' + ctl.value ,300,300,false)
    }	
    
    function ReturnDate()
	{
		var now = new Date();   
		return now.getDate()+'/'+eval(now.getMonth()+1)+'/'+now.getFullYear();
	}
	
	function dateAdd( start, interval, number ) {
		
		// Create 3 error messages, 1 for each argument. 
		var startMsg = "Sorry the start parameter of the dateAdd function\n"
			startMsg += "must be a valid date format.\n\n"
			startMsg += "Please try again." ;
			
		var intervalMsg = "Sorry the dateAdd function only accepts\n"
			intervalMsg += "d, h, m OR s intervals.\n\n"
			intervalMsg += "Please try again." ;

		var numberMsg = "Sorry the number parameter of the dateAdd function\n"
			numberMsg += "must be numeric.\n\n"
			numberMsg += "Please try again." ;
			
		// get the milliseconds for this Date object. 
		var buffer = Date.parse( start ) ;
		
		// check that the start parameter is a valid Date. 
		if ( isNaN (buffer) ) {
			alert( startMsg ) ;
			return null ;
		}
		
		// check that an interval parameter was not numeric. 
		if ( interval.charAt == 'undefined' ) {
			// the user specified an incorrect interval, handle the error. 
			alert( intervalMsg ) ;
			return null ;
		}

		// check that the number parameter is numeric. 
		if ( isNaN ( number ) )	{
			alert( numberMsg ) ;
			return null ;
		}

		// so far, so good...
		//
		// what kind of add to do? 
		switch (interval.charAt(0))
		{
			case 'd': case 'D': 
				number *= 24 ; // days to hours
				// fall through! 
			case 'h': case 'H':
				number *= 60 ; // hours to minutes
				// fall through! 
			case 'm': case 'M':
				number *= 60 ; // minutes to seconds
				// fall through! 
			case 's': case 'S':
				number *= 1000 ; // seconds to milliseconds
				break ;
			default:
			// If we get to here then the interval parameter
			// didn't meet the d,h,m,s criteria.  Handle
			// the error. 		
			alert(intervalMsg) ;
			return null ;
		}
		return new Date( buffer + number ) ;
	}
	function Yesterday()
	{
		var d = new Date();
		var i = 'd' ;
		var j = -1 ;
		
		temp = ( dateAdd( d, i, j ) ) ;
		
		if ( temp != null ) return temp.getDate()+'/'+eval(temp.getMonth()+1)+'/'+temp.getFullYear();
 ;
	}
