﻿/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-06-19 20:25:28 -0500 (Tue, 19 Jun 2007) $
 * $Rev: 2111 $
 *
 * Version 2.1
 */
(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&parseInt($.browser.version)<=6){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild)})}return this};if(!$.browser.version)$.browser.version=navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1]})(jQuery);

/*
 * jQuery Tooltip plugin 1.2
 *
 * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
 * http://docs.jquery.com/Plugins/Tooltip
 *
 * Copyright (c) 2006 - 2008 Jörn Zaefferer
 *
 * $Id: jquery.tooltip.js 4569 2008-01-31 19:36:35Z joern.zaefferer $
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
 (function($){var helper={},current,title,tID,IE=$.browser.msie&&/MSIE\s(5\.5|6\.)/.test(navigator.userAgent),track=false;$.tooltip={blocked:false,defaults:{delay:200,showURL:true,extraClass:"",top:15,left:15,id:"tooltip"},block:function(){$.tooltip.blocked=!$.tooltip.blocked;}};$.fn.extend({tooltip:function(settings){settings=$.extend({},$.tooltip.defaults,settings);createHelper(settings);return this.each(function(){$.data(this,"tooltip-settings",settings);this.tooltipText=this.title;$(this).removeAttr("title");this.alt="";}).hover(save,hide).click(hide);},fixPNG:IE?function(){return this.each(function(){var image=$(this).css('backgroundImage');if(image.match(/^url\(["']?(.*\.png)["']?\)$/i)){image=RegExp.$1;$(this).css({'backgroundImage':'none','filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+image+"')"}).each(function(){var position=$(this).css('position');if(position!='absolute'&&position!='relative')$(this).css('position','relative');});}});}:function(){return this;},unfixPNG:IE?function(){return this.each(function(){$(this).css({'filter':'',backgroundImage:''});});}:function(){return this;},hideWhenEmpty:function(){return this.each(function(){$(this)[$(this).html()?"show":"hide"]();});},url:function(){return this.attr('href')||this.attr('src');}});function createHelper(settings){if(helper.parent)return;helper.parent=$('<div id="'+settings.id+'"><h3></h3><div class="body"></div><div class="url"></div></div>').appendTo(document.body).hide();if($.fn.bgiframe)helper.parent.bgiframe();helper.title=$('h3',helper.parent);helper.body=$('div.body',helper.parent);helper.url=$('div.url',helper.parent);}function settings(element){return $.data(element,"tooltip-settings");}function handle(event){if(settings(this).delay)tID=setTimeout(show,settings(this).delay);else
show();track=!!settings(this).track;$(document.body).bind('mousemove',update);update(event);}function save(){if($.tooltip.blocked||this==current||(!this.tooltipText&&!settings(this).bodyHandler))return;current=this;title=this.tooltipText;if(settings(this).bodyHandler){helper.title.hide();var bodyContent=settings(this).bodyHandler.call(this);if(bodyContent.nodeType||bodyContent.jquery){helper.body.empty().append(bodyContent)}else{helper.body.html(bodyContent);}helper.body.show();}else if(settings(this).showBody){var parts=title.split(settings(this).showBody);helper.title.html(parts.shift()).show();helper.body.empty();for(var i=0,part;part=parts[i];i++){if(i>0)helper.body.append("<br/>");helper.body.append(part);}helper.body.hideWhenEmpty();}else{helper.title.html(title).show();helper.body.hide();}if(settings(this).showURL&&$(this).url())helper.url.html($(this).url().replace('http://','')).show();else
helper.url.hide();helper.parent.addClass(settings(this).extraClass);if(settings(this).fixPNG)helper.parent.fixPNG();handle.apply(this,arguments);}function show(){tID=null;helper.parent.show();update();}function update(event){if($.tooltip.blocked)return;if(!track&&helper.parent.is(":visible")){$(document.body).unbind('mousemove',update)}if(current==null){$(document.body).unbind('mousemove',update);return;}helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");var left=helper.parent[0].offsetLeft;var top=helper.parent[0].offsetTop;if(event){left=event.pageX+settings(current).left;top=event.pageY+settings(current).top;helper.parent.css({left:left+'px',top:top+'px'});}var v=viewport(),h=helper.parent[0];if(v.x+v.cx<h.offsetLeft+h.offsetWidth){left-=h.offsetWidth+20+settings(current).left;helper.parent.css({left:left+'px'}).addClass("viewport-right");}if(v.y+v.cy<h.offsetTop+h.offsetHeight){top-=h.offsetHeight+20+settings(current).top;helper.parent.css({top:top+'px'}).addClass("viewport-bottom");}}function viewport(){return{x:$(window).scrollLeft(),y:$(window).scrollTop(),cx:$(window).width(),cy:$(window).height()};}function hide(event){if($.tooltip.blocked)return;if(tID)clearTimeout(tID);current=null;helper.parent.hide().removeClass(settings(this).extraClass);if(settings(this).fixPNG)helper.parent.unfixPNG();}$.fn.Tooltip=$.fn.tooltip;})(jQuery);

/*
 * Autotab - jQuery plugin 1.0
 * http://dev.lousyllama.com/auto-tab
 * 
 * Copyright (c) 2008 Matthew Miller
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 * 
 * Revised: 2008/05/22 01:23:25
 */
(function($){$.fn.autotab=function(options){var defaults={format:'all',maxlength:2147483647,uppercase:false,lowercase:false,nospace:false,target:null,previous:null};$.extend(defaults,options);var check_element=function(name){var val=null;var check_id=$('#'+name)[0];var check_name=$('input[name='+name+']')[0];if(check_id!=undefined)val=$(check_id);else if(check_name!=undefined)val=$(check_name);return val};var key=function(e){if(!e)e=window.event;return e.keyCode};if(typeof defaults.target=='string')defaults.target=check_element(defaults.target);if(typeof defaults.previous=='string')defaults.previous=check_element(defaults.previous);var maxlength=$(this).attr('maxlength');if(defaults.maxlength==2147483647&&maxlength!=2147483647)defaults.maxlength=maxlength;else if(defaults.maxlength>0)$(this).attr('maxlength',defaults.maxlength);else defaults.target=null;if($.browser.msie){this.keydown(function(e){if(key(e)==8){var val=this.value;if(val.length==0&&defaults.previous)defaults.previous.focus()}})}return this.keypress(function(e){if(key(e)==8){var val=this.value;if(val.length==0&&defaults.previous)defaults.previous.focus()}}).keyup(function(e){var val=this.value;switch(defaults.format){case'text':var pattern=new RegExp('[0-9]+','g');var val=val.replace(pattern,'');break;case'alpha':var pattern=new RegExp('[^a-zA-Z]+','g');var val=val.replace(pattern,'');break;case'number':case'numeric':var pattern=new RegExp('[^0-9]+','g');var val=val.replace(pattern,'');break;case'alphanumeric':var pattern=new RegExp('[^0-9a-zA-Z]+','g');var val=val.replace(pattern,'');break;case'all':default:break}if(defaults.nospace){pattern=new RegExp('[ ]+','g');val=val.replace(pattern,'')}if(defaults.uppercase)val=val.toUpperCase();if(defaults.lowercase)val=val.toLowerCase();this.value=val;var keys=[8,9,16,17,18,19,20,27,33,34,35,36,37,38,39,40,45,46,144,145];var string=keys.toString();if(string.indexOf(key(e))==-1&&val.length==defaults.maxlength&&defaults.target)defaults.target.focus()})}})(jQuery);

var msgBoxShow = function(box){};
var msgBoxHide = function(box){};
$.msgBox = function(title, message, opts){
	var me = this;
	var s = opts || {};

	var box = $("<div>").addClass("msgBox");
	var overlay;
	if (s.overlay !== false) {
		overlay = $("<div>").addClass("overlay").css("opacity", 0.5).hide().appendTo("body").click(function(){me.close();});
		if (!s.hidden)
			overlay.fadeIn("fast");
	}
	if ($.browser.msie && parseInt($.browser.version) == 6) {
		$("html, body").css({height: "100%", width: "100%"});
		if (overlay)
			$("<p>").css({width: "100%", height: "100%"}).appendTo(overlay).bgiframe();
		//else
		//	box.bgiframe();
	}

	me.self = function(){
		return box;
	};
	me.hide = function(){
		box.fadeOut();
		if (overlay)
			overlay.fadeOut();
		msgBoxHide(me);
	};
	me.show = function(){
		if (overlay)
			overlay.fadeIn();
		box.fadeIn();
		msgBoxShow(me);
	};
	me.remove = function(){
		box.fadeOut("fast", function(){
			$(this).remove();
		});
		if (overlay) {
			overlay.fadeOut("fast", function(){
				$(this).remove();
			});
		}
		$().unbind("keydown", fkey);
		msgBoxHide(me);
	};
	me.close = function(){
		if (s.remove)
			me.remove();
		else
			me.hide();
	};
	var fkey = function(e){
		if (e.which == 27)
			me.close();
	}

	var t = $("<div>").addClass("title").html(title).appendTo(box);
	$("<a>").attr("href", "#").html("Close").appendTo(t).click(function(){
		me.close();
		return false;
	});
	var c = $("<div>").addClass("message").appendTo(box).append(message);
	$().keydown(fkey);
	if (s.width)
		box.css("width", s.width);
	if (s.top)
		box.css("top", s.top);
	if (s.left)
		box.css({"left": s.left, "margin-left": 0});
	else if (s.width)
		box.css("margin-left", "-" + Math.floor(s.width / 2) + "px");
	box.css("opacity", s.opacity || (overlay ? 0.9 : 0.95)).hide().appendTo("body");
	if (!s.hidden) {
		box.fadeIn();
		msgBoxShow(me);
	}
};
CKM.popup_error = function(title, err){
	var m = new $.msgBox(err ? title : "Error", "<p>" + (err || title) + "</p>", {remove: true});
};
CKM.format_valid = function(input){
	input.removeClass(CKM.error_class).addClass(CKM.valid_class).unbind("mouseenter").removeAttr("title");
};
CKM.format_invalid = function(input, err){
	input.removeClass(CKM.valid_class).addClass(CKM.error_class).unbind("mouseenter").attr("title", err).Tooltip();
};

$(function(){
	var ot = $("input:radio[name=over_ten]").click(function(){
		var f = function(first, second){
			CKM.format_valid(second);
			second.attr("name", "debt_amount2").removeClass(CKM.required_class).parent().parent().hide();
			CKM.remove_format(first);
			first.attr("name", "debt_amount").addClass(CKM.required_class).val("").parent().parent().show();
		};
		var y = this.value == "yes";
		f($("#debt_amount" + (y ? "" : "2")), $("#debt_amount" + (y ? "2" : "")));
	});
	ot.filter(":checked").click();

	$("form td.phone input").each(function(){
		var all = $(this).parent().children("input");
		var l = all.length;
		var i = all.index(this) + 1;
		$(this).autotab({format: "numeric", target: (i < l ? all.get(i) : null), previous: (i > 1 ? all.get(i - 2) : null)});
	});

	$("input[defval]").focus(function(){
		var me = $(this);
		if (me.val() == me.attr("defval"))
			me.val("").removeClass(CKM.default_value_class);
	}).blur(function(){
		var me = $(this);
		if ($.trim(me.val()).length == 0 || me.val() == me.attr("defval"))
			me.val(me.attr("defval")).addClass(CKM.default_value_class);
	}).blur();

	var box;
	$("form td a").click(function(){
		if (!box)
			box = new $.msgBox(this.innerHTML.replace(":", ""), $("#form .pop").show());
		else
			box.show();
		return false;
	}).not("a[title]").each(function(){
		$(this).attr("title", "What is unsecured debt?").Tooltip({showURL: false, extraClass: "small"});
	});

	$("#fb a").not("a[target]").unbind().click(function(){ return false; }).Tooltip({showURL: false, extraClass: "small"});
	
	$("a[href$='privacy.aspx']").click(function(){
		var leftPos = 0;
		var topPos = 40;
		if (screen) {
			leftPos = (screen.width / 2) - 300;
			topPos = (screen.height / 2) - 200;
		}
		window.open("privacy.aspx", "privacy", "status=1,height=400,width=600,resizable=0,scrollbars=1,left="+leftPos+",top="+topPos);
		return false;
	});
});
