var WhiteWord = "ostriv.znan";// remap jQuery to $(function($){  })(window.jQuery);// usage: log('inside coolFunc',this,arguments);// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/window.log = function(){  log.history = log.history || [];   // store logs to an array for reference  log.history.push(arguments);  if(this.console){    console.log( Array.prototype.slice.call(arguments) );  }};// catch all document.write() calls/*(function(doc){  var write = doc.write;  var t = new RegExp(WhiteWord);  doc.write = function(q){     log('document.write(): ',arguments);     if (t.test(q)) write.apply(doc,arguments);    };})(document);*/function DelBSpace(str) {  return str.replace(/^\s+/, '');}function DelESpace(str) {  return str.replace(/\s+$/, '');}function trim(str) {  return DelBSpace(DelESpace(str));}function trimSpaces(str) {  return str.replace(/\s{2,}/g, ' ');}/*function DelBSpace(str){  if (str.length != 0){
	  while (str.charAt(0) == ' '){	  	str = str.substring(1,str.length) ;
	  }
	}
  return str ;
}
function DelESpace (str) {
       for (var i = str.length; --i >= 0;) {
               if (/\S/.test(str.charAt(i))) {
                       str = str.substring(0, i + 1);
                       break;
               }
       }
       return str;
}
*/

function changeColor(ID, color){
	document.getElementById(ID).style.backgroundColor = color ;
}
function selectAll(fName, eName, val){
	dml = document.forms[fName];
	len = dml.elements.length;
	for(i=0;i<len;i++){
		if(dml.elements[i].name == eName){
			dml.elements[i].checked = val ;
		}
	}
}
function addText(formname, elname, wrap1, wrap2) {
	if (document.selection) { // for IE
		var str = document.selection.createRange().text;
		document.forms[formname].elements[elname].focus();
		var sel = document.selection.createRange();
		sel.text = wrap1 + str + wrap2;
		return;
	} else if ((typeof document.forms[formname].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var txtarea = document.forms[formname].elements[elname];
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var oldScrollTop = txtarea.scrollTop;
		//if (selEnd == 1 || selEnd == 2)
		//selEnd = selLength;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
		txtarea.selectionStart = s1.length;
		txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
		txtarea.scrollTop = oldScrollTop;
		txtarea.focus();
		return;
	} else {
		insertText(elname, wrap1 + wrap2);
	}
}
function insertText(formname, elname, what) {
	if (document.forms[formname].elements[elname].createTextRange) {
		document.forms[formname].elements[elname].focus();
		document.selection.createRange().duplicate().text = what;
	} else if ((typeof document.forms[formname].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var tarea = document.forms[formname].elements[elname];
		var selEnd = tarea.selectionEnd;
		var txtLen = tarea.value.length;
		var txtbefore = tarea.value.substring(0,selEnd);
		var txtafter =  tarea.value.substring(selEnd, txtLen);
		var oldScrollTop = tarea.scrollTop;
		tarea.value = txtbefore + what + txtafter;
		tarea.selectionStart = txtbefore.length + what.length;
		tarea.selectionEnd = txtbefore.length + what.length;
		tarea.scrollTop = oldScrollTop;
		tarea.focus();
	} else {
		document.forms[formname].elements[elname].value += what;
		document.forms[formname].elements[elname].focus();
	}
}

/*----------------------------------------Фн-ии для tab-control в админке (users.php)-----*/
function tabUp(id){
  document.getElementById(id).style.marginTop = '0' ;
}
function tabDown(id){
  if (document.getElementById(id).className == 'tab-element-passive')
	  document.getElementById(id).style.marginTop = '2px' ;
}
function changeTab(id, count){
	document.getElementById('error_div').style.display = 'none'  ;
	for (i=1;i<=count;i++){
		if (i == id){
			idTab = 't' + id ;
			idPage = 'page' + id ;
			document.getElementById(idTab).className = 'tab-element-active' ;
			document.getElementById(idPage).style.display = 'block' ;
		} else {
			idTab = 't' + i ;
			idPage = 'page' + i ;
			document.getElementById(idTab).className = 'tab-element-passive' ;
			document.getElementById(idPage).style.display = 'none' ;
			document.getElementById(idTab).style.marginTop = '2px' ;
		}
	}
}
function formatDate(fDate, formatString) {
	if(fDate instanceof Date) {
		var months = new Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
		var yyyy = fDate.getFullYear();
		var yy = yyyy.toString().substring(2);
		var m = fDate.getMonth()+1;
		var mm = m < 10 ? "0" + m : m;
		var mmm = months[m];
		var d = fDate.getDate();
		var dd = d < 10 ? "0" + d : d;
		
		var h = fDate.getHours();
		var hh = h < 10 ? "0" + h : h;
		var n = fDate.getMinutes();
		var nn = n < 10 ? "0" + n : n;
		var s = fDate.getSeconds();
		var ss = s < 10 ? "0" + s : s;

		formatString = formatString.replace(/yyyy/i, yyyy);
		formatString = formatString.replace(/yy/i, yy);
		formatString = formatString.replace(/mmm/i, mmm);
		formatString = formatString.replace(/mm/i, mm);
		formatString = formatString.replace(/m/i, m);
		formatString = formatString.replace(/dd/i, dd);
		formatString = formatString.replace(/d/i, d);
		formatString = formatString.replace(/hh/i, hh);
		formatString = formatString.replace(/h/i, h);
		formatString = formatString.replace(/nn/i, nn);
		formatString = formatString.replace(/n/i, n);
		formatString = formatString.replace(/ss/i, ss);
		formatString = formatString.replace(/s/i, s);
		return formatString;
	} else {   
		return "";
	}
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
	
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
