// Suckerfish :focus routine. http://www.htmldog.com/articles/suckerfish/focus/
sfFocus = function() { var sfEls = document.getElementsByTagName("INPUT"); for (var i=0; i<sfEls.length; i++) {	sfEls[i].onfocus=function() { this.className+=" sffocus"; } 
sfEls[i].onblur=function() { this.className=this.className.replace(new RegExp(" sffocus\\b"), ""); } } }//Enable form submits
function enableSubmit(enable) { var forms = document.getElementsByTagName("form"); for (var i = 0; i < forms.length; i++) { for(j=0; j<forms[i].elements.length; j++) { if(forms[i].elements[j].type=="submit" || forms[i].elements[j].type=="reset"){ forms[i].elements[j].disabled = !enable; } } } }

//Set focus to first input field
function initialInputFocus(){var bFound=false;for(f=0;f<document.forms.length;f++){if(document.forms[f].id&&startsWith(document.forms[f].id,"ignore")){continue}for(i=0;i<document.forms[f].length;i++){if(document.forms[f][i].id&&startsWith(document.forms[f][i].id,"ignore")){continue}if(document.forms[f][i].type&&document.forms[f][i].type!="hidden"&&document.forms[f][i].type!="undefined"){if(document.forms[f][i].disabled!=true){document.forms[f][i].focus();var bFound=true}}if(bFound==true)break}if(bFound==true)break}}
function startsWith(str,prefix){if(prefix.length>str.toString().length)return false;return str.toString().indexOf(prefix)==0}


// Ensure form only submitted a single time
//var submitted = 0;
//function singleSubmit() { if(!submitted) { submitted ++; return true; } else { return false; } }
function singleSubmit(form) { for(i=0; i<form.elements.length; i++){ if(form.elements[i].type=="submit" || form.elements[i].type=="reset"){ form.elements[i].disabled=true; } } }

function addHiddenField(element, name, value) { var field = document.createElement("input"); field.setAttribute("type","hidden"); field.setAttribute("name",name); field.setAttribute("value",value); element.appendChild(field); }

// Close overlay window, supports submodal and lytebox
function closeOverlay() { if(parent.myLytebox) { parent.myLytebox.end(); } else { window.top.hidePopWin(true); } }

// Get Window Width
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 getParameter(name){var q=document.location.search;var i=q.indexOf(name+'=');if(i==-1){return false}var r=q.substr(i+name.length+1,q.length-i-name.length-1);i=r.indexOf('&');if(i!=-1){r=r.substr(0,i)}return r.replace(/\+/g,' ')}

function getPath(script){var i,nl=document.getElementsByTagName('script');for(i=0;i<nl.length;i++){if(nl[i].src&&nl[i].src.indexOf(script)!=-1){return nl[i].src.substring(0,nl[i].src.indexOf(script))}}}

function endsWith(str, suffix){
    if(suffix.length > str.length) return false;
    return str.indexOf(suffix)==(str.length-suffix.length);
}



function toggle(id){var element=document.getElementById(id);if(element){if(element.style.display=='none'){element.style.display=''}else{element.style.display='none'}}}

function toggleFields(fields,field){for(i=0;i<fields.length;i++){if(field!=fields[i]){fields[i].checked=field.checked}}}

//Function to call all page initialization functions
function pageInit() { sfFocus(); initialInputFocus(); enableSubmit(true); }
//if (window.attachEvent) window.attachEvent("onload", pageInit);
window.onload = pageInit;


