var cifir= new Array("од","дв","три","четыр","пят","шест","сем","восем","девят");
var sotN=new Array("сто","двести","триста","четыреста","пятьсот","шестьсот","семьмот","восемьсот","девятьсот");
var milion=new Array("триллион","миллиард","миллион","тысяч");
var anDan =new Array("","","","сорок","","","","","девяносто");

function SP(XS){
(XS>0? this.XS=sumPROP(Math.floor(XS),Math.round((XS-Math.floor(XS))*100)) : this.XS="Пусто!" );
return this;
}

function sumPROP(xx,xx1)
{
var scet=4;
var cifR='';
var cfR='';
var oboR=new Array(0);
//==========================
	if (xx>999999999999999) { cfR="Густо!"; return cfR; }
	while(xx/1000>0){
		yy=Math.floor(xx/1000);
		delen=Math.round((xx/1000-yy)*1000);
		//-------------------------------
		sot=Math.floor(delen/100)*100;
		des=(Math.floor(delen-sot)>9?Math.floor((delen-sot)/10)*10:0);
		ed=Math.floor(delen-sot)-Math.floor((delen-sot)/10)*10;
		//-------------------------------
		forDes=(des/10==2?'а':'')
		forEd=(ed==1?'ин': (ed==2?'е':'') );
		ffD=(ed>4?'ь': (ed==1 || scet<3? (scet<3 && ed<2?'ин': (scet==3?'на': (scet<4? (ed==2?'а':( ed==4?'е':'')) :'на') ) ) : (ed==2 || ed==4?'е':'') ) );
		forTys=(des/10==1? (scet<3?'ов':'') : (scet<3? (ed==1?'': (ed>1 && ed<5?'а':'ов') ) : (ed==1?'а': (ed>1 && ed<5?'и':'') )) );
		//===============================
			oprSot=(sotN[sot/100-1]!=null?sotN[sot/100-1]:'');
			oprDes=' '+(cifir[des/10-1]!=null? (des/10==1?'': (des/10==4 || des/10==9?anDan[des/10-1]:(des/10==2 || des/10==3?cifir[des/10-1]+forDes+'дцать':cifir[des/10-1]+'ьдесят') ) ) :'');
			oprEd=' '+(cifir[ed-1]!=null? cifir[ed-1]+(des/10==1?forEd+'надцать' : ffD ) : (des==10?'десять':'') );
			oprTys=' '+(milion[scet]!=null && delen>0 ?milion[scet]+forTys:'');
		//-------------------------------
		cifR=(oprSot.length>1?oprSot:'')+
			 (oprDes.length>1?oprDes:'')+
             (oprEd.length>1?oprEd:'')+
			 (oprTys.length>1?oprTys:'');
		oboR[oboR.length]=cifR;
		xx=Math.floor(xx/1000);
		scet-=1;
		if ( Math.floor(xx)<1 ) {	break;	}
	}
		oboR.reverse();
		for (i=0; i<oboR.length; i++){
			cfR+=oboR[i]+' ';
		}
		(cfR.length<3?cfR='ноль ':cfR);
		cfR+='руб. '+xx1+' коп.';
		return cfR;
}


function explode(separator, string)
{
        var j, tmp;

        if (separator==null)
                return;

        var result = new Array();

        if (string=='' | string==null)
                return result;

        if (strpos(string, separator)<0) {
                result[0]=string;
                return result;
        }

        //-- errors handled
        tmp = string;
        j=0;

        while (strpos(tmp, separator)>-1) {
                result[j] = tmp.substring(0, strpos(tmp, separator));
                tmp = strDelete(tmp, 0, strpos(tmp, separator) + separator.length);
                j++;
        }

        if (tmp!='')
                result[j] = tmp;

        return result;
}
function strDelete(str,nach,pos)
{

    return (str.substring(0,nach)+str.substring(pos));

}
function strpos(haystack, needle)
{
        var i;
        for (i=0;i<=(haystack.length - needle.length);i++)
        {
                if (haystack.substr(i, needle.length) == needle)
                        return i;

        }
        return -1;
}
function strpos2(haystack, needle,st)
{
        var i;
        for (i=st;i<=(haystack.length - needle.length);i++)
        {
                if (haystack.substr(i, needle.length) == needle)
                        return i;

        }
        return -1;
}

function dropit(e,oIEorNN6s,sOneNN,xMenu){
	if(ie4){
		oneIE = oIEorNN6s;
		if (window.themenu&&themenu.id!=oneIE.id)
			themenu.style.visibility="hidden";
		themenu=oneIE;
		themenu.style.left=document.body.scrollLeft+event.clientX-event.offsetX;
		themenu.style.top=document.body.scrollTop+event.clientY-event.offsetY+15;
		lX=themenu.style.posLeft-document.body.scrollLeft;
		rX=lX+themenu.offsetWidth;
		tY=themenu.style.posTop-document.body.scrollTop-25;
		bY=themenu.offsetHeight+tY+25;
		//updateIt(oneIE);
		if (themenu.style.visibility=="hidden"){
			themenu.style.visibility="visible";
			themenu.style.zIndex=zi++;
		}
	}
	if(nn4){
		if (window.themenu&&themenu.id!=eval(sOneNN).id)
			themenu.visibility="hide";
		themenu=eval(sOneNN);
		if (themenu.visibility=="hide")
			themenu.visibility="show";
		themenu.zIndex++;
		themenu.left=e.pageX-e.layerX;
		themenu.top=e.pageY-e.layerY+14;
		lX=themenu.left;
		rX=lX+themenu.clip.width;
		tY=themenu.top-25;
		bY=themenu.top+themenu.clip.height;
		return false;
	}
	if(nn6){
		oneNN = document.getElementById(oIEorNN6s); //eval(sOneNN);
		if (window.themenu&&themenu.id!=oneNN.id)
			themenu.style.visibility="hidden";
		themenu=oneNN;
		themenu.style.left=xMenu;
		themenu.style.top=146;
		lX=parseInt(themenu.style.left);
		rX=lX+themenu.offsetWidth;
		tY=parseInt(themenu.style.top);
		bY=themenu.offsetHeight+tY+25;
		//updateIt(oneNN);
		if (themenu.style.visibility=="hidden"){
			themenu.style.visibility="visible";
			themenu.style.zIndex=zi++;

		}
	}
}

function hidemenu (whichone){
	if(ie4) hidemenu1 (whichone);
	if(nn4) hidemenu2();
	if(nn6) hidemenu3();
}

function hidemenu1(whichone){
	if(window.themenu)
		themenu.style.visibility="hidden";
	hidemenu2();
}

function hidemenu2(){
	if(typeof(themenu)!="undefined")
		themenu.visibility="hide";
}

function hidemenu3(){
	if (themenu.style.visibility=="visible")
		themenu.style.visibility="hidden";
}

function updateIt(oneIE){
	var x,y
	if(ie4){
		x=window.event.clientX;
		y=window.event.clientY;
		if(x>rX || x<lX) hidemenu(oneIE);
		else if(y>bY+1 || y<tY) hidemenu1(oneIE);
	}
	if(nn6){
		x=oneIE.clientX;
		y=oneIE.clientY;
		if(x>rX || x<lX) hidemenu3();
		else if(y>bY+1 || y<tY-30) hidemenu3();
	}
	if(nn4){
		x=oneIE.pageX;
		y=oneIE.pageY;
		if(x>rX || x<=lX-1) hidemenu2();
		else if(y>bY || y<tY) hidemenu2();
	}
}
function timestamp2date(timestamp)
{
  var theDate = new Date(timestamp * 1000);
  return theDate.toGMTString();
}

function date2timestamp(year, month, day, hour, min, sec) {
  return (Date.UTC(year, month-1, day, hour, min, sec) / 1000);
}

    function get_sutki(dat_from,dat_till)
	{
	        df=new Array(); df=explode('-',dat_from); stdf=date2timestamp(df[2], df[1], df[0], 23, 59, 59);
	        dt=new Array(); dt=explode('-',dat_till); stdt=date2timestamp(dt[2], dt[1], dt[0], 23, 59, 59);
			days=(stdt-stdf)/86400;
			if (days<0) days=0;
			return days;
    }


	function add_cost(dat_from,dat_till,nomer,kateg,razm,is_aditional)
	{
			days=get_sutki(dat_from,dat_till);
			if (days<0) days=0;
			cost_array=','+nomera[nomer][1];
//			aditional_cost =  nomera[nomer][9];
			pos1=strpos(cost_array,','+razm+'=>');
			cost_val=0;
			if (pos1!=-1)
			{
				posn=strpos2(cost_array,"'",(pos1));
				posk=strpos2(cost_array,"'",(posn+1));
				cost_val=cost_array.substring(posn+1, posk);
			}
//			alert(aditional_cost);
//			//if (pers!='без детей') cost_val-=200;
//			if (is_aditional==true) alert(is_aditional);
			if (is_aditional==true || is_aditional=='true')   aditional_cost=nomera[nomer][9]; else  aditional_cost =0;
			return days*cost_val*1+aditional_cost*1*days;
	}
