/*  ----  Jirath_b@truemail.co.th ---- */
/*------------------------------------------------------[ เริ่มส่วน OOP ]-------------------------------------------------------------------*/

function getCookie(c_name)//รับค่า Cookie
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) 
				c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return ""
} 


function SetCookie (name, value)//ลงทะเบียน Cookie
{  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  //alert(expires);
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
}


function DeleteCookie (c_name)// ลบ Cookie
{  
	var exp = new Date();  
		exp.setTime (exp.getTime() - 1);  
	var cval = getCookie (c_name);  
		document.cookie = c_name + "=" + cval + "; expires=" + exp.toGMTString();
}

function check_num(ch)
{
	var len, digit;
	if(ch == ""){ return false;len=0;}else{len = ch.length;}
	for(var i=0 ; i<len ; i++)
	{
		digit = ch.charAt(i)
		if(digit >="0" && digit <="9"){; }else{return false; } 
	} 
	return true;
}

function logout(cook1,cook2,url)
{
	//window.opener='x';window.close();	
	var yes='คุณต้องการที่จะออกจากระบบหรือไม่ ?';
	if(confirm(yes)==true){DeleteCookie(cook1);DeleteCookie(cook2); window.location=url;}
	else{window.location=url;}
}

function NewWindow(mypage,myname,w,h,scroll,resize)
{
	var win = null;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+'';
	win = window.open(mypage,myname,settings)
}

function js_forget(val,div)
{
	var req;
	if (window.XMLHttpRequest) req=new XMLHttpRequest();
	else if (window.ActiveXObject) req=new ActiveXObject("Microsoft.XMLHTTP");
	else 
	{
		alert("Browser not support");return false;
	}	
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{				
			document.getElementById(div).innerHTML=req.responseText;	
			//document.add_ref.gallery_name_post.focus();
		}
		else
		{
			document.getElementById(div).innerHTML="<font size='1' color='green'>...Please wait...</font>";
		}
	}
		var str=Math.random();
		var querystr="";
		querystr+="system_jb.ajax.php";
		querystr+="?time="+str;
		querystr+="&menu=forget";
		querystr+="&val="+val;querystr+="&div="+div;
		req.open("GET", querystr , true);
		req.send(null);
}

function js_forget_submit(val,div)
{
	var req;//alert(val);alert(div);
	var user = document.form2.user.value;
	var mail = document.form2.mail.value;
	if (window.XMLHttpRequest) req=new XMLHttpRequest();
	else if (window.ActiveXObject) req=new ActiveXObject("Microsoft.XMLHTTP");
	else 
	{
		alert("Browser not support");return false;
	}	
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{				
			document.getElementById(div).innerHTML=req.responseText;	
			//document.add_ref.gallery_name_post.focus();
		}
		else
		{
			document.getElementById(div).innerHTML="<font size='1' color='green'>...Please wait...</font>";
		}
	}
			var str=Math.random();
			var querystr="";
			querystr+="system_jb.inc.php";
			querystr+="?time="+str;
			querystr+="&action=forget";
			querystr+="&mail="+mail;
			querystr+="&user="+user;
			querystr+="&val="+val;querystr+="&div="+div;
			req.open("GET", querystr , true);
			req.send(null);
}

function prevent_right() //ห้ามคลิกขวา และลากเมาส์
{
	function clickIE4(){
	if (event.button==2){
	alert(message);
	return false;
	}
	}
	
	function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all){
	if (e.which==2||e.which==3){
	alert(message);
	return false;
	}
	}
	}
	
	if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
	}
	else if (document.all&&!document.getElementById){
	document.onmousedown=clickIE4;
	}
	document.oncontextmenu=new Function("alert('ไม่อนุญาตครับ');return false");
	
	//**********ส่วนล่างคือ ห้ามลากเมาส์
	/*function disableselect(e){
	return false
	}
	function reEnable(){
	return true
	}
	//if IE4+
	document.onselectstart=new Function ("return false")
	//if NS6
	if (window.sidebar){
	document.onmousedown=disableselect
	document.onclick=reEnable
	}*/

}

function pic_nets()
{
	var pic_net=document.add_gallery.pic_net.value;
	var req;
	if (window.XMLHttpRequest) req=new XMLHttpRequest();
	else if (window.ActiveXObject) req=new ActiveXObject("Microsoft.XMLHTTP");
	else 
	{
		alert("Browser not support");return false;
	}	
	req.onreadystatechange=function()
	{
		if (req.readyState==4)
		{				
			document.getElementById("pic").innerHTML=req.responseText;	
			document.add_gallery.gallery_name_post.focus();
		}
		else
		{
			document.getElementById("pic").innerHTML=":&nbsp;&nbsp;<img src=\"image/indicator_bouncing_ball.gif\" align=\"absmiddle\" border=\"0\" />&nbsp;<font size='1' color='green'>Please wait</font>&nbsp;<img src=\"image/indicator_bouncing_ball.gif\" align=\"absmiddle\" border=\"0\" />";
		}
	}
		var str=Math.random();
		var querystr="";
		querystr+="system_jb.inc.php";
		querystr+="?time="+str;
		querystr+="&menu_m=pic_net";
		querystr+="&pic_net="+pic_net;
		req.open("GET", querystr , true);
		req.send(null);
}

/*-----------------------------------------------------------[ จบส่วน OOP ]------------------------------------------------------------------------*/
/*  ----  Jirath_b@truemail.co.th ---- */
/*--------------------------------------------------------[ ส่วนของ Html Area ]-------------------------------------------------------------------*/

function xbDesignMode(aIFrame){ //ส่วนจัดการไอเฟรมสำหรับ Html Area
 
  this.mEditorDocument = null;
  this.mIFrameElement = null;
  
  // argument is a string, therefore an ID
  if ( (typeof(aIFrame) == "string") && (document.getElementById(aIFrame).tagName.toLowerCase()=="iframe") ){
    this.mIFrameElement = document.getElementById(aIFrame);
  } else if( (typeof(aIFrame)=="object") && (aIFrame.tagName.toLowerCase() == "iframe") ){
    this.mIFrameElement = aIFrame;   
  } else {
    throw "Argument isn't an id of an iframe or an iframe reference";
  }
  
  if (this.mIFrameElement.contentDocument){  
    // Gecko
    this.mEditorDocument = this.mIFrameElement.contentDocument;
    this.mEditorDocument.designMode = "On";    
  } else {
    // IE
    this.mEditorDocument = this.mIFrameElement.contentWindow.document;
    this.mEditorDocument.designMode = "On";   
    // IE needs to reget the document element after designMode was set 
    this.mEditorDocument = this.mIFrameElement.contentWindow.document;
  }
};

xbDesignMode.prototype.execCommand = function (aCommandName, aParam){
  if (this.mEditorDocument)
  {
  	this.mIFrameElement.contentWindow.focus();
    this.mEditorDocument.execCommand(aCommandName, false, aParam);
  }
  else 
    throw "no mEditorDocument found";    
};

xbDesignMode.prototype.setCSSCreation = function (aUseCss){
  if (this.mEditorDocument)
    this.mEditorDocument.execCommand("useCSS", false, aUseCss);
  else 
    throw "no mEditorDocument found";  
    
};
xbDesignMode.prototype.clear = function(){this.mEditorDocument.body.innerHTML = '';};
xbDesignMode.prototype.getHTML = function() {
	return this.mEditorDocument.body.innerHTML;
};
xbDesignMode.prototype.getText = function() {
	return document.all ? this.mEditorDocument.body.innerText : this.mEditorDocument.body.textContent;
};

xbDesignMode.prototype.wrap = function(tag1, tag2) {
	if(document.all) {
		var R = this.mEditorDocument.selection.createRange();
		if(R.text=='') { return false; }
		R.pasteHTML('<'+tag1+'>' + R.text + '</'+tag2+'>');
		R.collapse(false);
	} else {
		var R = this.mIFrameElement.contentWindow.getSelection().getRangeAt(0);
		if(R.toString()=='') { return false; }
		var h = '<'+tag1+'>'+R.toString()+'</'+tag2+'>';
		this.mEditorDocument.execCommand('insertHTML', false, h);
		R = this.mIFrameElement.contentWindow.getSelection().getRangeAt(0);
		R.collapse(false);
	}
};

//ส่วนจัดการหน้าต่างสำหรับ Html Area
function initEditor() { if(!document.DM) document.DM = new xbDesignMode('tRTE'); }
function askLink(){var uri=window.prompt('Enter URL for link (full url with http://)','');if(uri){document.DM.execCommand('createLink',uri);}};
function askImg(){var uri=window.prompt('Enter URL for image (full url with http://)','');if(uri){document.DM.execCommand('insertImage',uri);}};
function setFS(fs){document.DM.execCommand('fontSize',fs);};
function setFC(fc){document.DM.execCommand('foreColor',fc);};
function emo(im){document.DM.execCommand('insertImage',im.src);};
function cmd(c){document.DM.execCommand(c);};
function closeDivForm(){$('#divOverlay').hide();$('#divForm').hide();};
function formValidate(o)
{
  o.elements['Content'].value=document.DM.getHTML();
  return true;
};

/*------------------------------------------------------[ จบส่วนของ Html Area ]-------------------------------------------------------------------*/
/*  ----  Jirath_b@truemail.co.th ---- */
/*------------------------------------------------------[ เริ่มส่วนของโปรแกรม ]--------------------------------------------------------------------*/

////***************-----------------------ด้านบนคือส่วนของหน้า Home-----------------------*****************//
function check_news()
{
	if( document.f_news.topic.value=="" ){alert ("คุณใส่ข้อมูลไม่ครบ");document.f_news.topic.focus();return false;}
}

function check_pro()
{
	if( document.f_pro.name.value=="" ){alert ("คุณใส่ข้อมูลไม่ครบ");document.f_pro.name.focus();return false;}
}
////*****************--------------------ด้านล่างคือส่วนของหน้า Admin--------------------*****************//
function Dummy_programe_admin()
{
	
}

/*------------------------------------------------------[ จบส่วนของโปรแกรม ]--------------------------------------------------------------------*/
/*  ----  Jirath_b@truemail.co.th ---- */

/*  ----  Sub Tree Menu ---- */
function toggle(id,p)
{ 
	var myChild = document.getElementById(id);
	if(myChild.style.display!='block'){
	myChild.style.display='block';
	document.getElementById(p).className='folderOpen';
	}else{
	myChild.style.display='none';document.getElementById(p).className='folder';
	}
} 
