// JavaScript Document

///////////////////////////////////////////////////////////////////////////////
//
//  Index.php
//
///////////////////////////////////////////////////////////////////////////////
function account_mail()
{
	var Email = window.document.Login.email;

  if (Email.value=="") {
    alert("請先填入電郵位址！");
    return false;
  }
  else {
    alert("帳號資料將會寄到這個信箱，請稍後檢查您的郵件！");
    location.href = "http:/urequest.php?email=" + Email.value;
//    location.replace(location.href);
  }
  return true;
}

function check_loginform()
{
	var Email = window.document.Login.email;
	var Pwd = window.document.Login.password;
		
  if (Email.value=="") {
    alert("請先填入電郵位址！");
    return false;
  }
  
  if (Pwd.value=="") {
    alert("請填入密碼！");
    return false;
  }
  return true;
}



///////////////////////////////////////////////////////////////////////////////
//
//  Newnotice.php
//
///////////////////////////////////////////////////////////////////////////////
function changeAction(PageNo)
{
  document.forms[0].action = "http:/newnotice.php";
  document.forms[0].submit();
  return true;
}

function checkMainform()
{
	var Input = document.getElementsByTagName("input");
	var Msg = document.getElementsByTagName("textarea");
	
 	for (var i=0; i<Input.length; i++) {
 	  if(Input[i].type == "text") {
      if(Input[i].value == "" || Input[i].value == " ") {
        alert("每個欄位都需填寫資料！");
        return false;
      }
  	}
 	}
 	
 	if(Msg[0].value == "" || Msg[0].value == " ") {
   	alert("內容不可空白！");
    return false;
 	}
 	         
 	return true;
}

function checkDates(form)
{
  var today = new Date();

  today.setHours(0);
  today.setMinutes(0);
  today.setSeconds(0);

  if ( Date.parse(today) > Date.parse(form.postdate.value) )
  {
    alert("日期不可早於今天！");
    var mon = today.getMonth() + 1;
    var day = today.getDate();
    form.postdate.value = today.getYear() + "/" + mon + "/" + day;
    return;  
  }
}

//
// usage sample
// <a href="javascript:checkall('test','v1',true)">Check All</a><br>
// <a href="javascript:checkall('test','v1',false)">Uncheck All</a>
function checkall(formname, checkname, thestate)
{
  var el_collection;
  
  el_collection = eval("document.forms." + formname + "." + checkname);

  for (var m=0; m<el_collection.length; m++)
    el_collection[m].checked=thestate;
}


function add_selected()
{
  var Selected = new Array();
  var i, m = 0;
  var aForm = document.forms[0];
	var Input = document.getElementsByTagName("input");

 	for (i=0; i<Input.length; i++) {
  	if(Input[i].type == "checkbox" && Input[i].checked) {
      Selected[m++] = Input[i].value;
      Input[i].checked = false;
  	}
 	}
  
  for (i=0; i<m; i++) {
      aForm.recipient.value += Selected[i];
      aForm.recipient.value += ";";
  }
  checkall(aForm, 'choice', false);
}

function checkTAlength(form)
{
  var len = form.content.value.length;
  if (len>180) {
    alert("現在字數為"+len+"，請縮短到不超過180字！");
    form.content.focus();
  }
}

function backtoMain()
{
  location.href = "http:/thedate.php";
}

function backtoReport()
{
  location.href = "http:/reppage.php";
}

// Ref: <a href="javascript:history.back()">click here</a>



///////////////////////////////////////////////////////////////////////////////
//
//  Adbook.php
//
///////////////////////////////////////////////////////////////////////////////

function checkAddrform()
{
  var form = window.document.addrform;

  for (var i=0; i<form.elements.length; i++) {
    if ((form.elements[i].type == "text") && (form.elements[i].value == ''))
    {
      alert('請填滿每個欄位！');
      return false;
    }
  }
  return true;
}

function checkwhoselected()
{
  var Selected = new Array();
  var m = 0;
  var Result = false;

	var Input = document.getElementsByTagName("input");
 	for (var i=0; i<Input.length; i++) {
  	if(Input[i].checked) {
      Selected[m++] = Input[i].value;
      Result = true;;
  	}
 	}

 	return Result;
}

///////////////////////////////////////////////////////////////////////////////
//
//  Invite.php
//
///////////////////////////////////////////////////////////////////////////////
var InviteWin;

function makeNewWindow()
{
  if (!InviteWin || InviteWin.closed) {
    InviteWin = window.open("http:/invite.php", "newwindow", "height=550, width=580 toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
  }
  else {
    // window’s already open; bring to front
    InviteWin.focus();
  }
}

///////////////////////////////////////////////////////////////////////////////
//
//  thedate.php
//
///////////////////////////////////////////////////////////////////////////////
function checkReply()
{
  if (this.Rmsg.selectedIndex == 0) {
    alert("請先選擇一個回覆訊息。");
    return false;
  }
  
  return true;
}


///////////////////////////////////////////////////////////////////////////////
//
// makerep.php
//
///////////////////////////////////////////////////////////////////////////////

function TAInputCheck(form, maxChr)
{
//  var maxChr = 300;
	var nowChr = 0;

//  nowChr = form.content.value.length;
	for (var i=0; i<form.content.value.length; i++) {
		form.content.value.charCodeAt(i)<256 ? nowChr++ : nowChr+=2;
	}
  
  if (nowChr > maxChr) {
    form.content.value = form.content.value.substring(0, maxChr);
    alert("你已輸入超過" + (nowChr-maxChr) + "個字元。");
  }
  else {
  	document.getElementById("chrcounter").innerHTML =
          "<font size=\"-1\" color=\"#DE0022\">目前已輸入"+nowChr+"個字元，最多可輸入"+maxChr+"個字元。</font><p>";
  }
}
///////////////////////////////////////////////////////////////////////////////

