// Строка статуса 
window.defaultStatus = " " ;
//parent.defaultStatus = "ОАО «СТРОИТЕЛЬНАЯ КОРПОРЦИЯ «ВОЗРОЖДЕНИЕ САНКТ-ПЕТЕРБУРГА»" ;
//parent.document.title = "ОАО «СТРОИТЕЛЬНАЯ КОРПОРЦИЯ «ВОЗРОЖДЕНИЕ САНКТ-ПЕТЕРБУРГА»" ;

var bName = navigator.appName.indexOf("Internet Explorer") ;
/*
function click() {
	if (event.button==2) {
		var rus_str = ' Copyright © 2001 «Web-Media Studio»' ; //' Copyright © 2001 «Гефест»\n\n Все права защищены.\n' ;
		alert( rus_str );
		return false;
	}
}
document.onmousedown=click
*/
// загружаем стили  в зависимости от Броузера 
/*
if( navigator.appName.indexOf("Internet Explorer")==-1 ){		// те БРОУЗЕР не MS IExplorer
	if( navigator.appName.indexOf("Netscape")>=0 ){		// те БРОУЗЕР Netscape Navigator
		document.writeln( "<link rel='stylesheet' href='/common/nn.css'>" );
	}
}else{
	document.writeln( "<link rel='stylesheet' href='/common/ie.css'>" );
}
*/


//////////////////////////////////////////////////////////////////////////////////////;
//
//
//
//
//////////////////////////////////////////////////////////////////////////////////////;

// Default frame. We default to current frame if there is no frame defined.
if (typeof ol_frame == 'undefined') { var ol_frame = self; }

// Decide browser version
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;

var opera = navigator.userAgent.indexOf("Opera");
//alert(opera);
if (opera>=0){
	var s = 
'          В Н И М А Н И Е \n\n'+
'  В Выбранном Вами броузере сайт работает \n'+
'  с ограничениями. \n'+
'  Советуем воспользоваться более интелектуальным.';
	alert(s);
}

// Microsoft Stupidity Check(tm).
if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		ie5 = true;
	}
	if (ns6) {
		ns6 = false;
	}
}

////////////////////////////////////////////////////////////////;
//
//	
//
////////////////////////////////////////////////////////////////;
function todoPress( objName, objCur, objFrm )
{
	//
	var obj ;
	//
	if (parseInt(objCur)==0 || parseInt(objName)==parseInt(objCur)){
		// Already checked
		setOn( objName );
		//
		objFrm.curB.value = objName ;
		//alert(1);

	}else{
		// Not Checked 
		setOff( objCur );
		//obj.style.borderStyle = 'solid' ;
		//
		//alert(objCur);
		// Check Pressed BTN
		setOn( objName );
		//
		objFrm.curB.value = objName ;
		//
	}

}
function setOn( objName )
{
	//
	obj = MM_findObj( 'btn'+objName );
	obj.style.backgroundColor = '#E6E6E6' ;
	obj.style.color = '#000099' ;
	obj.style.borderTopWidth = '1' ;
	obj.style.borderRightWidth = '0' ;
	obj.style.borderBottomWidth = '0' ;
	obj.style.borderLeftWidth = '1' ;
	obj.style.borderStyle = 'solid' ;
	//
}
function setOff( objCur )
{
	//
	obj = MM_findObj( 'btn'+objCur );
	obj.style.backgroundColor = '#ED1C24' ;
	obj.style.color = '#FFFFFF' ;
	obj.style.borderTopWidth = '0' ;
	obj.style.borderRightWidth = '0' ;
	obj.style.borderBottomWidth = '0' ;
	obj.style.borderLeftWidth = '0' ;
	//
}

////////////////////////////////////////////////////////////////;
//
//	
//
////////////////////////////////////////////////////////////////;
function todoPress2( objName, objCur, objFrm )
{
	//
	var obj ;
	//
	if (parseInt(objCur)==0 || parseInt(objName)==parseInt(objCur)){
		// Already checked
		setOn2( objName );
		//
		objFrm.curB.value = objName ;
		//alert(1);

	}else{
		// Not Checked 
		setOff2( objCur );
		//obj.style.borderStyle = 'solid' ;
		//
		//alert(objCur);
		// Check Pressed BTN
		setOn2( objName );
		//
		objFrm.curB.value = objName ;
		//
	}

}


function setOn2( objName )
{
	//
	obj = MM_findObj( 'btn'+objName );
	obj.style.backgroundColor = '#ED1C24' ;
	obj.style.color = '#FFFFFF' ;

	obj.style.borderColor = '#999999' ;
	/*
	obj.style.borderTopWidth = '1' ;
	obj.style.borderRightWidth = '0' ;
	obj.style.borderBottomWidth = '0' ;
	obj.style.borderLeftWidth = '1' ;
	
	obj.style.borderStyle = 'solid' ;
	*/
	//
}
function setOff2( objCur )
{
	//
	obj = MM_findObj( 'btn'+objCur );
	obj.style.backgroundColor = '#FFFFFF' ;
	obj.style.color = '#000000' ;

	obj.style.borderColor = '' ;
	/*
	obj.style.borderTopWidth = '0' ;
	obj.style.borderRightWidth = '0' ;
	obj.style.borderBottomWidth = '0' ;
	obj.style.borderLeftWidth = '0' ;
	*/
	//
}

function setBG( parColor, objName )
{
	//
	obj = MM_findObj( objName );
	obj.style.backgroundColor = parColor ;
	//
}








/////////////////////////////////////////////////////////////////////////////////////////////////
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

/////////////////////////////////////////////////////////////////////////////////////////////////


//
function setStatus(strStatus) {
	window.status = strStatus;
	//taintedStatus=taint(window.defaultStatus);
	return true ;
}
//
function setParentStatus(strStatus) {
	parent.status = strStatus;
	//taintedStatus=taint(window.defaultStatus);
	return true ;
}
//



/////////////////////////////////////////////////////////////////////////////////////////////////
//
//		F O R M		Functions
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////
function fieldTextMy( Name , MaxChar, LenIE, LenNN , Class, Value) {
	if( bName!=-1 ){
		document.write("<input size="+LenIE+" name="+Name+" maxlength="+MaxChar+(Class==""?"":" class="+Class)+(Value==""?"":" value=\""+Value+"\"")+" onChange=\"chkInt(frm_register.age);\">" );
	}else{
		window.document.write("<input size="+LenNN+" name="+Name+" maxlength="+MaxChar+(Class==""?"":" class="+Class)+(Value==""?"":" value=\""+Value+"\"")+Other+" onChange=\"chkInt(frm_register.age);\">" );
	}
}

//============================================================================
function fieldTextJS( Name , MaxChar, LenIE, LenNN , Value, JS) {
	if( bName!=-1 ){
		document.write("<input size="+LenIE+" name="+Name+" maxlength="+MaxChar+(Value==""?"":" value=\""+Value+"\"")+(JS==""?"":" "+JS)+">" );
	}else{
		window.document.write("<input size="+LenNN+" name="+Name+" maxlength="+MaxChar+(Value==""?"":" value=\""+Value+"\"")+(JS==""?"":" "+JS)+">" );
	}
}

//============================================================================
function fieldPass( Name , MaxChar, LenIE, LenNN , Value, JS ) {
	if( bName!=-1 ){
		document.write("<input size="+LenIE+" name="+Name+" maxlength="+MaxChar+(Value==""?"":" value=\""+Value+"\"")+(JS==""?"":" "+JS)+" type=\"password\">" );
	}else{
		window.document.write("<input size="+LenNN+" name="+Name+" maxlength="+MaxChar+(Value==""?"":" value=\""+Value+"\"")+(JS==""?"":" "+JS)+" type=\"password\">" );
	}
}

//============================================================================
function fieldTextarea( Name , IECols, IERows , NNCols, NNRows , Wrap , defaultValue, JS ) {
//
//	WRAP : [ OFF | VIRTUAL | PHYSICAL ]
//
//	IECols / NNCols = 1.5
//
	var str;
	if( bName!=-1 ){
		str = "<textarea "+(Wrap==''?'':" wrap="+Wrap)+" name="+Name+" cols="+IECols+" rows="+IERows+(JS==""?"":" "+JS)+">"+defaultValue+"</textarea>" ;
	}else{
		str = "<textarea "+(Wrap==''?'':" wrap="+Wrap)+" name="+Name+" cols="+NNCols+" rows="+NNRows+(JS==""?"":" "+JS)+">"+defaultValue+"</textarea>" ;
	}
	document.write( str );
	//alert( 1 );
}
//============================================================================
function TextareaReadonly( Name , IECols, IERows , NNCols, NNRows , Wrap , defaultValue, Class) {
	if( bName!=-1 ){
		document.write("<textarea "+(Wrap==''?'':" wrap="+Wrap)+" name="+Name+" cols="+IECols+" rows="+IERows+(Class==""?"":" class="+Class)+" readonly>"+defaultValue+"</textarea>");
	}else{
		document.write("<textarea "+(Wrap==''?'':" wrap="+Wrap)+" name="+Name+" cols="+NNCols+" rows="+NNRows+(Class==""?"":" class="+Class)+" readonly>"+defaultValue+"</textarea>");
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function chkInt( obj ) {
	obj.value = obj.value.replace(/[\D ]/g,"");
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function chkFloat( obj ) {
	obj.value = obj.value.replace(/[^,.0-9]/g,"");
	obj.value = obj.value.replace(/\s/g,"");
	//obj.value = obj.value.replace(/ /g,"");
	obj.value = obj.value.replace(/,/g,".");
	if (obj.value=='')
	{
		obj.value='0';
	}
	if (obj.value.indexOf(".")!=-1)
	{
		obj.value += '001';
	}
	else
	{
		obj.value += '.001';
	}
	obj.value = obj.value.replace(/[.](\d+)[.].*/g,".$1");
	obj.value = obj.value.replace(/[.](\d\d)[\d]*/g,".$1");
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function chkDate( obj ) {
//	obj.value = obj.value.replace(/-/g,"/");
//	obj.value = obj.value.replace(/[^,/0-9]/g,"");
//	obj.value = obj.value.replace(/\s/g,"");
	reg=/\d\d-\d\d-\d\d\d\d/
	if (obj.value.search(reg)==-1)
	{
		alert("Дата должна быть в формате dd-mm-yyyy");
		obj.value="ДД-ММ-ГГГГ";
	}
//	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function backHistory( site, par ) {
	if( navigator.appName.indexOf("Internet Explorer")==-1 ){		// те БРОУЗЕР не MS IExplorer
		if( navigator.appName.indexOf("Netscape")>=0 ){		// те БРОУЗЕР Netscape Navigator
			history.go( par );
		}
	}else{
		location=  site+par ;
	}
	//return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function descObject( URL ){
	var w=680; h=600; x=0; y=0;
	ww = this.open( URL , "winoffer", "status=yes,scrollbars=yes,resizable=yes,width="+w+",height="+h+",left="+x+",top="+y );
	ww.focus();
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function openURL( strURL, x, y , w, h ){
	w=600;
	h=500;
	return window.open( strURL , "_blank", "toolbar=0,status=0,resizable=0,scrollbars=0,width="+w+",height="+h+",left="+x+",top="+y );
}


/////////////////////////////////////////////////////////////////////////////////////////////////
//Функция открывает увеличенную картинку
	function MM_openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
	}

//Возвращает правду, если навигатор IE, ложь если Netscape
function isIE()
{
		if( navigator.appName.indexOf("Internet Explorer")==-1 )
		{		// те БРОУЗЕР не MS IExplorer
			if( navigator.appName.indexOf("Netscape")>=0 )
			{		// те БРОУЗЕР Netscape Navigator
			}
		}
		else
		{
			return true;
		}
}



/////////////////////////////////////////////////////////////////////////////////////////////////
function MM_findObj(n, d) { //v4.0
	var p,i,x;
	//
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); 
	//
	return x;
}
			
function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { 
		v=args[i+2];
		if (obj.style) { 
			obj=obj.style; 
			v=(v=='show')?'visible':(v='hide')?'hidden':v; 
		}
		obj.visibility=v;
	}
}

function promotion(){
	var v,obj,height ;
	if ((obj=MM_findObj('promotion'))!=null){ 
		if(bName!=-1){	height = document.body.offsetHeight; } 
			else{ height = window.innerHeight ; }
		//alert( height+"|"+window.pageYOffset);
		//alert( document.all.promotion.style.pixelTop=-10);

		if (obj.style){
			obj=obj.style;
			if( obj.visibility=='visible' ){
				v='hidden';
			}else{
				v='visible';
			}
		}else{
			if(obj.visibility=='show'){
				v='hide';
			}else{
				v='show';
			}
		}
		obj.visibility=v; 

	}
	//MM_showHideLayers('promotion','','show')
}

////////////////////////////////////////////////////
function SetPassword() {
	var txt = "";
	txt = '';
	txt = txt + '<input type="password" name="password" class="frmTextSearchDark" >' ;
	inspwd.innerHTML = txt;
	document.frmLogin.password.focus();
}

////////////////////////////////////////////////////
function setColorBG( obj, myColor ) {
	obj.style.backgroundColor=myColor;
}

////////////////////////////////////////////////////
function setColorBG2( obj, myColor, newColor ) {
	obj.style.backgroundColor=myColor;
	obj.style.color=newColor;
}

////////////////////////////////////////////////////
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

////////////////////////////////////////////////////
function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

////////////////////////////////////////////////////
function wopen( url ) {
	window.open( url, '_self' );
}


function isCancel( the_form )
{
	question = 'Вы действительно хотите удалить?';

	if ( ! the_form )
	{
		return ( confirm( question ) ) ? true : false;		
	}
	else
	{
		f = document.forms[the_form];
		if ( confirm( question ) )
		{
			f.submit(  );
		}
	}

}

function openImageList( tree, id )
{
	wo = window.open( './?tree=' + tree + '&id=' + id + '&action=view_list', '_image', 'menubar=0, scrollbars=1,titlebar=0,directories=0,statusbar=0,resizable=1,width=600,height=600' );
	wo.focus(  );
	return false;
}

function openImage( image, w, h, title )
{
	title = ( title ) ? title : 'просмотр изображения';
	wo = window.open( '', '_blank', 'scollbars=0, menubar=0, titlebar=0, statusbar=0,directories=0, width=' + w + ',height=' + h );
	wo.document.write( '<html>\n' );
	wo.document.write( '<head>\n' );
	wo.document.write( '<title>' + title + '</title>\n' );
	wo.document.write( '</head>\n' );
	wo.document.write( '<body leftmargin=0 topmargin=0 marginheight=0 marginwidth=0 bgcolor="#FFFFFF" text="#000000">\n' );
	wo.document.write( '<img src="' + image + '" width="' + w + '" height="' + h + '" alt=\'' + title + '\' title=\'' + title + '\' onClick="javascript: window.close(  );">\n' );
	wo.document.write( '</body>\n' );
	wo.document.write( '</html>\n' );

	wo.focus(  );
	return;
}
function winHref ( to )
{
	window.location.href = to;
	return false;
}

function openMail(  ) 
{
	w = 570;
	h = 350;
	sw = screen.width;
	sh = screen.height;

	moveX = ( sw / 2 ) - ( w / 2 );
	moveY = ( sh / 2 ) - ( h / 2 );

	wo = window.open ('email_input.php', 'mail', 'scrollbars=0, toolbar=0, resizable=1, directories=0,status=0, width=' + w + ', height=' + h + '');
	wo.moveTo( moveX, moveY );
	wo.focus(  );
	return false;
}

function go_to ( href )
{
	window.location.href = href;
	return false;
}

function isCancel( the_form )
{
	question = 'Вы действительно хотите удалить?';

	if ( ! the_form )
	{
		return ( confirm( question ) ) ? true : false;		
	}
	else
	{
		f = document.forms[the_form];
		if ( confirm( question ) )
		{
			f.submit(  );
		}
	}

}

function test_prioritet( obj )
{
	re = /[^0-9]{1,}/g;
	msg = '';
	
	if ( ! obj.value ) 
	{
		msg = 'Не введен численный приоритет!';
	}
	if ( re.test( obj.value ) ) 
	{
		msg = 'Численный приоритет включает в себя не только цифры!';
	}
	if ( parseInt( obj.value ) <= 0 ) 
	{
		msg = 'Численный приоритет не может быть меньше или ровен нулю!';
	}

	if ( msg )
	{
		obj.focus(  );
		alert( msg );
		return false;
	}

	return true;
}

function test_select( obj, bad_value, _msg )
{
	re = /^select/i;

	if ( typeof obj == 'undefined' )
	{
		_msg = 'Выпадающий список не проинициализирован.';
		alert( _msg );
		return false;
	}
	else if ( ! re.test( obj.type ) )
	{
		_msg = 'Объект не является выпадающий списком';
		alert( _msg );
		return false;
	}

	si = obj.selectedIndex;

	if ( typeof bad_value.length != 'undefined' )
	{
		for( i = 0; i < bad_value.length; i ++ )
		{
			if ( si == bad_value[i] )
			{
				obj.focus(  );
				alert( _msg );
				return false;
			}
		}
	}
	else
	{
		if ( si == bad_value )
		{
			obj.focus(  );
			alert( _msg );
			return false;
		}
	}
	return true;
}

function test_value( obj, _msg )
{
	if ( obj.value == '' )
	{
		obj.focus(  );
		alert( _msg );
		return false;
	}
	return true;
}
function test_date( obj_d, obj_m, obj_y )
{
	si = obj_d.selectedIndex;

	if ( si == -1 ) 
	{
		alert( 'Не выбран день!' );
		obj_d.focus(  );
		return false;
	}
	
	day_id = obj_d.options[si].value;

	si = obj_m.selectedIndex;

	if ( si == -1 ) 
	{
		alert( 'Не выбран месяц!' );
		obj_m.focus(  );
		return false;
	}
	
	month_id = obj_m.options[si].value;

	if ( parseInt( month_id ) == 2 && parseInt( day_id ) > 29 ) 
	{
		alert( 'В Феврале количество дней не превышает 29!' );
		obj_m.focus(  );
		return false;
	}

	si = obj_y.selectedIndex;

	if ( si == -1 ) 
	{
		alert( 'Не выбран год!' );
		obj_y.focus(  );
		return false;
	}

	return true;
}

function openView( tree, id )
{
	win_name = tree + '_' + id;
	wo = window.open( './?tree=' + tree + '&id=' + id + '&action=view', win_name, 'menubar=0, title=0, statusbar=0, status=0, directories=0' );
	wo.focus(  );
	return false;
}

function clearObj( the_form, the_object, default_value, change_type )
{
	f = document.forms[the_form];
	if ( typeof f == 'undefined' )
	{
		return false;
	}
	obj = f.elements[the_object];
	if ( typeof obj == 'undefined' )
	{
		return false;
	}
	if ( obj.value == default_value )
	{
		obj.value = '';
	}
	if ( change_type )
	{
		obj.type = change_type;
	}
	return true;
}

function chkRegForm( )
{
	f = document.f1;
	if (!f.name.value)
	{
		alert ('Не заполнено поле Имя');
		return false;
	}
	if (!f.fam.value)
	{
		alert ('Не заполнено поле Фамилия');
		return false;
	}
	if (!f.org.value)
	{
		alert ('Не заполнено поле Организация');
		return false;
	}
	if (!f.dol.value)
	{
		alert ('Не заполнено поле Должность');
		return false;
	}
	if (!f.login.value)
	{
		alert ('Не заполнено поле Логин');
		return false;
	}
	if (!f.email.value)
	{
		alert ('Не заполнено поле Адрес электронной почты');
		return false;
	}
	return true;
}
