
	var ESHOP_URL	= document.location.protocol+'//'+document.location.hostname+'/evaistine/';

	(function(){
	  //if (document.location.protocol == 'http:') document.location.href = document.location.href.replace('http:', 'https:');
	})();

	function pausecomp(millis){
		var date = new Date();
		var curDate = null;
		do { curDate = new Date(); }
		while(curDate-date < millis);
	}

	function valid_email(email){  
		var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;  
		return emailPattern.test(email);
	}
	
	function get_info(v_type, v_get, v_oid, v_js) {
		try { var xmlHttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");	} catch (e) { alert("Nesupranta AJAX!"); return false; }
		//*********************************************//
		xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState==4) { 
				if (v_oid) {
					try {	document.getElementById(v_oid).innerHTML = xmlHttp.responseText; } catch (e) { alert(e+' Nesupranta innerHTML!'); }
				}	else { 
					if (xmlHttp.responseText.length!=0) { try { eval(xmlHttp.responseText);	} catch (e) { alert(e+' get=['+ xmlHttp.responseText+']!'); }}
				}
				if (v_js) {
					try { eval(v_js); } catch (e) { alert(e+' JS=['+v_js+']!'); }
				}
			}
		}
		//*********************************************//
		var v_url=ESHOP_URL+"lib/get.php?info="+v_type+"&"+v_get;
		xmlHttp.open("GET",v_url,true);
		xmlHttp.send(null);
	}

	/***********************************************/
	/********         PIESIAME FORMAS      *********/
	/***********************************************/


	function set_pg(p_value){
		get_info('set_page', 'pg='+p_value, null);
		pausecomp(500);
		get_info('draw_list', null, 'o_list');
		get_info('draw_pages', null, 'o_pages');
	}

	function set_pgi(p_value){
		get_info('set_itemsinpage', 'pgi='+p_value, null);
		pausecomp(500);
		get_info('draw_list', null, 'o_list');
		get_info('draw_pages', null, 'o_pages');
	}

	function set_toolbar(p_value){
		//alert('JS=['+p_value+']=['+escape(p_value)+']');
		get_info('set_toolbar', 'toolbar='+escape(p_value), null);
		pausecomp(100);
		// Darom refresh
		//get_info('draw_toolbar', null, 'o_toolbar');
		//get_info('draw_list', null, 'o_list');
		//get_info('draw_pages', null, 'o_pages');
	}

	function set_filter(p_value){
		//alert('JS=['+p_value+']=['+escape(p_value)+']');
		get_info('set_abecele', 'abc='+escape(p_value), null);
		pausecomp(100);
		// Darom refresh
		//get_info('draw_filter', null, 'o_filter');
		//get_info('draw_list', null, 'o_list');
		//get_info('draw_pages', null, 'o_pages');
	}
	
	/***********************************************/
	/********    DETALIZUOJAME PREKE       *********/
	/***********************************************/

	function set_stock_d_info(p_id){
		get_info('draw_stock_d_info', 'id='+p_id, 'o_list_details');
		document.getElementById('o_k_meniu_a').style.color = '#C00';
		document.getElementById('o_k_meniu_b').style.color = '#000';
		document.getElementById('o_k_meniu_c').style.color = '#000';
	}
	
	function draw_stock_d_from(p_id, p_rid){
		get_info('draw_stock_d_from', 'id='+p_id+'&rid='+p_rid, 'o_list_details');
		document.getElementById('o_k_meniu_a').style.color = '#000';
		document.getElementById('o_k_meniu_b').style.color = '#C00';
		document.getElementById('o_k_meniu_c').style.color = '#000';
	}
	
	function draw_stock_d_recommend(p_id){
		get_info('draw_stock_d_recommend', 'id='+p_id, 'o_list_details');
		document.getElementById('o_k_meniu_a').style.color = '#000';
		document.getElementById('o_k_meniu_b').style.color = '#000';
		document.getElementById('o_k_meniu_c').style.color = '#C00';
	}

	/***********************************************/
	/********    DARBAS SU PREKES KREPSELIU  *******/
	/***********************************************/

	function add_stock(p_value, p_qty){
		//alert('JS add_stock=['+p_value+','+p_qty+']');
		get_info('add_stock', 'id='+p_value+'&qty='+p_qty, null);
		pausecomp(300);
		get_info('draw_cardinfo', null, 'o_cardinfo');
	}
	
	function del_stock(p_value, p_drawcard){
		//alert('JS del_stock=['+p_value+']');
		get_info('del_stock', 'id='+p_value, null);
		pausecomp(300);
		get_info('draw_cardinfo', null, 'o_cardinfo');
		if (p_drawcard) {
			pausecomp(200);
			get_info('draw_card', null, 'o_list');
		}
	}

	function update_stock(p_value, p_qty){
		//alert('JS update_stock=['+p_value+','+p_qty+']');
		get_info('update_stock','id='+p_value+'&qty='+p_qty, null);
		pausecomp(300);
		get_info('draw_cardinfo', null, 'o_cardinfo');
		get_info('draw_card', null, 'o_list');
	}

	/***********************************************/
	/***********   BALSAVIMO FORMOS         ********/
	/***********************************************/
	
	function set_vote(){
		//alert('JS set_vote!');
		var voteid = '';
		for (i=0; i<document.apklausa.Vaistai.length; i++){
			//alert(document.apklausa.Vaistai[i].value);
			if (document.apklausa.Vaistai[i].checked==true) {
				voteid = document.apklausa.Vaistai[i].value;
			}
		}
		if (voteid == '') return false;
		get_info('set_vote','voteid='+voteid, null);
		pausecomp(700);
		get_info('draw_vote', null, 'o_vote');
	}

	/***********************************************/
	/***********    PRISTATYMO SALYGOS  ********/
	/***********************************************/

	function statusOption(){
		if (document.getElementById('oCity').selectedIndex > 9) { appendOptionLast(); }
		else { removeOptionLast(); }
	}
	
	function appendOptionLast(){
		//alert('append');
		var elOptNew = document.createElement('option');
		elOptNew.text = '8-18 val.';
		elOptNew.value = '4';
		var elSel = document.getElementById('oDeliveryid_sel');
		try {
			elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
			elSel.add(elOptNew); // IE only
		}
		
		document.getElementById('oDeliveryid').value=4;
		document.getElementById('oDeliveryid_sel').options[2].selected=true;
		document.getElementById('oDeliveryid_sel').disabled=true;
	}

	function removeOptionLast() {
		//alert('remove');
		var elSel = document.getElementById('oDeliveryid_sel');
		if (elSel.length > 0){
			elSel.remove(elSel.length - 1);
		}
		if (elSel.length > 2){
			document.getElementById('oDeliveryid').value=3;
			document.getElementById('oDeliveryid_sel').options[1].selected=true;
			document.getElementById('oDeliveryid_sel').disabled=false;
		}
	}


	/***********************************************/
	/**************    COOKIES VALDYMAS     ********/
	/***********************************************/

	function setCookie(name,value,days) {
		//alert('setCookie('+name+'=['+value+'] days=['+days+'])');
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
	function getCookie(name) {
		//alert('getCookie('+name+')');
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function delCookie(name) {
		//alert('delCookie('+name+')');
		setCookie(name,"",-1);
	}

