function CkNum(text){
	var tomatch=text.value.match(/[^0-9]/g);	
	if(text.value!='')
	{		
		if(tomatch)
		{
			alert("Must insert number.");
			text.focus();
			text.select();
			return false;
		}
	}
}
function CkMail(mail)
{
	var tomatch=/[A-Za-z0-9_\-\.]+@([0-9a-z][a-z0-9_\-\.]+)(\.)[A-Za-z\.]{2,}/;	
	if(mail.value!='')
	{		
		if(!tomatch.test(mail.value))
		{
			alert("E-mail format incorrect!!");
			mail.focus();
			mail.select();
			return false;
		}
	}
}
function CkPhoto(text){
	extname=GetExtName(text);
	if(!(extname=="jpg" || extname=="jpeg" || extname=="gif")){
		alert("相片格式錯誤！\n僅接受\"JPG\"或\"GIF\"檔案格式！");
		return false;
	}		
	return true;
}
function GetExtName(text){
	var extname='';
	var pointno=text.value.lastIndexOf('.');
	var len=text.value.length;
	for(i=pointno+1;i<len;i++){
		extname=extname + text.value.charAt(i);
	}
	extname=extname.toLowerCase();
	return extname;
}
function CkFileName(text){
	filename=GetFileName(text);
	var tomatch=filename.match(/[^A-Za-z0-9_-]/g);
	if(tomatch)
	{
		alert("上傳檔案檔名必需為英文字母、數字或底線，\n不可使用中文或包含特殊符號。!!");
		return false;
	}
	return true;
}
function GetFileName(text){
	var filename='';	//相片檔名
	var pointno1=text.value.lastIndexOf('\\');
	var pointno2=text.value.lastIndexOf('.');
	for(i=pointno1+1;i<pointno2;i++){
		filename=filename + text.value.charAt(i);
	}
	return filename;
}
function IsReadyContact(form){
  	if(form.company.value==''){
		alert("Please insert Company name.");
		form.company.focus();
		return false;
	}
  	if(form.con_name.value==''){
		alert("Please insert Contact person.");
		form.con_name.focus();
		return false;
	}
  	if(form.tel.value==''){
		alert("Please insert Tel.");
		form.tel.focus();
		return false;
	}
	if(form.e_mail.value==''){
		alert("Please insert E-mail.");
		form.e_mail.focus();
		return false;
	}
	if(form.subject.value==''){
		alert("Please insert Subject.");
		form.subject.focus();
		return false;
	}
	if(form.content.value==''){
		alert("Please insert Comments.");
		form.content.focus();
		return false;
	}
	for($kk=0; $kk<1; $kk++){
		if(eval('form.uppic_' + $kk).value!=''){
			var text=eval('form.uppic_' + $kk);
			if(!CkFileName(text)){
				text.focus();
				text.select();
				return false;
			}
			if(!CkPhoto(text)){
				text.focus();
				text.select();
				return false;
			}
		}
	}
	if(form.reg_no.value!=''){
		form.check_flg.value='etan';
	}
}

function ProdSearch(form){
  	if(form.str_qry.value==''){
		alert("Please insert Key word.");
		form.str_qry.focus();
		return false;
	}
}

//重新產生驗證碼圖片
//傳入驗證碼圖片元件
function reloadRegNoImg(img){
	img.src='../lib/create_reg_no_graph/create_reg_no_graph.php?s='+Math.random();//加上隨機參數解決ie8圖片即時刷新問題
}

//快速選單開始
//次選單預設選取值
//sel_value預設要選取的options的value
//要在body的 onLoad="set_select_default('form.roadid',series,<?php echo $townid;?>,<?php echo $roadid;?>);"
function set_select_default(obj_name,items,kind,sel_value){
	o = set_select_clean(obj_name);
	j = 0;	//次選單的options計數
	for(i = 0 ;i < items.length;i++){
		if(items[i].kind == kind){
			o.options[o.length] = new Option(items[i].option,items[i].value);
			if(items[i].value==sel_value){	//比對預設要選取的options的value
				o.selectedIndex = j;
			}
			j++;	//次選單的options計數
		}
	}
}
function set_select(obj_name,items,kind){
	o = set_select_clean(obj_name);
	for(i = 0 ;i < items.length;i++)
		if(items[i].kind == kind)
			o.options[o.length] = new Option(items[i].option,items[i].value);
}

function set_select_clean(obj_name){
	o = eval(obj_name + ".options")
	o.length = 0
	return o
}
function set_series(items,kind,value,option){
	items[items.length] = new new_item(kind,value,option)
}

function new_item(kind,value,option){
	this.kind = kind
	this.value = value	
	this.option = option
}
//快速選單結束

//跳出視窗定位
function OpenPage(topage,pagename,w,h,bar,resize) { 
	x = (screen.width - w)/2;
	y = (screen.height - h)/2;
	window.open(topage,pagename,'left='+x+',top='+y+',width='+w+',height='+h+',scrollbars='+bar+',resizable='+resize);
}
//跳出視窗定位，完整
function OpenPage_Full(topage,pagename,w,h,directories,location,menubar,resizable,scrollbars,staus,toolbar) { 
	x = (screen.width - w)/2;
	y = (screen.height - h)/2;
	window.open(topage,pagename,'left=' + x + ',top=' + y + ',width=' + w + ',height=' + h + ',directories=' + directories + ',location=' + location + ',menubar=' + menubar + ',resizable=' + resizable + ',scrollbars=' + scrollbars + ',staus=' + staus + ',toolbar=' + toolbar);
}


