﻿objects = document.getElementsByTagName("object");
for (var i = 0; i < objects.length; i++)
{
    objects[i].outerHTML = objects[i].outerHTML;
}

function popup(url,name,w,h)
{
	//url = escape(url);
	var winstate='toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h;
	//name = '';
	aPopup=window.open(url,name,winstate);
	aPopup.focus();
}

function popimg(url,name,w,h)
{
	//url = escape(url);
	var winstate='toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width='+w+',height='+h;
	//name = '';
	aPopup=window.open(url,name,winstate);
	aPopup.focus();
}

function gopage(page,go)
{
	rem_query(document.location.href,"cpage");
}

function Center_Win()
{
	var x_center=0;
	var y_center=0;
	if (document.all)
	{
		x_center = (screen.availWidth*1/4);
		y_center = (screen.availHeight*1/6);
	}else if (document.layers||document.getElementById)
	{
		x_center = ((screen.availWidth/2) - (top.window.outerWidth/2));
		y_center = (screen.availHeight/2) - (top.window.outerHeight/2);
	}
	if(x_center<0)x_center=0;
	if(y_center<0)y_center=0;
	top.window.moveTo(x_center,y_center);
}

function rem_query(url,para)
{
	var qpoint = url.indexOf("?");
	var qpara;
	var last;
	if (qpoint) {
		qpara = url.substr(qpoint+1,url.length);
		if (qpara.indexOf("&") >= 0) {
			arrpara = qpara.split("&");
			alert(arrpara[0]);	
		} else {
			alert(qpara);
		}
	}
	return url;	
}

//
// QueryString
//
function QueryString(key)
{
	var value = "";
	for (var i=0;i<=QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			//break;
		}
	}
	if (value==null)value="";
	while(value.indexOf("%20")!=-1)
	{
		value = value.replace("%20"," ");
	}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}

}

QueryString_Parse();

function search_place()
{
	obj_link = document.all("link_page");
	obj_group = document.all("place_group");
	obj_place = document.all("keyword");
	if (obj_link && obj_group && obj_place) {
		window.location = obj_link.value+"&gr="+obj_group.value+"&q="+obj_place.value;
	}
}

function search_hotel()
{
	obj_link = document.all("link_page");
	obj_group = document.all("hotel_group");
	obj_star = document.all("star");
	obj_place = document.all("keyword");
	if (obj_link && obj_group && obj_place && obj_star) {
		window.location = obj_link.value+"&st="+obj_star.value+"&gr="+obj_group.value+"&q="+obj_place.value;
	}
}

function search_foods()
{
	obj_link = document.all("link_page");
	obj_key = document.all("keyword");
	if (obj_link && obj_key) {
		window.location = obj_link.value+"&q="+obj_key.value;
	}
}

function search_hotel_q()
{
	obj_q = document.all("txt_hotel");
	obj_prov = document.all("prov_hotel");	
	window.location = "hotels.php?prov="+obj_prov.value+"&q="+obj_q.value;
}
function search_travel_q()
{
	obj_q = document.all("txt_travel");
	obj_prov = document.all("prov_travel");
	window.location = "travel.php?prov="+obj_prov.value+"&q="+obj_q.value;
}
function search_food_q()
{
	obj_q = document.all("txt_food");
	obj_prov = document.all("prov_food");
	window.location = "foods.php?prov="+obj_prov.value+"&q="+obj_q.value;
}
function search_calendar()
{
	obj_month = document.all("month");
	obj_year = document.all("year");
	window.location = "travelcalendar.php?month="+obj_month.value+"&year="+obj_year.value;
}

/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/

var Utf8 = {

    // public method for url encoding
    encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // public method for url decoding
    decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}
