function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
    do {
	curleft += obj.offsetLeft;
	curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
	return [curleft,curtop];
    }
}

function popup_email(gid_popup, gtitle, pageid, id, link){
    var popup=$("#pop_email");
    var current=$(link);
    if(gid_popup=='close')
	$(popup).hide();
    else{
	var position=findPos(link);
	$(popup).css('left', position[0]-570);
	$(popup).css('top', position[1]-40);
	$.get('popup_email.html', {
	    id_popup: gid_popup,
	    title: gtitle
	},
	function(data){
	    $(popup).html(data);
	    if(gid_popup==1){
		$("#subject").val(gtitle);
		$("#subject").attr('readOnly', true);
		$("#email_pageid").val(pageid);
	    }
	    else if(gid_popup==2){
		$("#feedback_page_title").val(gtitle);
		$("#feedback_page_title").attr('readOnly', true);
		$("#feedback_pageid").val(pageid);
	    }
	    $(popup).show();
	}
	, 'html'
	);
    }
    return false;
}
function close_popup(){
	$("#pop_email").hide();
}

/* popup for contact.html */
function popup(id_popup,curent){
    var pop_content =$("#pop_content");
    if(id_popup=="close")
	$(pop_content).fadeOut();
    else{
        var position = findPos(curent);
	var y = position[1]-50;
	$(pop_content).css('top', y-100+'px');
	var x  = position[0];
	$(pop_content).css('left', x+40+'px');
        var url = 'popup_contact.html?id_popup='+id_popup;
	$.get(url, {}, function(data){
	    $(pop_content).html(data);
	    $(pop_content).fadeIn();
	});
    }
    return false;
}
/* script to insert the blog ID to the blog comment form */
function insertBlogID(id){
    if(id>0){
    var hiddenElement = document.createElement("input");
    hiddenElement .setAttribute("type", "hidden");
    hiddenElement .setAttribute("name", "read");
    hiddenElement .setAttribute("id", "read");
    hiddenElement .setAttribute("value", id);
    var formObj=document.getElementById("form_1001"); // blog comment form ID
    formObj.appendChild(hiddenElement );
    }
}

/* scripts to show/hide the top nav menu */
var regionTime;
var langTime;
function menu(){
    clearTimeout(regionTime);
    $("#list_menu2").slideUp();
    $("#list_menu").slideDown();
    regionTime=setTimeout(function(){
	    $("#list_menu").slideUp();
	},
	5000
    );
}
function menu2(){
    clearTimeout(langTime);
    $("#list_menu").slideUp();
    $("#list_menu2").slideDown();
    langTime=setTimeout(function(){
	    $("#list_menu2").slideUp();
	},
	5000
    );
}
function show_navigation(){
    $("#main_navigation").slideDown();
}

/* functions for closing navigation menu */
var nav_timer;
function start_closing_nav(){
    nav_timer=setTimeout('close_navigation()',500);
}
function cancel_closing_nav(){
    clearTimeout(nav_timer);
}
function close_navigation(){
    $("#main_navigation").slideUp();
}

/* script for pagetools.html, show print window */
function printWindow(){
    browserVersion = parseInt(navigator.appVersion)
	if (browserVersion >= 4) window.print()
}

/* swap package type in monthly-service-plans.html*/
function show_swap(type_package,swap){
    var current = $("#current");
    var url = "package_id.html";
    $.get(url,
	{
	    type_package:$(current).val(),
	    id_swap:swap
	},
	function(data){
	$(current).val(type_package);
	$("#"+swap).html(data);
    });
}
function swap_package(type_package,swap){
    var url = "swap_packege.html";
    $.get(url,
	{
	    type_package:type_package
	},
	function(data){
	    $("#show_package").html(data);
	}
    );
}

function google_init(la, lo, canvas){
    if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById(canvas));
	var center = new GLatLng(la, lo);
	map.setCenter(center, 16);
	map.setZoom(17);
	
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	//Add new marker
	var marker = new GMarker(center);
	map.addOverlay(marker);
    } 
}

function faqs(id, cate){
    var url="faq/index_faq.php";
    $.get(url,
	{
	    id_popup:id,
	    category:cate
	},
	function(data){
	    $("#faq").html(data);
	}
    )
    return false;
}