/*************************************************************************************
 * Сборник JavaScript функций необходимых для создания любого сайта
 * WebInside.RU (c) 2008
 *
 * $(name)
 * getLeft(obj)
 * getTop(obj)
 * getElementsByClass(searchClass,node,tag) 
 * setCookie( name, value, expires, path, domain, secure )
 * getCookie( name )
 * doconfirm(url)
 * windows(win, w, h)
 *
 *************************************************************************************/


/////// $(name) : Object ////////////////////////////////////////////////////////// 
 
function $(obj)
	{
	return document.getElementById(obj);	
	}
	

/////// getLeft(obj) : Xcoord //////////////////////////////////////////////////////
	
function getLeft(obj)
	{
	var left = obj.offsetLeft
	if (obj.offsetParent)
    left += getLeft(obj.offsetParent)
	return left
	}


/////// getTop(obj) : Ycoord ///////////////////////////////////////////////////////

function getTop(obj)
	{
  var top = obj.offsetTop
	if (obj.offsetParent)
    top += getTop(obj.offsetParent)
	return top
	}


///// getElementsByClass(searchClass,node,tag) : Array ///////////////////////////////

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
} 

//////// setCookie( name, value, expires, path, domain, secure ) ///////////////////////

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	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() : '' ) +
//expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

////////// getCookie( name ) //////////////////////////////////////////////////////////////

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}


/////// doconfirm(url) ///////////////////////////////////////////////////////////////////

function doconfirm(url)
        {
        if (confirm("Вы уверены?"))
             {
             document.location.href= url;        
             }        
        }
        
/////// windows(win, w, h) ////////////////////////////////////////////////////////////////        
function windows(win, w, h)
	{
	window.open(win, 'popup', 'width='+w+',height='+h);  	
	}


