// JavaScript Document

	
$(document).ready(function() {

 //  $("#header li a").each(function(i,n)
//   { 
//   		h = "?p=" + $(n).attr("href");	
//		$(n).attr("href",h);
//   });
//   $(".footer li a").each(function(i,n)
//   { 
//   		h = "?p=" + $(this).attr("href");	
//		h = h.replace("http://www.willowsfinance.co.uk/","");
//		$(n).attr("href",h.slice(0, -1));
//   });
//   $("#breadcrumbs li a").each(function(i,n)
//   { 
//   		h = "?p=" + $(n).attr("href");		
//		h = h.replace("http://www.willowsfinance.co.uk/","");
//		$(n).attr("href",h.slice(0, -1));
//   });
//   
//   $("#main a").not("a[href^=http]").not("a[href^=/UserFiles]").not("a[href^=mailto]").each(function(i,n)
//   { 
//   		h = "?p=" + $(n).attr("href");		
//		h = h.replace("http://www.willowsfinance.co.uk/","");
//		$(n).attr("href",h.slice(0));
//   });





	$("input").click(function() {
		var  initialval =  $(this).attr("default");
		if ($(this).val()==initialval)
			$(this).val("");
	});
	$("input").blur(function() {
		var initialval =  $(this).attr("default");
		if ($(this).val()=="")
			$(this).val(initialval);
	});
	
	$("#logo").click (function() { window.location = "http://www.willowsfinance.co.uk/"; });
	

	// form handling
	          
			var callback = { 
				success:   showResponse,  // post-submit callback 
				dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
			}; 

			 var redirect = { 
				success:   doRedirect,  // post-submit callback 		 
				dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
			}; 
	
			function showResponse(responseText, statusText, xhr, $form)  { 			 
				$(responseText.div).replaceWith("<p>"+responseText.response+"</p>");		
			} 
			
			function doRedirect(responseText, statusText, xhr, $form)  { 	
			//	alert("[TENG_BaseRef]"+responseText.response);	
				if (responseText.response.search(/unsecured/i) > 0) {
					window.open(responseText.response,'mywindow') ;
				}
				else {
				window.location=responseText.response;
				}
			} 
			
			$('#introducer_pack').ajaxForm(function(callback) {});	
            $('#apply_online').ajaxForm(function(redirect) {});			
			$('#request_callback').ajaxForm(function(callback) {});

			$("#btn_introducerpack").click(function() { $("#introducer_pack").ajaxSubmit(callback); return false;});			
			$("#btn_applyonline").click(function() { $("#apply_online").ajaxSubmit(redirect); return false;});
			$("#btn_callback").click(function() 	{ $("#request_callback").ajaxSubmit(callback); return false; });
			


});
