//Have the propmt box turned on by default
var promptOn = true;

//Function to turn on or off the prompt box
function PromptMode(selectMode){
	
	if (selectMode.options[selectMode.selectedIndex].value == 0){
		promptOn = false;
	}
	else{
		promptOn = true;
	}
}


// Function to add the code for bold italic centre and underline, to the message
function AddMessageCode(code, promptText, InsertText) {

	if (code != "") {
		if (promptOn == true){
			insertCode = prompt(promptText + "\n[" + code + "]xxx[/" + code + "]", InsertText);
				if ((insertCode != null) && (insertCode != "")){
					document.frmAddMessage.message.value += "[" + code + "]" + insertCode + "[/" + code + "]";
				}
		}
		else{
			document.frmAddMessage.message.value += "[" + code + "][/" + code + "]";
		}
	}
				
	document.frmAddMessage.message.focus();
}

// Function to add the font colours, sizes, type to the message
function FontCode(code, endCode) {

	if (code != "") {
		if (promptOn == true){
			insertCode = prompt("Ysteğiniz yazıyı yazınız" + code + "\n[" + code + "]xxx[/" + endCode + "]", '');
				if ((insertCode != null) && (insertCode != "")){
					document.frmAddMessage.message.value += "[" + code + "]" + insertCode + "[/" + endCode + "]";
				}
		}
		else{
			document.frmAddMessage.message.value += "[" + code + "][/" + endCode + "]";
		}
	}	
	document.frmAddMessage.message.focus();
}



//Function to add the URL, indent, list, and Email code to the message
function AddCode(code) {

	//For the URL code
	if ((code != "") && (code == "URL")) {
		if (promptOn == true){
			insertText = prompt("Bağlantı kurmak istediğiniz Köprü nün ekranda görüntülenecek adını giriniz", "");
				
				if ((insertText != null) && (insertText != "") && (code == "URL")){
					insertCode = prompt("Köprü bağlantısının adresini giriniz", "http://");
						
						if ((insertCode != null) && (insertCode != "") && (insertCode != "http://")){					
							document.frmAddMessage.message.value += "[" + code + "=" + insertCode + "]" + insertText + "[/" + code + "]";
						}
				}
		}
		else {
			document.frmAddMessage.message.value += "[" + code + "= ][/" + code + "]";
		}
	}
	
	
	//For the email code
	if ((code != "") && (code == "EMAIL")) {
		if (promptOn == true){
			insertText = prompt("E-mail adresinin ekranda görüntülenecek yazısını giriniz", "");
				
				if ((insertText != null) && (insertText != "")){
					insertCode = prompt("E-Mail adresinin bağlantısını yazınız", "");
						
						if ((insertCode != null) && (insertCode != "")){					
						document.frmAddMessage.message.value += "[" + code + "=" + insertCode + "]" + insertText + "[/" + code + "]";
					}
				}
		}
		else {
			document.frmAddMessage.message.value += "[" + code + "= ][/" + code + "]";
		}
	}
	
	//For the image code
	if ((code != "") && (code == "IMG")) {
		if (promptOn == true){	
			insertCode = prompt("Resmin web uzantısını giriniz", "http://");
						
				if ((insertCode != null) && (insertCode != "")){					
				document.frmAddMessage.message.value += "[" + code + "]" + insertCode + "[/" + code + "]";
			}			
		}
		else {
			document.frmAddMessage.message.value += "[" + code + "][/" + code + "]";
		}
	}
	
	//For the list code
	if ((code != "") && (code == "LIST")) {
		if (promptOn == true){
			listType = prompt("Listeleme Tipi \n Lütfen \'1\' . listede görüntülemek istediğiniz NUMARAYI yazın", "");
			
			while ((listType != null) && (listType != "") && (listType != "1")) {
				listType = prompt("HATA! Lütfen \'1\' . listede görüntülemek istediğiniz NUMARAYI yazın","");               
			}
			
			if (listType != null) {			
				var listItem = "1";
				var insertCode = "";
				
				while ((listItem != "") && (listItem != null)) {
					listItem = prompt(". listede görüntülemek istediğiniz NUMARAYI yazınız",""); 
					if (listItem != "") {             
						insertCode += "[LI]" + listItem + "[/LI]"; 
					}                   
				} 
				
				if (listType == "") {
					document.frmAddMessage.message.value += "[" + code + "]" + insertCode + "[/" + code + "]";
				} else {
					document.frmAddMessage.message.value += "[" + code + "=" + listType + "]" + insertCode + "[/" + code + "=" + listType + "]";
				} 
				
			}
		}
		else{
			document.frmAddMessage.message.value += "[" + code + "][LI] [/LI][LI] [/LI][LI] [/LI][/" + code + "]";
		}			
	}
	
	
	//For the indent
	if ((code != "") && (code == "INDENT")) {
						
			document.frmAddMessage.message.value += "      ";				
	}
				
	document.frmAddMessage.message.focus();
}

//Function to add the code to the message for the smileys
function AddSmileyIcon(iconCode) {
 	var txtarea = document.frmAddMessage.message;
 	iconCode = ' ' + iconCode + ' ';
 	if (txtarea.createTextRange && txtarea.caretPos) {
  		var caretPos = txtarea.caretPos;
  		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? iconCode + ' ' : iconCode;
  		txtarea.focus();
 	} else {
  		txtarea.value  += iconCode;
  		txtarea.focus();
 	}
}

//Insert at Claret position.
function storeCaret(cursorPosition) {
 	if (cursorPosition.createTextRange) cursorPosition.caretPos = document.selection.createRange().duplicate();
}

function button_over(eButton,command) { 
eButton.src = 'images/imgEditor/' + command + '_over.gif'; 
} 
		
function button_out(eButton,command) { 
eButton.src = 'images/imgEditor/' + command + '.gif'; 
} 

function mySubmit(){
 document.frmAddMessage.submitBtn.disabled=true;
 document.frmAddMessage.submit();
}
