// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
// http://javascript.about.com/library/blscreen1.htm
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}

//http://www.hunlock.com/blogs/Totally_Pwn_CSS_with_Javascript
//The example code and concepts, unless otherwise noted, are released into the public domain and may be used and modified without compensation or attribution.

function getCSSRule(ruleName, deleteFlag) {               // Return requested style obejct
   ruleName=ruleName.toLowerCase();                       // Convert test string to lower case.
   if (document.styleSheets) {                            // If browser can play with stylesheets
      for (var i=0; i<document.styleSheets.length; i++) { // For each stylesheet
         var styleSheet=document.styleSheets[i];          // Get the current Stylesheet
         var ii=0;                                        // Initialize subCounter.
         var cssRule=false;                               // Initialize cssRule. 
         do {                                             // For each rule in stylesheet
            if (styleSheet.cssRules) {                    // Browser uses cssRules?
               cssRule = styleSheet.cssRules[ii];         // Yes --Mozilla Style
            } else {                                      // Browser usses rules?
               cssRule = styleSheet.rules[ii];            // Yes IE style. 
            }                                             // End IE check.
            if (cssRule)  {                               // If we found a rule...
               if (cssRule.selectorText.toLowerCase()==ruleName) { //  match ruleName?
                  if (deleteFlag=='delete') {             // Yes.  Are we deleteing?
                     if (styleSheet.cssRules) {           // Yes, deleting...
                        styleSheet.deleteRule(ii);        // Delete rule, Moz Style
                     } else {                             // Still deleting.
                        styleSheet.removeRule(ii);        // Delete rule IE style.
                     }                                    // End IE check.
                     return true;                         // return true, class deleted.
                  } else {                                // found and not deleting.
                     return cssRule;                      // return the style object.
                  }                                       // End delete Check
               }                                          // End found rule name
            }                                             // end found cssRule
            ii++;                                         // Increment sub-counter
         } while (cssRule)                                // end While loop
      }                                                   // end For loop
   }                                                      // end styleSheet ability check
   return false;                                          // we found NOTHING!
}                                                         // end getCSSRule 

function killCSSRule(ruleName) {                          // Delete a CSS rule   
   return getCSSRule(ruleName,'delete');                  // just call getCSSRule w/delete flag.
}                                                         // end killCSSRule

function addCSSRule(ruleName) {                           // Create a new css rule
   if (document.styleSheets) {                            // Can browser do styleSheets?
      if (!getCSSRule(ruleName)) {                        // if rule doesn't exist...
         if (document.styleSheets[0].addRule) {           // Browser is IE?
            document.styleSheets[0].addRule(ruleName, null,0);      // Yes, add IE style
         } else {                                         // Browser is IE?
            document.styleSheets[0].insertRule(ruleName+' { }', 0); // Yes, add Moz style.
         }                                                // End browser check
      }                                                   // End already exist check.
   }                                                      // End browser ability check.
   return getCSSRule(ruleName);                           // return rule we just created.
}

function parseDate(yearOnlyFlag) {

	// get a date object
	var d=new Date();
	
	// add a 0 to the month if it's only one digit
	var dmonth = d.getMonth() + 1;
	if (dmonth < 10) { dmonth = "0" + dmonth; }
	
	// add a 0 to the day if it's only one digit
	var dday = d.getDate();
	if (dday < 10) { dday = "0" + dday;	}
	
	// year
	var dyear = d.getFullYear();
	
	// set a global variable to a formatted date string
	dateToday = dyear + " " + dmonth + " " + dday;
	
	if (yearOnlyFlag == true) {
		return dyear;
	} else {
		return dateToday;
	}
	
}

    function onloadifcontent() {

   
        // reset the iframe
        setIframeHeight('ifcontent',0);

        // set the iframe height according to it's contents
        // IE6 only works with this, Safari seems to like it better also
        if ((navigator.userAgent.indexOf('Safari') > -1) || (navigator.userAgent.indexOf('IE 6') > -1)) {
            setIframeHeight('ifcontent',document.getElementById('ifcontent').contentWindow.document.body.scrollHeight);
        } else {
            if (navigator.userAgent.indexOf('Opera') > -1) {
                setIframeHeight('ifcontent',document.getElementById('ifcontent').contentWindow.document.body.scrollHeight); //who knows why Opera needs this
            }
            setIframeHeight('ifcontent',document.getElementById('ifcontent').contentWindow.document.documentElement.scrollHeight);
        }
        
    }

     
    function setIframeHeight(iframeName,iframeHeight) {

        //alert(iframeName + ': ' + iframeHeight);

        var iframeNameElement = document.getElementById(iframeName);
        var iframePageHeight;
        //iframePageHeight = (pageHeight() * 2);
        iframePageHeight = (pageHeight()-70); //pageheight - header - footer

        if (iframeHeight==0) {
            iframeNameElement.style.height = iframePageHeight + "px"; 
        } else {

            //alert(iframePageHeight + ', ' + iframeHeight);
   
            if (iframePageHeight > iframeHeight) {
                iframeNameElement.style.height = iframePageHeight + "px";
            } else {
                iframeNameElement.style.height = iframeHeight + "px";
            }
        }

    }


// modify the style sheet width using javascript for the centered and footer div's
function doOnResizeTasks() {

    return true;
    
	var minWidth = 923;
	var maxWidth = 1100;
	
	var centeredWidth=Math.round(pageWidth()*0.90);
	if (centeredWidth<minWidth) { centeredWidth=minWidth; }
	if (centeredWidth>maxWidth) { centeredWidth=maxWidth; }
	
	if (navigator.userAgent.indexOf('Safari') > -1)  {
		document.body.style.overflow='scroll';
   	}

	// modify the CSS style elements
	var centeredElementCSS = getCSSRule('#div_centered');
	var footerElementCSS = getCSSRule('#div_footer');

	centeredElementCSS.style.width=centeredWidth + 'px';
	footerElementCSS.style.width=centeredWidth + 'px';
}


// set window events to re-adjust on resize
window.onresize = function () { doOnResizeTasks(); setTimeout("onloadifcontent();",100);}
window.onload = function () { doOnResizeTasks(); } // safari needs this







