//Function to open pop up window
function Popup(page){
	OpenWin = this.open(page, "NewWindow", "toolbar=no,menubar=no,statusbar=no,location=no,scrollbars=no, resizable=no,top=0,width=500, height=350, left=0");
}
function OpenDownload(page){
	OpenWin = this.open(page, "NewWindow", "toolbar=no,menubar=no,statusbar=no,location=no,scrollbars=no, resizable=no,top=0,width=10, height=10,left=0");
}
function OpenImage(page){
	OpenWin = this.open(page, "Image", "toolbar=no,menubar=no,scrollbars=no,width=1,height=1,top=0,left=0,resizable=0");
}
function ViewAdvise(page){
	OpenWin = this.open(page, "NewWindow", "toolbar=no,menubar=no,statusbar=no,location=no,scrollbars=yes, resizable=yes,top=0,width=600, left=0");
}
function Advise(page){
	OpenWin = this.open(page, "NewWindow", "toolbar=no,menubar=no,statusbar=no,location=no,scrollbars=no, resizable=no,top=0,width=500, height=350, left=0");
}
function Alert(page){
	OpenWin = this.open(page, "NewWindow", "toolbar=no,'menubar=no,scrollbars=no,width=360,height=200,top=0,left=0,resizable=0'");
}
function openWin(theURL,winName,features){
	window.open(theURL,winName,features);
}
function OpenPreviewWindow(targetPage, formName){
	now = new Date  
	openWin('','preview','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=680,height=400')
	formName.action = targetPage + "?ID=" + now.getTime();	
	formName.target = "preview";
	formName.submit();
}
function ChangeImage(target,path) {
    var oElem = GE( target );
    oElem.src = path;
    return;
}

function checknum(xxx,minvalue,maxvalue,nnn){
	if (xxx>maxvalue||xxx<minvalue||isNaN(xxx)||xxx=="")
		{	alert("Hãy nhập số từ 0 - 10 !");
			nnn.focus();
		}
}
function MakeHome() {
theobj = document.anchors[0];  
theobj.style.behavior='url(#default#homepage)';
theobj.setHomePage('http://www.focy.net/');
}

function jumpTab(focusTarget,Targets,normalStyle,focusStyle) {
	if( GE( focusTarget ).className == focusStyle) return false;
	var array = Targets.split(";");
	for (var i = 0; i < array.length; i++) { GE( array[i] ).className = normalStyle; }
	GE( focusTarget ).className = focusStyle;
	return false;
}
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function isDate(day,month,year) {
	var today = new Date();
	year = ((!year) ? y2k(today.getYear()):year);
	month = ((!month) ? today.getMonth():month-1);
	if (!day) return false;
	var test = new Date(year,month,day);
	if ( (y2k(test.getYear()) == year) && (month == test.getMonth()) &&	(day == test.getDate()) )
	return true;
	return false;
}

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
function Trim(s) 
{
	// Remove leading spaces and carriage returns
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	 { s = s.substring(1,s.length); }
 
	// Remove trailing spaces and carriage returns
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	 { s = s.substring(0,s.length-1); }
 
	return s;
}
//Replace str1 with str2 from v
function Replace(v, str1, str2  ){ do v = v.replace(str1,str2); while ( v.indexOf(str1)>0 ); return v; }
function SearchMe() { var strKW = Trim(GE('kw').value);if (strKW.length>=3 && strKW != strFOCY ) {document.location.href="?s=search&kw=" + Replace(strKW, "&", "%26"); return false;}	else alert("Từ khóa tìm kiếm quá ngắn!"); return false; }
var strFOCY = 'http://www.focy.net/';
function FOCY(id,act) { if( GE(id).value == '' && act == 1 ) GE(id).value = strFOCY; if( GE(id).value == strFOCY && act == 0 ) GE(id).value = ''; }
function Decode(v) { return unescape(v); }
function GE(v) { if(document.all) { return document.all[v]; } return document.getElementById(v); }
function ConfirmForm(msg) {
    var agree=confirm(msg);
    if (agree) return true ; return false ;
}