function ajaxRenderArea(val){
	clearOptionTag('area_id','Please select');
	if(val!=0){
		$.ajax({
			url: 'index.php?module=front.Index.CheckArea',
			data: "1&province_id="+val,
			type: 'post',
			cache: false,
			success: function (data) {
				if(data){
					var txt = eval("("+data+");");
					var pRefObj = document.getElementById('area_id');
					createOptionElements(pRefObj,txt);
				}
			}
		});
	}
}
function CheckNameRest(lang,val){
	if(val!=0){
		$.ajax({
			url: 'index.php?module=front.Restaurantregis.checkrestname',
			data: "1&lang="+lang+"&name="+val,
			type: 'post',
			cache: false,
			success: function (data) {
				if(data){
					alert('มีชื่อร้านอาหารนี้แล้ว');
					$('#rest_name_'+lang).val('');
				}
			}
		});
	}
}	
function clearOptionTag(ID,pselect) {
     var Tag = document.getElementById(ID);
     while(Tag.childNodes.length > 0) {
              Tag.removeChild(Tag.childNodes[0]);
     }
     pRefObj = document.getElementById(ID);
	 var option = document.createElement("option");
		 option.appendChild(document.createTextNode(pselect));
		 option.setAttribute('value','0');
		 pRefObj.appendChild(option);
}
function createOptionElements(pRefObj, pArr){

	for (var i in pArr)
	{
		var option = document.createElement("option");
		option.appendChild(document.createTextNode(pArr[i]));
		option.setAttribute('value',i.replace("key_",""));
		pRefObj.appendChild(option);
	}
}
function SwitchImage(elm,img){
	elm.src=img_path+"/icon/"+img;
}
function Search(){
	document.getElementById('form_search').submit();
}
function CheckUsername(val){
	if(val!=0){
		$.ajax({
			url: 'index.php?module=front.Index.CheckUsername',
			data: "1&username="+val,
			type: 'post',
			cache: false,
			success: function (data) {
				if(data){
					eval(data);
				}
			}
		});
	}
}
function CheckUploadType(myfiles){
		myfile=myfiles.value;
		myfile = myfile.toLowerCase();
		Temp = myfile.charAt(myfile.length-4) + myfile.charAt(myfile.length-3) + myfile.charAt(myfile.length-2) + myfile.charAt(myfile.length-1);
		if(Temp!='.gif' && Temp!='.png' && Temp!='.jpg' && Temp!='.bmp') {
			alert('โปรดเลือกไฟล์รูปภาพที่มีนามสกุล .jpg,.gif,.png,.bmp ด้วยครับ');
		    myfiles.value = "";
        	return false;
        }
		return true;
}
