var clientPC = navigator.userAgent.toLowerCase();
var cli_ver = parseInt(navigator.appVersion);
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var doc_set=window.document;
///cookie
function set_lng_cookie(lng_id)
{
	var exp = new Date();
	exp.setTime(exp.getTime() + 1000000000000);
	document.cookie = "iabp_lang=" +lng_id +"; expires=" + exp.toGMTString();
}

function call_foto_gallery(foto_id)
{

	window.location = "/index.php?&topic=002&articl=2_06.php&foto=" + foto_id;
}



function set_wnd(wnd)
{
	doc_set = wnd.document;

}
function check_is_selection(obj)
{
	var s1=obj.value;
	var s2;
	if(is_ie)
	{
		obj.focus();
		s2 = doc_set.selection.createRange().text;
	}else
	{
		s2="";
		if(obj.selectionStart!=obj.selectionEnd)
			s2 = s1.substring(obj.selectionStart,obj.selectionEnd);
	}
	return s2.length;
}


function insert_font(ff,sz,fc,bg,obj)
{
	var sty="";
		if(ff)
			sty+="font-family: " + ff + ";";
		if(sz)
			sty+="font-size: " + sz + ";";
		if(fc)
			sty+="color: " + fc + ";";
		if(bg)
			sty+="background: " + bg + ";";
	insert_text("<span style=\"" + sty + "\">","</span>",obj);
}

function url_input(obj)
{
	var l,n;
	l = prompt("Enter the URL", "http://");
	if(l==null)
		return;
	n="";
	if(check_is_selection(obj)==0)
	{
		n = prompt("Enter the URL name", "url name");
		if(n==null)
			n="";
	}
	insert_text("<a href=\"" + l + "\">"+n,"</a>",obj);
}


function add_image(pth,wx,wy,obj)
{
	insert_text("<img src=\"" + pth + "\" width="+wx + " height=" + wy + ">","\n",obj);
}

function addins_raw_link(href,tx,obj)
{
	insert_text("<a href=\"" + href +"\">" + tx + "</a>",obj);
}
function add_foto_lnk(foto_id,obj)
{
	insert_text("<a href=\"javascript:call_foto_gallery('" + foto_id +"');\">" ,"</a>",obj);
}
function add_foto_lnk_2(ln,foto_id)
{
	return "<a href=\"/index.php?&topic=002&articl=2_06.php&foto=" + foto_id+ "\">"+ln+"</a>";
}

function insert_text(tx_start,tx_end,obj)
{
	var s1=obj.value;
	var s2,p1,p2;
	if(is_ie)
	{
		obj.focus();
		s2 = tx_start + doc_set.selection.createRange().text + tx_end;
		doc_set.selection.createRange().text = s2;
	}else
	{
		s2="";
		if(obj.selectionStart!=obj.selectionEnd)
			s2 = s1.substring(obj.selectionStart,obj.selectionEnd);
		p1 = s1.substring(0,obj.selectionStart);
		p2 = s1.substring(obj.selectionEnd,s1.length);
		obj.value=p1+tx_start+s2+tx_end+p2;
		obj.focus();
	}
}
