function newXmlHttp(){

	var xmlhttp		= false;
    var contentType = "application/x-www-form-urlencoded; charset=utf8";
	
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			xmlhttp = false;
		}
	}

	if(!xmlhttp && document.createElement){
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;

}

function display(sID) {
	oObj = document.getElementById(sID);
	if (oObj) {
		oObj.style.display='inline';
	}
}

function hide(sID) {
	oObj = document.getElementById(sID);
	if (oObj) {
		oObj.style.display='none';
	}
}

function getdivcontent(pagefile,divcontent){

	loading('<center><img src="/images/icon_loading.gif" border="0" class="no-border"> กำลังโหลดข้อมูล ...</center>',divcontent);

	var url		 =pagefile;	

	xmlhttp		 =newXmlHttp();
    xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				document.getElementById(divcontent).innerHTML = xmlhttp.responseText;
			}
	}
	xmlhttp.send(null);
}


function loading(msg,divcontent){
	document.getElementById(divcontent).innerHTML = msg;
}

function check_login(){
	var username	=	document.getElementById('form_login').username.value;
	var password	=	document.getElementById('form_login').password.value;

	if (username =="")
	{
		alert("กรุณาระบุชื่อผู้ใช้");
		document.getElementById('form_login').username.focus();
		return false;
	}else if (password =="")
	{
		alert("กรุณาระบุรหัสผ่าน");
		document.getElementById('form_login').password.focus();
		return false;
	}else
	{
		document.getElementById('form_login').submit();
	}

}


function check_profile(){

	var password1	=	document.getElementById('form_profile').password1.value;
	var password2	=	document.getElementById('form_profile').password2.value;

	var name		=	document.getElementById('form_profile').name.value;
	var surname		=	document.getElementById('form_profile').surname.value;
	var nickname	=	document.getElementById('form_profile').nickname.value;
	var email		=	document.getElementById('form_profile').email.value;

	var emailRE		= /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

if ((password1 !="")&&(password1 != password2))
{
	alert("กรุณาตรวจสอบรหัสผ่านอีกครั้ง");
	document.getElementById('form_profile').password1.focus();
	return false;
}

if (name =="")
{
	alert("กรุณาตรวจสอบชื่อ");
	document.getElementById('form_profile').name.focus();
	return false;
}

if (surname =="")
{
	alert("กรุณาตรวจสอบนามสกุล");
	document.getElementById('form_profile').surname.focus();
	return false;
}

if (nickname =="")
{
	alert("กรุณาตรวจสอบชื่อเล่น");
	document.getElementById('form_profile').nickname.focus();
	return false;
}

if (!emailRE.test(email))
{
	alert("กรุณาตรวจสอบอีเมล์");
	document.getElementById('form_profile').email.focus();
	return false;
}else{

	document.getElementById('form_profile').submit();

}

}


function type_add(){
	var type_name			=	document.form_type_add.type_name.value;
	var type_detail			=	document.form_type_add.type_detail.value;
	var type_path			=	document.form_type_add.type_path.value;
	var type_sort			=	document.form_type_add.type_sort.value;
	var numRE				= /^\d+$/;

if (type_name =="")
{
	alert("กรุณาตรวจสอบหัวข้อเรื่อง");
	document.form_type_add.type_name.focus();
	return false;
}

if (type_detail =="")
{
	alert("กรุณาตรวจสอบรายละเอียด");
	document.form_type_add.type_detail.focus();
	return false;
}




if (!numRE.test(type_sort)){
	alert("กรุณาตรวจสอบลำดับการแสดงผล");
	document.form_type_add.type_sort.focus();
	return false;
}else{

	document.form_type_add.submit();

}



}



function type_edit(){
	var type_name			=	document.form_type_edit.type_name.value;
	var type_detail			=	document.form_type_edit.type_detail.value;
	var type_path			=	document.form_type_edit.type_path.value;
	var type_sort			=	document.form_type_edit.type_sort.value;
	var numRE				= /^\d+$/;

if (type_name =="")
{
	alert("กรุณาตรวจสอบหัวข้อเรื่อง");
	document.form_type_edit.type_name.focus();
	return false;
}

if (type_detail =="")
{
	alert("กรุณาตรวจสอบรายละเอียด");
	document.form_type_edit.type_detail.focus();
	return false;
}




if (!numRE.test(type_sort)){
	alert("กรุณาตรวจสอบลำดับการแสดงผล");
	document.form_type_edit.type_sort.focus();
	return false;
}else{

	document.form_type_edit.submit();

}



}















function type_del(id) {   
        if (window.confirm("ยืนยันการลบอีกครั้ง ?")) {
            window.location.href = "/sitecontrol/type_del/?id="+id
        }
}

function check_forget(){
	var email		=	document.getElementById('form_forget_password').email.value;
	var emailRE		= /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

	if (!emailRE.test(email))
	{
		alert("กรุณาตรวจสอบอีเมล์");
		document.getElementById('form_forget_password').email.focus();
		return false;
	}else{

		document.getElementById('form_forget_password').submit();

	}
}


	function checkAgree()
	{
		if (document.getElementById('form_register').agree.checked == true){
			document.getElementById('form_register').button1.disabled=false;
			document.getElementById('form_register').button2.disabled=false;
			document.getElementById('form_register').button3.disabled=false;						

		}else{
			document.getElementById('form_register').button1.disabled=true;	
			document.getElementById('form_register').button2.disabled=true;	
			document.getElementById('form_register').button3.disabled=true;							
		}

	}


function genbanner(position_banner) {
	if (position_banner =="BOTTOM")
	{
		document.write("<iframe frameborder=\"0\" width=\"650\" height=\"90\" marginheight=\"0\" marginwidth=\"0\" scrolling=\"no\"  src=\"http://www.scriptdd.com/ads.php?id=BOTTOM\"></iframe>");
	}

	if (position_banner =="TOP")
	{
		document.write("<iframe frameborder=\"0\" width=\"650\" height=\"90\" marginheight=\"0\" marginwidth=\"0\" scrolling=\"no\"  src=\"http://www.scriptdd.com/ads.php?id=TOP\"></iframe>");
	}

}

function addemoticon(theSmilie) {
	document.getElementById('form_content_comment').comment.value+= ' ' + theSmilie + ' ';
	document.getElementById('form_content_comment').comment.focus();
}
