﻿// JScript File

    function absoluteTop(control) {
      if( typeof( control.offsetParent ) != 'undefined' ) {
        for( var posX = 0, posY = 0; control; control = control.offsetParent ) {
          posY += control.offsetTop;
        }
        return posY;
      } else {
        return control;
      }
    }
    
    function absoluteLeft(control) {
      if( typeof( control.offsetParent ) != 'undefined' ) {
        for( var posX = 0, posY = 0; control; control = control.offsetParent ) {
          posX += control.offsetLeft;
        }
        return posX;
      } else {
        return control.x;
      }
    }
            
    function getWindowHeight() {
        var myHeight = 0;
        if( typeof( window.innerWidth ) == 'number' ) {
            //Non-IE
            myHeight = window.innerHeight;
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myHeight = document.documentElement.clientHeight;
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            myHeight = document.body.clientHeight;
        }    
        return myHeight;
    }
    
    function getWindowWidth() {
        var myWidth = 0;
        if( typeof( window.innerWidth ) == 'number' ) {
            //Non-IE
            myWidth = window.innerWidth;
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
        }    
        return myWidth;
    }
         
    function InvalidDate(txtCtl) 
    { 
       var RegExp=/^(0?[1-9]|10|11|12)[/](0?[1-9]|[12][0-9]|30|31)[/](\d{4})$/ 
       strSource=txtCtl.value;
        
       if(!strSource.length) 
       {
            alert('The value you entered is not a valid date');
           return false; 
        }

       var Parts=strSource.match(RegExp); 
       if(!Parts) 
       {
            alert(Parts);
            return true; 
       }
       else 
       { 
           var Month=parseInt(Parts[1]),Day=parseInt(Parts[2]),Year=parseInt(Parts[3]); 
           var bInvalid=((Month==4||Month==6||Month==9||Month==11)&&Day==31)||(Month==2 && (Day>29 ||(Day==29 && !Year%4 && Year%100))) 
           if(!bInvalid)if(Year<1753)txtCtl.value="01/01/1753" 
           if (bInvalid)
           {
             alert('The value you entered is not a valid date');
             return false;
           }
           else
             return true;
       } 
} 

function isNumeric(sText) { 
   var ValidChars = "-0123456789."; 
   var Char;
   for (i = 0; i < sText.length; i++) {
       Char = sText.charAt(i);
       if (ValidChars.indexOf(Char) == -1) {
          return false;
       }
    }
   return true;
}

function getNumber(value) {
    if (value.charAt(0)=='£') { value = value.substring(1,value.length); }
    value = value.replace(/^\s+|\s+$/g, '') ;
    value = value.replace(',', '') ;    
    var output = parseFloat(value);
    if(isNaN(output)) {
        return 0; }
    else {
       return output; }
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

window.onload = init;

var curX = 0;
var curY = 0;

function init() {      
    if(document.all) window.attachEvent('onmousemove', MoveHandlerIE)
        else window.addEventListener('mousemove', MoveHandler , false)
}

function MoveHandler(e) {
    curX = e.pageX;
    curY = e.pageY;
}
 
function MoveHandlerIE() {
    curX = window.event.x + document.body.scrollLeft;
    curY = window.event.y + document.body.scrollTop;
}

function getXY(e) {
    curX = (window.Event) ? e.pageX : event.clientX;
    curY = (window.Event) ? e.pageY : event.clientY;
}      

function displayPleaseWait()
{    
    document.getElementById('PleaseWaitContainer').style.display = 'block';
    nHeight = getWindowHeight();
    nWidth = getWindowWidth();
    nTopOffset = (nHeight - document.getElementById('PleaseWaitContainer').offsetHeight) / 2;
    nLeftOffset = (nWidth - document.getElementById('PleaseWaitContainer').offsetWidth) / 2;
    document.getElementById('PleaseWaitContainer').style.top = document.documentElement.scrollTop + nTopOffset + 'px';
    document.getElementById('PleaseWaitContainer').style.left = document.documentElement.scrollLeft + nLeftOffset + 'px';
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function resizeFrame()
{
    nHeight = getWindowHeight();
    nWidth = getWindowWidth();
    document.getElementById('DisablePage').style.height = nHeight + 'px';
    document.getElementById('DisablePage').style.width = nWidth + 'px';
    document.getElementById('PictureViewerFrame').document.body.style.height = document.getElementById('PictureViewerFrame').style.height;
    document.getElementById('PictureViewerFrame').document.body.style.width = document.getElementById('PictureViewerFrame').style.width;
 }
       