// JavaScript Document
//-------------// color box //----------start-------//
			$(document).ready(function(){
				//Examples of how to assign the ColorBox event to elements
				$("a[rel='example1']").colorbox();
				$("a[rel='example2']").colorbox({transition:"fade", width:"100%", height:"100%"});
				$("a[rel='example2_1']").colorbox({transition:"fade", width:"100%", height:"100%"});
				$("a[rel='example2_2']").colorbox({transition:"fade", width:"100%", height:"100%"});
				$("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
				$("a[rel='example4']").colorbox({slideshow:true});
				$(".example5").colorbox();
				$(".example6").colorbox({iframe:true, innerWidth:780, innerHeight:576});
				$(".example7").colorbox({width:"80%", height:"80%", iframe:true});
				$(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"});
				$(".example9").colorbox({
					onOpen:function(){ alert('onOpen: colorbox is about to open'); },
					onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
					onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
					onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
					onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
				});
				
				//Example of preserving a JavaScript event for inline calls.
				$("#click").click(function(){ 
					$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
					return false;
				});
			});
			//-------------// color box //----------end-------//

function ajaxSubmit(url,getid,sendid){
	var sel = document.getElementById(getid);
	var idx = sel.selectedIndex;
	var data = "&getid="+sel.options[idx].value+"&sendid="+sendid;
	var URL = url;
	ajaxLoad('get',URL,data,'alert');
}

function sendData(url){
	var URL = url;
	var data = getFormData('frm');
	ajaxLoad('post',URL,data,'alert');
}

function DeleteData(url,id){
	if(confirm("ต้องการลบใช้หรือไม่")){
		var URL = url;
		var data = "&id="+id;
		ajaxLoad('get',URL,data,'alert');
	}
}

function ChangeStatus(url,id,display){
	if(confirm("ต้องการเปลี่ยนสถานะใช่หรือไม่")){
		var URL = url;
		var data = "&id="+id+"&display="+display;
		ajaxLoad('get',URL,data,'alert');
	}
}

function checkEmail(input){
	 var RE = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$/;
 	return (RE.test(input)); 
}
function checkCharEn(input){
	 var RE = /^[a-zA-Z0-9]+$/;
 	return (RE.test(input)); 
}
function checkPassword(input){
	 var RE = /^[a-zA-Z0-9]{6,14}$/;
 	return (RE.test(input)); 
}

function chkUser(id,displayid)
  {
	var url = "admin/func/chkuser.php";
	var data = "&uname="+document.getElementById(id)+"&id="+displayid;
	ajaxLoad('post',url,data,displayid);
  }
  
function checkCharEnInputU(id,displayid){
	if(!checkCharEn(document.getElementById(id).value)){
		document.getElementById(displayid).innerHTML = "กรอกข้อมูลไม่ถูกต้อง ต้องเป็นภาษาอังกฤษหรือตัวเลขเท่านั้น";
		document.getElementById(id).style.border = "1px solid #F00";
	}else{
		chkUser(id,displayid);
	}
}	

function checkEmailInput(id,displayid){
	if(!checkEmail(document.getElementById(id).value)){
		document.getElementById(displayid).innerHTML = "กรอกอีเมล์ไม่ถูกต้อง";
		document.getElementById(id).style.border = "1px solid #F00";
	}else{
		document.getElementById(displayid).innerHTML = "ผ่าน";
		document.getElementById(id).style.border = "1px solid #CCC";
	}
}
function checkCharEnInput(id,displayid){
	if(!checkCharEn(document.getElementById(id).value)){
		document.getElementById(displayid).innerHTML = "กรอกข้อมูลไม่ถูกต้อง ต้องเป็นภาษาอังกฤษหรือตัวเลขเท่านั้น";
		document.getElementById(id).style.border = "1px solid #F00";
	}else{
		document.getElementById(displayid).innerHTML = "ผ่าน";
		document.getElementById(id).style.border = "1px solid #CCC";
	}
}
function checkPasswordInput(id,displayid){
	if(!checkPassword(document.getElementById(id).value)){
		document.getElementById(displayid).innerHTML = "กรอกข้อมูลไม่ถูกต้อง ต้องเป็นตัวอักษรภาษาอังกฤษและตัวเลข 6-14 ตัวอักษรเท่านั้น";
		document.getElementById(id).style.border = "1px solid #F00";
	}else{
		document.getElementById(displayid).innerHTML = "ผ่าน";
		document.getElementById(id).style.border = "1px solid #CCC";
	}
}
function checkPasswordAgainInput(id,displayid){
	if(!checkPassword(document.getElementById(id).value)){
		document.getElementById(displayid).innerHTML = "กรอกข้อมูลไม่ถูกต้อง ต้องเป็นตัวอักษรภาษาอังกฤษและตัวเลข 6-14 ตัวอักษรเท่านั้น";
		document.getElementById(id).style.border = "1px solid #F00";
	}else if(document.getElementById(id).value!=document.getElementById('passwd').value){
		document.getElementById(displayid).innerHTML = "กรอกข้อมูลไม่ถูกต้อง";
		document.getElementById(id).style.border = "1px solid #F00";
	}else{
		document.getElementById(displayid).innerHTML = "ผ่าน";
		document.getElementById(id).style.border = "1px solid #CCC";
	}
}
function sendAdminData(url){
	var uname = document.getElementById('uname').value;
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	if(uname == "" || name == "" || email == ""){
		document.getElementById('alert').innerHTML = "กรอกข้อมูลไม่ครบ";
		alert("กรอกข้อมูลไม่ครบ");
	}else{
		sendData(url);
	}
}
function sendAdminProfile(url){
		sendData(url);
}
function sendPositionData(url){
	var pname = document.getElementById('pname').value;
	if(pname == ""){
		document.getElementById('alert').innerHTML = "กรอกข้อมูลไม่ครบ";
		alert("กรอกข้อมูลไม่ครบ");
	}else{
		sendData(url);
	}
}
function sendCatData(url){
	var catname = document.getElementById('catname').value;
	if(catname == ""){
		document.getElementById('alert').innerHTML = "กรอกข้อมูลไม่ครบ";
		alert("กรอกข้อมูลไม่ครบ");
	}else{
		sendData(url);
	}
}

function sendrCatData(url){
	var catname = document.getElementById('rcatname').value;
	if(catname == ""){
		document.getElementById('alert').innerHTML = "กรอกข้อมูลไม่ครบ";
		alert("กรอกข้อมูลไม่ครบ");
	}else{
		sendData(url);
	}
}

function sendSCatData(url){
	var catname = document.getElementById('scatname').value;
	if(catname == ""){
		document.getElementById('alert').innerHTML = "กรอกข้อมูลไม่ครบ";
		alert("กรอกข้อมูลไม่ครบ");
	}else{
		sendData(url);
	}
}
function sendComData(url){
	var comname = document.getElementById('comname').value;
	var comlink = document.getElementById('comlink').value;
	if(comname == "" || comlink== "" ){
		document.getElementById('alert').innerHTML = "กรอกข้อมูลไม่ครบ";
		alert("กรอกข้อมูลไม่ครบ");
	}else{
		sendData(url);
	}
}
function sendLinkData(url){
	var linkdesc = document.getElementById('linkdesc').value;
	var linkurl = document.getElementById('linkurl').value;
	if(linkdesc == "" || linkurl== "" ){
		document.getElementById('alert').innerHTML = "กรอกข้อมูลไม่ครบ";
		alert("กรอกข้อมูลไม่ครบ");
	}else{
		sendData(url);
	}
}

function popup(url,name,windowWidth,windowHeight){    
	myleft=(screen.width)?(screen.width-windowWidth)/2:100;	
	mytop=(screen.height)?(screen.height-windowHeight)/2:100;	
	properties = "width="+windowWidth+",height="+windowHeight;
	properties +=",scrollbars=yes, top="+mytop+",left="+myleft;   
	window.open(url,name,properties);
}

function changemenulevel(key){
	var menulevel = document.getElementById('menulevel'+key).value;
	var menuid = document.getElementById('menuid'+key).value;
	var URL = "menu/func/changelevel.php";
	var data = "&menulevel="+menulevel+"&menuid="+menuid;
	ajaxLoad('get',URL,data,'alert');
}

function changbbmenu(key){
	var id_topic = document.getElementById('id_topic'+key).value;
	var id_menu = document.getElementById('id_menu'+key).value;
	var URL = "board/func/changelevel.php";
	var data = "&id_topic="+id_topic+"&id_menu="+id_menu;
	ajaxLoad('get',URL,data,'alert');
}

function changgruplinkmenu(key){
	var id_link_grup = document.getElementById('id_link_grup'+key).value;
	var id_menu = document.getElementById('id_menu'+key).value;
	var URL = "component/com_weblink/func/changegrupmenu.php";
	var data = "&id_link_grup="+id_link_grup+"&id_menu="+id_menu;
	ajaxLoad('get',URL,data,'alert');
}

function changelinkmenu(key){
	var linkid = document.getElementById('linkid'+key).value;
	var id_menu = document.getElementById('id_menu_link'+key).value;
	var URL = "component/com_weblink/func/changelinkmenu.php";
	var data = "&linkid="+linkid+"&id_menu_link="+id_menu;
	ajaxLoad('get',URL,data,'alert');
}

function changemenubanner(key){
	var bannerid = document.getElementById('bannerid'+key).value;
	var id_banner = document.getElementById('id_banner'+key).value;
	var URL = "component/com_banner/func/changemenu.php";
	var data = "&bannerid="+bannerid+"&id_banner="+id_banner;
	ajaxLoad('get',URL,data,'alert');
}

function resetpassword(adminid){
	var URL = "admin/func/resetpassword.php";
	var data = "&adminid="+adminid;
	ajaxLoad('get',URL,data,'alert');
}

function resetMemberpassword(memid){
	var URL = "member/func/resetpassword.php";
	var data = "&memid="+memid;
	ajaxLoad('get',URL,data,'alert');
}

