function get_selected_value(id)
{
    var obj = document.getElementById(id);
    return obj.options[obj.selectedIndex].value;
}
function redirect(r)
{
    document.location = baseurl+'redirect.php?url='+r;
}
function set_currency(id)
{
    $.post(baseurl+'ajax.php',{
        action:'currency',
        item:id
    },redirect)
}
function create_order(id)
{

    if(isNaN(document.getElementById("q"+id).value) || document.getElementById("q"+id).value < 1)
    {
        document.getElementById("q"+id).value = "1";
    }
    $.post(baseurl+'ajax.php',{
        action:'get_params',
        tovar:id
    },send_order);

}
function check_required()
{
    var rarray = new Array ("lastname","firstname","phone1","email","city","street","house","icq");
	for(i = 0;i < rarray.length;i++)
	{
		if(TrimString(document.getElementById(rarray[i]).value) == "")
		{
			alert("Необходимо заполнить все обязательные поля !");
			return;
		}
	}
    document.forms['order'].action = 'basket/create';
    document.forms['order'].submit();
    return true;
}
function TrimString(sInString){
    sInString = sInString.replace(/ /g,' ');
    return sInString.replace(/(^\s+)|(\s+$)/g, "");
}
function set_input_text(obj,text,action)
{
    if(action == 1)
    {
        if(TrimString(obj.value) == "")
        {
            obj.value = text;
        }
    }
    else if(action == 0)
    {
        if(obj.value == text)
        {
            obj.value = '';
        }
    }
}
function set_page_size(catalog,pagesize,sort,source)
{
    $.post(baseurl+'ajax.php',{
        action:'pagesize',
        id:catalog,
        size:pagesize,
        s:source,
        sorting:sort
    },redirect);
    return false;
}
function uncheck_by_name(name)
{
    var obj = document.getElementsByName(name);
    for(var i = 0;i < obj.length;i++)
    {
        obj[i].checked = false;
    }

}
function set_stext(text)
{
    if(document.getElementById("stext").value == text)
    {
        $('#stext').attr('value', '');
    }
}
  function send_to_basket(id)
        {
            var q = document.getElementById("q"+id).value;
            if(q == 0 || q == "")
            {
                q = 1;
            }
            if(isNaN(q))
            {
                document.location.href = baseurl+'basket/add/'+id+'/1';

            }
            else
            {
                 document.location.href = baseurl+'basket/add/'+id+'/'+q;
            }
        }
		function after_load_catalog(r)
		{
			$("#c"+selected_catalog).slideDown();
		}
		var selected_catalog = "";
function load_subcatalog(id)
{
	selected_catalog = id;
	$("#c"+id).load(baseurl+'ajax.php',{parent:id,action:"catalog"},after_load_catalog);
}
function after_compare(r)
{
    
}
function compare(id,parentid,obj)
{
	if(obj.checked)
	{
		$("#compare_div").load(baseurl+"ajax.php",{action:'compare',tovarid:id,parent:parentid},after_compare);
	}
	else
	{
		$("#compare_div").load(baseurl+"ajax.php",{action:'compare',tovarid:id,parent:parentid,rm:1},after_compare);
	}
	
}
function set_mode(catalog,m)
{
	 $.post(baseurl+'ajax.php',{
        action:'mode',
        id:catalog,
		mode:m
    },redirect);
    return false;
}
function addcart(id)
{
	 document.location.href = baseurl+'basket/add/'+id+'/1';
}