// JavaScript Document
function onCheck(type) 
{

    if (isEmail(forms.email.value) == false )
	{
	alert("請輸入有效之E-mail，謝謝!!"); 
	forms.email.focus();     	
	return false;
	
	}
	
		switch(type){
			
			case "add":
				document.forms.action="epaperadd.php";
				forms.submit();     	
				return true;
			break;
			case "cancel":
				document.forms.action="epapercancel.php";
				forms.submit();     	
				return true;
			break;
		}
	
}
function epaper(type){
  switch(type){	
    case"add":
      document.getElementById("epaper").style.display='block';
	break;
	case "cancel":
	  document.getElementById("epaper").style.display='none';
	break;
  }
}
function isEmail(mailAddr)
{ 
  if(!mailAddr)                 return false; 
  if(mailAddr.indexOf("@")==-1) return false; 
  if(mailAddr.indexOf("@")==0)  return false; 
  if(mailAddr.indexOf("@")!=mailAddr.lastIndexOf("@")) 
  return false; 
  
  var mailStrArray=new Array(); 
  mailStrArray=mailAddr.split(".") 
   
  if(mailStrArray.length<2) 
  return false; 
   
  var mailString=new Array(); 
  mailString=mailAddr.split("@"); 
  var iChars = " *|,\"<:>[]{}`\';()&$#%"; 
  for(var i=0;i<mailString[0].length;i++)
  { 
     if(iChars.indexOf(mailString[0].charAt(i)) != -1) 
     return false; 
  } 
  for(var j=0;j<mailString[1].length;j++){ 
    if(mailString[1].charCodeAt(j)<48 && mailString[1].charCodeAt(j)!=46 && mailString[1].charCodeAt(j)!=45)  return false; 
    if(mailString[1].charCodeAt(j)>122) return false; 
    if((mailString[1].charCodeAt(j)>90) && (mailString[1].charCodeAt(j)<97)) return false; 
  } 
  var domain=new Array(); 
  domain=mailString[1].split("."); 
  for(var j=0;j<domain[domain.length-1].length;j++)
  { 
    if(domain[domain.length-1].charCodeAt(j)>47 && domain[domain.length-1].charCodeAt(j)<58) 
    return false; 
  } 
  return true; 
} 

function contactCheck() 
{
    if (noKeyIn(form1.company, "請輸入公司名稱。")  )
	{   	
		return false;
	}
    if (noKeyIn(form1.TITLE2, "請輸入聯絡人。")  )
	{   	
		return false;
	}
    if (noKeyIn(form1.Tel3, "請輸入電話。")  )
	{   	
		return false;
	}
    if (isEmail(form1.Email2.value) == false )
	{
	alert("請輸入有效之E-mail，謝謝!!");      	
	return false;
	
	}
	form1.submit();
	return true;
	
}
function noKeyIn(input, ErrorMsg)
{  
	if (input.value=='')
   	{
     		//input.focus();
     		alert(ErrorMsg);
     		return true;
    }
	return false;
}

//disable right click
 function clickIE4(){
  if (event.button==2){
   return false;
  }
 }
 
 function clickNS4(e){
  if (document.layers||document.getElementById&&!document.all){
  if (e.which==2||e.which==3){
   return false;
   }
  }
 }
 
 if (document.layers){
  document.captureEvents(Event.MOUSEDOWN);
  document.onmousedown=clickNS4;
 }
  else if (document.all&&!document.getElementById){
  document.onmousedown=clickIE4;
 }
 document.oncontextmenu=new Function("return false")

//disable text selection
 var omitformtags=["input", "textarea", "select"]
 omitformtags=omitformtags.join("|")
 
 function disableselect(e){
  if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
  return false
 }
 
 function reEnable(){
  return true
 }
 
 if (typeof document.onselectstart!="undefined")
  document.onselectstart=new Function ("return false")
 else{
  document.onmousedown=disableselect
  document.onmouseup=reEnable
 }
 
// --> 