// JavaScript Document

function initiallang() {
	var re = new RegExp("(\/)(tc|sc|en)(\/)");
	var m = re.exec(window.location);
	var currentLang = "tc";

	if (m != null) {
		currentLang = m[2];
	}

	$("#lang" + currentLang).addClass("selected");
}

function changelang(toLang) {
	var re = new RegExp("(\/)(tc|sc|en)(\/)");
	var m = re.exec(window.location);
	var currentLang = "tc";

	if (m != null) {
		currentLang = m[2];

		var re = new RegExp("\/(tc|sc|en)\/", "g");
		var newURL = window.location.href.replace(re, "/" + toLang + "/");

		window.location.href = newURL;
	}
}

function changesize(newFontSize) {
	var currentFontSize = getCookie("fontsize");

	if (newFontSize != currentFontSize) {
		$("html").addClass(newFontSize);
		$("#fontsize" + newFontSize).addClass("selected");
		if (currentFontSize != "") {
			$("html").removeClass(currentFontSize);
			$("#fontsize" + currentFontSize).removeClass("selected");
		}

		setCookie("fontsize", newFontSize);
	}
}

function initialfontsize() {
	var currentFontSize = getCookie("fontsize");

	if (currentFontSize == "") {
		currentFontSize = "normal";
	}

	$("html").addClass(currentFontSize);
	$("#fontsize" + currentFontSize).addClass("selected");
}

function setCookie(c_name, value, expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString())+";path = /";
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}

function bookmark(){
    var url = window.location;
    var title = document.title ? document.title : "房協長者通";
    try

    {

        window.external.addFavorite(url, title);

    }

    catch (e)

    {

        try

        {

            window.sidebar.addPanel(title, url, "");

        }

        catch (e)

        {

            alert("添加書籤失敗，請使用Ctrl+D進行添加。");

        }

    }


}

function sharewith(id){
    var url = "";
    var localurl = window.location;
    if (id == 'facebook') {
        url = "http://www.facebook.com/share.php?u="+encodeURIComponent(localurl);
    }else if(id == 'twitter'){
        url = "http://twitter.com/home?status="+encodeURIComponent(localurl);
    }
    window.open(url);
}
