function loadData(obj,type,sub)
{
    var parentForm = obj.parentNode;
    var request = '/'+type+'/'+obj.value+'/xhtml/';

// 	if(sub) request = request+'&sort='+sub;

    oS = document.createElement("script");
    oS.setAttribute("src",request);
    oS.setAttribute("name",'loadScript');
    oS.setAttribute("id",'loadScript');
    document.body.appendChild(oS);

    return;
}

function loadDataId(id,type,page,obj)
{
    if(obj) { parentForm = obj.parentNode; };
    var request = '/'+page+'/'+type+'/'+id+'/xhtml/';

    oS = document.createElement("script");
    oS.setAttribute("src",request);
    oS.setAttribute("name",'loadScript');
    oS.setAttribute("id",'loadScript');
    document.body.appendChild(oS);

    return;
}


function loadDataInd(id,type)
{
    var request = '/'+type+'/'+id+'/xhtml/';
    oS = document.createElement("script");
    oS.setAttribute("src",request);
    oS.setAttribute("name",'loadScript');
    oS.setAttribute("id",'loadScript');
    document.body.appendChild(oS);

    return;
}

function loadDataKInd(id,type,stype)
{
    var request = '/'+stype+'/'+type+'/'+id+'/xhtml/';
    oS = document.createElement("script");
    oS.setAttribute("src",request);
    oS.setAttribute("name",'loadScript');
    oS.setAttribute("id",'loadScript');
    document.body.appendChild(oS);

    return;
}

function loadDataKIndVal(id,type,stype,sval)
{
    var request = '/'+sval+'/'+stype+'/'+type+'/'+id+'/xhtml/';
    oS = document.createElement("script");
    oS.setAttribute("src",request);
    oS.setAttribute("name",'loadScript');
    oS.setAttribute("id",'loadScript');
    document.body.appendChild(oS);

    return;
}

function updateSelect(name)
{
    var selectObj = document.getElementById(name);

    if (selectObj)
    {
        selectObj.options.length = 0;

        for (i=0; i < Data[name].length; i++)
        {
            opt = new Option('', Data[name][i][0], false, false);
            selectObj.options[i] = opt;
            selectObj.options[i].innerHTML = Data[name][i][1];
        };

        selectObj.blur();

        if(Data[name].length>1) { selectObj.disabled = false; }
        else { selectObj.disabled = true; };
    }
    return;
}

function CheckSelect(name1, name2)
{
    var selectObj1 = document.getElementById(name1);
    var selectObj2 = document.getElementById(name2);

	if(selectObj1 && selectObj2)
	{
	    if (selectObj1.options.length <= 1)
	    {
	    	selectObj2.options.length = 1;
			selectObj2.disabled = true;
		};
    };
    return;
}

function show_sub(sub, show)
{
	if(show)
	{
		document.getElementById(sub).style.display = 'inline';
		document.getElementById(sub).style.visibility = 'visible';
	}
	else
	{
		document.getElementById(sub).style.display = 'none';
		document.getElementById(sub).style.visibility = 'hidden';
	};
}


function write_data(Data,id, xy)
{
	document.body.removeChild(oS);
    oS = document.createElement("div");
    oS.setAttribute("id",id);

    oS.innerHTML = Data;

	if(xy)
	{
		 var 	X = getClientWidth()/2 + getBodyScrollLeft() - 300;
		 if(X<0) { X = 0; };
		 var  Y = getBodyScrollTop();
		 if(Y<150) { Y = 150; };

		oS.style.position = 'absolute';
		oS.style.zIndex = 10000;
		oS.style.top = Y;
		oS.style.left = X;
	};

    document.body.appendChild(oS);

}

function write_data_top(Data,id)
{
    oS = document.createElement("div");
    oS.setAttribute("id",'fon_div');

	oS.style.position = 'absolute';
	oS.style.top = 0;
	oS.style.left = 0;
	oS.style.zIndex = 10000;

    var	X = getDocumentWidth();
    var Y = getDocumentHeight();

	oS.style.width = X;
	oS.style.height = Y;

    oS.style.background = '#FFE9CC';
    oS.style.opacity    = 0.4;
    oS.style.filter     = "progid:DXImageTransform.Microsoft.Alpha(opacity=40)";

    document.body.appendChild(oS);

    oS = document.createElement("div");
    oS.setAttribute("id",id);

	oS.style.position = 'absolute';
	oS.style.top = 0;
	oS.style.left = 0;
	oS.style.zIndex = 10000;

    var	X = getDocumentWidth();
    var Y = getDocumentHeight();

	oS.style.width = X;
	oS.style.height = Y;

    oS.innerHTML = Data;

    document.body.appendChild(oS);
}

function write_data_in(Data,id)
{
    oS = api.getElementById(id);
    oS.innerHTML = Data;
}

function destroy(id)
{
	document.body.removeChild(document.getElementById(id));
	return false;
}

function destroy_top(id)
{
	document.body.removeChild(document.getElementById('fon_div'));
	document.body.removeChild(document.getElementById(id));
	return false;
}

function update_span(id, val)
{
	if(document.getElementById(id)!='undefined')
	{
		document.getElementById(id).innerHTML = val;
	};
}

function destroy_table(id)
{
	document.getElementById(id).outerHTML = '';
}

function view_otziv(id)
{
   loadDataInd(id,'view_otziv');
}

function add_to_basket(id)
{
	loadDataInd(id,'to_basket');}

function add_to_basket_k(id)
{
	stype = 0;

	if(api.getElementById('k_val60_'+id).checked) stype=1;
	else if(api.getElementById('k_val120_'+id).checked) stype=2;

	if(stype>0)	loadDataKInd(id,'to_basket_k',stype);
}


function check_val(id,stype,sval)
{	if(sval==1)	loadDataKInd(id,'from_basket_k',stype);	if(sval==2)	loadDataKInd(id,'to_basket_k',stype);
}

function update_tovar_val(id,stype)
{
	var sval = api.getElementById('val'+stype+'_'+id).value;
	loadDataKIndVal(id,'up_basket_k',stype,sval);
}



function reSumm(id,type)
{
   if(type==0)
   {   	new_num = api.getElementById('val_'+id).value;

   	if(!isValidNum(new_num)) {
		new_num = 0;
		api.getElementById('val_'+id).value = 0;
	};
   }
   else
   {   	new_num = api.getElementById('val_'+id+'_'+type).value;

   	if(!isValidNum(new_num)) {
		new_num = 0;
		api.getElementById('val_'+id+'_'+type).value = 0;
	};
   }

   val = 'new_num='+new_num;

   Ajax_src('/'+type+'/basket_resumm/'+id+'/xhtml/',val,true);

	return;}

function isValidNum(num)
{
 return (/^[0-9]*$/i).test(num);
}



