//====================
// Powered by Ustas
//====================
// Ustas@spider.ru
//====================

function ShowModalURL(url, width, height)
{
    if (url == "") {
        return false;
    }
    window_top  = parseInt((screen.availHeight/2) - (height/2)); // Центрирование
    window_left = parseInt((screen.availWidth/2) - (width/2));   // по центру
    win = window.open(url, "MyWindow", "width="+width+', height='+height+', top='+window_top+', left='+window_left+', menubar=no, location=no, resizable=no, scrollbars=0, status=0, statusbar=no');

}

function HideShowElement(elm, line)
{    
    var element = document.getElementById(elm);
    var eline   = document.getElementById(line);
    
    element.style.display = (element.style.display == 'none') ? '' : 'none';
    eline.style.display   = (eline.style.display == 'none') ? '' : 'none';
}

function IsUrl(str) 
{
    return IsPattern("^https?:\\/\\/(?:[a-z0-9_-]{1,32}(?::[a-z0-9_-]{1,32})?@)?(?:(?:[a-z0-9-]{1,128}\\.)+(?:com|net|org|mil|edu|arpa|gov|biz|info|aero|inc|name|[a-z]{2})|(?!0)(?:(?!0[^.]|255)[0-9]{1,3}\\.){3}(?!0|255)[0-9]{1,3})(?:\\/[a-z0-9.,_@%&?+=\\~\\/-]*)?(?:#[^ '\"&<>]*)?$", str.toLowerCase());
}

function IsNumeric(str) 
{
    return IsPattern("^[0-9]+$", str);
}

function IsInteger(str) 
{
    return IsNumeric(str);
}

function IsFloat(str) 
{
    return IsPattern("^[1-9]?[0-9]+(\\.[0-9]+)?$", str);
}

function IsEmail(str) 
{
    return IsPattern("^([a-z0-9_-]+)(\\.[a-z0-9_-]+)*@((([a-z0-9-]+\\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2}))|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))$", str.toLowerCase());
}

function IsRuLat(str) 
{
    return IsPattern("^[ A-Za-zА-Яа-я_-]+$", str.toLowerCase());
}

function IsPhone(str) 
{
    return IsPattern("^[ 0-9_-]+$", str.toLowerCase());
}

function IsPattern(pattern, str) 
{
    if(str.length && pattern.length) {
        var re = new RegExp(pattern, "g");
        return re.test(str);
    }
}

function GetCookie(name) 
{
    var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) {
		return null;
	}
	if (start == -1) {
	    return null;
	}
	var end = document.cookie.indexOf(";", len);
	if (end == -1) {
	    end = document.cookie.length;
	}
	return document.cookie.substring(len, end);
}
	
function SetCookie(name, value) 
{
	var expiry = new Date();
        expiry.setTime(expiry.getTime() + 24 * 60 * 60 * 1000 * 10000);
        document.cookie = name + '=' + value + '; path=/; expires=' + expiry.toGMTString();
	/*if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date(today.getTime() + (expires));
	document.cookie = name + "=" + escape(value) +
		((expires) ? ";expires=" + expires_date.toGMTString() : "") + //expires.toGMTString()
		((path)    ? ";path=" + path : "") +
		((domain)  ? ";domain=" + domain : "") +
		((secure)  ? ";secure" : "");*/
}
	
function DeleteCookie(name) 
{
	if (getCookie(name)) {
	    document.cookie = name + '=;path=/; expires=expires=Thu, 01-Jan-1970 00:00:01 GMT';	    
	}
}

function Search(f)
{
    var f = document.SearchForm;
    
    if (f.keywords.value == '') {
        ShowMessage(f.keywords, 'Для поиска, Вы должны ввести в данное поле ключевые слова!');
        
        return false;
    }
    
    return true;
}

// Initialize message object
window.onload = function() {
    CreateMessage();
}

function VisibleDiv(div)
{    
    var element = document.getElementById(div);    
    var mimage  = document.getElementById('img_'+div);
    
    if (element.style.display == '') {
        if (mimage) {
            mimage.src = 'pic/fronted/div_left.gif';
        }
        element.style.display = 'none';
    } else {
        if (mimage) {
            mimage.src = 'pic/fronted/div_down.gif';
        }
        element.style.display = '';
    }
}
