//################################################################################
//#			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","exampleLayout","marsLayout","americanindiansLayout","flushingLayout","surveillanceLayout","tsunamiLayout","oceansLayout","lincolnLayout","chinausLayout","pittsburghLayout","alternativeenergyLayout","africandevelopmentLayout","dissentLayout","baseballLayout","gonorthLayout","greensburgLayout","jazzLayout","childsoldiersLayout","aidsLayout","nationalparksLayout","womeningovtLayout","undeclarationLayout","aidlatinamericaLayout","topuniversitiesLayout","identityLayout","cabinetLayout","endangeredLayout","obamaLayout","landingLayout","landolakesLayout","natoLayout","nonviolenceLayout","summitLayout","climatechangeLayout","journalismundersiegeLayout","communitycollegesLayout","moneytransfersLayout","swinefluLayout","portraitsiranLayout","passportsLayout","contrastscapitalismLayout","constitutionLayout","graphicnovelLayout","financecorruptionLayout","womencourageLayout","waterusageLayout","carbonLayout","anticorruptionLayout","cairoLayout","piracyLayout","revivetradeLayout","slampoetryLayout");		//Supplies the populated themeNames array
	var usedLayouts = new Array("obamaLayout","identityLayout","alternativeenergyLayout","communitycollegesLayout","climatechangeLayout","surveillanceLayout","money_transfersLayout","moneytransfersLayout","swinefluLayout","portraitsiranLayout","passportsLayout","contrastscapitalismLayout","constitutionLayout","graphicnovelLayout","financecorruptionLayout","womencourageLayout","waterusageLayout","aidlatinamericaLayout","oceansLayout","dissentLayout","africandevelopmentLayout","undeclarationLayout","pittsburghLayout","summitLayout","carbonLayout","anticorruptionLayout","cairoLayout","piracyLayout","revivetradeLayout","chinausLayout","slampoetryLayout");		//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 = 52;
	var themeArray = new Array(52);
	var imgHeight;
			
	for(i=0;i<counter;i++)
		themeArray[i] = new Array(2);
			
	
	themeArray[1-1][0] = "revivetradeLayout";			//Theme Name	
	themeArray[1-1][1] = "/uploads/sp/jR/spjRf4yZsJ7SFbgzAyJ7Mw/tradefinance-bkgd.jpg";		//Background Image
	
	themeArray[2-1][0] = "slampoetryLayout";			//Theme Name	
	themeArray[2-1][1] = "/uploads/x7/GX/x7GXCdG1TRvsWqacyll1Pg/slampoetry-bkgd.jpg";		//Background Image
	
	themeArray[3-1][0] = "graphicnovelLayout";			//Theme Name	
	themeArray[3-1][1] = "/uploads/d7/Y3/d7Y30GJ4M85QQmC8WMFRVA/graphic-novels-bkgd.jpg";		//Background Image
	
	themeArray[4-1][0] = "waterusageLayout";			//Theme Name	
	themeArray[4-1][1] = "/uploads/ya/fl/yaflYCGQMZphhcrJcYwJag/coloradoriver5-bkgd.jpg";		//Background Image
	
	themeArray[5-1][0] = "cairoLayout";			//Theme Name	
	themeArray[5-1][1] = "/uploads/Ao/q5/Aoq5MQ6w1KsGt6MUywJRVQ/cairo2.gif";		//Background Image
	
	themeArray[6-1][0] = "piracyLayout";			//Theme Name	
	themeArray[6-1][1] = "/uploads/1y/jo/1yjoF4CXZdilPcHtM_3dVw/combatingpiracy-bkgd.jpg";		//Background Image
	
	themeArray[7-1][0] = "carbonLayout";			//Theme Name	
	themeArray[7-1][1] = "/uploads/Z0/Rw/Z0Rwo5Sz88ofhGSScM4VJA/carbon_spread_title.jpg";		//Background Image
	
	themeArray[8-1][0] = "anticorruptionLayout";			//Theme Name	
	themeArray[8-1][1] = "/uploads/eG/yt/eGytT2j-pmNc0gBKcmNFRw/corruption-bkgd3b.jpg";		//Background Image
	
	themeArray[9-1][0] = "financecorruptionLayout";			//Theme Name	
	themeArray[9-1][1] = "/uploads/VL/jC/VLjCCb8k-5nPmiGCq8CbKQ/corruption-bkgd3b.jpg";		//Background Image
	
	themeArray[10-1][0] = "aidlatinamericaLayout";			//Theme Name	
	themeArray[10-1][1] = "/uploads/Aw/Qp/AwQp9BoPmCithEBKu2ab-w/Campaign-helpinghands-bkgd.jpg";		//Background Image
	
	themeArray[11-1][0] = "womencourageLayout";			//Theme Name	
	themeArray[11-1][1] = "/uploads/rq/nq/rqnqX1e4PnYgEff3se24QA/womenofcourage-bkgd.jpg";		//Background Image
	
	themeArray[12-1][0] = "swinefluLayout";			//Theme Name	
	themeArray[12-1][1] = "/uploads/PG/2T/PG2TW3jUWw9F0ZRTbtvcJw/swineflu-bkgd_2.jpg";		//Background Image
	
	themeArray[13-1][0] = "contrastscapitalismLayout";			//Theme Name	
	themeArray[13-1][1] = "/uploads/fK/_M/fK_M1eFZmRwbTgOx9ti8Xw/contrastincapitalism4-bkgd.jpg";		//Background Image
	
	themeArray[14-1][0] = "portraitsiranLayout";			//Theme Name	
	themeArray[14-1][1] = "/uploads/81/gV/81gV-mMAkETg0Irg_-OIsQ/imagesfromiran-bkgd3.jpg";		//Background Image
	
	themeArray[15-1][0] = "constitutionLayout";			//Theme Name	
	themeArray[15-1][1] = "/uploads/e4/Fe/e4Fez29gZ14TCZV0fyT0WQ/constitution-bkgd4.jpg";		//Background Image
	
	themeArray[16-1][0] = "communitycollegesLayout";			//Theme Name	
	themeArray[16-1][1] = "/uploads/tv/Tm/tvTmAl-HqGkGeBONN0HLBA/1community-colleges3-bkgd.jpg";		//Background Image
	
	themeArray[17-1][0] = "passportsLayout";			//Theme Name	
	themeArray[17-1][1] = "/uploads/4B/ua/4Buacf1jnZTlhu0qEXSnmA/passportvisas-bkgd.jpg";		//Background Image
	
	themeArray[18-1][0] = "moneytransfersLayout";			//Theme Name	
	themeArray[18-1][1] = "/uploads/jt/xQ/jtxQssdrjS7W6oTvzMlKog/remittances2.jpg";		//Background Image
	
	themeArray[19-1][0] = "climatechangeLayout";			//Theme Name	
	themeArray[19-1][1] = "/uploads/xa/77/xa77z6Fnc_v27AuawaNBFQ/Campaign-climate-bkgd-2.jpg";		//Background Image
	
	themeArray[20-1][0] = "journalismundersiegeLayout";			//Theme Name	
	themeArray[20-1][1] = "/uploads/v_/Ue/v_Uew_t0Q7GKLKjUuRyimg/2Campaign-journalism-bkgd.jpg";		//Background Image
	
	themeArray[21-1][0] = "summitLayout";			//Theme Name	
	themeArray[21-1][1] = "/uploads/H5/EU/H5EU2R3hdqifUzP3jf4ZoQ/summit_americas_bkgnd.jpg";		//Background Image
	
	themeArray[22-1][0] = "nonviolenceLayout";			//Theme Name	
	themeArray[22-1][1] = "/uploads/rv/6A/rv6AR-xSnHWAXWAIbiaj6w/nonviolence_bkgnd.jpg";		//Background Image
	
	themeArray[23-1][0] = "americanindiansLayout";			//Theme Name	
	themeArray[23-1][1] = "/uploads/vH/1V/vH1VPEgg_JKBq3o6PfYOhA/AmericaIndian_layout_final_.jpg";		//Background Image
	
	themeArray[24-1][0] = "natoLayout";			//Theme Name	
	themeArray[24-1][1] = "/uploads/kl/EP/klEPlowLYV6IiYkPCwK3Ug/nato_bckgrnd.jpg";		//Background Image
	
	themeArray[25-1][0] = "landolakesLayout";			//Theme Name	
	themeArray[25-1][1] = "/uploads/ZE/qc/ZEqce8NBfhL4FNBctP57lA/Land-O-Lakes_bkgd.jpg";		//Background Image
	
	themeArray[26-1][0] = "chinausLayout";			//Theme Name	
	themeArray[26-1][1] = "/uploads/zo/q7/zoq7MP3sGF7h98wJLAiusw/us_china_3.jpg";		//Background Image
	
	themeArray[27-1][0] = "undeclarationLayout";			//Theme Name	
	themeArray[27-1][1] = "/uploads/4S/1M/4S1MXghAWkctB9Fj_JnWqw/UN_declaration2_bkgnd.jpg";		//Background Image
	
	themeArray[28-1][0] = "womeningovtLayout";			//Theme Name	
	themeArray[28-1][1] = "/uploads/Ae/lv/AelvwGEIWRlLujBXlHbAnA/Campaign-cracking-bkgd.jpg";		//Background Image
	
	themeArray[29-1][0] = "flushingLayout";			//Theme Name	
	themeArray[29-1][1] = "/uploads/Cn/DB/CnDBx9QQkxbzjSCYZuls-w/flushing_bkgnd2.jpg";		//Background Image
	
	themeArray[30-1][0] = "identityLayout";			//Theme Name	
	themeArray[30-1][1] = "/uploads/Pb/Sn/PbSnID4IVy1wV8RK8DC7tQ/Identity_bkgd.jpg";		//Background Image
	
	themeArray[31-1][0] = "gonorthLayout";			//Theme Name	
	themeArray[31-1][1] = "/uploads/xr/Uq/xrUq5m6B5P43cOjPEL6JJw/go_north.jpg";		//Background Image
	
	themeArray[32-1][0] = "africandevelopmentLayout";			//Theme Name	
	themeArray[32-1][1] = "/uploads/zV/mD/zVmDY1U-10_JiFmKAqt3CQ/Campaign-blackbusiness-bkgd.jpg";		//Background Image
	
	themeArray[33-1][0] = "topuniversitiesLayout";			//Theme Name	
	themeArray[33-1][1] = "/uploads/Ky/4H/Ky4HidbPLK437SCZQOXv2Q/TopUniversity_bkgd.jpg";		//Background Image
	
	themeArray[34-1][0] = "pittsburghLayout";			//Theme Name	
	themeArray[34-1][1] = "/uploads/_-/U-/_-U-_o6anzxWWkvPaN2bqw/Campaign_rustbelt_bkgd.jpg";		//Background Image
	
	themeArray[35-1][0] = "nationalparksLayout";			//Theme Name	
	themeArray[35-1][1] = "/uploads/Aw/wW/AwwWfHvDMgh-W3EjSucYag/Campaign-passports-bkgd.jpg";		//Background Image
	
	themeArray[36-1][0] = "surveillanceLayout";			//Theme Name	
	themeArray[36-1][1] = "/uploads/PC/51/PC51wPTsINRFdIeOdIdnIQ/campaign-ids-bkgd2.jpg";		//Background Image
	
	themeArray[37-1][0] = "lincolnLayout";			//Theme Name	
	themeArray[37-1][1] = "/uploads/YK/zw/YKzwWg-QI5xdYBAhkaRfdg/abraham-lincoln-625.jpg";		//Background Image
	
	themeArray[38-1][0] = "oceansLayout";			//Theme Name	
	themeArray[38-1][1] = "/uploads/6h/2q/6h2qMpg1CiUZB6fspd7rSw/ocean-protecting2-bkgd.jpg";		//Background Image
	
	themeArray[39-1][0] = "aidsLayout";			//Theme Name	
	themeArray[39-1][1] = "/uploads/a2/Hp/a2Hp10Msz7t0PPtBZg2tVg/amgov_beating_aids_bg.jpg";		//Background Image
	
	themeArray[40-1][0] = "marsLayout";			//Theme Name	
	themeArray[40-1][1] = "/uploads/_G/6v/_G6vrjxPGEeCyQouz59miQ/campaign-mars-bkgd2.jpg";		//Background Image
	
	themeArray[41-1][0] = "tsunamiLayout";			//Theme Name	
	themeArray[41-1][1] = "/uploads/Oy/Bn/OyBnCHlEcWIbBMtfCnp0tQ/campaign-deploy-bkgd-new.jpg";		//Background Image
	
	themeArray[42-1][0] = "obamaLayout";			//Theme Name	
	themeArray[42-1][1] = "/uploads/kd/WS/kdWSB9wierKhxWZ3fU_XxQ/MeetBarackObama_bkgd.jpg";		//Background Image
	
	themeArray[43-1][0] = "cabinetLayout";			//Theme Name	
	themeArray[43-1][1] = "/uploads/cL/tI/cLtIDMEFJFxJ01z7N_txxA/ObamasCabinet_bkgd.jpg";		//Background Image
	
	themeArray[44-1][0] = "jazzLayout";			//Theme Name	
	themeArray[44-1][1] = "/uploads/PU/WN/PUWNTo1ESgzy0FeMMQ6WiA/Campaign-jazz-bkgd.jpg";		//Background Image
	
	themeArray[45-1][0] = "greensburgLayout";			//Theme Name	
	themeArray[45-1][1] = "/uploads/2k/j_/2kj_RXb6fUIIzfNBrz9Nsw/Campaign-gonerebuilt-bkgd.jpg";		//Background Image
	
	themeArray[46-1][0] = "childsoldiersLayout";			//Theme Name	
	themeArray[46-1][1] = "/uploads/w_/5N/w_5NP-8O7me_Ob9GpKIJuQ/Campaign-exploited-bkgd.jpg";		//Background Image
	
	themeArray[47-1][0] = "alternativeenergyLayout";			//Theme Name	
	themeArray[47-1][1] = "/uploads/NC/hq/NChqjDVrNlXCFU3tm0UXeA/Campaign-alt_energy_final.jpg";		//Background Image
	
	themeArray[48-1][0] = "dissentLayout";			//Theme Name	
	themeArray[48-1][1] = "/uploads/Gc/v0/Gcv0fIjCu3DYGODYHcWdTg/Campaign-dissent-bkgd.jpg";		//Background Image
	
	themeArray[49-1][0] = "baseballLayout";			//Theme Name	
	themeArray[49-1][1] = "/uploads/VU/-f/VU-fymCls7WjhEsuJStWuQ/Campaign-baseball-bkgd.jpg";		//Background Image
	
	themeArray[50-1][0] = "endangeredLayout";			//Theme Name	
	themeArray[50-1][1] = "/uploads/eM/s-/eMs-R0St758c_zPXdOYJ0g/vanishing-act_bkgd.jpg";		//Background Image
	
	themeArray[51-1][0] = "landingLayout";			//Theme Name	
	themeArray[51-1][1] = "";		//Background Image
	
	themeArray[52-1][0] = "exampleLayout";			//Theme Name	
	themeArray[52-1][1] = "/uploads/Wn/Ja/WnJaqnpywEgKXEgEB6dN2Q/25.png";		//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");
}


//################################################################################
//#			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("obamaLayout","identityLayout","alternativeenergyLayout","communitycollegesLayout","climatechangeLayout","surveillanceLayout","money_transfersLayout","moneytransfersLayout","swinefluLayout","portraitsiranLayout","passportsLayout","contrastscapitalismLayout","constitutionLayout","graphicnovelLayout","financecorruptionLayout","womencourageLayout","waterusageLayout","aidlatinamericaLayout","oceansLayout","dissentLayout","africandevelopmentLayout","undeclarationLayout","pittsburghLayout","summitLayout","carbonLayout","anticorruptionLayout","cairoLayout","piracyLayout","revivetradeLayout","chinausLayout","slampoetryLayout");		//Supplies the populated usedLayouts array
	var themeNames = new Array("Theme ManagerLayout","exampleLayout","marsLayout","americanindiansLayout","flushingLayout","surveillanceLayout","tsunamiLayout","oceansLayout","lincolnLayout","chinausLayout","pittsburghLayout","alternativeenergyLayout","africandevelopmentLayout","dissentLayout","baseballLayout","gonorthLayout","greensburgLayout","jazzLayout","childsoldiersLayout","aidsLayout","nationalparksLayout","womeningovtLayout","undeclarationLayout","aidlatinamericaLayout","topuniversitiesLayout","identityLayout","cabinetLayout","endangeredLayout","obamaLayout","landingLayout","landolakesLayout","natoLayout","nonviolenceLayout","summitLayout","climatechangeLayout","journalismundersiegeLayout","communitycollegesLayout","moneytransfersLayout","swinefluLayout","portraitsiranLayout","passportsLayout","contrastscapitalismLayout","constitutionLayout","graphicnovelLayout","financecorruptionLayout","womencourageLayout","waterusageLayout","carbonLayout","anticorruptionLayout","cairoLayout","piracyLayout","revivetradeLayout","slampoetryLayout");		//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='/page-layout-manager/page-layout-manager/" + usedLayouts[x].toLowerCase() +".html?func=edit'  class='editLayout' target='_blank'>Edit Layout</a>";	
				isUsed = 1;
			}
		if(!isUsed)	
			document.getElementById(themeNames[i] + 'Id').innerHTML = "<a href='/page-layout-manager/page-layout-manager.html?func=add;class=WebGUI::Asset::Post::Thread' class='addLayout'>Add a Layout</a>";
			
		isUsed = 0;			
	}	
}








