// Скрыть / показать группу меню
function cvChild(child, view){
	var st0;
	eval("st0=document.all.lev"+child+".style;");
	if (typeof(st0)=='object') { 
		if (!view) {
			if (st0.display=='none') st0.display='block'; 
			else st0.display='none';
		} else {
			st0.display=view;
		}	
	}	 
	return false;
}

// Скрыть / показать элемент
var lastcvElement=new Array();
function cvElement(eid,grp){

	if (!grp) grp=0;
	if (!eid) eid=lastcvElement[grp];
	if (eid) {
		var st0;
		eval("st0=document.all."+eid+".style;");
		if (typeof(st0)=='object') 
			if (st0.display=='none') st0.display='block'; 
			else st0.display='none'; 
		lastcvElement[grp]=eid;
	}	
	return false;
}

// Загрузить новое содержание в фрейм
function fOpen(fName,oUrl,fComments) {
	if (typeof(top.frames.colsframe)=='object') {
	
	if (!fName) fName = top.frames.menu.fActive;
	
	if (oUrl)
		eval("parent.f"+fName+".location.replace('"+oUrl+"')");
	if (fComments) {
		var shortfComments = fComments.substr(0,20);
		if (shortfComments.length < fComments.length) shortfComments+="..";
		eval("top.frames.menu.document.all.fpLink"+fName+".innerHTML='<div title=\""+fComments+"\">"+shortfComments+"</div>'");
		//document.all.fpages.rows[0].cells[fName].innerText=fName+":"+fComments;
	}
	} else {
	
		if (oUrl) opw(oUrl); // opw(oUrl, screen.width, screen.height);

	}	
}

// Текущий активный фрейм
var fActive='0';
var fMaxFrames=3;

// Перейти на след. фрейм
function fNext() {
	if (typeof(top.frames.colsframe)=='object') {
	fActive=top.frames.menu.fActive;

	if ( fActive==fMaxFrames ) fActive=0;
	else fActive++;

	return fActive;
	}
	return '';
}

// Переключиться на нужный фрейм
function fSwitch (fName) {
	if (typeof(top.frames.colsframe)=='object') {

		fActive=top.frames.menu.fActive;
		if (!fActive) fActive=0;
	
		if (typeof(top.frames.menu.document.all.fpages)=='object') {
			top.frames.menu.document.all.fpages.rows[0].cells[fActive].className="trs_unselect7";
			top.frames.menu.document.all.fpages.rows[0].cells[fName].className="trs_select7"; //trs_select
	top.frames.menu.document.all.fpages.rows[0].cells[fActive].background="/ru7/templ/adm/img/ci_"+(	parseInt(fActive)+1)+".gif";									
	top.frames.menu.document.all.fpages.rows[0].cells[fName].background="/ru7/templ/adm/img/ci_"+(fName+1)+"a.jpg";

		}	
		switch(fName) {
			case 0:
				top.frames.colsframe.cols='100%,0,0,0';
				//fActive='fA';
			break;	
			case 1:
				top.frames.colsframe.cols='0,100%,0,0'; 
				//fActive='fB';
			break;	
			case 2:
				top.frames.colsframe.cols='0,0,100%,0'; 
				//fActive='fC';
			break;	
			case 3:
				top.frames.colsframe.cols='0,0,0,100%'; 
				//fActive='fC';
			break;				
			
		}
		top.frames.menu.fActive=fName;
	}
}

// Set 


// Hide map frame 
function hmap () {
    fSwitch(2);
}

function showmap () {

	 fSwitch(0);
   /*
	top.frames.colsframe.cols='800,*'; 
	top.document.all.map.scrolling='yes'; 
	*/
	//top.map.document.all.ContentId.className='dhide'; 
}

// Универсальная функция заполенния параметра формы 
function setParam(obj,val) {
	if (val=='checked') obj.checked=1; else obj.value=val; 
}

// Установить значение параметра формы
function setFormParam(fname, name, val) {
	setParam(document.forms[fname][name],val);
}

// Отправка формы с заполеннием доп. параметров
function sf(fname, name, val, name1, val1, name2, val2, name3, val3) {

	if (name) setParam(document.forms[fname][name],val);
	if (name1) setParam(document.forms[fname][name1],val1);
	if (name2) setParam(document.forms[fname][name2],val2);	
	if (name3) setParam(document.forms[fname][name3],val3);		

	document.forms[fname].submit();
	return false;
}

// Отправка формы с заполеннием доп. параметров
function sfTarget(fname, targetName, name, val, name1, val1, name2, val2, name3, val3) {

	if (name) setParam(document.forms[fname][name],val);
	if (name1) setParam(document.forms[fname][name1],val1);
	if (name2) setParam(document.forms[fname][name2],val2);	
	if (name3) setParam(document.forms[fname][name3],val3);			

	document.forms[fname].target=targetName;	
	document.forms[fname].submit();
	document.forms[fname].target='';	
	return false;
}

// Отправка формы с заполеннием доп. параметров
var popupWidth=800, popupHeight=500;

function setwsize(width, height) {
	popupWidth=width;
	popupHeight=height;
}

// Создание окна и отправка в него формы
function sfa(fname, action, name, val, name1, val1, name2, val2, name3, val3, name4, val4) {

	width=popupWidth;
	height=popupHeight;

	var screen_w = width;
	var screen_h = height;
	
	var popupName='popupWin'+Math.round(Math.random()*100).toString();
	
	if(document.all){
		pw=window.open('',popupName,'top=20,width='+screen_w+',height='+screen_h+',scrollbars=yes,fullscreen=no,status=yes');
	}else{
		pw=window.open('',popupName, 'width='+screen_w+',height='+screen_h+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=no');
	}

	document.forms[fname].target=popupName;
	if (action) document.forms[fname].action=action;

	if (name) setParam(document.forms[fname][name],val);
	if (name1) setParam(document.forms[fname][name1],val1);
	if (name2) setParam(document.forms[fname][name2],val2);	
	if (name3) setParam(document.forms[fname][name3],val3);	
	if (name4) setParam(document.forms[fname][name4],val4);		
	document.forms[fname].submit();
	return false;
}


// Определение направления текущей сортировки заданного поля
function getSortOrder(fname) {

var pos=_orderVar.indexOf(fname);
if (pos==-1) {
	t=-1;
} 
else {
	var len = fname.length;
	var t = _orderVar.substring(pos+len , pos+len+1);
	if (t == "_") t=1; else t=0; // + %2B//
}
return t;
}

// Функция сортировки по заданному полю
function usort(fname) {

var pos=_orderVar.indexOf(fname);
if (pos==-1) {
	_orderVar=fname+"-"+_orderVar;
} 
else {
	var len = fname.length;
	var t = _orderVar.substring(pos+len , pos+len+1);
	if (t == "_") t="-"; else t="_";
	_orderVar=fname+t+_orderVar.substring(0,pos)+_orderVar.substring(pos+len+1,_orderVar.length);
}

window.location.replace(_linkClearOrder+"&ord["+_contentId+"]="+_orderVar);

return false;
}

// Для сокрытия email
/*
<p>Эта ссылка создаст письмо без темы: <br>
<a href="javascript:mailto('pupkin',0,'');"><script>email('pupkin',0);</script></a>
<br> Эта ссылка создаст письмо с темой "Tema_Pupkin"<br>
<a href="javascript:mailto('pupkin',0,'Tema_Pupkin');">Вася Пупкин</a>
*/

function _email (login, sc)
{
if (typeof(sc)=="number")
	eml = login +  "@" + eMailServers[sc];
else
	eml = login +  "@" + sc;
return eml;
}

function email (login, sc)
{
document.write (_email(login, sc));
}

function mailto (login, sc, sub)
{
eml = "mailto:" + _email(login, sc);
if (sub != "") eml += "?subject=" + sub;
window.location.href = eml;
}

//<a href="javascript:SaveAs()">cохранить</a>
//<a href="javascript:Print()">распечатать</a>

// Сохранить страницу
function SaveAs() {
	document.execCommand("SaveAs");
	document.body.focus();
}
// Распечатать страницу
function Print() {
	document.execCommand("Print");
	document.body.focus();
}

// Вызов html редактора в отдельном окне
function popupHtmlEdit(formname,fname) {

	var params=new Object();
	params.win=window;
	params.userConfig=userConfig;

    var myTitle = "HTMLEDITOR";
    var myText = showModalDialog("http://"+userConfig.fulladdress+"templ/adm/popuphtmleditor.htm?"+fname,
                                 params,      // str or obj specified here can be read from dialog as "window.dialogArguments"
                                 "resizable: yes; help: no; status: no; scroll: yes; ");
	
	if (myText!='_cancel_') {
	
		// Исправление ошибок в адресах ссылок и картинок: htmlarea подставляет абсолютные ссылки
		if (userConfig.baseUrlAddress) {
			var reg1=new RegExp(['src=(["\'])'+userConfig.baseUrlAddress],['g']);
			myText=myText.replace(reg1,'src=$1'+userConfig.baseUrlPath);		
			reg1=new RegExp(['href=(["\'])'+userConfig.baseUrlAddress],['g']);
			myText=myText.replace(reg1,'href=$1'+userConfig.baseUrlPath);		
		}
//		else {
			myText=myText.replace(/href="[^{"]+{/,'href="{');
			myText=myText.replace(/src="[^{"]+{/,'src="{');
//		}
			
		// Восстановление body
		content=document.forms[formname][fname].value;
		bi=content.indexOf('<body');
		if (bi>=0) {
			
			ei=content.indexOf('</body>');
			ebi=content.indexOf('>',bi);
			
			document.forms[formname][fname].value = content.substring(0,ebi+1);
			document.forms[formname][fname].value += myText;
			document.forms[formname][fname].value += content.substring(ei,content.length-1);			
			
		}
		else {
			document.forms[formname][fname].value = myText;
		}	
	}	
	
}

// Вызов bbcode редактора в отдельном окне
function popupBBCodeEdit(formname,fname) {
	
	var params=new Object();
	params.win=window;
	params.userConfig=userConfig;

    var myTitle = "BBCODEEDITOR";
    var myText = showModalDialog("templ/adm/popupbbcodeeditor.htm?"+fname,
                                 params,      // str or obj specified here can be read from dialog as "window.dialogArguments"
                                 "width: 780; resizable: yes; help: no; status: no; scroll: yes; ");
	
	if (myText!='_cancel_') document.forms[formname][fname].value = myText;
	
}
/*
Пример использования:
<form name="hhjjkk">
<textarea cols="10" rows="2" name="gghh">lkjlklkk</textarea>
<a class="fmenu" href="#" onclick="return popupBBCodeEdit('hhjjkk','gghh');">BBCode Редактор</a>
</form>

*/

function selectCheckbox(fname, gname, _id, val) {
	if (val=='checked' || val=='unchecked') {
		val=(val=='checked')? 1:0;
		for (var i=0; i<_id.length; i++) 
			if (typeof(document.forms[fname][gname+'['+_id[i]+']'])=='object') 
				document.forms[fname][gname+'['+_id[i]+']'].checked=val;
	} else {
		for (var i=0; i<_id.length; i++) 
			if (typeof(document.forms[fname][gname+'['+_id[i]+']'])=='object') 
				document.forms[fname][gname+'['+_id[i]+']'].value=val;
	}		
}


function big_photo(url,width,height){
//	var screen_w = screen.width;
//	var screen_h = screen.height;
	if (!width) width=670;
	if (!height) height=500;//height=screen.height-50;	
	var screen_w = width;
	var screen_h = height;
	
	if(document.all){
		window.open(url,'_blank','top=20,width='+screen_w+',height='+screen_h+',scrollbars=yes,fullscreen=no');
	}else{
		window.open(url,'_blank', 'width='+screen_w+',height='+screen_h+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=no');
	}
}

// Вызов Popup отдельном окне
function popupRun(fpopup,fname, fparams, width, height) {
/*
	var params=new Object();
	params.win=window;
*/
	if (!width) width=600;
	if (!height) height=500;//height=screen.height-50;	
	var screen_w = width;
	var screen_h = height;

	var url=fpopup+"&datafield="+fname+"&params="+fparams;
//	var url=fpopup+"&datafield="+fname;
	var pw;							 
	alert(url);
	
	if(document.all){
		pw=window.open(url,'_blank','top=20,width='+screen_w+',height='+screen_h+',scrollbars=yes,fullscreen=no,status=yes');
	}else{
		pw=window.open(url,'_blank', 'width='+screen_w+',height='+screen_h+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=no');
	}
//	if (myText!='_cancel_') document.forms[formname][fname].value = myText;
//	return myText;
}


// Open in new window
function opw(url,width,height){
//	var screen_w = screen.width;
//	var screen_h = screen.height;
	if (!width) width=800;
	if (!height) height=500;//height=screen.height-50;	
	var screen_w = width;
	var screen_h = height;
	
	if(document.all){
		return window.open(url,'_blank','width='+screen_w+',height='+screen_h+',scrollbars=yes,fullscreen=no');
	}else{
		return window.open(url,'_blank', 'width='+screen_w+',height='+screen_h+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=no');
	}
}

// Make window
function makew(target,width,height){
	if (!width) width=670;
	if (!height) height=500;//height=screen.height-50;	
	var screen_w = width;
	var screen_h = height;
	
	if(document.all){
		return window.open('',target,'top=20,width='+screen_w+',height='+screen_h+',scrollbars=yes,fullscreen=no');
	}else{
		return window.open('',target, 'width='+screen_w+',height='+screen_h+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=no');
	}
}


// ---------------------------------------------------------------------------------------------------------------------------------------
// Установка значения элемента формы для юзабилити
// Пример: <input name="uform[email]" type="text" style="width:100px" value="ваш email.." onblur="aiValue(this,'ваш email..')" onfocus="aiValue(this,'ваш email..')" >
function aiValue(ffield, defaultValue) {

	if (ffield.value==defaultValue) ffield.value='';
	else if (ffield.value=='') ffield.value=defaultValue;

}
