// СПРЯТАТЬ \ ПОКАЗАТЬ ЭЛЕМЕНТ
function showOrHide(nodeId){
	//alert (nodeId);
	childs = document.getElementById(nodeId);
	if (childs.style.display == 'inline' || !childs.style.display) {
		childs.style.display='none';
		return;
	}
	if (childs.style.display == 'none') {
		childs.style.display='inline';
		return;
	}
}
	

// Проверяем заполненность Textarea и возвращаем кол-во символов
function checkLength (nodeId) {
	var node = document.getElementById(nodeId);
	//alert (node.value.length);
	return node.value.length;
}



// Блокируем объект
function lockObj (nodeId) {
	var node = document.getElementById(nodeId);
	node.disabled = true;
}

// Разблокировываем объект
function unLockObj (nodeId) {
	var node = document.getElementById(nodeId);
	node.disabled = false;
}

// 
function checkFaq (nodeId){
	if (checkLength(nodeId) >= 1) { unLockObj('faq_btn'); } else { lockObj('faq_btn'); }
}

// проверить input
function checkField(formName){
	var el = document.getElementsByTagName("input");
	for (var i = 0; i < el.length; i++){
		if (el[i].getAttribute("required") == "true" || el[i].getAttribute("required") == "required") {
			if (el[i].value == '') {
				alert ('Все обязательные поля должны быть заполнены');
				return false;
			}
		}
	}
	window.document.forms[formName].submit();
} 


// AJAX

// divId - id где показывать контент
// nId - id ноды в БД
// ajaxRequestFile - файл обработчик запроса
function getAjaxContent(divId, nId, ajaxRequestFile){
	document.getElementById(divId).innerHTML = "Загрузка...";
	//alert (divId);
	ajaxObject = new sack();
	ajaxObject.requestFile = ajaxRequestFile + '?nodeId=' + nId;
	ajaxObject.onCompletion = function() { displayAjaxContent(divId); };	// Specify function that will be executed after file has been found					
	ajaxObject.runAJAX();		// Execute AJAX function
}

function displayAjaxContent (divId) {
	document.getElementById(divId).innerHTML = ajaxObject.response;
	ajaxObject = false;
} 


// галерея.показать_картинку
function showPic (whichpic, picId) {
	if (document.getElementById) {
		document.getElementById('placeholder').src = whichpic.href;
		
		//alert (whichpic.href);
		var old = document.getElementsByTagName("span");
		for (var i=0; i < old.length; i++) {
			if (old[i].className == "selectPic") { 
				cmnRemove_class(old[i], 'selectPic');	
			}
		}
		var thumb = document.getElementById(picId);
		//thumb.style.display = 'none';
		if (thumb.className == "selectPic") cmnRemove_class(thumb, 'selectPic');
		else cmnSet_class (thumb, 'selectPic');
		
		if (whichpic.title) {
			document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
		} else {
			document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
		}
		return false;
	} else {
		return true;
	}
}

// галерея.предзагрузчик
function preLoad() {
	if(document.images){
		var argLen = arguments.length;
		for(var i = 0; i < argLen; i++){
			var arg = arguments[i];
			self[arg] = new Image();
			self[arg].src = "/images/" + arg;
			//document.getElementById('test').src = self[arg].src;
		}
		loaded = true;
	}
}



function cmnSet_class( eOn, sClass_name, sInstead ){
	if( eOn ){
		sClass_name = ( sClass_name.length ) ? sClass_name.replace( /(^\s+|\s+$)/, "" ) : "";
		if( eOn.className.length ){
			var sOld = sClass_name;
			if( sInstead && sInstead.length ){
				sInstead = sInstead.replace( /\s+(\S)/g, "|$1" );
				if( sOld ){
					sOld += "|";
				}
				sOld += sInstead;
			}
			eOn.className = eOn.className.replace( new RegExp("(^|\\s+)(" + sOld +")($|\\s+)", "g"), "$1" );
		}
		eOn.className += ( eOn.className.length && sClass_name ? " " : "" ) + sClass_name;
	}
}

function cmnMatch_class( eOn, sClass_name ){
	return ( sClass_name && eOn.className && eOn.className.length && eOn.className.match( new RegExp("(^|\\s+)(" + sClass_name +")($|\\s+)") ) );
}

function cmnRemove_class( eOn, sClass_name ){
	cmnSet_class( eOn, "", sClass_name );
}




// Показать остальные списки
function showAllLi(rowId) {
	var mylist = document.getElementsByTagName('LI');
	for (var i=0; i<mylist.length; i++) {
		if (mylist[i].id.indexOf("li-"+rowId) != -1 && mylist[i].style.display == 'none') {
			mylist[i].style.display = 'list-item';
		}
		if (mylist[i].id.indexOf("li-href-"+rowId) != -1) mylist[i].style.display = 'none';
	}
}




