// JavaScript Document

	var winopen=new Array();
	function openPopup(_fileName,_winIndex,_width,_height) {
		_winName="win"+_winIndex;
		_info = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,dependent=yes,height="+_height+",width="+_width+",left="+(window.screen.width/2-(_width/2))+",top="+((window.screen.height/2-(_height/2))-20);
		if (winopen[_winIndex] != null)
			winopen[_winIndex].close();  
		winopen[_winIndex]=window.open(_fileName,_winIndex,_info);
		return winopen[_winIndex];
	}
	
	function openPopupFTP(_fileName,_winIndex,_width,_height) {
		_winName="win"+_winIndex;
		_info = "toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,dependent=yes,height="+_height+",width="+_width+",left="+(window.screen.width/2-(_width/2))+",top="+((window.screen.height/2-(_height/2))-20);
		if (winopen[_winIndex] != null)
			winopen[_winIndex].close();  
		winopen[_winIndex]=window.open(_fileName,_winIndex,_info);
		return winopen[_winIndex];
	}
	
	function openPopupFullScreen(_fileName,_winIndex,_resizable) {
		_winName="win"+_winIndex;
		_info = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable="+_resizable+",dependent=yes,height="+window.screen.height+",width="+window.screen.width+",left=0,top=0";
			
		if (winopen[_winIndex] != null)
			winopen[_winIndex].close();  
		winopen[_winIndex]=window.open(_fileName,'',_info);
	}
	
	function isNull(_obj,_alertText) {
		if(document.getElementById(_obj).type == 'select-one') {
			if(document.getElementById(_obj).options[document.getElementById(_obj).selectedIndex].value == '0') {
				alert ("กรุณาเลือก"+_alertText+"");
				document.getElementById(_obj).focus();
				return true;
			} else { return false; }
		} else {
			if(document.getElementById(_obj).value == '') {
				alert ("กรุณากรอก"+_alertText+"");
				document.getElementById(_obj).focus();
				return true;
			} else { return false; }
		}
	}
	
	function isNumber(_obj,_alertText) {
		var _test = document.getElementById(_obj).value;
		var anum = /(^\d+$)|(^\d+\.\d+$)/;
		if (!anum.test(_test)) {
			alert("กรุณากรอก"+_alertText+"เท่านั้น")
			document.getElementById(_obj).focus();
			return true;
		} else { return false; }
	}
	
	function invalidEmail(_obj) {
		var _string = document.getElementById(_obj).value
		if (!(_string.search("^.+@.+\\..+$") != -1)) {
			alert("กรุณากรอกรูปแบบ E-mail ให้ถูกต้อง")
			document.getElementById(_obj).focus();
			return true;
		}
	}
	
	function isArray(_obj) {
			if(_obj.length > 1) { return true; } else { return false; }
	}
	
	function checkChecked(_obj) {
		value = new Array;
		if(isArray(_obj)) {
			for(var _index = 0;_index < _obj.length;_index++) {
				if(_obj[_index].checked == true) { value[_index] = true; } else { value[_index] = false; }
			}var _check = false;
			for(_index = 0;_index < _obj.length;_index++) {
				if(value[_index] == true) { _check = true; }
			}
			if(_check) { return false; } else { return true; }
		} else {
			if(document.getElementById(_obj).checked == true) { return false; } else { return true; }
		}
	}
	function trim (str)
		{
  		str = this != window? this : str;
  		return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
		}
	
Array.prototype.indexOf=function(n){for(var i=0;i<this.length;i++){if(this[i]==n){return i;}}return -1;}

	function AddFavorite(location,title)
	{
	  if (window.sidebar) 
		{ // Mozilla Firefox Bookmark		
		//window.sidebar.addPanel(title,location,null);	
		alert("You need Ctrl+D to add bookmark");
		} 
	else if( window.external ) 
		{ // IE Favorite		
		window.external.AddFavorite(location, title);
		}	
	else if(window.opera && window.print) 
		{ // Opera Hotlist	
		alert("You need Ctrl+D to add bookmark");
		}
	
	}


