//Functions to Open Windows
function OpenHelp( filename )
{
	/*var features = 'scrollbars=no,resizable=no';
    var wleft = (screen.height / 2) - (420 / 2);
    var wtop = (screen.availHeight / 2) - (230 /2);
	features += ',width=420,height=230,top='+wtop+',left='+wleft;
	MM_openBrWindow(filename,'',features);
	*/
	var features = 'scrollbars=yes,resizable=yes';
	if(screen.width == 800)
	{
		features += ',width=700,height=500,top=15,left=25';
	}
	else if(screen.width > 800)
	{
		features += ',width=700,height=660,top=25,left=75';
	}
	MM_openBrWindow(filename,'',features);
}

function OpenLargeGraph(filename)
{
	var features = 'scrollbars=yes,resizable=yes';
	if(screen.width == 800)
	{
		features += ',width=700,height=500,top=15,left=25';
	}
	else if(screen.width > 800)
	{
		features += ',width=700,height=660,top=25,left=75';
	}
	MM_openBrWindow(filename,'',features);
}

function OpenBranchReport(filename)
{
	//var features = 'scrollbars=yes,resizable=yes,width=screen.width,height=screen.height,screenX=0,screenY=0';
	var features = 'scrollbars=yes,resizable=yes';
	if(screen.width == 800)
	{
		features += ',width=700,height=500,top=15,left=25';
	}
	else if(screen.width > 800)
	{
		features += ',width=700,height=660,top=25,left=75';
	}
	MM_openBrWindow(filename,'',features);
}

function OpenBranchReportAlert(filename)
{
	//var features = 'scrollbars=yes,resizable=yes,width=screen.width,height=screen.height,screenX=0,screenY=0';
	var features = 'scrollbars=yes,resizable=yes';
	if(screen.width == 800)
	{
		features += ',width=700,height=500,top=15,left=25';
	}
	else if(screen.width > 800)
	{
		features += ',width=700,height=660,top=25,left=75';
	}
	MM_openBrWindow(filename,'',features);
}



function OpenExportWind(filename)
{
	var features = 'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes';	
	if(screen.width == 800)
	{
		features += ',width=700,height=400,top=25,left=50';
	}
	else if(screen.width > 800)
	{
		features += ',width=800,height=610,top=50,left=100';
	}	
	MM_openBrWindow(filename,'',features);
}

function OpenEmailWind(filename)
{
	var features = 'scrollbars=no,resizable=no';
	if(screen.width == 800)
	{
		features += ',width=335,height=430,top=50,left=200';
	}
	else if(screen.width > 800)
	{
		features += ',width=330,height=430,top=200,left=300';
	}
		
	MM_openBrWindow(filename,'',features);
}

function OpenCUSearchWind(filename)
{
	var features = 'scrollbars=yes,resizable=yes';
	if(screen.width == 800)
	{
		features += ',width=700,height=450,top=50,left=50';
	}
	else if(screen.width > 800)
	{
		features += ',width=700,height=610,top=50,left=100';
	}
	MM_openBrWindow(filename,'',features);
}

function OpenCUSearchWindSelf(filename)
{
	self.location.href = filename;
}

function OpenSelectPeerGroupWind(filename)
{
	var features = 'scrollbars=yes,resizable=yes';
	if(screen.width == 800)
	{
		features += ',width=760,height=500,top=10,left=15';
	}
	else if(screen.width > 800)
	{
		features += ',width=807,height=610,top=50,left=100';
	}
	MM_openBrWindow(filename,'',features);
}

function OpenNewWindow(filename)
{
	var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,resizeable=yes"; 
       sOption+="scrollbars=yes,width=750,height=400,left=100,top=26"; 
	var winNewWind =window.open(filename,"",sOption); 
}

function ShowWait()
{
	setTimeout('ShowWaitImage();', 10);
}

function ShowWaitExport()
{
	setTimeout('ShowWaitImageExport();', 10);
}

function ShowWaitImage()
{
	divWait.style.left = (document.body.clientWidth - document.all.imgWait.width)/2;
	divWait.style.top = (document.body.clientHeight - document.all.imgWait.height)/2;
	divBody.style.visibility = "hidden";
	divWait.style.visibility = "visible";
}

function ShowWaitImageExport()
{
	divWaitExport.style.left = (document.body.clientWidth - document.all.imgWait.width)/2;
	divWaitExport.style.top = (document.body.clientHeight - document.all.imgWait.height)/2;
	divBody.style.visibility = "hidden";
	divWaitExport.style.visibility = "visible";
}

function HideWait()
{
	divBody.style.visibility = "visible";
	divWait.style.visibility = "hidden";
}

function HideWaitExport()
{
	divBody.style.visibility = "visible";
	divWaitExport.style.visibility = "hidden";
}

//RefreshParent(close status, CuId, PeerId)
//close status = 0, close current window, refresh main (and large graph if open)
//close status = -1, do not close current window, refresh main (and large graph if open)
//close status = 1, do not close current window, refresh main
function RefreshParent(CloseWin, CuId, PeerId)
{
	if(CloseWin == 0)
	{
		window.close();
	}
	var Control;
	var strStatus = "Loading... Please wait..."
	if(CuId == 0)
	{
		Control = 'ddlTheirPeers';
	}
	else if(PeerId == 0)
	{
		Control = 'ddlTheirCU';
	}
	if (window.opener.opener)
	{ 
		
		if(CloseWin!=1)
		{
			var LargeGraph = window.opener;
			var urlPath = unescape(LargeGraph.location);
			var Query = unescape(LargeGraph.location.search);
			var Left, Right;
			if(CuId == 0)
			{
				Left = Query.substr(0, Query.indexOf('PeerID'));
				Query = Left + 'PeerID=' + PeerId;
			}
			else if(PeerId == 0)
			{
				Left = Query.substr(0, Query.indexOf('CDSID'));
				Right = Query.substr(Query.indexOf('CDSID')-1);
				if(Query.indexOf(',') != -1)
				{
					Right = Query.substr(0,Query.indexOf(',')-1);
				}
				Right = '&'+Right.substr(Right.indexOf('PeerID')-1);
				Query = Left + 'CDSID=' + CuId + Right;
				
			}
			if(urlPath.indexOf('LargeGraph') > -1)
			{
				LargeGraph.location.href = "LargeGraph.aspx" + Query;
			}
			else
			{
				
				LargeGraph.location.href = "FindChart.aspx?" + Query;
			}
			LargeGraph.document.body.innerHTML = "";
			LargeGraph.document.body.style.cursor = "wait"; 
		}
		var Main = window.opener.opener;
		Main.__doPostBack(Control,'');
		Main.document.body.innerHTML = "";
		Main.document.body.style.cursor = "wait"; 
		Main.status = strStatus;
	}
	else
	{			
		var Main = window.opener;
		var urlPath = Main.location.href;
		if(urlPath.indexOf('Find') > -1)
		{					
			var Query = Main.location.search;
			var Left;
			Left = Query.substr(0, Query.indexOf('PeerID'));
			Query = Left + 'PeerID=' + PeerId;	
			Main.location.href = "FindChart.aspx" + Query;			
		}
		else
		{		
			Main.__doPostBack(Control,'');						
		}
		Main.document.body.innerHTML = "";
		Main.document.body.style.cursor = "wait";
		Main.status = strStatus;
	}
}

function Trim(strText)
{
	while(strText.substr(0,1) == " ")
	{
		strText = strText.substr(1,strText.length-1);
	}
	while(strText.substr(strText.length-1) == " ")
	{
		strText = strText.substr(0,strText.length-1);
	}		
	return(strText);
}

function MM_swapImgRestore() { //v3.0
  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() { //v3.0
  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 MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    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);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//Functions for printing the page
function PrintPage()
{
	window.print();
}
function SimplePrinterFriendly(title)
{
	var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes,resizable=yes"; 
	if(screen.width == 800)
	{
		sOption += ',width=600,height=350,top=26,left=100';
	}
	else if(screen.width > 800)
	{
		sOption += ',width=700,height=400,top=100,left=150';
	}
		
   var sWinHTML = document.getElementById('contentstart').innerHTML;
   var winprint = window.open("","",sOption); 
       winprint.document.open(); 
       winprint.document.write('<html><head><title>'+title+'</title><LINK href="http://www.cuanalyzer.com/nav.css" type="text/css" rel="stylesheet"><LINK href="http://calf/webclient/print.css" media="print" type="text/css" rel="stylesheet"></head>');
       winprint.document.write('<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>'); 
       winprint.document.write(sWinHTML);          
       winprint.document.write('<font face=Arial size = 1>Source: Credit Union Analyzer Reports: http://www.CUAnalyzer.com &copy; 2007 Callahan & Associates, Inc.  Phone: 1-800-446-7453</font></body></html>'); 
       winprint.document.close(); 
       winprint.focus();     
}

function PrinterFriendly()
{
	var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes,resizable=yes"; 
	if(screen.width == 800)
	{
		sOption += ',width=600,height=350,top=26,left=100';
	}
	else if(screen.width > 800)
	{
		sOption += ',width=700,height=400,top=100,left=150';
	}
		
   var sWinHTML = document.getElementById('contentstart').innerHTML;
   //Dummy javascript functions for removing the javascript error that may occur on clicking the peer tab data headings
   var sDummyScript = '<script language=javascript>function ChangeCursor(arg1){}function __doPostBack(arg1,arg2){}</script>';
   var winprint = window.open("","",sOption); 
       winprint.document.open(); 
       winprint.document.write('<html><head>'+sDummyScript+'<title>CU Analyzer - Printer Friendly Page</title><LINK href=nav.css rel=Stylesheet></head>');
       winprint.document.write('<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>'); 
       winprint.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
       winprint.document.write('<tr><td width="126" align="left" valign="top">');
       winprint.document.write('<img src="../images/cuanalyzerlogo.gif" border=0></td><td>&nbsp;</td></tr>');
       winprint.document.write('<tr><td width="374" align="left" valign="top"><font color="#999999"><b>');
       winprint.document.write('<font face="Geneva, Arial, Helvetica, san-serif" size="2">');
       winprint.document.write('This is a printer friendly version of the page </font></b></font></td>');
       winprint.document.write('<td align=right><input type=button value=Print onclick=javascript:window.print();></td></tr>');
       winprint.document.write('<tr><td colspan="2" height="7"><hr></td></tr></table>'); 
	   winprint.document.write(sWinHTML);          
       winprint.document.write('</body></html>'); 
       winprint.document.close(); 
       winprint.focus();     
}

//Function to Show and Hide the DisplayText in LargeGraph
function HideShow()
{
activelink = document.Form1.hdnActiveLink.value;
if(activelink == 'More')
{
	document.getElementById('divLargeText').style.visibility = "visible";
	document.getElementById('divSmallText').style.visibility = "hidden";
	document.Form1.hdnActiveLink.value = "Hide";
	//document.Form1.ddlSnippets.style.visibility = "hidden";
	
}
else if(activelink == 'Hide')
{
	document.getElementById('divSmallText').style.visibility = "visible";
	document.getElementById('divLargeText').style.visibility = "hidden";
	document.Form1.hdnActiveLink.value = "More";
	//document.Form1.ddlSnippets.style.visibility = "visible";
}	
}

//To  show the initial text
function ShowHideInitial()
{
	HideWait();	
	document.body.style.cursor='auto';	
	activelink = document.Form1.hdnActiveLink.value;
	if (activelink != "")
	{
		document.getElementById('divLargeText').style.visibility = "hidden";
		document.getElementById('divSmallText').style.visibility = "visible";
		document.Form1.hdnActiveLink.value = "More";				
		//document.Form1.ddlSnippets.style.visibility = "visible";
	}	
	else
	{
		document.getElementById('lnkSmall').style.visibility = "hidden";
		//document.Form1.ddlSnippets.style.visibility = "visible";
	}
}

function HideDropDown()
{
	//document.Form1.ddlSnippets.style.visibility = "hidden";
}

/*function eMailDiv() 
{
	var sWinHTML = document.getElementById('contentstart').innerHTML;
	
	var emailBody ="<html><head><title></title><LINK href=nav.css rel=Stylesheet></head>";
		emailBody +="<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>"; 
		emailBody +="<table width=100% border=0 cellspacing=0 cellpadding=0>";
		emailBody +="<tr><td align=left valign=top>";
		emailBody +=sWinHTML;
		emailBody +="</td></tr></table>"; 
		emailBody +="</body></html>"; 
	
	var emailBody = "<HTML><body><DIV id='Panel2' style='WIDTH: 744px' align='center'><BR><TABLE class='toptext' style=' BORDER-LEFT-COLOR: navy; BORDER-BOTTOM-COLOR: navy; WIDTH: 549px; BORDER-TOP-STYLE: solid; BORDER-TOP-COLOR: navy; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; HEIGHT: 520px; BORDER-RIGHT-COLOR: navy; BORDER-BOTTOM-STYLE: solid' borderColor='darkblue' cellSpacing='0' cellPadding='2' width='549' border='0' ID='Table1'><TBODY><TR><TD rowSpan='2' width='160'><IMG src='http://www.creditunions.com/data/CUanalyzer/images/cuanalyzerlogo.jpg' width='160' border='0' with='100%'></TD><TD align='center' bgColor='#dce0eb' colSpan='3'><DIV align='center'><FONT face='Arial' color='#004983' size='4'><B>CUAnalyzer Report</B></FONT></DIV></TD></TR><TR><TD align='center' width='125' bgColor='#dce0eb'><SPAN id='lblDate' style='FONT-WEIGHT: bold; WIDTH: 99px'>Week ending<BR>6/17/2005</SPAN></TD><TD align='center' width='125' bgColor='#dce0eb'><SPAN id='lblMonth' style='FONT-WEIGHT: bold'>June 2005</SPAN><FONT color='#cc0066'>*</FONT></TD><TD align='center' bgColor='#dce0eb'><STRONG>Total</STRONG></TD></TR></TBODY></TABLE>	<SPAN id='lblFootNote' style='FONT-SIZE: xx-small; COLOR: #cc0000'>* Month is represented from the week holding the first Friday of the month through the week holding the last Friday of the month.</SPAN>	</DIV></body></HTML>"	
		
		/*var winprint = window.open(); 
		winprint.document.open(); 
		winprint.document.write(sWinHTML); 
		winprint.document.close(); 
		winprint.focus();  
       
	
	var	mail_str = "mailto:?subject=CUA Report";
	mail_str += "&body="+emailBody;

	location.href = mail_str;
}*/

//Changing mouse cursor
function ChangeCursor(curtype)
{
	document.body.style.cursor= curtype;
}