//====================
// Powered by Ustas
//====================
// Ustas-V@mail.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 == 'block') {
        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 = 'block';
    }
}





function swapImgRestore() 
{
    var i, x, a = document.swap_img_src; 
    
    for ( i = 0; a && i < a.length && ( x = a[ i ] ) && x.oSrc; i++ ) { 
        x.src = x.oSrc;
    }
}

function swapImgPreloadImages() 
{
    var d = document; 
    
    if ( d.images ) {
        if ( ! d.swap_img_p ) d.swap_img_p = new Array();
        
        var i, j = d.swap_img_p.length;
        var a = swapImgPreloadImages.arguments; 
    
        for ( i = 0; i < a.length; i++ ) {
            if ( a[ i ].indexOf( '#' ) !=0 ) { 
                d.swap_img_p[ j ]       = new Image(); 
                d.swap_img_p[ j++ ].src = a[ i ];
            }
        }
    }
}

function swapImgFindObj( n, d )
{
    var p, i, x = null;  
    
    if ( ! d ) d = document; 
    if ( ( p = n.indexOf( '?' ) ) > 0 && parent.frames.length ) {
        d = parent.frames[ n.substring( p + 1 ) ].document; 
        n = n.substring( 0, p );
    }
    if ( ! ( x = d[ n ] ) && d.all ) x = d.all[ n ]; 
    
    for ( i = 0; ! x && i < d.forms.length; i++ ) {
        x = d.forms[ i ][ n ];
    }
    
    for ( i = 0; ! x && d.layers && i < d.layers.length; i++ ) {
        x = swapImgFindObj( n, d.layers[ i ].document );
    }
    
    if ( ! x && d.getElementById ) x = d.getElementById( n ); 
    
    return ( x );
}

function swapImage() 
{
    var i, j = 0;
    var x, a = swapImage.arguments; 
    
    document.swap_img_src = new Array(); 
    
    for ( i = 0; i < ( a.length - 2 ); i += 3 ) {
    
        if ( ( x = swapImgFindObj( a[ i ] ) ) != null ) {
            document.swap_img_src[ j++ ] = x; 
            if ( ! x.oSrc ) x.oSrc = x.src; 
            x.src = a[ ( i + 2 ) ];
        }
    }
}




var onload_function_list = new Array();

function onloadFunctions()
{
    var size = onload_function_list.length;
    
    for ( var i = 0; i < size; i++ ) {
    
        onload_function_list[ i ].call();
    }
};

function addOnloadEvent( fn )
{
    onload_function_list.push( fn );
};

function groupSearchForm( chk_box )
{
    var search_form = document.forms['shop_search_form'];
    var group_box   = document.getElementById( 'group_search_tr' );
    
    if ( ! search_form || ! group_box ) { return ( false ); }
    
    if ( chk_box.checked ) {
        search_form.keywords.disabled = true;
        search_form.wID.disabled      = true;
        group_box.style.display       = '';
    } else {
        search_form.keywords.disabled = false;
        search_form.wID.disabled      = false;
        group_box.style.display       = 'none';
    }
};








window.onload = function() 
{
    onloadFunctions();
};
