/*
 * =========================================== Event Handlers and Functions
 * ===========================================
 */

// function doStart()
// {
// doSIFR();
// }
// function doSIFR()
// {
//
// }
function addFavorite(url, title) {
	// if firefox
	if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
	// if IE
	else if (window.external)
		window.external.AddFavorite(url, title);
}

function popProduct(objSelect) {
	if (objSelect != null) {
		for (i = 0; i < objSelect.options.length; i++) {
			if (objSelect.options[i].selected) {
				if (objSelect.options[i].value != '') {
					window.location = objSelect.options[i].value;
				}
			}
		}
	}
}
function popRequestCall() {
	if (location.href.search(/\?page=offer/) == -1) {
		if (!getCookie('dontShow')) {
			var posY = document.documentElement.scrollTop
					|| document.body.scrollTop;
			$('request_call').setStyles({
						display : 'block',
						left : '20px',
						top : posY + 20 + 'px'
					});
		}

	}
}
function closePop() {
	setCookie('dontShow', true);
	document.getElementById("request_call").style.display = 'none';
}
window.onscroll = function() {
	var divRequest = document.getElementById("request_call");
	// divRequest.style.left = "20px";
	// var posY = document.body.scrollTop||window.pageYOffset;
	var posY = document.documentElement.scrollTop || document.body.scrollTop;
	// alert(posY);
	divRequest.style.top = posY + 20 + "px";
}
// возвращает cookie если есть или undefined
function getCookie(name) {
	var matches = document.cookie.match(new RegExp("(?:^|; )"
					+ name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1')
					+ "=([^;]*)"))
	return matches ? decodeURIComponent(matches[1]) : undefined
}

// уcтанавливает cookie
function setCookie(name, value, props) {
	props = props || {}
	var exp = props.expires
	if (typeof exp == "number" && exp) {
		var d = new Date()
		d.setTime(d.getTime() + exp * 1000)
		exp = props.expires = d
	}
	if (exp && exp.toUTCString) {
		props.expires = exp.toUTCString()
	}

	value = encodeURIComponent(value)
	var updatedCookie = name + "=" + value
	for (var propName in props) {
		updatedCookie += "; " + propName
		var propValue = props[propName]
		if (propValue !== true) {
			updatedCookie += "=" + propValue
		}
	}
	document.cookie = updatedCookie

}

// удаляет cookie
function deleteCookie(name) {
	setCookie(name, null, {
				expires : -1
			})
}
