var startTime = new Date();
var endTime = new Date();
var redBorderSetField = '';
var highlightedDiv = '';
//------------------------------------------------------------------------------------------------------------------------------------
function WriteEmailLink(username, domainName, linkClass){
	var at = "@";
	document.write("<a href='mailto:"+username+""+at+""+domainName+"' class=\"" + linkClass + "\">"+username+""+at+""+domainName+"</a>");
}
//------------------------------------------------------------------------------------------------------------------------------------
function open_link(link,linkname,x,y) {
	window.open(link, linkname, 'width='+x+',height='+y+',toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0,screenX=100,screenY=100,top=100,left=100')
}
//------------------------------------------------------------------------------------------------------------------------------------
function open_link_pos(link,linkname,x,y,px,py) {
//	alert(link+'|'+linkname+'|'+x+'|'+y+'|'+px+'|'+py);
	window.open(link, linkname, 'width='+x+',height='+y+',toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0,screenX='+px+',screenY='+py+',left='+px+',top='+py)
}
//------------------------------------------------------------------------------------------------------------------------------------
function bookmark(url, description){
	netscape="FireFox User's hit CTRL+D to add DanskAutoRent.com to your bookmarks."
	if (navigator.appName=='Microsoft Internet Explorer'){
	window.external.AddFavorite(url, description);
	}else if (navigator.appName=='Netscape'){
	alert(netscape);
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function leadZero(s){
	var st = new String(s);
	if (st.length==1){
		return "0"+s;
	}
	return s;
}
//------------------------------------------------------------------------------------------------------------------------------------
function getTimeObject(year, mon,day,hour,min){
	return new Date(year,mon-1,day,hour,min,0);
}
//------------------------------------------------------------------------------------------------------------------------------------
function getYear(t){
	var y = t.getYear();
	if (y<1900) y += 1900;
	return y;
}
//------------------------------------------------------------------------------------------------------------------------------------
function getMonLen(t){
	var d = new Date(getYear(t),t.getMonth()+1,0);
	return d.getDate();
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkCarClass(go){
	var f = document.f;
	car_class = document.getElementById('car_class');
	//alert(car_class.value);
	//if (f.car_class.value==0){
	if (!f.car_class.value){
		//if (go==1){
		//	document.location.href="#car_select";
		//}
		//setRedBorder('CAR_RESULTS');
		alert('Please select a Car!');
		return false;
	}else{
		return true;
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function no_submit(e){
	if (e.keyCode == 13){
		return false;
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function numbersonly(myfield, e, dec){
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	// decimal point jump
	else if (dec && (keychar == ".")){
	   myfield.form.elements[dec].focus();
	   return false;
	}else
	   return false;
}
//------------------------------------------------------------------------------------------------------------------------------------
//--- Global variable for slideshow on index.tpl page --------------------------------------------------------------------------------
//----BEGIN SLIDESHOW FUNCTIONS-------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------------
NewImg = new Array (
	"http://www.scandinaviancarrental.com/no/images/ad_focus_sw.jpg",
	"http://www.scandinaviancarrental.com/no/images/ad_ford_ka.jpg",
	"http://www.scandinaviancarrental.com/no/images/ad_ford_mondeo.jpg",
	"http://www.scandinaviancarrental.com/no/images/ad_s60.jpg",
	"http://www.scandinaviancarrental.com/no/images/ad_vw_caravelle.jpg"
);
NewLink = new Array (
	"https://www.scandinaviancarrental.com/no/book.php?from_cars_prices=1&car_class=6",
	"https://www.scandinaviancarrental.com/no/book.php?from_cars_prices=1&car_class=1",
	"https://www.scandinaviancarrental.com/no/book.php?from_cars_prices=1&car_class=7",
	"https://www.scandinaviancarrental.com/no/book.php?from_cars_prices=1&car_class=5",
	"https://www.scandinaviancarrental.com/no/book.php?from_cars_prices=1&car_class=8"
);
var ImgNum = 0;
var ImgLength = NewImg.length - 1;

//Time delay between Slides in milliseconds
var delay = 5000;
var lock = false;
var run;
//------------------------------------------------------------------------------------------------------------------------------------
function chgImg(direction) {
	if (document.images) {
		ImgNum = ImgNum + direction;
	if (ImgNum > ImgLength) {
		ImgNum = 0;
	}
	if (ImgNum < 0) {
		ImgNum = ImgLength;
	}
	document.slideshow.src = NewImg[ImgNum];
	document.getElementById("slideshowlink").href = NewLink[ImgNum];
   }
}
//------------------------------------------------------------------------------------------------------------------------------------
function auto() {
	if (lock == true) {
		lock = false;
		window.clearInterval(run);
	}else if (lock == false) {
		lock = true;
		run = setInterval("chgImg(1)", delay);
   }
}
//------------------------------------------------------------------------------------------------------------------------------------
//----END SLIDESHOW FUNCTIONS---------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------------
function scroller_down(){
	position = document.getElementById("CAR_RESULTS").scrollTop;
	document.getElementById("CAR_RESULTS").scrollTop = position+50;
}
//------------------------------------------------------------------------------------------------------------------------------------
function scroller_up(){
	position = document.getElementById("CAR_RESULTS").scrollTop;
	document.getElementById("CAR_RESULTS").scrollTop = position-50;
}
//------------------------------------------------------------------------------------------------------------------------------------
//--- Added by Dao G. Yang January 4, 2007 (Service Level Project)
//------------------------------------------------------------------------------------------------------------------------------------
function checkServiceLevel(go){
	var f = document.f;
	if (f.pick_loc.value==1 || f.pick_loc.value==''){
		document.getElementById('optional_text').innerHTML = "Required Credit Card Information";
	}else{
		document.getElementById('optional_text').innerHTML = "Optional Credit Card Information";
	}
	if (f.pick_loc.value==1){
		if (f.SS2){
			if (f.SS1){
				if (!f.SS1.checked && !f.SS2.checked){
					if (go==1){
						document.location.href="#service_select";
					}
					setRedBorder('SS1');
					setRedBorder('SS2');
					alert('Please select a Service Level!');
					return false;
				}
				if (f.SS1.checked && f.SS2.checked){
					alert('Please select only one service level.');
					return false;
				}
			}
		}else{
			check_avail();
		}
	}else if (f.pick_loc.value!=1 && f.SS1){
		if (f.SS1.checked){
			//alert('Premium Personal Service is not available outside Kastrup! Please select Express Self Service.');
			f.SS1.checked = false;
			f.SS2.checked = true;
		}
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function show_Steps(){
	if (!document.getElementById('num_5')){
		document.getElementById('num_6').innerHTML = '<IMG src="images/num_5.gif" alt="">';
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function select_Car_Class(car_class,type){
	if (type==0){
		if (document.getElementById('car_class').value != car_class){
			prev_sel = document.getElementById('car_class').value;
			if (prev_sel!=null && prev_sel!=''){
				document.getElementById('the_select_'+prev_sel).innerHTML = "<IMG src='images/icon_select.gif' alt=''>";
				document.getElementById(prev_sel).style.background="#FFFFFF";
				document.getElementById(prev_sel).style.border="1px solid #FFFFFF";
				document.getElementById('name_'+prev_sel).style.color="#555555";
			}
			document.getElementById('car_class').value = car_class;
			document.getElementById(car_class).style.background="#CCDBFF";
			document.getElementById(car_class).style.border="1px solid #BD0000";
			document.getElementById('name_'+car_class).style.color="#BD0000";
			document.getElementById('the_select_'+car_class).innerHTML = "<IMG src='images/icon_selected.gif' alt='' style='padding-bottom:3px;'>";
		}else{
			document.getElementById(document.getElementById('car_class').value).style.border="1px solid #FFFFFF";
			document.getElementById(document.getElementById('car_class').value).style.background="#FFFFFF";
			document.getElementById(document.getElementById('car_class').value).style.color="#555555";
			document.getElementById('name_'+document.getElementById('car_class').value).style.color="#555555";
			document.getElementById('car_class').value = '';
			document.getElementById('the_select_'+car_class).innerHTML = "<IMG src='images/icon_select.gif' alt=''>";
		}
	}else{
		if (document.getElementById('the_select_'+car_class)){
		document.getElementById(car_class).style.border="1px solid #BD0000";
		document.getElementById('name_'+car_class).style.color="#BD0000";
		document.getElementById('the_select_'+car_class).innerHTML = "<IMG src='images/icon_selected.png' alt='' style='padding-bottom:3px;'>";
		}
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function change_background(car_class){
	if (document.getElementById('car_class').value == car_class){
		document.getElementById(car_class).style.background="#CCDBFF";
	}else{
		document.getElementById(car_class).style.background="#FFFFFF";
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkDateDiff(){
	var f = document.f;

	if (parseInt(f.pick_time_year.value)>f.drop_time_year.value){
		return false;
	} else if (parseInt(f.pick_time_year.value)==f.drop_time_year.value){
		if (parseInt(f.pick_time_mon.value)>f.drop_time_mon.value){
			return false;
		} else if (parseInt(f.pick_time_mon.value)==f.drop_time_mon.value){
			if (parseInt(f.pick_time_day.value)>f.drop_time_day.value){
				return false;
			} else if (parseInt(f.pick_time_day.value)==f.drop_time_day.value){
				if (parseInt(f.pick_time_hour.value)>f.drop_time_hour.value){
					return false;
				} else if (parseInt(f.pick_time_hour.value)==f.drop_time_hour.value && parseInt(f.pick_time_min.value)>f.drop_time_min.value){
					return false;
				}
			}
		}
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkDate(year, mon, day, hour, min){
	if (book_start_time[0]>year){
		return false;
	} else if (book_start_time[0]==year){
		if (book_start_time[1]>mon){
			return false;
		} else if (book_start_time[1]==mon){
			if (book_start_time[2]>day){
				return false;
			} else if (book_start_time[2]==day){
				if (book_start_time[3]>hour){
					return false;
				} else if (book_start_time[3]==hour && book_start_time[4]>min){
					return false;
				}
			}
		}
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkDateDay(type){
	var f = document.f;
	var t, mon, mObj, day;
	if (type == 'pick_time'){
		t = getTimeObject(f.pick_time_year.value, f.pick_time_mon.value,f.pick_time_day.value,f.pick_time_hour.value,f.pick_time_min.value);
		mon = f.pick_time_mon.value-1;
		mObj = f.pick_time_mon;
		day = f.pick_time_day;
		monLen = getMonLen(getTimeObject(f.pick_time_year.value, f.pick_time_mon.value,1,0,0));
	} else {
		t = getTimeObject(f.drop_time_year.value, f.drop_time_mon.value,f.drop_time_day.value,f.drop_time_hour.value,f.drop_time_min.value);
		mon = f.drop_time_mon.value-1;
		mObj = f.drop_time_mon;
		day = f.drop_time_day;
		monLen = getMonLen(getTimeObject(f.drop_time_year.value, f.drop_time_mon.value,1,0,0));
	}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//				Added per Michael's Request to adjust for Opening hours on weekdays and weekends for Copenhagen City Desk
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	if (type == 'pick_time'){ // Copenhagen City Desk Time Restraints...//Added per Michael's Request by Dao G. Yang (11/1/2006)
		if (f.pick_loc.value==41){
			mon = f.pick_time_mon.value-1;
			year = f.pick_time_year.value;
			dayofweek = new Date();
			dayofweek.setDate(f.pick_time_day.value);
			dayofweek.setMonth(mon);
			dayofweek.setFullYear(f.pick_time_year.value);
			weekday = dayofweek.getDay();
			if (weekday>0 && weekday<6){
				if (f.pick_time_hour.value<7 || f.pick_time_hour.value>20){ //Weekdays
					alert("Pick-up Time: Copenhagen City Desk hours are between 07:00 and 20:00");
					return true;
				}
			}
			if (weekday==0 || weekday ==6){// Weekends
				if (f.pick_time_hour.value<8 || f.pick_time_hour.value>18){
					alert("Pick-up Time: Copenhagen City Desk hours are between 08:00 and 18:00 on weekends");
					return true;
				}
			}
		}
	}

	if (type == 'pick_time'){ // Billund Airport Desk Time Restraints...
		if (f.pick_loc.value==15){
			var location_wait = document.getElementById("location_wait");
			mon = f.pick_time_mon.value-1;
			year = f.pick_time_year.value;
			dayofweek = new Date();
			dayofweek.setDate(f.pick_time_day.value);
			dayofweek.setMonth(mon);
			dayofweek.setFullYear(f.pick_time_year.value);
			weekday = dayofweek.getDay();
			if (weekday>0 && weekday<6){//Weekdays
				//alert("Inside Weekday");
				if ((f.pick_time_hour.value==7 && f.pick_time_min.value<30) || (f.pick_time_hour.value<7) || (f.pick_time_hour.value>=22)){
					alert("Pick-up Time: Billund Airport hours are between 07:30 and 22:00. If you continue your booking with the curent pick-up time selected, we will place your booking on hold until we contact you for further information.");
					location_wait.value = 'Y';
					return true;
				}
			}
			if (weekday==6){// Saturday
				if (f.pick_time_hour.value<9 || f.pick_time_hour.value>=14){
					alert("Pick-up Time: Billund Airport hours are between 09:00 and 13:00 on Saturdays. If you continue your booking with the curent pick-up time selected, we will place your booking on hold until we contact you for further information.");
					location_wait.value = 'Y';
					return true;
				}
			}
			if (weekday==0){// Sunday
				if ((f.pick_time_hour.value==15 && f.pick_time_min.value<30) || (f.pick_time_hour.value<15) || (f.pick_time_hour.value==21 && f.pick_time_min.value>30) || (f.pick_time_hour.value>21)){
					alert("Pick-Up Time: Billund Airport hours are between 15:30 and 21:30 on Sundays. If you continue your booking with the curent pick-up time selected, we will place your booking on hold until we contact you for further information.");
					location_wait.value = 'Y';
					return true;
				}
			}
		}
	}
/*	if (type == 'drop_time'){
		if (f.drop_loc.value==41){
			mon = f.drop_time_mon.value-1;
			year = f.drop_time_year.value;
			dayofweek = new Date();
			dayofweek.setDate(f.drop_time_day.value);
			dayofweek.setMonth(mon);
			dayofweek.setFullYear(f.drop_time_year.value);
			weekday = dayofweek.getDay();
			if (weekday>0 && weekday<6){
				if (f.drop_time_hour.value<7 || f.drop_time_hour.value>20){
					alert("Drop-off Time: Copenhagen City Desk hours are between 7AM and 20PM");
				}
			}
			if (weekday==0 || weekday ==6){
				if (f.drop_time_hour.value<8 || f.drop_time_hour.value>18){
					alert("Drop-off Time: Copenhagen City Desk hours are between 8AM and 18PM on weekends");
				}
			}
		}
	}*/
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	if (mon != t.getMonth()){
		alert("The "+((type=="pick_time")? "arrival" : "depature")+" date is not a valid date! There is no day "+ day.value +" in "+mObj.options[mObj.selectedIndex].text + ". Changing to "+monLen+".");
		day.options[monLen-1].selected=true;
//		return false;
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function getInvalidDateMsg(){
	alert("You can't make a booking less than 6 hours before rental start. \n(current time in Norway is "+leadZero(today_time[2])+"/"+leadZero(today_time[1])+"/"+today_time[0]+ "  "+leadZero(today_time[3])+":"+leadZero(today_time[4])+")");
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkRentDates(){
	var f = document.f;
	//alert(checkDateDay('pick_time'));
	if (!checkDateDay('pick_time')) return false;
	if (!checkDateDay('drop_time')) return false;

	if (!checkDateDiff()){
		alert("Departure time can't precede Arrival time!");
		return false;
	}
	if (!checkDate(f.pick_time_year.value, f.pick_time_mon.value,f.pick_time_day.value,f.pick_time_hour.value,f.pick_time_min.value) || !checkDate(f.drop_time_year.value, f.drop_time_mon.value,f.drop_time_day.value,f.drop_time_hour.value,f.drop_time_min.value)){
		getInvalidDateMsg();
		return false;
	}

//	if (!checkSpecialBlock(parseInt(f.arrival_mon.value), parseInt(f.arrival_day.value), parseInt(f.depature_mon.value), parseInt(f.depature_day.value))) return false;

	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkExpDate(year, mon){
	if (today_time[0]>year){
		return false;
	} else if (today_time[0]==year){
		if (today_time[1]>mon){
			return false;
		}
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkAllDates(){
	var f = document.f;

	if (!checkRentDates()){
		return false;
	}

	if (f.offer_id){
		if (f.offer_id.checked && !checkSpecialOffer()){
			return false;
		}
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
// -1 kui start > end
// 0 kui start = end
// 1 kui start < end
function compareTimes(start, end){

	if (parseInt(start[0])>parseInt(end[0])){
		return -1;
	} else if (parseInt(start[0])==parseInt(end[0])){
		if (parseInt(start[1])>parseInt(end[1])){
			return -1;
		} else if (parseInt(start[1])==parseInt(end[1])){
			if (parseInt(start[2])>parseInt(end[2])){
				return -1;
			} else if (parseInt(start[2])==parseInt(end[2])){
				if (parseInt(start[3])>parseInt(end[3])){
					return -1;
				} else if (parseInt(start[3])==parseInt(end[3])){
					if (parseInt(start[4])>parseInt(end[4])){
						return -1;
					} else if (parseInt(start[4])==parseInt(end[4])){
						return 0;
					}
				}
			}
		}
	}
	return 1;
}
//------------------------------------------------------------------------------------------------------------------------------------
function updatename(){
var f = document.f; //Declaration of f as document.f
f.elements.name.value=f.elements.fname.value + ' ' + f.elements.lname.value;
}
//------------------------------------------------------------------------------------------------------------------------------------
function splitname(name){
var f = document.f;
if (name.indexOf(" ")>0){
var holder=name.split(" ");
f.elements.fname.value=holder[0];
f.elements.lname.value=holder[1];
}else{
f.elements.fname.value=name;
f.elements.fname.value=name;
}
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkSpecialOffer(){
	var f = document.f;
	var start = new Array(f.pick_time_year.value, f.pick_time_mon.value, f.pick_time_day.value, f.pick_time_hour.value, f.pick_time_min.value);
	var end = new Array(f.drop_time_year.value, f.drop_time_mon.value, f.drop_time_day.value, f.drop_time_hour.value, f.drop_time_min.value);
	if (compareTimes(sp_start,start)<0 || compareTimes(end, sp_end)<0){
		alert("If You want to get Special Offer arrival and depature times must be between Special Offer times. ("+leadZero(sp_start[2])+"/"+leadZero(sp_start[1])+"/"+sp_start[0]+" "+leadZero(sp_start[3])+":"+leadZero(sp_start[4])+" - "+leadZero(sp_end[2])+"/"+leadZero(sp_end[1])+"/"+sp_end[0]+" "+leadZero(sp_end[3])+":"+leadZero(sp_end[4])+")");
		return false;
	}
	if (f.pick_loc.value != kastrup_id || f.drop_loc.value != kastrup_id){
		alert("Special offers are available only in Kastrup.");
		return false;
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkCustomerInfo(){
	var f = document.f;
	var fields = new Array('fname','lname','address','city','state','postal','country','email','phone');
	var boxes = new Array('First Name', 'Last Name', 'Address', 'City', 'State/Province', 'Zip/Postal', 'Country', 'E-mail Address', 'Phone');

	for(var i=0; i<fields.length; i++){
		if (!f.elements[fields[i]].value || f.elements[fields[i]].value.length < 2)
		{
			document.location.href="#cust_info";
			setRedBorder(fields[i]);
			highlight_div('help_4');
			alert('Please fill the "'+boxes[i]+'" box! The "'+boxes[i]+'" Field must be at least 2 characters long.');
			return false;
		}else if ( (fields[i]=='fname' || fields[i]=='lname' )&& f.elements[fields[i]].value.indexOf(' ') > -1)
		{
			document.location.href="#cust_info";
			setRedBorder(fields[i]);
			highlight_div('help_4');
			alert('Please fill the "'+boxes[i]+'" box! The "'+boxes[i]+'" Field must be at least 2 characters long and contain no spaces.');
			return false;
		}
	}

	if (f.date_of_birth_day.value == "0")
	{
		document.location.href="#cust_info";
		setRedBorder("date_of_birth_day");
		highlight_div('help_4');
		alert('Please fill date of birth!');
		return false;
	}
	else if (f.date_of_birth_mon.value == "0")
	{
		document.location.href="#cust_info";
		setRedBorder("date_of_birth_mon");
		highlight_div('help_4');
		alert('Please fill date of birth!');
		return false;
	}
	else if (f.date_of_birth_year.value == "0")
	{
		document.location.href="#cust_info";
		setRedBorder("date_of_birth_year");
		highlight_div('help_4');
		alert('Please fill date of birth!');
		return false;
	}

	if (f.license.value == "")
	{
		document.location.href="#cust_info";
		setRedBorder("license");
		highlight_div('help_4');
		alert('Please fill the "License #" box!');
		return false;
	}

	if (f.license_exp_year.value == "" && f.license_exp_mon.value == "" && !f.NoExp.checked)
	{
		document.location.href="#cust_info";
		setRedBorder("license_exp_year");
		highlight_div('help_4');
		alert('Please select a License Expiration date or select the "No Expiration" box!');
		return false;
	}

	if (f.pass.value == "")
	{
		document.location.href="#cust_info";
		setRedBorder("pass");
		highlight_div('help_4');
		alert('Please fill the "Passport #" box. If not available now, write "N/A" and submit it later');
		return false;
	}

	s = new String(f.country.value);
	if (s.toLowerCase().indexOf('norway') != -1 || s.toLowerCase().indexOf('norge') !=-1 || s.toLowerCase().toString() == 'no')	{
		document.location.href="#cust_info";
		highlight_div('help_6');
		alert('Your address must be outside Norway.');
		return false;
	}
	var s = new String(f.email.value);
	if (s.indexOf('@') == -1 || s.lastIndexOf('.') < s.indexOf('@') || s.length == s.lastIndexOf('.')+1){
		document.location.href="#cust_info";
		setRedBorder('email');
		highlight_div('help_4');
		alert('Please give a valid e-mail address.');
		return false;
	}
	//if (f.denmark_phone.value == ""){
	//	setRedBorder("denmark_phone");
	//	highlight_div('help_6');
	//	alert('Please fill the "Phone no. in Denmark" box if available or write N/A');
	//	return false;
	//}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkCommentBox(){
	var f = document.f;
	var s = new String(f.comments.value);
//	var a = s.split("\n");

	if (s.length>200){
		alert("Text in comment box is too big! (max. 200 characters allowed. You have "+s.length+")");
		return false;
	}

//	if (a.length>4){
//		alert("There are too many line breaks ('enter' presses) in comment box (max. 3 allowed)");
//		return 0;
//	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
// for rent.php
function check_archive(){
	var f = document.f;

	//ADDED CHECK TO ENSURE PICK_LOC AND DROP_LOC WERE THE SAME - NENDE June 29th 2007
	if (f.pick_loc.value != f.drop_loc.value){
		alert("Arrival City and Departure city must be the same location.");
		return false;
	}else{
		if (!checkCustomerInfo()) {return false;}
		f.submit_type.value=3;
		f.submit();
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function getFormEl(f, name){
	var e = f.elements;
	for (var i=0; i<e.length; i++){
		if (e[i].name == name)
			return e[i];
	}
}

Date.prototype.add = function (sInterval, iNum){
  var dTemp = this;
  if (!sInterval || iNum == 0) return dTemp;
  switch (sInterval.toLowerCase()){
    case "ms":
      dTemp.setMilliseconds(dTemp.getMilliseconds() + iNum);
      break;
    case "s":
      dTemp.setSeconds(dTemp.getSeconds() + iNum);
      break;
    case "mi":
      dTemp.setMinutes(dTemp.getMinutes() + iNum);
      break;
    case "h":
      dTemp.setHours(dTemp.getHours() + iNum);
      break;
    case "d":
      dTemp.setDate(dTemp.getDate() + iNum);
      break;
    case "mo":
      dTemp.setMonth(dTemp.getMonth() + iNum);
      break;
    case "y":
      dTemp.setFullYear(dTemp.getFullYear() + iNum);
      break;
  }
  return dTemp;
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkExtras(){
	var f = document.f;

	var snow_tires = document.getElementById("extras["+snow_tires_id+"]");
	var snow_tires_wait = document.getElementById("snow_tires_wait");
	if (snow_tires != null)
	{
		if (snow_tires.checked)
		{
			//alert("!!! You've checked Snow/Winter Tires");
			var today = new Date();
			//alert(today);
			var tomorrow = today.add("d", 1); //+3days
			//alert(tomorrow);
			var booking = new Date()
			booking.setFullYear(f.pick_time_year.value,f.pick_time_mon.value,f.pick_time_day.value);
			booking.setHours(f.pick_time_hour.value,f.pick_time_min.value,0);
			//alert(booking.getFullYear());
			//alert(booking.getMonth());

			if (booking.getFullYear() >= tomorrow.getFullYear()){
				//alert("Checked Year OK");
				if (booking.getMonth() >= tomorrow.getMonth()){
					//alert("Checked Month OK");
					if(booking.getDate() >= tomorrow.getDate()){
						var dif =  booking.getDate() - tomorrow.getDate();
						//alert("dif" + dif);
							if (dif<1){
							//alert(booking.getDate());
							//alert(tomorrow.getDate());
							//alert("Checked Day OK");
							if(booking.getHours() >= tomorrow.getHours()){
								alert("!! Note: If you book Snow/Winter Tires less than 24 hours before your pick-up time, your booking will be put on a waiting list for Snow/Winter Tires.");
								snow_tires_wait.value = 'Y';
								return true;
							}
						}
					}
				}
			}
//			alert('Snow/winter tires are not available for this car.');
//			alert("Snow/Winter tires are not available on  any Opel car or cars in category A,B,H,Y and G+ please select a different category !");
//			alert("Snow tires are only available on category K, F, B, G, X, D, F+, G+, J, R, M except Opel Cars");
//			alert(f.car_class.value);
			//return false;
		}else return true;
	}
/*
	var gps = document.getElementById("extras["+gps_id+"]");
	if (gps != null)
	{
		if (gps.checked){
			if ((f.pick_loc.value != kastrup_id && f.pick_loc.value != 41 && f.pick_loc.value != 15 && f.pick_loc.value != 13) || (f.drop_loc.value != kastrup_id && f.drop_loc.value != 41 && f.drop_loc.value != 15 && f.drop_loc.value != 13)){
			alert('GPS is only available in Kastrup (CPH), Copenhagen City Desk, Billund (BLL) and Esbjerg (EBJ).');
			return false;
			}
		}
	}

*/
/*	if (!hertz[f.car_class.value]){
		if (f.offer_similar.value==''){
			return true;
		} else if (f.old_car_class.value != f.car_class.value) {
			return true;
		}
	}
*/
//	var pg = getFormEl(f, "extras["+park_and_go_id+"]");
//	if (parseInt(pg.value)){
//		alert("'Park & Go' is not available when booking a car from our partner's fleet.");
//		return false;
//	}
//	if (rb.checked){
/*	if (parseInt(rb.value)){
		if (!dansk_loc[f.pick_loc.value] || !dansk_loc[f.drop_loc.value]){
			alert("Roof box is not available outside Kastrup and København City.");
			return false;
		}
	}
*/
/*	var rb = getFormEl(f, "extras["+roof_box_id+"]");
	if (parseInt(rb.value)){
		if (parseInt(f.pick_loc.value) != kastrup_id || parseInt(f.drop_loc.value) != kastrup_id){
			alert("Roof box is not available outside Kastrup.");
			return false;
		}
	}
*/
	if (!check_roofbox())
	{
		return false;
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkFlightAndTime(){
	var f = document.f;
	if (!parseInt(f.bid.value) || flight_and_time_check) return true; // new book
	var start = new Array(f.pick_time_year.value, f.pick_time_mon.value, f.pick_time_day.value, f.pick_time_hour.value, f.pick_time_min.value);
	var start_current = new Array(f.current_pick_time_year.value, f.current_pick_time_mon.value, f.current_pick_time_day.value, f.current_pick_time_hour.value, f.current_pick_time_min.value);
	var end = new Array(f.drop_time_year.value, f.drop_time_mon.value, f.drop_time_day.value, f.drop_time_hour.value, f.drop_time_min.value);
	var end_current = new Array(f.current_drop_time_year.value, f.current_drop_time_mon.value, f.current_drop_time_day.value, f.current_drop_time_hour.value, f.current_drop_time_min.value);
	var msg = '';
	if ((compareTimes(start,start_current)!=0 && f.arrival_flight.value==f.current_arrival_flight.value)){
		msg += "You have changed arrival time, but not arrival flight #.\n";
	} else if ((compareTimes(start,start_current)==0 && f.arrival_flight.value!=f.current_arrival_flight.value)){
		msg += "You have changed arrival flight #, but not arrival time.\n";
	}

//	if ((compareTimes(end,end_current)!=0 && f.depature_flight.value==f.current_depature_flight.value)){
//		msg += "You have changed depature time, but not depature flight #.\n";
//	} else if ((compareTimes(end,end_current)==0 && f.depature_flight.value!=f.current_depature_flight.value)){
//		msg += "You have changed depature flight #, but not depature time.\n";
//	}
	if (msg){
		flight_and_time_check = true;
		alert(msg + "Please double-check the data !");
		return false;
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function setRedBorder(field){
	var fl = document.getElementById(field);
	fl.style.borderWidth='1px';
	fl.style.borderColor='#FF0000';
	redBorderSetField = field;
	fl.focus();
}
//------------------------------------------------------------------------------------------------------------------------------------
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  //return false;
}
//------------------------------------------------------------------------------------------------------------------------------------
function logmein(){
	nl = getQueryVariable('loginname');
	dwsp = getQueryVariable('password');
	if (nl && dwsp){
		//if (navigator.appName=='Microsoft Internet Explorer'){
			//document.getElementById("loginname").value = nl;
			//document.getElementById("password").value = dwsp;
			//document.forms["login"].submit();
		//}else if (navigator.appName=='Netscape'){
			document.forms["login"]["loginname"].value = nl;
			document.forms["login"]["password"].value = dwsp;
			document.forms["login"].submit();
		//}
	}
}
//------------------------------------------------------------------------------------------------------------------------------------//------------------------------------------------------------------------------------------------------------------------------------
//The main function to call other functions to check information on the Book.php page
function check_book_info() {
	var f = document.f;

	if (redBorderSetField!=''){
		var fl = document.getElementById(redBorderSetField);
		fl.style.borderWidth='1px';
		fl.style.borderColor='#000000';
	}

	unhighlight_div(highlightedDiv);

	if (!f.arrival_flight.value && !f.NoFlight.checked){
		if (!f.comments.value){
				setRedBorder('arrival_flight');
			document.location.href="#delivery_info";
			highlight_div('help_1');
			alert("Flight # missing. Please fill or explain in comment box! If you're not arriving by plane, please indicate.");
			return false;
		}
		if (f.NoFlight.checked){
			f.arrival_flight.value == "No Flight";
		}
	}
	//ADDED CHECK TO ENSURE PICK_LOC AND DROP_LOC WERE THE SAME - NENDE June 29th 2007
	if (f.pick_loc.value != f.drop_loc.value){
		alert("Arrival City and Departure city must be the same location.");
		return false;
	}
	if (!checkFlightAndTime()) return false;
	if (!checkAllDates()){return false;}
	if (!checkCarClass(1)){return false;}
	if (!checkCustomerInfo()) {return false;}
	if (!checkExtras()) {return false;}
	if (!checkCommentBox()) {return false;}
//------------------------------------------------------------------------------------------------------------------------------------
//--- Added by Dao G. Yang January 4, 2007 (Service Level Project)
//------------------------------------------------------------------------------------------------------------------------------------
	//if (!checkServiceLevel(1)){return false;}
	if (f.pick_loc.value==1 && checkCarClass(0)){
		if (f.SS2){
			if (f.SS2.checked){
				if (f.c_card.value==0){
					alert("You must enter your credit card information if you choose Express Self Service.")
					return false;
				}
				if (!f.CardType.value){
					alert("Please enter a card type.")
					return false;
				}
				if (!f.ExpMon.value){
					alert("Please enter an expiration month for your Credit Card.")
					return false;
				}
				if (f.ExpYear.value==0){
					alert("Please enter an expiration year for your Credit Card.")
					return false;
				}
			}
		}
	}else{
		if (!f.c_card.value==0){
			if (!f.CardType.value){
				alert("Please enter a card type.")
				return false;
			}
			if (!f.ExpMon.value){
				alert("Please enter an expiration month.")
				return false;
			}
			if (f.ExpYear.value==0){
				alert("Please enter an expiration year.")
				return false;
			}
		}
		return true;
	}
//------------------------------------------------------------------------------------------------------------------------------------
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
//Call from book.tpl to check the rent info on the page
function rent() {
	var f = document.f;
	updatename();
	if (!check_book_info())
		return false;
	f.submit_type.value=2;
	f.submit();
	show_ticker();
}
//------------------------------------------------------------------------------------------------------------------------------------
function checkbutton(){
	var f = document.f;
		rent();
}
//------------------------------------------------------------------------------------------------------------------------------------
function add_waiting_list() {
	var f = document.f;

	if (!check_book_info())
		return false;
	f.submit_type.value=4;
	f.submit();
	show_ticker();
}
//------------------------------------------------------------------------------------------------------------------------------------
function check_calc_info(){
	var f = document.f;

	if (redBorderSetField!=''){
		var fl = document.getElementById(redBorderSetField);
		fl.style.borderWidth='1px';
		fl.style.borderColor='#000000';
	}

	unhighlight_div(highlightedDiv);

	if (!checkRentDates()){
		return false;
	}

	if (f.offer_id){
		if (f.offer_id.checked && !checkSpecialOffer()){
			return false;
		}
	}
	if (!checkCarClass(0)){
		return false;
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function check_qq_avail(){
	var f = document.f;

	if (!check_calc_info()){
		return false;
	}
	//ADDED CHECK TO ENSURE PICK_LOC AND DROP_LOC WERE THE SAME - NENDE June 29th 2007
	if (f.pick_loc.value != f.drop_loc.value){
		alert("Arrival City and Departure city must be the same location.");
		return false;
	}else{
		f.submit_type.value=1;
		document.f.submit();
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function retain_s_level(){
	if (getQueryVariable('s_level')){
		s_level = getQueryVariable('s_level');
		if (s_level != ''){
			if (s_level == 'SS1'){
				document.getElementById('SS1').checked = true;
				document.getElementById('SS2').checked = false;
			}else if (s_level == 'SS2'){
				document.getElementById('SS1').checked = false;
				document.getElementById('SS2').checked = true;
			}

		}
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function retain_car_class(){
	if (getQueryVariable('car_class')){
		car_class = getQueryVariable('car_class');
		select_Car_Class(car_class,1);
		document.getElementById(car_class).scrollIntoView(true);
		document.getElementById('BODY').scrollIntoView(true);
		document.getElementById('car_class').value = car_class;
		document.getElementById('car_class').style.background='red';
		change_background(document.getElementById('car_class').value);
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function check_avail(){
	var f = document.f;

	updatename();

	if (!check_calc_info()){
		return false;
	}

	if (!checkExtras()) {return false;}
	var $variable = getQueryVariable("ac");
	var car_class = document.getElementById('car_class').value;

	if (f.SS1 && f.SS2){
		if (f.SS1.checked == true){
			s_level = 'SS1';
		}else if (f.SS2.checked == true){
			s_level = 'SS2';
		}else{
			s_level='';
		}
	}else{
		s_level='';
	}
	//ADDED CHECK TO ENSURE PICK_LOC AND DROP_LOC WERE THE SAME - NENDE June 29th 2007
	if (f.pick_loc.value != f.drop_loc.value){
		alert("Arrival City and Departure city must be the same location.");
		return false;
	}else{
		if ($variable){
	//--- DEV Links ---------------------------------------------------------------------------------------------------------------------
	//	f.action='http://192.168.2.226/no/book.php?from_quick_quote=1&ac='+$variable+'&car_class='+car_class+'&s_level='+s_level;
	//--- Live Links ---------------------------------------------------------------------------------------------------------------------
			f.action='https://www.scandinaviancarrental.com/no/book.php?from_quick_quote=1&ac='+$variable+'&car_class='+car_class+'&s_level='+s_level;
		}else{
	//--- DEV Links ---------------------------------------------------------------------------------------------------------------------
	//		f.action='http://192.168.2.226/no/book.php?from_quick_quote=1'+'&car_class='+car_class+'&s_level='+s_level;
	//--- Live Links ---------------------------------------------------------------------------------------------------------------------
			f.action='https://www.scandinaviancarrental.com/no/book.php?from_quick_quote=1'+'&car_class='+car_class+'&s_level='+s_level;
		}
		f.submit_type.value=1;
		document.f.submit();
	}
//	show_ticker();
}
//------------------------------------------------------------------------------------------------------------------------------------
function quick_quote_book_now(){
	var f = document.f;
	//alert(check_calc_info());
	//alert(document.getElementById('car_class').value);
	var car_class = document.getElementById('car_class').value;
	if (!check_calc_info()){
		return false;
	}
	//ADDED CHECK TO ENSURE PICK_LOC AND DROP_LOC WERE THE SAME - NENDE June 29th 2007
	if (f.pick_loc.value != f.drop_loc.value){
		alert("Arrival City and Departure city must be the same location.");
		return false;
	}else{
	f.submit_type.value=1;
//--- DEV Links ---------------------------------------------------------------------------------------------------------------------
//	f.action='http://192.168.2.226/no/book.php?from_quick_quote=1&car_class='+car_class;
//--- Live Links ---------------------------------------------------------------------------------------------------------------------
	f.action='https://www.scandinaviancarrental.com/no/book.php?from_quick_quote=1&car_class='+car_class;
	document.f.submit();
	}
}
//--- Added by Dao G. Yang --- November 8, 2006---------------------------------------------------------------------------------------
function cars_prices_book_now(car_type){
	var f = document.f;
	f.car_type.value = car_type;
	f.submit_type_from_cars_prices.value=1;
//--- DEV Links ---------------------------------------------------------------------------------------------------------------------
//	f.action='http://192.168.2.226/no/book.php?from_cars_prices=1&car_class='+car_type;
//--- Live Links ---------------------------------------------------------------------------------------------------------------------
	f.action='https://www.scandinaviancarrental.com/no/book.php?from_cars_prices=1&car_class='+car_type;
	document.f.submit();
}
//------------------------------------------------------------------------------------------------------------------------------------
function selectOption(sel, opt){
	for (var i=0; i<sel.options.length; i++){
		if (sel.options[i].value==opt){
			sel.options[i].selected=true;
			break;
		}
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function dateselect(yr, mon, field){
	y = yr[yr.selectedIndex].value;
	m = mon[mon.selectedIndex].value;
  window.open('dateselect.php?mon_year='+y+m+'&field='+field,'dateselect', 'width=200,height=200,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=0,copyhistory=0,screenX=350,screenY=300,top=300,left=350');
}
//------------------------------------------------------------------------------------------------------------------------------------
function takeDate(yr,m,d,field){
	ds = eval('document.f.'+field+'_day');
	ms = eval('document.f.'+field+'_mon');
	ys = eval('document.f.'+field+'_year');

	for(i=0; i<ds.length; i++){
		if (ds[i].value==d){
			ds[i].selected=true;
			break;
		}
	}

	for(i=0; i<ms.length; i++){
		if (ms[i].value==m){
			ms[i].selected=true;
			break;
		}
	}

	for(i=0; i<ys.length; i++){
		if (ys[i].text==yr){
			ys[i].selected=true;
			break;
		}
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function change_additional_drivers_sel(){
	var f = document.f;

	f.submit_type.value=10;
	car_class = document.getElementById("car_class").value;
	f.action=f.action+'&car_class='+car_class+'#additional_drivers_pos';
	document.f.submit();
}
//------------------------------------------------------------------------------------------------------------------------------------
function promoshow_sel(){//Added per Michael's Request to show Promo Code Select on edit_clients.php
	var f = document.f;
	f.submit_type.value=20;
	f.action=f.action+'#promoshow_pos';
	document.f.submit();
}

var ticker_preload = new Image();
ticker_preload.src="img/ticker3.gif";
//------------------------------------------------------------------------------------------------------------------------------------
function show_ticker(){
	var ticker_img = document.getElementById("ticker_img");
	ticker_img.src=ticker_preload.src;
	var ticker = document.getElementById("ticker");
	if (typeof(document.body.clientWidth)!='undefined')
		ticker.style.left=parseInt(parseInt(document.body.clientWidth)/2)-35;
	if (typeof(document.body.scrollTop)!='undefined' && typeof(document.body.clientHeight)!='undefined')
		ticker.style.top=parseInt(document.body.scrollTop)+parseInt(document.body.clientHeight)-200;
	ticker.style.display='block';
}
//------------------------------------------------------------------------------------------------------------------------------------
function show_live_help_icon(imgname, ddp_x, ddp_y, imgwidth, imgheight) {
	var text;
	var text = "<table width='100%' height='100%' border='0' bgcolor='#023B70' cellspacing='1' cellpadding='1'>";
	text += "<tr><td align='left' valign='top' bgcolor='white'>";
//--- DEV Links ---------------------------------------------------------------------------------------------------------------------
//	text += "<a href=\"\" onClick=\"javascript: window.open('http://192.168.2.226/no/onlinehelp.php', 'onlinehelp','width=330,height=500,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0'); return false;\"><img src='img/"+imgname+"' alt='' border='' width="+imgwidth+" height="+imgheight+"></a>";
//--- Live Links ---------------------------------------------------------------------------------------------------------------------
	text += "<a href=\"\" onClick=\"javascript: window.open('http://www.scandinaviancarrental.com/no/onlinehelp.php', 'onlinehelp','width=330,height=500,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0'); return false;\"><img src='img/"+imgname+"' alt='' border='' width="+imgwidth+" height="+imgheight+"></a>";
	text += "</td></tr></table>";

	ddp_show_layer(text, ddp_x, ddp_y, imgwidth+4, imgheight+4);
}
//------------------------------------------------------------------------------------------------------------------------------------
function check_roofbox(){
	var roofbox = document.getElementById("extras["+roof_box_id+"]");
	if (roofbox == null)
	{
		return true;
	}
	if (roofbox.value == "" || parseInt(roofbox.value) == 0)
	{
		return true;
	}

	if (parseInt(roofbox.value)){
		if (parseInt(f.pick_loc.value) != kastrup_id || parseInt(f.drop_loc.value) != kastrup_id){
			unhighlight_div();
			highlight_div('help_2');
			alert("Roof box is not available outside Kastrup.");
			return false;
		}
	}
	if (parseInt(document.f.car_class.value) != roof_box_car_class_id )
	{
		unhighlight_div();
		highlight_div('help_2');
		alert("Roof box is available only with Opel Zafira.");
		return false;
	}
	return true;
}
//------------------------------------------------------------------------------------------------------------------------------------
function highlight_div(div_id){
	var myDiv = document.getElementById(div_id);
	if (myDiv != null)
	{
//		myDiv.style.fontWeight = 'bold';
//		myDiv.style.color = 'red';
		myDiv.innerHTML = '<img src="img/helpfaqred.jpg" width="68" height="21" alt="Help/FAQ" Title="Help/FAQ" border="0">';
		highlightedDiv = div_id;
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function unhighlight_div(){
	if (highlightedDiv != '')
	{
		var myDiv = document.getElementById(highlightedDiv);
		if (myDiv != null)
		{
//			myDiv.style.fontWeight = 'normal';
//			myDiv.style.color = 'black';
			myDiv.innerHTML = '<img src="img/helpfaq.jpg" width="68" height="21" alt="Help/FAQ" Title="Help/FAQ" border="0">';
		}
	}
}
//------------------------------------------------------------------------------------------------------------------------------------
function showDiv(myDiv){
	myDiv.style.display = "";
}
//------------------------------------------------------------------------------------------------------------------------------------
function hideDiv(myDiv){
	myDiv.style.display = "none";
}

//=====================================================================================================================================
//=====================================================================================================================================
// Credit Card Check - BEGIN
//=====================================================================================================================================
//=====================================================================================================================================

<!-- Begin
var Cards = new makeArray(5);

Cards[0] = new CardType("MasterCard", "51,52,53,54,55", "16");
var MasterCard = Cards[0];

Cards[1] = new CardType("VisaCard", "4", "13,16");
var VisaCard = Cards[1];

Cards[2] = new CardType("AmExCard", "34,37", "15");
var AmExCard = Cards[2];

Cards[3] = new CardType("Dankort", "5019", "16");
var Dankort = Cards[3];

var LuhnCheckSum = Cards[4] = new CardType();

/*************************************************************************\
CheckCardNumber(form)
function called when users click the "check" button.
\*************************************************************************/
function CheckCardNumber() {
var f = document.f
var tmpyear;
	if (f.c_card.value.length == 0) {
		//alert("Please enter a Card Number.");
		f.c_card.focus();
		return;
	}
	if (f.ExpYear.value.length == 0) {
		//alert("Please enter the Expiration Year.");
		f.ExpYear.focus();
		return;
	}
	if (f.ExpYear.value < 21)

		tmpyear = "20" + f.ExpYear.value;
	else {
		alert("The Expiration Year is not valid.");
		return;
	}
	tmpmonth = f.ExpMon.options[f.ExpMon.selectedIndex].value;
	//alert("tmpmonth: "+tmpmonth);
	// The following line doesn't work in IE3, you need to change it
	// to something like "(new CardType())...".
	// if (!CardType().isExpiryDate(tmpyear, tmpmonth)) {
	if (!(new CardType()).isExpiryDate(tmpyear, tmpmonth)) {
		alert("This card has already expired.");
	return;
	}
	card = f.CardType.options[f.CardType.selectedIndex].value;
	//alert(card);
	//alert(card + ".checkCardNumber(\"" + f.c_card.value + "\", " + tmpyear + ", " + tmpmonth + ");");
	var retval = eval(card + ".checkCardNumber(\"" + f.c_card.value + "\", " + tmpyear + ", " + tmpmonth + ");");
	//alert(retval);
	cardname = "";
	if (retval)
		// comment this out if used on an order form
		//alert("This card number appears to be valid.");
	//else {
	// The cardnumber has the valid luhn checksum, but we want to know which
	// cardtype it belongs to.
		for (var n = 0; n < Cards.size; n++) {
			if (Cards[n].checkCardNumber(f.c_card.value, tmpyear, tmpmonth)) {
				cardname = Cards[n].getCardType();
				break;
			}
		}
		if (cardname.length > 0) {
			//alert(cardname.length);
			//alert("This looks like a " + cardname + " number, not a " + card + " number.");
			return true;
		}else{
			//alert(cardname.length);
			alert("This card number is not valid.");
			return false;
		}
	//}
}
/*************************************************************************\
Object CardType([String cardtype, String rules, String len, int year,
                                        int month])
cardtype    : type of card, eg: MasterCard, Visa, etc.
rules       : rules of the cardnumber, eg: "4", "6011", "34,37".
len         : valid length of cardnumber, eg: "16,19", "13,16".
year        : year of expiry date.
month       : month of expiry date.
eg:
var VisaCard = new CardType("Visa", "4", "16");
var AmExCard = new CardType("AmEx", "34,37", "15");
\*************************************************************************/
function CardType() {
	var n;
	var argv = CardType.arguments;
	var argc = CardType.arguments.length;

	this.objname = "object CardType";

	var tmpcardtype = (argc > 0) ? argv[0] : "CardObject";
	var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9";
	var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19";

	this.setCardNumber = setCardNumber;  // set CardNumber method.
	this.setCardType = setCardType;  // setCardType method.
	this.setLen = setLen;  // setLen method.
	this.setRules = setRules;  // setRules method.
	this.setExpiryDate = setExpiryDate;  // setExpiryDate method.

	this.setCardType(tmpcardtype);
	this.setLen(tmplen);
	this.setRules(tmprules);
	if (argc > 4)
	this.setExpiryDate(argv[3], argv[4]);

	this.checkCardNumber = checkCardNumber;  // checkCardNumber method.
	this.getExpiryDate = getExpiryDate;  // getExpiryDate method.
	this.getCardType = getCardType;  // getCardType method.
	this.isCardNumber = isCardNumber;  // isCardNumber method.
	this.isExpiryDate = isExpiryDate;  // isExpiryDate method.
	this.luhnCheck = luhnCheck;// luhnCheck method.
	return this;
}

/*************************************************************************\
boolean checkCardNumber([String cardnumber, int year, int month])
return true if cardnumber pass the luhncheck and the expiry date is
valid, else return false.
\*************************************************************************/
function checkCardNumber() {
	//alert("checkCardNumber: "+checkCardNumber);
	var argv = checkCardNumber.arguments;
	//alert("argv: "+argv);
	var argc = checkCardNumber.arguments.length;
	//alert("argc: "+argc);
	var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
	//alert("cardnumber: "+cardnumber);
	var year = (argc > 1) ? argv[1] : this.year;
	//alert("year: "+year);
	var month = (argc > 2) ? argv[2] : this.month;
	//alert("month: "+month);

	this.setCardNumber(cardnumber);
	this.setExpiryDate(year, month);

	//alert("Is this a card number: "+this.isCardNumber());

	if (!this.isCardNumber()){return false;}
	if (!this.isExpiryDate()){return false;}

	return true;
}
/*************************************************************************\
String getCardType()
return the cardtype.
\*************************************************************************/
function getCardType() {
	//alert(this.cardtype);
	return this.cardtype;
}
/*************************************************************************\
String getExpiryDate()
return the expiry date.
\*************************************************************************/
function getExpiryDate() {
	return this.month + "/" + this.year;
}
/*************************************************************************\
boolean isCardNumber([String cardnumber])
return true if cardnumber pass the luhncheck and the rules, else return
false.
\*************************************************************************/
function isCardNumber() {
	var argv = isCardNumber.arguments;
	//alert("argv: "+argv);
	var argc = isCardNumber.arguments.length;
	//alert("argc: "+argc);
	var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
	//alert("cardnumber: "+cardnumber);
	//alert("luhnCheck is: "+this.luhnCheck())
	if (!this.luhnCheck())
		return false;

	for (var n = 0; n < this.len.size; n++)
		if (cardnumber.toString().length == this.len[n]) {
			for (var m = 0; m < this.rules.size; m++) {
				var headdigit = cardnumber.substring(0, this.rules[m].toString().length);
				if (headdigit == this.rules[m])
				return true;
			}
			return false;
		}
	return false;
}

/*************************************************************************\
boolean isExpiryDate([int year, int month])
return true if the date is a valid expiry date,
else return false.
\*************************************************************************/
function isExpiryDate() {
	var argv = isExpiryDate.arguments;
	var argc = isExpiryDate.arguments.length;

	year = argc > 0 ? argv[0] : this.year;
	month = argc > 1 ? argv[1] : this.month;

	if (!isNum(year+""))
		return false;
	if (!isNum(month+""))
		return false;
	today = new Date();
	expiry = new Date(year, month);
	if (today.getTime() > expiry.getTime())
		return false;
	else
		return true;
}

/*************************************************************************\
boolean isNum(String argvalue)
return true if argvalue contains only numeric characters,
else return false.
\*************************************************************************/
function isNum(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;
}

/*************************************************************************\
boolean luhnCheck([String CardNumber])
return true if CardNumber pass the luhn check else return false.
\*************************************************************************/
function luhnCheck() {
	var argv = luhnCheck.arguments;
	var argc = luhnCheck.arguments.length;

	var CardNumber = argc > 0 ? argv[0] : this.cardnumber;

		if (! isNum(CardNumber)) {
		return false;
		}

	var no_digit = CardNumber.length;
	var oddoeven = no_digit & 1;
	var sum = 0;

		for (var count = 0; count < no_digit; count++) {
			var digit = parseInt(CardNumber.charAt(count));
				if (!((count & 1) ^ oddoeven)) {
					digit *= 2;
					if (digit > 9)
						digit -= 9;
				}
			sum += digit;
		}
	if (sum % 10 == 0)
		return true;
	else
		return false;
}

/*************************************************************************\
ArrayObject makeArray(int size)
return the array object in the size specified.
\*************************************************************************/
function makeArray(size) {
	this.size = size;
	return this;
}

/*************************************************************************\
CardType setCardNumber(cardnumber)
return the CardType object.
\*************************************************************************/
function setCardNumber(cardnumber) {
	this.cardnumber = cardnumber;
	return this;
}

/*************************************************************************\
CardType setCardType(cardtype)
return the CardType object.
\*************************************************************************/
function setCardType(cardtype) {
	this.cardtype = cardtype;
	return this;
}

/*************************************************************************\
CardType setExpiryDate(year, month)
return the CardType object.
\*************************************************************************/
function setExpiryDate(year, month) {
	this.year = year;
	this.month = month;
	return this;
}

/*************************************************************************\
CardType setLen(len)
return the CardType object.
\*************************************************************************/
function setLen(len) {
	// Create the len array.
	if (len.length == 0 || len == null)
	len = "13,14,15,16,19";

	var tmplen = len;
	n = 1;
	while (tmplen.indexOf(",") != -1) {
	tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length);
	n++;
	}
	this.len = new makeArray(n);
	n = 0;
	while (len.indexOf(",") != -1) {
	var tmpstr = len.substring(0, len.indexOf(","));
	this.len[n] = tmpstr;
	len = len.substring(len.indexOf(",") + 1, len.length);
	n++;
	}
	this.len[n] = len;
	return this;
}

/*************************************************************************\
CardType setRules()
return the CardType object.
\*************************************************************************/
function setRules(rules) {
// Create the rules array.
	if (rules.length == 0 || rules == null)
	rules = "0,1,2,3,4,5,6,7,8,9";

	var tmprules = rules;
	n = 1;
		while (tmprules.indexOf(",") != -1) {
		tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length);
		n++;
		}
	this.rules = new makeArray(n);
	n = 0;
		while (rules.indexOf(",") != -1) {
		var tmpstr = rules.substring(0, rules.indexOf(","));
		this.rules[n] = tmpstr;
		rules = rules.substring(rules.indexOf(",") + 1, rules.length);
		n++;
		}
	this.rules[n] = rules;
	return this;
}

//=====================================================================================================================================
//=====================================================================================================================================
// Credit Card Check - END
//=====================================================================================================================================
//=====================================================================================================================================
