/********** JS utils   v 2.0  	 		    **********/
/********** WildGroup 2001  (www.wildgroup.com.by)  **********/


/*
	function openes new window with supplied parameters.
	NOTE! DO NOT SPECIFY name WITH SPACES (like "Hello world") IT GENERATE IN IE JS ERROR (Object...)!
	NOTE! DO NOT SPECIFY name WITH CYRILLIC CHARS IT CAUSES SOME TROUBLES IN Netscape (Window may not open)
*/
function OpenNewWindow(win_url, win_x, win_y, name, params)
{
  alert("/js/tools.js is deprecated. Please use /js/tools/utils.js.");
  var scr_x, scr_y, loc_x, loc_y
  if(name == null) name='CMS';
  if(params == null) params = "width="+win_x+",height="+win_y; else
  params = "width="+win_x+",height="+win_y + "," + params;
//  alert(win_url+":"+name+":"+params);
  var win = window.open("/blank.jsp",name, params);
  scr_x = screen.width;
  scr_y = screen.height;
  loc_x = (scr_x) * 0.5 - win_x * 0.5;
  loc_y = (scr_y) * 0.5 - win_y * 0.5;
  win.moveTo(loc_x, loc_y);
  win.location.href = win_url;
  return win;
}



var win;

function openDialog(url, width, height, name, params) 
{
	if (!win || (win && win.closed)) {
		var scr_x, scr_y, loc_x, loc_y
		var blank;
		var ie = ((navigator.appName.indexOf("Explorer") != -1) && (navigator.userAgent.indexOf("Opera") == -1));
	    var thisleft;
	    var thistop;
		if(name==null) name="CMS";
		scr_x = screen.width;
		scr_y = screen.height;
		loc_x = (scr_x) * 0.5 - width * 0.5;
	    loc_y = (scr_y) * 0.5 - height * 0.5;
		if(ie){
			if(params == null)params = "help=no;dialogWidth=" + width + "px;dialogHeight=" +height+"px;";
			else params="help=no;dialogWidth=" + width + "px;dialogHeight=" +height+"px;"+params;
			window.showModalDialog(url,blank,params);
		}else{
			if(params == null)params = "width=" + width + ",height=" + height;
			else params = "width=" + width + ",height=" + height+","+params;
			win=window.open(url,name, params);
			win.moveTo(loc_x,loc_y);
			window.onfocus = checkModal;
			opener.onfocus = checkModal;
			parentFrames=new Array();
			var j=1;
			num =new Array();
			num[0]=top.frames;
			if(num.length>0){
				for(k=0;k<num.length;k++){
				parentFrames=num[k];
					for(i=0;i<parentFrames.length;i++){
						if(parentFrames[i].frames.length>0){
							num[j]=parentFrames[i].frames;
							j++;
						}else{
							parentFrames[i].document.onmousedown = checkModal;
						}
					}
				}
			}else{
				top.document.onmousedown = checkModal;
			}
		win.focus();
		}
	} 
}


function checkModal() {
	if (win && !win.closed ) {
		win.focus();
		
	}
}


/*
	function openes new window with supplied parameters
	without returning the window object.
*/

function OpenNewWindow1(win_url, win_x, win_y, name, params)
{
	alert("/js/tools.js is deprecated. Please use /js/tools/utils.js.");
  	OpenNewWindow(win_url, win_x, win_y, name, params);
}

/*
	checks all checkboxes on form
*/
function checkAll(form, checkbox)
{
  if(checkbox == null)
    return;
  var i = 0;
  while (i < form.length)
  {
    if (form.elements[i].type == "checkbox")
    {
      form.elements[i].checked = checkbox.checked;
    }
    i++;
  }
}

/*
	tests a field on nonempty value.
*/
function isNotEmpty(text) {
  if (text.value == "")
  {
    alert("Field is empty");
    return false;
  }
  else
    return true;
}

function isNotPredefinedRole(text, role1, role2)
{
  if ((text.value == role1) || (text.value == role2))
  {
    alert("This role is predefined");
    return false;
  }
  else
    return true;
}

