var val;

//----------------------------------------------------------------------------------
//ORGANISATION TYPE
//----------------------------------------------------------------------------------
var type1 = new Array("capa19", "capa1","capa2", "capa10", "capa12","capa15","capa16","capa17","capa18"); 
//Asset Manager

var type2 = new Array("capa19", "capa2","capa3", "capa4", "capa6","capa8","capa9","capa10","capa11","capa12","capa13","capa14","capa15","capa16","capa17","capa18"); 
//Custodian or Third Party Fund Administrator

var type3 = new Array("capa19",  "capa6","capa7", "capa9","capa16","capa17","capa18"); 
//Financial Planner / Dealer Group

var type4 = new Array("capa19", "capa1","capa2", "capa4", "capa6","capa8","capa9","capa10","capa12","capa13","capa14","capa16","capa17","capa18"); 
//Fund of Hedge Fund or Private Equity Manager

var type5 = new Array("capa19", "capa1","capa4", "capa11", "capa12","capa13","capa14","capa16","capa17","capa18"); 
//Industry Fund 

var type6 = new Array("capa19", "capa1","capa2", "capa3", "capa4", "capa5", "capa6", "capa7", "capa8","capa11","capa12","capa13","capa14","capa16","capa17","capa18"); 
//Life Company

var type7 = new Array("capa19", "capa1","capa2", "capa4", "capa8","capa10","capa12","capa13","capa14","capa16","capa17","capa18"); 
//Multi-Manager

var type8 = new Array("capa19", "capa1","capa2", "capa4","capa5", "capa6","capa7", "capa8","capa10","capa12","capa14","capa16","capa17","capa18"); 
//Offshore Fund Distributor

var type9 = new Array("capa19","capa4", "capa6","capa7", "capa9","capa12","capa13","capa14", "capa16","capa17","capa18"); 
//Platform or Wrap Operator

var type10 = new Array( "capa6","capa7", "capa9", "capa16","capa17","capa18","capa19"); 
//Private Wealth / Private Bank

var type11 = new Array("capa19", "capa1","capa4", "capa11", "capa12","capa13","capa14","capa16","capa17","capa18"); 
//Public Sector Fund

var type12 = new Array("capa19", "capa6","capa7", "capa9","capa16","capa17","capa18"); 
//Retail Bank

var type13 = new Array("capa1","capa16","capa18"); 
//Trustee Company

//----------------------------------------------------------------------------------
//OPERATION ACTIVITY
//----------------------------------------------------------------------------------

var activity1 = new Array("capa12", "capa13", "capa14", "capa18");
//Accounting or statutory reporting

var activity2 = new Array("capa8","capa9","capa18");
//Allocate and settle external fund distributions to investors

var activity3 = new Array("capa4","capa18");
//Allocate cash or rebalance funds

var activity4 = new Array("capa12","capa13","capa18");
//Calculate capital gains and losses

var activity5 = new Array("capa11","capa12", "capa18");
//Calculate daily tax accruals

var activity6 = new Array("capa7","capa18");
//Calculate fee rebates and invoice fund managers

var activity7 = new Array("capa8","capa10","capa12","capa18");
//Calculate fund distributions

var activity8 = new Array("capa2", "capa18");
//Calculate NAVs and unit prices

var activity9 = new Array("capa19", "capa1","capa17", "capa18");
//Check NAV and unit price accuracy from fund administrators

var activity10 = new Array("capa19", "capa2","capa3","capa17","capa18");
//Manage NAV production and accuracy

var activity11 = new Array("capa1","capa18");
//Monitor fund administrator and service provider accuracy and timeliness

var activity12 = new Array("capa2","capa4","capa5","capa6","capa7","capa8","capa11","capa12","capa13","capa14","capa18");
//Operate unit linked investment structures

var activity13 = new Array("capa6","capa18");
//Place and confirm external fund orders on behalf of investors

var activity14 = new Array("capa8","capa9","capa10","capa12","capa18");
//Process income distributions within a interfund structure

var activity15 = new Array("capa19", "capa17","capa18");
//Reconcile positions trades or bank statements

var activity16 = new Array("capa19", "capa1","capa17","capa18");
//Reconcile valuations from fund administrators to your back office

var activity17 = new Array("capa15","capa18");
//Report performance and attribution

var activity18 = new Array("capa15","capa16","capa18");
//Report unit price or NAV performance


$(document).ready(function(){
	var firsttime = $("#firsttime").html();
	$('#select-capabilities li').click(function(){
		if($(this).hasClass("selected")) return;
		val = $(this).attr("name");
		if(!firsttime){
			$('#result').slideUp(500, function(){
				$("#the_title").html("");
				$("#recommended-solutions").html("");	
				$.post("/wp-content/themes/milestonegroup/getSolutionName.php", { clickedValue: val },      
					function(data){				
						$("#the_title").html(data);
						$.post("/wp-content/themes/milestonegroup/getSolutionTag.php", { clickedValue: val },      
							function(data){				
								$("#recommended-solutions").html(data);	
								$('#result').slideDown(500, function(){
									$("#result").show();
								});
							}, "text"
						);
					}, "text"
				);
			});
		}
		else {
			firsttime = false;
			$.post("/wp-content/themes/milestonegroup/getSolutionName.php", { clickedValue: val },      
				function(data){				
					$("#the_title").html(data);
					
					$.post("/wp-content/themes/milestonegroup/getSolutionTag.php", { clickedValue: val },      
						function(data){				
							$("#recommended-solutions").html(data);	
						}, "text"
					);
					$('#result').slideDown(500, function(){
						$("#result").show();
					});
				}, "text"
			);
		}
		$("#select-capabilities .selected").removeClass("selected");
		$(this).addClass("selected");
	});
	
	$("#banner-navigation li a").hover(
	function() {
		if($(this).text() == "About Us")
		{
			$("#banner-head").removeClass("banner-large-whychooseus");
			$("#banner-head").removeClass("banner-large-oursolutions");
			$("#banner-head").addClass("banner-large-aboutus");
		}
		else
		{
			if($(this).text() == "Our Solutions")
			{
				$("#banner-head").removeClass("banner-large-whychooseus");
				$("#banner-head").removeClass("banner-large-aboutus");
				$("#banner-head").addClass("banner-large-oursolutions");
			}
			else
			{
				$("#banner-head").removeClass("banner-large-oursolutions");
				$("#banner-head").removeClass("banner-large-aboutus");
				$("#banner-head").addClass("banner-large-whychooseus");
			}
		}
	});
	var shownDivId = "";
	$(".solution-panel-default").hover(
		function() {
			$("#" + shownDivId).hide();
			var id = $(this).attr("class").split(" "); 
			shownDivId = id[id.length-1];
			$("#" + shownDivId).show();
			var url = location.href.substr(0, location.href.lastIndexOf("/"));
			url = location.href.substr(0, url.lastIndexOf("/"));
			$("#" + shownDivId).click(function() { window.location=url+"/solutions/"+shownDivId;});
		}, 
		function(){}
	);
	
	$("#main").hover(
		function() {}, 
		function(){$("#" + shownDivId).hide();}
	);
	
	
	var target;
	var classes;
	if($(".selected").attr("name") != null){
		if($(".selected").attr("name").indexOf("activity") == -1){
			eval('classes = type' + $(".selected").attr("name"));
		}
		else {
			eval('classes =' + $(".selected").attr("name"));
		}
		if(!firsttime){
			$('#step-2').slideUp(500, function(){		
				$(".group0").hide();
				$("#the_title").html("");
				$("#recommended-solutions").html("");	
				for(i=0; i < classes.length; i++){ target = classes[i]; $("."+target).show();	}			
				$('#step-2').slideDown(500);
			});
		}else {
			firsttime = false;
			$("#recommended-solutions").html("");	
			$(".group0").hide();
			for(i=0; i < classes.length; i++){target = classes[i]; $("."+target).show();}			
			$('#step-2').slideDown(500);
		}
	}
	
	$(".operational-activity").click(function(){
		if($(this).hasClass("selected")) return;
		$(".operational-activity.selected").removeClass("selected");
		$("#select-capabilities .selected").removeClass("selected");
		$(this).addClass("selected");
		var target;
		var classes;
		eval('classes = ' + $(this).attr("name"));

		if(!firsttime){
			$('#step-2').slideUp(500, function(){	
				$(".group0").hide();
				$("#the_title").html("");
				$("#recommended-solutions").html("");
				for(i=0; i < classes.length; i++){ target = classes[i]; $("."+target).show();	}			
				$('#step-2').slideDown(500);
			})
		}
		else {
			firsttime = false;
			$("#recommended-solutions").html("");	
			$(".group0").hide();
			for(i=0; i < classes.length; i++){target = classes[i]; $("."+target).show();}			
			$('#step-2').slideDown(500);
		}
		$("#result").slideUp(250);	
	});

	$(".organisation-type").click(function(){
		if($(this).hasClass("selected")) return;
		$(".organisation-type.selected").removeClass("selected");
		$("#select-capabilities .selected").removeClass("selected");
		$(this).addClass("selected");
		var target;
		var classes;
		eval('classes = type' + $(this).attr("name"));
	
		if(!firsttime){
			$('#step-2').slideUp(500, function(){		
				$(".group0").hide();
				$("#the_title").html("");
				$("#recommended-solutions").html("");	
				for(i=0; i < classes.length; i++){ target = classes[i]; $("."+target).show();	}			
				$('#step-2').slideDown(500);
			});
		}else {
			firsttime = false;
			$("#recommended-solutions").html("");	
			$(".group0").hide();
			for(i=0; i < classes.length; i++){target = classes[i]; $("."+target).show();}			
			$('#step-2').slideDown(500);
		}
		$("#result").slideUp(250);	
	});

	$("#result").hide();
	
	$(".clearselection").click(function(){
		firsttime = true;
		$("#result").slideUp(250);
		$("#step-2").slideUp(250);
		$(".group0").hide();
		$(".selected").removeClass("selected");
	});
		
	$("#organisationtypeselect").hide();
	$("#organisationtypeselect2").hide();
	$("#operationalactivityselect").hide();
	$("#operationalactivityselect2").hide();
	
	$("#organisation-type-btn").click(function(){
		$("#organisationtypeselect").show();
		$("#organisationtypeselect2").show();
		$("#operationalactivityselect").hide();
		$("#operationalactivityselect2").hide();
	});
	
	$("#operational-activities-btn").click(function(){
		$("#organisationtypeselect").hide();
		$("#organisationtypeselect2").hide();
		$("#operationalactivityselect").show();
		$("#operationalactivityselect2").show();
	});
			
	$("#organisationtypeselect").change(function(){
		if($("#organisationtypeselect").val() != 0){
			$("#gotosolution").attr("action", "../solution-finder-organisation-type");
			$("#gotosolutiontext").val($("#organisationtypeselect").val());
			$("#gotosolution").submit();
		}
	});
	
	$("#organisationtypeselect2").change(function(){
		if($("#organisationtypeselect2").val() != 0){
			$("#gotosolution").attr("action", "index.php/solution-finder-organisation-type");
			$("#gotosolutiontext").val($("#organisationtypeselect2").val());
			$("#gotosolution").submit();
		}
	});
	
	$("#operationalactivityselect").change(function(){
		if($("#operationalactivityselect").val() != 0){
			$("#gotosolution").attr("action", "../solution-finder-operational-activity");
			$("#gotosolutiontext").val($("#operationalactivityselect").val());
			$("#gotosolution").submit();
		}
	});
	
	$("#operationalactivityselect2").change(function(){
		if($("#operationalactivityselect2").val() != 0){
			$("#gotosolution").attr("action", "index.php/solution-finder-operational-activity");
			$("#gotosolutiontext").val($("#operationalactivityselect2").val());
			$("#gotosolution").submit();
		}
	});
	
	var loc = window.location.href;
	$(".secondary-menu li a").each(function(){
		var link = $(this).first().attr("href");
		if(loc.charAt(loc.length-1) != "/"){loc = loc + "/";}
		if(link == loc) {
			$(".selected").removeClass("selected");
			$(this).addClass("selected");
			return false;
		}

	}, secondarySearch());
	
	function secondarySearch() {
		var Urltabs = loc.split("/");
		if(Urltabs[Urltabs.length - 2] == "news" || Urltabs[Urltabs.length - 2] == "news-archives") return;
		$(".secondary-menu li a").each(function(){
			var link = $(this).first().attr("href");
			var type = Urltabs[Urltabs.length - 3];
			if(type == "index.php"){
				type = Urltabs[Urltabs.length - 2];
			}
			if(link.indexOf(type) != -1) {
				$(".selected").removeClass("selected");
				$(this).addClass("selected");
				return false;
			}
		});
	}
	
	
	$("#menu-primary li a").each(function() {
		var link = $(this).first().attr("href");
		var loc = window.location.href;
		if(loc.indexOf("our-solutions") == -1)
			loc = loc.replace(/solutions/g, "our-solutions");
		loc = loc.replace(/\/modules\//g, "\/capabilities\/");
		loc = loc.replace(/\/case-studies\//g, "\/news\/");
		loc = loc.replace(/\/press-releases\//g, "\/news\/");
		loc = loc.replace(/\/events\//g, "\/news\/");
		loc = loc.replace(/\/articles\//g, "\/news\/");
		loc = loc.replace(/\/thank-you\//g, "\/contact-us\/");
		if(loc.indexOf(link) > -1) {
			$(".selected2").removeClass("selected2");
			$(this).addClass("selected2");
		}
	});
	
});

function setCookie(c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value+";path=/";
}

function getCookie(c_name) {
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)	{
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name) {
			return unescape(y);
		}
	}
}

function checkCookie(t) {
	setCookie("testCookie","1",1);
	var testCooke = getCookie("testCookie");
	if (testCooke==null || testCooke=="") {alert("Please enable cookies to download"); return;}
	
	var MGCookie=getCookie("MGCookie2");
	if (MGCookie!=null && MGCookie!="") {
		window.open("http://www.milestonegroup.com.au/wp-content/themes/milestonegroup/downloadformAuto.php?filename="+t,  "", "height=200,width=500,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no");
	}
	else {
		window.open("http://www.milestonegroup.com.au/wp-content/themes/milestonegroup/downloadform.php?filename="+t, "", ",toolbar=0,menubar=0,resizable=0,location=0,width=500,height=280");
	}
}

function checkCookieLP(t, title) {
	setCookie("testCookie","1",1);
	var testCooke = getCookie("testCookie");
	if (testCooke==null || testCooke=="") {alert("Please enable cookies to download"); return;}
	
	var MGCookieLP=getCookie("MGCookie2");
	if (MGCookieLP!=null && MGCookieLP!="") {
		window.open("http://www.milestonegroup.com.au/wp-content/themes/milestonegroup/lp-downloadformAuto.php?filename="+t+"&title="+title,  "", "height=200,width=500,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no");
	}
	else {
		window.open("http://www.milestonegroup.com.au/wp-content/themes/milestonegroup/lp-downloadform.php?filename="+t+"&title="+title, "", ",toolbar=0,menubar=0,resizable=0,location=0,width=500,height=280");
	}
}

function downloadSubmit() {
	var error = 0;		
	if($("#first_name").val() == null || $("#first_name").val() == ""){ error++; }
	if($("#last_name").val() == null || $("#last_name").val() == ""){ error++; }
	if($("#country").val() == ""){ error++; }
	if($("#company").val() == null || $("#company").val() == ""){ error++; }
	var atpos= $("#email").val().indexOf("@");
	var dotpos= $("#email").val().lastIndexOf(".");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=$("#email").val().length){ error++; }
	
	if(error != 0) { 
		$("#download-error").text("Please fill all fields");
		return false;
	}
	var MGCookieLP=getCookie("MGCookie2");
	
	if (MGCookieLP==null || MGCookieLP=="") {
		setCookie("MGCookie2",$("#first_name").val()+"\:"+$("#last_name").val()+"\:"+$("#email").val()+"\:"+$("#company").val()+"\:"+$("#country").val(),365);
	}
	
	setTimeout("return true;", 2000);
}

