/*   
Application Name: Cekodok
Application URI: http://cekodok.com
Author: Bitter Coffee Studio
Author URI: http://www.bitter-coffee.com
Version: 1.0
.
This stylings (part of the whole application) is made exclusively for Cekodok.com. Any of this code here is free to be used as long as there are is violation of copyright
.
*/

var textbox_text = "type the food name or part of the food names"; //default text in textbox
var is_default = false;

//clear textbox upon clicking the textbox so that the user won't have to delete the text themselves
function clearTextbox() {
	if ($('searchbox').value === textbox_text) {
		$('searchbox').value = "";
	}
}

//put the values back if user leaves it blank
function fillTextbox() {
	if ($('searchbox').value === "") {
		$('searchbox').value =  textbox_text;
	}
}

//get all ads
function getInitialResult() {
	var varTemp = new Ajax.Updater ( 'result', '/_getList.php' );
}

//submit form to search for the ads
function runRequest() {
	
	is_default = false;
	
	$('loading').show();
	//$('result').hide();
	var varTemp = new Ajax.Updater('result', '/_getList.php', { method:'post', onComplete:function() { $('loading').hide(); $('result').show(); }, asynchronous:true, parameters: $('searchform').serialize(true)});
}

//wait few seconds to run runRequest
function sendRequest() {
	//setTimeout(alert('ajax_call'),500);
	setTimeout(function () {
		runRequest();
	}, 0);
	

}

//submit form to search for the foods in category
function runCategoryRequest(category_id) {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result', '/ajax/_getCategoryList.php?cat_id='+category_id, { method:'post', onComplete:function() { $('loading').hide(); $('result').show(); }, asynchronous:true, parameters: $('searchform').serialize(true)});
}

//submit form to search for the foods in category
function runDefaultRequest() {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result', '/ajax/_getDefaultList.php', { method:'post', onComplete:function() { $('loading').hide(); $('result').show(); }, asynchronous:true, parameters: $('searchform').serialize(true)});
}

//submit form to search for the foods in category
function searchRunFoodRequest() {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result_food', '/ajax/_searchGetFoodsList.php', { method:'post', onComplete:function() { $('loading').hide(); $('result_food').show(); }, asynchronous:true, parameters: $('h-search-form').serialize(true)});
}

//submit form to search for the foods in category
function searchRunMealPlanRequest() {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result_meal_plans', '/ajax/_searchGetMealPlansList.php', { method:'post', onComplete:function() { $('loading').hide(); $('result_meal_plans').show(); }, asynchronous:true, parameters: $('h-search-form').serialize(true)});
}

//submit form to search for the foods in category
function searchRunNewsRequest() {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result_news', '/ajax/_searchGetNewsList.php', { method:'post', onComplete:function() { $('loading').hide(); $('result_news').show(); }, asynchronous:true, parameters: $('h-search-form').serialize(true)});
}

//submit form to search for the foods in category
function searchRunDietTipsRequest() {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result_diet_tips', '/ajax/_searchGetDietTipsList.php', { method:'post', onComplete:function() { $('loading').hide(); $('result_diet_tips').show(); }, asynchronous:true, parameters: $('h-search-form').serialize(true)});
}

//wait few seconds to run runRequest
function sendCategoryRequest(category_id) {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        runCategoryRequest(category_id);
    }, 0);
}

//wait few seconds to run runRequest
function sendDefaultRequest() {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        runDefaultRequest();
    }, 0);
}

//wait few seconds to run runRequest
function searchGetFoodsList() {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        searchRunFoodRequest();
    }, 0);
}

//wait few seconds to run runRequest
function searchGetMealPlansList() {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        searchRunMealPlanRequest();
    }, 0);
}

//wait few seconds to run runRequest
function searchGetNewsList() {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        searchRunNewsRequest();
    }, 0);
}

//wait few seconds to run runRequest
function searchGetDietTipsList() {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        searchRunDietTipsRequest();
    }, 0);
}

//submit form to search for the foods in country
function runCountryRequest(country_id) {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result', '/ajax/_getCountryList.php?country_id='+country_id, { method:'post', onComplete:function() { $('loading').hide(); $('result').show(); }, asynchronous:true, parameters: $('searchform').serialize(true)});
}

//wait few seconds to run runRequest
function sendCountryRequest(country_id) {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        runCountryRequest(country_id);
    }, 0);
}

//submit form to search for the foods in brands
function runBrandRequest(brand_id) {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result', '/ajax/_getBrandList.php?brand_id='+brand_id, { method:'post', onComplete:function() { $('loading').hide(); $('result').show(); }, asynchronous:true, parameters: $('searchform').serialize(true)});
}

//submit form to search for the foods in brands
function runActTypeRequest(type_id) {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result', '/ajax/_getActTypeList.php?type_id='+type_id, { method:'post', onComplete:function() { $('loading').hide(); $('result').show(); }, asynchronous:true, parameters: $('searchform').serialize(true)});
}

//submit form to search for the activities
function runActivitiesRequest() {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result', '/ajax/_getActivitiesList.php', { method:'post', onComplete:function() { $('loading').hide(); $('result').show(); }, asynchronous:true, parameters: $('searchform').serialize(true)});
}

//submit form to search for the foods in brands
function runTagRequest(tag_id) {
    is_default = false;

    $('loading').show();
    //$('result').hide();
    var varTemp = new Ajax.Updater('result', '/ajax/_getTagsList.php?tag_id='+tag_id, { method:'post', onComplete:function() { $('loading').hide(); $('result').show(); }, asynchronous:true, parameters: $('searchform').serialize(true)});
}

//wait few seconds to run runRequest
function sendBrandRequest(brand_id) {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        runBrandRequest(brand_id);
    }, 0);
}

//wait few seconds to run runRequest
function sendActTypeRequest(type_id) {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        runActTypeRequest(type_id);
    }, 0);
}

//wait few seconds to run runRequest
function sendActivitiesRequest() {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        runActivitiesRequest();
    }, 0);
}

//wait few seconds to run runRequest
function sendTagRequest(tag_id) {
    //setTimeout(alert('ajax_call'),500);
    setTimeout(function () {
        runTagRequest(tag_id);
    }, 0);
}



//show form to add adverts
function showDefaultList() {
	is_default = true; //fix pagination so that when clicked on other page, dia x lost search keyword since no search keyword is present!
	
	var varTemp = new Ajax.Updater ( 'result', '/ajax/_getDefaultList.php?mode=default', { onComplete: function() { $('loading').hide(); $('result').show(); } } );
} 

//show form to add adverts
function showDefaultForCategy(cat_id) {
	
	is_default = true; //fix pagination so that when clicked on other page, dia x lost search keyword since no search keyword is present!
	
	new Ajax.Updater (
        'result',
        '/ajax/_getCategoryList.php?cat_id='+cat_id+'&mode=default',
        {
            onComplete: function() {
                $('loading').hide();
                $('result').show();
            }
        }
    );
} 

//show form to add adverts
function showDefaultForCountry(country_id) {
	
	is_default = true; //fix pagination so that when clicked on other page, dia x lost search keyword since no search keyword is present!
	
	new Ajax.Updater (
        'result',
        '/ajax/_getCountryList.php?country_id='+country_id+'&mode=default',
        {
            onComplete: function() {
                $('loading').hide();
                $('result').show();
            }
        }
    );
} 

//show form to add adverts
function showDefaultForBrand(brand_id) {
	
	is_default = true; //fix pagination so that when clicked on other page, dia x lost search keyword since no search keyword is present!
	
	new Ajax.Updater (
        'result',
        '/ajax/_getBrandList.php?brand_id='+brand_id+'&mode=default',
        {
            onComplete: function() {
                $('loading').hide();
                $('result').show();
            }
        }
    );
} 

//show form to add adverts
function showDefaultForActType(type_id) {
	
	is_default = true; //fix pagination so that when clicked on other page, dia x lost search keyword since no search keyword is present!
	
	new Ajax.Updater (
        'result',
        '/ajax/_getActTypeList.php?type_id='+type_id+'&mode=default',
        {
            onComplete: function() {
                $('loading').hide();
                $('result').show();
            }
        }
    );
} 

//show form to add adverts
function showDefaultActivities() {
	
	is_default = true; //fix pagination so that when clicked on other page, dia x lost search keyword since no search keyword is present!
	
	new Ajax.Updater (
        'result',
        '/ajax/_getActivitiesList.php?&mode=default',
        {
            onComplete: function() {
                $('loading').hide();
                $('result').show();
            }
        }
    );
} 

//show form to add adverts
function showDefaultForTag(tag_id) {
	
	is_default = true; //fix pagination so that when clicked on other page, dia x lost search keyword since no search keyword is present!
	
	new Ajax.Updater (
        'result',
        '/ajax/_getTagsList.php?tag_id='+tag_id+'&mode=default',
        {
            onComplete: function() {
                $('loading').hide();
                $('result').show();
            }
        }
    );
} 
