/*
 * Useful function for swapping images around
 */
function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for ( var i = 0; i < changeImages.arguments.length; i += 2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i + 1];
		}
	}
}

/*
 * Check for valid numeric strings
 */
function IsNumeric(strString) {
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;

	if (strString.length == 0 || strString.length < 10)
		return false;

	/*
	 * Test strString consists of valid characters listed above
	 */
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}

/*
 * Open a new popup window in demand
 */
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl
			+ ',scrollbars=' + scroll + ','
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}


function setAddressVisibility(checkBox, objectToToggle) {
	if(!checkBox.checked) {
		document.getElementById(objectToToggle).style.display = "none";
		document.getElementById("postalAddressHome").checked = true;
	} else {
		document.getElementById(objectToToggle).style.display = "inline";
	}
}

function hideBusinessAddress(checkBox) {
	if(!checkBox.checked) {
		document.getElementById("businessAddress").style.display = "inline";
	} else {
		document.getElementById("businessAddress").style.display = "none";
	}
}


function uncheck() {
	//document.getElementById("postalSameAsHome").checked = false;
}

function popUp(URL, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page"
			+ id
			+ " = window.open(URL, '"
			+ id
			+ "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width="
			+ width + ",height=" + height + "');");
}

function popUpLeft(URL, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page"
			+ id
			+ " = window.open(URL, '"
			+ id
			+ "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width="
			+ width + ",height=" + height + ",top=0,left=0');");
}

function popUpButtons(URL, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page"
			+ id
			+ " = window.open(URL, '"
			+ id
			+ "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width="
			+ width + ",height=" + height + "');");
}

function popUpClean(URL) {
	day = new Date();
	id = day.getTime();
	eval("page"
			+ id
			+ " = window.open(URL, '"
			+ id
			+ "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=650');");
}

function getRequestParams(param) {
   var search = window.location.search.substring(1);
   if(search.indexOf('&') > -1) {
      var params = search.split('&');
      for(var i = 0; i < params.length; i++) {
          var value = params[i].split('=');
          if(value[0] == param) return value[1];
      }
   } else {
      var params = search.split('=');
      if(params[0] == param) return params[1];
   }
   return null;
}

function getCheckedValue(radioNodes) {
	if(!radioNodes)
		return "";
	var radioNodesLength = radioNodes.length;
	if(radioNodes == undefined)
		if(radioNodes.checked)
			return radioNodes.value;
		else
			return "";
	for(var i = 0; i < radioNodesLength; i++) {
		if(radioNodes[i].checked) {
			return radioNodes[i].value;
		}
	}
	return "";
}


/**
 * globals for button mouseovers
 */

// submit
submit_up = new Image();
submit_up.src = '/images/buttons/submit.gif';
submit_dn = new Image();
submit_dn.src = '/images/buttons/submit_ro.gif';
submit_d = new Image();
submit_d.src = '/images/buttons/submit_d.gif';

// submit and resend
submit_resend_up = new Image();
submit_resend_up.src = '/images/buttons/submit_resend.gif';
submit_resend_dn = new Image();
submit_resend_dn.src = '/images/buttons/submit_resend_ro.gif';
submit_resend_d = new Image();
submit_resend_d.src = '/images/buttons/submit_resend_d.gif';

// search
search_up = new Image();
search_up.src = '/images/buttons/search.gif';
search_dn = new Image();
search_dn.src = '/images/buttons/search_ro.gif';

// update
update_up = new Image();
update_up.src = '/images/buttons/update.gif';
update_dn = new Image();
update_dn.src = '/images/buttons/update_ro.gif';

// next
next_up = new Image();
next_up.src = '/images/buttons/next.gif';
next_dn = new Image();
next_dn.src = '/images/buttons/next_ro.gif';
next_d = new Image();
next_d.src = '/images/buttons/next_d.gif';

// activate
activate_up = new Image();
activate_up.src = '/images/buttons/activate.gif';
activate_dn = new Image();
activate_dn.src = '/images/buttons/activate_ro.gif';

// deactivate
deactivate_up = new Image();
deactivate_up.src = '/images/buttons/deactivate.gif';
deactivate_dn = new Image();
deactivate_dn.src = '/images/buttons/deactivate_ro.gif';

// continue
continue_up = new Image();
continue_up.src = '/images/booking/btn_book_now.gif';
continue_dn = new Image();
continue_dn.src = '/images/booking/btn_book_now.gif';

// next day flights
nextday_up = new Image();
nextday_up.src = '/images/booking/btn_next_day.gif';
nextday_dn = new Image();
nextday_dn.src = '/images/booking/btn_next_day.gif';

// previous day flights
prevday_up = new Image();
prevday_up.src = '/images/booking/btn_previous_day.gif';
prevday_dn = new Image();
prevday_dn.src = '/images/booking/btn_previous_day.gif';

// purchase
purchase_up = new Image();
purchase_up.src = '/images/booking/but_purchase.gif';
purchase_dn = new Image();
purchase_dn.src = '/images/booking/but_purchase.gif';
purchase_d = new Image();
purchase_d.src = '/images/booking/but_purchase_d.gif';

// confirm
confirm_up = new Image();
confirm_up.src = '/images/buttons/btn_confirm.gif';
confirm_dn = new Image();
confirm_dn.src = '/images/buttons/btn_confirm.gif';
confirm_d = new Image();
confirm_d.src = '/images/buttons/btn_confirm_d.gif';

// find_reward_flights
find_reward_flights_up = new Image();
find_reward_flights_up.src = '/images/buttons/find_reward_flights.gif';
find_reward_flights_dn = new Image();
find_reward_flights_dn.src = '/images/buttons/find_reward_flights_ro.gif';

// find_reward_flights_red
find_reward_flights_red_up = new Image();
find_reward_flights_red_up.src = '/images/buttons/find_reward_flights_red.gif';
find_reward_flights_red_dn = new Image();
find_reward_flights_red_dn.src = '/images/buttons/find_reward_flights_red_ro.gif';

// yes
yes_up = new Image();
yes_up.src = '/images/buttons/yes.gif';
yes_dn = new Image();
yes_dn.src = '/images/buttons/yes_ro.gif';

// no
no_up = new Image();
no_up.src = '/images/buttons/no.gif';
no_dn = new Image();
no_dn.src = '/images/buttons/no_ro.gif';

// join_now
join_now_up = new Image();
join_now_up.src = '/images/buttons/join_now.gif';
join_now_dn = new Image();
join_now_dn.src = '/images/buttons/join_now_ro.gif';

// history
history_up = new Image();
history_up.src = '/images/buttons/history.gif';
history_dn = new Image();
history_dn.src = '/images/buttons/history_ro.gif';

// comments
comments_up = new Image();
comments_up.src = '/images/buttons/comments.gif';
comments_dn = new Image();
comments_dn.src = '/images/buttons/comments_ro.gif';

// add_comment
add_comment_up = new Image();
add_comment_up.src = '/images/buttons/add_comment.gif';
add_comment_dn = new Image();
add_comment_dn.src = '/images/buttons/add_comment_ro.gif';

// add_comment
login_up = new Image();
login_up.src = '/images/buttons/login.gif';
login_dn = new Image();
login_dn.src = '/images/buttons/login_ro.gif';

