//Функция установки cookie
function set_cookie(name, value, minutes)
{
	var expires = new Date();
	expires.setTime(expires.getTime() + minutes*60000);
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}
// Функция получения cookie
function get_cookie(name)
{
	cookie_name = name + "=";
	cookie_length = document.cookie.length;
	cookie_begin = 0;
	while (cookie_begin < cookie_length)
	{
		value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
		{
			var value_end = document.cookie.indexOf (";", value_begin);
			if (value_end == -1)
				value_end = cookie_length;
			return unescape(document.cookie.substring(value_begin, value_end));
		}
		cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
		if (cookie_begin == 0)
			break;
	}
	return null;
}


function fnEventClick(evt)
{
	if(get_cookie("confirmOldSite")!="true")
	{
	 set_cookie("confirmOldSite", true, 60);
	 if(confirm('Внимание!\r\n\r\nВы находитесь на странице старой версии сайта.\r\nВ этой версии не работает корзина заказов.\r\nТовары и цены здесь могут быть устаревшими.\r\nРаботает новая версия сайта. Перейти на нее?'))
	 {
		document.location.href = '/';
		if(typeof(evt.cancelBubble)!='undefined') evt.cancelBubble=true;
		if(evt.stopPropagation) evt.stopPropagation();
		if(evt && evt.preventDefault) evt.preventDefault();
		else if(window.event) window.event.returnValue=false;
		return false; 
	 }
	}
}
if(window.addEventListener) 
 window.addEventListener("click", fnEventClick, true);
else if(window.attachEvent) 
 window.attachEvent("onclick", fnEventClick);  


function exit( status ) {
    // Output a message and terminate the current script
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_exit/
    // +       version: 901.1520
    // +   original by: Brett Zamir
    // +      input by: Paul
    // +   bugfixed by: Hyam Singer (http://www.impact-computing.com/)
    // %        note 1: Should be considered expirimental. Please comment on this function.
    // *     example 1: exit();
    // *     returns 1: null

    var i;

    if (typeof status === 'string') {
        alert(status);
    }

    window.addEventListener('error', function (e) {e.preventDefault();e.stopPropagation();}, false);

    var handlers = [
        'copy', 'cut', 'paste',
        'beforeunload', 'blur', 'change', 'click', 'contextmenu', 'dblclick', 'focus', 'keydown', 'keypress', 'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'resize', 'scroll',
        'DOMNodeInserted', 'DOMNodeRemoved', 'DOMNodeRemovedFromDocument', 'DOMNodeInsertedIntoDocument', 'DOMAttrModified', 'DOMCharacterDataModified', 'DOMElementNameChanged', 'DOMAttributeNameChanged', 'DOMActivate', 'DOMFocusIn', 'DOMFocusOut', 'online', 'offline', 'textInput',
        'abort', 'close', 'dragdrop', 'load', 'paint', 'reset', 'select', 'submit', 'unload'
    ];
    
    function stopPropagation (e) {
        e.stopPropagation();
        // e.preventDefault(); // Stop for the form controls, etc., too?
    }
    for (i=0; i < handlers.length; i++) {
        window.addEventListener(handlers[i], function (e) {e.stopPropagation();}, true);
    }
    
    throw '';
}// }}}

function hl(item_id, status, odd)
{
	var item_title 	= document.getElementById('item_title_'+item_id);
	var item_img 	= document.getElementById('item_img_'+item_id);
	var item_desc 	= document.getElementById('item_desc_'+item_id);
	var class_name = "text"+(odd ? " odd" : "");
	if(status==1) {
		class_name = "text sel";
		class_name = "text sel";
		class_name = "text sel";
	}
	item_title.className = class_name;
	item_img.className = class_name;
	item_desc.className = class_name;
}

//open window
//obj - object with link
//w - window width
//h - window height
function ows(obj,w,h,w_name){
	if(obj.href)
	path=obj.href;
	else
	path=obj;
	w_name = w_name ? w_name : 'w';
	w=window.open(path,w_name,"toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width="+w+",height="+h);
	w.focus();
	return false;
}


var req;

function loadXML(url) {
	req = false;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
		// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				req = false;
			}
		}
	}
	if(req) {
		req.onreadystatechange = update_basket;
		req.open("GET", url, true);
		req.send("");
	}
}

function update_basket() {
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			var count = 0;
			var price = "0,00 руб.";

			if( req.responseXML ) {
				var items = req.responseXML.getElementsByTagName("count");
				if(items.length) count = items[0].firstChild.nodeValue;

				var items = req.responseXML.getElementsByTagName("price");
				if(items.length) price = items[0].firstChild.nodeValue;
			}

			document.getElementById('total_count').innerHTML = count;
			document.getElementById('total_price').innerHTML = price;
		} else {
			//alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}
