/*==============================================================================================================*/
/*
JavaScript routine for site validation
Author		:		Sanjeev Shukla
Date created:       02 Feb 2007
Modify Date:			02 Feb 2007
*/
/*==============================================================================================================*/

/*=====Start of Calendar & Picker JavaScript functions===========================================================*/
/* Function to set picker and calendar "To" date based on the "From" Date selected using a Picker.*/
function bkg1_PickerFrom_OnDateChange()
{
	var fromDate = bkg1_PickerFrom.GetSelectedDate();
	var toDate = bkg1_PickerTo.GetSelectedDate();
	bkg1_CalendarFrom.SetSelectedDate(fromDate);
	fromDate.setDate(fromDate.getDate()+1);
	bkg1_PickerTo.SetSelectedDate(fromDate);
	bkg1_CalendarTo.SetSelectedDate(fromDate);
}

/* Function to set picker and calendar "From" date based on the "To" Date selected using a Picker.*/
function bkg1_PickerTo_OnDateChange()
{
	var fromDate = bkg1_PickerFrom.GetSelectedDate();
	var toDate = bkg1_PickerTo.GetSelectedDate();
	bkg1_CalendarTo.SetSelectedDate(toDate);
	if (fromDate > toDate)
	{
	  bkg1_PickerFrom.SetSelectedDate(toDate);
	  bkg1_CalendarFrom.SetSelectedDate(toDate);
	}
}

/* Function to set picker and calendar "To" date based on the "From" Date selected using a Calendar.*/
function bkg1_CalendarFrom_OnChange()
{
	var fromDate = bkg1_CalendarFrom.GetSelectedDate();
	var toDate = bkg1_PickerTo.GetSelectedDate();
	bkg1_PickerFrom.SetSelectedDate(fromDate);
	fromDate.setDate(fromDate.getDate()+1);
	bkg1_PickerTo.SetSelectedDate(fromDate);
	bkg1_CalendarTo.SetSelectedDate(fromDate);
}

/* Function to set picker and calendar "From" date based on the "To" Date selected using a Calendar.*/
function bkg1_CalendarTo_OnChange()
{
	var fromDate = bkg1_PickerFrom.GetSelectedDate();
	var toDate = bkg1_CalendarTo.GetSelectedDate();
	bkg1_PickerTo.SetSelectedDate(toDate);
	if (fromDate > toDate)
	{
	  bkg1_PickerFrom.SetSelectedDate(toDate);
	  bkg1_CalendarFrom.SetSelectedDate(toDate);
	}
}

/* Show Hide function for From Calendar*/
function ButtonFrom_OnClick(obj)
	{
	if (obj.PopUpObjectShowing)
	{
	  obj.Hide();
	}
	else
	{
	  obj.SetSelectedDate(bkg1_PickerFrom.GetSelectedDate());
	  obj.Show();
	}
}

/* Show Hide function for To Calendar*/
function ButtonTo_OnClick(obj)
{
	if (obj.PopUpObjectShowing)
	{
	  obj.Hide();
	}
	else
	{
	  obj.SetSelectedDate(bkg1_PickerTo.GetSelectedDate());
	  obj.Show();
	}
}

/* From Button event Handling*/
function ButtonFrom_OnMouseUp(obj)
{
	if (obj.PopUpObjectShowing)
	{
	  event.cancelBubble=true;
	  event.returnValue=false;
	  return false;
	}
	else
	{
	  return true;
	}
}

/* To Button event Handling*/
function ButtonTo_OnMouseUp(obj)
{
	if (obj.PopUpObjectShowing)
	{
	  event.cancelBubble=true;
	  event.returnValue=false;
	  return false;
	}
	else
	{
	  return true;
	}
}

/* Function to set calendar Departure date based on selection made through picker*/
function bkg1_onPickerChange(picker)
{
	bkg1_Calendar1.SetSelectedDate(bkg1_Picker1.GetSelectedDate());
}

/* Function to set Picker Departure date based on selection made through Calendar*/
function bkg1_onCalendarChange(calendar)
{
	bkg1_Picker1.SetSelectedDate(bkg1_Calendar1.GetSelectedDate());
}

/*=====End of Calendar & Picker JavaScript functions===========================================================*/

/* 
This function will take Pickup Country as Input and will call the Callback function
to generate the list of pickup cities, dropoff country list and dropoff cities.
If an error is generated the callback error function is called and the user is notified
accordingly. While the Callback is generating the data, the system will not allow
to select the submit button!!
*/

function PKCityList()
{
	var pkCountry = document.Form1.ddlPickupCountry;
	var pk_selectedCountry = pkCountry.options[pkCountry.selectedIndex].value;
	if(pk_selectedCountry !=0)
	{
		ctl02_CallBack1.Callback(pk_selectedCountry);
	}
}


/* 
This function will take Pickup Country and dropoff Country as Input and will call the Callback 
functionto generate the list of dropoff cities. The initial selection made by the user would be
preservedIf an error is generated the callback error function is called and the user is notified
accordingly. While the Callback is generating the data, the system will not allow to select the 
submit button!!
*/
function DRCityList()
{
	var pkCountry = document.Form1.ddlPickupCountry;
	var pk_selectedCountry = pkCountry.options[pkCountry.selectedIndex].value;
	var drCountry = document.Form1.ddlDropoffCountry;
	var dr_selectedCountry = drCountry.options[drCountry.selectedIndex].value;
	var pk_selectedCity;
	if (document.Form1.ddlPickupCity.options.length > 0)
	{var pkCity = document.Form1.ddlPickupCity;
		pk_selectedCity = pkCity.options[pkCity.selectedIndex].value;
	}
	else
	{pk_selectedCity="";
	}
	var dr_selectedCity;
	if (document.Form1.ddlDropoffCity.options.length > 0)
	{var drCity = document.Form1.ddlDropoffCity;
		dr_selectedCity = drCity.options[drCity.selectedIndex].value;
	}
	else
	{dr_selectedCity="";
	}
	var str = pk_selectedCountry + ":" + dr_selectedCountry  + ":" +  pk_selectedCity + ":" + dr_selectedCity;
	ctl02_CallBack1.Callback(str);
}

function callback1_onend()
{

}


/* This function will automatically change the dropoff city to the pickup city.*/
function changeCityList()
{
	document.Form1.ddlDropoffCity.selectedIndex = document.Form1.ddlPickupCity.selectedIndex;
}


function chkObject()	
{

if ((document.Form1.ddlPickupCountry == null) || (document.Form1.ddlDropoffCountry==null) || (document.Form1.ddlPickupCity==null) || (document.Form1.ddlDropoffCity==null)) 
	{
		return false;
	} 
else 
	{
		return true;
	}
}

function ValidateInput()
{

if(chkObject())
{
	var pkCountry = document.Form1.ddlPickupCountry;
	var pk_selectedCountry = pkCountry.options[pkCountry.selectedIndex].value;
	if(pk_selectedCountry==0)
		{	alert('Please select a valid Country from the list');
			return false;
		}

	var errorStr="";
	var total=0;
	for(var i=0; i < 10; i++)
	{
		var pk = eval("document.Form1.bkg1_chbxlsCarCategory_" + i);
		if(pk.checked) total=total + 1;
	}
	if(total==0){errorStr=errorStr + 'You need to select at least one car category\n';}

    if (document.Form1.bkg1_tbxDriverAge.value == "")
    {
	errorStr=errorStr + 'You need to fill in the driver age \n';
	}
    else
    {
        if (isNaN(document.Form1.bkg1_tbxDriverAge.value))
        {
			errorStr=errorStr + 'Driver age must be numeric\n';
        }
    }

	var pickup_dt = bkg1_PickerFrom.GetSelectedDate();
	var departure_dt = bkg1_Picker1.GetSelectedDate();


	if (departure_dt == null)
	{
		errorStr=errorStr + 'Departure date from origin is required to proceed\n';
	}

	if (departure_dt>pickup_dt)
	{
			errorStr=errorStr + 'Departure date from origin cannot be greater than pick-up date\n';
	}

	var nowDate = new Date();
	var newDate = new Date(nowDate.getTime() + 7*24*60*60*1000);


	if ((document.Form1.ddlPickupCity.selectedIndex == '-1') || ((document.Form1.ddlDropoffCity.selectedIndex == '-1') && (!document.Form1.chkloc.checked)))
	{
			errorStr=errorStr + 'Sorry there are no rates loaded for this country. Please phone 1300 363 500.\n';
	}
	if(errorStr=='')
		{	//var where_to=true;
			//if (departure_dt<newDate)
			//	{
			//		where_to= confirm("Please Note: \nThe Invoice me/Quote me option will not be available as the departure date is within 7 days.\n Payment by credit card will be required immediately.\n Do you wish to continue?");
			//	}
			
			//if (where_to== true)
			//{
//			if((document.Form1.ddlPickupCountry.value == "GB") || (document.Form1.ddlDropoffCountry.value == "GB"))
//				alert('END OF SUMMER UK SPECIAL\n All discounted UK rates shown are for BOOK and PAY by 29th February 2008.\n');
			bkg1_BusyBox1.Show();
			document.Form1.submit();
			//}
		}
	else
		{
			alert(errorStr);
			return false;
		}
	}
else
	{
	alert('Loading Country & City list.........Please wait!!');
	return false;
	}



}

// following has been moved into ctlGetQuote.ascx
//function showLocation(objSender, objBlockName)
//{
//	try
//	{
//		if(objSender.checked)
//		{
//			if(document.getElementById(objBlockName) != null)
//			{
//				document.getElementById(objBlockName).style.display = "none";
//				document.getElementsByName("ddlPickupCountry").selectedIndex = document.getElementsByName("ddlDropoffCountry").selectedIndex;
//				document.getElementsByName("ddlPickupCity").selectedIndex = document.getElementsByName("ddlDropoffCity").selectedIndex;
//			}
//		}
//		else
//		{
//			if(document.getElementById(objBlockName) != null)
//			{
//				document.getElementById(objBlockName).style.display = "block";
//			}		
//		}
//		document.Form1.ddlDropoffCity.selectedIndex = document.Form1.ddlPickupCity.selectedIndex;
//	}
//	catch(e)
//	{
//	}
//}

/* 
The following function will show and hide content by wrapping the content inside the div tag. The name of 
the div tag has to be unique. 
*/
function showBlock(objSender, objBlockName)
{
	try
	{
		if(objSender.checked)
		{
			if(document.getElementById(objBlockName) != null)
			{
				document.getElementById(objBlockName).style.display = "none";
			}
		}
		else
		{
			if(document.getElementById(objBlockName) != null)
			{
				document.getElementById(objBlockName).style.display = "block";
			}		
		}
	}
	catch(e)
	{
	}
}

function HideBlock(objSender, objBlockName)
{
	try
	{
		if(objSender.checked)
		{
			if(document.getElementById(objBlockName) != null)
			{
				document.getElementById(objBlockName).style.display = "block";
			}
		}
		else
		{
			if(document.getElementById(objBlockName) != null)
			{
				document.getElementById(objBlockName).style.display = "none";
			}		
		}
	}
	catch(e)
	{
	}
}

/* 
	Function to show dynamic content ends Here.............
*/

/*
The function ImageLoadFailed will be called whenever the car image cannot be displayed. This function will display a default
image to show that
*/
function ImageLoadFailed() 
{
window.event.srcElement.src = "http://www.globalmediaserver.com/images/cars/photona_sm.gif";
}
/* 
	Function ImageLoadFailed ends Here.............
*/
/* 
	Function to show dynamic content ends Here.............
*/

/*
The function ImageLoadFailed will be called whenever the car image cannot be displayed. This function will display a default
image to show that
*/
function ImageLoadFailed() 
{
window.event.srcElement.src = "http://www.globalmediaserver.com/images/cars/photona_sm.gif";
}
/* 
	Function ImageLoadFailed ends Here.............
*/


/* 
	The function carWindow() & EEWindow() are used to open popup windows
*/
function carWindow(page) 
{ 
	window.open(page,'_blank','width=620,height=500,left=100,top=100,scrollbars=yes,resizable=no, status=no, titlebar=no, toolbar=no'); 
} 
function EEWindow(page) 
{ 
	window.open(page,'_blank','width=700,height=550,left=100,top=100,scrollbars=yes,resizable=no, status=no, titlebar=no, toolbar=no'); 
}
/* 
	Function ends Here.............
*/


/*==============================================================================================================*/

/* 
	The following two JavaScript functions would be called to show depot information
	Function PKDepot() will take the Depot id and would open a new poopup window 
	and display the detaile depot information
*/
function PKDepot(locationID)
{
	var pk = eval("document.Form1.PickupDepot_" + locationID);
	var pk_selectedItem = pk.selectedIndex;
	var pk_selectedText = pk.options[pk_selectedItem].value;
	if (pk_selectedText == "0")
	{
		alert('Please select Pick-up location first to view Information');
	}
	else
	{
		var url = "DepotInfo.aspx?l=" + pk_selectedText;
		w = window.open(url,'mywindow','width=550,height=500,left=100,top=50,screenX=0,screenY=100,scrollbars=yes');
		w.focus();
	}
}

function DRDepot(locationID)
{
	var dr = eval("document.Form1.DropoffDepot_" + locationID);
	var dr_selectedItem = dr.selectedIndex;
	var dr_selectedText = dr.options[dr_selectedItem].value;
	if (dr_selectedText == "0")
	{
		alert('Please select Drop-off depot to view Information');
	}
	else
	{
		var url = "DepotInfo.aspx?l=" + dr_selectedText;

		w = window.open(url,'mywindow','width=550,height=500,left=100,top=50,screenX=0,screenY=100,scrollbars=yes');
		w.focus();
	}
}
/* Function to display Depot Information Ends Here..............*/


/* 
	The function displayRedbook() will display the redbook information to the Agents.
	It would take Chaos Session id, Quote id, Car SippCode, Depotid and the Car name 
	as parameter.
	If there are no active depots selected then it will prompt the user to select the Depots first
*/
function displayRedbook(SIPPCode,Location,name)
{
	var pk = eval("document.Form1.PickupDepot_" + Location);
	var pk_selectedItem = pk.selectedIndex;
	var pk_selectedText = pk.options[pk_selectedItem].value;
	if (pk_selectedText == "0")
	{
		alert('Please select Pick-up location first to view Redbook Information');
	}
	else
	{
	var url = "redbook.aspx?s=" + SIPPCode + "&l=" + pk_selectedText + "&pname=" + name + "&p=" + Location;
	w = window.open(url,'mywindow','width=700,height=590,left=50,top=50,screenX=0,screenY=100,resizable=yes,scrollbars=yes');
	w.focus();
	
	}
}
/* Function displayRedbook Information Ends Here..............*/

/* 
The function selectProduct() will display the terms and condition by taking chaos session id, quote id, car sippcode and 
pickup and dropoff depot id. 
*/
function selectProduct(ChoasSession,Quoteid,SIPPCode,param,MinAge,MaxAge,Supplier, countrycode)
{

document.Form1.chkterms.checked=false;
if (document.Form1.chkAgents != null) 
	document.Form1.chkAgents.checked=false;


if (MaxAge == "100")
	MaxAge = "99";

var driverage = document.Form1.tbxdriverAge.value;
if((driverage>=MinAge) && (driverage<=MaxAge)) {
	var pk = eval("document.Form1.PickupDepot_" + param);
	var dr = eval("document.Form1.DropoffDepot_" + param);
	var pk_selectedItem = pk.selectedIndex;
	var dr_selectedItem = dr.selectedIndex;
	var pk_selectedText = pk.options[pk_selectedItem].value;
	var dr_selectedText = dr.options[dr_selectedItem].value;
	if (pk_selectedText == "0" && dr_selectedText == "0")
	{
		alert('Please Select a Pick-up and a Drop-off depot');
	}
	else if(pk_selectedText =="0")
	{
		alert('Select a Pick-up depot');
	}
	else if (dr_selectedText == "0")
	{
		alert('Select a Drop-off depot');
	}
	else
	{
		var pk_pos=pk_selectedText.indexOf("-1:");
		var dr_pos=dr_selectedText.indexOf("-1:");
		if ((pk_pos>=0) || (dr_pos>=0))
		{
				alert('The selected car cannot be chosen because the \npick-up/drop-off depot is closed at dates/time requested. \nClick on Change Details to modify your request.');
				return false;
		} 
		else 
		{
			var chkSupplier=true;
			if (Supplier == "PGT")
			{
				var str;
				str = "To qualify for a Peugeot Lease, the contracted driver must meet all the following criteria:\n\n"
				str = str + "They must;\n"
				str = str + "- Reside outside of the European Union.\n"
				str = str + "- Stay in the European Union for no more than 185 days in any consecutive 12 month period.\n"
				str = str + "- Not carry out any activity for gain during your stay (No working Visa's allowed).\n"
				str = str + "- Must be an Australian Resident.\n"
				str = str + "- Minimum age to be 18 years with a full Australian driver's license (provisional license not accepted).\n\n"
				str = str + "If the contracted driver qualifies to do a Peugeot Lease, select 'OK'.\n\n"
				str = str + "If the contracted driver does not qualify, please select 'Cancel' and choose a rental vehicle.\n"
				chkSupplier = confirm(str);
			}
			if (Supplier == "RTZWK")
			{
				var str;
				str = "To qualify for the Weekend Special Rate, the booking must meet the following criteria:\n\n"
				str = str + "- Pick up: Must be between 12pm Thursday and 12pm Sunday.\n"
				str = str + "- Drop off: Must be before 12pm Monday.\n"
				str = str + "- Pick up & Drop off must be at the same location. No one way rentals permitted.\n\n"
				str = str + "Participating Locations:\n"
				str = str + "Sydney Airport, Melbourne Airport, Brisbane Airport, Adelaide Airport, Coolangatta Airport, Maroochydore Airport, Canberra Airport.\n\n"
				str = str + "If the booking qualifies for the Weekend Special Rate, select 'OK'.\n\n"
				str = str + "If the booking does not qualify, please select 'Cancel' and choose another vehicle.\n"
				chkSupplier = confirm(str);
			}
			if ((Supplier == "THT") && (document.Form1.hdncountrycode.value == "AU"))
			{
				if (document.Form1.hdnpucity.value == "ADELAIDE")
				{
					if (SIPPCode == "ECMRAPOW" || SIPPCode == "CCARAPOW" || SIPPCode == "ICARAPOW" || SIPPCode == "IWARAPOW" || SIPPCode == "FCARAPOW" || SIPPCode == "ECMRDTOW" || SIPPCode == "CCARDTOW" || SIPPCode == "ICARDTOW" || SIPPCode == "IWARDTOW" || SIPPCode == "FCARDTOW")
					{
						var str;
						str = "To qualify for the Relocation Special Rate, the booking must meet the following criteria:\n\n"
						str = str + "- Pick Up: Adelaide Airport, City or Adelaide North ONLY\n"
						str = str + "- Drop Off: Cairns Airport or City ONLY\n"
						str = str + "- Maximum 10 days rental.\n\n"
						str = str + "Note: No one way fees applicable on this Special Rate, regardless of duration.\n"
						str = str + "If the booking qualifies for the Relocation Special Rate, select 'OK'.\n\n"
						str = str + "If the booking does not qualify, please select 'Cancel' and choose another vehicle.\n"
						chkSupplier = confirm(str);
					}
				}
			}
			if (Supplier == "THTWK")
			{
				var str;
				str = "To qualify for the Weekend Special Rate, the booking must meet the following criteria:\n\n"
				str = str + "- Pick up: Must be between 12pm Thursday and 12pm Sunday.\n"
				str = str + "- Drop off: Must be before 12pm Monday.\n"
				str = str + "- One way rentals are permitted between participating locations.\n\n"
				str = str + "Participating Locations:\n"
				str = str + "Sydney Airport, Melbourne Airport, Adelaide Airport, Canberra Airport.\n\n"
				str = str + "If the booking qualifies for the Weekend Special Rate, select 'OK'.\n\n"
				str = str + "If the booking does not qualify, please select 'Cancel' and choose another vehicle.\n"
				chkSupplier = confirm(str);
			}
					if (chkSupplier== true)
					{
						var str = SIPPCode + ":" + pk_selectedText + ":" + dr_selectedText + ":" + param;
						document.Form1.tbxsipp.value =SIPPCode;
						document.Form1.tbxpkdp.value =pk_selectedText;
						document.Form1.tbxdrdp.value =dr_selectedText;
						document.Form1.tbxproductid.value=param;
						showBlock(this,'termscondition');
						BusyBox1.Show();
						CallBack1.Callback(str);
					}
					else
					{
						return false;
					}
		}
	}
}
else
	{
		var emsg = "The selected car has a minimum age of " + MinAge + " and a maximum age of " + MaxAge; 
		alert(emsg);
	}
}

/* Function callbackTC_onend is called when the callback function to load the
   terms and condition has finished
*/
function callbackTC_onend()
{
	BusyBox1.Close();
	window.scrollTo(0,1400)
}
/* Function callbackTC_onend Ends Here..............*/


/* 
	Function callbackTC_onError is called when the callback function to load the
	terms and condition encountered and error
*/
function callbackTC_onError()
{
	BusyBox1.Close();
	document.Form1.chkterms.disabled = true;
	alert("There was an error loading the Terms & Conditions\n. Please try again later");
}
/* Function callbackTC_onError Ends Here..............*/


/* 
	The function processbkg() would be called when the user has selected the car & agreed to terms 
	and condition
*/
function processbkg()
{
	var errorStr="";
	var pk = eval("document.Form1.cblOptionalEquipment_0");
	if(pk.checked)
	{	if (document.Form1.tbxAge1.value == "")
			{	errorStr=errorStr + 'You need to fill in the child age \n';
			}
		else
		{	if (isNaN(document.Form1.tbxAge1.value))
				{
					errorStr=errorStr + 'Child age must be numeric\n';
				}
		}
		if (document.Form1.tbxWeight1.value == "")
		{
		errorStr=errorStr + 'You need to fill in the child weight \n';
		}
		else
		{	if (isNaN(document.Form1.tbxWeight1.value))
			{
				errorStr=errorStr + 'Child weight must be numeric\n';
			}
		}
	}
	if (!document.Form1.chkterms.checked)
	{
		errorStr = errorStr + 'You need to accept the Terms & Conditions before proceeding \n';
	}
	/*Added new code here............*/

	if (document.Form1.chkAgents != null)
	{
		if (!document.Form1.chkAgents.checked)
		{
			errorStr = errorStr + 'You also need to accept the Bonus Commission Terms & Conditions. \nNote: Emailing enquiries@driveaway.com.au will secure your commission. \n';
		}
	}
	/*.............................*/



	if(errorStr=='')
	{
		document.Form1.submit();
	}
	else
	{
		alert(errorStr);
	}
}
/* Function processbkg Ends Here..............*/


function printpage()
{
	window.print();  
}


function checkCC()
{ 
	var val = 0;
	var flt = document.getElementById("ddlCarrier");
	var flt_selected = flt.options[flt.selectedIndex].value;
	if(flt_selected == 'WI' )
	{	
	}
	else
	{	
		if (document.Form1.tbxFlightNumber.value.length == 0)
		{
			alert('Flight Number is required');
			return false;
		}
		
		if (document.Form1.tbxArrvTime.value.length == 0)
		{
			alert('Arrival Time is required');
			return false;
		}
	}


	for( i = 0; i < document.Form1.Payment.length; i++ )
	{
		if( document.Form1.Payment[i].checked == true )
			val = document.Form1.Payment[i].value;
	}
	if ((val =="rbtnCreditCard") || (val==0))
	{
		var ccstatus;
		ccstatus = validateCard(document.Form1.tbxCardNumber.value,document.Form1.ddlCardType.value,document.Form1.ddlCardMonth.value,document.Form1.ddlCardYear.value,document.Form1.tbxVerficationCode.value,document.Form1.tbxCardName.value);
		if(ccstatus)
		{
			BusyBox1.Show();
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		BusyBox1.Show();
		return true;
	}
}


function ValidateGPSInput()
{	
	var counter=0;
	var pickup_dt = bkg1_PickerFrom.GetSelectedDate();
	var departure_dt = bkg1_Picker1.GetSelectedDate();
	if (pickup_dt>=departure_dt)
	{		
			alert('Departure date from origin should be greater than the agreed GPS delivery date.\n');
			counter=-1;
			return false;
	}
	if(counter=="0")
	{
			BusyBox1.Show();
			document.Form1.submit();
	}
	else
	{
		return false;
	}
}


function checkGPSCC()
{ 
	var val = 0;
	if (!document.Form1.chkterms.checked)
	{	
		alert('You need to accept the Terms & Conditions before proceeding \n');
		return false;
	}

	for( i = 0; i < document.Form1.Payment.length; i++ )
	{
		if( document.Form1.Payment[i].checked == true )
			val = document.Form1.Payment[i].value;
	}
	if ((val =="rbtnCreditCard") || (val==0))
	{
		var ccstatus;
		ccstatus = validateCard(document.Form1.tbxCardNumber.value,document.Form1.ddlCardType.value,document.Form1.ddlCardMonth.value,document.Form1.ddlCardYear.value,document.Form1.tbxVerficationCode.value,document.Form1.tbxCardName.value);
		if(ccstatus)
		{
			BusyBox1.Show();
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		BusyBox1.Show();
		return true;
	}
}

//javascript:window.history.forward(1);


function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

function AgentcheckCC()
{ 
	var val = document.Form1.tbxAmount.value;
	var val1 = val.length - (val.indexOf(".")+1);
	if(val.indexOf(".") > -1)
		if(val1 > 1)
		{
				//alert("All validation passed");
		}
		else
		{
			alert("Incorrect Format: Please enter the amount as XX.XX");
			return false;
		}
	else
		{
			alert("Incorrect Format: Please enter the amount as XX.XX");
			return false;
		}

	var ccstatus;
	ccstatus = validateCard(document.Form1.tbxCardNumber.value,document.Form1.ddlCardType.value,document.Form1.ddlCardMonth.value,document.Form1.ddlCardYear.value,document.Form1.tbxVerficationCode.value,document.Form1.tbxCardName.value);
	if(ccstatus)
		{
			return true;
		}
		else
		{
			return false;
		}
		return false;

}

function LoadDERC()
{ 
	document.getElementById("no").checked=false;
	var testvar='0';
	CallBack1.Callback(testvar);
	if (document.Form1.rbtnQuote == null)
	{
		//Do Something here for future...
	}
	else
	{
		//document.Form1.rbtnQuote.disabled=true;
	}
}

function callbackDERC_onend()
{
//alert("callback operation complete");
}

function callbackDERC_onError()
{
	alert("There was an error loading the DriveAway Excess Refund Cover Charges");
}

function NoDERC(chkstatus)
{ 
	document.Form1.yes.checked=false
	CallBack1.Callback(chkstatus);
	if (document.Form1.rbtnQuote == null)
	{
		//Do Something here for future...
	}
	else
	{
		//document.Form1.rbtnQuote.disabled=false;
	}
}

function validateCard(cardNumber,cardType,cardMonth,cardYear,cardVerficationCode,cardName)
{
	var id = document.Form1.hdnID.value;
	if( cardNumber.length == 0 )
	{						//most of these checks are self explanitory
		alert("Please enter a valid card number.");
		return false;
	}
	for( var i = 0; i < cardNumber.length; ++i ) {		// make sure the number is all digits.. (by design)
		var c = cardNumber.charAt(i);
		if( c < '0' || c > '9' ) {
			alert("Please enter a valid card number. Use only digits. do not use spaces or hyphens.");
			return false;
		}
	}
	var length = cardNumber.length;			//perform card specific length and prefix tests
	switch( cardType ) {
		case 'a':
			if( length != 15 ) {
				alert("Please enter a valid American Express Card number.");
				return false;
			}
			var prefix = parseInt( cardNumber.substring(0,2));
			if( prefix != 34 && prefix != 37 ) {
				alert("Please enter a valid American Express Card number.");
				return false;
			}
		break;
		case 'd':
			if( length != 14 ) {
				alert("Please enter a valid Diners Club card number.");
				return false;
			}
		break;
		case 'm':
			if( length != 16 ) {
				alert("Please enter a valid MasterCard number.");
				return false;
			}
			var prefix = parseInt( cardNumber.substring(0,2));
			if( prefix < 51 || prefix > 55) {
				alert("Please enter a valid MasterCard Card number.");
				return false;
			}
		break;
		case 'v':
			if( length != 16 && length != 13 ) {
				alert("Please enter a valid Visa Card number.");
				return false;
			}
			var prefix = parseInt( cardNumber.substring(0,1));
			if( prefix != 4 ) {
				alert("Please enter a valid Visa Card number.");
				return false;
			}
		break;
	}
	if( !mod10( cardNumber ) ) { 		// run the check digit algorithm
		alert("Sorry! this is not a valid credit card number.");
		return false;
	}
	if( expired( cardMonth, cardYear ) ) {							// check if entered date is already expired.
		alert("Sorry! The expiration date you have entered would make this card invalid.");
		return false;
	}
	if ((id != "56") && (id != "76455") && (id != "120201"))
	{
		if (cardVerficationCode.length != 0)
		{
			if ((cardVerficationCode.length < 3) || (cardVerficationCode.length > 4))
			{
				alert("Sorry! The credit card verification code cannot be less than three characters");
				return false;
			}
			if (isNaN(cardVerficationCode))
			{
				alert("Sorry! The credit card verification code must be numeric only");
				return false;
			}
		}
		else
		{
			alert("Sorry! The credit card verification code cannot be blank");
			return false;
		}
	}
	if (cardName.length == 0)
	{
		alert("Sorry! The credit card holder name cannot be blank");
		return false;
	}
	if (chkalpha(cardName))
	{
		alert("Sorry! The credit card holder name contains some invalid characters");
		return false;
	}
	return true; // at this point card has not been proven to be invalid
}

