// apply to all png images and to div#logo
$(document).ready(function(){
	$('img[@src$=.png], div#footer').ifixpng();
	
	$('#submit_form').parents('form').submit(function()
	{
		$('.status').html('');
		
		$('.processing').html('Processing form... Please wait...');
		
		$(this).ajaxSubmit(
		{
			dataType: 'json',
			success : post_submit
		});
		
		return false;
	});
	
	function post_submit(jsonResponse)
	{
		$('.status').html('');
		
		response = eval(jsonResponse);
		
		if(response.status == 1)
		{
			$('.processing').html('<span class="error">Please correct all errors before submission</span>');
			
			for (i=0; i< response.message.length; i++)
			{	
				$('#' + response.message[i].id).siblings('span.error').html( response.message[i].error ); // print error message
			}
		}
		else
		{
			$('.processing').html('<span class="successful">Form processing completed... <strong>Your enquiry has been successfully submitted.</strong></span>');
			
			var trackingAttributes = document.createElement("script");
			trackingAttributes.setAttribute("type", "text/javascript");
			var trackingAttributesText = document.createTextNode('var google_conversion_id = 1036342020;var google_conversion_language = "en_AU";var google_conversion_format = "1";var google_conversion_color = "ffffff";var google_conversion_label = "O6TMCO6KlgEQhKaV7gM";if (100.0) {  var google_conversion_value = 100.0; }');
			trackingAttributes.appendChild(trackingAttributesText);

			var trackingScript = document.createElement("script");
			trackingScript.setAttribute("type", "text/javascript");
			var trackingScriptText = document.createTextNode('(function(){var b=null,d=document,h="push",i="google_conversion_format",j="toString",k="length",l="location",m="google_conversion_snippets";function n(a){if(a!=b)return escape(a[j]());return""}function o(a){if(a!=b)return a[j]().substring(0,256);return""}function p(a,c){c=n(c);if(c!=""){a=n(a);if(a!="")return"&".concat(a,"=",c)}return""}function q(a,c,g){var e=[];if(a){var f=a.screen;if(f){e[h](p("u_h",f.height));e[h](p("u_w",f.width));e[h](p("u_ah",f.availHeight));e[h](p("u_aw",f.availWidth));e[h](p("u_cd",f.colorDepth))}a.history&&e[h](p("u_his",a.history[k]))}g&&typeof g.getTimezoneOffset=="function"&&e[h](p("u_tz",-g.getTimezoneOffset()));if(c){typeof c.javaEnabled=="function"&&e[h](p("u_java",c.javaEnabled()));c.plugins&&e[h](p("u_nplug",c.plugins[k]));c.mimeTypes&&e[h](p("u_nmime",c.mimeTypes[k]))}return e.join("")}function r(a,c){var g="";if(c){var e=c.referrer;if(a&&a.top&&c[l]&&a.top[l]==c[l]){g+=p("ref",o(e));e=c[l]}g+=p("url",o(e))}return g}function s(a){if(a&&a[l]&&a[l].protocol&&a[l].protocol[j]().toLowerCase()=="https:")return"https:";return"http:"}function t(a,c){return s(a)+"//www.googleadservices.com/pagead/"+c}function u(a,c,g){var e="/?";if(a.google_conversion_type=="landing")e="/extclk?";e=t(a,["conversion/",n(a.google_conversion_id),e,"random=",n(a.google_conversion_time)].join(""));var f;a:{f=a.google_conversion_language;if(f!=b){f=f[j]();if(2==f[k]){f=p("hl",f);break a}if(5==f[k]){f=p("hl",f.substring(0,2))+p("gl",f.substring(3,5));break a}}f=""}e+=[p("cv",a.google_conversion_js_version),p("fst",a.google_conversion_first_time),p("num",a[m]),p("fmt",a[i]),p("value",a.google_conversion_value),p("label",a.google_conversion_label),p("bg",a.google_conversion_color),f,p("guid","ON"),q(a,c,a.google_conversion_date),r(a,g)].join("");return e}function v(a){if({ar:1,bg:1,cs:1,da:1,de:1,el:1,en_AU:1,en_US:1,en_GB:1,es:1,et:1,fi:1,fr:1,hi:1,hr:1,hu:1,id:1,is:1,it:1,iw:1,ja:1,ko:1,lt:1,nl:1,no:1,pl:1,pt_BR:1,pt_PT:1,ro:1,ru:1,sk:1,sl:1,sr:1,sv:1,th:1,tl:1,tr:1,vi:1,zh_CN:1,zh_TW:1}[a])return a+".html";return"en_US.html"}function w(a,c,g){c=u(a,c,g);g=function(e,f,B){return\'<img height="\'+B+\'" width="\'+f+\'" border="0" src="\'+e+\'" />\'};return a[i]==0?\'<a href="\'+(s(a)+"//services.google.com/sitestats/"+v(a.google_conversion_language)+"?cid="+n(a.google_conversion_id))+\'" target="_blank">\'+g(c,135,27)+"</a>":a[m]>1||a[i]==3?g(c,1,1):\'<iframe name="google_conversion_frame" width="\'+(a[i]==2?200:300)+\'" height="\'+(a[i]==2?26:13)+\'" src="\'+c+\'" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no">\'+g(c.replace(/\?random=/,"?frame=0&random="),1,1)+"</iframe>"};var x=window;if(x)if(/[\?&;]google_debug/.exec(d.URL)!=b){var y=d.getElementsByTagName("head")[0];if(!y){y=d.createElement("head");d.getElementsByTagName("html")[0].insertBefore(y,d.getElementsByTagName("body")[0])}var z=d.createElement("script");z.src=t(window,"conversion_debug_overlay.js");y.appendChild(z)}else{try{var A;if(x.google_conversion_type=="landing"||!x.google_conversion_id)A=false;else{x.google_conversion_date=new Date;x.google_conversion_time=x.google_conversion_date.getTime();if(typeof x[m]=="number"&&x[m]>0)x.google_conversion_snippets+=1;else x.google_conversion_snippets=1;if(typeof x.google_conversion_first_time!="number")x.google_conversion_first_time=x.google_conversion_time;x.google_conversion_js_version="6";if(x[i]!=0&&x[i]!=1&&x[i]!=2&&x[i]!=3)x.google_conversion_format=1;A=true}A&&d.write(w(x,navigator,d))}catch(C){}x.google_conversion_date=b;x.google_conversion_time=b;x.google_conversion_js_version=b;x.google_conversion_id=b;x.google_conversion_value=b;x.google_conversion_label=b;x.google_conversion_language=b;x.google_conversion_format=b;x.google_conversion_color=b;x.google_conversion_type=b};})();');
			trackingScript.appendChild(trackingScriptText);
			
			var noScript = document.createElement("noscript");
			var noScriptImage = document.createElement("img");
			noScriptImage.setAttribute("height", "1");
			noScriptImage.setAttribute("width", "1");
			noScriptImage.setAttribute("border", "0");
			noScriptImage.setAttribute("src", "http://www.googleadservices.com/pagead/conversion/1036342020/?value=100.0&amp;label=O6TMCO6KlgEQhKaV7gM&amp;guid=ON&amp;script=0");
			noScript.appendChild(noScriptImage);
			
			document.getElementById("TB_ajaxContent").appendChild(trackingAttributes);
			document.getElementById("TB_ajaxContent").appendChild(trackingScript);
			document.getElementById("TB_ajaxContent").appendChild(noScript);
			
			$('#submit_form').parents('form').clearForm();
			setTimeout('tb_remove()', 5000);
		}
	}
	
	// bind 'subscribeForm' and provide a simple callback function
	$("#newsletterSubmit").click(function() {
	    $('#subscribeForm').ajaxForm( {
			beforeSubmit: validateSubscription,
			target: '#subscriptionResponse', 
	    // success identifies the function to invoke when the server response 
	    // has been received; here we apply a fade-in effect to the new content 
	    success: function() { 
		    $('#subscriptionResponse').animate({opacity: 1.0}, 3000).fadeOut('slow'); 
	    }
		});
	});
});
