

function checkProperty(formobj, propname)
{
	alertMsg = "";
	var obj = formobj.elements["property"];

	if (obj){
		switch(obj.type){
			default:
			if (obj.value == "" || obj.value == null){
				alertMsg = "Пожалуйста выберите : " + propname;
			}
		}
	}

	if (alertMsg.length == 0){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}


/*
Значения по умолчанию
*/

DHTML_Cart.id			= 'DHTML_Cart';
DHTML_Cart.left			= 0;
DHTML_Cart.top			= 0;
DHTML_Cart.width		= 158;
DHTML_Cart.height		= 100;
DHTML_Cart.headerHeight	= 22;
DHTML_Cart.headerHTML	= "";
DHTML_Cart.scroll		= true;
DHTML_Cart.scrolling	= 'no';
DHTML_Cart.src			= '/common/default/download/empty_cart.htm';
DHTML_Cart.visible		= false;

function DHTML_Cart(init)
{
	var sHTML = '';
	
	if (init)
	{
		this.id				= (init.id)				? init.id			: DHTML_Cart.id;
		this.left			= (init.left)			? init.left			: DHTML_Cart.left;
		this.top			= (init.top)			? init.top			: DHTML_Cart.top;
		this.width			= (init.width)			? init.width		: DHTML_Cart.width;
		this.height			= (init.height)			? init.height		: DHTML_Cart.height;
		this.headerHeight	= (init.headerHeight)	? init.headerHeight	: DHTML_Cart.headerHeight;
		this.scroll			= (init.scroll)			? init.scroll		: DHTML_Cart.scroll;
		this.scrolling		= (init.scrolling)		? init.scrolling	: DHTML_Cart.scrolling;
		this.src			= (init.src)			? init.src			: DHTML_Cart.src;
		this.visible		= (init.visible)		? init.visible		: DHTML_Cart.visible;
		this.headerHTML		= (init.headerHTML)		? init.headerHTML	: DHTML_Cart.headerHTML;
		this.cartstyle		= (init.cartstyle)		? init.cartstyle	: DHTML_Cart.cartstyle;
	}
	else
	{
		this.id				= DHTML_Cart.id;
		this.left 			= DHTML_Cart.left;
		this.top 			= DHTML_Cart.top;
		this.width 			= DHTML_Cart.width;
		this.height 		= DHTML_Cart.height;
		this.headerHeight 	= DHTML_Cart.headerHeight;
		this.scroll 		= DHTML_Cart.scroll;
		this.scrolling 		= DHTML_Cart.scrolling;
		this.src 			= DHTML_Cart.src;
		this.visible		= DHTML_Cart.visible;
		this.headerHTML		= DHTML_Cart.headerHTML;
		this.cartstyle		= DHTML_Cart.cartstyle;
	}
	
	sHTML  = '<div id="' + this.id + '_header" class="DHTML_CartHeader" style="position:absolute;overflow:clip;z-index:10;';
	sHTML += 'left:' + this.left + ';top:' + this.top + ';';
	sHTML += 'height:' + this.headerHeight + ';width:' + this.width + ';';
	
	if (this.visible) sHTML += 'visibility:visible;">'; else sHTML += 'visibility:hidden;">';
	
	sHTML += this.headerHTML;
	sHTML += '</div>';
	
	sHTML += '<iframe id="' + this.id + '" src="' + this.src + '" frameborder=0';
	sHTML += 'width="' + this.width + '" height="' + this.height + '" scrolling="' + this.scrolling + '" ';
	sHTML += 'style="position:absolute; ' + this.cartstyle + ' left:' + this.left + '; top:' + (this.top + this.headerHeight) + '; width:' + this.width + '; height:' + (this.height - this.headerHeight) + ';';
	
	if (this.visible) sHTML += 'visibility:visible;">'; else sHTML += 'visibility:hidden;">';
	sHTML += '</iframe>';

	document.write(sHTML);
	
	this.setSrc			= DHTML_Cart_SetSrc;
	this.setVisibility	= DHTML_Cart_SetVisibility;
	
	this.rootDocObj		= document.all[this.id];
	this.rootDocHeader	= document.all[this.id + '_header'];
	this.rootDocFrame	= document.frames[this.id];
	
	this.rootDocObj.DHTML_Cart = this;
	this.rootDocHeader.DHTML_Cart = this;
	
	this.rootDocHeader.onmousedown = DHTML_CartDrag;

	if (this.scroll)
	{
    	if (typeof document.objArray == 'undefined' || document.objArray == null)
        {
        	document.objArray = new Array();
            document.numObj   = 0;
		}
        document.numObj += 1;
        document.objArray[document.numObj] = this.id;

	    window.onscroll = DHTML_Cart.CheckOnScroll;
	}
	
	return this;
}

document.write('<style type="text/css">');
document.write('.DHTML_CartHeader {cursor:hand;}');
document.write('</style>');

function DHTML_Cart_SetSrc(src)
{
	if (this.src != src)
	{
		this.src = src;
		this.rootDocObj.src = src;
	}

	return true;
}

function DHTML_Cart_SetVisibility(visible)
{
	if (visible)
	{
		this.visible = true;
		this.rootDocObj.style.visibility	= 'visible';
		this.rootDocHeader.style.visibility = 'visible';
	}
	else
	{
		this.visible = false;
		this.rootDocObj.style.visibility	= 'hidden';
		this.rootDocHeader.style.visibility = 'hidden';
	}
}

DHTML_Cart.CheckOnScroll=function()
{
    for (var i = 1; i <= document.numObj; i++)
    {
		obj = document.all[document.objArray[i]].DHTML_Cart;

		if (!obj) break;

		diffY = document.body.scrollTop;
		diffX = document.body.scrollLeft;

		curX  = obj.rootDocHeader.style.pixelLeft;
		curY  = obj.rootDocHeader.style.pixelTop;

		targetX = obj.left + diffX;
		targetY = obj.top  + diffY;

		if (curX != targetX)
    	{
    		curHorShift = (targetX - curX);
	        curHorShift = (curHorShift > 0) ? Math.ceil(curHorShift):Math.floor(curHorShift);

			obj.rootDocHeader.style.pixelLeft += curHorShift;
    	    obj.rootDocObj.style.pixelLeft  += curHorShift;
		}

		if (curY != targetY)
    	{
	    	curVertShift = (targetY - curY);
    	    curVertShift = (curVertShift > 0) ? Math.ceil(curVertShift):Math.floor(curVertShift);

			obj.rootDocHeader.style.pixelTop += curVertShift;
    	    obj.rootDocObj.style.pixelTop  += curVertShift;
		}
    }
}

function DHTML_CartOnMouseOver()
{
    var obj                 = this.DHTML_Cart;
    window.draggedDHTML_Cart = obj;    
    obj.oldonmousedown      = document.onmousedown;
    window.onmousedown      = DHTML_CartDrag;

    window.captureEvents(Event.MOUSEDOWN);
    return false;
}

function DHTML_CartOnMouseOut()
{
    var obj                 = this.DHTML_Cart;
    window.draggedDHTML_Cart = null;   
    window.onmousedown      = obj.oldonmousedown;

    window.releaseEvents(Event.MOUSEDOWN);

    return false;
}

function DHTML_CartMove(e)
{
    var obj = document.draggedDHTML_Cart;
    var curX;
    var curY;

	if(event.button == 0)
    {
    	DHTML_CartDrop();                        
        return true;
	}

    curX     = event.clientX - obj.dragXOffset;
    curY     = event.clientY - obj.dragYOffset
    obj.left = curX;
    obj.top  = curY;

	obj.rootDocObj.style.visibility = "hidden";

	obj.rootDocHeader.style.pixelLeft = curX + document.body.scrollLeft;
    obj.rootDocHeader.style.pixelTop  = curY + document.body.scrollTop;
    obj.rootDocObj.style.pixelLeft  = curX + document.body.scrollLeft;
    obj.rootDocObj.style.pixelTop   = curY + obj.headerHeight + document.body.scrollTop;

	event.returnValue = false;      
    return false;
}

function DHTML_CartDrop()
{       
    var obj = document.draggedDHTML_Cart;

	obj.rootDocObj.style.visibility = "visible";

	document.onmousemove = obj.oldonmousemove;
    document.onmouseup   = obj.oldonmouseup;            

    document.draggedDHTML_Cart = null;
    return true;               
}

function DHTML_CartDrag(e)
{
    var obj;

	obj = this.DHTML_Cart;

	obj.dragXOffset = event.clientX - obj.left;
    obj.dragYOffset = event.clientY - obj.top;  

	obj.oldonmousemove = document.onmousemove;
    obj.oldonmouseup   = document.onmouseup;

	document.onmousemove = DHTML_CartMove;
    document.onmouseup   = DHTML_CartDrop;

    document.draggedDHTML_Cart = obj;  
    return true;
}
