var sort = 'price';
var range = 'All';
var alpha = 'All';
var promo_type = 'All';
var page = 1;
var currId = 1;
var siteId = 3;
var language = 'en';
var urlSorting = "/include/callQryCitySort.php";


function ajaxConnect(url, obj) {
    var xmlhttp;
    var d = new Date();
	url = url+'&time='+d.getTime();
    if (window.XMLHttpRequest) {
        xmlhttp=new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("Your browser does not support XMLHTTP!");
    }
    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById(obj).innerHTML  = xmlhttp.responseText;
        }
	else {
	     // loading screen
	    try {
		document.getElementById('hotelList').innerHTML  = '<div align="center" style="width:100%; padding:80px 0;"><span class="txtred-16"><b><i>Please Wait</i></b></span>					<img src="http://www.hotelthailand.com/images/shared/loading3x.gif" border="0" style="vertical-align:middle"><br><b class="txtblack-b12"><i>While we process your request...</i></b></div>';
	    }
	    catch(err) {}
	}
    }
    xmlhttp.open("POST", url, true);
    xmlhttp.send(null);
}

function setUrlSorting(language) {
    if (language == 'th')
        this.urlRateTable = "/include/callQryCitySort.php";
    else if (language == 'jp')
        this.urlRateTable = "/include/callQryCitySort.php";
    else
        this.urlRateTable = "/include/callQryCitySort.php";
}

function ajaxSortTable(obj) {
    setUrlSorting(this.language);
    
    var url = this.urlSorting + "?object=" + obj + "&cty=" + this.cty + "&siteId=" + this.siteId + "&currId=" + this.currId+ "&page=" + this.page + "&sort=" + this.sort;
    if (this.sort == 'price')
	url += "&price_range=" + this.range;
    else if (this.sort == 'name')
	url += "&name_alpha=" + this.alpha;
    else if (this.sort == 'promotion')
	url += "&promotion_type=" + this.promo_type
    url += "&language=" + this.language + "&noerror=true";
    ajaxConnect(url, obj);
}

function setInit() {
    this.sort = 'price';
    this.range = 'All';
    this.alpha = 'All';
    this.promo_type = 'All';
    this.page = 1;
    this.currId = 1;
    this.siteId = 3;
    this.language = 'en';
}

function changeSort(sortby) {
    this.sort = sortby
    this.range = 'All';
    this.alpha = 'All';
    this.promo_type = 'All';
    this.page = 1;
    ajaxSortTable('tableSorting');
}

function changePriceRange(range) {
    this.range = range;
    this.page = 1;
    ajaxSortTable('tableSorting');
}

function changeAlphabet(alphabet) {
    this.alpha = alphabet;
    this.page = 1;
    ajaxSortTable('tableSorting');
}

function changePage(page) {
    this.page = page;
    ajaxSortTable('tableSorting');
}

