function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function doSubmit(valkey)
{
	    
	var keyword = $("#keysinput").val();    
    if(keyword == valkey){
    	$("#keysinput").val('');
    	keyword = ''; 
    	}  
    select_ct = document.getElementById("city").value;
    select_cat = document.getElementById("category").value;
    keyword = trim(keyword);
    
    if(keyword != "" || select_ct>0 || select_cat>0){    	
    	$("#keysinput").val(keyword);    	
    	return true;
    	
    }
    alert(sl_please_one_or_more_condition);
    return false;
}

function changeCitySelect(cityId)
{
    $('#p_city').val(cityId);
}

function getTotalBiz()
{
    jQuery.ajax({
      url: '/ajax/get-total-biz',
      success: function(data) {
        $('#total_biz').html(data);
        setTimeout("getTotalBiz();", 5000);
      }
    });
}

function getRecentBiz(maxId)
{
    //maxId = maxId - 1;
    jQuery.ajax({
      url: '/ajax/get-last-register-biz/id/' + maxId,
      success: function(data) {
        if(data != "") {
            $('#recent_biz').html(data);
        }
        setTimeout("getRecentBiz("+maxId+");", 10000);
      }
    });
    
}

function setSearchCond(name)
{
    var field = document.getElementById("search_field");
    field.value = name;
    
    if(name == "cat_serv"){
        document.getElementById("head_search_form").action = "/product/search";
        document.getElementById("info").style.backgroundColor = "";
        $("#business_keyword").hide();
        $("#cat_serv_keyword").show();
     
    }else if (name == "promotion"){
        document.getElementById("head_search_form").action = "/promotions/all-deal/";
        document.getElementById("info").style.backgroundColor = "";
        document.getElementById("cat_serv").style.backgroundColor = "";  
        $("#cat_serv_keyword").hide();
        $("#business_keyword").hide();

    }else{
        document.getElementById("head_search_form").action = "/index/search";
        document.getElementById("cat_serv").style.backgroundColor = "";
        $("#cat_serv_keyword").hide();
        $("#business_keyword").show();
    }    
}

function showHideBox(boxId)
{
    var boxObj = document.getElementById(boxId);
    if(boxObj.style.display != "block"){
        boxObj.style.display = "block";
    }else{
        boxObj.style.display = "none";
    }
}

function showBox(boxId)
{
    var boxObj = document.getElementById(boxId);
    if(boxObj.style.display != "block"){
        boxObj.style.display = "block";
    }
}

function hideBox(boxId)
{
    var boxObj = document.getElementById(boxId);
    if(boxObj.style.display != "none"){
        boxObj.style.display = "none";
    }
}

var tabClick = "";
function getIframeService(boxId, uri, size, innerLink)
{
    var resultDesc = $("#result_desc_" + boxId).slideDown('normal');
    resultDesc.find('.content').hide();
    resultDesc.find('iframe').show();
    if(tabClick != uri){
        showBox("result_desc_" + boxId);       
        var iFrameObj = document.getElementById("desc_frame_" + boxId);
        iFrameObj.contentWindow.document.body.innerHTML = "";
        if(innerLink == true){
            iFrameObj.src = baseUrl +  uri;
        }else{
            iFrameObj.src = uri;
        }
        //alert(iFrameObj.src);
        tabClick = uri;
        if(size > 0) iFrameObj.height = size;
    }
}

var searchOnMapLoad = false;
function showSearchOnMap()
{
    showHideBox('view_on_map');
    if(searchOnMapLoad == false){
        var iFrameObj = document.getElementById("search_map_iframe");        
        iFrameObj.src = baseUrl +  "ajax/multi-map";
        searchOnMapLoad = true;
    }
}

function closeToggle(id)
{
    $(id).slideUp('normal');
}
