﻿
/* ==============================================================================
 * Do some validation, then send the query off to the search results page. Note
 * that the base URL is provided by index.asp.cs
 * ============================================================================== */
function doSearchSubmit(){
    try{
        var e = document.getElementById("qstext");
        var sQueryString = e.value;
        if(!sQueryString || sQueryString.length == 0){
            alert("Please enter a query. This can be a site number, a campaign reference beginning with a '#', part of a site address or a keyword");
            return;
        }
        
        // if this is a reference number then post to the selections page
        if(sQueryString.substr(0,1) == "#"){
            document.getElementById("regno").value = sQueryString.substr(1);
            document.forms["formqs"].action = getSiteBase() + "selection.aspx";
            document.forms["formqs"].submit();
            return true;
        }
        
        // Otherwise post it to the search results page
        document.getElementById("q_keywords").value = sQueryString;
        document.forms["formqs"].action = getSiteBase() + "searchresults.aspx";
        document.forms["formqs"].submit();
        
    }catch(err){
        alert(err.message);
    }
}

function getSiteBase(){
    try{
        //var locn = window.location.href;
        //return locn.substring(0,locn.lastIndexOf("/")+1);  
        return "http://www1.isitemedia.co.nz/isitesignz/";          
    }catch(err){
        return "";
    }
}
