//################################################################################
//#			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("nato_psLayout","disaster_warning_psLayout","pictures_iran_psLayout","meet_obama_psLayout","constitution_psLayout","community_coll_psLayout","top_universities_psLayout","altern_violence_psLayout","journalism_psLayout","declaration_hr_psLayout","new_beginning_mus_psLayout","american_indian_art_psLayout","go_north_psLayout","land_o_lakes_psLayout","cabinet_psLayout","lincoln_psLayout","women_in_govt_psLayout","alternative_energy_psLayout","disease_surveillance_psLayout","climate_change_psLayout","vanishing_act_psLayout","rust_belt_psLayout","flushing_psLayout","beating_aids_psLayout","identity_psLayout","mars_psLayout","anti_corruption_psLayout","protecting_oceans_psLayout","us_china_rel_psLayout","gone_with_wind_psLayout","gonorthtrainingLayout","usun_psLayout","capcompareLayout","Capitalism3Layout","Theme ManagerLayout","capitalismLayout","engineerLayout","parkLayout","journalismsiegeLayout","h1n1fluLayout","poetryLayout","foodsecurityLayout","imagesiranLayout","reviveLayout","anatomyofajuryLayout","digitallibraryLayout","nanotechnologyLayout","architecturegreenLayout","foiaLayout","ThreadLayout","ramadanLayout","nobelpeaceLayout","nuclearfreeworldLayout","cairoLayout","michelleobamaLayout","corruptionLayout","womencourageLayout","carsshifttogreenLayout","aceLayout","searchandrescueLayout","bikesLayout","nuclearLayout","july4thLayout","smartgridLayout","newconsumerLayout","evolvingdemocracyLayout","G8-summitLayout","woc2010Layout","helping-grilsLayout","oprahLayout","cybersecurityLayout","esummitLayout","asian_novelLayout","agriculturalLayout","nikeLayout","youasked_diversityLayout","preservingcultureLayout","jazzLayout","internet_freedomLayout","michelle_obama_mexicoLayout","ThreadLayout","exchange4Layout","eastmeetswestLayout","refugeesLayout","marktwainabroadLayout","refugees01Layout","plantingtreesLayout","usscienceenvoysLayout","seeyouusaLayout","usg_clickLayout","dancerssoarLayout","internetfreedomLayout","spaceLayout","ccpartnershipsLayout","guptaLayout","refugees_ejLayout");		//Supplies the populated themeNames array
	var usedLayouts = new Array("nato_psLayout","disaster_warning_psLayout","altern_violence_psLayout","declaration_hr_psLayout","go_north_psLayout","community_coll_psLayout","constitution_psLayout","land_o_lakes_psLayout","cabinet_psLayout","lincoln_psLayout","women_in_govt_psLayout","meet_obama_psLayout","alternative_energy_psLayout","disease_surveillance_psLayout","climate_change_psLayout","rust_belt_psLayout","flushing_psLayout","top_universities_psLayout","vanishing_act_psLayout","beating_aids_psLayout","american_indian_art_psLayout","identity_psLayout","mars_psLayout","anti_corruption_psLayout","protecting_oceans_psLayout","us_china_rel_psLayout","gone_with_wind_psLayout","gonorthtrainingLayout","usun_psLayout","capcompareLayout","capitalismLayout","engineerLayout","parkLayout","journalismsiegeLayout","h1n1fluLayout","poetryLayout","foodsecurityLayout","imagesiranLayout","reviveLayout","anatomyofajuryLayout","nanotechnologyLayout","architecturegreenLayout","digitallibraryLayout","foiaLayout","ramadanLayout","nobelpeaceLayout","nuclearfreeworldLayout","cairoLayout","michelleobamaLayout","corruptionLayout","michelleobamaLayout","womencourageLayout","carsshifttogreenLayout","aceLayout","searchandrescueLayout","nuclearLayout","bikesLayout","july4thLayout","smartgridLayout","newconsumerLayout","evolvingdemocracyLayout","G8-summitLayout","woc2010Layout","helping-grilsLayout","oprahLayout","cybersecurityLayout","esummitLayout","asian_novelLayout","agriculturalLayout","agriculturalLayout","nikeLayout","youasked_diversityLayout","preservingcultureLayout","jazzLayout","internet_freedomLayout","michelle_obama_mexicoLayout","exchange4Layout","eastmeetswestLayout","refugeesLayout","marktwainabroadLayout","refugees01Layout","plantingtreesLayout","usscienceenvoysLayout","seeyouusaLayout","usg_clickLayout","dancerssoarLayout","internetfreedomLayout","spaceLayout","ccpartnershipsLayout","guptaLayout","refugees_ejLayout");		//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 = 95;
	var themeArray = new Array(95);
	var imgHeight;
			
	for(i=0;i<counter;i++)
		themeArray[i] = new Array(2);
			
	
	themeArray[1-1][0] = "refugees_ejLayout";			//Theme Name	
	themeArray[1-1][1] = "/persian/uploads/Dj/6-/Dj6-6TpW45Spa6qfBdLtHg/refugees_bg_FA.jpg";		//Background Image
	
	themeArray[2-1][0] = "guptaLayout";			//Theme Name	
	themeArray[2-1][1] = "/persian/uploads/k6/Zr/k6Zr-a7l9_u_OG0TVrotMw/gupta_bg_fa.jpg";		//Background Image
	
	themeArray[3-1][0] = "ccpartnershipsLayout";			//Theme Name	
	themeArray[3-1][1] = "/persian/uploads/kR/y_/kRy_tYlqmjL6KTyuhfB2Qg/climate_bg_fa.JPG";		//Background Image
	
	themeArray[4-1][0] = "spaceLayout";			//Theme Name	
	themeArray[4-1][1] = "/persian/uploads/w0/4F/w04FEG5cKVr2vie8XnjVcQ/space.jpg";		//Background Image
	
	themeArray[5-1][0] = "internetfreedomLayout";			//Theme Name	
	themeArray[5-1][1] = "/persian/uploads/30/6g/306gYdSIvqrxA7tQ9GBJFA/internet_freedom_fa.jpg";		//Background Image
	
	themeArray[6-1][0] = "dancerssoarLayout";			//Theme Name	
	themeArray[6-1][1] = "/persian/uploads/Md/DA/MdDAOhQUBIU4nw9_K3O7nQ/underafricanskies_comp_fa.JPG";		//Background Image
	
	themeArray[7-1][0] = "usg_clickLayout";			//Theme Name	
	themeArray[7-1][1] = "/persian/uploads/ac/jY/acjYkBdStIcrDWoqJydVwA/USGattheClick_FA.jpg";		//Background Image
	
	themeArray[8-1][0] = "seeyouusaLayout";			//Theme Name	
	themeArray[8-1][1] = "/persian/uploads/kb/fS/kbfS89Xav-t5VJY9xDWDNA/seeyou_inthe_usa_fa.jpg";		//Background Image
	
	themeArray[9-1][0] = "usscienceenvoysLayout";			//Theme Name	
	themeArray[9-1][1] = "/persian/uploads/um/0x/um0xrsF5jNG3TmyS8jlKuw/bg_template_fa.jpg";		//Background Image
	
	themeArray[10-1][0] = "plantingtreesLayout";			//Theme Name	
	themeArray[10-1][1] = "/persian/uploads/Ef/fP/EffPmHIgd6LIaQt8jDeHZQ/trees_bg_fa.jpg";		//Background Image
	
	themeArray[11-1][0] = "refugees01Layout";			//Theme Name	
	themeArray[11-1][1] = "/persian/uploads/Ig/Lm/IgLm44jj61h6OzHGSt17Lg/refugees_bg_FA.jpg";		//Background Image
	
	themeArray[12-1][0] = "refugeesLayout";			//Theme Name	
	themeArray[12-1][1] = "/persian/uploads/av/DM/avDMJJOmOA5wZX7KMpS0qw/refugees_bg_FA.jpg";		//Background Image
	
	themeArray[13-1][0] = "marktwainabroadLayout";			//Theme Name	
	themeArray[13-1][1] = "/persian/uploads/qj/bA/qjbAcf7zUoACIGp8TGJxPQ/MT_abroad_bg_blank.jpg";		//Background Image
	
	themeArray[14-1][0] = "eastmeetswestLayout";			//Theme Name	
	themeArray[14-1][1] = "/persian/uploads/xR/2d/xR2dyZhIBIA93WXH8GpX5w/eastmeetswest_comp_fa.jpg";		//Background Image
	
	themeArray[15-1][0] = "untitledLayout";			//Theme Name	
	themeArray[15-1][1] = "";		//Background Image
	
	themeArray[16-1][0] = "exchange4Layout";			//Theme Name	
	themeArray[16-1][1] = "/persian/uploads/dO/3d/dO3dDIrxJB6qmfOSg_bQyA/pubs_exchange4_bg_FA.jpg";		//Background Image
	
	themeArray[17-1][0] = "agriculturalLayout";			//Theme Name	
	themeArray[17-1][1] = "/persian/uploads/hH/QQ/hHQQmqIJudHn2yum3jQgCQ/agricultural_ed_feature_background_FA.jpg";		//Background Image
	
	themeArray[18-1][0] = "michelle_obama_mexicoLayout";			//Theme Name	
	themeArray[18-1][1] = "/persian/uploads/ki/ZY/kiZYgcwkQspWR6z3NwbkYA/mo_mexico_FA.jpg";		//Background Image
	
	themeArray[19-1][0] = "internet_freedomLayout";			//Theme Name	
	themeArray[19-1][1] = "/persian/uploads/Go/TA/GoTATyOBh6TMzHbOQ1L35g/regional_header_FA.jpg";		//Background Image
	
	themeArray[20-1][0] = "jazzLayout";			//Theme Name	
	themeArray[20-1][1] = "/persian/uploads/LK/cf/LKcfsuJyXSoswk8Zbu9KUQ/jazz_fa.jpg";		//Background Image
	
	themeArray[21-1][0] = "preservingcultureLayout";			//Theme Name	
	themeArray[21-1][1] = "/persian/uploads/Kz/0j/Kz0j4tGltrDy5H3c4_aDWw/bg_cultural_heritage_fa.jpg";		//Background Image
	
	themeArray[22-1][0] = "youasked_diversityLayout";			//Theme Name	
	themeArray[22-1][1] = "/persian/uploads/ch/00/ch00XuPqlSivb7C3ofbRcw/bg_comp_fa.jpg";		//Background Image
	
	themeArray[23-1][0] = "nikeLayout";			//Theme Name	
	themeArray[23-1][1] = "/persian/uploads/Ml/VZ/MlVZURb1w8IJzqkTQ2krFA/AmericanIndiansinBusinessFa.jpg";		//Background Image
	
	themeArray[24-1][0] = "asian_novelLayout";			//Theme Name	
	themeArray[24-1][1] = "/persian/uploads/Tm/SG/TmSGWDV3oTCzl2qR_UD-RQ/graphic-novels_FA.jpg";		//Background Image
	
	themeArray[25-1][0] = "esummitLayout";			//Theme Name	
	themeArray[25-1][1] = "/persian/uploads/0I/s5/0Is5a5WWCdP-IfenYATBDA/ent_summit_comp.jpg";		//Background Image
	
	themeArray[26-1][0] = "cybersecurityLayout";			//Theme Name	
	themeArray[26-1][1] = "/persian/uploads/Pq/RW/PqRWZXRng_eBcXEwzO3grQ/cyber_security_fa.jpg";		//Background Image
	
	themeArray[27-1][0] = "oprahLayout";			//Theme Name	
	themeArray[27-1][1] = "/persian/uploads/Bu/QC/BuQCXaSzyASLbbiy4Q3_aA/oprah_bg_FA.jpg";		//Background Image
	
	themeArray[28-1][0] = "helping-grilsLayout";			//Theme Name	
	themeArray[28-1][1] = "/persian/uploads/_X/um/_XumeCeml_IrDwUc9lJOEA/girls_edu_bg_FA.jpg";		//Background Image
	
	themeArray[29-1][0] = "woc2010Layout";			//Theme Name	
	themeArray[29-1][1] = "/persian/uploads/Om/un/Omun3DeG_7dWIBiT546v7Q/feature_background_fa.jpg";		//Background Image
	
	themeArray[30-1][0] = "G8-summitLayout";			//Theme Name	
	themeArray[30-1][1] = "/persian/uploads/3v/D6/3vD6PY9T70k2He_Vlwb16Q/G8Summit-FA.jpg";		//Background Image
	
	themeArray[31-1][0] = "evolvingdemocracyLayout";			//Theme Name	
	themeArray[31-1][1] = "/persian/uploads/yq/Qa/yqQa2lxrDK5hEZgMxLlemA/democracy_bg_fa.jpg";		//Background Image
	
	themeArray[32-1][0] = "newconsumerLayout";			//Theme Name	
	themeArray[32-1][1] = "/persian/uploads/Yr/ti/YrtiS0yA9t9PnK_33kTgxQ/NewConsumerFa.jpg";		//Background Image
	
	themeArray[33-1][0] = "smartgridLayout";			//Theme Name	
	themeArray[33-1][1] = "/persian/uploads/Dv/Vj/DvVjajm126VXQUgQlk3HEg/smartgrid_bkgd_FA-.jpg";		//Background Image
	
	themeArray[34-1][0] = "july4thLayout";			//Theme Name	
	themeArray[34-1][1] = "/persian/uploads/0Q/gJ/0QgJyANty8GzhwAuoz0N_g/4thofjuly_fa.jpg";		//Background Image
	
	themeArray[35-1][0] = "nuclearLayout";			//Theme Name	
	themeArray[35-1][1] = "/persian/uploads/So/VL/SoVLPwvYB_GeIUALH-rxoQ/whosright_bg_FA.jpg";		//Background Image
	
	themeArray[36-1][0] = "bikesLayout";			//Theme Name	
	themeArray[36-1][1] = "/persian/uploads/fT/yI/fTyIgQuC4rF68PIUSzeOXA/BikesfortheWorld2_fa.jpg";		//Background Image
	
	themeArray[37-1][0] = "searchandrescueLayout";			//Theme Name	
	themeArray[37-1][1] = "/persian/uploads/s8/6l/s86ljeQNw7cbI3CX27M0yA/searchandrescue1_fa.jpg";		//Background Image
	
	themeArray[38-1][0] = "aceLayout";			//Theme Name	
	themeArray[38-1][1] = "/persian/uploads/LG/z1/LGz1PJGxKdfQuxHACeHing/2009awardsforexcellence_FA.jpg";		//Background Image
	
	themeArray[39-1][0] = "carsshifttogreenLayout";			//Theme Name	
	themeArray[39-1][1] = "/persian/uploads/1l/2o/1l2oRN2Gqgiq1KZ9DPuDew/carsshifttogreen_fa.jpg";		//Background Image
	
	themeArray[40-1][0] = "womencourageLayout";			//Theme Name	
	themeArray[40-1][1] = "/persian/uploads/br/RK/brRKY9P5o1LjHt8rc8lfRQ/womenofcourage_FA.jpg";		//Background Image
	
	themeArray[41-1][0] = "corruptionLayout";			//Theme Name	
	themeArray[41-1][1] = "/persian/uploads/gs/hN/gshNSXcLt-SqKsZDhB4f0g/anticorruption_FA.jpg";		//Background Image
	
	themeArray[42-1][0] = "michelleobamaLayout";			//Theme Name	
	themeArray[42-1][1] = "/persian/uploads/9W/cS/9WcSvxJHaQ1Ad8O9pgdbQQ/michelleobama_fa.jpg";		//Background Image
	
	themeArray[43-1][0] = "cairoLayout";			//Theme Name	
	themeArray[43-1][1] = "/persian/uploads/68/vp/68vp_AtRqtzILKiISCHoOQ/cairo.jpg";		//Background Image
	
	themeArray[44-1][0] = "nuclearfreeworldLayout";			//Theme Name	
	themeArray[44-1][1] = "/persian/uploads/_m/GL/_mGLPQ6jNw5PeXC-o_HEpQ/feature_bg_FA.jpg";		//Background Image
	
	themeArray[45-1][0] = "nobelpeaceLayout";			//Theme Name	
	themeArray[45-1][1] = "/persian/uploads/cO/Wg/cOWg-A4uIbTNN4co_kw9jA/obama_bg_FA.jpg";		//Background Image
	
	themeArray[46-1][0] = "ramadanLayout";			//Theme Name	
	themeArray[46-1][1] = "/persian/uploads/by/n3/byn35U2HRjdsaczxdPX8FQ/ramadan_layout_FA.jpg";		//Background Image
	
	themeArray[47-1][0] = "untitledLayout";			//Theme Name	
	themeArray[47-1][1] = "";		//Background Image
	
	themeArray[48-1][0] = "foiaLayout";			//Theme Name	
	themeArray[48-1][1] = "/persian/uploads/Kz/BL/KzBLz1EQiWU4Iv_P30z6rA/freedomofinformationact_FA.jpg";		//Background Image
	
	themeArray[49-1][0] = "digitallibraryLayout";			//Theme Name	
	themeArray[49-1][1] = "/persian/uploads/dR/Kk/dRKkcVsCigHMjkux7U6plw/digitallibrary_FA.jpg";		//Background Image
	
	themeArray[50-1][0] = "architecturegreenLayout";			//Theme Name	
	themeArray[50-1][1] = "/persian/uploads/U0/bq/U0bqY9R8mRXDCBTmn-TM6g/usarchitecturegoesgreen_FA.jpg";		//Background Image
	
	themeArray[51-1][0] = "nanotechnologyLayout";			//Theme Name	
	themeArray[51-1][1] = "/persian/uploads/kq/Gu/kqGu7GoPyz6eyVZC4ia3ZA/ScienceandArtofNanotechnology-FA.jpg";		//Background Image
	
	themeArray[52-1][0] = "anatomyofajuryLayout";			//Theme Name	
	themeArray[52-1][1] = "/persian/uploads/B7/do/B7doEAGaXVB89qVzlA2ZsQ/AnatomyofaJury_FA.jpg";		//Background Image
	
	themeArray[53-1][0] = "reviveLayout";			//Theme Name	
	themeArray[53-1][1] = "/persian/uploads/Id/aN/IdaNX3ys6pKElJZmjaS_tQ/FA-tradefinance2.jpg";		//Background Image
	
	themeArray[54-1][0] = "imagesiranLayout";			//Theme Name	
	themeArray[54-1][1] = "/persian/uploads/p7/mB/p7mBLgY_PJIgpsd1J_cJeA/FA_iran2_bkgd.jpg";		//Background Image
	
	themeArray[55-1][0] = "foodsecurityLayout";			//Theme Name	
	themeArray[55-1][1] = "/persian/uploads/gj/fw/gjfwFikE00KUOaAIaCRDhw/foodsecurityBkgnd_FA.jpg";		//Background Image
	
	themeArray[56-1][0] = "poetryLayout";			//Theme Name	
	themeArray[56-1][1] = "/persian/uploads/By/2f/By2fN1T2p__VeNRcoDg4WA/slampoetry-FA.jpg";		//Background Image
	
	themeArray[57-1][0] = "h1n1fluLayout";			//Theme Name	
	themeArray[57-1][1] = "/persian/uploads/-R/lJ/-RlJTQhVai6GlNFETRgSoA/FA-swineflu-bkgd1.jpg";		//Background Image
	
	themeArray[58-1][0] = "journalismsiegeLayout";			//Theme Name	
	themeArray[58-1][1] = "/persian/uploads/kC/mm/kCmmrQyVnFlTxZhhJ7ngIw/FA_Campaign-journaism3_bkgd.jpg";		//Background Image
	
	themeArray[59-1][0] = "parkLayout";			//Theme Name	
	themeArray[59-1][1] = "/persian/uploads/GW/DK/GWDKoxDLhb0Cs9FnRzEo9w/Campaign-passports-FA.jpg";		//Background Image
	
	themeArray[60-1][0] = "usun_psLayout";			//Theme Name	
	themeArray[60-1][1] = "/persian/uploads/gT/zA/gTzAeI0Yyh130FTx6OUPaA/TheUSandUN2_FA.jpg";		//Background Image
	
	themeArray[61-1][0] = "engineerLayout";			//Theme Name	
	themeArray[61-1][1] = "/persian/uploads/fF/pZ/fFpZzpHYM4mF4J9LupwwWw/globalengineering-FA-copy.jpg";		//Background Image
	
	themeArray[62-1][0] = "capitalismLayout";			//Theme Name	
	themeArray[62-1][1] = "/persian/uploads/sG/XO/sGXOCX2KZLfRX0m9D6q7bA/cFA-contrastincapitalism2.jpg";		//Background Image
	
	themeArray[63-1][0] = "Capitalism3Layout";			//Theme Name	
	themeArray[63-1][1] = "/persian/uploads/BB/XU/BBXUPTLNK_oPG-TuE9JtCA/cFA-contrastincapitalism2.jpg";		//Background Image
	
	themeArray[64-1][0] = "capcompareLayout";			//Theme Name	
	themeArray[64-1][1] = "/persian/uploads/kj/5B/kj5BBzwZFH_AS6lNrIq-9A/FA-contrastincapitalism2.jpg";		//Background Image
	
	themeArray[65-1][0] = "gonorthtrainingLayout";			//Theme Name	
	themeArray[65-1][1] = "/persian/uploads/M6/vP/M6vProuQCF3-KcktcuyZGQ/FA-go_north.jpg";		//Background Image
	
	themeArray[66-1][0] = "gone_with_wind_psLayout";			//Theme Name	
	themeArray[66-1][1] = "/persian/uploads/kV/WA/kVWAIjXuaQESVmpHd9_hCQ/FA-Campaign-gonerebuilt.jpg";		//Background Image
	
	themeArray[67-1][0] = "us_china_rel_psLayout";			//Theme Name	
	themeArray[67-1][1] = "/persian/uploads/lo/2U/lo2UuZ3A9VRyGnflulf1Fg/FA-us_china_3.jpg";		//Background Image
	
	themeArray[68-1][0] = "identity_psLayout";			//Theme Name	
	themeArray[68-1][1] = "/persian/uploads/_E/NX/_ENXyeY2nXB11-PPBaTr2g/FA_Identity_bkgd.jpg";		//Background Image
	
	themeArray[69-1][0] = "beating_aids_psLayout";			//Theme Name	
	themeArray[69-1][1] = "/persian/uploads/FD/QF/FDQFxlKscIGjxqhb8YEB0g/FA-hands_bkgd.jpg";		//Background Image
	
	themeArray[70-1][0] = "rust_belt_psLayout";			//Theme Name	
	themeArray[70-1][1] = "/persian/uploads/Oy/cZ/OycZO-5azVdpmubBoRkwyg/FA-Campaign-rustbelt.jpg";		//Background Image
	
	themeArray[71-1][0] = "climate_change_psLayout";			//Theme Name	
	themeArray[71-1][1] = "/persian/uploads/1R/F-/1RF-WUWtMl8CPnQ1Vp7ABQ/FA-Campaign-changing-climate3.jpg";		//Background Image
	
	themeArray[72-1][0] = "disease_surveillance_psLayout";			//Theme Name	
	themeArray[72-1][1] = "/persian/uploads/Qc/2H/Qc2HVG3dPIYYgNTlTWp_Wg/FA-campaign-disease3.jpg";		//Background Image
	
	themeArray[73-1][0] = "alternative_energy_psLayout";			//Theme Name	
	themeArray[73-1][1] = "/persian/uploads/ZI/7p/ZI7pVctrcu0h6xBrkpsT4g/FA-Campaign-e2-3.jpg";		//Background Image
	
	themeArray[74-1][0] = "women_in_govt_psLayout";			//Theme Name	
	themeArray[74-1][1] = "/persian/uploads/JU/rk/JUrkqu7cHIIt5O2KjHwJvw/FA-Campaign-cracking.jpg";		//Background Image
	
	themeArray[75-1][0] = "land_o_lakes_psLayout";			//Theme Name	
	themeArray[75-1][1] = "/persian/uploads/6i/4H/6i4H_a51VgiG5FVtW1hVMA/FA-Land-O-Lakes-Master_Final.jpg";		//Background Image
	
	themeArray[76-1][0] = "lincoln_psLayout";			//Theme Name	
	themeArray[76-1][1] = "/persian/uploads/Ou/l3/Oul3qSkyXiBEoMXIHfDCrg/FA_abraham-lincoln-625.jpg";		//Background Image
	
	themeArray[77-1][0] = "meet_obama_psLayout";			//Theme Name	
	themeArray[77-1][1] = "/persian/uploads/N9/A-/N9A-XR_4oZopMV7Eh_BUrg/FA_MeetBarackObama_bkgd.jpg";		//Background Image
	
	themeArray[78-1][0] = "vanishing_act_psLayout";			//Theme Name	
	themeArray[78-1][1] = "/persian/uploads/FY/zL/FYzLOnN60WqN-sMzob6kBA/FA_vanishing-act_final.jpg";		//Background Image
	
	themeArray[79-1][0] = "protecting_oceans_psLayout";			//Theme Name	
	themeArray[79-1][1] = "/persian/uploads/On/xA/OnxArVikvS8yHIoKgxnoFQ/FA-ocean-protecting2.jpg";		//Background Image
	
	themeArray[80-1][0] = "cabinet_psLayout";			//Theme Name	
	themeArray[80-1][1] = "/persian/uploads/Db/rr/DbrrXRTmUwS9ZElpHKXwKQ/FA_TheCabinet_bkgd.jpg";		//Background Image
	
	themeArray[81-1][0] = "anti_corruption_psLayout";			//Theme Name	
	themeArray[81-1][1] = "/persian/uploads/fA/mY/fAmYIU-ny5paj6eIfUzKZQ/FA-corruption.jpg";		//Background Image
	
	themeArray[82-1][0] = "go_north_psLayout";			//Theme Name	
	themeArray[82-1][1] = "/persian/uploads/vI/ii/vIiiLHue4mVS2YF4-Uepgg/FA-go_north.jpg";		//Background Image
	
	themeArray[83-1][0] = "altern_violence_psLayout";			//Theme Name	
	themeArray[83-1][1] = "/persian/uploads/Cw/Rj/CwRjAGf2mdU93iMbPiXxXg/FA_nonviolence1_bkgd.jpg";		//Background Image
	
	themeArray[84-1][0] = "community_coll_psLayout";			//Theme Name	
	themeArray[84-1][1] = "/persian/uploads/lr/cw/lrcwnFyL3NJl8ic0WChF2g/FA_community-colleges3_bkgd.jpg";		//Background Image
	
	themeArray[85-1][0] = "mars_psLayout";			//Theme Name	
	themeArray[85-1][1] = "/persian/uploads/IQ/zg/IQzgNRsGGoVwWTteaXFA5A/FA-mars3.jpg";		//Background Image
	
	themeArray[86-1][0] = "american_indian_art_psLayout";			//Theme Name	
	themeArray[86-1][1] = "/persian/uploads/Dz/xh/DzxhCC-vVHPDZYar6Y-ZeQ/FA_indians3_bkgd.jpg";		//Background Image
	
	themeArray[87-1][0] = "top_universities_psLayout";			//Theme Name	
	themeArray[87-1][1] = "/persian/uploads/jI/vF/jIvFutRVh0u1-cP6tmR_Xg/FA_Top_UniversityDesign_bkgd.jpg";		//Background Image
	
	themeArray[88-1][0] = "flushing_psLayout";			//Theme Name	
	themeArray[88-1][1] = "/persian/uploads/Ll/vJ/LlvJIuM6ElOICehGSRer9Q/FA_flushing_bkgnd.jpg";		//Background Image
	
	themeArray[89-1][0] = "new_beginning_mus_psLayout";			//Theme Name	
	themeArray[89-1][1] = "/persian/uploads/Lg/O9/LgO9CtxtCAw4bFToD8JzLQ/FA_cairo_bkgd.gif";		//Background Image
	
	themeArray[90-1][0] = "declaration_hr_psLayout";			//Theme Name	
	themeArray[90-1][1] = "/persian/uploads/RX/Sh/RXShDtZFfqvs6IQIY8BkQg/FA_UN_declaration2_bkgd.jpg";		//Background Image
	
	themeArray[91-1][0] = "journalism_psLayout";			//Theme Name	
	themeArray[91-1][1] = "/persian/uploads/E3/qo/E3qoRfnbW3N5kVjv8VpfJA/FA_Campaign-journaism3_bkgd.jpg";		//Background Image
	
	themeArray[92-1][0] = "constitution_psLayout";			//Theme Name	
	themeArray[92-1][1] = "/persian/uploads/3P/PI/3PPIGxLEICOxJ9aio_oG_w/FA_constitution3_bkgd.jpg";		//Background Image
	
	themeArray[93-1][0] = "pictures_iran_psLayout";			//Theme Name	
	themeArray[93-1][1] = "/persian/uploads/Zc/Ix/ZcIxq4B_127hkF6kqu0NJA/FA_iran2_bkgd.jpg";		//Background Image
	
	themeArray[94-1][0] = "disaster_warning_psLayout";			//Theme Name	
	themeArray[94-1][1] = "/persian/uploads/Vd/7U/Vd7UpzMwU4U1IMyIe_lJnQ/FA-tsunami.jpg";		//Background Image
	
	themeArray[95-1][0] = "nato_psLayout";			//Theme Name	
	themeArray[95-1][1] = "/persian/uploads/HB/Mw/HBMwLy5tmNksu77w0Yroyg/FA_nato_bkgd.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("nato_psLayout","disaster_warning_psLayout","altern_violence_psLayout","declaration_hr_psLayout","go_north_psLayout","community_coll_psLayout","constitution_psLayout","land_o_lakes_psLayout","cabinet_psLayout","lincoln_psLayout","women_in_govt_psLayout","meet_obama_psLayout","alternative_energy_psLayout","disease_surveillance_psLayout","climate_change_psLayout","rust_belt_psLayout","flushing_psLayout","top_universities_psLayout","vanishing_act_psLayout","beating_aids_psLayout","american_indian_art_psLayout","identity_psLayout","mars_psLayout","anti_corruption_psLayout","protecting_oceans_psLayout","us_china_rel_psLayout","gone_with_wind_psLayout","gonorthtrainingLayout","usun_psLayout","capcompareLayout","capitalismLayout","engineerLayout","parkLayout","journalismsiegeLayout","h1n1fluLayout","poetryLayout","foodsecurityLayout","imagesiranLayout","reviveLayout","anatomyofajuryLayout","nanotechnologyLayout","architecturegreenLayout","digitallibraryLayout","foiaLayout","ramadanLayout","nobelpeaceLayout","nuclearfreeworldLayout","cairoLayout","michelleobamaLayout","corruptionLayout","michelleobamaLayout","womencourageLayout","carsshifttogreenLayout","aceLayout","searchandrescueLayout","nuclearLayout","bikesLayout","july4thLayout","smartgridLayout","newconsumerLayout","evolvingdemocracyLayout","G8-summitLayout","woc2010Layout","helping-grilsLayout","oprahLayout","cybersecurityLayout","esummitLayout","asian_novelLayout","agriculturalLayout","agriculturalLayout","nikeLayout","youasked_diversityLayout","preservingcultureLayout","jazzLayout","internet_freedomLayout","michelle_obama_mexicoLayout","exchange4Layout","eastmeetswestLayout","refugeesLayout","marktwainabroadLayout","refugees01Layout","plantingtreesLayout","usscienceenvoysLayout","seeyouusaLayout","usg_clickLayout","dancerssoarLayout","internetfreedomLayout","spaceLayout","ccpartnershipsLayout","guptaLayout","refugees_ejLayout");		//Supplies the populated usedLayouts array
	var themeNames = new Array("nato_psLayout","disaster_warning_psLayout","pictures_iran_psLayout","meet_obama_psLayout","constitution_psLayout","community_coll_psLayout","top_universities_psLayout","altern_violence_psLayout","journalism_psLayout","declaration_hr_psLayout","new_beginning_mus_psLayout","american_indian_art_psLayout","go_north_psLayout","land_o_lakes_psLayout","cabinet_psLayout","lincoln_psLayout","women_in_govt_psLayout","alternative_energy_psLayout","disease_surveillance_psLayout","climate_change_psLayout","vanishing_act_psLayout","rust_belt_psLayout","flushing_psLayout","beating_aids_psLayout","identity_psLayout","mars_psLayout","anti_corruption_psLayout","protecting_oceans_psLayout","us_china_rel_psLayout","gone_with_wind_psLayout","gonorthtrainingLayout","usun_psLayout","capcompareLayout","Capitalism3Layout","Theme ManagerLayout","capitalismLayout","engineerLayout","parkLayout","journalismsiegeLayout","h1n1fluLayout","poetryLayout","foodsecurityLayout","imagesiranLayout","reviveLayout","anatomyofajuryLayout","digitallibraryLayout","nanotechnologyLayout","architecturegreenLayout","foiaLayout","ThreadLayout","ramadanLayout","nobelpeaceLayout","nuclearfreeworldLayout","cairoLayout","michelleobamaLayout","corruptionLayout","womencourageLayout","carsshifttogreenLayout","aceLayout","searchandrescueLayout","bikesLayout","nuclearLayout","july4thLayout","smartgridLayout","newconsumerLayout","evolvingdemocracyLayout","G8-summitLayout","woc2010Layout","helping-grilsLayout","oprahLayout","cybersecurityLayout","esummitLayout","asian_novelLayout","agriculturalLayout","nikeLayout","youasked_diversityLayout","preservingcultureLayout","jazzLayout","internet_freedomLayout","michelle_obama_mexicoLayout","ThreadLayout","exchange4Layout","eastmeetswestLayout","refugeesLayout","marktwainabroadLayout","refugees01Layout","plantingtreesLayout","usscienceenvoysLayout","seeyouusaLayout","usg_clickLayout","dancerssoarLayout","internetfreedomLayout","spaceLayout","ccpartnershipsLayout","guptaLayout","refugees_ejLayout");		//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='/persian/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='/persian/page-layout-manager/page-layout-manager.html?func=add;class=WebGUI::Asset::Post::Thread' class='addLayout'>Add a Layout</a>";
			
		isUsed = 0;			
	}	
}









