sessionId = '&' + sessionId;

function changeMainMenu(node, sub_menu){
	$('.main-menu .selected').removeClass();		 
	$(node.parentNode.parentNode).addClass('selected');
	
	$('.sub-menu > div').removeAttr('style');
	$('#sub-menu_'+sub_menu).css('display', 'block');
}

function resize(){
	if($(window).width() > 1200){/*jei didelis*/
		$('.size-frame').css({'width':'1200px'});
		$('.foot').css({'width':'1164px'});/*-36 padding*/
	}else{
		$('.size-frame').css({'width':'990px'});
		$('.foot').css({'width':'954px'});/*-36 padding*/
	}
}

u=true;
a=true;
function WindowOpen(url, title, width, height){
	w = window.open(url, title,  'height='+height+'px,width='+width+'px,menubar=0,personalbar=0,resizable=0,status=0,titlebar=0,toolbar=0,scrollbars=1');
	w.focus();
}


function ChangeTab(selected){
	var paieskos_box_temp = document.getElementById('paieskos_box_temp');
	if (paieskos_box_temp) {
		paieskos_box_temp.id = 'paieskos_box';
	}
	var footer_temp = document.getElementById('footer_temp');
	if (footer_temp) {
		footer_temp.style.display = 'block';
	}
	var header_temp = document.getElementById('header_temp');
	if (header_temp) {
		header_temp.style.display = 'block';
	}
	
	//atzymime pries tai buvusi
	document.getElementById('tab'+last).className='pa_tekstas';
	if(last==1){
		document.getElementById('aimg'+last).src='images/pbox_9_01.gif';
		document.getElementById('aimg'+(last*1+1)).src='images/pbox_9.gif';
	}else{
		document.getElementById('aimg'+last).src='images/pbox_9.gif';
		if(document.getElementById('aimg'+(last*1+1))){
			document.getElementById('aimg'+(last*1+1)).src='images/pbox_9.gif';
		}
	}
	document.getElementById('dimg'+last).src='images/pbox_11.gif';
	document.getElementById('content'+last).style.display='none';
	last=selected;//nurodome, kuri yra pazymetas
	//pazymime nauja
	document.getElementById('tab'+selected).className='pbox_selected';
	if(selected==1){
		document.getElementById('aimg'+selected).src='images/Untitled-3_01.gif';
	}else{
		document.getElementById('aimg'+selected).src='images/Untitled-3_02.gif';
	}
	document.getElementById('dimg'+selected).src='images/pbox_5.gif';
	var next=selected*1+1;
	if(document.getElementById('aimg'+next)){
		document.getElementById('aimg'+next).src='images/pbox_6.gif';
	}
	document.getElementById('content'+selected).style.display='block';
	
}

function ChangeTabIesko(selected){
	//atzymime pries tai buvusi
	if(selected==1){
		document.getElementById('aimg1').src='images/Untitled-3_01.gif';
		document.getElementById('dimg1').src='images/pbox_5.gif';
		document.getElementById('tab1').className='pbox_selected';
		document.getElementById('content1').style.display='block';
		
		document.getElementById('aimg2').src='images/pbox_6.gif';
		document.getElementById('dimg2').src='images/pbox_11.gif';
		document.getElementById('tab2').className='pa_tekstas';
		document.getElementById('content2').style.display='none';
	}else{
		document.getElementById('aimg1').src='images/pbox_9_01.gif';
		document.getElementById('dimg1').src='images/pbox_11.gif';
		document.getElementById('tab1').className='pa_tekstas';
		document.getElementById('content1').style.display='none';
		
		document.getElementById('aimg2').src='images/Untitled-3_02.gif';
		document.getElementById('dimg2').src='images/pbox_5.gif';	
		document.getElementById('tab2').className='pbox_selected';
		document.getElementById('content2').style.display='block';
	}
}

new function()
{
	var _W = window, _D = document;
	addEvent(_W, 'load', onLoad);

	function addEvent(element, name, handler)
	{
		if (element.attachEvent) element.attachEvent('on'+name, function(){handler.apply(element)});
		else if(element.addEventListener) element.addEventListener(name, handler, false);
	}

	function cEle(name)
	{
		return _D.createElement(name)
	}

	function onLoad()
	{
		setIFrameLinks()
	}

	function setIFrameLinks()
	{
		var a = _D.links;
		for (var i=0; i < a.length; i++)
		{
			if (/\biframe\b/.test(a[i].className))
			{
				new IOpener(a[i]);
			}
		}
	}

	function IOpener(element)
	{
		var f;
		if (!(f = IOpener.iframe)) {
			f = IOpener.iframe = cEle('iframe');
			f.id = 'iframas';
			f.frameBorder = 0;
			f.allowTransparency =1;
			
			f.name = 'iframas';
			_D.body.appendChild(f);
		}

		element.onclick = function()
		{
			if (f.clicker != this) {
				f.clicker = this;
				f.style.display = 'block';
				f.style.backgroundColor = 'transparent';
			
				f.style.top = this.offsetTop + 'px';
				f.style.left = this.offsetLeft + this.offsetWidth + 'px';
				f.src = f.clicker.href;
				f.frameborder = 0;
			} else {
				f.clicker = null;
				f.style.display = 'none';
			}
			return false;
		}
	}

}();

function DefineXHR(){
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false
		}
	}
	return xmlhttp;
}

function BigWindow(link){
	window.open(link + '&' + sessionId, "", "status=1, width=840, height=600, dependent=1, scrollbars=1, directories=0, location=0, menubar=0, personalbar=0, resizable=0, titlebar=0, toolbar=0, screenX=200, screenY=200");
}

function SmallWindow(link, width, height){
	if(!width){
		width = 650;
	}
	if(!height){
		height = 500;
	}
	
	params = "status=1, width="+width+", height="+height+", dependent=1, directories=0, " + 
	         "location=0, menubar=0, personalbar=0, resizable=0, titlebar=0, " +
	         "toolbar=0, screenX=200, screenY=200, left=200, top=200, scrollbars=1";
	window.open(link + '&' + sessionId, "", params);
}
function ServicesWindow(link){
	var link1 = '';
	for(var j=0; j<i; j++){
		if(Arr[j]!=null){
			link1 += '&Object['+j+']='+Arr[j];
		}
	}
	params = "status=1, width=700, height=400, left=100, top=200, dependent=1, directories=0, " + 
	         "location=0, menubar=0, personalbar=0, resizable=0, titlebar=0, " +
	         "toolbar=0, screenX=200, screenY=200, scrollbars=1";
	window.open(link + link1 + '&' + sessionId, "Service", params);
}
function SelectAdv(check){
	if(check.checked==true){
		Arr[i++]=check.id;
	}else{
		for(var j=0; j<i; j++){
			if(Arr[j]==check.id){
				delete Arr[j];
			}
		}
	}
}

function ReplyWindow(link){
	params = "status=1, width=600, height=480, dependent=1, directories=0, " + 
	         "location=0, menubar=0, personalbar=0, resizable=0, titlebar=0, " +
	         "toolbar=0, screenX=200, screenY=200, scrollbars=1";
	window.open(link, "", params);
}

function PrintWindow(link){
	window.open(link, "", "menubar=1, status=1, width=820, height=600, resizable=1, scrollbars=1");
}
function newWindow(link){
	window.open(link);
}


function GetCheck(toUrl){
	$.get(toUrl, {}, function(data){
		$('.selected-adverts').val(data);
	});
}

function check(ob, obj, ids) {
	if(ob.checked == true){
		GetCheck('/index.php?mod=Print&act=Check&check=true&obj='+obj+'&id='+ids + sessionId);
	}
	else {
		GetCheck('/index.php?mod=Print&act=Check&check=false&obj='+obj+'&id='+ids + sessionId);
	}
}

function checkuser(ob, obj, ids) {
	if(ob.checked == true){
		GetCheck('/index.php?mod=Print&act=CheckUser&check=true&obj='+obj+'&id='+ids + sessionId);
	}
	else {
		GetCheck('/index.php?mod=Print&act=CheckUser&check=false&obj='+obj+'&id='+ids + sessionId);
	}
}

/*
 * Funkcija užduoda klausima ir, jei atsakymas teigiamas, permeta nurodytu adresu
 */
function ask(theLink, askmsg){
    var is_confirmed = confirm(askmsg);
    if (is_confirmed) {
        theLink.href;
    }

    return is_confirmed;
}

function allowedSymbol(e){
	var event = (window.event) ? window.event : e;
	if(!event || !event.type) return true;
	var str = (event.keyCode)? event.keyCode: ((event.charCode)? event.charCode: event.which);
	
	if(str == 8 || str == 9 || str == 13 || str == 37 || str == 38 || str == 39 || str == 40 || str == 46){//special symbols
		return true;
	}

	return (str >= 48 && str <= 57);
}
//papildomai leidzia + (telefonams)
function allowedSymbolPlius(event){
	var event = (window.event) ? window.event : e;
	if(!event || !event.type) return true;
	var str = (event.keyCode)? event.keyCode: ((event.charCode)? event.charCode: event.which);

	if(str == 8 || str == 9 || str == 13 || str == 37 || str == 38 || str == 39 || str == 40 || str == 46){//special symbols
		return true;
	}
	return (str >= 48 && str <= 57 || str == 43 || str == 32 || str == 8 || str == 13);
}


// Check that a string contains only numbers
function isNumeric(string, ignoreWhiteSpace) {
   if (string.search) {
      if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) return false;
   }
   return true;
}

function edit_to(id, obj){
	if (a) window.location.href='/index.php?mod=Edit&act=AddObj&obj='+obj+'&id='+id + sessionId;
	a=true;
}

function uncheckAll(){
	forminputs = document.getElementsByTagName('input');
	for (var i = 0; i < forminputs.length; i++) {
		if (forminputs.item(i).name == "sel") forminputs.item(i).checked = false;
	}
}

function checkSubmit(document, fields){
	if (!document || !fields){
		return false;
	}
	var error_msg = document.getElementById('error_msg');
	if(!error_msg){
		alert('No error_msg div');
	}

	for (x = 0; x < fields.length; x++){
		var el = document.getElementsByName(fields[x]);
		if(!el) continue;
		el = el[0];
		
		if(!this.validateInput(el)){
			error_msg.style.color="red";
			error_msg.style.display = '';
			error_msg.innerHTML = "Užpildykite privalomus laukus!!!";
			return false;
		}
		el.style.backgroundColor="white";
	}

	return true;
}

function validateInput (input){
	if(!input) return false;
	input.style.backgroundColor = 'white';
	
	var without_space = input.value.replace(/\s+/, '');
	if(!without_space.length){
		focusEmptyField(input);
		return false;
	}
	
	return input;
}

function focusEmptyField (input_obj){
	input_obj.style.backgroundColor = 'LightPink';
	input_obj.focus();
}

function checkOfferedPrice(min_price){
	var offered_price = document.getElementById('offered_price');
	offered_price = offered_price.value.replace(/,/, ".");
	
	if(isNaN(offered_price)){
		alert('Jūsų įvesta kaina nėra skaičius.');
		return false;
	}else{
		if(offered_price < min_price){
			alert('Jūsų siūloma kaina yra per maža.');
			return false;
		}
	}
	return true;
}

function debug(variable, type){
	var str = 'Type: ' + typeof(variable) + '\n';
	str += 'Properties:\n';
	
	if(typeof variable == 'string'){
		str += variable;
	}else{		
		for(i in variable){
			if(typeof variable[i] == 'function'){
				continue;
			}
			try{
				str += i + ': (' + typeof(variable[i]) +') '+  variable[i] + "\n";
			}catch(e){}
		}
	}
	
	if(!type){
		alert(str);
	}
	else{
		return str;
	}
}

//gemius_identifier = new String('ofgwEjsWS1bpbAI2VNIqeJYlLSnFnJsu8wUkkrJj47r.A7');
//gemius_href=document.location.href;
//if (document.referrer) { gemius_ref = document.referrer; } else { gemius_ref = ""; }
//if(typeof(Error)!='undefined') eval("try { if (typeof(top.document.referrer)=='string') { gemius_ref = top.document.referrer } } catch(gemius_ex) {}");
//var iname = 'id='+gemius_identifier+';ref='+escape(gemius_ref.substring(0,299))+';href='+escape(gemius_href.substring(0,299))+';';
//document.write('<div style="position: absolute; left:-500px; top:-500px;"><iframe src="http://lt.hit.gemius.pl/gemiusaudience.html" name="'+iname+'" width="1" height="1" frameborder="0" scrolling="no"></iframe></div>');


var pp_gemius_identifier = new String('Apg6GCspJ6e5ciu3tGXAZKP8LSoicJsuJpmsBM_O6Rn.W7');
var pp_gemius_hitcollector = 'adnetgalt.hit.gemius.pl';