//################################################################################
//#			NAME: 		functionLoader
//#			CALLED BY:	Page Layout Manager (Post Form) [WebGUI Template]
//#			PURPOSE:	A single function that launches all necessary functions
//#						to run the form. Keeps the form page a little cleaner.
//################################################################################
function functionLoader(titleVal) {
	parseFields(1);
	parseFields(2);
	parseFields(3);
	parseFields(4);
	parseFields(5);
	populateMe(titleVal);
	attachValidation();
	validateForm();
	backgroundImages(document.getElementById('themeName').value,'miniLayout',320);
}


//################################################################################
//#			NAME: 		updateFields
//#			CALLED BY:	functionLoader, validateForm
//#			PURPOSE:	Obtains the values of a given layout, top, left and width
//#						and concatenates them into a single value, and assigns 
//#						them to a user defined variable. Secondly, it feeds these
//#						values to the miniLayout function.
//################################################################################
function updateFields(positionVal) {
	var topVal = document.getElementById('top' + positionVal).value;
	var leftVal = document.getElementById('left' + positionVal).value;
	var widthVal = document.getElementById('width' + positionVal).value;	
	
	var combineEm = topVal + "," + leftVal + "," + widthVal;
	
	document.getElementById("userDefined" + positionVal + "_formId").value = combineEm;
	miniLayout(positionVal,topVal,leftVal,widthVal);
}


//################################################################################
//#			NAME: 		parseFields
//#			CALLED BY:	functionLoader
//#			PURPOSE:	Grabs the concatenated top, left and width values and
//#						splits them up again to populate the input boxes when the
//#						page is loaded.
//################################################################################
function parseFields(userField) {
	var valArray = document.getElementById("userDefined" + userField + "_value").value.split(",");
	var elementArray = new Array(document.getElementById('top' + userField),document.getElementById('left' + userField),document.getElementById('width' + userField));
	for(i=0;i<valArray.length;i++) {
		elementArray[i].value = valArray[i];	
	}
	
}


//################################################################################
//#			NAME: 		populateMe
//#			CALLED BY: 	functionLoader
//#			PURPOSE:	Two WebGUI navigation assets create two javascript arrays
//#						that contain all of the names of user created themes, and
//#						then the names of themes to not be displayed. The function
//#						takes the values from the arrays and uses them to populate
//#						a dropdown box
//################################################################################
function populateMe(noTitle) {
	var themeNames = new Array("Theme ManagerLayout","identityLayout","constitution_arLayout","cabinet_arLayout","reviving_trade_arLayout","gone_wind_arLayout","Iraq_withdrawal_arLayout","climate_change_arLayout","obama_cairo_arLayout","top_univ_arLayout","lincoln_arLayout","obama_arLayout","women_courage_arLayout","tracking_h1n1_arLayout","flushingLayout","identity_arLayout","un_declarationLayout","gitmo_arLayout","usaid_me_arLayout","middleeastpeaceLayout","anatomyofajuryLayout","exploringmarsLayout","ungaLayout","community_collegeLayout","spaceLayout","foiaLayout","food_securityLayout","nobelpeaceLayout","corruptionLayout","nuclearfreeworldLayout","money_transfersLayout","infect_diseaseLayout","agriculturalLayout","awardsLayout","black_histLayout","bikesLayout","notable_africanLayout","e-exchange_openLayout","religiousfreedomLayout","science_envoysLayout","women_govtLayout","piracyLayout","oprahLayout","wocLayout","cars_shift_greenLayout","climate_waterLayout","architecture_greenLayout","studentLifeLayout","Michelle_ObamaLayout","entrepreneurship_summitLayout","press_fredomLayout","nuclear_strategyLayout","huck_finnLayout","planting_treesLayout","Digital_libraryLayout","see_youLayout","jazz_americaLayout","refugeeLayout","july4thLayout","usg_clickLayout","preserving_cultureLayout","passportLayout","multicultural_RamadanLayout","defining_internetLayout","ramadan_communityLayout","you_askedLayout","dissentLayout");		//Supplies the populated themeNames array
	var usedLayouts = new Array("identityLayout","constitution_arLayout","cabinet_arLayout","reviving_trade_arLayout","gone_wind_arLayout","Iraq_withdrawal_arLayout","climate_change_arLayout","obama_cairo_arLayout","top_univ_arLayout","lincoln_arLayout","obama_arLayout","women_courage_arLayout","tracking_h1n1_arLayout","flushingLayout","identity_arLayout","un_declarationLayout","gitmo_arLayout","usaid_me_arLayout","middleeastpeaceLayout","anatomyofajuryLayout","exploringmarsLayout","ungaLayout","community_collegeLayout","spaceLayout","foiaLayout","food_securityLayout","nobelpeaceLayout","corruptionLayout","nuclearfreeworldLayout","money_transfersLayout","infect_diseaseLayout","agriculturalLayout","2009_awardsLayout","awardsLayout","black_histLayout","e-exchange_openLayout","religiousfreedomLayout","science_envoysLayout","women_govtLayout","bikesLayout","piracyLayout","wocLayout","oprahLayout","cars_shift_greenLayout","climate_waterLayout","architecture_greenLayout","studentLifeLayout","Michelle_ObamaLayout","entrepreneurship_summitLayout","press_fredomLayout","nuclear_strategyLayout","huck_finnLayout","planting_treesLayout","Digital_libraryLayout","see_youLayout","jazz_americaLayout","refugeeLayout","july4thLayout","usg_clickLayout","preserving_cultureLayout","passportLayout","multicultural_RamadanLayout","defining_internetLayout","ramadan_communityLayout","you_askedLayout");		//Supplies the populated usedLayouts array
	var themeName = document.getElementById('themeName').options;
	
	if(noTitle != 'Thread') {
		themeName[themeName.length] = new Option(noTitle, noTitle);
		themeName[themeName.length] = new Option("", "");
	}
	
	for (i=1;i<themeNames.length; i++) {
		if(noTitle != themeNames[i]) {
			for(x=0;x<usedLayouts.length;x++) {
				if(usedLayouts[x] == themeNames[i]) {
					repeatedLayout = 1;
					break;				
				}
				else
					repeatedLayout = 0;
			}
			if(!repeatedLayout) 
				themeName[themeName.length] = new Option(themeNames[i],themeNames[i]);	
		}
	}
}


//################################################################################
//#			NAME: 		miniLayout
//#			CALLED BY:	updateFields
//#			PURPOSE:	Positions boxes on a mock layout that is 1/3rd the scale
//#						of an actual america.gov layout
//################################################################################
function miniLayout(miniVal,topVal,leftVal,widthVal) {
	var miniVal = document.getElementById("mini" + miniVal);
	if((topVal != '') && (leftVal != '') && (widthVal != '')) {
		miniVal.style.top = Math.round(topVal / 3) + "px";
		miniVal.style.left = Math.round(leftVal / 3) + "px";
		miniVal.style.width = Math.round(widthVal / 3) + "px";
		miniVal.style.display = "block";
	}
	else {
		miniVal.style.top = "0px";
		miniVal.style.left = "0px";
		miniVal.style.width = "0px";
		miniVal.style.display = "none";
	}
}


//################################################################################
//#			NAME: 		validateForm
//#			CALLED BY: 	attachValidation, functionLoader
//#			PURPOSE:	Primarily this is to validate that each layout has all 3
//#						necessary values, left, top and width when the submit
//#						button is pressed. Error notifications are displayed in 
//#						red. This is also called to initially place the boxes
//#						in the mini layout.
//################################################################################
function validateForm() {
	var numOf = 5;
	var valid = true;
	var errorVal = document.getElementById('errorConsole');
	errorVal.innerHTML = '';
	
	for(i=1;i<=numOf;i++) {
		var topVal = document.getElementById('top' + i).value;
		var leftVal = document.getElementById('left' + i).value;
		var widthVal = document.getElementById('width' + i).value;
		var labelVal = document.getElementById('label' + i);
		
		if((topVal == '') || (leftVal == '') || (widthVal == '')) {
			if((topVal == '') && (leftVal == '') && (widthVal == '')) {
				//No values were entered, so don't do anything
			}
			else
			{	
				errorVal.style.color = 'red';
				errorVal.innerHTML = errorVal.innerHTML + "<div style='padding:5px 15px'>You must enter left, top and width values for layout " + i + "</div>"
				labelVal.style.color = 'red';
				valid = false;
			}
		}
		else {
			labelVal.style.color = 'black';
			updateFields(i);
			continue;
		}
		
	}
	//alert(valid);
	return valid;
}
	

//################################################################################
//#			NAME: 		attachValidation
//#			CALLED BY: 	functionLoader
//#			PURPOSE:	Attachs an onsubmit event to fire off the validateForm
//#						function
//################################################################################
function attachValidation() {
	var attachForm = document.getElementById('layoutManagerPost');	
	attachForm = attachForm.getElementsByTagName('form');
	attachForm[0].onsubmit = function () { return validateForm(); };
}


//################################################################################
//#			NAME: 		backgroundImages
//#			CALLED BY: 	Page Layout Manager (Thread), functionLoader()
//#			PURPOSE:	Places the correct background image for the layout. This 
//#						function is AssetProxied into the updatefields.js Snippet
//#						because it is actually a Collaboratoin System template,
//#						so its MIME type isn't text/javascript
//################################################################################
function backgroundImages(themeName,elementId,bckImgWidth) {
	//var themeName = themeName;
	var counter = 66;
	var themeArray = new Array(66);
	var imgHeight;
			
	for(i=0;i<counter;i++)
		themeArray[i] = new Array(2);
			
	
	themeArray[1-1][0] = "dissentLayout";			//Theme Name	
	themeArray[1-1][1] = "/ar/uploads/zN/2k/zN2k7EYsnqTRZSHvommShg/Campaign-dissent.jpg";		//Background Image
	
	themeArray[2-1][0] = "defining_internetLayout";			//Theme Name	
	themeArray[2-1][1] = "/ar/uploads/g0/pz/g0pzKzk49rMrHQPyhFRr8w/internet_freedom_newcomp.jpg";		//Background Image
	
	themeArray[3-1][0] = "you_askedLayout";			//Theme Name	
	themeArray[3-1][1] = "/ar/uploads/2b/gG/2bgGFogrRaV9wjG0CRcM_A/american_culture_comp2.jpg";		//Background Image
	
	themeArray[4-1][0] = "ramadan_communityLayout";			//Theme Name	
	themeArray[4-1][1] = "/ar/uploads/FX/Yh/FXYhjB8mUBgWBz8j6Yu7dg/ramadan_in_america_bg.jpg";		//Background Image
	
	themeArray[5-1][0] = "multicultural_RamadanLayout";			//Theme Name	
	themeArray[5-1][1] = "/ar/uploads/sZ/9X/sZ9XtiI0nRTYCe0RwUzZjw/ramadan_layout_ar.jpg";		//Background Image
	
	themeArray[6-1][0] = "passportLayout";			//Theme Name	
	themeArray[6-1][1] = "/ar/uploads/GA/b3/GAb3Yoo4Ms-q8Tu1es0W_g/passportvisas-i-bkd.jpg";		//Background Image
	
	themeArray[7-1][0] = "preserving_cultureLayout";			//Theme Name	
	themeArray[7-1][1] = "/ar/uploads/0W/r9/0Wr99k8etfZEhHd0db_-Aw/preserving_mock_up_mena.jpg";		//Background Image
	
	themeArray[8-1][0] = "Digital_libraryLayout";			//Theme Name	
	themeArray[8-1][1] = "/ar/uploads/MC/wZ/MCwZ_U7sezpiuvZ16YFg6w/digitallibrary.jpg";		//Background Image
	
	themeArray[9-1][0] = "usg_clickLayout";			//Theme Name	
	themeArray[9-1][1] = "/ar/uploads/A-/aX/A-aXsM_WL-W0WO3dfCqCZA/USGattheClick.jpg";		//Background Image
	
	themeArray[10-1][0] = "july4thLayout";			//Theme Name	
	themeArray[10-1][1] = "/ar/uploads/rF/NJ/rFNJ-XNCzBRZDl77kGzaxg/4thofjuly.jpg";		//Background Image
	
	themeArray[11-1][0] = "refugeeLayout";			//Theme Name	
	themeArray[11-1][1] = "/ar/uploads/Zz/Fo/ZzFoCqpGzANgxhEfjXnUEg/refugees_bg.jpg";		//Background Image
	
	themeArray[12-1][0] = "jazz_americaLayout";			//Theme Name	
	themeArray[12-1][1] = "/ar/uploads/VU/l_/VUl_XT7m6OlJfBIl1Ma_0w/jazz.jpg";		//Background Image
	
	themeArray[13-1][0] = "see_youLayout";			//Theme Name	
	themeArray[13-1][1] = "/ar/uploads/CW/g1/CWg1TUWjOCGISnQoutpEHA/seeyou_inthe_usa_comp.jpg";		//Background Image
	
	themeArray[14-1][0] = "planting_treesLayout";			//Theme Name	
	themeArray[14-1][1] = "/ar/uploads/OD/k1/ODk1ClinSeqXuOKgADbnWw/trees_bg2.jpg";		//Background Image
	
	themeArray[15-1][0] = "huck_finnLayout";			//Theme Name	
	themeArray[15-1][1] = "/ar/uploads/ul/ML/ulMLpFCvziWLBCezVK1KXA/huck_finn_bg.jpg";		//Background Image
	
	themeArray[16-1][0] = "nuclear_strategyLayout";			//Theme Name	
	themeArray[16-1][1] = "/ar/uploads/if/b-/ifb-ZaNxKYBVMrBKHSPnqA/us_nukestrategy_horizontal2.jpg";		//Background Image
	
	themeArray[17-1][0] = "press_fredomLayout";			//Theme Name	
	themeArray[17-1][1] = "/ar/uploads/aG/-o/aG-ol7V91DPOgGHYodk_dA/journalism_background_DPF.jpg";		//Background Image
	
	themeArray[18-1][0] = "entrepreneurship_summitLayout";			//Theme Name	
	themeArray[18-1][1] = "/ar/uploads/nt/R1/ntR1zZ0gcuPQRa2TI1B_SQ/ent_summit_comp.jpg";		//Background Image
	
	themeArray[19-1][0] = "Michelle_ObamaLayout";			//Theme Name	
	themeArray[19-1][1] = "/ar/uploads/oe/I1/oeI1Pxnia46yTx5G7ECprg/michelleobama.jpg";		//Background Image
	
	themeArray[20-1][0] = "architecture_greenLayout";			//Theme Name	
	themeArray[20-1][1] = "/ar/uploads/Vf/hU/VfhUzDWA9fi6oOHNSpR5Cg/usarchitecturegoesgreen.jpg";		//Background Image
	
	themeArray[21-1][0] = "studentLifeLayout";			//Theme Name	
	themeArray[21-1][1] = "/ar/uploads/z8/mf/z8mfWrOsEc6kr73ozX8dRQ/Arabic-EducationExchange.jpg";		//Background Image
	
	themeArray[22-1][0] = "climate_waterLayout";			//Theme Name	
	themeArray[22-1][1] = "/ar/uploads/Fv/mY/FvmYOYSFlzTpslFb6vt4Gw/water_background.jpg";		//Background Image
	
	themeArray[23-1][0] = "cars_shift_greenLayout";			//Theme Name	
	themeArray[23-1][1] = "/ar/uploads/pj/nF/pjnFWsKZjrpvNue9ddisoQ/carsshifttogreen1.jpg";		//Background Image
	
	themeArray[24-1][0] = "wocLayout";			//Theme Name	
	themeArray[24-1][1] = "/ar/uploads/2w/Yh/2wYhbNdX4M1RsbdOPVJMPg/AR_feature_background2.jpg";		//Background Image
	
	themeArray[25-1][0] = "oprahLayout";			//Theme Name	
	themeArray[25-1][1] = "/ar/uploads/RT/6J/RT6JqnVyuG8BFjndi0BWrA/bg_template4.jpg";		//Background Image
	
	themeArray[26-1][0] = "women_govtLayout";			//Theme Name	
	themeArray[26-1][1] = "/ar/uploads/-f/Qw/-fQwQBuuvkYU5CL-tSHAFQ/Campaign-cracking.jpg";		//Background Image
	
	themeArray[27-1][0] = "piracyLayout";			//Theme Name	
	themeArray[27-1][1] = "/ar/uploads/uK/59/uK59dQOIgAXamyQrAx4aoQ/ar_combatingpiracy.jpg";		//Background Image
	
	themeArray[28-1][0] = "science_envoysLayout";			//Theme Name	
	themeArray[28-1][1] = "/ar/uploads/oB/gd/oBgdT0eGNJ38UfW9irJgsQ/bg_template.jpg";		//Background Image
	
	themeArray[29-1][0] = "religiousfreedomLayout";			//Theme Name	
	themeArray[29-1][1] = "/ar/uploads/Ft/DM/FtDMvePXPkZng80bfZU-9A/bg_draft3.jpg";		//Background Image
	
	themeArray[30-1][0] = "e-exchange_openLayout";			//Theme Name	
	themeArray[30-1][1] = "/ar/uploads/fW/1k/fW1kuswJYUFEnwiZzOk40Q/AR_whosright_bg-1.jpg";		//Background Image
	
	themeArray[31-1][0] = "notable_africanLayout";			//Theme Name	
	themeArray[31-1][1] = "/ar/uploads/08/eT/08eTQzQ_nXNrjJTxbvwkxg/black_american_bg.jpg";		//Background Image
	
	themeArray[32-1][0] = "bikesLayout";			//Theme Name	
	themeArray[32-1][1] = "/ar/uploads/x-/Zg/x-ZgpMWcQ8xinfJDBy8oVA/BikesfortheWorldar1.jpg";		//Background Image
	
	themeArray[33-1][0] = "black_histLayout";			//Theme Name	
	themeArray[33-1][1] = "/ar/uploads/hH/Ol/hHOl1OdDBWhnnuV9NeMx3g/black_history_bg.jpg";		//Background Image
	
	themeArray[34-1][0] = "awardsLayout";			//Theme Name	
	themeArray[34-1][1] = "/ar/uploads/BZ/s3/BZs3GmwtGBr9D9aJfnaV-w/2009awardsforexcellence_bg.jpg";		//Background Image
	
	themeArray[35-1][0] = "money_transfersLayout";			//Theme Name	
	themeArray[35-1][1] = "/ar/uploads/a2/0q/a20qv4bxxGJ4R3MWdrRdCg/remittances2.jpg";		//Background Image
	
	themeArray[36-1][0] = "infect_diseaseLayout";			//Theme Name	
	themeArray[36-1][1] = "/ar/uploads/q3/hZ/q3hZnKg0XwzB45hkvaRg3Q/campaign-disease3.jpg";		//Background Image
	
	themeArray[37-1][0] = "agriculturalLayout";			//Theme Name	
	themeArray[37-1][1] = "/ar/uploads/vt/7F/vt7FNxT5ENwDIvnQCVYL2g/agricultural_bg.jpg";		//Background Image
	
	themeArray[38-1][0] = "corruptionLayout";			//Theme Name	
	themeArray[38-1][1] = "/ar/uploads/cA/BG/cABGH8aMj-u1EOxevKKqVQ/anticorruption.jpg";		//Background Image
	
	themeArray[39-1][0] = "nuclearfreeworldLayout";			//Theme Name	
	themeArray[39-1][1] = "/ar/uploads/k_/OL/k_OLTUs6FgIUfA51kYEu2A/feature_bg.jpg";		//Background Image
	
	themeArray[40-1][0] = "food_securityLayout";			//Theme Name	
	themeArray[40-1][1] = "/ar/uploads/RG/oE/RGoE4qluX5EQooMdDXKcKA/foodsecurityBkgnd.jpg";		//Background Image
	
	themeArray[41-1][0] = "nobelpeaceLayout";			//Theme Name	
	themeArray[41-1][1] = "/ar/uploads/iG/ez/iGezY96n9Xl48QoVElbxIw/obama_bg.jpg";		//Background Image
	
	themeArray[42-1][0] = "foiaLayout";			//Theme Name	
	themeArray[42-1][1] = "/ar/uploads/Nj/Hj/NjHj0NZGMhfjb1g1kN8wDQ/freedomofinformationact.jpg";		//Background Image
	
	themeArray[43-1][0] = "spaceLayout";			//Theme Name	
	themeArray[43-1][1] = "/ar/uploads/Lf/t7/Lft7C_L3n4QJCOqxwclJMQ/space3.jpg";		//Background Image
	
	themeArray[44-1][0] = "community_collegeLayout";			//Theme Name	
	themeArray[44-1][1] = "/ar/uploads/Ph/wa/PhwaG_DrFrJjiIBsTweicw/AR_community-colleges3.jpg";		//Background Image
	
	themeArray[45-1][0] = "ungaLayout";			//Theme Name	
	themeArray[45-1][1] = "/ar/uploads/Mb/Y4/MbY46FmJmeW8yVa0TiaN5g/TheUSandUN2-bkgd2.jpg";		//Background Image
	
	themeArray[46-1][0] = "exploringmarsLayout";			//Theme Name	
	themeArray[46-1][1] = "/ar/uploads/D3/7O/D37O-zqrjXrQJjeC8Pph5Q/mars3.jpg";		//Background Image
	
	themeArray[47-1][0] = "anatomyofajuryLayout";			//Theme Name	
	themeArray[47-1][1] = "/ar/uploads/rI/1o/rI1oRjYzA3Q6_yWeDlxJwA/AnatomyofaJury.jpg";		//Background Image
	
	themeArray[48-1][0] = "middleeastpeaceLayout";			//Theme Name	
	themeArray[48-1][1] = "/ar/uploads/ng/fO/ngfOMw3Hsj9FYwRHKz097Q/mideast-peace-arabic2-bkgd.jpg";		//Background Image
	
	themeArray[49-1][0] = "constitution_arLayout";			//Theme Name	
	themeArray[49-1][1] = "/ar/uploads/ce/sa/cesahBUQrGvICCIo59V8Kg/AR_constitution3_new.jpg";		//Background Image
	
	themeArray[50-1][0] = "un_declarationLayout";			//Theme Name	
	themeArray[50-1][1] = "/ar/uploads/ZM/6R/ZM6RNWIKELGxlF7B2G08Kw/AR_UN_declaration2.jpg";		//Background Image
	
	themeArray[51-1][0] = "gitmo_arLayout";			//Theme Name	
	themeArray[51-1][1] = "/ar/uploads/K_/W-/K_W-jL2bx0zPTzPEfg2ESw/AR_guantanamo_layout2_ar.jpg";		//Background Image
	
	themeArray[52-1][0] = "usaid_me_arLayout";			//Theme Name	
	themeArray[52-1][1] = "/ar/uploads/vt/Hu/vtHu0zdlcTIERfehu-wGVg/AR_usaid_bkgd_ar.jpg";		//Background Image
	
	themeArray[53-1][0] = "identity_arLayout";			//Theme Name	
	themeArray[53-1][1] = "/ar/uploads/SA/T-/SAT-PmVjkqpNG2dQVmj95w/AR_Identity.jpg";		//Background Image
	
	themeArray[54-1][0] = "tracking_h1n1_arLayout";			//Theme Name	
	themeArray[54-1][1] = "/ar/uploads/4B/7x/4B7x0Es5kKgbIhBYGYxi1w/AR_swineflu-bkgd1.jpg";		//Background Image
	
	themeArray[55-1][0] = "flushingLayout";			//Theme Name	
	themeArray[55-1][1] = "/ar/uploads/3P/Cj/3PCjLTFVWIc0e54hg-k2gQ/ar_flushing_bkgnd.jpg";		//Background Image
	
	themeArray[56-1][0] = "climate_change_arLayout";			//Theme Name	
	themeArray[56-1][1] = "/ar/uploads/-r/tb/-rtbSGKHi3cVB0OQRgrjaA/AR_Campaign-changing-climate3.jpg";		//Background Image
	
	themeArray[57-1][0] = "obama_cairo_arLayout";			//Theme Name	
	themeArray[57-1][1] = "/ar/uploads/Su/9W/Su9WWcyhponWxdYLoKKX5A/AR_cairo_bkgd.jpg";		//Background Image
	
	themeArray[58-1][0] = "gone_wind_arLayout";			//Theme Name	
	themeArray[58-1][1] = "/ar/uploads/Ya/Zi/YaZiwliwo-oPq-5BQrC6tQ/ARCampaign-gonerebuilt.jpg";		//Background Image
	
	themeArray[59-1][0] = "women_courage_arLayout";			//Theme Name	
	themeArray[59-1][1] = "/ar/uploads/Xg/Nv/XgNvk_3cEgkhA6spCBRrEw/AR_womenofcourage.jpg";		//Background Image
	
	themeArray[60-1][0] = "obama_arLayout";			//Theme Name	
	themeArray[60-1][1] = "/ar/uploads/cr/bv/crbvoVmh_-NYtscRUDyUoA/AR_MeetBarackObama.jpg";		//Background Image
	
	themeArray[61-1][0] = "lincoln_arLayout";			//Theme Name	
	themeArray[61-1][1] = "/ar/uploads/zu/7S/zu7S9garJ8WWtb2aiJmf5A/AR_abraham-lincoln-625.jpg";		//Background Image
	
	themeArray[62-1][0] = "top_univ_arLayout";			//Theme Name	
	themeArray[62-1][1] = "/ar/uploads/x3/MJ/x3MJ4rorg4i0KOYBZTzliw/AR_University_bkgd.jpg";		//Background Image
	
	themeArray[63-1][0] = "Iraq_withdrawal_arLayout";			//Theme Name	
	themeArray[63-1][1] = "/ar/uploads/-e/bJ/-ebJnvpkhkE3xd1epp4q-Q/IraqWith_layout_ar.jpg";		//Background Image
	
	themeArray[64-1][0] = "reviving_trade_arLayout";			//Theme Name	
	themeArray[64-1][1] = "/ar/uploads/Cw/g3/Cwg3ploToiCG1q8u1uGZmg/AR_tradefinance2.jpg";		//Background Image
	
	themeArray[65-1][0] = "cabinet_arLayout";			//Theme Name	
	themeArray[65-1][1] = "/ar/uploads/3Y/XY/3YXYKdFLpzhsZzevA4quxw/AR_TheCabinet.jpg";		//Background Image
	
	themeArray[66-1][0] = "identityLayout";			//Theme Name	
	themeArray[66-1][1] = "/ar/uploads/kG/oT/kGoTQQW2Tx_Xf_H4F3rNsw/AR_Identity.jpg";		//Background Image
	
	
	
	for(i=0;i<counter;i++)		
		if(themeName == themeArray[i][0]) {			
			var bckImg = document.getElementById(elementId);
			var ifImage = bckImg.getElementsByTagName('img');
			if(ifImage.length > 0)
				bckImg.removeChild(ifImage[0])
			var newImg = document.createElement('img');
			newImg.setAttribute('src',themeArray[i][1]);
			newImg.setAttribute('style','z-index:0;position:relative;top:0px;left:0px;');
			newImg.setAttribute('width',bckImgWidth);
			//imgHeight = (bckImgWidth < 500) ? '33%' : '100%';	
			newImg.setAttribute('height','*');			
			bckImg.appendChild(newImg);
		}
}


//################################################################################
//#			NAME: 		expandParent
//#			CALLED BY: 	Page Layout Manager (Thread)
//#			PURPOSE:	Resizes the containing element to allow all of the
//#						absolutely positioned items to not overflow
//################################################################################
function expandParent(parentEl) {
	var parentEl = document.getElementById(parentEl);
	var childEl = parentEl.getElementsByTagName('div');  
	var childImg = parentEl.getElementsByTagName('img');
	var dynaCells = new Array();
	var counter = 1;
	var finalVal = 0;
	var isProduction = 0;
	
	for(i=0;i<childEl.length;i++) {
		if(childEl[i].id.indexOf('dyna') != -1) isProduction = 1;
		if(childEl[i].className.indexOf('Layout') != -1) parentEl = childEl[i];
	}
			
	
	if(isProduction) {
		counter = 0;
		for(i=0;i<childEl.length;i++) {
			dynaCells[counter] = childEl[i].offsetTop + childEl[i].offsetHeight;
			counter++
		}
		counter = 1;
		
		for(i=0;i<dynaCells.length;i++) {
			if(i==dynaCells.length-1)
				counter = 0;
			
			if(dynaCells[i] >= dynaCells[counter]) {
				if(dynaCells[i] > finalVal)
					finalVal = dynaCells[i]
				
				//alert(i + "- " + dynaCells[i] + " vs." + dynaCells[counter] + " = " + finalVal);
			}
		}	

	}
	else {
		for(i=0;i<childEl.length;i++) {
			if(i==childEl.length - 1)
				counter = 0;
	
			if(childEl[i].offsetTop + childEl[i].offsetHeight > childEl[counter].offsetTop + childEl[counter].offsetHeight)
				finalVal = childEl[i].offsetTop + childEl[i].offsetHeight;
				
			counter++;			
		}
	}


	if(!isProduction)
		for(i=0;i<childImg.length;i++) {
			if(i==childImg.length -1)
				counter = 0;
				
			if(childImg[i].offsetHeight > finalVal) {
				finalVal = childImg[i].offsetHeight;		
				
			}
		}

	/*parentEl.setAttribute("style", "min-height:" + (finalVal + 16) + "px;height:auto !important;height:" + (finalVal + 16) + "px");
	parentEl.style.height = finalVal + 16 + "px";*/
}


//################################################################################
//#			NAME: 		macroLayout
//#			CALLED BY: 	Page Layout Manager (Thread)
//#			PURPOSE:	Positions the layout squares based on the info provided
//#						via the Post Form
//################################################################################
function macroLayout(posValues,itemId) {
	var itemId = document.getElementById(itemId);
	if(posValues != '') {
		var posArray = posValues.split(",");
		itemId.style.top = posArray[0] + "px";
		itemId.style.left = posArray[1] + "px";
		itemId.style.width = posArray[2] + "px";
		itemId.style.display = "block";	
	}	
}


//################################################################################
//#			NAME: 		initializeDelete
//#			CALLED BY: 	Page Layout Manager (Thread)
//#			PURPOSE:	Takes the 'confirmDelete' box from the template, clones it
//#						removes the original and then attaches the clone to the 
//#						body of the document. This allows the box to be centered
//#						on the page no matter what layout is used. It also creates
//#						the dropshadow div.
//################################################################################
function intializeDelete() {
	var newDiv = document.createElement('div');
	var confirmDelete = document.getElementById('confirmDelete');
	var confirmClone = confirmDelete.cloneNode(true);
	
	newDiv.setAttribute('id','overlay');
	newDiv.setAttribute('style','display:none');		
	document.body.appendChild(newDiv);	
	
	confirmDelete.parentNode.removeChild(confirmDelete);
	document.body.appendChild(confirmClone);
}



//################################################################################
//#			NAME: 		confirmDelete
//#			CALLED BY: 	Page Layout Manager (Thread)
//#			PURPOSE:	Handles the appearance of the confirmDelete box and its
//#						dropshadow
//################################################################################
function confirmDelete(titleVal) {
	var confirmDelete = document.getElementById('confirmDelete');
	var deleteMessage = document.getElementById('deleteMessage');
	var overlayDiv = document.getElementById('overlay');
	deleteMessage.innerHTML = "Are you sure you wish to delete " + titleVal + "?";
	
	overlayDiv.style.display = "block";
	confirmDelete.style.display = "block";
	
	overlayDiv.style.width = confirmDelete.offsetWidth + "px";
	overlayDiv.style.height = confirmDelete.offsetHeight + "px";
			
	confirmDelete.style.left = ((document.body.clientWidth / 2) - (confirmDelete.offsetWidth / 2)) + "px";
	confirmDelete.style.top = ((document.body.clientHeight / 2) - confirmDelete.offsetHeight) + "px";
	overlayDiv.style.left = eval(x=confirmDelete.style.left.split('p')[0]) + 5 + "px";
	overlayDiv.style.top = eval(x=confirmDelete.style.top.split('p')[0]) + 5 + "px";

}


function addLayoutLink() {
	var usedLayouts = new Array("identityLayout","constitution_arLayout","cabinet_arLayout","reviving_trade_arLayout","gone_wind_arLayout","Iraq_withdrawal_arLayout","climate_change_arLayout","obama_cairo_arLayout","top_univ_arLayout","lincoln_arLayout","obama_arLayout","women_courage_arLayout","tracking_h1n1_arLayout","flushingLayout","identity_arLayout","un_declarationLayout","gitmo_arLayout","usaid_me_arLayout","middleeastpeaceLayout","anatomyofajuryLayout","exploringmarsLayout","ungaLayout","community_collegeLayout","spaceLayout","foiaLayout","food_securityLayout","nobelpeaceLayout","corruptionLayout","nuclearfreeworldLayout","money_transfersLayout","infect_diseaseLayout","agriculturalLayout","2009_awardsLayout","awardsLayout","black_histLayout","e-exchange_openLayout","religiousfreedomLayout","science_envoysLayout","women_govtLayout","bikesLayout","piracyLayout","wocLayout","oprahLayout","cars_shift_greenLayout","climate_waterLayout","architecture_greenLayout","studentLifeLayout","Michelle_ObamaLayout","entrepreneurship_summitLayout","press_fredomLayout","nuclear_strategyLayout","huck_finnLayout","planting_treesLayout","Digital_libraryLayout","see_youLayout","jazz_americaLayout","refugeeLayout","july4thLayout","usg_clickLayout","preserving_cultureLayout","passportLayout","multicultural_RamadanLayout","defining_internetLayout","ramadan_communityLayout","you_askedLayout");		//Supplies the populated usedLayouts array
	var themeNames = new Array("Theme ManagerLayout","identityLayout","constitution_arLayout","cabinet_arLayout","reviving_trade_arLayout","gone_wind_arLayout","Iraq_withdrawal_arLayout","climate_change_arLayout","obama_cairo_arLayout","top_univ_arLayout","lincoln_arLayout","obama_arLayout","women_courage_arLayout","tracking_h1n1_arLayout","flushingLayout","identity_arLayout","un_declarationLayout","gitmo_arLayout","usaid_me_arLayout","middleeastpeaceLayout","anatomyofajuryLayout","exploringmarsLayout","ungaLayout","community_collegeLayout","spaceLayout","foiaLayout","food_securityLayout","nobelpeaceLayout","corruptionLayout","nuclearfreeworldLayout","money_transfersLayout","infect_diseaseLayout","agriculturalLayout","awardsLayout","black_histLayout","bikesLayout","notable_africanLayout","e-exchange_openLayout","religiousfreedomLayout","science_envoysLayout","women_govtLayout","piracyLayout","oprahLayout","wocLayout","cars_shift_greenLayout","climate_waterLayout","architecture_greenLayout","studentLifeLayout","Michelle_ObamaLayout","entrepreneurship_summitLayout","press_fredomLayout","nuclear_strategyLayout","huck_finnLayout","planting_treesLayout","Digital_libraryLayout","see_youLayout","jazz_americaLayout","refugeeLayout","july4thLayout","usg_clickLayout","preserving_cultureLayout","passportLayout","multicultural_RamadanLayout","defining_internetLayout","ramadan_communityLayout","you_askedLayout","dissentLayout");		//Supplies the populated themeNames array
	
	var isUsed = 0;	
	
	for(i=1;i<themeNames.length;i++) {
		for(x=0;x<usedLayouts.length;x++)
			if(themeNames[i] == usedLayouts[x])	{	
				document.getElementById(usedLayouts[x] + 'Id').innerHTML = "<a href='/ar/page-layout-manager/page-layout-manager/" + usedLayouts[x].toLowerCase() +"?func=edit'  class='editLayout' target='_blank'>Edit Layout</a>";	
				isUsed = 1;
			}
		if(!isUsed)	
			document.getElementById(themeNames[i] + 'Id').innerHTML = "<a href='/ar/page-layout-manager/page-layout-manager.html?func=add;class=WebGUI::Asset::Post::Thread' class='addLayout'>Add a Layout</a>";
			
		isUsed = 0;			
	}	
}









