
function msg_box(strURL,strName,strScrollBar,strReSizable,intHeight,intWidth,intX,intY,intToolbar){
	var properity="scrollbars="+strScrollBar+",resizable="+strReSizable+",directories=no,location=no,menubar=no,status=no,statusbar=no,height="+intHeight+",width="+intWidth;
	if (intToolbar > 0)
		properity=properity+",toolbar=1";
	else
		properity=properity+",toolbar=0";
	var NewWin=window.open('',strName,properity);
	NewWin.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=big5">');
	NewWin.document.write('<title>DATA LOADING...</title><link rel="stylesheet" href="/vegeworld.css"><script>self.focus();</script></head><body class=f11>');
	NewWin.document.write('<center><br>DATA LOADING...</center></body></html>');
	if (intX >0 && intY >=0){
		NewWin.moveTo (intX,intY);
	}
	else {
		var w = screen.availWidth;
		var h = screen.availHeight;
		NewWin.moveTo (((w - intWidth - 10) * .5),((h - intHeight - 30) * .5));
	}
	NewWin.location=strURL;
}

function msg_box2(strURL,strName,intHeight,intWidth){
	var properity="scrollbars=1,resizable=1,toolbar=1,directories=no,location=1,menubar=1,status=1o,statusbar=1,height="+intHeight+",width="+intWidth;
	var NewWin=window.open('',strName,properity);
	NewWin.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=big5">');
	NewWin.document.write('<title>DATA LOADING...</title><link rel="stylesheet" href="/vegeworld.css"><script>self.focus();</script></head><body class=f11>');
	NewWin.document.write('<center><br>DATA LOADING...</center></body></html>');
	var w = screen.availWidth;
	var h = screen.availHeight;
	NewWin.moveTo (((w - intWidth - 10) * .5),((h - intHeight - 30) * .5));
	NewWin.location=strURL;
}

function modal_box(strURL,objArg,intScrollBar,intReSizable,intHeight,intWidth)
{
    if ($.browser.msie) {
        var properity="scroll:"+intScrollBar+";resizable:"+intReSizable+";status:0;help:no;dialogHeight:"+intHeight+"px;dialogWidth:"+intWidth+"px";
        var NewWin=window.showModalDialog("/Dialog.asp?p="+strURL,objArg,properity);
    } else
        msg_box("/Dialog.asp?p="+strURL,objArg,intScrollBar,intReSizable,intHeight,intWidth);
}

function modeless_box(strURL,objArg,intScrollBar,intReSizable,intHeight,intWidth)
{
    if ($.browser.msie) {
        var properity="scroll:"+intScrollBar+";resizable:"+intReSizable+";status:0;help:no;dialogHeight:"+intHeight+"px;dialogWidth:"+intWidth+"px";
        var NewWin=window.showModelessDialog("/Dialog.asp?p="+strURL,objArg,properity);
    } else
        msg_box("/Dialog.asp?p="+strURL,objArg,intScrollBar,intReSizable,intHeight,intWidth);
}
function vProfile(id){
	var URL="/Member/ProfileW.asp?id="+id;
	var mWin=modeless_box(URL,window,1,1,530,550);
}

//===================================================================
// 設? select ????
// ex: InitOption(window.form1.xSelect, "1");
//===================================================================
function InitOption(sCtl, str)
{
   for(i=0; i < sCtl.options.length; i++)
    {
        if( sCtl.options[i].value == str )
        {
           sCtl.options[i].selected=true;
            break ;
        }
    }
}

//===================================================================
//	將?窗由 sW,sH ?大??eW, eH
// win_resizel(sW, sH, eW, eH );
//===================================================================
function win_resize1(sW, sH, eW, eH)
{
    var sW, sH, win_x, win_y, XStep, YStep ;
    win_x = (screen.width - eW)/2;
    win_y = (screen.height - eH)/2 - 20;

    XStep = (eW - sW)/90;
    YStep = (eH - sH)/90;
    window.resizeTo(sW,sH) ;
    window.moveTo(win_x,win_y);
    for ( w=sW,h=sH ; h<eH ; h+=YStep,w+=XStep)
    {
        window.resizeTo(w,h) ;
    }
}
//===================================================================
//	將?窗放大至 W x H
// win_resize(W, H [, row, rowH , maxH ] );
//===================================================================
function win_resize(W,H,row,rowH,maxH)
{
    MaxY = window.screen.availHeight;
    MaxX = window.screen.availWidth;

    WinWidth = W;
    if (!row)
        WinHeight = H ;
    else
        WinHeight = H + rowH*row ;

    // WinHeight 不可大於 maxH
    if ( ( maxH ) && ( WinHeight > maxH ) )
        WinHeight = maxH ;

    From_W = 160 ;
    From_H = 50 ;
    XStep = (WinWidth - From_W)/20;
    YStep = (WinHeight - From_H)/20;

    for ( j=From_W,i=From_H ; i<WinHeight ; i+=YStep,j+=XStep)
    {
        window.resizeTo(j,i);
        window.moveTo((MaxX-j)/2,(MaxY-i)/2);
    }
}
//===================================================================
//	將?窗縮???
//===================================================================
function win_close()
{
    MaxY = window.screen.availHeight;
    MaxX = window.screen.availWidth;
    WinWidth = document.body.offsetWidth;
    WinHeight = document.body.offsetHeight ;

    XStep=WinWidth/30;
    YStep=WinHeight/30;
    for (j=WinWidth,i=WinHeight;i>0;i-=YStep,j-=XStep)
    {
       window.resizeTo(j,i);
       window.moveTo((MaxX-j)/2,(MaxY-i)/2);
    }
	Window.close();
}
//===================================================================
//
//
//===================================================================
function show_span(spanobj)
{
    document.getElementById(spanobj).style.display   = "block" ;
}

//===================================================================
//
//
//===================================================================

function hidden_span(spanobj)
{
    document.getElementById(spanobj).style.display   = "none" ;
}

//===================================================================
//	檢查?件????                           2K.11
//===================================================================
function objecttype(obj)
{
    var objtype = "", var_undefined;
    if (obj == var_undefined)
    {
        alert("object undefined");
        return;
    }
    if (obj.type == var_undefined)
    {
        if (obj[0].type != var_undefined)
            objtype = obj[0].type;
        else
        {
            alert("object:["+obj+"] error");
            return;
        }
    }
    else
    {
        objtype = obj.type;
    }
    return objtype;
}
//===================================================================
//	求??件?????援:hidden,text,radio,checkbox,select-one,select-multiple)
//                                             2K01.04
//===================================================================
function value(obj)
{
    var i;
    var retvalue = '' ;
    var objtype = objecttype(obj);
    switch (objtype)
    {
        case "textarea":
            retvalue = obj.value;
            break;
    	case "password":
            retvalue = obj.value;
            break;
        case "hidden":
            retvalue = obj.value;
            break;
        case "text"  :
            retvalue = obj.value;
            break;
        case "checkbox" :
            var idx = 0 ;
            retvalue = new Array();
            if ( !obj.length )
            {
                if (obj.checked)
                    retvalue[0] = obj.value ;
                else
                    retvalue[0] = '' ;
            }
            else
            {
                for (z=0;z<obj.length;z++)
                {
                    if ( obj[z].checked )
                    {
                        retvalue[idx] = obj[z].value ;
                        idx++ ;
                    }
                }
            }
            //alert("my checkbox["+retvalue+"]");
            break;
        case "select-one" :
            retvalue = obj.options[obj.selectedIndex].value;
            //alert("my select-one["+retvalue+"]");
            break;
        case "select-multiple" :
            var inx=0;
            retvalue = new Array();
            for (i=0; i<obj.length; i++)
            {
                if (obj.options[i].selected == true)
                {
                    retvalue[inx] = obj.options[i].value;
                    inx++;
                }
            }
            //alert("my select-multiple["+retvalue.toString()+"]");
            break;
        case "radio" : //radio
            for (i=0; i<obj.length; i++)
                if (obj[i].checked == true)
                    retvalue = obj[i].value;
            //alert("my radio["+retvalue+"]");
            break;
        default :
            alert("function value(obj) obj:["+obj+"] error...");
            return;

    }
    return retvalue;
}
//===================================================================
//	?到str?尾?separator, separator ??定??? "
//                                             2K01.04
//===================================================================
function trim(str, separator)
{
    var strlen = str.length;
    if (separator == null)
        separator = " ";
    // ?頭尾?多???符?

    if (strlen == 0)
        return "" ;

    do
    {
        if (str.substring(0, 1) == separator)
        {
            str = str.substring(1);
            strlen--;
        }
        if (str.substring(strlen-1) == separator)
        {
            str = str.substring(0, strlen-1);
            strlen--;
        }
    }while(str.substring(0, 1) == separator || str.substring(strlen-1) == separator)
    return (str);
}
//========================================================================
//= 檢查欄???( 空?, ?數 , ?? , E-MAIL )
//= vege_chk_val( form_name , input_name , message [ , mode ] [, no_focus])
//========================================================================
function vege_chk_val( f_name , input_name , msg ,mode ,no_focus )
{
    form_obj = eval ( 'window.document.' + f_name ) ;
    if ( ! form_obj )   // L form object
    {
        alert('L : '+ f_name) ;
        return false ;
    }

    input_obj = eval ( 'window.document.' + f_name + '.' + input_name ) ;
    if ( ! input_obj )  // L input object
    {
        alert('L : '+ input_name) ;
        return false ;
    }
     val =  trim(value( input_obj ));
    flag = true ;
    if ( ! mode )   // L Ѽ
        mode = '' ;

    if ( ( val == '' ) || ( val == null ) )
        flag = false ;
    switch(mode)
    {
        case '' :
        {
            break ;
        }
        case 'int' :
        {
            if ( parseInt(val).toString(10) != val.toString(10)  )
               flag = false ;

            break ;
        }
        case 'num' :
        {
            if ( isNaN(val) )
               flag = false ;
            break ;
        }
        case 'str' :
        {
            break ;
        }
        case 'email' :
        {
            pos1 = parseInt( val.indexOf('@') ) ;
            pos2 = parseInt( val.indexOf('.') ) ;
            len =  parseInt( val.length ) ;
            if ( ( pos1 == -1 ) || ( pos2 == -1 ) || ( pos1*pos2 == 0) ||
                 ( pos1+1 == len ) || ( pos2+1 == len ) || ( Math.abs(pos1-pos2) == 1 )  )
                flag = false ;

            break ;
        }
        case 'date' :
        {
           // Create a variable to hold the correct format.
           var CorrectFormat = /[0-9][0-9][0-9][0-9]\/[0-9]\d{0,1}\/[0-9]\d{0,1}/;
           // If the field has value, validate the date.
           // Test to see if the format of the date is correct.
          if (CorrectFormat.test(val))
          {
             // Split out the month, day and year variables.
             strDate = val.split("/");
             var Year = strDate[0];
             var Month = strDate[1];
             var Day = strDate[2];

             // Ensure all the values are greater than 0
             if (Month > 0 && Day > 0 && Year > 0)
             {
                // Find the max day for the month
                // The default max day is 31
                var maxDays = 31;
                // If the month is April, June, September or November the max day is 30
                if (Month == 4 || Month == 6 || Month == 9 || Month == 11) {
                   maxDays = 30;
                }
                if (Month == 2){
                   if (Year % 4 > 0)
                      maxDays =28;
                   else
                   if (Year % 100 == 0 && Year % 400 > 0)
                      maxDays = 28;
                   else
                      maxDays = 29;
                }
                // Determine if the day entered is less than the max days for that month.
                if (Day <= maxDays)
                    flag = true;
                else
                    flag = false;
             }
          }
          else
            flag = false;

            break;
        }
        default :
        {
            alert('L : ' + mode ) ;
            return false ;
            break ;
        }
    }

    if ( flag )
        return true ;
    else
    {
    	if(no_focus != "1")
        	input_obj.focus() ;
        if ( trim(msg) != '' )
            alert(msg) ;
        return false ;
    }
}

function DisplayPhoto(filename){
	document.getElementById('DisplayPhotoTag').innerHTML="<img src='"+filename+"'>";
	location.href="#photo";
}

//===================================================================
// 設? Radio ????
// ex: InitRadio(window.form1.xRadio, "1");
//===================================================================
function InitRadio(sCtl, str)
{
   for(i=0; i < sCtl.length; i++)
    {
        if( sCtl[i].value == str )
        {
           sCtl[i].checked=true;
            break ;
        }
    }
}


//===================================================================
// 設? CheckBox ????
// ex: InitCheckBox(window.form1.xCheckBox, "1");
//===================================================================
function InitCheckBox(sCtl, str)
{
        if( sCtl.value == str )
        	sCtl.checked=true;
}


// 將控?????設?str(?於 radio, checkbox)
function setRadio(optCtl)
{
	optCtl.checked=true;
}

//===================================================================
// 設? Checkbox ?部???全???
// ex: SetCheckBoxAll(window.form1.xCheckbox, true|flase);
//===================================================================
function SetCheckBoxAll(obj, str)
{
	if ( !obj.length )  // ??一?checkbox
		obj.checked=str;
	else
	{
		for (z=0;z<obj.length;z++)
			obj[z].checked=str;
	}
}


//===================================================================
// 統?字數
// ex: jsCountTxt(window.form1.object, max,show count ID,left ID);
//===================================================================
function jsCountTxt(obj,intMax,str,str2){
if (obj!= null) {
	var data=obj.value;
	var datalen=data.length;
	var times=0;
	if(datalen > intMax){
		obj.value=data.substr(0,intMax);
		datalen=obj.value.length;
	}
	times = intMax-datalen;
	if (str.length>0)
		document.getElementById(str).innerHTML = datalen;
	if (str2.length>0)
		document.getElementById(str2).innerHTML = times;
}
}

function opener_url(strURL){
	if ($.browser.msie){
		var sData = window.dialogArguments;
		sData.location.href = strURL;}
	else{
		opener.location.href = strURL;}
        window.close();
}

function ChangePic(id,pic){
	document.getElementById(id).src=pic;
}

function PushMBlog(type,url,title,lead)
{
	var sel='';
	if (window.getSelection) { sel = window.getSelection();}
	else if (document.getSelection) {sel = document.getSelection();}
	else if (document.selection) {sel = document.selection.createRange().text;}
	if (sel != "")
		{lead = sel;}
	if (type=="twitter") 
		{javascript: void(window.open('http://twitter.com/home/?status='.concat(encodeURIComponent(title+' '+lead+'...')) .concat(' ') .concat(encodeURIComponent(url))));}
	else if (type=="plurk")
		{javascript: void(window.open('http://www.plurk.com/?qualifier=shares&amp;status=' .concat(encodeURIComponent(url)) .concat(' ') .concat('(') .concat(encodeURIComponent(title)) .concat(') ') .concat(encodeURIComponent('...')),"plurk"));
		}
	else if (type=="facebook")
		{javascript: void(window.open('http://www.facebook.com/share.php?u=' + encodeURIComponent(url) ,"facebook"));
		}
}


// Use this function to retrieve a cookie.
    function getCookie(name)
    {
        var cname = name + "=";
        var dc = document.cookie;
        if (dc.length > 0)
        {
            begin = dc.indexOf(cname);
            if (begin != -1)
            {
                begin += cname.length;
                end = dc.indexOf(";", begin);
                if (end == -1) end = dc.length;
                return unescape(dc.substring(begin, end));
            }
        }
        return null;
    }

// Use this function to save a cookie.
    function setCookie(name, value, expires)
    {
        var exp = new Date();
        exp.setTime(exp.getTime()+(31*86400*1000));
        if(expires>"")
		document.cookie = name + "=" + escape(value) + "; path=/" + "; expires=" + expires;
	else
		document.cookie = name + "=" + escape(value) + "; path=/" + "; expires=" + exp.toGMTString();
    }

// Use this function to delete a cookie.
    function delCookie(name)
    {
        var exp = new Date();
        exp.setTime(exp.getTime()-30);
        document.cookie = name + "=" + "; path=/" + "; expires=" + exp.toGMTString();
    }

// MM_swapImgRestore v3.0
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//get bless
function getBless(){var xmlhttp=false;try{xmlhttp=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{xmlhttp=new
ActiveXObject('Microsoft.XMLHTTP');}catch(E){xmlhttp=false;}}
if(!xmlhttp&&typeof XMLHttpRequest!='undefined'){xmlhttp=new XMLHttpRequest();}
var file='/func/getbless.asp?id=';xmlhttp.open('GET',file+id,true);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){var content=xmlhttp.responseText;if(content){var temp=content.split("<br>");for(loop=0;loop<(temp.length-1);loop++){var loopid=loop+id-10;pausecontent2[loopid]=temp[loop]+"<br>";}}}}
xmlhttp.send(null);if(id<maxChannelNum){id=id+10;var callChannel=setTimeout("getBless()",40000)}else{id=0;clearTimeout(callChannel);}}


//bless push
function pausescroller(content,divId,divClass,delay){this.content=content
this.tickerid=divId
this.delay=delay
this.mouseoverBol=0
this.hiddendivpointer=1
//document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div><div align=right>i<a class=f9 href="/member/bless.asp">ְU</a>j</div></div>')
var scrollerinstance=this
if(window.addEventListener)
window.addEventListener("load",function(){scrollerinstance.initialize()},false)
else if(window.attachEvent)
window.attachEvent("onload",function(){scrollerinstance.initialize()})
else if(document.getElementById)
setTimeout(function(){scrollerinstance.initialize()},500)}
pausescroller.prototype.initialize=function(){this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv,this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if(window.attachEvent)
window.attachEvent("onunload",function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()},this.delay)}
pausescroller.prototype.animateup=function(){var scrollerinstance=this
if(parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()},50)}
else{this.getinline(this.hiddendiv,this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()},this.delay)}}
pausescroller.prototype.swapdivs=function(){var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer}
pausescroller.prototype.getinline=function(div1,div2){div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight,div1.offsetHeight)+"px"}
pausescroller.prototype.setmessage=function(){var scrollerinstance=this
if(this.mouseoverBol==1)
setTimeout(function(){scrollerinstance.setmessage()},100)
else{var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)?0:i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()}}
pausescroller.getCSSpadding=function(tickerobj){if(tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if(window.getComputedStyle)
return window.getComputedStyle(tickerobj,"").getPropertyValue("padding-top")
else
return 0}

// confirm
document.write("<div id=\'modal-confirm\' style=\'display:none;\'><div class=\'modal-header\'><span>`NI</span></div><p class=\'message\'></p><div class=\'buttons\'><div class=\'simplemodal-close\'>_</div><div class=\'simplemodal-yes\'>O</div></div></div>");
function ModalConfirm(message, callback, yesname, noname, header) {
	$('.modal-header').html(header);
	$('.simplemodal-yes').html(yesname);
	$('.simplemodal-close').html(noname);
	$('#modal-confirm').modal({
		closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId:'modal-confirm-overlay',
		containerId:'modal-confirm-container', 
		onShow: function (dialog) {
			$('.message', dialog.data[0]).append(message);

			// if the user clicks "yes"
			$('.simplemodal-yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
			});
		}
	});
}
function ModalAlert(message, callback, btnname, header) {
	ModalConfirm(message, callback, btnname, '', header);
	$('.simplemodal-close').hide();
}

// ajax-loading msg
document.write("<div id=\'ajax-loading\' style=\'position: fixed; display:none;z-index:1;\'><span>еy...</span><p><img src=\'/image/ajax-loader.gif\'></p></div>");

function AjaxLoadingPanel(act){
  if (act=="0") {
    $.unblockUI();
    //$('#ajax-loading').hide();
  }
  if (act=="1") {
    var nTop = ($(window).height()-$('#ajax-loading').outerHeight())/2;
    var nLeft = ($(window).width()-$('#ajax-loading').outerWidth())/2;
    //alert(nTop + ", " + nLeft);
    $('#ajax-loading').css("top",nTop).css("left",nLeft);
    $.blockUI({ message: $('#ajax-loading') });
    //$('#ajax-loading').show()
  }
}