/* menu */

/* menu */
/*PHP TO JS*/
function GetString(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}

function sleep(millis){ 
var date = new Date();
  var curDate = null;
  do { curDate = new Date(); }
  while(curDate-date < millis);
}
function base64_decode (data) {
    // Decodes string using MIME base64 algorithm  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/base64_decode
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Thunder.m
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Pellentesque Malesuada
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_decode
    // *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
    // *     returns 1: 'Kevin van Zonneveld'
    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof this.window['btoa'] == 'function') {
    //    return btoa(data);
    //}
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
        ac = 0,
        dec = "",
        tmp_arr = [];
 
    if (!data) {
        return data;
    }
 
    data += '';
 
    do { // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));
 
        bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
 
        o1 = bits >> 16 & 0xff;
        o2 = bits >> 8 & 0xff;
        o3 = bits & 0xff;
 
        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);
 
    dec = tmp_arr.join('');
    dec = this.utf8_decode(dec);
 
    return dec;
}

function is_numeric (mixed_var) {
    // Returns true if value is a number or a numeric string  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/is_numeric
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: David
    // +   improved by: taith
    // +   bugfixed by: Tim de Koning
    // +   bugfixed by: WebDevHobo (http://webdevhobo.blogspot.com/)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: is_numeric(186.31);
    // *     returns 1: true
    // *     example 2: is_numeric('Kevin van Zonneveld');
    // *     returns 2: false
    // *     example 3: is_numeric('+186.31e2');
    // *     returns 3: true
    // *     example 4: is_numeric('');
    // *     returns 4: false
    // *     example 4: is_numeric([]);
    // *     returns 4: false
    return (typeof(mixed_var) === 'number' || typeof(mixed_var) === 'string') && mixed_var !== '' && !isNaN(mixed_var);
}

function base64_encode (data) {
    // Encodes string using MIME base64 algorithm  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/base64_encode
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Bayron Guevara
    // +   improved by: Thunder.m
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Pellentesque Malesuada
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_encode
    // *     example 1: base64_encode('Kevin van Zonneveld');
    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof this.window['atob'] == 'function') {
    //    return atob(data);
    //}
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
        ac = 0,
        enc = "",
        tmp_arr = [];
 
    if (!data) {
        return data;
    }
 
    data = this.utf8_encode(data + '');
 
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);
 
        bits = o1 << 16 | o2 << 8 | o3;
 
        h1 = bits >> 18 & 0x3f;
        h2 = bits >> 12 & 0x3f;
        h3 = bits >> 6 & 0x3f;
        h4 = bits & 0x3f;
 
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
 
    enc = tmp_arr.join('');
 
    switch (data.length % 3) {
    case 1:
        enc = enc.slice(0, -2) + '==';
        break;
    case 2:
        enc = enc.slice(0, -1) + '=';
        break;
    }
 
    return enc;
}
function rand (min, max) {
    var argc = arguments.length;
    if (argc === 0) {
        min = 0;
        max = 2147483647;
    } else if (argc === 1) {
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function range ( low, high, step ) {
    var matrix = new Array;
    var inival, endval, plus;
    var walker = step || 1;
    var chars  = false;
 
    if ( !isNaN( low ) && !isNaN( high ) ) {
        inival = low;
        endval = high;
    } else if ( isNaN( low ) && isNaN( high ) ) {
        chars = true;
        inival = low.charCodeAt( 0 );
        endval = high.charCodeAt( 0 );
    } else {
        inival = ( isNaN( low ) ? 0 : low );
        endval = ( isNaN( high ) ? 0 : high );
    }
 
    plus = ( ( inival > endval ) ? false : true );
    if ( plus ) {
        while ( inival <= endval ) {
            matrix.push( ( ( chars ) ? String.fromCharCode( inival ) : inival ) );
            inival += walker;
        }
    } else {
        while ( inival >= endval ) {
            matrix.push( ( ( chars ) ? String.fromCharCode( inival ) : inival ) );
            inival -= walker;
        }
    }
 
 	eval('matrix_array=['+matrix+'];');
 	
	 return matrix_array;
}




function explode (delimiter, string, limit) {
    // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/explode
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||
        typeof arguments[1] == 'undefined' ) {
        return null;
    }
 
    if ( delimiter === '' ||
        delimiter === false ||
        delimiter === null ) {
        return false;
    }
 
    if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' ) {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}
function basename (path, suffix) {
    // Returns the filename component of the path  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/basename
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
    // *     example 2: basename('ecra.php?p=1');
    // *     returns 2: 'ecra.php?p=1'
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

function empty (mixed_var) {
    // !No description available for empty. @php.js developers: Please update the function summary text file.
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/empty
    // +   original by: Philippe Baumann
    // +      input by: Onno Marsman
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: LH
    // +   improved by: Onno Marsman
    // +   improved by: Francesco
    // +   improved by: Marc Jansen
    // +   input by: Stoyan Kyosev (http://www.svest.org/)
    // *     example 1: empty(null);
    // *     returns 1: true
    // *     example 2: empty(undefined);
    // *     returns 2: true
    // *     example 3: empty([]);
    // *     returns 3: true
    // *     example 4: empty({});
    // *     returns 4: true
    // *     example 5: empty({'aFunc' : function () { alert('humpty'); } });
    // *     returns 5: false
    
    var key;
    
    if (mixed_var === "" ||
        mixed_var === 0 ||
        mixed_var === "0" ||
        mixed_var === null ||
        mixed_var === false ||
        typeof mixed_var === 'undefined'
    ){
        return true;
    }
 
    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            return false;
        }
        return true;
    }
 
    return false;
}

function time () {
    return Math.floor(new Date().getTime()/1000);
}
/**/

function gotourl(url,blank)
{
	if (blank=='_blank') window.open(url);
	else
	location.href=url;
}

function checkToggle(checkboxid)
{
	if ($('#'+checkboxid+'').attr("checked"))
	{
		$('#'+checkboxid+'').removeAttr('checked');
	}
	else
	{
		$('#'+checkboxid+'').attr('checked', 'checked');
	}
	//if ($('#'+checkboxid+'').attr('checked')) $('#'+checkboxid+'').attr('checked', false); else $('#'+checkboxid+'').attr('checked', true);
}
function makeEmpty(str)
{
	return str.replace(/\s+/g,'');
}


/////////////////////
function bvalidator()// არგუმენტები: მეთოდი,ეს ობიექტი
{
	thisobject=arguments[1];
	thisid=$(thisobject).attr('id');
	
	$('#'+thisid+'_after').remove();
	
	alert($(thisobject).val());
	$(thisobject).after('<div class="validator" id="'+thisid+'_after">arasworia</div>');
	//return false;
}
////////////////////
//$(document).click(function() {$('.validator').remove();});

function showlargeimage(ob,imageinfo)
{
	$('.largeimage').hide(200);
	imageurl=$(ob).attr('href');
	divid="div"+rand(10000,99999);
	$(ob).before('<div class="largeimage" style="display:none" id="'+divid+'"><div>'+imageinfo+'</div><img src="'+imageurl+'" onclick="$(\'#'+divid+'\').fadeOut(150);" alt="Loading..."/></div>');
	$('#'+divid).fadeIn(150);
	$('#'+divid).draggable();
	return false;
}

function clearbasket(ask)
{
	if (confirm(ask)==false) return;
	$("#basket_processing").delay(300).fadeIn(200);
	overlay_waiting_to_basket_div();
	$.post(
			"/ajax.php", 
			{ 
				basketpage: is_basket_page(),
				action: "clear basket"
			},
			function(data)
					{
						$("#user_basket").html(data);
						normalize_basket_size();
						hide_waiting_div();
					}
			);
}
function addthisproduct(product_id,qty)
{
		
	if (qty=='' || is_numeric(qty)==false || qty<0) 
	{
	alert('Wrong quantity');
	return;
	}
	else qty=Math.round(qty);
		
		
		setTimeout(function(){
		//function
		
		$("#basket_processing").delay(300).fadeIn(200);
		overlay_waiting_to_basket_div();
			$.post(
			"/ajax.php", 
			{ 
				qty: qty,
				product_id: product_id, 
				basketpage: is_basket_page(),
				action: "add to basket" 
			},
			function(data)
					{
						$("#user_basket").html(data).show(0);
						normalize_basket_size();
						hide_waiting_div();
					}
			);
		//end function
		}, 600);
}

function is_basket_page()
{
	if (document.location.href.match(/basket.html/))return 1;
	else return 0;
}
function delete_product_in_basket(id,ask)
{
	if (confirm(ask)==false) return;
	
	overlay_waiting_to_basket_div()
		$("#basket_processing").delay(300).fadeIn(200);
	$.post(
			"/ajax.php", 
			{ 
				id: id,
				basketpage: is_basket_page(),
				action: "delete product in basket" 
			},
			function(data)
					{
						$("#user_basket").html(data);
						normalize_basket_size();
						hide_waiting_div();
					}
			);
}
function make_this_product_more(id)
{
	
	
	overlay_waiting_to_basket_div();
		$("#basket_processing").delay(300).fadeIn(200);
	$.post(
			"/ajax.php", 
			{ 
				id: id,
				basketpage: is_basket_page(),
				action: "plus one product in basket" 
			},
			function(data)
					{
						
						$("#user_basket").html(data);
						normalize_basket_size();
						hide_waiting_div();
					}
			);
}
function make_this_product_less(id)
{
	if ($("#qty_"+id+"").html()=='1')
	{
		if (confirm("delete?")==false) return;

	}
	
	$("#basket_processing").delay(300).fadeIn(200);
		overlay_waiting_to_basket_div();
		
	$.post(
			"/ajax.php", 
			{ 
				id: id,
				basketpage: is_basket_page(),
				action: "minus one product in basket" 
			},
			function(data)
					{
						
						$("#user_basket").html(data);
						normalize_basket_size();
						hide_waiting_div();
					}
			);
}
function normalize_basket_size()
{
	$("#user_basket_parent").height( $("#user_basket").height() );
}

function overlay_waiting_to_basket_div()
{
	$("#basket_processing").height( $("#user_basket").height() );
	$("#basket_processing").width( $("#user_basket").width() );
}
function hide_waiting_div()
{
	$("#basket_processing").height(30);
	$("#basket_processing").width(130);
}

function disableEnterKey(e)
 {
      var key;      
      if(window.event)
           key = window.event.keyCode; //IE
      else
           key = e.which; //firefox      

      return (key != 13);
 }
function is_email(email){
	var result = email.search(/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{1,30})+$/);
	if(result > -1){ return true; } else { return false; }
}

function keyup_basket_check(id)
{
	
	if ( parseInt($('#in_stock_count_'+id+'').html())<parseInt($('#in'+id+'').val()))
	{  
	$('#in'+id+'').val($('#in'+id+'').val().slice(0,$('#in'+id+'').val().length-1)); 
	return;
	};
}

function check_and_move_to_basket(id)
{
	
	/*
	if ( parseInt($('#in_stock_count_'+id+'').html())<parseInt($('#in'+id+'').val()))
	{ 
	alert('Incorrect QTY'); 
	return;
	}; 
	*/
	$.add2cart( 'div'+id+'', 'basket'  ); 
	
	addthisproduct(id,$('#in'+id+'').val());
}


