var trigger=false;
function push(){
	if (document.all.swapmode.value == "Edit in Text Mode"){
		//document.all.editform.ptext.value=divtext.innerText
	}else{
		//document.all.editform.ptext.value=divtext.innerHTML
	}
}


function swapModes(){
	if (document.getElementById('swapmode').value == "Edit in HTML Mode"){
	
	var edhtml=true;
	
		var divObject = document.all.tags("div");
		for (i = 0; i < divObject.length; i++){
			if(divObject[i].id!='menu' && divObject[i].id!='responder'){
				divObject[i].innerText=divObject[i].innerHTML;
				divObject[i].style.backgroundColor='silver';
			}	
		}
		document.getElementById('swapmode').value="Edit in Text Mode"
  	}else{
  	edhtml=false;
		var divObject = document.all.tags("div");
		for (i = 0; i < divObject.length; i++){
			if(divObject[i].id!='menu' && divObject[i].id!='responder'){
				divObject[i].innerHTML=divObject[i].innerText;
				divObject[i].style.backgroundColor='white';
			}	
		}
		document.getElementById('swapmode').value="Edit in HTML Mode"
  	}
}

function BtnDown(){
	window.event.srcElement.style.border = "inset 1px";
}
function BtnUp(){
	window.event.srcElement.style.border = "none";
}







//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function insertimg(){
	theImg = document.getElementById('path').value;
	if (theImg != ""){
		tosplit = theImg.split('\\');
		th=tosplit.length;
		theImg=tosplit[th-1];
		theImg = 'uploads/gen_images/'+theImg;
		document.getElementById('uploadform').submit();
		
	}
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function ImAlert(im_to_insert){
		alert("Please click where you want to insert the image");
		trigger=true;
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function handleImInsertion(imstring, pageid){
	if(trigger==true){
		document.execCommand('InsertImage', false, imstring);
		fieldupdate('edit.php', 'update', 'pages', 'im_to_insert', '', 'pageid', pageid);
		trigger=false;
	}
}

















function insertlnk(){
	theLink = document.getElementById('path').value;
	if (theLink != ""){
		document.execCommand("CreateLink", false, theLink);
	}
}





function Toggle(){
	text = window.event.srcElement.innerText;

	if (text == "ContentEditable"){
		if (document.all("divtext").contentEditable == "true"){
			document.all("divtext").contentEditable = "false";
			window.event.srcElement.style.borderStyle = "outset";
		}else{
			document.all("divtext").contentEditable = "true";
			window.event.srcElement.style.borderStyle = "inset";
		}
		return;
	}

	else if (text == "B")
		document.execCommand("Bold");

	else if (text == "I")
		document.execCommand("Italic");

	else if (text == "U")
		document.execCommand("Underline");
		
	else if (text == "S")
		document.execCommand("StrikeThrough");

	else if (text == "<-")
		document.execCommand("JustifyLeft");

	else if (text == "--")
		document.execCommand("JustifyCenter");
		
	else if (text == "->")
		document.execCommand("JustifyRight");
		
	else if (text == "Font Colour"){
		theColor = document.all.fontcolor.options.value;
		if (theColor != "")
			document.execCommand("ForeColor", false, theColor);
	}

	else if (text == "Font Size"){
		theSize = document.all.fontsize.options.value;
		if (theSize != "")
			document.execCommand("FontSize", false, theSize);
	}

	else if (text == "Font Name"){
		theName = document.all.fontname.value;
		if (theName != "")
			document.execCommand("FontName", false, theName);
	}

	else if (text == "Image"){
		theImg = document.all.path.value;
		if (theImg != "")
		alert(theImg);
			document.execCommand("InsertImage", false, theImg);
	}
	
	else if (text == "Hyperlink"){
		theLink = document.all.path.value;
		if (theLink != "")
			document.execCommand("CreateLink", false, theLink);
	}

	window.event.srcElement.style.borderStyle = "outset";
}