/** Function to calculate window height @return windowHeight Integer window height */ function getWindowHeight() { var windowHeight = 0; if (typeof(window.innerHeight) == 'number') { windowHeight = window.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { windowHeight = document.documentElement.clientHeight; } else if (document.body && document.body.clientHeight) { windowHeight = document.body.clientHeight; } return windowHeight; } /** Function to calculate window width @return windowWidth Integer window height */ function getWindowWidth() { var windowWidth = 0; if (typeof(window.innerWidth) == 'number') { windowWidth = window.innerWidth; } else if (document.documentElement && document.documentElement.clientWidth) { windowWidth = document.documentElement.clientWidth; } else if (document.body && document.body.clientWidth) { windowWidth = document.body.clientWidth; } return windowWidth; } /** Function to position footer block on page using CSS and W3C DOM */ function setFooter() { if (document.getElementById) { var windowHeight = getWindowHeight(); if (windowHeight > 0) { var contentHeight = document.getElementById('content').offsetHeight; var footerElement = document.getElementById('footer'); var footerHeight = footerElement.offsetHeight; if (windowHeight - (contentHeight + footerHeight) >= 0) { footerElement.style.position = 'relative'; footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px'; } else { footerElement.style.position = 'static'; } } } } function setMenuImage() { var imgNo = parseInt(Math.floor((Math.random() * 6)) + 1, 10); document.getElementById('menuImage').src = 'images/general/menu' + imgNo + '.jpg'; document.getElementById('menuImage').className = 'noprint'; } window.onload = function() { setFooter(); setMenuImage(); onLoadFunction(); handleOnSubmit(); } window.onresize = function() { setFooter(); } /** Function to add preventDoubleClick() call to the existing onsubmit event handler */ function handleOnSubmit(){ var theForm = document.forms[0]; if(!theForm){return;} if(theForm.onsubmit){ var fOriginalSubmit=theForm.onsubmit; fOriginalSubmit=(fOriginalSubmit.toString()).replace(/this/,'document.forms[0]'); //alert(fOriginalSubmit); //theForm.onsubmit=new Function("if("+fOriginalSubmit+"()==true){return preventDoubleClick();}else{return false;}"); theForm.onsubmit=new Function("return ( "+fOriginalSubmit+"() && preventDoubleClick() );"); }else{ theForm.onsubmit=new Function("return preventDoubleClick();"); } } /** Function to prevent double click */ var DOUBLE_CLICK_COUNTER=0; var CLICK_TIME=0; var NUMBER_OF_SECONDS_TO_WAIT=5; var DOUBLE_CLICK_ALERT_MESSAGE="This form has already been submitted\nPlease wait..."; //will be translated function preventDoubleClick(){ if(CLICK_TIME == 0){ var tDate = new Date; CLICK_TIME = tDate.valueOf(); } DOUBLE_CLICK_COUNTER++; var trapTheClick = false; if(DOUBLE_CLICK_COUNTER > 1 ) { trapTheClick = true; var tDate = new Date; var secondClickTime = tDate.valueOf(); //alert('DOUBLE_CLICK_COUNTER='+DOUBLE_CLICK_COUNTER+'; CLICK_TIME='+CLICK_TIME+'; secondClickTime='+secondClickTime+'; diff='+(secondClickTime - CLICK_TIME)); if((secondClickTime - CLICK_TIME) > (NUMBER_OF_SECONDS_TO_WAIT * 1000)) { CLICK_TIME = 0; trapTheClick = false; DOUBLE_CLICK_COUNTER = 0; } } var valueToReturn = true; if(trapTheClick == true) { valueToReturn = false; alert(DOUBLE_CLICK_ALERT_MESSAGE); } return valueToReturn; }