/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

//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; 
 } 
}
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};


function runFlash()
{
	if(typeof sIFR == "function"){
		//sIFR.replaceElement("#bannerLanding_tagline p", named({sFlashSrc: "flash/myriad_pro.swf", sColor: "#ffffff", sWmode: "transparent"}));
		//sIFR.replaceElement("#header_sitename", named({sFlashSrc: "flash/gill_sans_f8.swf", sColor: "#003038", sWmode: "transparent"}));
	};
	var so = new SWFObject("includes/flash/home_banner.swf", "flash_area", "680", "190", "8", "#ffffff");
	so.addParam("wmode", "transparent");
	if(document.getElementById("flash_b")) { so.write("flash_b"); }

	var so_test = new SWFObject("includes/flash/kite680-190-b.swf", "flash_area", "680", "190", "8", "#ffffff");
	so_test.addParam("wmode", "transparent");
	if(document.getElementById("flash_b2")) { so_test.write("flash_b2"); }

}

function hoverCheck ()
{
	try {
		var sfEls = document.getElementById("mainContent").getElementsByTagName("ul");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() { this.className+=" sfhover"; }
			sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); }
		}
	}
	catch(e) { }
}

function showHideTab (x)
{
		var getDiv = document.getElementById(x);
		getDiv.style.display = 'block';
		var getAllDivs = getElementsByClassName('', 'div', 'document');
		for(var i = 0; i < test; i++)
		{

			test[i].style.display = 'none';
		}
}

function setSubnavHeight()
{
	try 
	{	// Only run if the wrapper is found & the browser is IE6
		if(document.getElementById("textContentWrapper") && BrowserDetect.browser == "Explorer" && BrowserDetect.version == "6" ) {
			var getContent = document.getElementById("textContentWrapper").offsetHeight;
			document.getElementById("subnavigation_wrapper").style.height= getContent;
		}
	}
	catch(e) { }
}

function showHide()
{
	if(document.getElementById("showHide").style.display == "none") { document.getElementById("showHide").style.display = "block"; document.getElementById("showHidePara").style.display = "none"; }
}


function initPage()
{
	runFlash();
	BrowserDetect.init();
	setSubnavHeight();
	/*
	if(document.getElementById("showHide") && document.getElementById("formVisible") ) { document.getElementById("showHide").style.display = "none"; }
	else { 
		if(document.getElementById("showHidePara")) { document.getElementById("showHidePara").style.display = "none";  }
	}
	*/
}

addEvent(window, 'load', initPage);
//if (window.attachEvent) window.attachEvent("onload", hoverCheck);
// An IE only onload event (there's no need to use the custom function as the li:hover state works with FF / IE7



jQuery(document).ready(function() 
{
	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(); });

	// "Type of Account" Show & Hide on Step 1
	// ----- For page loads & where the account is preselected in a query string -----
	//switch(jQuery(".typeAccShowHideSelect option:selected").val())
	//{
	//	case "1 Month":
	//		jQuery("#currency_0").remove();
	//		jQuery(".typeAccShowHideDiv").show(); break;
	//	case "3 Month":
	//		jQuery(".typeAccShowHideDiv").show(); break;
	//	case "6 Month":
	//		jQuery(".typeAccShowHideDiv").show(); break;
	//	case "1 Year":
	//		jQuery(".typeAccShowHideDiv").show(); break;
	//	case "2 Year":
	//		jQuery(".typeAccShowHideDiv").show(); break;
	//	case "3 Year":
	//		jQuery(".typeAccShowHideDiv").show(); break;
	//	default:
	//		jQuery(".typeAccShowHideDiv").hide(); break;
	//}
	
	// ----- For when the user changes the account type in the dropdown -----
	//var euroString = "<option id=\"currency_0\" value=\"Euro\" selected=\"selected\">Euro</option>";
	//jQuery(".typeAccShowHideSelect").change( function(){ 
	//	switch(jQuery("option:selected", this).val())
	//	{
	//		case "1 Month":
	//			jQuery("#currency_0").remove();
	//			jQuery(".typeAccShowHideDiv").show(); break;
	//		case "3 Month":
	//			if(jQuery("#currency_0").length == 0) jQuery(".typeAccShowHideDiv option:first").before(euroString); jQuery("#currency_0").focus(); 
	//			jQuery(".typeAccShowHideDiv").show(); break;
	//		case "6 Month":
	//			if(jQuery("#currency_0").length == 0) jQuery(".typeAccShowHideDiv option:first").before(euroString);
	//			jQuery(".typeAccShowHideDiv").show(); break;
	//		case "1 Year":
	//			if(jQuery("#currency_0").length == 0) jQuery(".typeAccShowHideDiv option:first").before(euroString);
	//			jQuery(".typeAccShowHideDiv").show(); break;
	//		case "2 Year":
	//			if(jQuery("#currency_0").length == 0) jQuery(".typeAccShowHideDiv option:first").before(euroString);
	//			jQuery(".typeAccShowHideDiv").show(); break;
	//		case "3 Year":
	//			if(jQuery("#currency_0").length == 0) jQuery(".typeAccShowHideDiv option:first").before(euroString);
	//			jQuery(".typeAccShowHideDiv").show(); break;
	//		default:
	//			if(jQuery("#currency_0").length == 0) jQuery(".typeAccShowHideDiv option:first").before(euroString);
	//			jQuery(".typeAccShowHideDiv").hide(); break;
	//	}
	//});

	
}); // END jQuery(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
	
	jQuery(".showhide_wrapper").css("display", "none");
	jQuery(".showhide").click(
		function() { 
			jQuery(this).toggleClass("s_closed");
			jQuery(this).children(".showhide_wrapper").slideToggle(300); 
		}
	);
		
	
	// 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();
		}
    });
	
    

}

				