
var base = "http://localhost/static";



function validate_shoutbox_form(frm)
{
	if(frm.message.value=='')
	{
		alert('فرم ارسال خالی است');
		return false;
	}
	else
	{
		frm.post_comment.disabled=true;
	}
			
}


function make_mail(name, domain)
{
	document.write('<a title="'+name+'@'+domain+'" href="mailto:'+name+'@'+domain+'"><img alt="'+name+'@'+domain+'" src="'+base+'/icons/mail.gif"/></a>');
}

function make_url(url,uname)
{
	document.write('<a href="http://'+url+'" target="_blank" title="'+url+'">'+uname+'</a>');
}


function show_hide(msg_id)
{

	document.getElementById (msg_id).style.display = document.getElementById (msg_id).style.display == 'none' ? 'block' : 'none';
}

function isemail(str)
{
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	if (! str.match(re))
	{
		return (false);
	}
	return(true);
}

function confirmIt(message)
{
	
	if (!message) message='مطمئن هستید؟';
	return confirm(message);
}

function sm(strCode)
{
	document.getElementById ("message").value +="[" + strCode +"]";
}

function flipBox(who) {
	var tmp; 
	if (document.images['b_' + who].src.indexOf('_on') == -1) { 
		tmp = document.images['b_' + who].src.replace('_off', '_on');
		document.getElementById('box_' + who).style.display = 'none';
		document.images['b_' + who].src = tmp;
	} else { 
		tmp = document.images['b_' + who].src.replace('_on', '_off');
		document.getElementById('box_' + who).style.display = 'block';
		document.images['b_' + who].src = tmp;
	} 
}

function addText(elname, wrap1, wrap2)
{
	if (document.selection)
	{ // for IE 
		var str = document.selection.createRange().text;
		document.getElementById(elname).focus();
		var sel = document.selection.createRange();
		sel.text = wrap1 + str + wrap2;
		return;
	}
	else if ((typeof document.getElementById(elname).selectionStart) != 'undefined')
	{ // for Mozilla
		var txtarea = document.getElementById(elname);
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var oldScrollTop = txtarea.scrollTop;
		//if (selEnd == 1 || selEnd == 2)
		//selEnd = selLength;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
		txtarea.selectionStart = s1.length;
		txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
		txtarea.scrollTop = oldScrollTop;
		txtarea.focus();
		return;
	}
	else
	{
		insertText(elname, wrap1 + wrap2);
	}
}

function insertText(elname, what)
{
	if (document.getElementById (elname).createTextRange) {
		document.getElementById(elname).focus();
		document.selection.createRange().duplicate().text = what;
	} else if ((typeof document.getElementById(elname).selectionStart) != 'undefined') { // for Mozilla
		var tarea = document.getElementById(elname);
		var selEnd = tarea.selectionEnd;
		var txtLen = tarea.value.length;
		var txtbefore = tarea.value.substring(0,selEnd);
		var txtafter = tarea.value.substring(selEnd, txtLen);
		var oldScrollTop = tarea.scrollTop;
		tarea.value = txtbefore + what + txtafter;
		tarea.selectionStart = txtbefore.length + what.length;
		tarea.selectionEnd = txtbefore.length + what.length;
		tarea.scrollTop = oldScrollTop;
		tarea.focus();
	} else {
		document.getElementById(elname).value += what;
		document.getElementById(elname).focus();
	}
}


function setCookie (name, value, expires, path, domain, secure) {
 var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") +
 (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
 document.cookie = curCookie;
}

function getCookie (name) {
 var prefix = name + '=';
 var c = document.cookie;
 var nullstring = '';
 var cookieStartIndex = c.indexOf(prefix);
 if (cookieStartIndex == -1)
 return nullstring;
 var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
 if (cookieEndIndex == -1)
 cookieEndIndex = c.length;
 return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
 if (getCookie(name))
 document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
 ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
 var base = new Date(0);
 var skew = base.getTime();
 if (skew > 0)
 date.setTime(date.getTime() - skew);
}

function rememberMe (f) {

 var now = new Date();
 fixDate(now);
 now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
 now = now.toGMTString();

 if (f.author != undefined)
 setCookie('kauth', f.author.value, now, '/', '', '');
 if (f.email != undefined)
 setCookie('kmail', f.email.value, now, '/', '', '');
 if (f.url != undefined)
 setCookie('khome', f.url.value, now, '/', '', '');
}

function forgetMe (f)
{
	
 deleteCookie('kmail', '/', '');
 deleteCookie('khome', '/', '');
 deleteCookie('kauth', '/', '');
 f.email.value = '';
 f.author.value = '';
 f.url.value = 'http://';
}



function loadcommenter() {
	
 if (document.comment_form) {

 if (document.comment_form.email != undefined && (kmail = getCookie("kmail"))) document.comment_form.email.value = kmail;
 if (document.comment_form.author != undefined && (kauth = getCookie("kauth"))) document.comment_form.author.value = kauth;
 if (document.comment_form.url != undefined && (khome = getCookie("khome"))) document.comment_form.url.value = khome;
 if (kauth || khome) {document.comment_form.bakecookie.checked = true;} else {document.comment_form.bakecookie.checked = false;}
 }
}

function make_comment_form(code,type, show_smile)
{
	var smiles = '';
	if (show_smile == 1)
	{
		for(i=1;i<=20;i++){smiles +="<img style='cursor:hand' src='"+base+"/smiles/"+i+".gif' onClick=\"insertText('comment_message', '[:"+i+"]');\">";}
	}


	if (type==1)
	{
		document.write(code);
		document.write("<center><textarea name='comment_message' rows='6' cols='70'></textarea><br/>"+smiles+"<br/><input class='button' type='submit' name='save_comment' value='  ارسال  '/></center>");
	}
	else if (type==2)
	{
	
		document.write(code);
		document.write("<table border=0 width=100%><tr><td width='150'><span style='color:#ff0000'>*</span>نام:</td><td><input id='author' name='comment_author' size='30' type='text' class='text'/></td></tr><tr><td ><span style='color:#ff0000'>*</span>ایمیل:</td><td><input id='email' type='text' name='comment_email' size='30' class='text' dir='ltr' align='left'/></td></tr><tr><td >وب سایت / وبلاگ:</td><td><input type='text' id='url' name='comment_url' size='30' class='text' dir='ltr' align='left' value='http://'/></td></tr><tr><td valign='top'><input id='bakecookie' name='bakecookie' onclick='if (!this.checked) forgetMe(document.comment_form)' value='1' type='checkbox'/> اطلاعات من را حفظ کن</td><td><textarea id='text' name='comment_message' rows='7' cols='70'></textarea><br/>"+smiles+"<br/><br/><input class='button' type='submit' name='save_comment' value='  ارسال  '/></td></tr></table></form>");
		loadcommenter();
	}
	else if (type==3)
	{
		document.write(code);
		//document.write('');
	}
}


function validate_comment_form(frm)
{
	if(frm.comment_message.value=='')
	{
		alert('فرم ارسال نظر خالی است');
		return false;
	}
	else
	{
		frm.post_comment.disabled=true;
	}
}

function checkAll(form)
{
	for (i = 0, n = form.elements.length; i < n; i++)
	{
		if(form.elements[i].type == "checkbox" && !(form.elements[i].getAttribute('onclick',2)))
		{
			if(form.elements[i].checked == true)
				form.elements[i].checked = false;
			else
				form.elements[i].checked = true;
		}
	}
}
