var objChkCaptAjax=null;
var timeNow=null;
var urlChkCapt=null;
var strAddType=null;
var strIDDelNot=null;
var strxYPCMSRootPath=null;

	function doSendNotice(Obj)
	{
		document.getElementById('ErrShowTxt').style.display='block';
		if(document.getElementById('strCaptNotice').value=='')
		{
			document.getElementById('ErrShowTxt').innerHTML='กรุณาใส่รหัสยืนยัน';
			return false;
		}
		document.getElementById('ErrShowTxt').innerHTML='';
		objChkCaptAjax=CreateAjaxObject();
		timeNow = new Date().getTime();
		urlChkCapt=strxYPCMSRootPath+'admin/deletenotice_add.aspx?cmd=add&i='+strIDDelNot+'&t='+strAddType+'&c='+document.getElementById('strCaptNotice').value+'&g='+timeNow;
		//alert(urlChkCapt);//return false;
		objChkCaptAjax.open('GET',urlChkCapt,true);				
		objChkCaptAjax.onreadystatechange = doChkCapt;
		objChkCaptAjax.send(null);
		document.getElementById('ErrShowTxt').innerHTML='รอสักครู่...';
		return false;
	}

	//--- BEGIN Check valid captcha
		function doChkCapt()
		{
			 if(objChkCaptAjax.readyState  == 4)
			 {
				if(objChkCaptAjax.status  == 200) 
				{
					try	{
						var xmlDoc=objChkCaptAjax.responseXML.documentElement;
						//alert(xmlDoc.getElementsByTagName("state")[0].childNodes[0].nodeValue);
						if(xmlDoc.getElementsByTagName("state")[0].childNodes[0].nodeValue=="True")
						{
							document.getElementById('ErrShowTxt').innerHTML='บันทึกรายการแจ้งลบเรียบร้อยแล้ว';
							setLayer('captNotmiddleLayer','hidden');
							setLayer('captNottopLayer','hidden');
//							document.getElementById('ErrShowTxt').style.display='block';
						}else{
							//alert('FALSE');
							document.getElementById('ErrShowTxt').innerHTML='รหัสยืนยันไม่ถูกต้อง';
//							document.getElementById('ErrShowTxt').style.display='block';
						}
					}catch (e){
							alert('Error: \n'+e);
					}
				}
			 }
		}
	//---END Check valid captcha

function onInit()
{
	objAjax=CreateAjaxObject();
}

// --- Begin Initial Ajax Object
	function CreateAjaxObject()
	{
		var objAjax=null;
		try	{objAjax = new ActiveXObject('Msxml2.XMLHTTP');}
		catch (e){
			try	{objAjax = new ActiveXObject('Microsoft.XMLHTTP');}
			catch (e2) 	{
				try {objAjax = new XMLHttpRequest();	}
				catch(e3){	objAjax = false;	}
			}
		}
		return objAjax;
	}
// --- End Initial Ajax Object

function setLayer(idname, setlayer) {
	timeNow = new Date().getTime();
	document.getElementById('ErrShowTxt').style.display='none';
	document.getElementById('captchaNoticeIMG').src=strxYPCMSRootPath+'CaptchaNoticeImage.aspx?g='+timeNow;
	if (idname=='captNotmiddleLayer')
	{
		document.getElementById(idname).style.height = getPageSizeWithScroll()[1]+'px';
	}else if (idname=='captNottopLayer'){
		document.getElementById(idname).style.top = f_scrollTop() +Math.floor(f_clientHeight()/2)-150>0?f_scrollTop() +Math.floor(f_clientHeight()/2)-200:0;
		document.getElementById(idname).style.left = f_scrollLeft()+Math.floor(f_clientWidth()/2)-165>0?f_scrollLeft()+Math.floor(f_clientWidth()/2)-165:0;
		
	}
	document.getElementById(idname).style.visibility = setlayer;
//	alert(getPageSizeWithScroll()[1]);
//	getPageSizeWithScroll();
}

function showDelNoticeTag(inttype,intId)
{
	document.getElementById('strCaptNotice').value='';
	strAddType=inttype;
	strIDDelNot=intId;
	setLayer('captNotmiddleLayer','visible');
	setLayer('captNottopLayer','visible');
}

/* --- Begin Get window properties ---*/
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}

// Credit http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
/* --- End Get window properties ---*/


function doSubmit(Obj)
{
//	return true;
	if (Obj.strPostName!=undefined && Obj.strPostName.value=='')
	{
		alert('กรุณาใส่ชื่อหรืออีเมล์ของท่าน');
		Obj.strPostName.focus();
		return false;
	}
	if (Obj.strCaptChar.value=='')
	{
		alert('กรุณาใส่โค้ดตามรูปด้านข้าง');
		Obj.strCaptChar.focus();
		return false;
	}
	var api = FCKeditorAPI.GetInstance("strComment"); 
	if (api.GetHTML()=='')
	{
		alert('กรุณาใส่ข้อความแสดงความคิดเห็น');
		api=null;
		return false;
	}
	api=null;
	return true;
}

function cfDel(strContent)
{
	//alert(strCatname);
	if (confirm('Delete :'+strContent+' ?'))
	{
		return true;
	}else{
		return false;
	}
}

