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 getBrowserInfo(){
	var t,v = undefined;
	if (window.chrome) t = 'Chrome';
	else if (window.opera) t = 'Opera';
	else if (document.all) {
		t = 'IE';
		var nv = navigator.appVersion;
		var s = nv.indexOf('MSIE')+5;
		v = nv.substring(s,s+1);
	} else if (navigator.appName) t = 'Netscape';
	return {type:t,version:v};
}
function bookmark(a){
	var url = window.document.location;
	var title = window.document.title;
	var b = getBrowserInfo();
	if (b.type == 'IE' && 8 >= b.version && b.version >= 4) window.external.AddFavorite(url,title);
	else if (b.type == 'Opera') {
		a.href = url;
		a.rel = 'sidebar';
		a.title = url+','+title;
		return true;
	} else if (b.type == 'Netscape') window.sidebar.addPanel(title,url,'');
	else alert('Нажмите CTRL-D, чтобы добавить страницу в закладки.');
	return false;
}
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));
}


