/*
* 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 setPostalAddress(chckbox) {
	if ( chckbox.checked ) {
		document.getElementById("workAddress.line1").value = document.getElementById("homeAddress.line1").value;
		document.getElementById("workAddress.line2").value = document.getElementById("homeAddress.line2").value;
		document.getElementById("workAddress.city").value = document.getElementById("homeAddress.city").value;
		document.getElementById("workAddress.state").value = document.getElementById("homeAddress.state").value;
		document.getElementById("workAddress.postcode").value = document.getElementById("homeAddress.postcode").value;
		document.getElementById("workAddress.countryCode").value = document.getElementById("homeAddress.countryCode").value;

        if (document.getElementById("homeAddress.line3").value != "") {
            document.getElementById("workAddress.line3").value = document.getElementById("homeAddress.line3").value;
            document.getElementById("workAddressLine3a").style.display = "";
            document.getElementById("workAddressLine3b").style.display = "";
            
        } else {
            document.getElementById("workAddress.line3").value = ""; 
            document.getElementById("workAddressLine3a").style.display = "none";
            document.getElementById("workAddressLine3b").style.display = "none";
        }


	} else {
		document.getElementById("workAddress.line1").value = "";
		document.getElementById("workAddress.line2").value = "";
		document.getElementById("workAddress.line3").value = "";
		document.getElementById("workAddress.city").value = "";
		document.getElementById("workAddress.state").value = "";
		document.getElementById("workAddress.postcode").value = "";
		document.getElementById("workAddress.countryCode").value = "";
		document.getElementById("workAddressLine3a").style.display = "none";
        document.getElementById("workAddressLine3b").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');");
}

/**
 * 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';
