function init(id)
{
 var win = window.open('popuppage.php?id=' + id + '', id, 'height=250,width=650,toolbar=0,location=0,scrollbars=1');
}

function initimg(i,w) 
{
 var win = window.open('popupimage.php?i=' + i + '&w='+w, '', 'height=500,width=650,toolbar=0,location=0,scrollbars=1');
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("It's about time to upgrade you browser don't you think?");
	}
}

var getReq = getXmlHttpRequestObject();

var allow_email = 1;

function email_check()
{
	if (getReq.readyState == 4 || getReq.readyState == 0) {
		var email = document.getElementById('email').value;
		if(email){
	                var rand  = Math.random();
			getReq.open("GET", '/ajax_action.php?action=email&login='+email+'&rand='+rand, true);
			getReq.onreadystatechange = email_check_request;
			getReq.send(null);
		} else allow_email=1;
	}
}


function email_check_request()
{
	if (getReq.readyState == 4) {
		var str = getReq.responseText;
		if (str==1) allow_email=1; else allow_email=0;
	}
}



function subscribe_check() {
	if (getReq.readyState == 4 || getReq.readyState == 0) {
		var rand=Math.random();
		var email      = document.getElementById('subscribe_input_email').value;
		if (email=="")    {alert("Pentru a va abona la newsletter-ul Quicky\ncompletarea cimpului \"e-mail\" este obligatorie"); document.getElementById('subscribe_input_email').focus(); return false;};
		if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) 
		{alert("Email-ul introdus nu este unul valid"); document.getElementById('subscribe_input_email').focus(); return false;};

                document.getElementById('subscription_loading').style.display="block";
		getReq.open("GET", '/ajax_action.php?action=subscribe&email='+email+'&rand='+rand, true);
		getReq.onreadystatechange = subscribe_request;
		getReq.send(null);
	}
}



function subscribe_request()
{
	if (getReq.readyState == 4) {
		var str = getReq.responseText.split("\n");
                document.getElementById('subscription_loading').style.display="none";
		if (str[0]==1)	document.getElementById('subscribebox').innerHTML=str[1];
		else alert(str[1]);
	}
}

function login_check() {
	if (getReq.readyState == 4 || getReq.readyState == 0) {
		var rand=Math.random();
		var email      = document.getElementById('login_input_email').value;
		var password   = document.getElementById('login_input_password').value;
		var save       = 'save';

		var cart       = "";
		if (document.getElementById('cart'))		
		cart           = document.getElementById('cart').value;

		if (email=="")    {alert("Completarea cimpului \"e-mail\" este obligatorie");  return false;};
		if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) 
		{alert("E-mailul introdus nu este unul valid"); return false;};
		if (password=="") {alert("Completarea cimpului \"parola\" este obligatorie"); return false;};
                document.getElementById('login_loading').style.display="block";
		getReq.open("GET", '/ajax_action.php?action=check&login='+email+'&password='+password+'&save='+save+'&cart='+cart+'&rand='+rand, true);
		getReq.onreadystatechange = login_request;
		getReq.send(null);

	}
}

var saved_menu=0;

function save_data(element) {
	if (getReq.readyState == 4 || getReq.readyState == 0) {
		var rand=Math.random();
		var value      = document.getElementById(element).value;
		getReq.open("GET", '/ajax_action.php?action=save_data&element='+element+'&value='+value+'&rand='+rand, true);
		getReq.send(null);

	}
}


function login_request()
{
	if (getReq.readyState == 4) {
		var str = getReq.responseText.split("\n");
		var set = str[0].split("~|~");
		saved_menu=set[1];
                document.getElementById('login_loading').style.display="none";

		if (set[0]==1)
			location.reload(true);
		else{
			document.getElementById('login_status').innerHTML=str[1];
			document.getElementById('login_input_password').value="";
		}
	}
}


function menu_login() {
	if (getReq.readyState == 4 || getReq.readyState == 0) {
		var rand=Math.random();
		getReq.open("GET", '/ajax_action.php?action=menu&rand='+rand, true);
		getReq.onreadystatechange = menu_request;
		getReq.send(null);

	}
}


function menu_request()
{
	if (getReq.readyState == 4) {
		var str = getReq.responseText;
		document.getElementById('login_status').innerHTML=str;
		if (saved_menu==1){
			shopping_cart();
        	        document.getElementById('cart_loading').style.display="block";
		}
                document.getElementById('loginbox').style.display="none";
                document.getElementById('login_loading').style.display="none";
	}
}



function shopping_cart() {
	if (getReq.readyState == 4 || getReq.readyState == 0) {
		var rand=Math.random();
		getReq.open("GET", '/ajax_action.php?action=cart&rand='+rand, true);
		getReq.onreadystatechange = cart_request;
		getReq.send(null);

	}
}


function cart_request()
{
	if (getReq.readyState == 4) {
		var str = getReq.responseText;
		document.getElementById('shoppingcart').innerHTML=str;
                document.getElementById('cart_loading').style.display="none";
	}
}


function password_send() {
	if (getReq.readyState == 4 || getReq.readyState == 0) {
		var rand=Math.random();
		var email = document.getElementById('login_input_email').value;

		if (email=="")    {alert("Completarea cimpului \"email\" este obligatorie");  return false;};
		if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) 
		{ alert("Emailul introdus nu este unul valid"); return false;};
                document.getElementById('login_loading').style.display="block";
		getReq.open("GET", '/ajax_action.php?action=resend&login='+email+'&rand='+rand, true);
		getReq.onreadystatechange = password_request;
		getReq.send(null);
	}
}


function password_request()
{
	if (getReq.readyState == 4) {
		var str = getReq.responseText.split("\n");
                document.getElementById('login_loading').style.display="none";
		document.getElementById('login_status').innerHTML=str[1];

		document.getElementById('login_input_email').value="";
		document.getElementById('login_input_password').value="";

		if (str[0]==1)
		{
		}
		else
		{
		}

	}
}

function calculate(id,quantity)
{
var div_id='cart_add_'+id;
if (quantity=="") quantity=1;
var div=document.getElementById(div_id);
div.innerHTML='<a href="/buy.html?add='+id+'&qty='+quantity+'&return=true" class="menu-small"><img src="templates/default/images/btn_add.jpg" border="0" /></a>';
}
