/******************************************************************
	TIMETRAK JAVASCRIPT FILE - WINDOWS
	(c) Copyright 2010 Exosoft
******************************************************************/

/* Open URL in Modal Window */
function openModalWindow(url, w, h){
	if (isIE7()) h -= 20;
	if (window.showModalDialog){
		var result = window.showModalDialog(url,'','dialogHeight: ' + h + 'px; dialogWidth: ' + w + 'px; edge: Raised; center: Yes; help: No; resizable: No; status: No; scroll: No;');
		return getModalResult(result);
	} else {
		openWindow(url,w,h);
		return false;
	}
}

/* Open URL in Modal Window */
function openModalWindow(url, w, h, windowName){
	if (isIE7()) h -= 20;
	if (window.showModalDialog){
		var result = window.showModalDialog(url,'','dialogHeight: ' + h + 'px; dialogWidth: ' + w + 'px; edge: Raised; center: Yes; help: No; resizable: No; status: No; scroll: No;');
		return getModalResult(result);
	} else {
		openWindow(url,w,h,windowName);
		return false;
	}
}

/* Get the result from the modal dialog */
function getModalResult(result){
	if ((result==true)||(result=='true')){
		return true;
	} else if ((result==false)||(result=='false')){
		return false;
	} else if (typeof(result)=='undefined'){
		return false;
	} else {
		return result;
	}
}

/* Open URL and Maximise Window */
function openMax(url){
	try{
		windowHandle = window.open(url,'myWindow','resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,copyhistory=0,top=0,left=0');
		maximiseWindow(windowHandle);
		if (!windowHandle.opener) windowHandle.opener=self;
		windowHandle.focus();
	} catch(ex){
	}
}

/* New Window */
function newWindow(url, windowName){
	try{
		windowHandle=window.open(url,windowName);
		if (!windowHandle.opener) windowHandle.opener=self;
		centerOnScreen(windowHandle,w,h);
		windowHandle.focus();
	} catch(ex){
	}
}

/* New Window */
function newWindow(url,w,h){
	try{
		windowHandle=window.open(url,'','width='+w+',height='+h+',toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
		windowHandle.resizeTo(w,h);
		if (!windowHandle.opener) windowHandle.opener=self;
		centerOnScreen(windowHandle,w,h);
		windowHandle.focus();
	} catch(ex){
	}
}

/* Open New Window */
function openWindow(url,w,h){
	try{
		windowHandle=window.open(url,'myWindow','resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,copyhistory=0,top=0,left=0,width=' + w + ',height=' + h);
		windowHandle.resizeTo(w,h);
		centerOnScreen(windowHandle,w,h);
		if (!windowHandle.opener) windowHandle.opener=self;		
		windowHandle.focus();
	} catch(ex){
	}
}

/* Open New Window */
function openWindow(url,w,h,windowName){
	try{
		windowHandle=window.open(url,windowName,'resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,copyhistory=0,top=0,left=0,width=' + w + ',height=' + h);
		windowHandle.resizeTo(w,h);
		centerOnScreen(windowHandle,w,h);
		if (!windowHandle.opener) windowHandle.opener=self;		
		windowHandle.focus();
	} catch(ex){
	}
}

/* Open New Window Fit to Screen */
function openFitWindow(url,windowName){
	try{
		var w = screen.availWidth - 40;
		var h = screen.availHeight - 40;
		windowHandle=window.open(url,windowName,'resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,copyhistory=0,top=0,left=0,width=' + w + ',height=' + h);
		windowHandle.resizeTo(w,h);
		centerOnScreen(windowHandle,w,h);
		if (!windowHandle.opener) windowHandle.opener=self;
		windowHandle.focus();
	} catch(ex){
	}
}

/* Center new Window on screen */
function centerOnScreen(winRef,w,h){
	xW = w / 2;
	xH = h / 2;
	w = screen.availWidth / 2;
	h = screen.availHeight / 2;
	winRef.moveTo(w-xW,h-xH);
}

/* Maximise Window */
function maximiseWindow(winRef){
	if (window.screen) {
		winRef.moveTo(-5,-5);
		winRef.resizeTo(screen.availWidth+10,screen.availHeight+10);
	}
}

/* Is Internet Explorer 7 */
function isIE7(){
	if (window.navigator.appVersion.indexOf('MSIE 7.0') > -1)
		return true
	else
		return false;	
}

/* Window Properties */

function getWidth(){
	if (self.innerWidth) { 
		return self.innerWidth; 
	} else if( document.documentElement && document.documentElement.clientWidth ) { 
		return document.documentElement.clientWidth; 
	} else if( document.body ) { 
		return document.body.clientWidth; 
	} else {
		return 0;
	} 
}

function getHeight(){
	if (self.innerHeight) { 
		return self.innerHeight; 
	} else if( document.documentElement && document.documentElement.clientHeight ) { 
		return document.documentElement.clientHeight; 
	} else if( document.body ) { 
		return document.body.clientHeight; 
	} else {
		return 0;
	} 
}

function getTop(){
	if( self.pageYOffset ) {
		return self.pageYOffset; 
	} else if( document.documentElement && document.documentElement.scrollTop ) { 
		return document.documentElement.scrollTop; 
	} else if( document.body ) { 
		return document.body.scrollTop; 
	} else {
		return 0;
	}
}

function getLeft(){
	if( self.pageXOffset ) {
		return self.pageXOffset; 
	} else if( document.documentElement && document.documentElement.scrollLeft ) { 
		return document.documentElement.scrollLeft; 
	} else if( document.body ) { 
		return document.body.scrollLeft; 
	} else {
		return 0;
	}
}

/* centerDiv */
function centerDiv(xWidth, yHeight, divId) {

	// First, determine how much the visitor has scrolled 
	var scrolledX = getLeft();
	var scrolledY = getTop();
		
	// Next, determine the coordinates of the center of browser's window 
	var centerX = getWidth();
	var centerY = getHeight(); 
	
	// xWidth is the width of the div, yHeight is the height of the div passed as arguments to the function: 
	var leftOffset = scrolledX + (centerX - xWidth) / 2; 
	var topOffset = scrolledY + (centerY - yHeight) / 2;
	
	// The initial width and height of the div can be set in the 
	// style sheet with display:none; divId is passed as an argument to the function 
	var o = document.getElementById(divId);
	var r = o.style; 
	r.position = 'absolute'; 
	r.top = topOffset + 'px'; 
	r.left = leftOffset + 'px'; 
	r.display = 'block';

} 

/* showModalIFrame */
function showModalIFrame(iFrameId, modalId, width, height){

	// Show Modal Background
	var o = document.getElementById(modalId);
	var r = o.style;
	r.position = 'absolute';
	r.top = getTop() + 'px';
	r.left = getLeft() + 'px';
	r.width = getWidth() + 'px';
	r.height = getHeight() + 'px';
	r.display = 'block';
	r.zIndex = 9;
	r.opacity = 0.10;
	r.backgroundColor = '#333333';
	r.filter = 'alpha(opacity=10)';
			
	// Show IFrame
	var o = document.getElementById(iFrameId);
	var r = o.style;
	r.zIndex = 10;
	r.display = 'block';
		
	// Center IFrame
	centerDiv(width, height, iFrameId);
	
}

/* hideModalIFrame */
function hideModalIFrame(iFrameId, modalId){

	// Show Modal Background
	var o = document.getElementById(modalId);
	var r = o.style;
	r.display = 'none';
	
	// Show IFrame
	var o = document.getElementById(iFrameId);
	var r = o.style; 
	r.display = 'none';

}

