//document.getElementById('registracijaSlot').innerHTML='<div style=margin-left:16px;height:64px;background-color:#282828;>lalab</div>';

function register()
{
   var elpastas = document.getElementById('reg_elpastas').value;
   var klaidos = 0;   
   if(trimString(elpastas).length==0)
   {
      document.getElementById('reg_elpastas').style.background = "red";
    	document.getElementById('reg_elpastas').style.color = "white";
    	document.getElementById('reg_elpastas').value = "!!!";
    	window.setTimeout("document.getElementById('reg_elpastas').style.background='#FFFFFF';document.getElementById('reg_elpastas').value = '';document.getElementById('reg_elpastas').style.color = 'black';",2000)
    	klaidos++;
   }
   
   if(klaidos>0)
   {
      return false;
   }
   
   advAJAX.get({
    url: "index.php?action=register_email",
    onSuccess : function(obj) {
    	if(obj.responseText=='email_error')
    	{
          old_value = document.getElementById('reg_elpastas').value;
          document.getElementById('reg_elpastas').style.background = "red";
    	    document.getElementById('reg_elpastas').style.color = "white";
    	    document.getElementById('reg_elpastas').value = "Užpildykite šį laukelį";
    	    window.setTimeout("document.getElementById('reg_elpastas').style.background='#FFFFFF';document.getElementById('reg_elpastas').value = old_value;document.getElementById('reg_elpastas').style.color = 'black';",2000)
    	}else if(obj.responseText=='gerai')
    	{
    	     document.getElementById('uzsakytiBlock').innerHTML='<div>Jūs sėkmingai užsiprenumeravote naujienas.</div>';
    	}else if(obj.responseText=='jau_yra')
    	{
    	     document.getElementById('uzsakytiBlock').innerHTML='<div><b>Jūs jau esate prisiregistravę...</b></div>';
    	}
    	//window.setTimeout("document.getElementById('ajax_error').innerHTML=''",2000)
    },
    parameters : {
      "elpastas" : elpastas
    },
    onTimeout : function() {    	
       if(document.getElementById('ajax_error'))
       {
          document.getElementById('ajax_error').innerHTML="<span style='color:red'>!</span>";
       } 
    },
    onError : function(obj) {
      if(document.getElementById('ajax_error'))
      {
         document.getElementById('ajax_error').innerHTML="<span style='color:red'>Error: "+ obj.status +"</span>";
      } 
    },
    onLoading : function() {
        if(document.getElementById('ajax_indicator_reg'))
        {
            document.getElementById('ajax_indicator_reg').className = "ajax_loading_vote";
        }
    },
	onFinalization : function() {
	     if(document.getElementById('ajax_indicator_reg'))
	     {
	        document.getElementById('ajax_indicator_reg').className = "normal";
	     }
    }

	});
}

function deleteFromCart()
{
   advAJAX.get({
    url: "index.php?action=delete_from_cart",
    onSuccess : function(obj) {
    	if(obj.responseText=='gerai')
    	{
          document.location.reload();
    	}
    },
    parameters : {
      "cart" : getChecked(document.cart_form)
    },
    onTimeout : function() {    	
       if(document.getElementById('ajax_error'))
       {
          document.getElementById('ajax_error').innerHTML="<span style='color:red'>!</span>";
       } 
    },
    onError : function(obj) {
      if(document.getElementById('ajax_error'))
      {
         document.getElementById('ajax_error').innerHTML="<span style='color:red'>Error: "+ obj.status +"</span>";
      } 
    },
    onLoading : function() {
        if(document.getElementById('ajax_indicator'))
        {
            document.getElementById('ajax_indicator').className = "ajax_loading2";
        }
    },
	onFinalization : function() {
	     if(document.getElementById('ajax_indicator'))
	     {
	        document.getElementById('ajax_indicator').className = "normal";
	     }
    }

	});
}

function vote(klausimas_id)
{
    advAJAX.get({
    url: "index.php?action=vote_apklausa",
    onSuccess : function(obj) {
    	if(obj.responseText!="negerai")
    	{
           document.getElementById('atsakymai_'+klausimas_id).innerHTML = obj.responseText;
    	}
    },
    parameters : {
      "klausimas_id" : klausimas_id,
      "atsakymai" : getRadioSelected(document.forms['apklausa_'+klausimas_id])
    },
    onTimeout : function() {    	
       if(document.getElementById('ajax_error_'+klausimas_id))
       {
          document.getElementById('ajax_error_'+klausimas_id).innerHTML="<span style='color:red'>!</span>";
       } 
    },
    onError : function(obj) {
      if(document.getElementById('ajax_error_'+klausimas_id))
      {
         document.getElementById('ajax_error_'+klausimas_id).innerHTML="<span style='color:red'>Error: "+ obj.status +"</span>";
      } 
    },
    onLoading : function() {
        if(document.getElementById('ajax_indicator_'+klausimas_id))
        {
            document.getElementById('ajax_indicator_'+klausimas_id).className = "ajax_loading_vote";
        }
    },
	onFinalization : function() {
	     if(document.getElementById('ajax_indicator_'+klausimas_id))
	     {
	        document.getElementById('ajax_indicator_'+klausimas_id).className = "normal";
	     }
    }

	});
}

function rezultatai(klausimas_id)
{
    advAJAX.get({
    url: "index.php?action=rezultatai",
    onSuccess : function(obj) {
    	if(obj.responseText!="negerai")
    	{
           document.getElementById('atsakymai_'+klausimas_id).innerHTML = obj.responseText;
    	}
    },
    parameters : {
      "klausimas_id" : klausimas_id
    },
    onTimeout : function() {    	
       if(document.getElementById('ajax_error_'+klausimas_id))
       {
          document.getElementById('ajax_error_'+klausimas_id).innerHTML="<span style='color:red'>!</span>";
       } 
    },
    onError : function(obj) {
      if(document.getElementById('ajax_error_'+klausimas_id))
      {
         document.getElementById('ajax_error_'+klausimas_id).innerHTML="<span style='color:red'>Error: "+ obj.status +"</span>";
      } 
    },
    onLoading : function() {
        if(document.getElementById('ajax_indicator_'+klausimas_id))
        {
            document.getElementById('ajax_indicator_'+klausimas_id).className = "ajax_loading_vote";
        }
    },
	onFinalization : function() {
	     if(document.getElementById('ajax_indicator_'+klausimas_id))
	     {
	        document.getElementById('ajax_indicator_'+klausimas_id).className = "normal";
	     }
    }

	});
}

function ajaxAtsiliepimas()
{
    advAJAX.get({
    url: "index.php?action=atsiliepimai",
    onSuccess : function(obj) {
    	if(obj.responseText!="negerai")
    	{
           document.getElementById('ajaxRekomendacijos').innerHTML = obj.responseText;
    	}
    },
    onTimeout : function() {    	
       if(document.getElementById('ajaxRekomendacijos'))
       {
          document.getElementById('ajaxRekomendacijos').innerHTML="<span style='color:red'>!</span>";
       } 
    },
    onError : function(obj) {
      if(document.getElementById('ajaxRekomendacijos'))
      {
         document.getElementById('ajaxRekomendacijos').innerHTML="<span style='color:red'>Error: "+ obj.status +"</span>";
      } 
    },
    onLoading : function() {
        if(document.getElementById('ajaxRekomendacijos'))
        {
            document.getElementById('ajaxRekomendacijos').className = "ajax_loading_vote";
        }
    },
	onFinalization : function() {
	     if(document.getElementById('ajaxRekomendacijos'))
	     {
	        document.getElementById('ajaxRekomendacijos').className = "normal";
	     }
    }

	});
}

function getChecked(formName) {
	list = "";
	checkForm = formName;
	for (i=0; i <= checkForm.length-1; i++)
	{
		if (checkForm.elements[i].type == "checkbox")
		{
			if (checkForm.elements[i].checked == true)
			{
				list += checkForm.elements[i].value+",";
			}
		}
	}
	return list;
}

function getRadioSelected(formName) {
	list = "";
	checkForm = formName;
	for (i=0; i <= checkForm.length-1; i++)
	{
		if (checkForm.elements[i].type == "radio")
		{
			if (checkForm.elements[i].checked == true)
			{
				list += checkForm.elements[i].value+",";
			}
		}
	}
	return list;
}


function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   document.location.href="index.php?cid=4&lang={lang}&filter=3&q="+escape(document.getElementById("quick_search").value);
   return false;
   }
else
   return true;
}

function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );
  return sInString.replace( /\s+$/g, "" );
}

function ajaxTimer()
{
   setInterval("ajaxAtsiliepimas()", 20000);
}

