
function get_text (key) {
   response = $.ajax ({ type: 'POST', url: '/ajax/translate.php', data: 'key='+key, async: false }).responseText;

   return response;
}

function getRequest (name, value, strict) {
   name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
   var regexS = "[\\?&]"+name+"=([^&#]*)";
   var regex = new RegExp( regexS );
   var results = regex.exec( window.location.href );

   if( results == null ) {
      if (value)
	 return value
      else
	 return "";
   } else
      if (!strict)
	 return results[1];
      else if (strict) {
	 if (results[1])
	    return results[1];
	 else
	    return value;
      }
}

function verify(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

function addIngredients (id) {
   $.ajax ({
      type: "POST",
      url: "/ajax/addIngredients.php",
      data: "obj_id="+id,
      success: function(msg){
	 $('#countSL').html(msg);
	 myAlert(get_text('Message'), get_text ('Ta_ylika_prostethikan_sta_pswnia_mou'));
      }
   });
}

function addIngredient (i_id) {
   $.ajax ({
      type: "POST",
      url: "/ajax/addIngredient.php",
      data: "id="+i_id,
      success: function(msg){
	 $('#countSL').html(msg);
      }
   });
}

function addIngredientsQuantity (id, q) {
   $.ajax ({
      type: "POST",
      url: "/ajax/addIngredientsQuantity.php",
      data: "item="+id+"&quantity="+q
   });
}

function delIngredient (id) {
   $.ajax ({
      type: "POST",
      url: "/ajax/delIngredient.php",
      data: "id="+id,
      success: function(msg){
	 $('#countSL').html(msg);
      }
   });
}

function openCloseFridge () {
   $('#kati-sta-grigora').toggle('slow');
   $('#fridge-block').toggle('slow');
   if ($('#openclosefridge').attr ('src').indexOf ('closeFridge') > -1)
      $('#openclosefridge').attr ('src', '/images/icons/openFridge.jpg');
   else
      $('#openclosefridge').attr ('src', '/images/icons/closeFridge.jpg');
   if ($('#openCloseQuick').attr ('src').indexOf ('closeFridge') > -1)
      $('#openCloseQuick').attr ('src', '/images/icons/openFridge.jpg');
   else
      $('#openCloseQuick').attr ('src', '/images/icons/closeFridge.jpg');
}

function showTaPswniaMou () {
   $('#extraHTML').html ('<div id="bgscreen"><div id="bgscreen_loading"><img src="/images/bgscreen-loading.gif" border="0" alt="Loading"></div><div id="bgscreen_contents" style="display:none;"></div></div>');
   $('#bgscreen_contents').load ('/shoppinglist.php', function () {$('#bgscreen_contents').show();});
}

function hideTaPswniaMou () {
   $('#bgscreen').remove();
}

function showSendMail () {
   $('#extraHTML').html ('<div id="bgscreen"><div id="bgscreen_loading"><img src="/images/bgscreen-loading.gif" border="0" alt="Loading"></div><div id="bgscreen_contents" style="display:none;"></div></div>');
   $('#bgscreen_contents').load ('/sendmail.php', function () {$('#bgscreen_contents').show();});
}

function hideSendMail (id) {
   if (!id)
      $('#bgscreen').remove();
   if (id == 1)
      $('#bgscreen_contents').remove();
   if (id == 2)
      $('#bgscreen').remove();
}

function myAlert (title, text) {
   var html = '<div class="genericPopUp psonia_popup"><div class="close"><a href="#" onclick="return false;"><img src="/images/general-imgs/genericPopClose.gif"></a></div><h1>'+title+'</h1><p>'+text+'</p><div class="altClose"><a href="#" onclick="return false;">'+get_text('CLOSE')+'</a></div></div>';

   $('#popup_holder').html (html);
   $('.close').click (function () {$('#popup_holder').html ('');});
   $('.altClose').click (function () {$('#popup_holder').html ('');});   
}
