function pnt(x, y){
	this.x=x;
	this.y=y;
	return this;
}

/* reg form animation */

function RegFormClass(sID){
	this.Init(sID);
}

RegFormClass.prototype.Init=function(sID){
	this.oPtr=document.getElementById(sID);
	this.oFrame=document.getElementById(sID+'Frame');
	this.oContent=document.getElementById(sID+'Content');
	this.x=this.oFrame.offsetLeft;
	this.y=this.oFrame.offsetTop;
	this.bVisible=false;
}

RegFormClass.prototype.onAnimationOver=function(){
	delete this.onAnimate;
}

RegFormClass.prototype.InitResize=function(oSPnt, oTPnt, iDecay, oSnapPoint){
	this.sW=oSPnt.x;
	this.sH=oSPnt.y;
	this.tW=oTPnt.x;
	this.tH=oTPnt.y;
	this.d=iDecay;

	this.x=this.oFrame.offsetLeft;
	this.y=this.oFrame.offsetTop;

	this.iBodyWidth=document.body.clientWidth;
	this.bWide=(oSPnt.x < oTPnt.x);

	this.oSnapInit=new pnt(this.sW, this.sH);
	this.oSnapPoint=new pnt(this.sW/2, this.sH/2);

	this.onAnimate=this.Resize;
}

RegFormClass.prototype.Resize=function(){
	this.sW+=(this.tW-this.sW)*this.d;
	this.sH+=(this.tH-this.sH)*this.d;

	if(Math.abs(this.tW-this.sW) < 2 && Math.abs(this.tH-this.sH) < 2){
		this.sW=this.tW;
		this.sH=this.tH;
		this.onAnimationOver();
	}

	//считаем соотношение текущей и целевой ширины, чтобы выставить правильный размер шрифта
	//~ this.oPtr.style.fontSize=(this.bWide) ? Math.round(this.sW/this.tW * 100)+'%' : Math.round(this.sW/this.oSnapInit.x * 100)+'%';
	this.oPtr.style.width=this.sW+'px';
	this.oPtr.style.height=this.sH+'px';
	this.Snap();
}

RegFormClass.prototype.Snap=function(){
	var dx=this.oSnapPoint.x*(1 - this.sW/this.oSnapInit.x);
	var dy=this.oSnapPoint.y*(1 - this.sH/this.oSnapInit.y);
	this.MoveTo(this.x + dx, this.y + dy);
}

RegFormClass.prototype.MoveTo=function(x, y){
	this.oFrame.style.left=x+'px';
	this.oFrame.style.top=y+'px';
}

RegFormClass.prototype.Show=function(){
	this.bVisible=true;
	this.oFrame.style.visibility="visible";
	this.oContent.style.display="none";
	this.InitResize(new pnt(20, 20), new pnt(600, 370),.3);
	this.onAnimationOver=function(){
		delete this.onAnimate;
		this.oContent.style.display="block";
	}
	return false;
}

RegFormClass.prototype.Hide=function(){
	this.bVisible=false;
	this.InitResize(new pnt(600, 370), new pnt(20, 20),.5);
	this.oContent.style.display="none";
	this.onAnimationOver=function(){
		this.oFrame.style.visibility="hidden";
		delete this.onAnimate;
	}
	return false;

}

RegFormClass.prototype.Switch=function(){
	if(this.bVisible)
		return this.Hide();
	else
		return this.Show();

}

function RegFormAnimate(){
	if(oRegForm.onAnimate)
		oRegForm.onAnimate();
}








/* ############################################################ */






function OrderFormClass(sID){
	this.Init(sID);
}

OrderFormClass.prototype.Init=function(sID){
	this.oPtr=document.getElementById(sID);
	this.oFrame=document.getElementById(sID+'Frame');
	this.oContent=document.getElementById(sID+'Content');
	this.x=this.oFrame.offsetLeft;
	this.y=this.oFrame.offsetTop;
	this.bVisible=false;
}

OrderFormClass.prototype.onAnimationOver=function(){
	delete this.onAnimate;
}

OrderFormClass.prototype.InitResize=function(oSPnt, oTPnt, iDecay, oSnapPoint){
	this.sW=oSPnt.x;
	this.sH=oSPnt.y;
	this.tW=oTPnt.x;
	this.tH=oTPnt.y;
	this.d=iDecay;

	this.x=this.oFrame.offsetLeft;
	this.y=this.oFrame.offsetTop;

	this.iBodyWidth=document.body.clientWidth;
	this.bWide=(oSPnt.x < oTPnt.x);

	this.oSnapInit=new pnt(this.sW, this.sH);
	this.oSnapPoint=new pnt(this.sW/2, this.sH/2);

	this.onAnimate=this.Resize;
}

OrderFormClass.prototype.Resize=function(){
	this.sW+=(this.tW-this.sW)*this.d;
	this.sH+=(this.tH-this.sH)*this.d;

	if(Math.abs(this.tW-this.sW) < 2 && Math.abs(this.tH-this.sH) < 2){
		this.sW=this.tW;
		this.sH=this.tH;
		this.onAnimationOver();
	}

	//считаем соотношение текущей и целевой ширины, чтобы выставить правильный размер шрифта
	//~ this.oPtr.style.fontSize=(this.bWide) ? Math.round(this.sW/this.tW * 100)+'%' : Math.round(this.sW/this.oSnapInit.x * 100)+'%';
	this.oPtr.style.width=this.sW+'px';
	this.oPtr.style.height=this.sH+'px';
	this.Snap();
}

OrderFormClass.prototype.Snap=function(){
	var dx=this.oSnapPoint.x*(1 - this.sW/this.oSnapInit.x);
	var dy=this.oSnapPoint.y*(1 - this.sH/this.oSnapInit.y);
	this.MoveTo(this.x + dx, this.y + dy);
}

OrderFormClass.prototype.MoveTo=function(x, y){
	this.oFrame.style.left=x+'px';
	this.oFrame.style.top=y+'px';
}

OrderFormClass.prototype.Show=function(){
	this.bVisible=true;
	this.oFrame.style.visibility="visible";
	this.oContent.style.display="none";
	this.InitResize(new pnt(50, 50), new pnt(400, 250),.4);
	this.onAnimationOver=function(){
		delete this.onAnimate;
		this.oContent.style.display="block";
	}
	return false;
}

OrderFormClass.prototype.Hide=function(){
	this.bVisible=false;
	this.InitResize(new pnt(400, 250), new pnt(50, 50),.4);
	this.oContent.style.display="none";
	this.onAnimationOver=function(){
		this.oFrame.style.visibility="hidden";
		delete this.onAnimate;
	}
	return false;

}

OrderFormClass.prototype.Switch=function(){
	if(this.bVisible)
		return this.Hide();
	else
		return this.Show();

}

function RegFormAnimate(){
	if(oRegForm.onAnimate)
		oRegForm.onAnimate();
}





/* ############################################################ */

function dalert(str){
	document.getElementById('debug').innerHTML+=str+'<br />';
}