/**********************************************************************
	
	tivg.js
	-------
	
	Author:		Ashley Meadows
	Copyright:	© tIVG 2009
	Created:	Thursday 19th February 2009
	Version:	1.0.0
	
	Description
	-----------
	
	tIVG JavaScript classes document 
	
 **********************************************************************/

// preload images
var iHome=new Image(); iHome.src="/images/home_button_on.png";
var iAbout=new Image(); iAbout.src="/images/about_button_on.png";
var iInvest=new Image(); iInvest.src="/images/investments_button_on.png";
var iPortfo=new Image(); iPortfo.src="/images/portfolio_button_on.png";
var iPitch=new Image(); iPitch.src="/images/pyi_button_on.png";
var iContact=new Image(); iContact.src="/images/contact_button_on.png";

// tIVG class
var tIVG=
{
	/**
	 * when the mouse hovers a menu image we
	 * call this function
	 */
	menu_o:function(o)
	{
		var inarray=o.src.split("/");
		o.src="/images/" + inarray[inarray.length-1].split("_")[0]+"_button_on.png";	
	},
	
	/**
	 * when the mouse hovers a menu image we
	 * call this function
	 */
	menu_u:function(o)
	{
		var inarray=o.src.split("/");
		o.src="/images/" + inarray[(inarray.length-1)].split("_")[0]+"_button_off.png";
	},
	
	/**
	 * reload capcha
	 */
	reloadCapcha:function()
	{
		$("capcha_img").src="/includes/capcha.php?"+(new Date()).getTime();
		$("capcha").value="";
	},
	 
	/**
	 * valudate the form
	 */
	validate:function(form)
	{
		if(form=="enquiries")
		{
			// enquiries form
			var pv_array=
			[
			 "title="+$("title", null).value,
			 "first_name="+$("firstname", null).value,
			 "surname="+$("surname", null).value,
			 "tel="+$("telephone", null).value,
			 "email="+$("email", null).value,
			 "enquiry="+$("enquiry", null).value,
			 "capcha="+$("capcha", null).value
			];
			
			new httpreq(
			{
				script:"/ajax_forms.php",
				method:"post",
				get_vars:["form=enquire"],
				post_vars:pv_array,
				callback:tIVG.callback.enquireies
			});
			
		}
		else if(form=="pitch")
		{
			// pitch form
			if(document.getElementById("agree_check").checked!=true)
			{
				alert("Please check the confirm checkbox before you can submit your ideas.");
			}
			else
			{
				new httpreq(
				{
					script:"/ajax_forms.php",
					method:"post",
					get_vars:["form=pitch"],
					post_vars:["capcha=" + document.getElementById("capcha").value],
					callback:tIVG.callback.pitch
				});
			};
		};
	},
	
	/**
	 * callback functions from ajax when
	 * validating forms
	 */
	callback:
	{
		enquireies:function(b)
		{
			if(b.length)
			{
				$("tIVG_error", null).style.display="block";
				$("tIVG_error", null).innerHTML=b;
				location.href="#top";
				tIVG.reloadCapcha();
			}
			else
			{
				document.tIVGenquiries.submit();
			};
		},
		
		pitch:function(b)
		{
			if(b!="wrong-capcha")
			{
				document.pitchIdeas.submit();
			}
			else
			{
				alert("You have incorrectly entered the security image, please try again.");
				tIVG.reloadCapcha();
			};
		}
	}
};
