

function JSRedirect(sLocation)
{
 window.location.href = sLocation;
}


//-----------------------------------------------------------------------------

// проверить строковое поле
function ChkFld_str(IdName)
{
 var Obj = document.getElementById(IdName);
 Obj.value = trim(Obj.value);

 if (Obj.value == '') { Obj.className = Obj.className.replace(/\bInpFld\b/, ' '); Obj.className += ' FldErr'; Obj.focus(); return 1; }
 else                 { Obj.className = Obj.className.replace(/\bFldErr\b/, ' '); Obj.className += ' InpFld'; }
 return 0;
}

// проверить поле файла
function ChkFld_file(IdName)
{
 var Obj = document.getElementById(IdName);
 if (Obj.value == '') { Obj.className = Obj.className.replace(/\bInpFld\b/, ' '); Obj.className += ' FldErr'; Obj.focus(); return -1; }
 else                 { Obj.className = Obj.className.replace(/\bFldErr\b/, ' '); Obj.className += ' InpFld'; }
 return 0;
}

// проверить цивровое поле
function ChkFld_num(IdName, minval, maxval)
{
 var Obj = document.getElementById(IdName);
 Obj.value = trim(Obj.value);
 if (Obj.value < minval || Obj.value > maxval) 
      { Obj.className = Obj.className.replace(/\bInpFld\b/, ' '); Obj.className += ' FldErr'; Obj.focus(); return -1; }
 else { Obj.className = Obj.className.replace(/\bFldErr\b/, ' '); Obj.className += ' InpFld'; }
 return 0;
}

// проверить телефон
function ChkFld_tel(IdName, IsCanBeEmpty)
{
 var $isErr;
 var Obj = document.getElementById(IdName);
 Obj.value = trim(Obj.value);
 if (Obj.value == '' && IsCanBeEmpty) { Obj.className = Obj.className.replace(/\bFldErr\b/, ' '); Obj.className += ' InpFld'; return 0; }

 $isErr = false;
 for (i=0; i<Obj.value.length; i++)
    {
     if ((Obj.value[i] >= '0' && Obj.value[i] <= '9') || Obj.value[i] == '+') { ; }
     else { $isErr = true; }
    }

 if (Obj.value == '') { $isErr = true; }
 if ($isErr) { Obj.className = Obj.className.replace(/\bInpFld\b/, ' '); Obj.className += ' FldErr'; Obj.focus(); return -1; }
 else        { Obj.className = Obj.className.replace(/\bFldErr\b/, ' '); Obj.className += ' InpFld'; }
 return 0;
}


// проверить е-майл
function ChkFld_email(IdName)
{
 var Obj = document.getElementById(IdName);
 var value = trim(Obj.value);

 // reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
 // if (!value.match(reg)) { Obj.className = 'FldErr'; Obj.focus(); return -1; }
 // else { Obj.className = 'InpFld'; }
 // if ( !(/\w+@\w+\.[a-z]{2,4}/.test(value)) )

 if ( !(/\w+@\w+\.[A-Za-z0-9_]{2,4}/.test(value)) ) 
      { Obj.className = Obj.className.replace(/\bInpFld\b/, ' '); Obj.className += ' FldErr'; Obj.focus(); return -1; }
 else { Obj.className = Obj.className.replace(/\bFldErr\b/, ' '); Obj.className += ' InpFld'; }

 return 0;
}

// проверить строковое поле
function ChkFld_id(IdName, ObjName)
{
 var Obj    = document.getElementById(IdName);
 var FldObj = document.getElementById(ObjName);
 if (Obj.value <= 0)
   { 
    Obj.className = Obj.className.replace(/\bInpFld\b/, ' '); FldObj.className += ' FldErr'; 
    FldObj.focus(); return -1; 
   }
 else { Obj.className = Obj.className.replace(/\bFldErr\b/, ' '); FldObj.className += ' InpFld'; }
 return 0;
}

function ChkFld_ch(IdName, CheckValue, ErrObjName)
{
 var Obj    = document.getElementById(IdName);
 var ObjErr = document.getElementById(ErrObjName);
 if (Obj.checked != CheckValue) 
   {
    ObjErr.className = 'FldErr'; Obj.focus(); return -1;
   }
 else { ObjErr.className = ''; }
 return 0;
}

function ChkFld_date(IdNamePre)
{
 var ObjD = document.getElementById((IdNamePre+"d"));
 var ObjM = document.getElementById((IdNamePre+"m"));
 var ObjY = document.getElementById((IdNamePre+"y"));
 var isErr = false;
 var M = ObjM.options[ObjM.selectedIndex].value;
 var D = ObjD.value;

 var DT = new Date(ObjY.value, ObjM.options[ObjM.selectedIndex].value-1, ObjD.value);
 if (isNaN(DT) || ObjY.value < 1900)
   {
    isErr = true;
   }

      if (M < 1 || M > 12) isErr = true;
 else if (D < 1 || D > 31) isErr = true;

 if (isErr)
   {
    ObjD.className = ObjD.className.replace(/\bInpFld\b/, ' '); ObjD.className += ' FldErr'; 
    ObjM.className = ObjM.className.replace(/\bInpFld\b/, ' '); ObjM.className += ' FldErr'; 
    ObjY.className = ObjY.className.replace(/\bInpFld\b/, ' '); ObjY.className += ' FldErr'; 
    ObjD.focus();
    return -1;
   }
 else
   {
    ObjD.className = ObjD.className.replace(/\bFldErr\b/, ' '); ObjD.className += ' InpFld';
    ObjM.className = ObjM.className.replace(/\bFldErr\b/, ' '); ObjM.className += ' InpFld';
    ObjY.className = ObjY.className.replace(/\bFldErr\b/, ' '); ObjY.className += ' InpFld';
   }
 return 0;
}

// проверить корректность ввода пароля
function ChkFld_pswd(IdName1, IdName2)
{
 var Obj1 = document.getElementById(IdName1);
 var Obj2 = document.getElementById(IdName2);

 if ((Obj1.value != Obj2.value) || Obj1.value == "" || Obj2.value == "" || Obj1.value.length < 6)
   { 
    Obj1.className = Obj1.className.replace(/\bInpFld\b/, ' '); Obj1.className += ' FldErr'; 
    Obj2.className = Obj2.className.replace(/\bInpFld\b/, ' '); Obj2.className += ' FldErr'; 
    Obj1.focus(); 
    return -1; 
   }
 else 
   { 
    Obj1.className = Obj1.className.replace(/\bFldErr\b/, ' '); Obj1.className += ' InpFld'; 
    Obj2.className = Obj2.className.replace(/\bFldErr\b/, ' '); Obj2.className += ' InpFld'; 
   }
 return 0;
}

//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
//
/*function TabChange(ToTab, FromTab)
{
 var Obj1 = document.getElementById(ToTab);
 var Obj2 = document.getElementById(FromTab);

 Obj1.className="NoLink Selected";
 Obj2.className="NoLink";
}*/
//-----------------------------------------------------------------------------
/*
function open_window(link) 
{
 var win = "width=700, height=450, menubar=no, location=no, resizable=no, scrollbars=yes, left=150, top=100";
 newWin = window.open(link,'newWin',win);
 newWin.focus();
}
*/
//-----------------------------------------------------------------------------

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function ExpClp(id, state_visible)
{
 var set_state = "block";
 if (state_visible == true) { set_state = "block"; }
 else                       { set_state = "none"; }

 obj  = document.getElementById(id);
 if (obj) { obj.style.display = set_state; }
}

function FlipFlop(id)
{
 obj  = document.getElementById(id);
 if (obj.style.display == "none" ||
     obj.style.display == "") { obj.style.display = "block"; }
 else                         { obj.style.display = "none"; }
}

function ShowBlk(id)
{
 document.getElementById('grid').style.display = 'block';
 var set_state = "block";
 obj  = document.getElementById(id);
 if (obj) { obj.style.display = set_state; }
}

function HideBlk(id)
{
 var set_state = "none";
 obj  = document.getElementById(id);
 if (obj) { obj.style.display = set_state; }
 document.getElementById('grid').style.display = 'none';
}

function SetVal(id, val)
{
 obj  = document.getElementById(id);
 if (obj) { obj.value = val; }
}

function SetContent(id, val)
{
 obj  = document.getElementById(id);
 if (obj) { obj.innerHTML = val; }
}



function showGifter(e)/*{{{*/
{
	var D		= e.getElementsByTagName( 'DIV' )[0];
	D.style.display = 'block';
	if( !e.__gift )
	{
		e.__gift	= 1;
        var Img	= D.getElementsByTagName('IMG');
		for( var i = 0; Img[i]; i++ )
		{
			if( !Img[i].src )
			{
				Img[i].src = Img[i].getAttribute('scr');
			}
		}
		Img = null;
	}
	D	= null;
}/*}}}*/
function hideGifter(el)/*{{{*/
{
    var childs = el.getElementsByTagName('div');
    childs[0].style.display = 'none';
}/*}}}*/


function ReInitLB()
{
 $(document).ready(function(){ $(".lightbox").lightbox(); });
}




/*

//------------------------
function popupInit()
{
 document.write('<div id="PUOverlay"></div>');
 document.write('<div id="PUBlock"><div class="In" id="popupContent"></div></div>');
}

// открыть окно просмотра изображения
function popupDiv(iIdPhoto, isAlbum)
{
 popupOpen();
 if (isAlbum) sAlbum = "&albm=1";
 else         sAlbum = "";
 doLoad("ajax/ajCtrlPhoto.php?act=view&idu=&idp="+iIdPhoto+sAlbum, "BrowseShort", "popupContent", "", true, 4, "");
 
 // <div id="overlay" style="width: 100%; height: 1100px; opacity: 0.25; display: block;"/>
}

// открыть окно оплаты
function popupPay(sAct, iIdUser)
{
 popupOpen();
 doLoad("ajax/ajPay.php?act="+sAct+"&idtouser="+iIdUser, "BrowseShort", "popupContent", "", true, 4, ""); 
}

function popupOpen()
{
 var oObj = document.getElementById("PUOverlay"); 

 document.getElementById("swf1").style.display = "none";
 
 addHandler(window,   'DOMMouseScroll', wheel); // Gecko
 addHandler(window,   'mousewheel', wheel); // Opera
 addHandler(document, 'mousewheel', wheel); // IE

 // TODO: блокировать, скролл по ужержанию колеса как в однокласниках
 // 1. aj, загрузить фото с элементами голосования и прочего

 //addHandler(window,   'DOMMouseDown', mouseTracker);
 //addHandler(window,   'mousedown',    mouseTracker);
 //addHandler(document, 'mousedown',    mouseTracker);
 
 oObj.style.width   = "100%";
 oObj.style.height  = document.body.clientHeight+"px";
 oObj.style.display = "block";
 oObj.style.opacity = "0.25";
 oObj.style.filter  = "progid:DXImageTransform.Microsoft.Alpha(opacity=25);";

 var oObj = document.getElementById("PUBlock");
 oObj.style.display = "block";

 var WinWorkH = get_wh() ? get_wh() : document.body.clientHeight;
 // alert(WinWorkH + ' ' + get_wh() + ' ' + document.body.clientHeight);
 if (WinWorkH < 600)
   { // Высота меньше минимальной допустимой
    oObj.style.width = "720px";
    oObj.style.height   = WinWorkH+"px";
    oObj.style.paddingRight = "20px";
    oObj.style.overflow = "scroll";
    oObj.style.overflowX = "hidden";
    oObj.style.marginTop = "-"+(WinWorkH/2)+"px";
   }
 else
   {
    oObj.style.width = "720px";
    oObj.style.height = "600px";
    oObj.style.paddingRight = "0px";
    oObj.style.overflow = "hidden";
   }

 window.scrollTo(0, 0);
}

function popupClose()
{
 removeHandler(window,   'DOMMouseScroll', wheel); // Gecko
 removeHandler(window,   'mousewheel', wheel); // Opera
 removeHandler(document, 'mousewheel', wheel); // IE

 document.getElementById("PUOverlay").style.display = "none";
 document.getElementById("PUBlock").style.display = "none";
 document.getElementById("swf1").style.display = "block";
}

 // Функция для добавления обработчика событий
function addHandler(object, event, handler, useCapture) 
{
 if (object.addEventListener) { object.addEventListener(event, handler, useCapture ? useCapture : false); }
 else if (object.attachEvent) { object.attachEvent('on' + event, handler); } 
 else                         { alert("Add handler is not supported"); }
}

function removeHandler(object, event, handler)
{
 if (typeof object.removeEventListener != 'undefined') object.removeEventListener(event, handler, false);
 else if (typeof object.detachEvent != 'undefined')    object.detachEvent('on' + event, handler);
 else                                                  throw "Incompatible browser";
}

// function mouseTracker(e)
//{
// e = e || window.Event || window.event;
// if (e && ((e.button == 3 || e.button == 2) || (e.which == 3 || e.which == 2)))
//   {
//    if (e.preventDefault) e.preventDefault();
//    if (e.stopPropagation)  e.stopPropagation();
//    e.returnValue = false;
    //alert("Left clicks only...");
//    return false;
//   }
//} 

// Обработчик события
function wheel(event) 
{
 var delta; // Направление скролла
 // -1 - скролл вниз
 // 1  - скролл вверх
 event = event || window.event;
 // Opera и IE работают со свойством wheelDelta
 if (event.wheelDelta) 
   {
    delta = event.wheelDelta / 120;
    // В Опере значение wheelDelta такое же, но с противоположным знаком
    if (window.opera) delta = -delta;
    // В реализации Gecko получим свойство detail
   } 
 else if (event.detail) 
   {
    delta = -event.detail / 3;
   }
 // Запрещаем обработку события браузером по умолчанию
 if (event.preventDefault)  event.preventDefault();
 event.returnValue = false;
 return delta;
}
*/


function getStyle(elem)
{
   if (window.getComputedStyle)
	  var compStyle = window.getComputedStyle(elem,"");//FireFox, Safari
	else
	  var compStyle = elem.currentStyle;//IE, Opera  
	return compStyle;
}



function get_ww()
{
 var frameWidth = 0;
 if (self.innerWidth)
    frameWidth = self.innerWidth;
 else if (document.documentElement && document.documentElement.clientWidth)
    frameWidth = document.documentElement.clientWidth;
 else if (document.body) 
    frameWidth = document.body.clientWidth;
 return frameWidth;
}



function get_wh()
{
 var frameHeight = 0;
 if (self.innerHeight) 
    frameHeight = self.innerHeight;
 else if (document.documentElement && document.documentElement.clientHeight) 
    frameHeight = document.documentElement.clientHeight;
 else if (document.body)
    frameHeight = document.body.clientHeight;
 return frameHeight;
}





function ExpandCollapce(id, state_visible)
{
 var set_state = "block";
 if (state_visible == true) { set_state = "block"; }
 else                       { set_state = "none"; }
 obj  = document.getElementById(id);
 if (obj) { obj.style.display = set_state; }
}
function ExpClp(id, state_visible)
{
 var set_state = "block";
 if (state_visible == true) { set_state = "block"; }
 else                       { set_state = "none"; }
 obj  = document.getElementById(id);
 if (obj) { obj.style.display = set_state; }
}

function ExpandCollapceFilpFlop(id)
{
 obj  = document.getElementById(id);
 if (obj.style.display == "none") { obj.style.display = "block"; }
 else                             { obj.style.display = "none"; }
}

function FilpFlop(id)
{
 obj  = document.getElementById(id);
 if (obj.style.display == "none") { obj.style.display = "block"; }
 else                             { obj.style.display = "none"; }
}

function ShowRip(id)
{
 document.getElementById('grid').style.display = 'block';
 var set_state = "block";
 obj  = document.getElementById(id);
 if (obj) { obj.style.display = set_state; }
}

function HideRip(id)
{
 var set_state = "none";
 obj  = document.getElementById(id);
 if (obj) { obj.style.display = set_state; }
 document.getElementById('grid').style.display = 'none';
}

function SetVal(id, val)
{
 obj  = document.getElementById(id);
 if (obj) { obj.value = val; }
}

function SetContent(id, val)
{
 obj  = document.getElementById(id);
 if (obj) { obj.innerHTML = val; }
}

function is_int(str)
{
	var i = parseInt (str);

	if (isNaN (i))
		return false;

	i = i . toString ();
	if (i != str)
		return false;

	return true;
}

