function getBaseURL() { if (typeof(SITE_CAPE) != "undefined" && SITE_CAPE) { return "http://capetown.capeads.co.za/"; } else { return "http://www.junkmail.co.za/"; } } function getImageAssetsBaseURL() { if (typeof(SITE_CAPE) != "undefined" && SITE_CAPE) { return "http://capetown.capeads.co.za/"; } else { return "http://www.junkmail.co.za/"; } } /** * Does a document.getElementById() on our site structure. * * Always ensures to be executed inside the "view" page. */ function getObject(id) { if (top.displayFrame) return top.displayFrame.document.getElementById(id); else return document.getElementById(id); } /** * Some JavaScript wrappers all pages need access to */ /** * Logs out */ function goLogout() { top.location.href = getBaseURL() + '/?out=yes'; } /** * Checks if we're logged in and redirects to the My Items page */ function goBasket() { if (USER_ID) { top.document.location.href = getBaseURL() + "quick_basket.php"; return; //getPage('basket'); } else { if (confirm("Please log in to manage your items.")) top.document.location.href = getBaseURL() + "login-my-items"; } } /* optionally you can add the url parameter, this will be returned with the fromindex variable added as a GET variable to it. You would omit the url argument when you use the function like this: location.href = targetUrl + addFromIndex(fromindex); You will use the url argument when you use the function like this: location.href = addFromIndex(fromindex, targetUrl); The benefit of the latter is that an occurence of ? is gaurenteed. */ function addFromIndex(f, url) { if (typeof(url) == "undefined") { url = ""; } else { if (url.indexOf("?") == -1) { url += "?"; } } if (f) { url += "&fromindex=t"; } return url; } /** * Runs a search (can break out of frameset) */ function goSearch(url) { top.document.location.href = url; } /** * Returns the key pressed from an event */ function getkey(e) { if (window.event) return window.event.keyCode; else if (e) return e.which; else return null; } /** * Starts a search from the minisearch box at the top of the page */ function goSearchMini(fldname, event) { // we received an event from the field itself, only proceed if it's enter if (typeof(event) != "undefined" && getkey(event) != 13) { return; } var kwds = getObject(fldname).value; var section = getObject('searchSection').value; if (typeof(kwds) == "undefined") { kwds = ""; } if (section == '8') { goSearch(getSearchURLForCategoryType(3) + "?gender=0&gender_seek=0&nickname=" + kwds) } else if (section == '7') { goSearch(getSearchURLForCategoryType(2) + "?kw_match=any&posted=0&kw=" + kwds); } else if(kwds.length > 0) { var region = getObject('switchRegion').value; if (region == '/classifieds/browse-johannesburg') { var region = '1'; } else if (region == '/classifieds/browse-pretoria') { var region = '2'; } else if (region == '/classifieds/browse-kwazulunatal') { var region = '3'; } else if (region == '/classifieds/browse-capetown') { var region = '4'; } else if (region == '/classifieds/browse-southafrica') { var region = '5'; } else if (region == '/classifieds/browse-gauteng') { var region = '6'; } goSearch(getSearchURLForCategoryType(1) + "?kwd=" + kwds + "&sec=" + section + "&rgn=" + region); } else { var region = getObject('switchRegion').value; goSearch(getSearchURLForCategoryType(1) + "?&sec=" + section + "&rgn=" + region); } } /** * Loads the getcontent.php script for the given page (if we're not inside the frameset, it will be recreated) */ function getPage(page, fromindex ) { if (page == "subscribe") //redirect to gofree page! { top.document.location.href = getBaseURL() + "gofree.php"; return; } if (page == "freead") { top.document.location.href = "/post-free-ad"; return; } if (top.displayFrame) { getContent("/getcontent.php?s="+page+addFromIndex(fromindex), fromindex); } else { //top.document.location.href = "/home2.php?splashact=" + page + "&fromindex=t"; u = getFriendlyUrl(page); if (typeof(BASEURL) != "undefined") { u = BASEURL + u.substring(1); } top.document.location.href = u; } } function getFriendlyUrl(page) { switch (page) { case "basket" : return "/my-items-basket"; case "login" : return "/login"; case "freead" : return "/post-free-ad"; case "livead_new" : return "/post-live-ad"; default: return "/home2.php?splashact=" + page + "&fromindex=t"; } } /** * Returns the search file used for each category type */ function getSearchFileForCategoryType(t) { switch (t) { case 3: return "search.lovemail.php"; case 2: return "search.jobmail.php"; default: if (typeof(SITE_SEARCHHOST) != "undefined") { return "/q/"; } else { return "/q/"; } } } function getSearchURLForCategoryType(t) { switch (t) { case 3: case 2: if (typeof(BASEURL) == "undefined") return "/" + getSearchFileForCategoryType(t); else return BASEURL + getSearchFileForCategoryType(t); default: if (typeof(SITE_SEARCHHOST) == "undefined") return getSearchFileForCategoryType(t); else return "http://" + SITE_SEARCHHOST + getSearchFileForCategoryType(t); } } /** * Changes the search region from the drop down */ function changeSearchRegion(region) { var parts = document.location.href.split("?"); var url = parts[0]; for (i = 1; i < parts.length; ++i) { url += "?" + parts[i].replace(/&?rgn=[1-6a-zA-Z]+/, ""); } if (parts.length == 1 || parts[1].length == 0) { url += "?rgn=" + region; } else { url += "&rgn=" + region; } goSearch(url); } /** * Returns the absolute position from the left of the page */ function getAbsoluteLeft(objectId) { o = document.getElementById(objectId); oLeft = o.offsetLeft; while(o.offsetParent!=null) { oParent = o.offsetParent; oLeft += oParent.offsetLeft; o = oParent; } return oLeft; } /** * Returns the absolute position from the top of the page */ function getAbsoluteTop(objectId) { o = document.getElementById(objectId); oTop = o.offsetTop; while(o.offsetParent!=null) { oParent = o.offsetParent; oTop += oParent.offsetTop; o = oParent; } return oTop; } /** * Opens a popup window with selected options */ function popupOpen(url, name, w, h) { if (!w || !h) { w = screen.width; h = screen.height; l = 0; t = 0; } else { l = (screen.width - w) / 2; t = (screen.height - h) / 2; } x = window.open(url, name,"menubar=0,toolbar=0,resizable=1,top="+t+",left="+l+",scrollbars=yes,width="+w+",height="+h+""); x.focus(); return x; } /*********************************************** ** ** Change Log 2009-10-16, Qiniso S. Mdletshe ** ***********************************************/ function at_show_aux(parent, child) { var p = document.getElementById(parent); var c = document.getElementById(child ); var top = (c["at_position"] == "y") ? p.offsetHeight+2 : 0; var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0; for (; p; p = p.offsetParent) { top += p.offsetTop; left += p.offsetLeft; } c.style.position = "absolute"; c.style.top = top +'px'; c.style.left = left+'px'; c.style.visibility = "visible"; } // ***** at_show ***** function at_show() { var p = document.getElementById(this["at_parent"]); var c = document.getElementById(this["at_child" ]); at_show_aux(p.id, c.id); clearTimeout(c["at_timeout"]); } // ***** at_hide ***** function at_hide() { var p = document.getElementById(this["at_parent"]); var c = document.getElementById(this["at_child" ]); c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333); } // ***** at_click ***** function at_click() { var p = document.getElementById(this["at_parent"]); var c = document.getElementById(this["at_child" ]); if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden"; return false; } // ***** at_attach ***** // PARAMETERS: // parent - id of the parent html element // child - id of the child html element that should be droped down // showtype - "click" = drop down child html element on mouse click // "hover" = drop down child html element on mouse over // position - "x" = display the child html element to the right // "y" = display the child html element below // cursor - omit to use default cursor or specify CSS cursor name function at_attach(parent, child, showtype, position, cursor) { var p = document.getElementById(parent); var c = document.getElementById(child); p["at_parent"] = p.id; c["at_parent"] = p.id; p["at_child"] = c.id; c["at_child"] = c.id; p["at_position"] = position; c["at_position"] = position; c.style.position = "absolute"; c.style.visibility = "hidden"; if (cursor != undefined) p.style.cursor = cursor; switch (showtype) { case "click": p.onclick = at_click; p.onmouseout = at_hide; c.onmouseover = at_show; c.onmouseout = at_hide; break; case "hover": p.onmouseover = at_show; p.onmouseout = at_hide; c.onmouseover = at_show; c.onmouseout = at_hide; break; } } /****************************************************** ** ** End Avoid scams ** ******************************************************/