var popup = null;
			
function testPopup(msg)
{				
	if(popup != null)
	{
		popup.close();
	}							
}
			
function LaunchSecondWindow(url, target, features)
{
	switch (features)
	{
		case "0":
			features = "toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes";
			break;
		case "1":
			intY = (screen.availHeight/2) - 50;
			intX = (screen.availWidth/2) - 90;
			features = "width=180,height=100,resizable=no,top=" + intY + ",left=" + intX;					
			break;
		case "2":
			features = "width=340,height=422,resizable=no";
			break;
		case "3":
			features = "width=610,height=422,scrollbars=yes";
			break;
		case "4":
			features = "width=610,height=422,status=yes,scrollbars=yes,resizable=yes";
			break;
		case "5":
			features = "width=610,height=422,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes";
			break;
		case "6":
			features = "toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=762,height=422";
			break;
		case "7":	//	SPECIAL FOR START_SEARCH PAGE: Browser attributes for search-results window
			features = "toolbar=yes,status=yes,menubar=yes,scrollbars=no,resizable=yes,width=595,height=422";
			break;					
	}
				
	if (features == null)
	{
		popup = window.open(url, target);
	}
	else
	{
		popup = window.open(url, target, features);
	}
				
	popup.focus();
	return false;
}

function win(fileName){	
	//myFloater = window.open('','MyCylo','height=100%,width=100%,left=20,top=0,menubar=no,status=no,resizable=yes,scrollbars=yes') 
	//myFloater.location.href = fileName; 
	
	var myFloater = null;
	intY = screen.availHeight - 50;
	intX = screen.availWidth - 50;
	features = "left=20,top=0,menubar=no,status=no,resizable=yes,scrollbars=yes,height=" + intY + ",width=" + intX;
	myFloater = window.open(fileName, 'Viewer', features);	
	myFloater.focus();
	return false;
} 

function winSets(fileName){ 
	myFloater = window.open('','MyCylo','height=400,width=600,left=100,top=0,menubar=no,status=no,resizable=yes,scrollbars=yes') 
	myFloater.location.href = fileName; 
} 

function submitFocus(field,e)
{
	var whichCode = (window.Event) ? e.which : e.keyCode;	
	
	if(field.id == "GoogleSearch_q")
	{
		if(whichCode == 13) //Return key
		{	
			//document.getElementById('GoogleSearch_btnSearch').focus();	
			//document.MainForm.GoogleSearch_btnSearch.focus();
			//document.MainForm.GoogleSearch_btnSearch.click();
			//if(document.getElementById('GoogleSearch_btnSearch'))
			//{
			//	alert('1');
			//}
			//else
			//{
			//	alert('2');
			//}		
		}
	}	
	
	if(field.id == "txtUserId")
	{
		if(whichCode == 13) //Return key
		{						
			document.MyCyloFramework.btnLogin.focus();		
		}		
	}	
	
	if(field.id == "txtPassword")
	{
		if(whichCode == 13) //Return key
		{			
			document.MyCyloFramework.btnLogin.focus();				
		}		
	}			
}

function SelectAll(grid, bool)
{
	if(grid == 'Set')
	{
		var pattern = /SelectCheckBoxSet/i;
		var elements = document.getElementsByTagName("input");
		for(var i = 0; i < elements.length; i++)
		{
			if(pattern.test(elements[i].id))
			{
				elements[i].checked = bool;
			}
		}
	}
	else
	{
		var pattern = /SelectCheckBox/i;
		var elements = document.getElementsByTagName("input");
		for(var i = 0; i < elements.length; i++)
		{
			if(pattern.test(elements[i].id))
			{
				elements[i].checked = bool;
			}
		}
	}
}

function SetCurrentYear()
{
	var thedate = new Date( );
	var theyear = thedate.getYear( );
	spnCurrentYear.innerHTML = theyear;
}

function SetGoogleFocus()
{
	document.MainForm.GoogleSearch_q.focus();
}

//http://www.faqts.com/knowledge_base/view.phtml/aid/8308
//document.onkeydown = // assumes not handled at lower level
//  function ()
//    {
//    var whichCode = (window.Event) ? event.which : event.keyCode;
    
//    if (event.ctrlKey)
 //     {
//      event.cancelBubble = true // assumes you want to block it
//      event.returnValue = false // assumes you want to kill it
      //...call to your local CTRL key handler goes here...
 //     return false // assumes you want to kill it
 //     }
//    else if(whichCode == 13)
//      {
//		document.login.btnLogin.click();
//      }
//    else return true
//    }


function numbersOnly(field,e)
{
	var key = '';
	var strCheck = '0123456789.-';
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}

function numbersOnlyPaging(field,e)
{
	var key = '';
	var strCheck = '0123456789';
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}

function loginOnEnterKey(e)
{
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) // Enter
	{
	
		return true;  
	}
}


//http://www.sitepoint.com/article/1022			
var NS = (navigator.appName=="Netscape")?true:false; 
			
//Note: Images will load at top=0 left=200
					
//Variables used for resizing.
			var sizeW = 0, sizeH = 0;			

function FitPic()
{ 
			iWidth = (NS)?window.innerWidth:document.body.clientWidth; 
			iHeight = (NS)?window.innerHeight:document.body.clientHeight; 
			//iWidth = document.images[0].width - iWidth; 
			//iHeight = document.images[0].height - iHeight;
			
			iWidth = document.getElementById('imgPic').width - iWidth; 
			iHeight = document.getElementById('imgPic').height - iHeight;			
			
			//Set default values for resize function			
			//sizeW = document.images[0].width + 30; 
			//sizeH = document.images[0].height + 42;	
			
			sizeW = document.getElementById('imgPic').width + 32; 
			sizeH = document.getElementById('imgPic').height + 88;					
			
			//Test values
			//testW = (screen.width - 200) - (sizeW);
			testW = (screen.width - 20) - (sizeW);
			testH = (screen.height - 30) - (sizeH);
			
			if(testW < 0)	
			{	
				//Adjusted image width is wider than adjusted screen width.			
				//sizeW = screen.width - 200;	
				sizeW = screen.width - 20;				
			}
			
			if(testH < 0)
			{	
				//Adjusted image height is taller than adjusted screen height.				
				sizeH = screen.height - 30;				
			}		
			
			//window.resizeBy(sizeW, sizeH); -->Different way to resize.
			window.resizeTo(sizeW, sizeH);
			self.focus(); 
}
