
if(!defined('order_admin'))
{ 
	order_admin = '';
}

var date_2039 = new Date(2039,11,31,23,59,59);
var expires_2039 = date_2039.toGMTString();

var date = new Date();
//date.setFullYear(date.getFullYear()+10);
//var expires=date.toGMTString();

date.setDate(date.getDate()+1);
var expires=date.toGMTString();

var check_spaces_only = /^\s+$/;
var check_digits_only = /^\d+$/i;
var check_email = /^[a-z0-9-_.]+\@([a-z0-9-]{1,}[\.]{1})*[a-z0-9-]{2,}\.[a-z]{2,4}$/i;
var check_url = /^http:\/\/(www.)*([a-z0-9-]{1,}[\.]{1})*[a-z0-9-]{2,}\.[a-z]{2,4}(\/.*)*$/i;
var check_password_symbols = /^[a-z0-9_]+$/i;
var check_phone_symbols = /^[0-9-\s\(\)\+\,]+$/i;
var check_fax_symbols = /^[0-9-\s\(\)\+\,]+$/i;
var check_textarea_symbols = /^[\\s\\n\\r]+\$/ig;

/* 
	Получение куки 
*/
function getCookie(variable) 
{
	if(variable == null)
	{
		variable = 'report';
	}
	
	var prefix = variable +"=";
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1)
               return "";
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1)
               cookieEndIndex = document.cookie.length;
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}


/* 
	Запись новой куки 
*/
function saveCookie(variable, value, expires)
{
	var newCookie = variable +"=" + escape(value) + "; path=/; expires=" + expires;
	document.cookie = newCookie;
}


/* Смена изображения при наведении */
function over(img, ref)
{
	document.images[img].src = ref;
}	 


/* Смена изображения при убирании */
function out(img, ref)
{
	document.images[img].src = ref;
}


/* Открытие нового окна */
function w_open()
{
	var url = w_open.arguments[0];
	
	var w;
	var h;
	var settings;
	
	if(w_open.arguments[1]) 
	{
		w = w_open.arguments[1];
	} 
	else
	{
		w = screen.width - 100;
	} 
	
	if(w_open.arguments[2]) 
	{
		var h = w_open.arguments[2];
	} 
	else
	{
		h = screen.height - 200;
	}
	
	var wn = 'wname' + Math.round(Math.random() * 10000);
	
	if(w_open.arguments[3] == 'all_enable')
	{
		settings = 'toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, fullscreen=yes, target=_blank';	
	}
	else if(w_open.arguments[3])
	{
		settings = w_open.arguments[3];	
	}
	else
	{
		settings = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, status=no, fullscreen=no, left=40, top=40, width='+w+',height='+h+', target=_blank';	
	}

	var openedWindow = window.open(url, wn, settings);

	if(openedWindow.opener == null) openedWindow.opener = self;
	openedWindow.focus();
}


/* Функция загрузки функции по окончании загрузки страницы (пример вызова: addLoadEvent(onloadSelect);) */
function addLoadEvent(func) 
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	}
	else
	{
		window.onload = function() 
		{
			oldonload();
			func();
		}
	}
}

/* Определение наличия функции */
function defined(constant_name)
{
	return (typeof window[constant_name] !== 'undefined');  
}

/* Аналог PHPшной функции var_dump */
function var_dump(obj) 
{     
	var out = "";     
	if(obj && typeof(obj) == "object")
	{         
		for(var i in obj) 
		{             
			out += i + ": " + obj[i] + "\n";         
		}     
	} 
	else
	{
		out = obj;
	}
			
	alert(out); 
}

/* Confirm */
function confirm_alert(text)
{
	if(confirm(text))
	{
		return true;
	}
	else
	{
		return false;
	}
}


/* Clone */
function clone(o) 
{
	if(!o || 'object' !== typeof o)  
	{
		return o;
	}

	var c = 'function' === typeof o.pop ? [] : {};

	var p, v;

	for(p in o) 
	{
		if(o.hasOwnProperty(p)) 
		{
			v = o[p];
			if(v && 'object' === typeof v) 
			{
				c[p] = clone(v);
			}
			else
			{
				c[p] = v;
			}
		}
	}

	return c;
}


/*
открытие ссылки через onclick с наличием http_refrer в IE
*/
function open_link(url, target, timeout)
{
	target = target || '';
	timeout = timeout || 1;
	
	setTimeout("open_link_func('"+ url +"', '"+ target +"')", timeout);	
}

function open_link_func(url, _target)
{ 
	_target = _target || '_self';
    	
	var fakeLink = document.createElement('a');

 	if((typeof(fakeLink.click) == 'undefined')||(typeof(fakeLink.click) == 'function'))
	{
		if(_target == '_blank')
		{
			w_open(url, '', '', 'all_enable');	
		}
		else
		{
			window.location.href = url;
		}
	}
	else
	{
		fakeLink.target = _target;
		fakeLink.href = url;
		document.body.appendChild(fakeLink);
		fakeLink.click();
	}
} 


/*
аналог alert() и confirm()
для использования требуется подключить модуль jquery-ui свойство dialog
*/
function alert_window(id, text_id, title, text, function_load_on_true, buttons, options)
{
	buttons = buttons || '';
		
	$('#'+ text_id).html(text);
	
	$('#'+ id).attr('class', '');
	
	if(title != '')
	{
		$('#'+ id).attr('title', title);
		$('#ui-dialog-title-'+ id).html(title);
	}	
	
	if(buttons == '')
	{    	
    	$('#'+ id).dialog({buttons: [
        	{
        		text: 'Ok',
        		click: function() {
        			$(this).dialog('close'); 
					
					if(function_load_on_true != '')
					{
						eval(function_load_on_true);
					}
       			}
       		}	
    	]}, {modal: true, draggable: false, resizable: false}, options);	
	}
	else
	{
		$('#'+ id).dialog({buttons: [
			{
        	 	text: buttons['0']['name'],
        		click: function() {
        			$(this).dialog('close'); 
					
					if(buttons['0']['action'] != '')
					{
						eval(buttons['0']['action']);
					}
       			}
    		},
    		{
        		text: buttons['1']['name'],
        		click: function() {
        			$(this).dialog('close'); 
					
					if(buttons['1']['action'] != '')
					{
						eval(buttons['1']['action']);
					}
       			}
    		}
   		]}, {modal: true, draggable: false, resizable: false}, options);	
	}
	
	return false;
}


function confirm_window(id, text_id, title, text, function_load_on_true)
{
	$('#'+ text_id).html(text);
	
	$('#'+ id).attr('class', '');
	
	if(title != '')
	{
		$('#'+ id).attr('title', title);
		$('#ui-dialog-title-'+ id).html(title);
	}
	
	$('#'+ id).dialog({buttons: [
			{
        	 	text: text__yes,
        		click: function() {
        			$(this).dialog('close'); 
					
					if(function_load_on_true != '')
					{
						eval(function_load_on_true);
					}
       			}
    		},
    		{
        		text: text__no,
        		click: function() {
        			$(this).dialog('close'); 
       			}
    		}
   	]}, {modal: true, draggable: false, resizable: false});
	
	return false;
}


function alert_window_show(id, text_id, title, text, function_load_on_true)
{
	if((alert_window_type == 'alert')||(order_admin == 'yes'))
    {
    	alert(text);
    	if(function_load_on_true != '')
    	{
    		eval(function_load_on_true);
    	}	
    }
    else if(alert_window_type == 'alert_window')
    {
    	text = text.replace(/\n/ig, "<br>");
       	alert_window('dialog_message', 'dialog_message_text', title, text, function_load_on_true);
    }
}


/*
Выводить по
*/
function change_on_page(modul_prefix, count, url)
{
	document.cookie = "mess_"+ modul_prefix +"="+ count +"; path=/; expires=" + expires_2039;
	
	document.location.href = url;
}


/*Проверка на включенность яваскрипта и кук*/
function check_cookies_js()
{	
	var curCookie = "check_cookies_js=ok; path=/;"
	document.cookie = curCookie;
		
	var get_Cookie = getCookie('check_cookies_js');	
		
	if(get_Cookie == 'ok')
	{
		document.getElementById('no_cookies_js').style.display = 'none';
	}
	else
	{
		document.getElementById('js_off').style.display = 'none';
	} 
}


