
function sendmail(user_id, item_id, email, text, phone){
	error = 0;
	if(email==''){
		$('#se_email').css({'border':'1px solid #660000'});
		error = 1;
	}
	if(text==''){
		$('#se_text').css({'border':'1px solid #660000'});
		error = 1;
	}
	if(error!=1){
		$.ajax({
			type:"POST", 
			url:"ajax.php?content=sendmail&lng=lt&user_id="+user_id+"&item_id="+item_id, 
			data:"email="+email+"&text="+text+"&phone="+phone, 
			beforeSend:function(){ $('#sendmail_'+user_id).html('Palaukite...') },
			success:function(msg){ $('#sendmail_'+user_id).html(msg) }
		})
	}
}


var stop_scroll = false;

function slider(container, content){ 
	if(!stop_scroll){
		stop_scroll=true;
		topPos = parseInt($('#'+container).css('top'))-parseInt($('#'+content).height())-6+'px';
		if($('#'+container).height()<=((parseInt(topPos))*(-1))){
			$('#'+container).animate( { top:'0px' }, 1000, '', function(){ stop_scroll=false; } );
		}else{
			$('#'+container).animate( { top:topPos }, 1000, '', function(){ stop_scroll=false; } );
		}
	}
}

function deleteItem(item_id){
 $.ajax({
   type: "GET",
   url: "ajax.php?content=delete_item&id="+item_id,
   success: function(msg){
      if(msg=='ok'){
        $('#product_'+item_id).hide(1000);
      }else{
      	alert('Prisijunkite!');
      }
    }
 });
}

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).fadeOut(500, function(){  });
			  },
			  success: function(html){
			    $("#"+a_obj).html(html);
			    $("#"+a_obj).fadeIn(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';
	}
	
}


