function id(Id) {
	return document.getElementById(Id);
}
function delDOM(Id) {
	elem = document.getElementById(Id);
	elem.parentNode.removeChild(elem);
}
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
function preLoadImages(){
	for(i=0;i<arguments.length;i++){
		this[i]=new Image()
		this[i].src=arguments[i]
	}
	return this
}
function in_array(needle, haystack, strict) {
	var found = false, key, strict = !!strict;
	for (key in haystack) {
		if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
			found = true;
			break;
		}
	}
	return found;
}
function addBookmark(title,url) {
	var dom = (document.getElementById) ? true : false;
	var nn4 = (document.layers) ? true : false;
	var ie = (document.all) ? true : false;
	var ie4 = (!dom && ie) ? true : false;
	var moz = (dom && (navigator.appName=="Netscape")) ? true : false;
	var opr = (dom && window.opera) ? true : false;
	var op7 = false;
	if (opr) {
		ua = navigator.userAgent;
		opisp = ua.indexOf("Opera");
		if (opisp >= 0) {
			opisp+=6;
			op7 = ( (ua.charAt(opisp)>6 && ua.charAt(opisp)<=9) || (ua.charAt(opisp)==1) ) ? true : false;
		}
	}
	if(opr || op7) {
		alert('Пожалуйста нажмите CTRL + T для добавления в закладки.');
	} else if(ie4 || ie) {
		window.external.AddFavorite(url,title);
	} else if(nn4 || moz) {
		window.sidebar.addPanel(title,url,"");
	}
}

function delAllChild (elem) {
	for(var i=elem.childNodes.length-1; i>=0; i--) {
		elem.removeChild(elem.childNodes[i]);
	}	
}
globalUIDs = Array();
function getUID () {
	var ID = String();
	for (var i=0; i<10; i++) {
		ID += Math.floor(Math.random()*10);
	}
	if (globalUIDs[ID]) ID = getUID ();
	globalUIDs[ID] = 1;
	return ID;
}

function showShadow (id) {
	bigEl = document.createElement('div');
	bigEl.id = 'shadow'+id;
	bigEl.style.position = 'absolute';
	bigEl.style.background = 'black';
	bigEl.style.zIndex = 9998;
	bigEl.style.width = '100%' 
	bigEl.style.height = ((document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight)+'px';
	bigEl.style.top = '0px';
	bigEl.style.left = '0px';		
	document.body.appendChild (bigEl);
	setElementOpacity(bigEl, 0.5);	
}

function hideShadow(id) {
	delDOM('shadow'+id);
}
function showLoading (id, onclose) {
	var width = 100;
	var height = 50;
	theLoading = document.createElement('div');
	theLoading.id = 'loading'+id;
	theLoading.style.zIndex = 9999;
	theLoading.style.position = 'absolute';
	theLoading.style.background = '#EEE';
	theLoading.style.border = '1px solid #CCC';
	theLoading.style.width = width+'px';
	theLoading.style.height = height+'px';	
	var windowSize = getWindowSize();
	var windowOffset = getWindowOffset();	
	theLoading.style.top = (windowOffset.y + (windowSize.height - height)/2)+'px';
	theLoading.style.left = (windowOffset.x + (windowSize.width - width)/2)+'px';
//	theLoading.style.top = document.body.scrollTop+((document.body.clientHeight - 50) / 2)+'px';	
//	theLoading.style.left = ((document.body.offsetWidth - 50) / 2)+'px';
	theLoading.innerHTML = '<div style="text-align:center; cursor: pointer;font-size:12px"><img src="well/pics/big/loading.gif" alt="LOADing" style="padding:0;margin:0"><br>ЗАГРУЗКА</div>';
	if (onclose) theLoading.onclick = onclose;
	document.body.appendChild(theLoading);
}
function hideLoading(id) {
	//if (id('loading'+id)) 
	delDOM('loading'+id);
}

// get RANDOM string
function randString (params) {
	if (params.l==null) params.l = 32;
	if (params.c==null) params.c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
	var s = '';
	for (var i = 0, z = params.c.length-1; i < params.l; x = rand(0,z), s += params.c.charAt(x), i++); 
	return s; 
}






// COMMON FUNCTIONS
function rand(min, max) {	// Generate a random integer
	if( max ) return Math.floor(Math.random() * (max - min + 1)) + min;
	else return Math.floor(Math.random() * (min + 1));
}


