//  Force getElementById to work
if(!document.getElementById) {
	if(document.all) {
		document.getElementById=function() {
			if(typeof document.all[arguments[0]]!="undefined")
			return document.all[arguments[0]]
			else
			return null
		}
	} else if(document.layers) {
		document.getElementById=function() {
			if(typeof document[arguments[0]]!="undefined")
			return document[arguments[0]]
			else
			return null
		}
	}
}

// Showcase controls
function ShowcaseSwitch() {
	var ShowcaseDiv		= document.getElementById('showcase');
	var ShowcaseText	= document.getElementById('showcase_text');
	var ShowcaseSeeAll	= document.getElementById('showcase_see_all');	
	
	if(ShowcaseDiv.style.zIndex == '5') {			
		ShowcaseDiv.style.zIndex = -1;
		ShowcaseText.style.display = 'none';
		ShowcaseSeeAll.style.display = 'none';
		return true;
	} else {
		ShowcaseDiv.style.zIndex = 5;
		ShowcaseText.style.display = 'block';
		ShowcaseSeeAll.style.display = 'inline';
		return true;
	}
}



// text formatting tools  - - - - - - - - - - - - - - - - - - - - - - - - - - //
function textEdit(action, elementID) {
	
	var textEditDiv = document.getElementById(elementID);
	var textEdit = document.getElementById(elementID).value;
	
	
	// add a bold word(s) - - - - - - - - - - - - - - - - - - - - - - - - - - //
	if(action == 'addBold' || action == '1') {
		var boldAdded = prompt("The word(s) you want bolded:","bold word(s)");
		
		if(!boldAdded) { }
		else { document.getElementById(elementID).value = textEdit + '<b>'+boldAdded+'</b> '; }
	}

// add an italicized word(s)  - - - - - - - - - - - - - - - - - - - - - - - - //
	else if(action == 'addItalic' || action == '2') {
		var italicAdded = prompt("The word(s) you want italicized:","italic word(s)");
		
		if(!italicAdded) { }
		else { document.getElementById(elementID).value = textEdit + '<i>'+italicAdded+'</i> '; }
	}
	
// add an anchor link - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
	else if(action == 'addLink' || action == '3') {
		var nameAdded = prompt("Name your link (what it will say):","title of the link");
		var linkAdded = prompt("Paste your link here (where it will go; http://...):","http://");
		
		if(!nameAdded || !linkAdded) { }
		else { document.getElementById(elementID).value = textEdit + '<a href="'+linkAdded+'">'+nameAdded+'</a> '; }
	}
		
// add an email link  - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
	else if(action == 'addEmail' || action == '5') {
		var linkAdded = prompt("Paste your email link here (name@website.com):","name@website.com");
		
		if(!linkAdded) { }
		else { document.getElementById(elementID).value = textEdit + '<a href="mailto:'+linkAdded+'">'+linkAdded+'</a> '; }
	}
		
// add a list - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
	else if(action == 'addList' || action == '4') {

		//number of items in list
		var maxNum = prompt("Number of Items in this list:","");
		if(maxNum == null) { return false; } // if 'cancel' was hit
		
		var container = new Array(maxNum);
		textEdit += '<ul>\n';
		
		// iterate through the amount entered for list items
		for (i = 0; i < maxNum; i++) {
			container[i] = prompt("List Item "+i+":","");
			if(container[i] == null) { return false; } // if 'cancel' was hit, kill the function
			textEdit += '<li>' + container[i] + '</li>\n';
		}
		textEdit += '</ul>\n';
		document.getElementById(elementID).value = textEdit;
	}
	
	document.getElementById(elementID).focus();
}



// add a file - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
function addFile() {
	var DynamicDiv = document.getElementById('DynamicDiv');
	
	var count = (document.getElementById('fieldCount').value -1)+ 2;
	var fieldCount = document.getElementById('fieldCount');
		fieldCount.value = count;
	
	var linebreak = document.createElement("br");
	var newdiv = document.createElement('div');
		newdiv.setAttribute("id","DynamicDiv"+count);
		newdiv.setAttribute("class","DynamicDiv");
		newdiv.innerHTML  = "";
		newdiv.innerHTML += "<div style=\"padding-top:10px;\"><input type=\"file\" name=\"DynamicFile[]\" id=\"DynamicFile[]\" \/><br />";
		//newdiv.innerHTML += "<span class=\"label\"><small><b>Title<\/b><\/small><\/span>";
		//newdiv.innerHTML += "<input type=\"text\" name=\"DynamicFileTitle[]\" id=\"DynamicFileTitle[]\" size=\"55\" /><br /><br />";
		newdiv.innerHTML += "<input type=\"hidden\" name=\"DynamicFileTitle[]\" id=\"DynamicFileTitle[]\" />";
		newdiv.innerHTML += "<span class=\"label\"><small><b>Caption/Description<\/b><\/small><\/span>";
		newdiv.innerHTML += "<input type=\"text\" name=\"DynamicFileCaption[]\" id=\"DynamicFileCaption[]\" size=\"55\" /><br /><br />";
		// newdiv.innerHTML += "<br />rank "+count;
		newdiv.innerHTML += "<input type=\"hidden\" name=\"DynamicFileCaptionRank[]\" id=\"DynamicFileCaptionRank[]\" value=\""+count+"\" size=\"55\" /></div>";
		newdiv.innerHTML += "<input type=\"button\" name=\"remove"+count+"\" value=\"REMOVE\" onclick=\"removeDynamicDivContent(\'DynamicDiv"+count+"\');\"  style=\"background:#FFBC6E;\" />";
		// newdiv.innerHTML += "<br /><a href=\"javascript:;\" onclick=\"removeDynamicDivContent(\'DynamicDiv"+count+"\')\" style=\"font-size:9px;\">remove<\/a>";
		
	DynamicDiv.appendChild(newdiv);
	
}


// add text - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
function addCopy() {
	var DynamicDiv = document.getElementById('DynamicDiv');
	var count = (document.getElementById('fieldCount').value -1)+ 2;
	var fieldCount = document.getElementById('fieldCount');
		fieldCount.value = count;
	
	var linebreak = document.createElement("br");
	var newdiv = document.createElement('div');
		newdiv.setAttribute("id","DynamicDiv"+count);
		newdiv.setAttribute("class","DynamicDiv");
		newdiv.innerHTML  = "";
		newdiv.innerHTML += "<div style=\"padding-top:10px;\"><textarea name=\"DynamicText[]\" id=\"DynamicText"+count+"\" class=\"dynamic_copy\"></textarea><br /><br />";
		newdiv.innerHTML += "<input type=\"hidden\" name=\"DynamicTextRank[]\" id=\"DynamicTextRank[]\" value=\""+count+"\" size=\"55\" /></div>";
		newdiv.innerHTML += "<input type=\"button\" name=\"bold"+count+"\" value=\"BOLD\" onclick=\"textEdit(\'1\', \'DynamicText"+count+"'); \" />";
		newdiv.innerHTML += "<input type=\"button\" name=\"italic"+count+"\" value=\"ITALIC\" onclick=\"textEdit(\'2\', \'DynamicText"+count+"'); \" />";
		newdiv.innerHTML += "<input type=\"button\" name=\"link"+count+"\" value=\"LINK\" onclick=\"textEdit(\'3\', \'DynamicText"+count+"'); \" />";
		//newdiv.innerHTML += "<input type=\"button\" name=\"link"+count+"\" value=\"EMAIL\" onclick=\"textEdit(\'5\', \'DynamicText"+count+"'); \" />";
		newdiv.innerHTML += "<input type=\"button\" name=\"link"+count+"\" value=\"LIST\" onclick=\"textEdit(\'4\', \'DynamicText"+count+"'); \" />";
		newdiv.innerHTML += "<input type=\"button\" name=\"remove"+count+"\" value=\"REMOVE\" onclick=\"removeDynamicDivContent(\'DynamicDiv"+count+"\');\" style=\"background:#FFBC6E;\" />";
		//newdiv.innerHTML += "<br /><a href=\"javascript:;\" onclick=\"removeDynamicDivContent(\'DynamicDiv"+count+"\')\" style=\"font-size:9px;\">remove<\/a>";
		
	DynamicDiv.appendChild(newdiv);
}


// remove a dynamic input - - - - - - - - - - - - - - - - - - - - - - - - - - //
function removeField(divNum) {
	var DynamicDiv = document.getElementById('fields');
	var count = (document.getElementById('fieldCount').value -1);
	var fieldCount = document.getElementById('fieldCount');
		fieldCount.value = count;		
	var removeDiv = document.getElementById(divNum);
	Effect.Fade(removeDiv);
	DynamicDiv.removeChild(removeDiv);
}


function removeDynamicDivContent(divNum) {
	var DynamicDiv = document.getElementById('DynamicDiv');
	var removeDiv = document.getElementById(divNum);
	DynamicDiv.removeChild(removeDiv);
}