﻿//Business search form
//I send the txtfields as parameters since this method is reused several times in the application
function ValidateBusSearch(evt, txtWhat, txtWhere, divError){
    var isValid = false;    
    var txtWhat = new getObj(txtWhat).obj;
    var txtWhere =  new getObj(txtWhere).obj;   
    var divError = new getObj(divError).obj; 
    divError.innerHTML = "";    
    
    var strErr = ""; 
    if (trim(txtWhat.value) == "")
        strErr = "business/keyword missing";    
    else if (trim(txtWhat.value).length < 3)
        strErr = "search term too small"; 

    if (trim(txtWhere.value) == "" || trim(txtWhere.value).length < 5)
        strErr = (strErr.length == 0)? strErr + "location missing": strErr + "," + "location missing";
    
    if (strErr.length != 0){
        divError.innerHTML += "We could not complete your search. <br>Please check the following:<br><br>";
        var strErrors = strErr.split(",");
        for (i=0; i<strErrors.length; i++)
            divError.innerHTML += "- " + strErrors[i] + "<br>";
        isValid = false;
    }
    else{       
        isValid = true;
    }

    if (!isValid){
        preventDefaultAction(evt);
        return false;
    }
    else
       return true;      
    
}


//Function that's called by txtWhere to determine when to start an AJAX search
function OnClientItemsRequesting(sender,e)
{
    if (e.get_text().length < 3)
        e.set_cancel(true)
    else
        e.set_cancel(false);
}


function OnClientKeyPressing(sender, args){
    if(args.get_domEvent().keyCode == 13){
          //I call a function in the form that has the clientID of the button to submit
          SearchSubmit();
    }
}







