
function xtractFile(data){
var m = data.match(/(.*)\/([^\/\\]+)(\.\w+)$/);
if(m == null) { m = "null"; }
return {path: m[1], file: m[2], extension: m[3]}
}

//customised addEvent function for having a proper onload function call.
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
/*
 * 
 * 
 * Animate the hompage panels - NB NB NB NB
 * As these elements are being "faded in", the elements have to be initially disabled / hidden. To make sure that
 * those with javaScript disabled can still see the buttons, the CSS hiding them initially is called from a javaScript
 * function (think about it), in the homepage's master template.
 * 
 * 
 * */
jQuery(window).load(function(){
	jQuery(".home_prod_1_learnmore a, .home_prod_2_learnmore a").animate({ opacity : 0}, 0);
	jQuery(".home_prod_1_img, .home_prod_2_img").animate({ opacity : 0}, 0);

	jQuery(".home_prod_1_learnmore a, .home_prod_2_learnmore a").css( { "z-index" : 9999, "position" : "relative", "top" : "30px" } ).animate({ 
		opacity: 1, top: "0px"
      }, 1250, "swing" );
	jQuery(".home_prod_1_img, .home_prod_2_img").animate({ 
		opacity: 1
      }, 1500, "linear" );

});

jQuery(document).ready(function(){
	// Apply Tab functionality.
	jQuery("#ps_home_tabs").tabs();
	jQuery("#ps_home_tabs .ui-tabs-panel li:odd").addClass("zebra_row_1");
	jQuery("#dmcie_tabs").tabs();


	jQuery(".maincontent li").each(function(i){
		var jObj = jQuery(this);
		jQuery(this).find(".faq_toggle_question").click(function(){ jObj.find(".faq_toggle_answer").slideToggle(); });
	});

	// ============ Turn links into curve-cornered buttons (with the help of spans & CSS)
	var getButton_width = 0;
	var convertHTML = ".misc_submit";
	jQuery(convertHTML).each(function(){
		getButton_width = jQuery(this).width();
		jQuery(this).addClass("but_misc").css({ "width" : (getButton_width + 30) });
		jQuery(this).wrapInner("<span class=\"but_misc_text\"></span>")
		jQuery(this).prepend("<span class=\"but_misc_corner but_corner_l\"></span>");
		jQuery(this).append("<span class=\"but_misc_corner but_corner_r\"></span>");
		jQuery(this).wrapInner("<span class=\"but_misc_text_wrapper\"></span>");

	});
	
	// ============ Alternate: Apply a right-pointing version
	getButton_width = 0;
	convertHTML = ".misc_submit_r";
	jQuery(convertHTML).each(function(){
		getButton_width = jQuery(this).width();
		jQuery(this).addClass("but_misc_r").css({ "width" : (getButton_width + 30) });
		jQuery(this).wrapInner("<span class=\"but_misc_text\"></span>")
		jQuery(this).prepend("<span class=\"but_misc_corner but_corner_l\"></span>");
		jQuery(this).append("<span class=\"but_misc_corner but_corner_r\"></span>");
		jQuery(this).wrapInner("<span class=\"but_misc_text_wrapper\"></span>");

	});
	
	jQuery(".search_input").focus(function(){
		jQuery(".search_input").attr("value") == "Enter your search terms" ? jQuery(".search_input").attr("value", "") : null;	
	});

	jQuery(".fadeHover").hover(
		function(){ jQuery(this).fadeTo("fast", 0.5); },
		function(){ jQuery(this).fadeTo("fast", 1.0); }
	);

	// (Onload) Check for any validation warnings that are visible and highlight the associated row.
	jQuery(".warn_validation").each( function() { jQuery(this).css("visibility") != "hidden" ? jQuery(this).parent(".form_rowWrapper").addClass("error_row") : null; } );
	
	// Check for any visible error messages when the submit button is clicked.
	var errorsVisible = 0;
	var scrollTo = 0;
	jQuery(".next_step").bind("click", function(i)
	{ 
	    jQuery(".warn_validation").each(function(){
			//alert(jQuery(this).css("visibility"));
			if(jQuery(this).css("visibility") != "hidden")
			{
				errorsVisible == 0 ? scrollTo = jQuery(this).offset().top : null; 
				jQuery(this).parents(".form_rowWrapper").addClass("error_row");
				errorsVisible ++;
			}
		});
		if(errorsVisible > 0 ){ errorsVisible=0; jQuery("html, body").animate( { scrollTop: scrollTo }, "normal");  }
	});

	jQuery(".form_rowWrapper input, .form_rowWrapper textarea, .form_rowWrapper select").change(function() {
		jQuery(this).parents(".form_rowWrapper").removeClass("error_row");
	});


	if (document.getElementById("form_showHide") && document.getElementById("formVisible")) 
			{ jQuery("#form_showHide").hide();}
	else 	{ jQuery("#form_showHidePara").hide(); }
	 
	jQuery("#form_showHidePara").click(function(){
		jQuery(this).hide();
		jQuery("#form_showHide").show();
	});
	
	jqueryReady();
	
	// "Title" Show & Hide on Step 2
	jQuery(".titleShowHideSelect option:selected").val() == "Other" ? jQuery(".titleShowHideDiv").show() : jQuery(".titleShowHideDiv").hide();
	jQuery(".titleShowHideSelect").change( function(){ jQuery("option:selected", this).val() == "Other" ? jQuery(".titleShowHideDiv").show() : jQuery(".titleShowHideDiv").hide(); });

	// "How Did you Hear of Us" Show & Hide on Step 2
	jQuery(".hearOfShowHideSelect option:selected").val() == "Other" ? jQuery(".hearOfShowHideDiv").show() : jQuery(".hearOfShowHideDiv").hide();
	jQuery(".hearOfShowHideSelect").change( function(){ jQuery("option:selected", this).val() == "Other" ? jQuery(".hearOfShowHideDiv").show() : jQuery(".hearOfShowHideDiv").hide(); });

	
	
}); // End Document.ready


function jqueryReady()
{
    var i = 0;
	jQuery(".appform_row_wrapper").each( function(i){
		i % 2 == 0 ? jQuery(this).addClass("zebra_row_0") : jQuery(this).addClass("zebra_row_1");
		i++;
	});
	
	jQuery(".appform_row_wrapper input").focus( function() 
		{ jQuery(this).parents(".appform_row_wrapper").addClass("row_hover") }
	).blur( function()
		{ jQuery(this).parents(".appform_row_wrapper").removeClass("row_hover") }
	);
	jQuery(".appform_row_wrapper select").focus( function() 
		{ jQuery(this).parents(".appform_row_wrapper").addClass("row_hover") }
	).blur( function()
		{ jQuery(this).parents(".appform_row_wrapper").removeClass("row_hover") }
	);
	
	jQuery(".prev_step, .next_step, .wizard_download_options img, .wizard_download_options input").hover( function(){ jQuery(this).fadeTo("fast", 0.5); }, function(){ jQuery(this).fadeTo("fast", 1.0); } );
	
	// show / hide toggle for step 3
	
	var showHideCount = 0;
	jQuery(".showhide_wrapper").each(function(){
		jQuery(this).css("display", "none");
		jQuery(this).parent().addClass("s_closed showhidepanel_"+ showHideCount);
		showHideCount++;
	});
	// Show the first step - step 1
	jQuery(".showhidepanel_0").toggleClass("s_closed");
	jQuery(".showhidepanel_0").children(".heading").addClass("hithere"); 
	jQuery(".showhidepanel_0").children(".showhide_wrapper").slideToggle(500); 
	// If user clicks on a tab ...
	jQuery(".showhide").click( function() {
		if($(this).hasClass("s_closed") == true)
		{
			$(".showhide").each( function() { $(this).addClass("s_closed"); $(this).children(".showhide_wrapper").slideUp(500); } );
			$(this).removeClass("s_closed");
			$(this).children(".showhide_wrapper").slideToggle(500); 
		}
		else {  			
			$(this).addClass("s_closed");
			$(this).children(".showhide_wrapper").slideToggle(500);  
		}
	} );	
		
	
	// Apply opacity to AJAX loading
	jQuery(".progress_overlay").width(jQuery("#inner_wrapper").innerWidth());
	jQuery(".progress_overlay").height(jQuery("#inner_wrapper").innerHeight());
	jQuery(".progress_overlay").fadeTo("fast", 0.5);
	jQuery(".progress_overlay").bgiframe( { height: jQuery("#inner_wrapper").innerHeight(), width: jQuery("#inner_wrapper").innerWidth() } );
	
	$('.progress').css('top', $(this).scrollTop() + ($(this).height() / 2) + "px");
	$(window).scroll(function() {
		$('.progress').css('top', $(this).scrollTop() + ($(this).height() / 2) + "px");
	});

	
	/* ---------------------------------------------- Applicant 2 Warning */
	//jQuery(".applicant2_highlight").fadeOut("slow");
	
	/* ---------------------------------------------------------------------------------------------------- ERROR MESSAGE EVENT MONITORING */
	
	// (Onload) Check for any validation warnings that are visible and highlight the associated row.
	jQuery(".warning_popup").each( function() { jQuery(this).css("visibility") != "hidden" ? jQuery(this).parent(".appform_row_wrapper").addClass("error_row") : null; } );
	
	// Check for any visible error messages when the submit button is clicked.
	var errorsVisible = 0;
	var scrollTo = 0;
	jQuery(".next_step").bind("click", function(i)
	{ 
	    jQuery(".warning_popup").each(function(){
			//alert(jQuery(this).css("visibility"));
			if(jQuery(this).css("visibility") != "hidden")
			{
				errorsVisible == 0 ? scrollTo = jQuery(this).offset().top : null; 
				jQuery(this).parents(".appform_row_wrapper").addClass("error_row");
				errorsVisible ++;
			}
		});
		if(errorsVisible > 0 ){ errorsVisible=0; jQuery("html, body").animate( { scrollTop: scrollTo }, "normal");  }
	});
	
	// If the user has changed any values in the input / select fields, check for any visible error messages.

	
	jQuery(".appform_row_wrapper input, .appform_row_wrapper select").change(function() {
		jQuery(this).parents(".appform_row_wrapper").removeClass("error_row");
	});
		
		
	jQuery(".form_row_other input, .form_row_other2 input").change(function() {
		jQuery(this).next(".warning_popup").toggleClass("hide_warning_popup");
	});

	jQuery(".numonly").change(function(){
		re = /[a-z]/ig;
		var str = jQuery(this).val();
		str.match(re) != null ? jQuery(this).parents(".appform_row_wrapper").addClass("error_row") : null; 
	});


	/* Fix the issue of IE6 showing <select> above the warning pop-up */
	jQuery(".warning_popup").bgiframe({height: 34});
	
	/* ---------------------------------------------------------------------------------------------------- ERROR MESSAGE EVENT MONITORING */

	/* ---------------------------------------------------------------------------------------------------- STEP 2 HELP TEXT TOGGLE - SHOW / HIDE */
	jQuery(".showhide_help").focus(
		function()
		{
			jQuery(".help_show_1").fadeOut("fast", function(){ jQuery(".help_show_2").fadeIn("fast"); } );
		}
	);
	jQuery(".showhide_help").blur(
		function()
		{
			jQuery(".help_show_1").fadeIn("fast", function() { jQuery(".help_show_2").fadeOut("fast");} );
		}
	);
	
	/* ---------------------------------------------------------------------------------------------------- STEP 2 SUPERSCRIPT HOVER FUNCTION */
	jQuery("span.superscript").each(function(i){
		jQuery(this).children(".superscript_note").css({"left" : (jQuery(this).position().left + 15) });
	});
	jQuery("span.superscript").hover(
		function(e) { jQuery(this).children(".superscript_note").fadeIn("fast"); },
		function(e) { jQuery(this).children(".superscript_note").fadeOut("fast"); }
	);
	
	jQuery(".dob_1").attr("autocomplete", "off");
   	jQuery(".dob_1").keyup(function() {
		if (jQuery(this).val().length == 2)
		{
			jQuery(this).blur();
			jQuery(".dob_2").focus();
		}
    });
	jQuery(".dob_2").attr("autocomplete", "off");
   	jQuery(".dob_2").keyup(function() {
		if (jQuery(this).val().length == 2)
		{
			jQuery(this).blur();
			jQuery(".dob_3").focus();
		}
    });
	jQuery(".dob_3").attr("autocomplete", "off");
   	jQuery(".dob_3").keyup(function() {
		if (jQuery(this).val().length == 4)
		{
			jQuery(this).blur();
			jQuery(".dob_exit").focus();
		}
    });

} // end jqueryReady()

