// Java Script document
// удаление пробелов
var allSpacesRe = /\s+/g;
var leadingSpacesRe = /^\s+/;
var trailingSpacesRe = /\s+$/;

function removeSpaces(s) { return s.replace(allSpacesRe, ""); } // удаляет все пробелы
function trimLeading(s) { return s.replace(leadingSpacesRe, ""); }  // удаляет лидирующие пробелы
function trimTrailing(s) { return s.replace(trailingSpacesRe, ""); }  // удаляет концевые пробелы

function trim(s) { return trimLeading(trimTrailing(s)); }    //удаляет пролидирующие пробелы и в конце


// Windows
function RR_msg(W,H, header, msg ){
    RR_wndw(W,H)
    document.getElementById('RR_wndw_header').innerHTML=header
    document.getElementById('RR_wndw_body').innerHTML=msg
}


function chk_mail(mail)
{
   if (mail.indexOf(".") == -1) return (false);
	dog = mail.indexOf("@");
   	if (dog == -1) return (false);
    if ((dog < 1) || (dog > mail.length - 5)) return (false);
    if ((mail.charAt(dog - 1) == '.') || (mail.charAt(dog + 1) == '.') ) return (false);
    return (true);

}
function dig_length(pstr) // возвращает число цифр
{
    var reg=/\D/g
    if (pstr.length==0) return 0
    pstr.replace(reg,"")
	return pstr.length
}

//RR_wndw

function RR_wndw(W,H)
{
  var w_id='RR_wndw'
	// проверяем наличие тега окна
	try{
		document.getElementById(w_id).innerHTML=''
	} catch (e) {
		var RR_wndw_elmnt=document.createElement("DIV")
			RR_wndw_elmnt.id=w_id
			document.body.appendChild(RR_wndw_elmnt)

			document.getElementById(w_id).style.visibility='hidden';

	  		if	(navigator.userAgent.indexOf ('MSIE 6') != -1
	  		|| navigator.userAgent.indexOf ('MSIE 5') != -1
	  		)	document.getElementById(w_id).style.position='absolute'
	  		else document.getElementById(w_id).style.position='fixed'
		  	document.getElementById(w_id).style.background='#CCCCCC'
    		document.getElementById(w_id).style.padding='0px'
    		document.getElementById(w_id).style.zIndex='50'
		// включаем заголовок и кнопку выключения
	}
    	document.getElementById(w_id).innerHTML='<div id="RR_wndw_close"><img src="http://h3.com.ua/BEX_RR/close.png"  onclick="close_RR_wndw()"></div><div id="RR_wndw_header"></div><div id="RR_wndw_body"></div>'
	    document.getElementById('RR_wndw_close').style.textAlign='right'
		document.getElementById('RR_wndw_header').style.textAlign='center'
        document.getElementById('RR_wndw_header').style.background='#FFFF00'
        document.getElementById('RR_wndw_body').style.padding='3px'


		document.getElementById(w_id).style.top=parseInt((document.getViewportHeight()-H)/2) + 'px';
 		document.getElementById(w_id).style.left=parseInt((document.getViewportWidth()-W)/2) + 'px';
	document.getElementById(w_id).style.width=W + 'px';
  	document.getElementById(w_id).style.height=H + 'px';
    document.getElementById(w_id).style.visibility='visible';
}
//close_RR_wndw
function close_RR_wndw()
{

 document.getElementById('RR_wndw').style.visibility='hidden'
}


// самозакрывающееся окно для сообщений

function  RR_self_close_msg(W,H,color,msg)
{
	var SCM=new String()
	SCM='SСM'
	try{
		document.getElementById('SCM').style.visibility='hidden'
	} catch(e){
	     var SCM_element=document.createElement("DIV")
			SCM_element.id='SCM'
			document.body.appendChild(SCM_element)

			SCM_style=document.getElementById('SCM').style
			SCM_style.visibility='hidden'

	        if	( navigator.userAgent.indexOf ('MSIE 6') != -1
	  		|| navigator.userAgent.indexOf ('MSIE 5') != -1
	  		)	SCM_style.position='absolute'
	  		else SCM_style.position='fixed'
	 }
     SCM_teg=document.getElementById('SCM')
     SCM_teg.innerHTML='<p>'+msg+'</p>'

	 SCM_style=document.getElementById('SCM').style
	 SCM_style.padding='3px'
	 SCM_style.background=color
	 SCM_style.border='#000000 thin solid'
	 SCM_style.textAlign='center'

		SCM_style.top=parseInt((document.getViewportHeight()-H)/2) + 'px';
 		SCM_style.left=parseInt((document.getViewportWidth()-W)/2) + 'px';
		SCM_style.width=W + 'px';
	  	SCM_style.height=H + 'px';
	    SCM_style.visibility='visible';

        setTimeout('SCM_style.visibility="hidden"',4000)
}


// технические функции

document.getViewportWidth = function()
   {
    return (document.compatMode || navigator.isIE) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth : (document.parentWindow || document.defaultView).innerWidth;
  };

document.getViewportHeight = function()
   {
    return ((document.compatMode || navigator.isIE) && !navigator.isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
  };


