// JavaScript Document
/*
	8/01/2006 - Modified display_roundtrip function - included logic for super value-pack  - jjm
*/
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
function swap_locations(value){
	if (value == "departing") {
	var temp = document.newuser.departing.selectedIndex;
	var str = document.newuser.departing[temp].value;
	var arg_str1 = document.form2.arv_str1.value;
	var arg_str2 = document.form2.arv_str2.value;
	if ( str.indexOf("&") == -1 && str.indexOf(":") == -1 && str.indexOf("-") == -1 ){
		// a hampton location picked
		arg_str1 = arg_str1.split(";");
		for ( var i = 0; i <= arg_str1.length - 1; i++ ){
			document.newuser.arriving[i].value = arg_str1[i];
			document.newuser.arriving[i].text = arg_str1[i];
		}
	} else {
		if( str.indexOf("&") != - 1 ){
			// a nyc location selected
			arg_str2 = arg_str2.split(";");
			for ( var i = 0; i <= arg_str2.length - 1; i++ ){
				document.newuser.arriving[i].value = arg_str2[i];
				document.newuser.arriving[i].text = arg_str2[i];
			}
		}
	}	
	} else {
		var temp = document.newuser.rtdeparting.selectedIndex;
		var str = document.newuser.rtdeparting[temp].value;
		var arg_str1 = document.form2.dep_str1.value;
		var arg_str2 = document.form2.arv_str1.value;
		if ( str.indexOf("&") == -1 && str.indexOf(":") == -1 && str.indexOf("-") == -1 ){
		// a hampton location picked
			arg_str2 = arg_str2.split(";");
			for ( var i = 0; i <= arg_str2.length - 1; i++ ){
				document.newuser.rtarriving[i].value = arg_str2[i];
				document.newuser.rtarriving[i].text = arg_str2[i];
			}
		} else {
			if( str.indexOf("&") != - 1 ){
			// a nyc location selected
				arg_str1 = arg_str1.split(";");
				for ( var i = 0; i <= arg_str1.length - 1; i++ ){
					document.newuser.rtarriving[i].value = arg_str1[i];
					document.newuser.rtarriving[i].text = arg_str1[i];
				}
			}
		}
	}
}

function verify_loc(value){
	var txt = "";
	if (value == "departing"){
		var temp = document.newuser.departing.selectedIndex;
		var str = document.newuser.departing[temp].value;
		if ( str.indexOf("&") == -1 && str.indexOf(":") == -1 && str.indexOf("-") == -1 ){
		// a hampton location picked
			swap_locations(value)
		} else {
			if( str.indexOf("&") != - 1 ){
			// a nyc location selected
				/*if( str == "40th St. & Third Ave"){
					document.newuser.departing.selectedIndex = document.newuser.departing.selectedIndex - 1;
					swap_locations(value)
					alert("Sorry for the inconvience. However, the departing location you sepcified is not currently available.");
					
				} else {swap_locations(value)}*/
				swap_locations(value)
			}
		}		
	} else if ( value == "arriving" ){
		var temp = document.newuser.arriving.selectedIndex;
		var str = document.newuser.arriving[temp].value;
		if ( str.indexOf("&") == -1 && str.indexOf(":") == -1 && str.indexOf("-") == -1 ){
		// a hampton location picked
			pass = true;
		} else {
			if( str.indexOf("&") != - 1 ){
			// a nyc location selected
				if( str != "40th St. & Third Ave"){
					//document.newuser.arriving.selectedIndex = 2;
					//alert("Sorry for the inconvience. However, the departing location you sepcified is not currently available.");
				}
			}
		}		
	} else if (value == "rtdeparting"){
		var temp = document.newuser.rtdeparting.selectedIndex;
		var str = document.newuser.rtdeparting[temp].value;
		if ( str.indexOf("&") == -1 && str.indexOf(":") == -1 && str.indexOf("-") == -1 ){
		// a hampton location picked
			swap_locations(value)
		} else {
			if( str.indexOf("&") != - 1 ){
			// a nyc location selected
				/*if( str == "40th St. & Third Ave"){
					document.newuser.rtdeparting.selectedIndex = 5;
					swap_locations(value)
					alert("Sorry for the inconvience. However, the return trip departing location you sepcified is not currently available.");
				} else {swap_locations(value)}*/
				swap_locations(value)
			}
		}		
	} else if (value == "rtarriving") {
		var temp = document.newuser.rtarriving.selectedIndex;
		var str = document.newuser.rtarriving[temp].value;
		if ( str.indexOf("&") == -1 && str.indexOf(":") == -1 && str.indexOf("-") == -1 ){
		// a hampton location picked
		} else {
			if( str.indexOf("&") != - 1 ){
			// a nyc location selected
				if( str != "40th St. & Third Ave"){
					//document.newuser.rtarriving.selectedIndex = 2;
					//alert("Sorry for the inconvience. However, the departing location you sepcified is not currently available.");
				}
			}
		}		
	}
	
}

function display_roundtrip(value){
	var temp_str = "select_trip_type.asp?";
	switch(value){
		case "oneway":
			temp_str += "visible=off&checked=oneway";
			//document.newuser.rt.value = "off";
		break;
		case "roundtrip":
			if(confirm("Would you like to schedule your return trip at this time?")){
				temp_str += "visible=on&checked=roundtrip";
				//document.newuser.rt.value = "on";
			} else {
				if( document.URL.indexOf("visible=on") != -1 ){
					temp_str += "visible=off&checked=roundtrip";
					//document.newuser.rt.value = "off";
				}
			}
		break;
		case "value":
			if(confirm("Are you sure you want to purchase a value pack? \n You will receive 10 tickets to apply to any One-Way or Round trip(s).")){
				if(confirm("Would you like to schedule your return trip at this time?")){
					temp_str += "visible=on&checked=value";
					//document.newuser.rt.value = "on";
				} else {
					if( document.URL.indexOf("visible=on") != -1 ){
						temp_str += "visible=off&checked=value";
						//document.newuser.rt.value = "off";
					}
				}
			} else {
				window.location = temp_str;
			}
		break;
		case "supervalue":
			if(confirm("Are you sure you want to purchase a super value pack? \n You will receive 20 tickets to apply to any One-Way or Round trip(s).")){
				if(confirm("Would you like to schedule your return trip at this time?")){
					temp_str += "visible=on&checked=supervalue";
					//document.newuser.rt.value = "on";
				} else {
					if( document.URL.indexOf("visible=on") != -1 ){
						temp_str += "visible=off&checked=supervalue";
						//document.newuser.rt.value = "off";
					}
				}
			} else {
				window.location = temp_str;
			}
		break;
	}
	if( temp_str.indexOf("=") != -1 ){
		window.location = temp_str;
	}
}

function display_roundtrip_promo(value){
	var temp_str = "select_trip_type_promo.asp?";
	switch(value){
		case "oneway":
			temp_str += "visible=off&checked=oneway";
			//document.newuser.rt.value = "off";
		break;
		case "roundtrip":
			if(confirm("Would you like to schedule your return trip at this time?")){
				temp_str += "visible=on&checked=roundtrip";
				//document.newuser.rt.value = "on";
			} else {
				if( document.URL.indexOf("visible=on") != -1 ){
					temp_str += "visible=off&checked=roundtrip";
					//document.newuser.rt.value = "off";
				}
			}
		break;
		case "value":
			if(confirm("Are you sure you want to purchase a value pack? \n You will receive 10 tickets to apply to any One-Way or Round trip(s).")){
				if(confirm("Would you like to schedule your return trip at this time?")){
					temp_str += "visible=on&checked=value";
					//document.newuser.rt.value = "on";
				} else {
					if( document.URL.indexOf("visible=on") != -1 ){
						temp_str += "visible=off&checked=value";
						//document.newuser.rt.value = "off";
					}
				}
			} else {
				window.location = temp_str;
			}
		break;
		case "supervalue":
			if(confirm("Are you sure you want to purchase a super value pack? \n You will receive 20 tickets to apply to any One-Way or Round trip(s).")){
				if(confirm("Would you like to schedule your return trip at this time?")){
					temp_str += "visible=on&checked=supervalue";
					//document.newuser.rt.value = "on";
				} else {
					if( document.URL.indexOf("visible=on") != -1 ){
						temp_str += "visible=off&checked=supervalue";
						//document.newuser.rt.value = "off";
					}
				}
			} else {
				window.location = temp_str;
			}
		break;
	}
	if( temp_str.indexOf("=") != -1 ){
		window.location = temp_str;
	}
}

var test = "";
function validate_destination(btn){ // called from Trips.Asp to validate form
 var msg = ""; 
 var departing = document.newuser.departing[document.newuser.departing.selectedIndex].value;
 var arriving = document.newuser.arriving[document.newuser.arriving.selectedIndex].value;
 var t = "";
 switch( btn ){
	case "otrip":
		if ( departing.indexOf(":") != -1  || departing.indexOf("-") != -1 ){
		msg = "Required! -- Please select a valid departing destination."
		t = true;
		}
		if (arriving.indexOf(":") != -1  || arriving.indexOf("-") != -1 ){
		msg = msg + "\n" + "Required! -- Please select a valid arriving destination."
		t = true;
		}
		if (!t) {
		 if ( (departing.indexOf("&") != -1 && arriving.indexOf("&") != -1) || (departing.indexOf("&") == -1 && arriving.indexOf("&") == -1) ){
		 msg = "You can not Depart and Arrive in the same area";
		 } 
		}
		break;
	case "rttrip":
		var rtdeparting = document.newuser.rtdeparting[document.newuser.rtdeparting.selectedIndex].value;
 		var rtarriving = document.newuser.rtarriving[document.newuser.rtarriving.selectedIndex].value;
		var dep_date = document.newuser.depdate.value;
		var rt_date = document.newuser.rtdate.value;
		var compared = compare_dates(rt_date,dep_date);
		switch( compared ){
			case "less":
				msg = "The Return Trip Date can not occur prior to the Departing Trip Date!";
			break;
			case "equal":
				if( (departing.indexOf("&") != -1 && rtdeparting.indexOf("&") != -1) || (departing.indexOf("&") ==  -1 && rtdeparting.indexOf("&") == -1 )){
					msg = "You can not schedule a trip with both the same Departing and Returning directions on the same day!"; 
				}
			break;
		}
		if( msg == ""){
			if (departing.indexOf(":") != -1  || departing.indexOf("-") != -1 ){
			msg = "Required! -- Please select a valid departing destination." + "\n"
			t = true;
			}
			if (arriving.indexOf(":") != -1  || arriving.indexOf("-") != -1 ){
			msg = msg + "Required! -- Please select a valid arriving destination." + "\n"
			t = true;
			}
			if(!t){
		 		if ( (departing.indexOf("&") != -1 && arriving.indexOf("&") != -1) || (departing.indexOf("&") == -1 && arriving.indexOf("&") == -1) ){
		 		msg = "You can not Depart and Arrive in the same area";
		 		}
			}
			if (rtdeparting.indexOf(":") != -1  || rtdeparting.indexOf("-") != -1 ){
			msg = msg + "\x0D" + "Required! -- Please select a valid return trip departing destination." + "\n"
			t = true;
			}
			if (rtarriving.indexOf(":") != -1  || rtarriving.indexOf("-") != -1 ){
			msg = msg + "Required! -- Please select a valid return trip arriving destination."
			t = true;
			}
			if(!t){
		 		if ( (rtdeparting.indexOf("&") != -1 && rtarriving.indexOf("&") != -1) || (rtdeparting.indexOf("&") == -1 && rtarriving.indexOf("&") == -1) ){
		 		msg = "You can not Depart and Arrive in the same area";
		 		}
			}
 		}
		break;
 	}
	if ( msg != "" ){alert(msg);} else {document.newuser.submit();}
}

function round_trip(value){
	if ( test != value ){
		if(!confirm("Would you like to schedule the return trip at this time?")){
		alert("A one-way trip will be accreditated to your account to use for a future trip.");
		window.location = "trip2.asp?" + value + "on";
		} else {change_direction(value);}
	}
}


function change_direction(value){
	var url_redirect_string = url_check(value);
	if (url_redirect_string != "" ) {
		window.location = url_redirect_string;
	}
}
	
function validate_form(){
	var alert_message = "";
	var today = new Date;
	if( !document.form1.cookie2.checked ){
		document.form1.cookie2.value = "false";
	} 
	if( document.form1.first.value == null || document.form1.first.value == "" ){
		alert_message = "Please enter your first name. \n";
	}
	if( document.form1.last.value == null || document.form1.last.value == "" ){
		alert_message += "Please enter your last name. \n";
	}
	if( document.form1.cc_card1.value == null || document.form1.cc_card1.value == "" ) { 
		 alert_message += "Please enter a valid Credit Card number. \n";
	} else {
		if( isNaN(parseInt(document.form1.cc_card1.value.substring(document.form1.cc_card1.value.length - 4,document.form1.cc_card1.value.length)))){
			alert_message += "Please enter a valid Credit Card number. \n";
		}
	}
	if( document.form1.address1.value == null || document.form1.address1.value == "" ){
		alert_message += "Please enter the billing address of the Credit Card. \n";
	} else {
		if( document.form1.address2.value != null && document.form1.address2.value != "" ){
			document.form1.addfull.value = document.form1.address1.value + " " + document.form1.address2.value;
		} else {
			document.form1.addfull.value = document.form1.address1.value;
		}
	}
	if( document.form1.city.value == null || document.form1.city.value == "" ){
		alert_message += "Please enter the city of the billing address. \n";
	}
	if( document.form1.state.value == "default" ){
		alert_message += "Please enter the state of the billing address. \n";
	}
	if( document.form1.zip.value == null || document.form1.zip.value == "" ){
		alert_message += "Please enter the zip code of the billing address. \n";
	}
	if( parseInt(document.form1.expmonth.value) < today.getMonth() && parseInt(document.form1.expyear.value) == today.getYear() ){
		alert_message += "The expiration date specified has already passed. \n";
	}
	if( alert_message != "" ){alert(alert_message);} else {document.form1.submit();}
}

function compare_dates(date1,date2){	
	var return_str = "";
	var temp_date = parse_date(date1);
	var temp_date2 = parse_date(date2);
	var temp_date = new Date(parseInt(temp_date[2]),parseInt(temp_date[0])-1,parseInt(temp_date[1]));
	var temp_date2 = new Date(parseInt(temp_date2[2]),parseInt(temp_date2[0])-1,parseInt(temp_date2[1]));
	if( temp_date.getYear() < temp_date2.getYear() ){
		return_str = "less";
	} else if( temp_date.getYear() == temp_date2.getYear() ){
		if( temp_date.getMonth() < temp_date2.getMonth() ){
			return_str = "less";
		} else if( temp_date.getMonth() == temp_date2.getMonth() ){
			if( temp_date.getDate() < temp_date2.getDate() ){
				return_str = "less";
			} else if( temp_date.getDate() == temp_date2.getDate() ){
				return_str = "equal";
			} else {
				return_str = "greater";
			}
		} else {
			return_str = "greater";
		}
	} else {
		return_str = "greater";
	}
	return return_str;
}

function parse_date(date){
	var tmp = date.split("/");
	if (tmp == "undefined" ){
		Response.Write("problem with date format");
	} else {
		for( var i=0;i<tmp.length;i++){
			
			if( tmp[i].charAt(0) == "0"){
				tmp[i] = tmp[i].substring(1,tmp.length-1);
			}
		}
		return tmp;
	}
}