var boxWidth = 240; //boxWidth including left and right padding var topPosition = 17; //topPosition of Search box based on top position of Search link var rightPosition = 20; //rightPosition from window border function setScrollingObjects() { positionSearchBox(); } window.onresize = setScrollingObjects; function showSearch() { if (document.getElementById('searchContainer').className != "searchContainerShow") { positionSearchBox(); document.getElementById('searchLink').className = "searchLinkOn"; document.getElementById('searchContainer').style.display = "block"; document.getElementById('searchContainer').className = "searchContainerShow"; document.getElementById('dnn_dnnDTSEARCHSO_SearchInput').focus(); } } function hideSearch() { document.getElementById('searchLink').className = "searchLink"; document.getElementById('searchContainer').className = "searchContainer"; document.getElementById('searchContainer').style.display = "none"; } function findPos(obj) { var curleft = curtop = 0; if (obj != null && obj != 'undefined') { if (obj.offsetParent) { do { curleft += obj.offsetLeft; curtop += obj.offsetTop; } while (obj = obj.offsetParent); } return [curleft, curtop]; //return curleft; } } function positionSearchBox() { var objSearchLink = document.getElementById('searchLink'); if (objSearchLink != null && objSearchLink != 'undefined') { var windowWidth = document.body.clientWidth; var searchLinkPos = findPos(document.getElementById('searchLink')); var searchLinkLeftPos = searchLinkPos[0]; var searchLinkTopPos = searchLinkPos[1]; var widthNeeded = searchLinkLeftPos + boxWidth + rightPosition; //Check if link position plus search box size will fit inside the browser window. if (document.getElementById('searchContainer').className == "searchContainerShow") { if (windowWidth > widthNeeded) { document.getElementById('searchContainer').style.left = searchLinkLeftPos + 'px'; } else { document.getElementById('searchContainer').style.left = (windowWidth - boxWidth - rightPosition) + 'px'; } } else if (windowWidth < searchLinkLeftPos) { document.getElementById('searchContainer').style.left = (searchLinkLeftPos - boxWidth) + 'px'; } else if (windowWidth < widthNeeded) { document.getElementById('searchContainer').style.left = searchLinkLeftPos - (widthNeeded - windowWidth) + 'px'; } else { document.getElementById('searchContainer').style.left = searchLinkLeftPos + 'px'; } //Set top position based on top of Search link. document.getElementById('searchContainer').style.top = (searchLinkTopPos + topPosition) + 'px'; } }