function popup(url, scrollbars, resizable, w, h)
{
	window.open(url, "123", 'toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable='+resizable+',width='+w+',height='+h);
}

function setVisible(obj, value)
{
	obj = document.getElementById(obj);
	if (value != null) {
		obj.style.display = value ? 'block' : 'none';
	} else {
		obj.style.display = (obj.style.display == 'block') ? 'none' : 'block';
	}
}

function setVisibility(obj, value)
{
	obj = document.getElementById(obj);
	if (value != null) {
		obj.style.visibility = value ? 'visible' : 'hidden';
	} else {
		obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
	}
}

function textCounter(field, countfield, maxlimit) {
	field = document.getElementById(field);
	countfield = document.getElementById(countfield);
	
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	}
	else {
		countfield.value = maxlimit - field.value.length;
	}
}

function limitTextarea(field,maxLines,maxChar) {
	
	// countfield = document.getElementById(countfield);
	
	if(!field.x){
		field.x=uniqueInt();
		field.onblur=function(){clearInterval(window['int'+field.x])}
	}
	window['int'+field.x] = setInterval( function() {
		var lines=field.value.replace(/\r/g,'').split('\n'),
		i=lines.length,
		lines_removed,
		char_removed;
		
		// countfield.value = maxLines - i;
		
		if(maxLines&&i>maxLines){
			// alert('You can not enter\nmore than '+maxLines+' lines');
			lines=lines.slice(0,maxLines);
			lines_removed=1
		}
		if (maxChar) {
			i=lines.length;
			while(i-->0)if(lines[i].length>maxChar) {
				lines[i]=lines[i].slice(0,maxChar);
				char_removed=1;
			}
			// if(char_removed) alert('You can not enter more\nthan '+maxChar+' characters per line')
		}
		if(char_removed||lines_removed) field.value = lines.join('\n');
	},50);
}

function uniqueInt(){
	var num,maxNum=100000;
	if(!uniqueInt.a||maxNum<=uniqueInt.a.length)uniqueInt.a=[];
	do num=Math.ceil(Math.random()*maxNum);
	while(uniqueInt.a.hasMember(num))
	uniqueInt.a[uniqueInt.a.length]=num;
	return num
}

Array.prototype.hasMember = function(testItem) {
	var i=this.length;
	while(i-->0)if(testItem==this[i])return 1;
	return 0
};

function GetXmlHttpObject() 
{ 
	var xmlHttp=null; 
	try { 
		// Firefox, Opera 8.0+, Safari 
	 xmlHttp=new XMLHttpRequest(); 
	}
	catch (e) { 
		//Internet Explorer 
		try { 
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	  }
		catch (e) { 
	  	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	  } 
	} 
	return xmlHttp; 
}
