function getAjaxWindowContent(urlas){
	

	document.getElementById('WINDOW').style.top = 50 + f_scrollTop() + 'px';
	document.getElementById('WINDOW').style.left = parseInt(f_clientWidth()/2) - 385 + 'px';
	
	$.ajax({
		url:urlas,
		success:function(html){
			$('#WINDOW_content').html(html);
			$('#WINDOW').slideDown(500);
			$('#OVERLAY').slideDown(500);
		}	
	});


}

function closeAjaxWindow(){
	$('#WINDOW').slideUp(500);
	$('#OVERLAY').slideUp(500);
}



$(document).ready(function () { $('a[rel]').lightBox(); document.getElementById('OVERLAY').onclick = closeAjaxWindow; } );

function Cituoti(id){

	time = document.getElementById('comment_time_'+id).innerHTML;
	author = document.getElementById('comment_author_'+id).innerHTML;
	desc = document.getElementById('comment_desc_'+id).innerHTML;

	//obj = document.getElementById('title___Frame');

	window.frames['title___Frame'].FCK.SetHTML('<div class="citata" contenteditable="false"><b>'+time+' - '+author+'</b><br />'+desc+'</div><p id="cit_pradzia">&nbsp;</p>');
	window.frames['title___Frame'].FCK.Focus();

}

function setValues(formName, elmName){
	var options = document.forms[formName].elements[elmName].options;
	for(var i=0, j=0, ids=""; i<options.length; i++){
		if(options[i] && options[i].selected){
			if(j!=0) ids += "::";
			ids += options[i].value;
			j++;
		}
	}
	document.forms[formName].elements[elmName+'_tmp'].value = ids;
	return ids;
}

function addSuccess(){
	$("#cart_sum b").animate( { backgroundColor:"#FF6666" }, 500, 0, function(){ $("#cart_sum b").animate( { backgroundColor:"#FFFFFF" }, { queue:false, duration:2000 } ) } );
}

function addSuccess_order(){
	$("#order_cart_sum b").animate( { backgroundColor:"#FF6666" }, 500, 0, function(){ $("#order_cart_sum b").animate( { backgroundColor:"#FFFFFF" }, { queue:false, duration:2000 } ) } );
}

function add2cart(aurl, content, func){
$.ajax({
  url: aurl,
  cache: false,
  success: function(html){
    $("#"+content).html(html);
    func();
  }
});
}

function modifSelected(){
	ok = true;
	$('.item_modif select').each( function(){ if($(this).val()==''){ ok=false; } } );
	return ok;
}

function getAllModif(){
	str = "";
	$('.item_modif select').each( function(){ str+="::"+$(this).val(); } );
	return str;
}


stop_scroll = false;

function slider(container, content, direction){ 
	if(!stop_scroll){
		leftPos_int = parseInt($('#'+container).css('left'))-(direction)*parseInt($('#'+content).width());
		if(direction==-1){
			if(leftPos_int>0){ 
				stop_scroll=false;
				return;
			}
		}else{
			if(leftPos_int*(-1)>$('#'+container+' .product_thumb').length*136){ 
				stop_scroll=false;
				return;
			}
		}
		leftPos = leftPos_int+'px';
		if($('#'+container).width()<=((parseInt(leftPos))*(-1))){
			$('#'+container).animate( { left:'0px' }, 1000, '', function(){ stop_scroll=false; } );
		}else{
			$('#'+container).animate( { left:leftPos }, 1000, '', function(){ stop_scroll=false; } );
		}
	}
}

function submitSearchForm(url, form){
	location = url + document.forms['search'].elements['q'].value;
}

function getMouseXY(e) {
  if (document.all) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return { x:tempX, y:tempY }
}

function ajax(a_url, a_obj, top_pos){
			$.ajax({
			  async: true,
			  url: a_url,
			  cache: false,
			  beforeSend: function(){
			  	//$("#"+a_obj).slideUp(1000, function(){  });
			  },
			  success: function(html){
			    $("#"+a_obj).html(html);
			    if(top_pos) $("#"+a_obj).animate({height:"150px", top:top_pos}, 1000);
			  },
			  //timeout: 20,
			  complete: function(html){
			    
			  }
			});
}

function post(a_url, a_obj, form){
			$.ajax({
			  type: "POST",
			  async: true,
			  url: a_url,
			  cache: false,
			  data: formData2QueryString(form),
			  beforeSend: function(){
			  	$("#"+a_obj).slideUp(500, function(){  });
			  },
			  success: function(html){
			    $("#"+a_obj).html(html);
			    $("#"+a_obj).slideDown(1000);
			  },
			  //timeout: 20,
			  complete: function(html){
			    
			  }
			});
}

function setSelected(obj, val){
	for(i=0; i<obj.options.length; i++){
		if(obj.options[i].value==parseInt(val)) index=i;
	}
	if(index) obj.options[index].selected=true;
}

function formData2QueryString(docForm) {

        var strSubmit       = '';
        var formElem;
        var strLastElemName = '';
        
        for (i = 0; i < docForm.elements.length; i++) {
                formElem = docForm.elements[i];
                switch (formElem.type) {
                        // Text, select, hidden, password, textarea elements
                        case 'text':
                        case 'hidden':
                        case 'password':
                        case 'textarea':
				formElem.value = formElem.value.replace(/&/g, '%26');
				formElem.value = formElem.value.replace(/\+/g, '%2B');
				strSubmit += formElem.name + '=' + formElem.value + '&';
                        break;
                        case 'select-one':
                        	strSubmit += formElem.name + '=' + escape(formElem.options[formElem.selectedIndex].value) + '&';
                        break;
                        case 'checkbox':
                        	if(formElem.checked == true) strSubmit += formElem.name + '=' + escape(formElem.value) + '&';
                        break;
                        case 'radio':
	                        if(formElem.checked == true) strSubmit += formElem.name + '=' + escape(formElem.value) + '&';
                }
        }
        return strSubmit;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return { x:curleft, y:curtop };
}

function showPostForm(obj){
	document.getElementById('NL_overlay').style.display = 'block';
	document.getElementById(obj).style.display = 'block';
	try{
		document.getElementsByTagName("html")[0].style.overflow = "hidden";
	}catch(e){}
}

function closePostForm(obj){
	
	clearPostForm(obj);
	
	document.getElementById('NL_overlay').style.display = 'none';
	document.getElementById(obj).style.display = 'none';
	try{
		document.getElementsByTagName("html")[0].style.overflow = "";
	}catch(e){}
}

function clearPostForm(obj){
	document.getElementById(obj + '_form').reset();
}

function format_float(number){
	var str = new String();
	str = number + "";
	arr = str.split(/\./);
	if(arr.length>1){
		if((arr[1]).length<2)
			str = str + "0";
		if((arr[1]).length>2)
			str = Math.round(str*100)/100;
	}else{
		str = str + ".00";
	}
	return str;
}

function checkInt(x){
	var filter  = /^[0-9]*$/;
	if (filter.test(x)) return true;
	else return false;
}

function valid_email(){
	if(checkMail(document.forms['news'].elements['email'].value)) 
		document.forms['news'].submit();
	else
		alert('Neteisingai įvestas el. paštas.');
}

function checkMail(x)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function valid_number(x)
{
	var filter  = /^([0-9])*$/;
	if (filter.test(x)) return true;
	else return false;
}

function inputFocus(field){
	if(document.getElementById(field.name + '_').value != 1) 
		field.value='';
}

function inputBlur(field, text){
	if(document.getElementById(field.name + '_').value != 1 && field.value != '') 
		document.getElementById(field.name + '_').value = 1;
	if(document.getElementById(field.name + '_').value != 1) 
		field.value = text;
}

function show_hide(id){
	var obj = document.getElementById(id);
	if(obj.style.display=='none'){
		//obj.style.visibility='visible';
		//obj.style.position='static';
		obj.style.display = 'block';
	}else{
		//obj.style.visibility='hidden';
		//obj.style.position='absolute';
		obj.style.display = 'none';
	}
	
}


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}



