$().ready(function(){

	var currentPage = window.location.pathname;

	//////////////////////////////////////
	////////// Header Animation //////////
	//////////////////////////////////////

	//$("#header").css({position:"relative", top:-20, opacity: 0});
	//$("#header").animate({top:0, opacity: 1}, {duration: 400, easing: "easeOutQuad"});


	//////////////////////////////////////////
	////////// Page Load Animations //////////
	//////////////////////////////////////////
	
	// subnav
	if (
		   document.title == "GCP | Home"
		|| document.title == "GCP | Our Solutions > Corporations"
		|| document.title == "GCP | Our Advantage > Custom Control"
		|| document.title == "GCP | Our Clients"
		|| document.title == "GCP | Our People > Our History"
		|| document.title == "GCP | News"
		|| document.title == "GCP | Contact > Contact Details"
		|| document.title == "GCP | Privacy Policy"
		|| document.title == "GCP | Terms & Conditions"
		|| document.title == "GCP | Login"
		|| document.title == "GCP | Dasboard"
	)
	{
		$("#subnav ul").css({marginTop:"22px"}).animate({marginTop:"1px"}, 300);
	}

	// body_wrapper, sidebar and sidbox
	
	$("#body").css({opacity:0, position: "relative", left:"-50px"});
	$("#sidebox").css({opacity:0, position: "relative", left: "300px"});
	$("#sidebar_image").css({opacity:0, position: "relative", left: "300px"});
	$("#body_wrapper").css({opacity:0}).animate({opacity:1}, {duration:250, complete:function() {
		$("#body").animate({opacity:1, left:"-10px"}, {duration:250});
		$("#sidebar_image").animate({opacity:1, left:"0px"}, {duration: 300, easing:"easeOutBack", complete:function() {
				$("#sidebox").animate({opacity:1, left:"0px"}, {duration: 300, easing:"easeOutBack"});
		}});		
	}});

	//////////////////////////////////////
	////////// Topnav Animation //////////
	//////////////////////////////////////

	$(".down").css({opacity:0.5});
	$(".down").hover(function(){topnavover(this.id)},function(){topnavout(this.id)});

	function topnavover(id)
	{ 
		$("#"+id).stop().animate({opacity: 1.0},250);
	}
	
	function topnavout(id)
	{
		$("#"+id).stop().animate({opacity: 0.5},250);
	}


	//////////////////////////
	////////// FAQs //////////
	//////////////////////////

	$('.faq_q').click(function (){faq(this)});
	function faq(id)
	{
		$(id).toggleClass("faq_q_down");
		var id = "#"+$(id).attr('id')+"_a";
		$(id).slideToggle(250);
	}
	
	//////////////////////////
	////////// Bios //////////
	//////////////////////////
	
	if(document.title == "GCP | Our People > Senior Executive Team" || document.title == "GCP | Our People > Board of Directors")
	{
		setUpBios();
	}
	function setUpBios()
	{
		$(".bio_body").css({display:"none"});
		
		var doctitle = document.title;
		var h = getElementHeight("bio_links") - 10;

		if(doctitle == "GCP | Our People > Senior Executive Team") {
			var members = new Array("kelms_bio", "rmcmillan_bio", "tshepherd_bio", "phyde_bio", "mcarroll_bio");
			var c = members.length;
		} else if (doctitle == "GCP | Our People > Board of Directors") {
			var members = new Array("rbinyon_bio", "cjrodrigues_bio", "wjhopper_bio", "gbrady_bio", "kelms_bio", "rmcmillan_bio", "tshepherd_bio");
			var c = members.length;
		}
		var heights = new Array();		
		
		for(i=0;i<c;i++) {
			var x = getElementHeight(members[i]);
			heights.push(x);
		}

		var y = Math.max.apply( Math, heights );
	
		if(doctitle == "GCP | Our People > Senior Executive Team")
		{
			$('#kelms_bio').css({display:"", height:h});
			$('#rmcmillan_bio').css({display:"none", height:h});
			$('#tshepherd_bio').css({display:"none", height:h});
			$('#phyde_bio').css({display:"none", height:h});
			$('#mcarroll_bio').css({display:"none", height:h});
		} else if (doctitle == "GCP | Our People > Board of Directors")
		{
			$('#rbinyon_bio').css({display:"", height:h});
			$('#cjrodrigues_bio').css({display:"none", height:h});
			$('#wjhopper_bio').css({display:"none", height:h});
			$('#gbrady_bio').css({display:"none", height:h});
			$('#kelms_bio').css({display:"none", height:h});
			$('#rmcmillan_bio').css({display:"none", height:h});
			$('#tshepherd_bio').css({display:"none", height:h});
		}
		
	}


	$('.bio_link').click(function(){bio(this)});
	
	function bio(id){
		$('.bio_body').hide(0);
		$('.bio_link').css({background:"#FFF"});
		$(id).css({background:"#dbeaf9"});
		var id_body = "#"+$(id).attr('id')+"_bio";
		
		if($(id_body).is(":hidden")) {
			$(id_body).show(0);
		}
	}

	////////////////////////////////
	////////// Login Page //////////
	////////////////////////////////

	hideLoginPassField();
	
	$("#loginform #login_email").blur(function() { validateLoginEmail(); })
	$("#loginform #login_pass").blur(function() { validateLoginPass(); })
	
	$("#loginform #login_submit").click(function() {
		if(validateLoginEmail()=="pending") {
		/* alert(); */
			$("#loginform").attr("action", "/login/activate");
		} else {
			$("#loginform").submit(function(){ return false; });
			submitLogin();
		}
	})

	$("#activateform #login_email").blur(function() { validateLoginEmail2(); })
	$("#activateform #login_newpass").blur(function() { validateLoginNewPass(); })
	$("#activateform #login_newpassagain").blur(function() { validateLoginNewPassAgain(); })
	
	$("#activateform #newpass_submit").click(function() {

		var email = validateLoginEmail2();
		var newpass = validateLoginNewPass();
		var newpassagain = validateLoginNewPassAgain();
		
		//alert(newpassagain);
				
		if(!email || !newpass || !newpassagain)
		{
			$("#activateform").submit(function(){ return false; });
			//$("#activateform").submit();
		}
	})
	
	function showLoginPassField()
	{
		$("#login_pass").css({display: ""});
		$("#login_pass_label").css({display: ""});
		$("#login_pass_msg").css({display: ""});
	}
	function hideLoginPassField()
	{
		$("#login_pass").css({display: "none"});
		$("#login_pass_label").css({display: "none"});
		$("#login_pass_msg").css({display: "none"});
	}
	
	function validateLoginEmail() {
		var loginCheck;
		var val = $("#login_email").val();
		if(val=="")
			{
				$("#login_email_msg").html(inputResponse("This field is required", "error"));
				$("#login_submit").text("Login");
				$("#login_clear").show();
				$("#loginform").attr("action", "/login/auth");
				hideLoginPassField();
				loginCheck = "invalid";
			}
		else 
			{				
				xmlHttp=GetXmlHttpObject()
				if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return }
				var url = "../includes/function_checkLogin.php?e="+val+"&sid="+Math.random();
				xmlHttp.open("GET",url,false);
				xmlHttp.send(null);
				var rt = xmlHttp.responseText;
				
				if(rt=="unknown")
					{
						$("#login_email_msg").html(inputResponse("Unknown User", "error"));
						$("#login_submit").text("Login");
						$("#login_clear").show();
						$("#loginform").attr("action", "/login/auth");
						hideLoginPassField();
						loginCheck = "invalid";
					}
				else if(rt=="staff")
					{
						$("#login_email_msg").html(inputResponse("Okay", "ok"));
						$("#login_submit").text("Login");
						$("#login_clear").show();
						$("#loginform").attr("action", "/login/auth");
						showLoginPassField();
						loginCheck = "valid-staff";
					}
				else if(rt=="investor-active")
					{
						$("#login_email_msg").html(inputResponse("Okay", "ok"));
						$("#login_submit").text("Login");
						$("#login_clear").show();
						$("#loginform").attr("action", "/login/auth");
						loginCheck = "valid-investor";
						showLoginPassField();
					}
				else if(rt=="investor-notactive")
					{
						$("#login_email_msg").html(inputResponse("Account not active", "pending"));
						$("#login_submit").text("Activate Account");
						$("#login_clear").hide();
						$("#loginform").attr("action", "/login/activate");
						hideLoginPassField();
						loginCheck = "pending";
					}
			}
		return loginCheck;
	}

	function validateLoginPass()
	{
		var passCheck;
		var val = $("#login_pass").val();
		if(val=="")
			{
				$("#login_pass_msg").html(inputResponse("Password is required", "error"));
				$("#loginform").attr("action", "/login/auth");
				passCheck = false;
			}
		else
			{
				$("#login_pass_msg").html(inputResponse("Okay", "ok"));
				$("#loginform").attr("action", "/login/auth");
				passCheck = true;
			}
		return passCheck;
	}

	function submitLogin()
	{
		var email = $("#login_email").val();
		var pass = $("#login_pass").val();
		var type = validateLoginEmail();
		var passCheck = validateLoginPass();

		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return }
		var url = "../includes/function_submitlogin.php?email="+email+"&pass="+pass+"&type="+type+"&sid="+Math.random();
		xmlHttp.open("GET",url,false);
		xmlHttp.send(null);
		var rt = xmlHttp.responseText;

		if (rt=="loginok")
			{
				setTimeout( "window.location = '/dashboard'", 1);
			}
		else if (rt=="badpass")
			{
				$("#login_pass_msg").html(inputResponse("Incorrect Password", "error"));
			}
	}
	
	function validateLoginEmail2() {
		var response =false;
		var val = $("#login_email").val();
		if(val=="")
			{
				$("#login_email_msg").html(inputResponse("This field is required", "error"));
				response = false;
			}
		else if (!validateEmail(val))
			{
				$("#login_email_msg").html(inputResponse("Invalid Email", "error"));
				response = false;
			}
		else
			{
				$("#login_email_msg").html(inputResponse("Okay", "ok"));
				response = true;
			}
		return response;
	}

	function validateLoginNewPass()
	{
		var response =false;
		var val = $("#login_newpass").val();
		if(val=="")
			{
				$("#login_newpass_msg").html(inputResponse("This field is required", "error"));
				response = false;
			}
		else if ((val.length)<6)
			{
				$("#login_newpass_msg").html(inputResponse("Password must be 6 characters or longer", "error"));
				response = false;
			}
		else
			{
				$("#login_newpass_msg").html(inputResponse("Okay", "ok"));
				response = true;
			}
		return response;
	}

	function validateLoginNewPassAgain()
	{
		var response =false;
		if(!validateLoginNewPass()) {
			$("#login_newpassagain_msg").html(inputResponse("Please correct the pass above", "error"));
			return false;
		}
		else
		{
		var val1 = $("#login_newpass").val();
		var val2 = $("#login_newpassagain").val();
		if(val2=="")
			{
				$("#login_newpassagain_msg").html(inputResponse("This field is required", "error"));
				response = false;
			}
		else if(val1!=val2)
			{
				$("#login_newpassagain_msg").html(inputResponse("Passwords do not match", "error"));
				response = false;
			}
		else
			{
				$("#login_newpassagain_msg").html(inputResponse("Okay", "ok"));
				response = true;
			}
		}
		return response;
	}
	
	function validateEmail(email) {
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;		
		var response =false;
		if(!emailReg.test(email))
			{
				response = false;
			}
		else
			{
				response = true;
			}
		return response;
		}	

	///////////////////////////////////
	////////// Investor Page //////////
	///////////////////////////////////

	$("#investor_continue").click(function(){
		var e = $("#email1").val();
		if (emailExists(e)) {
			investorLastLogin(e);
			$('#email1_error').text('');
			$("#investor_part2_sub1_container").slideDown();
			$('#investor_progress').fadeIn();
		} else {
			$('#email1_error').text('Email Does Not Exist');
			//alert("Email Does Not Exist");
		}
	});
	
	$("#investor_part2_sub1_container_toggle").click(
		function(){
			if($("#investor_part2_sub1_container_body").is(":visible")){
				$("#investor_part2_sub1_container_body").slideUp();
				$("#investor_part2_sub1_container_toggle").text("Show");
			} else {
				$("#investor_part2_sub1_container_body").slideDown();
				$("#investor_part2_sub1_container_toggle").text("Hide");
			}
		}
	);
	$("#investor_part2_sub2_container_toggle").click(
		function(){
			if($("#investor_part2_sub2_container_body").is(":visible")){
				$("#investor_part2_sub2_container_body").slideUp();
				$("#investor_part2_sub2_container_toggle").text("Show");
			} else {
				$("#investor_part2_sub2_container_body").slideDown();
				$("#investor_part2_sub2_container_toggle").text("Hide");
			}
		}
	);
	$("#investor_part2_sub3_container_toggle").click(
		function(){
			if($("#investor_part2_sub3_container_body").is(":visible")){
				$("#investor_part2_sub3_container_body").slideUp();
				$("#investor_part2_sub3_container_toggle").text("Show");
			} else {
				$("#investor_part2_sub3_container_body").slideDown();
				$("#investor_part2_sub3_container_toggle").text("Hide");
			}
		}
	);
	$("#investor_part2_sub4_container_toggle").click(
		function(){
			if($("#investor_part2_sub4_container_body").is(":visible")){
				$("#investor_part2_sub4_container_body").slideUp();
				$("#investor_part2_sub4_container_toggle").text("Show");
			} else {
				$("#investor_part2_sub4_container_body").slideDown();
				$("#investor_part2_sub4_container_toggle").text("Hide");
			}
		}
	);
	
	$("#investor_part2_sub1_agree").click(function(){
		var checked = $('#investor_part2_sub1_agree').attr('checked');
		if(!checked){
			$("#investor_progress_bar").animate({width:"0%"},{easing: 'easeOutQuad'});
			$("#investor_progress_amount").text("0%");
			$("#investor_progress_label").text("Step 1 of 5");
			
			$("#investor_part2_sub2_container").slideUp();
			$('#investor_part2_sub2_agree').removeAttr('checked');
			$("#investor_part2_sub3_container").slideUp();
			$('#investor_part2_sub3_agree').removeAttr('checked');
			$("#investor_part2_sub4_container").slideUp();
			$('#investor_part2_sub4_agree').removeAttr('checked');
			$("#investor_part2_sub5_container").slideUp();
			$('#investor_part2_sub5_agree').removeAttr('checked');
			$("#investor_part3_sub1_container").slideUp();
			$("#investor_part2_sub1_container_toggle").text("Hide");
			$("#investor_part2_sub2_container_toggle").text("Hide");
			$("#investor_part2_sub3_container_toggle").text("Hide");
			$("#investor_part2_sub4_container_toggle").text("Hide");
			
			$("#investor_part2_sub5_origin").val("NULL");
			
			$("#investor_part2_sub1_agree_label").css({backgroundColor:"#CCC"});
			$("#investor_part2_sub2_agree_label").css({backgroundColor:"#CCC"});
			$("#investor_part2_sub3_agree_label").css({backgroundColor:"#CCC"});
			$("#investor_part2_sub4_agree_label").css({backgroundColor:"#CCC"});
			$("#investor_part2_sub5_origin_label").css({backgroundColor:"#CCC"});
			
			$("#investor_part2_sub1_agree_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			$("#investor_part2_sub2_agree_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			$("#investor_part2_sub3_agree_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			$("#investor_part2_sub4_agree_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			$("#investor_part2_sub5_origin_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");

			$("#investor_part2_sub1_container_body").slideDown();
		} else{
			$("#investor_progress_bar").animate({width:"20%"},{easing: 'easeOutQuad'});
			$("#investor_progress_amount").text("20%");
			$("#investor_progress_label").text("Step 2 of 5");
			$("#investor_part2_sub1_container_body").slideUp();
			$("#investor_part2_sub2_container").slideDown();
			$("#investor_part2_sub2_container_body").slideDown();
			$("#investor_part2_sub1_agree_label").css({backgroundColor:"#99DD98"});
			$("#investor_part2_sub1_agree_comment").css({color:"#669966"}).text("You have agreed to this section");
			$("#investor_part2_sub1_container_toggle").text("Show");
			$("html").animate({ scrollTop: $(document).height() }, "slow");
		}
	});
	$("#investor_part2_sub2_agree").click(function(){
		var checked = $('#investor_part2_sub2_agree').attr('checked');
		if(!checked){
			$("#investor_progress_bar").animate({width:"20%"},{easing: 'easeOutQuad'});
			$("#investor_progress_amount").text("20%");
			$("#investor_progress_label").text("Step 2 of 5");

			$("#investor_part2_sub3_container").slideUp();
			$('#investor_part2_sub3_agree').removeAttr('checked');
			$("#investor_part2_sub4_container").slideUp();
			$('#investor_part2_sub4_agree').removeAttr('checked');
			$("#investor_part2_sub5_container").slideUp();
			$('#investor_part2_sub5_agree').removeAttr('checked');
			$("#investor_part3_sub1_container").slideUp();

			$("#investor_part2_sub5_origin").val("NULL");
			
			$("#investor_part2_sub2_agree_label").css({backgroundColor:"#CCC"});
			$("#investor_part2_sub3_agree_label").css({backgroundColor:"#CCC"});
			$("#investor_part2_sub4_agree_label").css({backgroundColor:"#CCC"});
			$("#investor_part2_sub5_origin_label").css({backgroundColor:"#CCC"});
			
			$("#investor_part2_sub2_agree_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			$("#investor_part2_sub3_agree_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			$("#investor_part2_sub4_agree_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			$("#investor_part2_sub5_origin_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			
			$("#investor_part2_sub2_container_body").slideDown();
			
			$("#investor_part2_sub2_container_toggle").text("Hide");
			$("#investor_part2_sub3_container_toggle").text("Hide");
			$("#investor_part2_sub4_container_toggle").text("Hide");

		} else {
			$("#investor_progress_bar").animate({width:"40%"},{easing: 'easeOutQuad'});
			$("#investor_progress_amount").text("40%");
			$("#investor_progress_label").text("Step 3 of 5");

			$("#investor_part2_sub3_container").slideDown();
			$("#investor_part2_sub2_agree_label").css({backgroundColor:"#99DD98"});
			$("#investor_part2_sub2_agree_comment").css({color:"#669966"}).text("You have agreed to this section");
			$("#investor_part2_sub2_container_body").slideUp();
			$("#investor_part2_sub3_container_body").slideDown();
			$("#investor_part2_sub2_container_toggle").text("Show");
		}
		
	});

	$("#investor_part2_sub3_agree").click(function(){
		var checked = $('#investor_part2_sub3_agree').attr('checked');
		if(!checked){
			$("#investor_progress_bar").animate({width:"40%"},{easing: 'easeOutQuad'});
			$("#investor_progress_amount").text("40%");
			$("#investor_progress_label").text("Step 3 of 5");

			$("#investor_part2_sub4_container").slideUp();
			$('#investor_part2_sub4_agree').removeAttr('checked');
			$("#investor_part2_sub5_container").slideUp();
			$('#investor_part2_sub5_agree').removeAttr('checked');
			$("#investor_part3_sub1_container").slideUp();
			
			$("#investor_part2_sub5_origin").val("NULL");

			$("#investor_part2_sub3_agree_label").css({backgroundColor:"#CCC"});
			$("#investor_part2_sub4_agree_label").css({backgroundColor:"#CCC"});
			$("#investor_part2_sub5_origin_label").css({backgroundColor:"#CCC"});
			
			$("#investor_part2_sub3_agree_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			$("#investor_part2_sub4_agree_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			$("#investor_part2_sub5_origin_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			
			$("#investor_part2_sub3_container_body").slideDown();

			$("#investor_part2_sub3_container_toggle").text("Hide");
			$("#investor_part2_sub4_container_toggle").text("Hide");
		} else {
			$("#investor_progress_bar").animate({width:"60%"},{easing: 'easeOutQuad'});
			$("#investor_progress_amount").text("60%");
			$("#investor_progress_label").text("Step 4 of 5");

			$("#investor_part2_sub4_container").slideDown();
			$("#investor_part2_sub3_agree_label").css({backgroundColor:"#99DD98"});
			$("#investor_part2_sub3_agree_comment").css({color:"#669966"}).text("You have agreed to this section");
			$("#investor_part2_sub3_container_body").slideUp();
			$("#investor_part2_sub4_container_body").slideDown();
			$("#investor_part2_sub3_container_toggle").text("Show");
		}
		
	});

	$("#investor_part2_sub4_agree").click(function(){
		$('#email2_error').text('');
		var e1 = $("#email1").val();
		var e2 = $("#investor_part2_sub4_email").val();
		var checked = $('#investor_part2_sub4_agree').attr('checked');
		if(!checked){
			$("#investor_progress_bar").animate({width:"60%"},{easing: 'easeOutQuad'});
			$("#investor_progress_amount").text("60%");
			$("#investor_progress_label").text("Step 4 of 5");

			$("#investor_part2_sub5_container").slideUp();
			$("#investor_part3_sub1_container").slideUp();
			$("#investor_part2_sub4_agree_label").css({backgroundColor:"#CCC"});
			$("#investor_part2_sub5_origin_label").css({backgroundColor:"#CCC"});

			$("#investor_part2_sub5_origin").val("NULL");

			$("#investor_part2_sub4_agree_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			$("#investor_part2_sub5_origin_comment").css({color:"#AAA"}).text("You must agree to this section to proceed");
			
			$("#investor_part2_sub4_container_body").slideDown();

			$("#investor_part2_sub4_container_toggle").text("Hide");
		} else {
			if(e1==e2){
				$("#investor_progress_bar").animate({width:"80%"},{easing: 'easeOutQuad'});
				$("#investor_progress_amount").text("80%");
				$("#investor_progress_label").text("Step 5 of 5");

				$("#investor_part2_sub5_container").slideDown();
				$("#investor_part2_sub4_agree_label").css({backgroundColor:"#99DD98"});
				$("#investor_part2_sub4_agree_comment").css({color:"#669966"}).text("You have agreed to this section");
				
				$("#investor_part2_sub4_container_body").slideUp();
				
				$("#investor_part2_sub4_container_toggle").text("Show");

				if($("#investor_part2_sub5_origin").val()!="NULL")
				{
					$("#investor_part3_sub1_container").slideUp();
				}
			} else {
				$("#investor_part2_sub5_container").slideUp();
				$("#investor_part3_sub1_container").slideUp();
				$('#investor_part2_sub4_agree').removeAttr('checked');
				$('#email2_error').text('Email must match email above');
			}
		}
		});
	$("#investor_part2_sub5_origin").change(function(){
		$('#submit_error').text('');
		if($("#investor_part2_sub5_origin").val()=="NULL")
			{
				$("#investor_progress_bar").animate({width:"80%"},{easing: 'easeOutQuad'});
				$("#investor_progress_amount").text("80%");
				$("#investor_part2_sub5_origin_label").css({backgroundColor:"#CCC"});
				$("#investor_part3_sub1_container").slideUp();
				$('#submit_error').text('Please select an origin');
				$("#investor_part2_sub5_origin_comment").css({color:"#AAA"}).text("You must select an origin to proceed");
				$("#investor_part2_sub5_container_toggle").text("Hide");				
			} else {
				$("#investor_progress_bar").animate({width:"100%"},{easing: 'easeOutQuad'});
				$("#investor_progress_amount").text("100%");
				$("#investor_part2_sub5_origin_label").css({backgroundColor:"#99DD98"});
				$("#investor_part2_sub5_origin_comment").css({color:"#669966"}).text("Origin selected");
				$("#investor_part3_sub1_container").slideDown();
				$("#investor_part2_sub5_container_toggle").text("Show");
				var o = $("#investor_part2_sub5_origin").val();
				var doclist = getdoclist(o);
				$("#idd_doclist").html(doclist).bind('click', function(){ updateDownloadCount(); });
			}
		});

	$("#idd_doclist li").click(
		function(){
		 alert("Click!");
		
		var e = $("#investor_part2_sub4_email").val();
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return }
		var url = "../includes/investor_download_count.php"+"?e="+e+"&sid="+Math.random();
		xmlHttp.open("GET",url,false);
		xmlHttp.send(null);		 
		}
	);

	function updateDownloadCount() {
		var e = $("#investor_part2_sub4_email").val();
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return }
		var url = "../includes/investor_download_count.php"+"?e="+e+"&sid="+Math.random();
		xmlHttp.open("GET",url,false);
		xmlHttp.send(null);		 
	}

	function investorLastLogin(e)
	{
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return }
		var url = "../includes/investor_lastlogin.php"+"?e="+e+"&sid="+Math.random();
		xmlHttp.open("GET",url,false);
		xmlHttp.send(null);
		if (xmlHttp.responseText == 'true') { return true; } else { return false; }
	}

	function emailExists(e)
	{
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return }
		var url = "../includes/emailcheck.php"+"?e="+e+"&sid="+Math.random();
		xmlHttp.open("GET",url,false);
		xmlHttp.send(null);
		if (xmlHttp.responseText == 'true') { return true; } else { return false; }
	}

	function getdoclist(o)
	{
		var e = $("#investor_part2_sub4_email").val();
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return }
		var url = "../includes/getidddocs.php?e="+e+"&sid="+Math.random();
		xmlHttp.open("GET",url,false);
		xmlHttp.send(null);
		var rt = xmlHttp.responseText;
		var olink = "";
		if(o=="AUS") { olink="<li><a href='/files/investordocs/Investor_Application_Form/GCP_Investor_Form_Australia.pdf'>Application Form (Australia)</a></li>"} else if ( o=="OTHER") { olink="<li><a href='/files/investordocs/Investor_Application_Form/GCP_Investor_Form_International.pdf'>Application Form (International)</a></li>" }
		return "<ul id='idd_doclist'>"+olink+rt+"</ul>";
	}

	$("#fname").change(function(){
		updateFileName();
	});

	$("#lname").change(function(){
		updateFileName();
	});
	$("#docid").change(function(){
		updateFileName();
	});

	$("#doc1_filename").click(function(){
		this.select();
	});
	$("#doc2_filename").click(function(){
		this.select();
	});
	$("#doc3_filename").click(function(){
		this.select();
	});
	$("#doc4_filename").click(function(){
		this.select();
	});
	$("#doc5_filename").click(function(){
		this.select();
	});

	function updateFileName() {
	
		var fname = $("#fname").val();
		var lname = $("#lname").val();
		var docid = $("#docid").val();
		
		var doc1 = "GCP_NXD_Intro_Letter_"+docid+"_"+fname+"_"+lname+".pdf";
		var doc2 = "GCP_Shareholder_Intro_Letter_"+docid+"_"+fname+"_"+lname+".pdf";
		var doc3 = "GCP_WDS_Intro_Letter_"+docid+"_"+fname+"_"+lname+".pdf";
		var doc4 = "GCP_Summary_2011_R2b_"+docid+"_"+fname+"_"+lname+".pdf";
		var doc5 = "GCP_Summary_2011_R3_"+docid+"_"+fname+"_"+lname+".pdf";
		
		$("#doc1_filename").val(doc1);
		$("#doc2_filename").val(doc2);
		$("#doc3_filename").val(doc3);
		$("#doc4_filename").val(doc4);
		$("#doc5_filename").val(doc5);
	}


	$("#table_col3").click(function(){
		$(".col3").toggle();
		var w = getElementWidth("investor_list") - 140;

		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col4").click(function(){
		$(".col4").toggle();
		var w = getElementWidth("#investor_list") - 140;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col5").click(function(){
		$(".col5").toggle();
		var w = getElementWidth("#investor_list") - 160;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col6").click(function(){
		$(".col6").toggle();
		var w = getElementWidth("#investor_list") - 100;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col7").click(function(){
		$(".col7").toggle();
		var w = getElementWidth("#investor_list") - 160;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col8").click(function(){
		$(".col8").toggle();
	});
	$("#table_col9").click(function(){
		$(".col9").toggle();
		var w = getElementWidth("#investor_list") - 80;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col10").click(function(){
		$(".col10").toggle();
		var w = getElementWidth("#investor_list") - 60;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col11").click(function(){
		$(".col11").toggle();
		var w = getElementWidth("#investor_list") - 70;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col12").click(function(){
		$(".col12").toggle();
		var w = getElementWidth("#investor_list") - 80;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col13").click(function(){
		$(".col13").toggle();
		var w = getElementWidth("#investor_list") - 120;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col14").click(function(){
		$(".col14").toggle();
		var w = getElementWidth("#investor_list") - 60;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col15").click(function(){
		$(".col15").toggle();
		var w = getElementWidth("#investor_list") - 60;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col16").click(function(){
		$(".col16").toggle();
		var w = getElementWidth("#investor_list") - 160;
		$("#investor_list").css({width: w+"px"});
	});
	$("#table_col17").click(function(){
		$(".col17").toggle();
		var w = getElementWidth("#investor_list") - 80;
		$("#investor_list").css({width: w+"px"});
	});


	/////////////////////////////////////////
	////////// GEMS Demo Functions //////////
	/////////////////////////////////////////

	$(".gems_demo_link").click(function() {
		var id = this.id;
		var img = this.href;
		var text = this.title;

		$(".gems_demo_link_thumb_current").removeClass("gems_demo_link_thumb_current").addClass("gems_demo_link_thumb");
		$("#"+id+"_image").removeClass("gems_demo_link_thumb").addClass("gems_demo_link_thumb_current");

		$("#demo_image").css({position: 'relative'}).animate({opacity:0, top: '-20px'}, {duration: 200});
		$("#demo_text").animate({opacity:0}, {duration: 300, complete: function()
		{
			$('#demo_text').html(text).animate({opacity:1}, {duration: 300, complete: function()
			{
				$('#demo_image').attr("src",img).animate({opacity:1, top: '0px'}, {duration: 200});	
			}});
		}});
		
		return false;
	});
	
	$("#demo_text").hover(function() {
		//$("#demo_text").animate({opacity:1});
	}, function() {
		//$("#demo_text").animate({opacity:0.5});		
	});
	
	/*
	$("#demo_image").toggle(function() {
		$("#demo_text").animate({opacity:0.5}, {duration:250});
		$("#demo_image").animate({width:"940px"}, {duration:250});
		$("#demo_image").attr("title", "Click image to reduce size");
	}, function() {
		$("#demo_text").animate({opacity:1}, {duration:250});
		$("#demo_image").animate({width:"560px"}, {duration:250});		
		$("#demo_image").attr("title", "Click image to enlarge size");
	})
	*/

	/////////////////////////////////////////////
	////////// Investor List Functions //////////
	/////////////////////////////////////////////

	$("#investorlist_printable").tablesorter({sortList: [[0,0]]});


	$("#investor_list tr").click(function(){
		var tid = "#"+this.id+"_more";
		$(tid).toggle();
	});



	/////////////////////////////////////////
	////////// Agreement Functions //////////
	/////////////////////////////////////////

	$("#nda_agreement_button").click(function()
	{

		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return }
		var url = "../includes/function_ndaagree.php?sid="+Math.random();
		xmlHttp.open("GET",url,false);
		xmlHttp.send(null);
		var rt = xmlHttp.responseText;
		setTimeout( "window.location = '/dashboard'", 1);
		return false;
	});


	///////////////////////////////////////////////
	////////// Agreement Icon Animations //////////
	///////////////////////////////////////////////

	$("#gcp_confidentiality_icon").hover(function() { animateReadMe_in(); }, function() { animateReadMe_out(); });
	$("#readme_icon").hover(function() { animateReadMe_in(); }, function() { animateReadMe_out(); });
	
	function animateReadMe_in() {
		$("#readme_icon").stop().animate({width:"160px", left:"22px", rotate:"-10deg", opacity:1}, {duration: 300});
	}
	function animateReadMe_out() {
		$("#readme_icon").stop().animate({width:"120px", left:"42px", rotate:"10deg", opacity:0.35}, {duration: 300});
	}


	//////////////////////////////
	////////// Fancybox //////////
	//////////////////////////////

	/*
	$(".bert_demo").fancybox({
		//'transitionIn'		: 'elastic',
		//'transitionOut'		: 'elastic',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.75,
		'centerOnScroll'	: 'true'
	});
	*/

	/////////////////////////////////////////
	////////// Page Reload Counter //////////
	/////////////////////////////////////////

	var counter = 5;
	var interval = setInterval(function() {
    	counter--;
    	$(".secs").text(counter);
   	}, 1000);

	//////////////////////////////////////
	////////// Global Functions //////////
	//////////////////////////////////////

	function inputResponse(msg, type)
	{
		var inputResponse;
		if(type=="ok")
		{
			var inputResponse = "<img style='position:relative;top:3px;' src='../images/ok.png' alt=''> <span class='inputResponse colgreen'>"+msg+"</span>";
		}
		else if(type=="error")
		{
			var inputResponse = "<img style='position:relative;top:3px;' src='../images/error.png' alt=''> <span class='inputResponse colred'>"+msg+"</span>";			
		}
		else if(type=="pending")
		{
			var inputResponse = "<img style='position:relative;top:3px;' src='../images/pending.png' alt=''> <span class='inputResponse colblue'>"+msg+"</span>";			
		}
		else if(type=="loading")
		{
			var inputResponse = "<img style='position:relative;top:3px;' src='../images/loading.gif' alt=''> <span class='inputResponse colgray'>"+msg+"</span>";			
		}
		return inputResponse;
	}

	////////////////////////////////////
	////////// XmlHttp Object //////////
	////////////////////////////////////

	function GetXmlHttpObject()
	{
		var xmlHttp=null;
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			//Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return xmlHttp;
	}
	
	////////////////////////////////////////////////
	////////// Get DOM Element Dimensions //////////
	////////////////////////////////////////////////

		 function getElementWidth(objectId)
	{
		x = document.getElementById(objectId);
		return x.offsetWidth;
	}

	function getElementHeight(objectId)
	{
		y = document.getElementById(objectId);
		return y.offsetHeight;
	} 

})
