var static_domain='http://s.jj.lv';
var user_id;
var d=document;
var fp_id=0;

//fjas.js
function getHTTPObject(){
var xmlhttp;
/*@cc_on
@if (@_jscript_version >=5)
try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")}
catch(e){
try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}
catch(E){xmlhttp=false}}
@else
xmlhttp=false;
@end @*/
if(!xmlhttp && typeof XMLHttpRequest!='undefined')
try{xmlhttp=new XMLHttpRequest()}
catch(e){xmlhttp=false}
return xmlhttp}


//calendar.js
var ct=new Date;function ch_month(a,b){ct.setFullYear(ct.getFullYear(),ct.getMonth()+a,1);showcal(ct,b);if(b!="cal"){showcal(ct,"cal1");showcal(ct,"cal2")}else showcal(ct,b);return false}function ins_date(a,b){d.getElementById("event_"+a).value=b;if(a=="cal2")d.getElementById("event_cal1").value=b;return false}
function cal_click(a){for(var b=a.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("a"),c=0;c<b.length;c++)b[c].className="";a.className="cal_click"}
function showcal(a,b){var c=a.getFullYear(),e=a.getMonth();a=a.getDate();a=new Date;a.setFullYear(c,e,1);a.getDay()!=0?a.setDate(a.getDate()-(a.getDay()-1)):a.setDate(a.getDate()-6);var f=new Date;f.setFullYear(c,e+1,0);f.getDay()!=0&&f.setDate(f.getDate()+(7-f.getDay()));div=d.getElementById(b);div.childNodes[0]&&clearChild(div);container=ce("div");container.className="c";py=ce("a");py.setAttribute("href","#3");py.onclick=new Function("ch_month(-12,'"+b+"');return false;");py.setAttribute("title",
c-1);ac(py,d.createTextNode("<"));ny=ce("a");ny.setAttribute("href","#3");ny.onclick=new Function("ch_month(12,'"+b+"');return false;");ny.setAttribute("title",c+1);ac(ny,d.createTextNode(">"));ac(container,py);ac(container,d.createTextNode(" "+c+" "));ac(container,ny);ac(container,ce("br"));pm=ce("a");pm.setAttribute("href","#3");pm.onclick=new Function("ch_month(-1,'"+b+"');return false;");e>0?pm.setAttribute("title",men[e-1]):pm.setAttribute("title",men[11]);ac(pm,d.createTextNode("<"));nm=ce("a");
nm.setAttribute("href","#3");nm.onclick=new Function("ch_month(1,'"+b+"');return false;");e==11?nm.setAttribute("title",men[0]):nm.setAttribute("title",men[e+1]);ac(nm,d.createTextNode(">"));ac(container,pm);ac(container,d.createTextNode(" "+men[e]+" "));ac(container,nm);t=ce("table");stils(t,"border-collapse:collapse;");t.setAttribute("class","c");tb=ce("tbody");row=ce("tr");for(nd=1;nd<=7;nd++){cell=ce("td");stils(cell,"font-weight:bold;padding:2px;");ac(cell,d.createTextNode(wd[nd]));ac(row,cell)}stils(cell,
"color:#f33;font-weight:bold;");ac(tb,row);for(var g=0;a<=f;){a.getDate()==1&&g++;if(a.getDay()==1)row=ce("tr");cell=ce("td");stils(cell,"width:1.5em;height:1.5em;text-align:right;");lnk=ce("a");stils(lnk,"color:#000;");if(g==0)e>0?lnk.setAttribute("title",ni[a.getDay()]+", "+c+lng_tlc_cal_gada+a.getDate()+"."+men[e-1].toLowerCase()):lnk.setAttribute("title",ni[a.getDay()]+", "+(c-1)+lng_tlc_cal_gada+a.getDate()+"."+men[11].toLowerCase());if(g==2)e<11?lnk.setAttribute("title",ni[a.getDay()]+", "+c+lng_tlc_cal_gada+a.getDate()+
"."+men[e+1].toLowerCase()):lnk.setAttribute("title",ni[a.getDay()]+", "+(c+1)+lng_tlc_cal_gada+a.getDate()+"."+men[0].toLowerCase());g==0||g==2?stils(lnk,"color:#999;display:block;padding:2px;text-decoration:none;"):stils(lnk,"display:block;padding:2px;text-decoration:none;");cell.onmouseover=new Function('stils(this,"background-color:#cfc;width:1.5em;height:1.5em;text-align:right;");');cell.onmouseout=new Function('stils(this,"background-color:transparent;width:1.5em;height:1.5em;text-align:right;");');
if(b=="cal")lnk.setAttribute("href","/meklet/?sd="+Math.floor(a.getTime()/86400000));else{lnk.setAttribute("href","#3");lnk.onclick=new Function("cal_click(this);ins_date('"+b+"','"+a.getDate()+"."+(a.getMonth()+1)+"."+a.getFullYear()+"');return false;")}ac(lnk,d.createTextNode(a.getDate()));ac(cell,lnk);ac(row,cell);if(a.getDay()==0){g==1?stils(lnk,"color:#f33;display:block;padding:2px;text-decoration:none;"):stils(lnk,"color:#f99;display:block;padding:2px;text-decoration:none;");ac(tb,row)}var h=
new Date;a.getYear()==h.getYear()&&a.getMonth()==h.getMonth()&&a.getDate()==h.getDate()&&stils(lnk,"color:#f00;font-weight:bold;display:block;padding:2px;text-decoration:none;");a.setDate(a.getDate()+1)}ac(t,tb);ac(container,t);opacity(b,false,0);ac(div,container)};


function DraugiemSay( title, url, titlePrefix ){
 window.open(
  'http://www.draugiem.lv/say/ext/add.php?title='+encodeURIComponent(title)+
  '&link='+encodeURIComponent(url)+
  (titlePrefix?'&titlePrefix='+ encodeURIComponent(titlePrefix):''),'',
  'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
 );
 return false;
}


function clearChild(el){
	while(el.childNodes[0])el.removeChild(el.firstChild)
	}

function ce(el){
	return(d.createElement(el))
	}

function ac(el,ch){
	el.appendChild(ch);
	return(el)
	}
function ctn(txt){
	return(d.createTextNode(txt))
	}

function sa(el,atr,val){
	el.setAttribute(atr,val);
	return(el)
	}

function unescapeHTML(str) //paartaisa &amp; par &
	{
	var div=ce('div');
	div.innerHTML=str;
	return div.childNodes[0].nodeValue
	}
	
function wordWrap(r,m,b,c){
	var i,j,s;
	if(m>0) {
		for(s=r,r=""; s.length>m; j=c ? m:(j=s.substr(0, m).match(/\S*$/)).input.length-j[0].length	|| j.input.length+(j=s.substr(m).match(/^\S*/)).input.length+j[0].length,r+=s.substr(0,j)+((s=s.substr(j)).length ? b:""));
		r+=s;
		}
	return r
	}
function wordWrap2(what,ttt,letters)
	{
	if (letters!=0)
		{
		bbb=wordWrap(what,letters,lng_separator,true);
		bbb=bbb.split(lng_separator);
		for(bba in bbb)
			{
			ac(ttt,ctn(bbb[bba]));
			if (bbb[bba].length==letters)	ac(ttt,ce('wbr'))
			}
		}
	else ac(ttt,ctn(what))
	}

function add_links(where,sourc,letters)
	{
 	rr=sourc.split(' ');
	var urlRegex = /\b(https?:\/\/[^\s\"\<\>\(\)]+)/ig;
	for (kk in rr)
		{
		urlRegex.exec('');
		if (match=urlRegex.exec(rr[kk]))
			{
			elmLink = ce('a'); 
			wordWrap2(match[0].substring(7,match[0].length),sa(sa(sa(elmLink,'href',match[0]),'title',match[0]),'target','_blank'),letters);
			
			wordWrap2(RegExp.leftContext,where,letters);
			
			wordWrap2(RegExp.rightContext,ac(where,elmLink),letters);
			}
		else wordWrap2(rr[kk],where,letters);
		ac(where,ctn(' '))
		}
	}


var translit=[ 
	/a{3}/g,/e{3}/g,/i{3}/g,/u{3}/g, /llj/g, /nnj/g,
	/Aa/g, /Ch/g, /Ee/g, /Gj/g, /Ii/g, /Kj/g, /Lj/g, /Nj/g, /Sh/g, /Uu/g, /Zh/g,
	/aa/g, /ch/g, /ee/g, /gj/g, /ii/g, /kj/g, /lj/g, /nj/g, /sh/g, /uu/g, /zh/g ];
var windows_1257=[
	"a\u0101", "\u0113", "i\u012b", "u\u016b", "\u013c\u013c", "\u0146\u0146", 
	"\u0100", "\u010C", "\u0112", "\u0122", "\u012a", "\u0136", "\u013b", "\u0145", "\u0160", "\u016a", "\u017d",
	"\u0101", "\u010d", "\u0113", "\u0123", "\u012b", "\u0137", "\u013c", "\u0146", "\u0161", "\u016b", "\u017e" 
	];


var exceptions=[ /^([ps]aa[^a]|nee[^\be])/i , 3,
				/^[mb]iljon/i, 6,
				/^[mb]iljard/i, 7,
				/buljon/i, 6,
				/(^|[^ghdr])iee[^\be]/i,3,
				/sheem/i, 2,
				/shem/i, 3,
				/vakuum/i,6
	  ];

var tl_prog="JS/translit";

var default_encoding="utf_8";
var debug=false;


function decodeChars(in_string,cp_reference)
{
	sym_count=cp_reference.length;
	result=in_string;
	
	if (typeof(in_string)!="string")
	{
		if (debug)
			alert(tl_prog+"error decodeChars: non-string given");
		return null
	}
	
	for (counter=0;counter< sym_count; counter++)
		result=result.replace(translit[counter],cp_reference[counter]);
	return result
}

function decodeTranslit(input_string,encoding)
{
	var URI_definition=/((https?|ftp|telnet):\/\/|mailto:)[A-z0-9%:@#=_\/\.\?\+\-]+/;
	var latinword = /[qwxy]/i;

	var cp_reference=eval(encoding);
	
	if (cp_reference == null)
	{
		if (debug) alert(tl_prog+" error: Encoding "+encoding+" not found!");
		return null
	}
	if (cp_reference.length != translit.length)
	{
		if (debug) alert(tl_prog+" error: Encoding "+encoding+" has different "+
			"size than the translit table, not all chars defined to be changed!");
		return null
	}
	var words=input_string.split(" ");
	var wc=words.length;
	var excount=exceptions.length;
	var dontAnalyze;
	var changeStart,changeEnd;
	var result= new Array();
	for (i=0; i< wc; i++)
	{
		resultword="";
		dontAnalyze = new Array();
		if (words[i].search(URI_definition)==-1 && words[i].search(latinword)== -1)
		{

			if (debug) alert("Analyzing: "+words[i]);
			for (j=0;j<excount;j+=2)
			{
				excplace=words[i].search(exceptions[j]);
				if (excplace != -1)
				{
					if (debug) alert("Found exception "+exceptions[j]+" length: "+exceptions[j+1]);
					dontAnalyze.push(excplace, excplace+exceptions[j+1])
				}
			}
			var daCount=dontAnalyze.length;
			changeStart=0;
			changeEnd=words[i].length;
			if (daCount > 0)
			{
				if (debug) alert("Found "+(daCount / 2)+" exceptions in "+words[i]+"\n"+dontAnalyze.join(","));
				resultword+=decodeChars(words[i].slice(0,dontAnalyze[0]),cp_reference);
				for (j=0; j<daCount; j+=2)
				{
					tmpvar1=words[i].slice(dontAnalyze[j],dontAnalyze[j+1]);
					if (debug) alert("processing exception, adding "+tmpvar1);
					resultword+=tmpvar1;
					changeStart=dontAnalyze[j+1];
					if (j+2 >= daCount)
					{
						changeEnd=words[i].length;
						break
					}
					else
						changeEnd=dontAnalyze[j+2];
					tmpvar1=words[i].slice(changeStart,changeEnd);
					if (debug) alert("exception: adding processed "+tmpvar1);
					resultword+=decodeChars(tmpvar1,cp_reference)
				}
			}
			tmpvar1=words[i].slice(changeStart,changeEnd);
			if (debug) alert("adding the rest of the word:"+tmpvar1);
			resultword+=decodeChars(tmpvar1,cp_reference)
		}
		else
			resultword=words[i];
		result.push(resultword)
	}
	return result.join(" ")
}


function doTranslit()
{
	if (typeof(arguments)!="object")
	{
		alert(tl_prog+" no object passed to doTranslit()");
		return false
	}
	if (arguments.length < 1)
	{
		alert(tl_prog+" too few arguments to doTranslit");
		return false
	}
	var encoding=(arguments.length > 1 ? arguments[1] : default_encoding);
	var input_object=arguments[0];
	
	if (! (input_object.type=="text" || input_object.type=="textarea"))
	{
		alert(tl_prog+" non-text form element passed to doTranslit? Can't "+
			" get value of "+input_object);
		return false
	}
	
	var result=decodeTranslit(input_object.value,encoding);
	
	if (debug) alert(tl_prog+" final result, got: "+result);
	input_object.value=result;
	
	return false
}

function externalLinks() {
 if (!d.getElementsByTagName) return;
 var anchors = d.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       (anchor.getAttribute("rel") == "nofollow" || anchor.getAttribute("rel") == "follow")
		&& anchor.getAttribute("rel") != "int")
     anchor.target = "_blank"
 }
}

function stils(el,stils)
	{
	sa(el,'style',stils);
	el.style.cssText=stils
	}

function sms() {
	if (d.getElementById('sms_length'))
		{
		smslength=d.getElementById('sms_length');
		ac(smslength,ctn('('+(d.getElementById('sms_text').value.length+d.getElementById('sign').value.length)+lng_tlc_from+' 800)'))
  	}
}

function ikt() {
	if (d.getElementById("ikt_length"))
		{
		smslength=d.getElementById("ikt_length");
		ac(smslength,ctn('('+(d.getElementById('zina_ir-ko-teikt').value.length)+lng_tlc_from+' 250)'))
  	}
}

function arrow(u){
  if(!u){
    if(window.event ){
      u = window.event;
      targ=u.srcElement
    }else{
      return
    }
  }
  else targ=u.target;
  if(typeof(u.keyCode)=='number') u=u.keyCode;
  else
  	if(typeof(u.which)=='number') u=u.which;
 		else if(typeof(u.charCode)=='number') u=u.charCode;
  else return;
  if (targ.id=="chatbarText")
  	switch (u){
  		case 38:
  		if (hist.length!=0){
  			hn++;
  			if (hn>hist.length) hn=1;
  			d.getElementById("chatbarText").value=hist[hist.length-hn]
  		}
  		break;
  		case 40:
  		if (hn!=0){
  			hn--;
  			if (hn==0) hn=hist.length;
  			d.getElementById("chatbarText").value=hist[hist.length-hn]
  		}
	  	break;
	  	case 13:
  		if (d.getElementById("chatbarText").value) sendComment();
	  	break;
	  	default:
	  	hn=0;
  	}
  if (targ.id=="sms_text" || targ.id=="sign")
  	{
  	smsbody=d.getElementById('sms_text').value;
  	sign=d.getElementById('sign').value.length;
  	if (smsbody.length+sign>800) d.getElementById('sms_text').value=smsbody.substring(0,800-sign);
  	smslength=d.getElementById("sms_length");
  	smslength.removeChild(smslength.firstChild);
  	ac(smslength,ctn('('+(d.getElementById('sms_text').value.length+sign)+lng_tlc_from+' 800)'))
  	}
  if (targ.id=="zina_ir-ko-teikt")
  	{
  	iktbody=d.getElementById('zina_ir-ko-teikt').value;
  	if (iktbody.length>250) d.getElementById('zina_ir-ko-teikt').value=iktbody.substring(0,250);
  	iktlength=d.getElementById("ikt_length");
  	iktlength.removeChild(iktlength.firstChild);
  	ac(iktlength,ctn('('+(d.getElementById('zina_ir-ko-teikt').value.length)+lng_tlc_from+' 250)'))
  	}
	}
function enter(){
	sendComment();
	return(false)
	}
	
	
	
function comment_urls()
	{
	if (d.getElementById('com_fieldset'))
		{
		elem = d.getElementById('com_fieldset').getElementsByTagName('p');
		for(i in elem)
			{
			if (elem[i].id!=null && elem[i].id.substr(0,3)=='com')
				{
				
				kr=elem[i].childNodes;
				de=kr.length;
				for(c=0;c<de;c++)
					{
					if (kr[c].nodeName=='#text')
						{
						span=ce('span');
						add_links(span,kr[c].nodeValue,0);
							{
							elem[i].insertBefore(span,kr[c].nextSibling);
							elem[i].removeChild(kr[c])
							}
						}
					}
				}
			}
		} 
	}
	
function ikt_urls()
	{
	if (d.getElementById('ikt_box'))
		{
		elem = d.getElementById('ikt_box').getElementsByTagName('strong');
		for(i in elem)
			{
			if (elem[i].id!=null)
				{
				kr=elem[i].childNodes;
				de=kr.length;
				for(c=0;c<de;c++)
					{
					if (kr[c].nodeName=='#text')
						{
						span=ce('span');
						add_links(span,kr[c].nodeValue,0);
							{
							elem[i].insertBefore(span,kr[c].nextSibling);
							elem[i].removeChild(kr[c])
							}
						}
					}
				}
			}
		} 
	}
		
	
function load_ajax()
	{
		if(typeof checkName == 'function') 
			{
			highlight();
			if (checkName()) //Ja ir ielogojies
				{
				receiveUO();
				load_new_mail();
				}
			receiveChatText();
			sa(d.forms['chatForm'].elements['chatbarText'],'autocomplete','off');
			//clearChild(d.getElementById("chat_load"));
			if(typeof rA == 'function') rA()
			}
		else setTimeout('load_ajax();',750);
	}

function load_new_mail()
	{
	if(typeof init_new_mail == 'function') init_new_mail();
	else setTimeout('load_new_mail();',750)
	}
	
function hide_buttons()
	{
	if (d.getElementById('js_hide_button'))stils(d.getElementById(('js_hide_button')),'display:none;z-index:0')
	}
function upd_url(id1,form1)
	{
	form1.action=form1.action+'?place='+id1
	}


var shjd=true;	
function shj()
	{
	if (d.getElementById('shj'))
		{
		stils(d.getElementById('shj'),'height:0');
		d.getElementById('share_joy_txt').onfocus=function(){if (shjd) for(var a=1;a<90;a++) setTimeout("stils(d.getElementById('shj'),('height:"+a+"px'));",a*10);shjd=false};
		}
	}


function opacity(el,hide,percent)
	{
	o_el=d.getElementById(el);
	if (navigator.appName=="Microsoft Internet Explorer")
		{
		if (hide) percent=percent-10; else percent=percent+20;
		stils(o_el,('filter: alpha(opacity='+percent+');'));
		}
	else
		{
		if (hide) percent=percent-2; else percent=percent+2;
		stils(o_el,('opacity:'+(percent/100)+';'));
		}
	if (percent!=0 && percent!=100) setTimeout('opacity("'+el+'",'+hide+','+percent+');',0);
	}
		
function init_forms()
	{
	elc = d.getElementsByTagName('input');
	for(i in elc)
		if (elc[i].className=='input-text')
			{
			if (elc[i].value) focus1(elc[i],false,false);
			else elc[i].onkeyup=function(){focus1(this,false,false);};
			//if (d.getElementById('adv_s_link')) elc[i].onfocus=function(){stils(d.getElementById('adv_s_link'),'visibility:visible;');opacity('adv_s_link',false,0);};
			}
	}
	
function focus1(eld,label,search_visible)
	{
	elm=d.getElementsByTagName('label');
	for(j in elm)
		if (elm[j].className=='inlined' && elm[j].getAttribute('for')==eld.id)
			{
			if(!label) label=elm[j].lastChild.nodeValue;
			//clearChild(elm[j]);
			if(eld.value && (!search_visible))
				{
				elm[j].removeChild(elm[j].lastChild);
				opacity('search_button',false,0); //paraadam
				eld.onkeyup=function(){focus1(this,label,true);}
				}
			if((!eld.value) && search_visible)
				{
				ac(elm[j],ctn(label));
				opacity('search_button',true,100) //nosleepjam
				eld.onkeyup=function(){focus1(this,label,false);}
				}
			break
			}
	}

function loadfunctions()
	{
	//google analytics
	var _gaq=_gaq||[];_gaq.push(['_setAccount','UA-241594-1']);_gaq.push(['_trackPageview']);(function(){var ga=d.createElement('script');ga.src=('https:'==d.location.protocol?'https://ssl':'http://www')+'.google-analytics.com/ga.js';ga.setAttribute('async','true');d.documentElement.firstChild.appendChild(ga);})();
	init_forms();
	hide_buttons();
	if (d.getElementById('adbox') && d.getElementById('defer')) d.getElementById('adbox').innerHTML=d.getElementById('adbox').innerHTML.replace(/<!--##DEFER(.+)DEFER##-->/g,'$1');
	externalLinks();
	comment_urls();
	if(typeof showcal == 'function') 
		{
		if (d.getElementById('cal')) showcal(ct,'cal');
		if (d.getElementById('cal1')) showcal(ct,'cal1');
		if (d.getElementById('cal2')) showcal(ct,'cal2')
		}
	}


window.onload = loadfunctions;
d.onkeyup=arrow;
