//#################################################################################
//## Snitz Forums 2000 v3.4.06
//#################################################################################
//## Copyright (C) 2000-06 Michael Anderson, Pierre Gorissen,
//##                       Huw Reddick and Richard Kinser
//##
//## This program is free software; you can redistribute it and/or
//## modify it under the terms of the GNU General Public License
//## as published by the Free Software Foundation; either version 2
//## of the License, or (at your option) any later version.
//##
//## All copyright notices regarding Snitz Forums 2000
//## must remain intact in the scripts and in the outputted HTML
//## The "powered by" text/logo with a link back to
//## http://forum.snitz.com in the footer of the pages MUST
//## remain visible when the pages are viewed on the internet or intranet.
//##
//## This program is distributed in the hope that it will be useful,
//## but WITHOUT ANY WARRANTY; without even the implied warranty of
//## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//## GNU General Public License for more details.
//##
//## You should have received a copy of the GNU General Public License
//## along with this program; if not, write to the Free Software
//## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//##
//## Support can be obtained from our support forums at:
//## http://forum.snitz.com
//##
//## Correspondence and Marketing Questions can be sent to:
//## manderson@snitz.com
//##
//#################################################################################

helpstat = false;
stprompt = false;
basic = true;

function thelp(swtch){
	if (swtch == 1){
		basic = false;
		stprompt = false;
		helpstat = true;
	} else if (swtch == 0) {
		helpstat = false;
		stprompt = false;
		basic = true;
	} else if (swtch == 2) {
		helpstat = false;
		basic = false;
		stprompt = true;
	}
}

/*function AddText(text) {
	var tarea = document.PostTopic.Message;
	if (tarea.selectionStart){ // if it supports DOM2
		tarea.value = tarea.value.substr(0,tarea.selectionStart)
			+ text + tarea.value.substr(tarea.selectionEnd);
		tarea.focus();
		tarea.selectionStart = tarea.selectionEnd + text.length;
		tarea.selectionEnd = tarea.selectionStart;
	} else {
		if (tarea.createTextRange && tarea.caretPos) {
			var caretPos = tarea.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?   text + ' ' : text;
		}
		else {
			tarea.value += text;
		}
		tarea.focus(caretPos);
	}
}*/

function AddText(text) {
	var tarea = document.PostTopic.Message;
	if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
		start = tarea.selectionStart;
		end = tarea.selectionEnd;
		tarea.value = tarea.value.substr(0,tarea.selectionStart)
			+ text + tarea.value.substr(tarea.selectionEnd);
		tarea.focus();
		tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
		tarea.selectionEnd = start + text.length;
	} else {
		if (tarea.createTextRange && tarea.caretPos) {
			var caretPos = tarea.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?   text + ' ' : text;
		}
		else {
			tarea.value += text;
		}
		tarea.focus(caretPos);
	}
}

function bold() {
	var text = getText();
	if (helpstat) {
		alert("Kalın (BOLD) imi metni daha kalınlaştırır.\n\KULLANIM: [k]Bu kalın bir metindir[/k]");
	} else if (basic) {
		AddTxt="[k]" + text + "[/k]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Kalın gösterilecek metin.",text);
		} else {
			txt=prompt("Kalın gösterilecek metin.","Metin");
		}
		if (txt!=null) {
			AddTxt="[k]"+txt+"[/k]";
			AddText(AddTxt);
		}
	}
}

function italicize() {
	var text = getText();
	if (helpstat) {
		alert("İtalik imi, metni sağa doğru eğer.\n\nKULLANIM: [i]Bu sağa doğru eğilmiş bir metindir[/i]");
	} else if (basic) {
		AddTxt="[i]" + text + "[/i]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Eğik yazılacak metin",text);
		} else {
			txt=prompt("Eğik yazılacak metin","Metin");
		}
		if (txt!=null) {
			AddTxt="[i]"+txt+"[/i]";
			AddText(AddTxt);
		}
	}
}

function underline() {
	var text = getText();
  	if (helpstat) {
		alert("Altıçizili imi metni altı çizili olarak gösterir.\n\nKULLANIM: [a]Bu metin altı çizgili bir metindir[/a]");
	} else if (basic) {
		AddTxt="[a]" + text + "[/a]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Altı çizilecek metin.",text);
		} else {
			txt=prompt("Altı çizilecek metin.","Metin");
		}
		if (txt!=null) {
			AddTxt="[a]"+txt+"[/a]";
			AddText(AddTxt);
		}
	}
}

function strike() {
	var text = getText();
	if (helpstat) {
		alert("Orta çizgili imi, seçili metnin ortasından çizilmesini sağlar.\n\nKULLANIM: [o]Bu metin ortadan çizilidir[/o]");
	} else if (basic) {
		AddTxt="[o]" + text + "[/o]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Ortadan çizilecek metin.",text);
		} else {
			txt=prompt("Ortadan çizilecek metin.","Metin");
		}
		if (txt!=null) {
			AddTxt="[o]"+txt+"[/o]";
			AddText(AddTxt);
		}
	}
}

function left() {
	var text = getText();
 	if (helpstat) {
		alert("Sol imi seçili metnin sola yaslanmasını sağlar.\n\nKULLANIM: [sol]Bu metin sola yaslıdır[/sol]");
	} else if (basic) {
		AddTxt="[sol]" + text + "[/sol]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Sola yaslanacak metin",text);
		} else {
			txt=prompt("Sola yaslanacak metin","Metin");
		}
		if (txt!=null) {
			AddTxt="[sol]"+txt+"[/sol]";
			AddText(AddTxt);
		}
	}
}

function center() {
	var text = getText();
 	if (helpstat) {
		alert("Ortala imi, seçili metnin ekranda ortalanmasını sağlar.\n\nKULLANIM: [ortala]This text is centered[/ortala]");
	} else if (basic) {
		AddTxt="[ortala]" + text + "[/ortala]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Ortalanacak metin",text);
		} else {
			txt=prompt("Ortalanacak metin","Metin");
		}
		if (txt!=null) {
			AddTxt="[ortala]"+txt+"[/ortala]";
			AddText(AddTxt);
		}
	}
}

function right() {
	var text = getText();
 	if (helpstat) {
		alert("Sağ imi, metnin sağa yaslanmasını sağlar.\n\nKULLANIM: [sag]Bu metin sağa yaslıdır[/sag]");
	} else if (basic) {
		AddTxt="[sag]" + text + "[/sag]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Sağa yaslanacak metin",text);
		} else {
			txt=prompt("Sağa yaslanacak metin","Metin");
		}
		if (txt!=null) {
			AddTxt="[sag]"+txt+"[/sag]";
			AddText(AddTxt);
		}
	}
}

function hr() {
	var text = getText();
	if (helpstat) {
		alert("Yatay çizgi, mesajınıza yatay bir çizgi çizer.\n\nKULLANIM: [yc]");
	} else {
		AddTxt="[yc]" + text;
		AddText(AddTxt);
	}
}

function hyperlink() {
	var text = getText();
	if (helpstat) {
		alert("Bağlantı imi \nbir web adresini bağlantıya çevirir.\n\nKULLANIM: [url]http://www.biradres.com[/url]\n\nKULLANIM: [url=\"http://www.biradres.com\"]Bağlantı metni[/url]");
	} else if (basic) {
		AddTxt="[url]" + text + "[/url]";
		AddText(AddTxt);
	} else {
		if (text!="") {
			txt2=text;
		} else {
			txt2=prompt("Bağlantı için gösterilecek metin.\nBağlantı için web adresi gösterilsin istiyorsanız boş bırakın.","");
		}
		if (txt2!=null) {
			txt=prompt("Bağlantı için web adresi","http://");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt+"[/url]";
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}
			}
		}
	}
}

function email() {
	if (helpstat) {
		alert("E-Posta imi bir e-posta adresini bağlantıya çevirir.\n\nKULLANIM: birisi\@biradres.com \nUSE #2: [url=\"birisi\@biradres.com\"]Bağlantı metni[/url]");
		}
	else {
		txt2=prompt("Bağlantı için gösterilecek metin\nEğer e-postanın gösterilmesini istiyorsanız, boş bırakın.","");
		if (txt2!=null) {
			txt=prompt("E-posta adresi.","mailto:");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt=txt;
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}
			}
		}
	}
}

function image() {
	var text = getText();
	if (helpstat){
		alert("Resim imi, mesajınıza bir resim ekler.\n\nKULLANIM: [resim]http://www.biradres.com/resim.gif[/resim]");
	} else if (basic) {
		AddTxt="[resim]" + text + "[/resim]";
		AddText(AddTxt);
	} else {
		txt=prompt("Resim / Fotoğraf için adres","http://");
		if(txt!=null) {
			AddTxt="[resim]"+txt+"[/resim]";
			AddText(AddTxt);
		}
	}
}

function sncode() {
	var text = getText();
	if (helpstat) {
		alert("Kod imi, metnin içine program kodu eklemenizi sağlar.\n\nKULLANIM: [kod]This is formated text[/kod]");
	} else if (basic) {
		AddTxt="[kod]" + text + "[/kod]";
		AddText(AddTxt);
	} else {
		txt=prompt("Kodu girin","");
		if (txt!=null) {
			AddTxt="[kod]"+txt+"[/kod]";
			AddText(AddTxt);
		}
	}
}

function quote() {
	var text = getText();
	if (helpstat){
		alert("Alıntı imi, başka bir yerden veya birinden alınan bir metni temsil eder.\n\nKULLANIM: [alıntı]Bu metin bir alıntıdır[/alıntı]");
	} else if (basic) {
		AddTxt=" [alıntı]" + text + "[/alıntı]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Alıntı olan metin",text);
		} else {
			txt=prompt("Alıntı olan metin","Metin");
		}
		if(txt!=null) {
			AddTxt=" [alıntı] "+txt+" [/alıntı]";
			AddText(AddTxt);
		}
	}
}

function list() {
	if (helpstat) {
		alert("Liste imi, düğmeli, rakamlı veya alfabetik olarak dizi oluşturabilir.\n\nKULLANIM: [liste] [*]1. nesne [*]2. nesne [*]3. nesne [/liste]");
	} else if (basic) {
		AddTxt=" [liste][*]  [*]  [*]  [/liste]";
		AddText(AddTxt);
	} else {
		type=prompt("Alfabetik liste için \'A\', Sayısal bir dizi için \'1\' yazın. Eğer düğmeli dizi isterseniz boş bırakın.","");
		while ((type!="") && (type!="A") && (type!="a") && (type!="1") && (type!=null)) {
			type=prompt("HATA! Bir liste için uygun girişler boşluk, 'A' ve '1'dir.","");
		}
		if (type!=null) {
			if (type=="") {
				AddTxt="[liste]";
			} else {
				AddTxt="[liste="+type+"]";
			}
			txt="1";
			while ((txt!="") && (txt!=null)) {
				txt=prompt("Liste nesnesi","");
				if (txt!="") {
					AddTxt+="[*]"+txt+"";
				}
			}
			if (type=="") {
				AddTxt+="[/liste] ";
			} else {
				AddTxt+="[/liste="+type+"]";
			}
			AddText(AddTxt);
		}
	}
}

function snfont(font) {
	var text = getText();
 	if (font) {
	 	if (helpstat) {
			alert("Font imi yazı tipini belirler.\n\nKULLANIM: [font="+font+"]Bu metnin yazıtipi: "+font+"[/font]");
		} else if (basic) {
			AddTxt="[font="+font+"]" + text + "[/font]";
			AddText(AddTxt);
		} else {
			if (text) {
				txt=prompt(font+" yazıtipinde yazılacak metin",text);
			} else {
				txt=prompt(font+" yazıtipinde yazılacak metin"+font,"Metin");
			}
			if (txt!=null) {
				AddTxt="[font="+font+"]"+txt+"[/font]";
				AddText(AddTxt);
			}
		}
	document.PostTopic.Font.selectedIndex = 0;
	}
}

function snsize(size) {
	var text = getText();
	if (size) {
		if (helpstat) {
			alert("Boyut imi, metnin boyutunu belirler, 1 en küçük olmak üzere, 6'ya kadardır.\n\nKULLANIM: [boyut="+size+"]Bu "+size+" boyutunda bir metindir[/boyut]");
		} else if (basic) {
			AddTxt="[boyut="+size+"]" + text + "[/boyut]";
			AddText(AddTxt);
		} else {
			if (text) {
				txt=prompt("Text to be size "+size,text);
			} else {
				txt=prompt("Text to be size "+size,"Metin");
			}
			if (txt!=null) {
				AddTxt="[boyut="+size+"]"+txt+"[/boyut]";
				AddText(AddTxt);
			}
		}
	document.PostTopic.Size.selectedIndex = 0;
	}
}

function sncolor(color) {
	var text = getText();
	if (color) {
		if (helpstat) {
			alert("Renk imi seçili metni renklendirir.\n\nKULLANIM: [renk="+color+"]Bu metnin rengi "+color+"[/renk]");
		} else if (basic) {
			AddTxt="[renk="+color+"]" + text + "[/renk]";
			AddText(AddTxt);
		} else {
			if (text) {
		     		txt=prompt("Renklendirilecek metin ",text);
			} else {
	     			txt=prompt("Renklendirilecek metin ","Metin");
			}
			if(txt!=null) {
				AddTxt="[renk="+color+"]"+txt+"[/renk]";
				AddText(AddTxt);
			}
		}
	// document.PostTopic.Color.selectedIndex = 0;
	}
}

function resizeTextarea(tmpCookieURL)
{
	var today = new Date();
	var expires = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); // plus 365 days
	if (document.PostTopic.SelectSize.value == 1)
	{
		document.PostTopic.Message.cols = 45;
		document.PostTopic.Message.rows = 11;
	}
	if (document.PostTopic.SelectSize.value == 2)
	{
		document.PostTopic.Message.cols = 70;
		document.PostTopic.Message.rows = 12;
	}
	if (document.PostTopic.SelectSize.value == 3)
	{
		document.PostTopic.Message.cols = 90;
		document.PostTopic.Message.rows = 12;
	}
	if (document.PostTopic.SelectSize.value == 4)
	{
		document.PostTopic.Message.cols = 130;
		document.PostTopic.Message.rows = 15;
	}
	document.cookie = tmpCookieURL + "strSelectSize=" + document.PostTopic.SelectSize.value + "; expires=" + expires.toUTCString()
}

function storeCaret(ftext) {
	if (ftext.createTextRange) {
		ftext.caretPos = document.selection.createRange().duplicate();
	}
}

function getText() {
	var tarea = document.PostTopic.Message;
	if (tarea.createTextRange && tarea.caretPos) {
		return tarea.caretPos.text;
	} else if (typeof tarea.selectionStart != 'undefined'){
		return tarea.value.substr(tarea.selectionStart,tarea.selectionEnd-tarea.selectionStart)
	}
	return '';
}

function OpenPreview()
{
	if (document.PostTopic.Message) {
		if (sntrim(document.PostTopic.Message.value)=="") {
			alert("Önizlenecek bir şey girmediniz")
			return false
		}
		popupWin = window.open('pop_preview.asp', 'preview_page', 'scrollbars=yes,width=650,height=450')
		return true
	}
}

function OpenSigPreview(fName)
{
	if (fName.Sig) {
		if (sntrim(fName.Sig.value)=="") {
			alert("Önizlenecek bir imza girmediniz")
			return false
		}
		popupWin = window.open('pop_preview_sig.asp', 'preview_page', 'scrollbars=yes,width=650,height=450')
		return true
	}
}

function validate(){

	if (document.PostTopic.Subject) {
		if (sntrim(document.PostTopic.Subject.value)=="") {
			alert("Bir başlık girmelisiniz")
			return false
		}
		var mySubject = sntrim(document.PostTopic.Subject.value);
		if (mySubject == mySubject.toUpperCase() && mySubject.length > 10) {
			alert("CAPS tuşunuz açık kalmış olabilir.\n\nLütfen küçük/büyük harf kurallarına uygun şekilde başlığınızı yazınız");
			return false
		}
		if (mySubject.indexOf('LLLP') > 0 || mySubject.indexOf('IIIIM') > 0 || mySubject.indexOf('ııım') > 0 || mySubject.indexOf('İİİL') > 0 || mySubject.indexOf('iiil') > 0) {
			alert("Başlığı, sorunuzu daha iyi anlatacak şekilde şekilde düzenlerseniz, yardım almanız daha kolaylaşacaktır.");
			return false
		}
		if (mySubject.match(/([^>=\]"'\/@]|^)((((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast):\/\/))([\w\-]+\.)*[:\.@\-\w\u4e00-\u9fa5]+\.([\.a-zA-Z0-9]+|\u4E2D\u56FD|\u7F51\u7EDC|\u516C\u53F8)((\?|\/|:)+[\w\.\/=\?%\-&~`@':+!#]*)*)/ig)) {
			alert("Başlığınıza lütfen internet adresleri kullanmayın. Başlıklar bir konunun ne hakkında olduğuyla ilgili bir bilgi verici cümlelerdir.");
			return false
		}
		
	}
	if (document.PostTopic.Spot) {
		if (sntrim(document.PostTopic.Spot.value)=="") {
			alert("Bir spot manşet girmelisiniz")
			return false
		}
	}
	
	if (document.PostTopic.Message) {
		if (sntrim(document.PostTopic.Message.value)=="") {
			alert("Bir mesaj girmelisiniz")
			return false
		}
	}
	document.PostTopic.Submit.disabled = true
	return true
}

function ResetForm(form) {
	var where_to= confirm("Form alanlarını eski haline getirmek istediğinize emin misiniz?");
	if (where_to== true) {
		form.reset();
	}
}

//code below found here:  http://www.marzie.com/devtools/javascript/functions.asp

function snltrim(s) {
	return s.replace( /^\s*/, "" );
}
function snrtrim(s) {
	return s.replace( /\s*$/, "" );
}
function sntrim ( s ) {
	return snrtrim(snltrim(s));
}

function cleanKod(message) {
	var s = message;
	s = s.replace(/\r/, "");
	s = s.replace(/\n/, "");
	s = s.replace(/\t/, "");
	s = s.replace(/ /, "");
}