// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function popUp(URL) {
  day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=461,height=231');");
}

jQuery(document).ready(function($) {
  $('a[rel*=facebox]').facebox()
  $(document).pngFix()
})

function toggleYield(elm) {
	if (elm.options[elm.selectedIndex].value == "4") {
		$('#yield_icon').show();
		$('#account_type_yield').show();
	} else {		
		$('#yield_icon').hide();
		$('#account_type_yield').hide();
	}
}
function sendDelayedForm() {
  var zip = $('#zipcode').val();
  if (isNumeric(zip) && zip.length == 5) {
    $('#form_container').hide(); 
    $('#searching_container').show(); 
    window.setTimeout('$(\'form:first\').submit();', 3000); 
  } else {
    alert("Please enter a valid, 5-digit zipcode.");
  }
}
function isNumeric(sText) {
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;
  for (i = 0; i < sText.length && IsNumber == true; i++) { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;
}
function toggleTerms() {
	if (($("#lead_upsale_1:checked").val()) != undefined) {
		$("#ubc_terms").show();
	} else {
		$("#ubc_terms").hide();
	}
}
function confirmUpsaleIfApplicable() {
	if (($("#lead_upsale_1:checked").val()) != undefined) {
		resp = confirm("Press OK to continue and we will begin to find the best lender for you. By pressing OK, you agree you have read and understood and accept all terms for this cash advance offer, as well as all terms for Direct Benefits Online, including charges for 49.9 after the trial and 39.95 a month. By pressing cancel, you still understand and accept all terms of this cash advance offer, but do not wish to try Direct Benefits Online today.");
		if (resp == true) {
			return true;
		} else {
			$('#lead_upsale_1').attr("checked", "");
			return true;
		}
	} else {
		return true;
	}
}

function showSavePopup(){
    if (($("#lead_upsale_1:checked").val()) == undefined) {
	    resp = confirm("Press OK to submit your loan application and still take advantage of the trial for Direct Benefits online. By pressing OK, you agree you have read and understood and accept all terms for this cash advance offer, as well as all terms for Direct Benefits Online, including charges for 49.9 after the trial, and 39.95 a month in charges that will occur if you fail to cancel during the ten day trial.\n\nBy pressing cancel, you still understand and accept all terms of this cash advance offer, but do not wish to try Direct Benefits Online today.");
		if (resp == true) {
			$('#lead_upsale_1').attr("checked", "checked");
			return true;
		} else {
			$('#lead_upsale_1').attr("checked", "");
			return true;
		}
	} else {
		return true;
    }
}

// Adapted from getPageSize() by quirksmode.com
function 
getPageWidth() {
    var windowWidth
    if (self.innerWidth) {	// all except Explorer
        windowWidth = self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientWidth) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
    }
    return windowWidth
}
