﻿var baseTime = 7*60*60*24;
function ChangeArea(val, obj){
document.WeatherImg.src = 'http://udn.com/WEATHER/IMAGES/'+val+'icon.gif';
document.WeatherLow.src = 'http://udn.com/WEATHER/IMAGES/'+val+'lowtemp.gif';
document.WeatherHigh.src = 'http://udn.com/WEATHER/IMAGES/'+val+'hightemp.gif';
document.getElementById('div_weatherlist').style.display = "none";
document.getElementById('spn_weathercity').innerHTML = obj;
document.getElementById('spn_weatherarrow').innerHTML = "▼";
DelCookie("OMG_Weather");
SetCookie("OMG_Weather", val + "_" + obj, baseTime, "/", ".98173.com.tw");
}
function FirstLoadArea(){
    var area = GetCookie("OMG_Weather");
    if(area == null){
        ChangeArea("taipei", "台北");
    }else{
        arr_area = new Array();
        arr_area = area.split("_");
        ChangeArea(arr_area[0], arr_area[1]);
    }
}
function realPosX (oTarget) {
	try {
		var realX = oTarget.offsetLeft;
		if (oTarget.offsetParent != null && oTarget.offsetParent.tagName.toUpperCase() != "BODY") {
			realX += realPosX(oTarget.offsetParent); 
		}
		return realX;
	} catch (e) {
		alert("realPosX: "+e);
	} 
}
function realPosY (oTarget) {
	try {
		var realY = oTarget.offsetTop;
		if (oTarget.offsetParent != null && oTarget.offsetParent.tagName.toUpperCase() != "BODY") {
			realY += realPosY(oTarget.offsetParent);
		}
		return realY;
	} catch (e) { 
		alert("realPosY: "+e);
	}
}
function realPosY_ad (oTarget) {
	try {
		var realY = oTarget.offsetTop;
		if(document.all && typeof(document.all) == "object"){
		    realY = oTarget.offsetTop;
		}else{
		    realY = oTarget.offsetTop-47;
		}
		return realY;
	} catch (e) { 
		alert("realPosY_ad: "+e);
	}
}
function callWeatherList(obj){
    document.getElementById('div_weatherlist').innerHTML = BindWeatherList();
    objList = document.getElementById('div_weatherlist');
    if(objList.style.display == "inline"){
        objList.style.display = "none";
        document.getElementById('spn_weatherarrow').innerHTML = "▼";
    }else{
        document.getElementById('spn_weatherarrow').innerHTML = "▲";
        objList.style.display = "inline";
        y = realPosY(obj) + 0;
        x = realPosX(obj);
        objList.style.top = y.toString() + "px";
        objList.style.left = x.toString() + "px";
    } 
}
function inWeatherList(obj){
    objList = obj;
    if(objList.style.display == "inline"){
    }else{
        document.getElementById('spn_weatherarrow').innerHTML = "▲";
        objList.style.display = "inline";
    } 
}
function outWeatherList(obj){
    objList = obj;
    if(objList.style.display == "inline"){
        objList.style.display = "none";
        document.getElementById('spn_weatherarrow').innerHTML = "▼";   
    }
}
function BindWeatherList(){
    var objCounty = [{en:"taipei",tw:"台北"},{en:"kaoshiung",tw:"高雄"},{en:"jilung",tw:"基隆"},{en:"taoyuan",tw:"桃園"},{en:"xinju",tw:"新竹"},{en:"miaoli",tw:"苗栗"},{en:"taichung",tw:"台中"},{en:"zhanghua",tw:"彰化"},{en:"nantou",tw:"南投"},{en:"yunlin",tw:"雲林"},{en:"jiayi",tw:"嘉義"},{en:"tainan",tw:"台南"},{en:"pingtong",tw:"屏東"},{en:"hengchun",tw:"恆春"},{en:"yilan",tw:"宜蘭"},{en:"hualian",tw:"花蓮"},{en:"taitung",tw:"台東"},{en:"penghu",tw:"澎湖"},{en:"jinmeng",tw:"金門"},{en:"matsu",tw:"馬祖"}];
    objHtml = "<table width=\"200\" height=\"130\" align=\"center\" border=\"0\" id=\"tbweather\" cellspacing=\"2\" cellpadding=\"1\" style=\"color: #333;background-color:White;border:#AAA 1px solid;\"><tbody>";
    for(var i=0; i<objCounty.length; i++){
        if((i)%5 == 0){
            objHtml += "<tr>";
        }
        objHtml += "<td bordercolor=\"#FFFFFF\"><span onclick=\"ChangeArea('" + objCounty[i].en + "','" + objCounty[i].tw + "');\" style=\"cursor:pointer;text-decoration:none;color: #333;\">" + objCounty[i].tw + "</span></td>";
        if((i+1)%5 == 0){
            objHtml += "</tr>";
        }
    }
    return objHtml + "</tbody></table>";
}//-----------------------cookieset-------------------------
function GetCookieVal(offset){//取得Cookie解碼後的值
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name, value){//設定Cookie值
    var expdate = new Date();
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
    document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
    +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
    +((secure == true) ? "; secure" : "");
}
function DelCookie(name){//删除Cookie
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function GetCookie(name){//取得Cookie的原始值
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen){
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return GetCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}//----------------------------String--------------------------
function trim(strText){
    return strText.replace(/^\s+|\s+$/g, '').replace(/^[\s　]+|[\s　]+$/g, '');
}
function clrHtmlTag(strHTML){
    return strHTML.replace(/<[^<>]+>/g, '')
}
function repSpecialWord(strText){
	strText = trim(strText);
	strText = strText.replace(/'/g, '');
	strText = strText.replace(/"/g, '');
	strText = strText.replace(/</g, '＜');
	strText = strText.replace(/>/g, '＞');
	return strText;
}
function TrimAndClear(strText){
    return repSpecialWord(clrHtmlTag(trim(strText)));
}
function getRadom(intMax){
	var intR = Math.floor(Math.random() * (intMax + 1));
	if (intR == 0)
		intR = 1;
	return intR;
}
// Initializes a new instance of the StringBuilder class(var sb = new StringBuilder();)
// and appends the given value if supplied
function StringBuilder(value){
    this.strings = new Array("");
    this.append(value);
}
// Appends the given value to the end of this instance.(sb.append(.....))
StringBuilder.prototype.append = function (value){
    if (value){
        this.strings.push(value);
    }
}
// Clears the string buffer(sb.clear())
StringBuilder.prototype.clear = function (){
    this.strings.length = 1;
}
// Converts this instance to a String.(sb.toString())
StringBuilder.prototype.toString = function (){
    return this.strings.join("");
}
function ReplaceAll(sString, strSource, strObject){
	while(sString.indexOf(strSource) != -1){
		sString = sString.replace(strSource, strObject);
	}
	return sString;
}//-------------------------Search
function searchCheck(){
    var sk = encodeURIComponent(TrimAndClear(document.getElementById("txt_keyword").value));
    var objarea = document.getElementById("sel_sarea");
    var objstp = document.getElementById("sel_stype");
    if(objarea.value=="0" && objstp.value=="2"){
        if(document.getElementById('txt_ssdate').value == ""){
            alert("請選擇起始日期");
            onfireClick("txt_ssdate");
            return false;
        }else if(document.getElementById('txt_sedate').value == ""){
            alert("請選擇結束日期");
            onfireClick("txt_sedate");
            return false;
        }else{
            sk = document.getElementById('txt_ssdate').value + "~" + document.getElementById('txt_sedate').value;
        }
    }else if(sk == ""){
        alert("請輸入搜尋關鍵字");
        document.getElementById('txt_keyword').focus();
        return false;
    }
    if (objarea.value == "0"){
        location.href = "/News/SearchResult.aspx?area=" + objarea.value + "&stp=" + objstp.value + "&sk=" + sk;
    }
    else if(objarea.value == "2"){
        if(objstp.value == "0"){
            location.href = "/WiKi/WiKi_PageList.aspx?area=" + objarea.value + "&stp=" + objstp.value + "&sk=" + sk;
        }else if(objstp.value == "4"){
            location.href = "/WiKi/WiKi_List.aspx?area=" + objarea.value + "&stp=" + objstp.value + "&sk=" + sk;
        }
    }else if(objarea.value == "1" || objarea.value == "3"){
        if(objstp.value == "4"){
            location.href = "/Forum/SearchResult_ForumName.aspx?area=" + objarea.value + "&stp=" + objstp.value + "&sk=" + sk;
        }else{
            location.href = "/Forum/SearchResult.aspx?area=" + objarea.value + "&stp=" + objstp.value + "&sk=" + sk + "&fmid=" + fmsid + "&tid=" + tid;
        }
    }else if(objarea.value == "5"){
        location.href = "/NewsForumSearch.aspx?area=" + objarea.value + "&cx=" + escape("partner-pub-7825468216517755:od267cdqk51") + "&cof=" + escape("FORID:9") + "&ie=" + escape("UTF-8") + "&q=" + sk;
    }
    return false;
}
function onfireClick(objName){
    if(document.all && typeof(document.all) == "object"){
        document.getElementById(objName).fireEvent("onclick");
    }else{  
        var evt = document.createEvent('MouseEvent');   
        evt.initEvent('click',false,false);
        document.getElementById(objName).dispatchEvent(evt);
    }
}
function onBtnKeyEvent(eventTag, btnName){
    var events = eventTag||window.event;
    var eventSource;
    var currentKey = events.charCode||events.keyCode;
    if(document.all){    
        eventSource =window.event.srcElement;
    }else{
        eventSource = events.target;
    }
    if(currentKey==13){
        onfireClick(btnName);
    }
}
function CheckIsIe6(){
    var verStr = navigator.appVersion;
    var result = false;
    try{
        if (verStr.indexOf("MSIE") != -1) {
            var tempStr = verStr.split(";");
            for(var i=0; i<tempStr.length; i++){
                if(tempStr[i].indexOf("MSIE") != -1){
                    var vIE = parseFloat(tempStr[i].replace("MSIE ",""));
                    result = (vIE <= 6)? true : false;
                    break;
                }
            }
        }
    }catch(e){}
    return result;
}
var IsIE6 = CheckIsIe6();
if(IsIE6){
    jsTag = document.createElement("script");
    try{
        jsTag.type = "text/javascript";
        jsTag.src = "/Javascript/IE6Warring.js";
    }catch(e){}
    document.getElementsByTagName("head")[0].appendChild(jsTag);
}
function ReSizePicForIe6(varObj, varWidth, varHeight){
    if(varObj.width>varObj.height && varObj.width>varWidth){
        varObj.width = varWidth;
    }else if(varObj.height>varObj.width && varObj.height>varHeight){
        varObj.height = varHeight;
    }else{
        varObj.width = varWidth;
    }
}
function searchAreaChange(){
    var oAreaDL = document.getElementById("sel_sarea");
    var objarea = oAreaDL[oAreaDL.selectedIndex].value;
    searchTypeClear();
    document.getElementById("sel_stype").style.display = "";
    document.getElementById("txt_keyword").size = "47";
    if(objarea == "1"){
        searchTypeAdd([{txt:"版名",val:"4"},{txt:"標題",val:"0"},{txt:"作者",val:"1"}]);
    }else if(objarea == "2"){
        searchTypeAdd([{txt:"版名",val:"4"},{txt:"標題",val:"0"}]);
    }else if(objarea == "3"){
        searchTypeAdd([{txt:"標題",val:"0"},{txt:"作者",val:"1"}]);
    }else if(objarea == "0"){
        searchTypeAdd([{txt:"標題",val:"0"},{txt:"時間",val:"2"},{txt:"作者",val:"1"}]);
    }else if(objarea == "5"){
        document.getElementById("sel_stype").style.display = "none";
        document.getElementById("txt_keyword").size = "55";
    }
    searchTypeChange();
}
function searchTypeClear(){
    for(var i=0; i<document.getElementById("sel_stype").length; i++){
        document.getElementById("sel_stype").remove(i);
    }
}
function searchTypeAdd(objValue){
    for(var i=0; i<objValue.length; i++){
        document.getElementById("sel_stype").options[i] = new Option(objValue[i].txt, objValue[i].val);
    }
}
function searchTypeChange(){
    if(document.getElementById("sel_sarea").value == "0" && document.getElementById("sel_stype").value == "2"){
        document.getElementById("txt_keyword").style.display = "none";
        document.getElementById("spn_datectrl").style.display = "";
    }else{
        document.getElementById("txt_keyword").style.display = "";
        document.getElementById("spn_datectrl").style.display = "none";
    }
}
function onSearchList(){
    var oDDL=document.getElementById('sel_sarea');
    reqsk = (q != "")? q : reqsk;
    if((fmsid==null || fmsid=='') && (tid==null || tid==''))
    {
        OptionSetting(oDDL,"Reomve");
    }
    else
    {
        OptionSetting(oDDL,"Selected");
    }
    if(area == '0' && stp == '2' && reqsk.indexOf('~') != -1){
        var arrsk = new Array();
        arrsk = reqsk.split('~');
        document.getElementById('txt_ssdate').value = arrsk[0];
        document.getElementById('txt_sedate').value = arrsk[1];
    }else{
        document.getElementById('txt_keyword').value = reqsk;
    }
    if(reqsk != ""){
        checkSelectIndex(document.getElementById("sel_sarea"), area);
        searchAreaChange();
        checkSelectIndex(document.getElementById("sel_stype"), stp);
        searchTypeChange();
    }
}
function OptionSetting(_oDDL,sCommand)
{
    var i;
    if(_oDDL!=null)
    for(i=_oDDL.options.length-1;i>=0;i--)
    {
        if(_oDDL.options[i].value==3)
        {
            if(sCommand=="Reomve")
            {
                _oDDL.remove(i);
            }
            else if(sCommand=="Selected")
            {
                _oDDL.options[i].selected = true;
            }
        }
    } 
    searchAreaChange();
}
function checkSelectIndex(obj, val){
    for(var i=0; i<obj.length; i++){
        if(obj.options[i].value == val){
            obj.options[i].selected = true;
            break;
        }
    }
}
function onSearchBtnOver(obj){
    if(obj.src.indexOf("_on") != -1){
        obj.src = obj.src.replace("_on", "");
    }else{
        obj.src = obj.src.replace(".gif", "_on.gif");
    }
}//---------------水球訊息Script---------------------------------------//
var sMid = 0;
var sPid = 0;
var sName = "";
var sMlid = 0;
function CheckLogin(){
    if(HeadChkLogin != '1'){
        if(confirm("使用水球功能必須先登入會員，確定要登入 ?")){
            window.location='http://Member.98173.com.tw/Login/Login.aspx?FromUrl='+escape(location.href);
            return false;
        }else{
            return false;
        }
    }else{
        return true;
    }
}
function CallMsg(mid, nkname, evt){
    if(!CheckLogin()){ return; }
    sMid = mid;
    if(document.getElementById("div_msgreply") != null){
        var argv = CallMsg.arguments;
        var iex; var iey;
        var dbst;
        var dbsl;
        if(document.body.scrollTop && document.body.scrollTop !=0){
            dbst=document.body.scrollTop;
            dbsl=document.body.scrollLeft;
        }
        else{
            dbst=document.getElementsByTagName("html")[0].scrollTop;
            dbsl=document.getElementsByTagName("html")[0].scrollLeft;
        }
        if(argv.length > 3 && argv[3] == "1"){//訊息視窗置中
            iex = eval(screen.availWidth/2)-eval(500)/2 + dbsl;
            iey = eval(screen.availHeight/2)-eval(300)/2 + dbst; 
        }else if(argv.length > 3 && argv[3] == "2"){
            iex = evt.clientX - 460 + dbsl;
            iey = evt.clientY - 20 + dbst;
        }else{
            iex = evt.clientX + 5 + dbsl;
            iey = evt.clientY - 20 + dbst;
        }
        if(argv.length > 4){
            sMlid = argv[4];
        }
        objWin = document.getElementById("div_msgreply");
        objWin.style.left = iex + "px";
        objWin.style.top = iey + "px";
        objWin.style.display = "";
        document.getElementById("txt_msgreplynickname").value = nkname;
        document.getElementById("txt_msgreplycontent").value = "";
        var oIframe = document.getElementById("WB_Back_iFrame_02");
        if(oIframe!=null)
        {
            oIframe.style.width = "500px";
            oIframe.style.height = "250px";
            oIframe.style.position = "absolute";
            oIframe.style.top = objWin.offsetTop+"px";
            oIframe.style.left = objWin.offsetLeft+"px";
            oIframe.style.display = "";
        }
    }
}
var dragapproved=false;
function initializedragie(e, obj) {
    iex=e.clientX;
    iey=e.clientY;
    tempx=parseInt(document.getElementById(obj).style.left, 10);
    tempy=parseInt(document.getElementById(obj).style.top, 10);
    dragapproved=true;
    objName = obj;
    document.onmousemove= function(e) {
        if (dragapproved==true) {
            var evt = e||window.event;
            document.getElementById(objName).style.left=tempx + evt.clientX-iex + "px";
            document.getElementById(objName).style.top=tempy + evt.clientY-iey + "px";
            if(document.getElementById(objName).id=="NewsArticle")
            {
                if(document.getElementById("ReplyFrame") != null){
                    document.getElementById("ReplyFrame").style.left=tempx + evt.clientX-iex+20 + "px";
                    document.getElementById("ReplyFrame").style.top=tempy + evt.clientY-iey+20 + "px";
                }
            }
            if(document.getElementById(objName).id=="div_msgsend")
            {
                if(document.getElementById("WB_Back_iFrame") != null){
                    document.getElementById("WB_Back_iFrame").style.left=tempx + evt.clientX-iex+20 + "px";
                    document.getElementById("WB_Back_iFrame").style.top=tempy + evt.clientY-iey + "px";
                }
            }
            if(document.getElementById(objName).id=="div_msgreply")
            {
                if(document.getElementById("WB_Back_iFrame_02") != null){
                    document.getElementById("WB_Back_iFrame_02").style.left=tempx + evt.clientX-iex+20 + "px";
                    document.getElementById("WB_Back_iFrame_02").style.top=tempy + evt.clientY-iey + "px";
                }
            }
            return false; } }
}
document.onmouseup=new Function("dragapproved=false");
