function loading_cart(fid,q,sign)
	{
	gid('ajax_loading').style.visibility = 'visible';
	post('loaded_cart',window.location,'ajax=update_cart&fid='+fid+'&q='+q+'&sign='+sign);
	changecss('body','cursor','wait');
	changecss('.loading_cart','cursor','wait');
	}


function loaded_cart(){
	//return;
	if (http_request.readyState == 4  && http_request.status == 200 )
			{

				try {	

					//alert(http_request.responseText);
					params = http_request.responseText.split('###');
				
					gid('cart_broy').innerHTML = params[0];

					gid('cart_products').innerHTML = params[2];

					gid('ajax_loading').style.visibility = 'hidden';
					if(params[1].length>0)
						{
						alert(params[1]);
						}
					

					changecss('body','cursor','');
					changecss('.loading_cart','cursor','');
					}
					catch(e){
						alert(e.message);
						return false;
						}

			}
		else if(http_request.readyState == 4  && http_request.status != 200)
			{
			alert('error with Ajax status!= 200');
			}
}


function show_hide_cart()
 {
 try{
	co = gid('cart_items');

	 if(co.style.display == 'none')
		 {
			co.style.display = '';
			post('ne',window.location,'ajax=save_show_cart&display=');
		 }
	 else{
		 	co.style.display = 'none';
			post('ne',window.location,'ajax=save_show_cart&display=none');
		 }

	
	
 	}
	 catch(e){
	 alert(e.message);
	 }
 }

function ne()
	{
	return true;
	}


function digit(e)
	{
	if (document.all)
				{
				var key = e.keyCode;
				var ch = String.fromCharCode(key);
				var obj = e.srcElement;
				}
	else
				{
				var key = e.which;
				var ch = String.fromCharCode(key);
				var obj = e.target;
				}

	
	if(ch == '.' && obj.value.indexOf('.') !=-1 ) return false;
	if(ch.match(/[^0-9\.]{1}/) && key!=8 && key!=0 ) return false;
	
	}


function changecss(theClass,element,value) {
//documentation for this script at http://www.shawnolson.net/a/503/
 var cssRules;
 if (document.all) {
  cssRules = 'rules';
 }
 else if (document.getElementById) {
  cssRules = 'cssRules';
 }
 for (var S = 0; S < document.styleSheets.length; S++){
  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
    document.styleSheets[S][cssRules][R].style[element] = value;
   }
  }
 }	
}

function show_hide(id)
 {
 try{
	 if(gid(id).style.display == 'none')
		 {
		 	gid(id).style.display = '';
		 }
	 else{
	 	gid(id).style.display = 'none';
		 }
 	}
	 catch(e){
	 alert(e.message);
	 }
 }


//POST
  function post(hf,url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = eval(hf);
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Accept-Charset", "windows-1251");
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      //http_request.setRequestHeader("Content-Transfer-Encoding","binary");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "keep-alive");
      http_request.send(parameters);
   }


function fake_post(address_target,params)
	{

	var adrt = address_target.split('|');
	var url = adrt[0];
	var target = adrt[1];

	//napravi nova forma 
	var form = document.createElement( "form" );
	form.method = 'POST';
	form.action = url;

	if(target)
		{
		form.target  = target;
		}

	//Zapochi da nabivash vytre inputcheta
	

	var params_array = params.split(',');
	for (i=0;i<params_array.length;i++)
		{
		pma = params_array[i].split('=');
		name = pma[0];
		value = pma[1];

		//JS TRIM :)
		name = name.replace(/^[\s]+/,'');
		value = value.replace(/^[\s]+/,'');

		name = name.replace(/[\s]+$/,'');
		value = value.replace(/[\s]+$/,'');
		
		input_el = document.createElement( "input" );
		input_el.type = 'hidden';
		input_el.name = name;
		input_el.value = value;

		form.appendChild(input_el);
		
		}

	//skrii shibanata forma ot shibani FF
	form.style['display'] = 'none';

	//NAII FORMATA U DOKUMENTO
	document.body.appendChild(form);

	//ARE ZAMINAVAY
	form.submit();
	}


function gid(id)
	{
	return document.getElementById(id);
	}

function clk(id)
	{
	gid('menu_dot'+id).style.background = 'black';
	}

function unclk(id)
	{
	gid('menu_dot'+id).style.background = '#EDC623';
	}



function ipop(url) {
  window.open(url,'ipop','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}



function insert_option()
	{
	var all_options = gid('all_options');
	var options = gid('options');

	if(!(all_options.value>0))
		{
		alert('No option selected');
		}
	
	var found = 0;

	if(options.length>0)
		{
		for(key=0;key<options.length;key++)
			{
			if(options.options[key].value == all_options.value)
				found = 1;
			}
		}



	if(found!=1)
		{
		options.options[options.options.length] = new Option(all_options.options[all_options.selectedIndex].text,all_options.options[all_options.selectedIndex].value);	
		}

	}


function delete_option()
	{
	var options = gid('options');
	if(options.length>0)
		{
		for(key=0;key<options.length;key++)
			{
			if(options.options[key].selected)
				{
				options.options[key] = null;
				}
			}
		}
	}



function select_all(obj)
{	
	for (i=0 ;i < obj.options.length; i++)
	{
	obj.options[i].selected = true;
	}
}





