
var lastTip = null;
var lastMes = null;

function getClientWidth(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}


function showScreenShot(object, url, e) {
	if (!e) e = window.event;
	var tip = document.createElement("div");
	var scrollTop;
	

	_x=e.clientX+10; 
	_y=e.clientY;

	if (window.pageYOffset){  
	 scrollTop = window.pageYOffset 
	} else if(document.documentElement && document.documentElement.scrollTop){ 
	 scrollTop = document.documentElement.scrollTop; 
	} else if(document.body){ 
	 scrollTop = document.body.scrollTop; 
	}
  
	document.body.appendChild(tip);
	tip.style.left = "-700px"; //hack for mozilla
  if (url!="")
    tip.innerHTML = "<img src='" + url + "' />";
  else  
    tip.innerHTML = "Изображение отсутствует";
  
	tip.id = "tip";
  tip.style.background = "#ffffff";
  tip.style.border = "solid 1px #7f7f7f";
	tip.style.position = "absolute";
  tip.style.padding = "5px";
	if(_y+tip.clientHeight>getClientHeight()-20){
		_y=getClientHeight()-tip.clientHeight-20;
	} 

	tip.style.left = (_x ) + "px";
	tip.style.top = (_y + scrollTop) + "px";
  tip.style.display = "inline";
	object.setAttribute("tip", tip);
}

function hideScreenShot(object) {
	var tip = document.getElementById("tip");
	//tip = lastTip;
	if (tip != null) {
		tip.style.display = "none";
		document.body.removeChild(tip);
		object.setAttribute("tip", null);
		delete tip;
	}
}






















// Checkers //////////////////////////////////////////////////////////////////

var rNotBlank = "/.+/gi";
var rMail = "/^.+@[A-Za-z\\-\\.0-9]{2,}\.[A-Za-z]{2,4}$/gi"; 
var rDate =  "/^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\\d\\d$/gi";

var checkers = new Array();

function chGetObj(id) {
    var obj = document.getElementById(id);
    if (obj == null) obj = document.getElementById("#" + id);
    return obj;
}

function _setChecker(obj, regex, msg) {
    if (typeof(obj) == "string") obj = chGetObj(obj);
    if (obj != null) {
        obj.regex = regex;
        obj.message = msg;
        checkers[checkers.length] = obj;
    }
}

function check1() {
    var obj, flag = true, result, message = ''; 
    for (j = 0; j < checkers.length; j ++) {
        obj = checkers[j];
        if (typeof(obj.regex) == 'string') {
            result = eval(obj.regex + ".test(obj.value)");
        }else{
            result = obj.regex.test(obj.value);
        }
        flag = flag && result;
        if (!result) message = message + ((message == '' ? '' : ',') + "\n" + obj.message);
    }
    if (message != '') alert(message + ".");
    if (event != undefined) event.returnValue = flag;
    return flag;
}

/////////////////////////////////////////////////////////////////////////////////

function dialog(url, width, height, arg) {
    // var features = "dialogWidth:" + width + "px; dialogHeight:" + height + "px; resizable:yes; center:yes;";
    features = ""; 
    return window.showModalDialog(url, null, features);
}

function _close() {
    window.close();
}

function _change(obj) {
    if (obj.style.display == 'none') {
        obj.style.display = '';
    }else{
        obj.style.display = 'none';
    }
}

function checkChange(id) {
    var obj = _obj(id);
    if (obj.type == 'checkbox')
        obj.checked = !obj.checked;
}

function _obj(id) {
    return document.getElementById(id);
}

function _open(url, width, height, target, type) {
    var feats; 
    if (type == undefined) type = 1;
    if (target == undefined) target = "";
    if ((width == undefined) || (width == -1)) width = 600;
    if ((height == undefined) || (height == -1)) height = 600;
    switch (type) {
        case 1:
            feats = "resizable=no, location=no, toolbar=no, scrollbars=no, ";
            break;
        case 2:
            feats = "resizable=yes, location=no, toolbar=no, scrollbars=yes, ";
            break;
    }                                                                                    
    window.open(url, target, feats + "width=" + width + "px, height=" + height + "px, ");
    window.event.returnValue = false; 
    return false; 
}

function isemail(value) {
    return /^.+@[A-Za-z\-\.0-9]{2,}\.[A-Za-z]{2,4}$/gi.test(value);
}

function isdate(value) {
    return /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d/gi.test(value);
}

function validate(r, value) {
    return r.test(value);
}

function setChecker(obj, regex) {
    if (typeof(obj) == "string") obj = _obj(obj);
    obj.regex = regex;
    var _check = function () {
        this.style.color = this.regex.test(this.value) ? "#000000" : "#ff0000";
    }
    obj.onkeydown = _check;
    obj.onkeyup = _check; 
    obj.onkeypress = _check;
}

function _alert(message) {
    alert(message);
    window.event.returnValue = false;
    return false;
}

function _select(obj, value) {
    if (typeof(obj) == "string") obj = _obj(obj);
    if (obj == null) return false;
    for (var j = 0; j < obj.options.length; j ++)
        if (String(obj.options.item(j).value).toLowerCase() == String(value).toLowerCase()) {
            obj.selectedIndex = j;
            return true;
        }
    return false;
}

function _print() {
	document.getElementById("_download").style.display = 'none';
	document.getElementById("_print").style.display = 'none';
	window.print();
	if (event != undefined) event.returnValue = false;
}

