﻿Page = {};

Page.resize = function() {
	var header = document.getElementById('header');
	var footer = document.getElementById('footer');
	var content = document.getElementById('content');
	var details = document.getElementById('details');
	var myaccountImage = document.getElementById('imgMyAccount');
	var pageHeight,pageWidth;
	
	// Various things required for different browsers. Firefox uses the minHeight property
	// and the offsetHeight property is not set until after the page is loaded
	
	            
	
	//alert('Header Height: ' + header.offsetHeight);
	//alert('Footer Height: ' + footer.offsetHeight);
	//alert('window.height: ' + window.height);
    //alert('document.body.scrollHeight: ' +  document.body.scrollHeight);
	//alert('document.body.offsetHeight: ' +  document.body.offsetHeight);
	//alert('document.body.offsetTop: ' +  document.body.offsetTop);
	//alert('window.innerHeight: ' +  window.innerHeight);
	//alert('window.scrollMaxY: ' +  window.scrollMaxY);

    pageHeight = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
    //pageHeight = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight); 
    
    //alert('Page Height: ' + pageHeight);
    window.status = "Resizing...";
    
	var contentHeight = (pageHeight - (header.offsetHeight + footer.offsetHeight) - 25);

    if (contentHeight < 8000) {
        // To prevent it from recursively calling itself which for some reason it does
        // rarely.
	    // The div tag
	    
	    content.style.minHeight = contentHeight + "px";
	    content.style.height = contentHeight + "px";
    		
	    // The table
	    details.style.minHeight = contentHeight+"px";
	    details.style.height = contentHeight+"px";
    	    	   	
        // Repos the myaccount image
	    myaccountImage.style.top = (contentHeight-19) + "px";      //  IE -19 seems to work. FF needs px
        myaccountImage.style.visibility = "";
        
    }
    window.status = "Done";
}

//onload = onresize = Page.resize;   onresize upsets the large pages like contacts.aspx

function old() {
	if( window.innerHeight && window.scrollMaxY ) // Firefox 
	    {
            alert('Firefox');
            pageWidth = window.innerWidth + window.scrollMaxX;
            pageHeight = window.innerHeight + window.scrollMaxY;
        }
    else if( document.body.scrollHeight > document.body.offsetHeight ) 
        // all but Explorer Mac
        {
            alert('Non Mac');
            pageWidth = document.body.scrollWidth;
            pageHeight = document.body.scrollHeight;
        }
        else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        { 
            //alert('Explorer 6 Strict, Mozilla');
            pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
            pageHeight = document.body.offsetHeight + document.body.offsetTop; 
        }
        
        pageHeight = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
}        


function validateForm() {
// Routine to check that all the appropriate fields have been entered.

var sTmp = '', sMiss = ''
var oObj
var o1st, o1stFld
var x
var tag
var bMin = false
var bAtLeastOne = false

//  Must set these defaults to use in comparisons later
try {
    for (x in document.all) {
        oObj = document.all[x]
        if (oObj.tagName) {
            tag = oObj.tagName.toUpperCase()
            if (tag == 'INPUT' || tag == 'SELECT' || tag == 'TEXTAREA') {
		        if (oObj.style.visibility.toUpperCase() != 'HIDDEN') {
		            //alert(oObj.id + ' is visible')
		            
			        if (oObj.className.toUpperCase() == 'COMPULSORY') {
			            bAtLeastOne = true
			            if (oObj.value == '') {
				            if (!o1st) o1st = oObj
        					    
				            if (oObj.title)
					            sMiss = sMiss + ', ' + oObj.title.toLowerCase()
				            else
					            sMiss = sMiss + ', ' + oObj.name.toLowerCase()
                            }
			            else
				            bMin = true
				        }
			        else {
				        //  If the object has some information and 
				        //  the minimum information hasn't been set then set it
				        //alert(oObj.id + ' is not compulsory, and it is a ' + oObj.type + ' object')
				        if (oObj.type.toUpperCase() == 'TEXT') {        								
					        if (! o1stFld) o1stFld = oObj        				
					        if (oObj.value != '' && ! bMin) bMin = true					        
				            }
			            }
                    }	
		        else {
			        // If find a hidden text object then don't worry about the minimum
			        bMin = true 
		            }
	            }
         }   // has a tagname
	    
    }   // end for	        


    //  Set the first field to be the first other text field if not found
    if (! o1st)
        o1st = o1stFld

    if (sMiss) {
	    sMiss = putInAnd(sMiss.substring(2))
	    alert('Please enter all the compulsory information. You are missing the ' + sMiss + '.')
	    //  Ignore any errors with this one
	    o1st.focus()
	    return false
	    }
    else {
	    if (! bMin && bAtLeastOne) {
		    alert('You have not filled in the required information. Please complete more of it.')
		    //  Ignore any errors with this one
		    if (o1st) o1st.focus()
		    return false
		    }
	    else
		    return true
    }
}
catch(err) {
    var txt
    txt='There was an error on this page.\n\n'
    txt+='validateForm() Error: ' + err.description + '\n\n'
    txt+='Click OK to continue.\n\n'
    alert(txt)
  }

}

