// use for function fillterimg 
var extArray = new Array(".gif", ".jpg", ".png",".jpeg");	
var allowSubmit = false;
//for function checkall checkbox
var checkflag = "false";
//for check mail address
var good;
// for count check box
var xcount=false;
/**********************************************************************************/
/* function check email address
var goog=false;
exp. ckemail(document.frm.email);
*/
function ckemail(field) 
{
	// the following expression must be all on one line...
	var goodEmail =field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	if (goodEmail) 
	{
		good = true;
	}
	else
	{
		good = false;
	}
}
/* format field */
function FORMAT(fields,format)
{
	for (var i=0;i<fields.length;i++) {
	     if (format.indexOf(fields.charAt(i)) == -1)	 return false;
	 }
	 return true;
}
function EN(fields)
{
	format="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_#$@%&";
	for (var i=0;i<fields.length;i++) {
	     if (format.indexOf(fields.charAt(i)) == -1)	 return false;
	 }
	 return true;
}
/* function fillter imgae  --------------------------------------------------------------------------
	Original:  ArjoGod, Shauna Merritt 
	Modified By:  Ronnie T. Moore, Editor 
	This script and many more are available free online at 
	The JavaScript Source!! http://javascript.internet.com 
	<input type=button name="Submit" value="Submit" onclick="ckimg(this.form, this.form.uploadfile.value)">
*/
function ckimg(form, file)
 {
	if (!file) return;
	while (file.indexOf("\\") != -1)
	{
		file = file.slice(file.indexOf("\\") + 1);
	}
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) 
	{
		if (extArray[i] == ext) 
		{ 
			allowSubmit = true; 
			break; 
		}
	}
}

/* Check All checkbox 
exp. onClick="CK_ALL(this.form)";
*/
function CK_ALL(xform)
{
		var msg="";
		for(var x=0;x<xform.elements.length;x++)
		{
				var y = xform.elements[x];
				var ytr = y.parentNode.parentNode;
				var check = xform.ckall.checked;  // check all check box
				if(y.name == 'ck[]')
				{
						if (y.disabled != true)
						{
							 y.checked = check;
							  if (y.checked == true){
								  ytr.className = 'checked';
								  msg="ยกเลิกรายการทั้งหมด"; 
							  }
							 else{
								 ytr.className = 'mouseout';
								 msg="เลือกรายการทั้งหมด"; 
							 }
						}
				}
		}
		return msg;
}
function CK_ONE(xform)
{
		for(var x=0;x<xform.elements.length;x++)
		{
				var y = xform.elements[x];
				var ytr = y.parentNode.parentNode;
				var check = xform.ckall.checked;  // check all check box name
				if(y.name == 'ck[]')
				{
						if (y.disabled != true)
						{
							  if (y.checked == true)  ytr.className = 'checked';
							 else	 ytr.className = 'mouseout';
						}
				}
		}
}

/* function check all checkbox 
<input type=checkbox name=all title="เลือกรายการทั้งหมด" onClick="this.title=ckall(this.form.list)">
*/
function ckall(field) 
{
	if (checkflag == "false") 
	{
		for (i = 0; i < field.length; i++) 
		{
			field[i].checked = true;
		}
		checkflag = "true";
		return "ยกเลิกรายการทั้งหมด"; 
	}
	else 
	{
		for (i = 0; i < field.length; i++) 
		{
			field[i].checked = false; 
		}
		checkflag = "false";
		return "เลือกรายการทั้งหมด"; 
	}
}
/* function count checkbox */
/*EXP. <br>8<input type=checkbox name=ckbox>
<br>9<input type=checkbox name=ckbox>
<p><input type=button value="Count Checkboxes" onClick="countck(this.form.check)">
*/
function countck(field) {
//var checkvar = document.form1.Chk;
  var check = "";
  for (i = 0; i < field.length; i++) {
    if (field[i].checked){
      check = "Y";
      break;
    }
  }
  if (check=="")
  {
	  	if(field.checked==false){
			alert("กรุณาเลือกรายการอย่างน้อย 1 รายการ ");
		   return false;
		}
  }
  else
  {
	  	if(!confirmbox(this,"แน่ใจนะว่าจะลบรายการที่เลือกทั้งหมด")){
			return false;
		}
		else
		{
	   		 return true;
		}
  }
}
/* auto size for pupop ------------------------------------------------------- */
/*for exe. <A HREF="javascript:resize('/img/auto-resizable-pop-up/lg-1.gif')" BORDER="0">
  <IMG SRC="/img/auto-resizable-pop-up/1.gif" BORDER="0"></A>
  */
function resize(img)
{
	  foto1= new Image();
	  foto1.src=(img);
	  Controlla(img);
}
function Controlla(img)
{
	  if((foto1.width!=0)&&(foto1.height!=0))
	  {
			viewFoto(img);
	  }
	  else
	  {
			funzione="Controlla('"+img+"')";
			intervallo=setTimeout(funzione,20);
	  }
}
function viewFoto(img)
{
	  var finestra=0;
	  var largh=foto1.width+20;
	  var altez=foto1.height+20;	 
	  var left=(screen. largh/2)-largh/2;
	  var top=(screen.altez/2)-altez/2;
	//  'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,
	  var stringa="toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width="+largh+",height="+altez+"left="+left+", top="+top+",screenX="+left+",screenY="+top+"";
	  finestra=open(img,"",stringa);
}
/* end of auto size for pupop ------------------------------------------------------- */

/* function reload document or forn new*/
function RELOAD(xtime)
{
   window.opener.location.reload();
   setTimeout("self.close()",xtime);
}

/* function close windows auto */
function AUTO_CLOSE(xtime)
{
   setTimeout("self.close()",xtime);
}

/* function confirm dialog box */
/*
onClick='return comfirmbox(this,"ทดสอบ");' 
*/
function confirmbox(object,msg) 
{
	if (confirm(msg) ==true) {
			return true;
	}
	else	return false;
}

/* Open new Windows */
function newwin(URLStr,width, height)
{
	  var popUpWin=0;
	  var left = (screen.width/2) - width/2;
	  var top = (screen.height/2) - height/2;
	  if(popUpWin)
	  {
		  if(!popUpWin.closed) popUpWin.close();
	   }
	   popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
function dialog(URLStr,width, height)
{
		  var ns4 = document.layers;
		  var ns6 = document.getElementById && !document.all;
		  var ie4 = document.all;
		  var popUpWin=0;
		  var left = (screen.width/2) - width/2;
		  var top = (screen.height/2) - height/2;
		 if(ie4){
				 popUpWin=window.showModalDialog(URLStr,"footwareshops.com","dialogWidth:"+width+"px;dialogHeight:"+height+"px;help:no;status:no;scroll:no;resizable:no;")
		 }
		 else{
				  if(popUpWin)
				  {
					if(!popUpWin.closed) popUpWin.close();
				  }
				  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
		 }
}
/* Tree menu function ------------------------------------------------ */

/* Rev. 09/07/2003 by http://www.industriavirtual.com.br  */
function Toggle(item) {
   obj=document.getElementById(item);
   visible=(obj.style.display!="none")
   key=document.getElementById("x" + item);
   if (visible) {
     obj.style.display="none";
    key.innerHTML="<img src='../icons/down_arow_blue.gif' width='12' height='12' hspace='0' vspace='0' border='0' align='absmiddle'>";
   } else {
      obj.style.display="block";
      key.innerHTML="<img src='../icons/top_arow_blue.gif' width='12' height='12' hspace='0' vspace='0' border='0' align='absmiddle'>";
   }
}

function Expand() {
   divs=document.getElementsByTagName("DIV");
   for (i=0;i<divs.length;i++) {
     divs[i].style.display="block";
     key=document.getElementById("x" + divs[i].id);
     key.innerHTML="<img src='../icons/top_arow_blue.gif' width='12' height='12' hspace='0' vspace='0' border='0' align='absmiddle'>";
   }
}

function Collapse() {
   divs=document.getElementsByTagName("DIV");
   for (i=0;i<divs.length;i++) {
     divs[i].style.display="none";
     key=document.getElementById("x" + divs[i].id);
     key.innerHTML="<img src='../icons/top_arow_blue.gif' width='12' height='12' hspace='0' vspace='0' border='0' align='absmiddle'>";
   }
}
/* end tree menu */

