var Imgdex = 0;
var ctls,wrap;
var ThisForm;
var RightSide;
function bootup(){
	var hidden_doc = document.getElementById('hidden_resource');
	var hiddenChilderen = hidden_doc.childNodes;
	RightSide = document.getElementById('right');
	ThisForm = document.forms.myform;
	ThisForm.reset();
	elementarray = ThisForm.image_file;
	for(var i = 0;i<elementarray.length;i++)
	{
	elementarray[i].disabled=false;
	}
	var j = 0
	for(i = 0; i<hiddenChilderen.length;i++)
	{
		chitlin = hiddenChilderen[i];
		if(chitlin.nodeName=='DIV'&&j==0){ctls=chitlin;j+=1;}
		if(chitlin.nodeName=='DIV'&&j==1){wrap=chitlin;}
	}
	setfoot();
}

function setfoot()
{	
	contid = document.getElementById('main');
	footposition =contid.offsetHeight;
	leftid = document.getElementById('left');
	rightid = document.getElementById('right');
	bottomid = document.getElementById('bottom');
	if(footposition<800)
	{
		footposition=800;
		}
	contid.style.height = footposition + 'px';
	rightid.style.height =  footposition + 'px';
	leftid.style.height = footposition + 'px';
	tposit = footposition + 50;
	bottomid.style.top = tposit + 'px';
	}

function InIMG(n_i)
{
	fname = basename(n_i.value)
	en = endsWith(fname).toLowerCase();
	cdiv = n_i.parentNode;
	if(en=='peg'||en=='gif'||en=='jpg'||en=='png')
	{
		ThisForm.content.value += "<img src='images/"+fname+"'/>";
		n_i.disabled = true;
		newctls = ctls.cloneNode(true);
		cdiv.appendChild(newctls);
		newput = wrap.cloneNode(true);
		RightSide.appendChild(newput);
	}
}

/*gets the last three characters of a string*/
function endsWith(st)
{
	end = st.length;
	start=end -3;
	output = st.substring(start,end);
	return output;
}
/*removes an image*/
function Ixnay(cur)
{
	bigPappy = cur.parentNode.parentNode;
	littleChitlins = bigPappy.childNodes;
	for(i=0;i<littleChitlins.length;i++)
	{	
		chitlin=littleChitlins[i];
		if(chitlin.nodeName=='INPUT')
		{	fname=basename(chitlin.value);
			iname = "<img src='images/"+fname+"'/>"
			newcontent = ThisForm.content.value.replace(iname,'');
			ThisForm.content.value = newcontent;
			i = littleChitlins.length +1
			
		}
	RightSide.removeChild(bigPappy);
	}
	
}
/*removes an image in edit mode*/
function Ixnay2(cur)
{
	mynum = cur.value;
	var working = ThisForm.content.value
	allimg = working.match(/<img.*?>/g,'');
	for(var i=0;i<allimg.length;i++)
	{
		is = allimg[i];
		if(is.match(mynum)){working = working.replace(allimg[i],'');}
	}
	ThisForm.content.value = working;
}
function inAgain(cur)
{
	bigPappy = cur.parentNode.parentNode;
	littleChitlins = bigPappy.childNodes;
	for(i=0;i<littleChitlins.length;i++)
	{	
		chitlin=littleChitlins[i];
		if(chitlin.nodeName=='INPUT')
		{	fname=basename(chitlin.value);
			iname = "<img src='images/"+fname+"'/>"
			ThisForm.content.value+=iname;
			i = littleChitlins.length +1			
		}
	}
}
function checkPls()
{
	elementarray = ThisForm.image_file;
	for(var i = 0;i<elementarray.length;i++)
	{
		elementarray[i].disabled=false;
	}
}

function togHigh(cur)
{
	cur.style.color='#0f0';
	cur.style.textDecorationLineThrough = true;
}

function togLow(cur)
{
	cur.style.color='#000';
	cur.style.textDecorationLineThrough = false;

}
/*gets the filename from the uploaded filename*/
 function basename(ph) 
	{
 	bigbase = ph.replace(/.*[\/\\]/, '');
	return bigbase;
}

