﻿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];}
}
function swapBg(x, y)
{
	if(y)
	{
		x.style.backgroundColor="#ffffff";
	}
	else
	{
		x.style.backgroundColor="";		
	}
}
function showCalList(d,a,b) 
{ 
  	var element = document.getElementById('calendar_detail_right_'+d);

	if(b)
	{
		var title=eval("cal_topic_"+d+"["+a+"]");
		var location=eval("cal_location_"+d+"["+a+"]");
		var person=eval("cal_person_"+d+"["+a+"]");
		var content=eval("cal_content_"+d+"["+a+"]");
		element.innerHTML="";
		element.innerHTML="<div id='calendar_detail_right_head>"+
								"<div id='calendar_detail_right_title'>事件標題："+title+
								"</div>"+
								"<div id='calendar_detail_right_location'>事件地點："+location+
								"</div>"+
								"<div id='calendar_detail_right_person'>主持人/講師："+person+
								"</div>"+
								"</div>"+
								"<div id='calendar_detail_right_content'>事件內容："+content+
								"</div>";
	}
	else
	{
		hidePopupBox('#calendar_detail_right_'+d);
		element.innerHTML="";
	}
			
}


function treeShowHidden(t,a,b)
{
	var path="image/common/tree/";
  	var node = document.getElementById('level_2_'+t);
	var newbranch= document.getElementById('level_bg_2_'+t);
	var right_node=document.getElementById('level_right_3_'+t);
		
	//隱藏第三層時，bg 使用 tree_line_bg_3.gif (左邊有線, 右邊沒線)
	if(right_node.style.display !="none")
	{
		node.style.background ="url("+path+"tree_show_"+a+".gif)";
		newbranch.style.background ="url("+path+"tree_line_bg_3.gif)";
		newbranch.style.backgroundRepeat="repeat-y"
		right_node.style.display ="none";
	}
	else
	{
		node.style.background ="url("+path+"tree_hidden_"+a+".gif)";
		newbranch.style.background ="url("+path+"tree_line_bg_"+b+".gif)";
		newbranch.style.backgroundRepeat="repeat-y"
		right_node.style.display="block";	
	}
	
}


function CheckformContact() 
{
	var f=document.formContact;
	var captcha = document.getElementById('captcha_input');
	if(f.name.value.length<=0) 
		{
			alert("請填寫姓名，謝謝!!");
			f.name.focus();
		}
	else if(f.phone.value.length<=0 ) 
		{
			alert("請填寫聯絡電話，謝謝!!");
			f.phone.focus();
		}
	else if(! isTel(f.phone.value))
	{
		f.phone.focus();
	}    
	else if(f.mail.value.length<=0 ||  (! isEmail(f.mail.value))) 
		{
			alert("請填寫正確電子郵件地址，謝謝!!");
			f.mail.focus();
		}
	else if(f.title.value.length<=0) 
		{
			alert("請填寫主旨，謝謝!!");
			f.title.focus();
		}
	else if(f.suggestion.value.length<=0) 
		{
			alert("請填寫意見，謝謝!!");
			f.suggestion.focus();
		}
	else if(captcha.value.length<=0) 
		{
			alert("請填寫驗證碼，謝謝!!");
			captcha.focus();
		}
	else
		{
		f.submit();
		}
}

function isEmail(str) 
{
    var supported = 0;
    if (window.RegExp) 
    {
        var tempStr = "a";
        var tempReg = new RegExp(tempStr);
        if (tempReg.test(tempStr)) supported = 1;
    }
    if (!supported) 
    {
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    }
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    return (!r1.test(str) && r2.test(str));
}
function isTel( phone ) 
{
	
    var no = new RegExp("^\\d{7,}.#?\\d+$");
	if(!no.test(phone))
	{
		alert("很抱歉，電話號碼格式範例如下:\n027732994#223");
		return false;
	}
else
	{
     return true;
	}
}


function isCellPhone( phone ) 
{
	
    var no = new RegExp("^\\d+$");
	if(!no.test(phone))
	{
		alert("很抱歉，手機號碼只能填寫數字!!");
		return false;
	}
	else
	{
     return true;
	}
}

//検查CHECK BOX是否有勾選
function delete_item(formName, elementName){
   radio_check= false;

   len = document.forms[formName].elements.length;
   for (var i=0;i<len;i++) {
	   if(document.forms[formName].elements[i].name == elementName){
         if (document.forms[formName].elements[i].checked == true) {
            radio_check = true;
            break;
         }
       }
   }

   if(radio_check==false){
       alert("請勾選要刪除的項目!!");
       return false;
   }
   else{
	   if(document.forms[formName].elements['work'].value=='set_page'){
            msg = "確定將此張相片設成封面?";
	   }
	   else {
            msg = "確定要刪除所勾選的項目?";
	   }
       if(confirm(msg) ){
            //*
            document.forms[formName].submit();
            return true;
            //*/
            /*
			with (document.delete_form){
				action = 'download_private_mod.php';
				method = 'post';
				submit();
				return (true);
			}
                                */
	   }
	   else{
		    return false;
	   }
   }
}
