//------------------------------------------------------------------------
//	OPEN CREDIT CARD VERIFICATION HELP WINDOW
//------------------------------------------------------------------------
function OpenCCHelpWindow()
{
	var Opt = "Height=550,Width=540,Status=yes,top=100,left=100,resizable=no,Scrollbars=no";
	window.open('CCVerificationHelp.html','hlpWind',Opt);
}
//------------------------------------------------------------------------
//	CHECK IF VALUE ENETERED IS A VALID STRING
//------------------------------------------------------------------------
function IfValidString(TextBoxValue)
{
	try{
		if(TextBoxValue.length == 0) return false;
		if(TextBoxValue =='') return false;
		if(TextBoxValue.indexOf(" ") == 0) return false;
	}catch (e){return false ;}
	return true;
}
//------------------------------------------------------------------------
//	CHECK IF VALUE ENETERED IS A VALID STRING
//------------------------------------------------------------------------
function ValidString2(Field, bRet)
{
	var Ret1 = true;
	
	try{
		if(Field.value.length == 0) Ret1 = false;
		if(Field.value =='') Ret1 = false;
		if(Field.value.indexOf(" ") == 0) Ret1 = false;
	}catch (e){Ret1 = false;}
	
	if(bRet == true && Ret1 == false){
		return false;
	}else if(bRet == false && Ret1 == true){
		return false;
	}else{
		return Ret1;
	}
}
//------------------------------------------------------------------------
//	RETURN TRUE IF VALID NUMBER
//------------------------------------------------------------------------
function IsNumber(argvalue){
	argvalue = argvalue.toString();
	if (argvalue.length == 0) return false;
	for (var n = 0; n < argvalue.length; n++){
		if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9") return false;
	}
	return true;
}

//**************************************************************************
// PERFORM DAYS DIFFERENCE BETWEEN CURRENT DATE AND SENT BusinessDate
//**************************************************************************
function CheckIfBookingAvailable(BusinessDate)
{
	var Ret = true;
	var CurrentDate = GetCurrentDate();
	var DateDiff = DateDifference(CurrentDate, BusinessDate);

	if(DateDiff > 120) Ret= false;
	return Ret;
}


/*** JS DATE FUNCTIONS ***/

//------------------------------------------------------------------------
//	UPDATE DATE
//------------------------------------------------------------------------
function IncrDropoffDate()
{
	var frm = document.forms[0];
	var NewDate = frm.DDLPickupMonth.options[frm.DDLPickupMonth.selectedIndex].value;
	NewDate += "/" +  frm.DDLPickupDay.options[frm.DDLPickupDay.selectedIndex].value;
	NewDate += "/" + frm.DDLPickupYear.options[frm.DDLPickupYear.selectedIndex].value;
	SetDropoffDate(NewDate, frm);
	frm = null;
}

//------------------------------------------------------------------------
//	UPDATE DROPOFF LIST BOX OPTIONS
//------------------------------------------------------------------------
function SetDropoffDate(m_date, FRM)
{
	var Day1, Mon1, Year1;
	m_date = FormatDate(DaysIncr(new Date(m_date),3));
	
	try{
		Day1 = GetDay(m_date);
		Mon1 = GetMonth(m_date);
		Year1 = GetYear(m_date);
	}catch(e){;}
	
	try{FRM.DDLDropoffMonth.options[Math.abs(Mon1)-1].selected = true;}catch(e){;}
	try{FRM.DDLDropoffDay.options[Math.abs(Day1)-1].selected = true;}catch(e){;}
	var n = Math.abs(Year1) - Math.abs(GetCurrentYear());
	try{FRM.DDLDropoffYear.options[n].selected = true;}catch(e){;}
}

//------------------------------------------------------------------------
//	RETURN INCREMENT DATE
//------------------------------------------------------------------------
function DaysIncr(mDate, Days){
	return (new Date(mDate.getTime() + (Days * 24 * 60 * 60 *1000)));
}

//------------------------------------------------------------------------
//	RETURN DATE MM/DD/YYYY
//------------------------------------------------------------------------
function FormatDate(SrcDate)
{
	var D2 = new Date(SrcDate);
	var Mon;
	if(Math.abs(D2.getMonth()+1) < 10)
		Mon = "0" + Math.abs(D2.getMonth()+1);
	else
		Mon = Math.abs(D2.getMonth()+1);
	return (Mon + "/" + D2.getDate() + "/" + D2.getFullYear());
}

//------------------------------------------------------------------------
//	RETURN YEAR PORTION FROM DATE (MM/DD/YYYY)
//------------------------------------------------------------------------
function GetYear(m_date)
{
	var Pos1 = m_date.lastIndexOf('/');
	return(m_date.substring(Pos1+1));
	
}

//------------------------------------------------------------------------
//	RETURN MONTH PORTION FROM DATE (MM/DD/YYYY)
//------------------------------------------------------------------------
function GetMonth(m_date)
{
	var Pos1;
	Pos1 = m_date.indexOf('/');
	return(m_date.substring(0, Pos1));
}

//------------------------------------------------------------------------
//	RETURN DAY PORTION FROM DATE (MM/DD/YYYY)
//------------------------------------------------------------------------
function GetDay(m_date)
{
	var Pos1, Pos2;
	
	Pos1 = m_date.indexOf('/');
	Pos2 = m_date.indexOf('/', Pos1+1)
	return(m_date.substring(Pos1+1, Pos2));
}
/*************************************************************************
******				FORM DATE METHODS								******
*************************************************************************/

//	RETURN CURRENT YEAR FOR DATE CALENDAR
function curYr(DropOff){
	var Field;
	var Frm = document.forms[0];
	if(DropOff == undefined){
		Field = Frm.Nav_txtPickupDate;
	}else{
		Field = Frm.Nav_txtDropoffDate;
	}

	var yr = new Date(Field.value);
	if (yr!='NaN'){
		return yr.getFullYear().toString();
	}else{
		return '';
	}
}

//------------------------------------------------------------------------
//	RETURN CURRENT MONTH FOR CALENDAR
//------------------------------------------------------------------------
function curMon(DropOff){
	var Frm = document.forms[0];
	var Field;
	if(DropOff == undefined){
		Field = Frm.Nav_txtPickupDate;
	}else{
		Field = Frm.Nav_txtDropoffDate;
	}
	var mon = new Date(Field.value);
	if (mon!='NaN'){
		return mon.getMonth();
	}else{
		return '';
	}
}
//------------------------------------------------------------------------
//	CHECK FOR VALID DATE INPUT
//------------------------------------------------------------------------
function ValidateDate(Val1)
{
	if(Val1.indexOf(" ") != -1 || Val1.indexOf("/") == -1 || Val1.indexOf("/") == Val1.lastIndexOf("/"))
	{
		return false;
	}
	if(Val1.length != 10) return false;
	var mMonth, mDay, mYear;
	mMonth = Val1.substring(0,2);
	mDay = Val1.substring(3,5);
	if(Val1.length == 8)
		mYear = Val1.substring(6,8);
	else if(Val1.length == 10)
		mYear = Val1.substring(6,10);
	var IsLeapYear;
	var IsValid = true;
	if(mYear%4 == 0)
		IsLeapYear = true;
	else
		IsLeapYear = false;

	if((mMonth <= 0 || mMonth > 12) || (mDay <= 0 || mDay > 31)) IsValid = false;
	if ((mMonth == '04' | mMonth == '06' || mMonth == '09' || mMonth == '11') && (mDay > 30)) IsValid = false
	if(!IsLeapYear)
	{
		if(mMonth == '02' && mDay > 28)IsValid = false;
	}
	else
	{
		if(mMonth == '02' && mDay > 29) IsValid = false;
	}
	if(mMonth.indexOf("/") != -1 || mDay.indexOf("/") != -1 || mYear.indexOf("/") != -1) IsValid = false;
	return IsValid;
}
//------------------------------------------------------------------------
//	RETURN CURRENT MONTH
//------------------------------------------------------------------------
function GetCurrentMonth()
{
	var D = new Date();
	var MM = D.getMonth();
	var Mon;
	MM = MM + 1;
	Mon = MM;
	if(MM < 10) Mon = "0" + MM;
	
	return Mon;
}
//------------------------------------------------------------------------
//	RETURN CURRENT YEAR
//------------------------------------------------------------------------
function GetCurrentYear()
{
	var D = new Date();
	return  "" + D.getFullYear();
}
//------------------------------------------------------------------------
//	EETURN CURRENT DATE
//------------------------------------------------------------------------
function GetCurrentDate()
{
	return FormatDate(new Date());
}

//------------------------------------------------------------------------
// RETURN DATE DIFFERENCE IN DAYS
//------------------------------------------------------------------------
function DateDifference(Date1, Date2)
{
	var Return = -1;
	var D1 = new Date(Date1)
	var D2 = new Date(Date2);
	var OneDayMS =1000*60*60*24; // MILLISECONDS IN A DAY
	Return = Math.ceil((D2.getTime()-D1.getTime())/(OneDayMS)) - 1;
	return Return;
}

