// JavaScript Document


function ADOBE_MNGR(){
	var deactivate = false;
	var select_text = "-- select --";
	var hold_obj = {'id':'state_select'};
	// input field names
	var country = "country";
	var email  = "email";
	var state = "state";
	var relationship = "relationship";
	var level2 = "level2";
	var level3 = "level3_pre";
	var solutions_of_interest = "solutions_of_interest";
	// option elements
	var state_select = new Element('select',{'id':'state_select'});
	var state_select_option = new Element('option',{'text':select_text,'value':''})
	// signifigent options
	var australia = "Australia";
	var nz = "New Zealand";
	var curr_cust = "Current Adobe Customer";
	var Cust_Education = "Cust_Education";
	var Cust_Government = "Cust_Government";

	this.adobe_form_onload = function(){
		var IE6=(navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1)
		if(IE6){
			deactivate = true;
			$("intro_div").setProperty('html','<p style="border:1px solid #666666;background-color:#cccccc; padding:4px;">We have detected that your browser is too old to view some of the features on this page. A modified version of the page is presented below, however we strongly recommend that you <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx" target="_blank">update your browser</a></p><br />To update your details and stay informed of the latest Adobe products, simply complete these fields below.<br />Make sure you click on the SUBMIT NOW button at the end of this form in order for your details to be captured.<br /><br /><span class="red">Required fields denoted by *</span><br />');
		}else{
			addStateSelect();
			this.onRelationshipChange();
			this.onLevel2Change();
			this.onCountryChange();
		}
	}

	// events
	this.onCountryChange = function (){
		if(!deactivate){
			var has_state = sub_select_arr[state][$(country).getSelected()[0].value]
			changeStateInput(has_state);
		}
	}
	this.onRelationshipChange = function (){
		if(!deactivate){
			var rel_val = $(relationship).getSelected()[0].value
			controlLevel2(rel_val)
			controlSolutionOfIntrest(rel_val)
			this.onLevel2Change()
		}
	}
	this.onLevel2Change = function (){
		if(!deactivate){
			var rel_val = $(level2).getSelected()[0].value
			controlLevel3(rel_val)
		}
	}

	
	// processing functions
	function addStateSelect(){
		$(state_select).adopt(state_select_option);
		state_select.inject($(state),'after');
	}
	function controlLevel2(rel_val){
		if($(level2)){
			var sty = (rel_val == curr_cust)?'block':'none';
			$(level2+"_li").setStyle('display',sty);
			if(sty == 'none'){$(level2).selectedIndex = 0;}
		}
	}
	function controlSolutionOfIntrest(rel_val){
		if($(solutions_of_interest)){
			var sty = (options_arr.indexOf(rel_val) > -1)?'block':'none';
			$(solutions_of_interest+"_li").setStyle('display',sty);
		}
	}
	function controlLevel3(rel_val){
		if($(level3)){
			if(rel_val == Cust_Education || rel_val == Cust_Government){
				addOptions(true, $(level3), sub_select_arr[level3][rel_val])
			}
			var sty = (rel_val == Cust_Education || rel_val == Cust_Government)?'block':'none';
			$(level3+"_li").setStyle('display',sty);
			if(sty == 'none'){$(level3).selectedIndex = 0;}
		}
	}
	function changeStateInput(state_arr){
		var state_input_id = (state_select.id == state)?'state_input':state;
		if(state_arr){
			$(state_input_id).setStyles({'display':'none'});
			$(state_input_id).setProperties({'id':'state_input','name':'state_input'});
			state_select.setStyles({'display':'inline'});
			state_select.setProperties({'id':state,'name':state});
			hold_obj = state_select
			addOptions(true, hold_obj, state_arr);
			if(state_arr.length == 1){
				$(state+"_li").setStyles({'display':'none'});
				$(state).selectedIndex = 1;
			}else{
				$(state+"_li").setStyles({'display':'inline'});
			}
		}else{
			$("state_li").setStyles({'display':'inline'});
			state_select.setStyles({'display':'none'});
			state_select.setProperties({'id':'state_select','name':'state_select'});
			$(state_input_id).setStyles({'display':'inline'});
			$(state_input_id).setProperties({'id':state,'name':state});
		}
	}
	function addOptions(delete_existing, obj, option_arr){
		var i;
		if(delete_existing){
			var old_options = obj.getElements('option');
			for(i = 1; i<old_options.length; i++){
				old_options[i].destroy();
			}
		}
		for(i = 0; i<option_arr.length;i++){
			var o_arr = option_arr[i].split("|");
			var t = o_arr[0];
			var v = (o_arr.length == 2)?o_arr[1]:o_arr[0];
			var el = new Element('option',{'text':t,'value':v})
			obj.adopt(el);
			//alert(i+" = "+option_arr[i]);
		}
	}
	// vars 
	var options_arr = [
									   "Not an Adobe Customer, but want to know more",
									   "Not an Adobe Customer, but have downloaded trial software",
									   "Not an Adobe Customer, but have downloaded free Adobe Reader"
									   ];
	var sub_select_arr = new Array();
						sub_select_arr[state] = new Array();
						sub_select_arr[state][australia] = [
															"ACT",
															"NSW",
															"NT",
															"QLD",
															"SA",
															"TAS",
															"VIC",
															"WA"];
						sub_select_arr[state][nz] = [
															"NZ"];
						sub_select_arr[level3] = new Array();
						sub_select_arr[level3][Cust_Education] = [
															"Student|Edu_Students",
															"K6 Private School|School_PrivateK6",
															"K12 Private School|School_PrivateK12",
															"K6 Religious School|School_ReligiousK6",
															"K12 Religious School|School_ReligiousK12",
															"K6 Government School|School_GovtK6",
															"K12 Government School|School_GovtK12",
															"University|HED_University",
															"Polytechnic/TAFE|HED_PolytechnicTAFE",
															"Private College|HED_PrivateCollege",
															"Independent|Ministry_Independant",
															"Religious|Ministry_Religious",
															"Government|Ministry_Government"];
						sub_select_arr[level3][Cust_Government] = [
															"Federal - Aust|Govt_FederalAU",
															"State - NSW|Govt_StateNSW",
															"State - QLD|Govt_StateQLD",
															"State - VIC|Govt_StateVIC",
															"State - SA|Govt_StateSA",
															"State - TAS|Govt_StateTAS",
															"State - WA|Govt_StateWA",
															"State - NT|Govt_StateNT",
															"State - ACT|Govt_StateACT",
															"Local - Aust|Govt_LocalAU",
															"Central - NZ|Govt_CentralNZ",
															"Local - NZ|Govt_LocalNZ"];
}
var adobe = new ADOBE_MNGR();
