// JavaScript Document
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name;nm_id=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='→  請輸入正確的 「'+nm_id+'」 格式。\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='→ 「'+nm+'」必須為數字。\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '→ 「'+nm_id+'」 為必填欄位。\n'; }
}
 
 var frm = args[args.length-1];
 
 //密碼長度檢查4-12
 if(frm.password)
 {
  if(frm.password != null && (frm.password.value.length > 7 || frm.password.value.length < 4 ))
  errors += '→   密碼長度在4~7個字元間。\n'

  //確認密碼檢查
  if(frm.confirm_pass)
  if(frm.password != null && frm.password.value != frm.confirm_pass.value)
  errors += '→ 「登入密碼」與「確認密碼」不符。\n';
 }
  
 if(frm.mail_confirm && frm.email.value != frm.mail_confirm.value)
 errors += '→ 「電子信箱」與「確認信箱」不符。\n';
  
 if(frm.sexual) 
  errors += confirm_checkboxes(frm.sexual,'→   請點選您的「性別」。\n');

　if(frm.build) 
  errors += confirm_checkboxes(frm.build,'→   請點選您的「住宅型態」。\n');
 
 if(frm.contact_type) 
  errors += confirm_checkboxes(frm.contact_type,'→   請點選您的「詢問事項」。\n');
 
 if(document.getElementById('public'))
  {
	 var public = document.getElementById('public');
	 if(!public.checked && frm.pwd.value.length < 4)
	 {
	  errors += '→   請輸入4位數「保密密碼」(英數皆可)。\n';
	 }
  }
 
 if(frm.city)
  {
	if(frm.city.value == '請選擇...')
	errors += '→   請選擇「居住地區」。\n';
  }
 
 if(document.getElementById('yy'))
  {
	var yy = document.getElementById('yy');
	if(yy.value == 'null')
	errors += '→   請選擇您的出生「年份」。\n';  
  }
  
  if(document.getElementById('mm'))
  {
	var mm = document.getElementById('mm');
	if(mm.value == 'null')
	errors += '→   請選擇您的出生「月份」。\n';  
  }
  
  if(document.getElementById('dd'))
  {
	var dd = document.getElementById('dd');
	if(dd.value == 'null')
	errors += '→   請選擇您的出生「日」。\n';  
  }
 
 if (errors) alert('無法送出表單，請填寫下列項目：\n'+errors);
  document.MM_returnValue = (errors == '');
}

//檢查核取方塊的必填欄位是否有值
function confirm_checkboxes(obj,val)
{
var	chk_skin=0;	

	for(x=0;x<obj.length;x++)
	 {
		  if(obj[x].checked == true )
		  {
		   chk_skin++;
		  }	 
	 } 
	 if(chk_skin==0)
	 return val;
	 else
	 return '';
}