﻿/*
* Lấy về tên loại của trình duyệt Get Browser Type, trả về "IE" đối với
* MS Internet Explorer và "NN" đối với Netscape Navigator, còn với 
* các trình duyệt khác sẽ trả về "NA"
*/
function getBrowser()
{
	var bname = navigator.appName;
	var retval = "NA";
	if (bname == "Netscape")
	{
		retval = "NN";
	}
	else if (bname == "Microsoft Internet Explorer")
	{
		retval = "IE";
	}
	return retval;
}

/*
* Hàm đưa màn hình vào chính giữa và đổi kích thước về 800x600
*/
function ReSizeAndCenterizeWindow()
{
	var w = screen.width;
	var h = screen.height;
	
	var win_h = 600;
	var win_w = 800;

	var left = (w - win_w) / 2;
	var top= (h - win_h) / 2;
	
	self.moveTo(left, top);
	
	// Fix size
	self.resizeTo(win_w, win_h);
}

/*
* Ẩn các menu và toolbar cũng như statusbar cho trình duyệt Netscape
*/
function NoBarForNetscape()
{
	var bname = getBrowser();
	if (bname == "NN")
	{
		this.menubar.visible=false;
		this.toolbar.visible=false;
		this.locationbar.visible=false;
		this.personalbar.visible=false;
		this.statusbar.visible=false;
		this.resizeable=false;
	}
}

/*	
* Hiện thông tin tàu			
* CuongLT
* 08/09/2004
* Tạo mới
*/
function ShowVesselInfo(theDiv)
{
	layer = document.getElementById(theDiv);
	if (layer.style["display"] == "none")
	{
		layer.style["display"] = "";
	}		
}

/*
* Ẩn thông tin tàu
* CuongLT
* 08/09/2004
* Tạo mới
*/
function HideVesselInfo(theDiv)
{
	layer = document.getElementById(theDiv);
	if (layer.style["display"] == "")
	{	
		layer.style["display"] = "none";
	}		
}

function validateDate_vi_VN( strValue, strDateFormat )
{
	var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;

	//check to see if in correct format
	if(!objRegExp.test(strValue))
		return false; //doesn't match pattern, bad date
	else{
		var strSeparator = strValue.substring(2,3);
		var arrayDate = strValue.split(strSeparator);
		//create a lookup for months not equal to Feb.
		var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31, '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31};
		
		var strDay;
		var strMonth;
		if (strDateFormat == 'ddmmyyyy')
		{
			strDay = arrayDate[0];
			strMonth = arrayDate[1];
		}
		else if (strDateFormat == 'mmddyyyy')
		{
			strDay = arrayDate[1];
			strMonth = arrayDate[0];
		}
		var strYear = arrayDate[2];
		var intDay = eval(strDay);
		var intMonth = eval(strMonth);
		var intYear = eval(strYear);
		
		if ((intMonth > 12) || (intMonth <= 0))
		{
			return false;
		}
		else
		{
			//check if month value and day value agree
			if(arrayLookup[strMonth] != null) {
				if(intDay <= arrayLookup[strMonth] && intDay != 0)
				{
					return true; //found in lookup table, good date
				}
			}
			
			//check for February
			if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
				return true; //Feb. had valid number of days
		}
	}
	return false; //any other values, bad date8
}

function validateFromDate_vi_VN(oSrc, args)
{
	args.IsValid = validateDate_vi_VN(args.Value, 'ddmmyyyy');
}

function validateFromDate_en_US(oSrc, args)
{
	args.IsValid = validateDate_vi_VN(args.Value, 'mmddyyyy');
}
/*function FromDateLeToDate(fromDate, toDate)
{
	return ((Date.parse(fromDate.Value) <= (Date.parse(toDate.Value));
}*/
