// JavaScript Document

/**
 * Clear 'href' attribute for hyperlinks that won't really change location
 */
function smart_hyperlinks() {
	try {
		links = document.links
		if (links.length) {
			var current_location      = window.location.href
			current_location          = current_location.toString()
			current_location_relative = current_location.replace(/^[a-z]+\/\/[^\/]+/, '')
			var i = 0
			var node, href, inner, span;
			while (node = links.item(i++)) {
				href = node.getAttribute('href')
				href = href.toString()
				if (!href || 
					(href == current_location) || 
					(href == current_location+"#") || 
					(href == current_location+"/#") || 
					(href == current_location_relative) || 
					(href == current_location_relative+"#") || 
					(href == current_location_relative+"/#") || 
					(href == "./") || 
					(href == "#") || 
					(href == "./#")) {
					node.removeAttribute('href');
					if (!(node.parentNode && node.parentNode.parentNode && node.parentNode.parentNode.parentNode && node.parentNode.parentNode.parentNode.id == 'footer-content')) {
						node.className += ' active'
					}
				}
			}
		}
	} catch (e) {
		alert(e.message)
	}
}
addLoadEvent(smart_hyperlinks);

function foc(inp)
{
obj = document.getElementById(inp);
obj.className="input_sel";
obj.value=""; 
}
function bl(inp)
{
obj = document.getElementById(inp);
obj.className="input";
}
function submit_query(formName, actionName, actionValue) {
	var form_obj = eval("document."+formName);
	eval("window.document."+formName+"."+actionName).value = actionValue;
	return true;
}
function submit_query_prompt(formName, actionName, actionValue, msg) {
	if ((msg != "") && (!window.confirm(msg))) {
		return false;
	}
	return submit_query(formName, actionName, actionValue);
}
function clearInput(formName, inputName) {
	eval("document."+formName+"."+inputName).value = '';
}
function view_image(path, width, height, id) {
	//window.confirm(path);
	//window.location = "admin/popup/view_image.php?"+path;
	pop = popup("units/catalog/view_image.php?file="+path+"&id="+id, "popup", width, height, false, false, 50, 150);
}
function popup(url){
	xPos = window.screenLeft+10;
	yPos = window.screenTop+20;
	win = window.open(url, 'filepopup', "width=400,height=300,left="+xPos+",top="+yPos+",scrollbars=yes,resizable=yes,toolbars=no");
}
function popupbyname(url){
	xPos = window.screenLeft+10;
	yPos = window.screenTop+20;
	win = window.open(siteURL + '/objects/editor/viewpopup.php?url='+url, 'filepopup', "width=400,height=230,left="+xPos+",top="+yPos+",scrollbars=no,resizable=no,toolbars=no");
}
function toggleDiv(id){
	obj = document.getElementById(id);
	tmp = obj.style.display;
	if (tmp == 'none') obj.style.display='block';
	else obj.style.display='none';
}
function show_basket() {
	param = "top=150,left=150,width=630,height=500,scrollbars,resizable";
	popupwindow = window.open("func_const('DIR')/basket/", "BasketWindow", param);
}

function showhide(arr) {
	if (arr.length > 0) {
		for (var i=0; i<arr.length; i++) {
			toggleDiv(arr[i]);
		}
	}
}

function init() {
//	alert(obj.onload);
}

function enterpriseClick(n) {
//	_manufactur = n

	// Пересчитываем
//	calculate()
}
function responsibilityClick(n) {

	// Пересчитываем
//	calculate()
}

function hideNote()
{
var div = document.getElementById('current_footnote');
div.className = 'footnote_new';
div.style.display = 'none';
return false;
}

function getElementPosition(offsetTrail)
{
var offsetLeft = 0;
var offsetTop = 0;
while(offsetTrail) {
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
return { left:offsetLeft, top:offsetTop }
}


function showNote(img, id, img_src)
{
	var note = document.getElementById(id);
	var div = document.getElementById('current_footnote');
	var o = document.getElementById(img);
	var coords = getElementPosition(o); 
	div.innerHTML = '<a href="#" onclick="return hideNote()"><img src="'+img_src+'" height="13" width="13" border="0" id="x_image" /></a><div style="float: right; width: 17px; height: 17px"></div><div style="padding: 7px">' + note.innerHTML + '</div>';
	div.className = 'footnote_new_active';
	div.style.top = (coords.top + o.offsetHeight) + 'px';
	div.style.left = coords.left + 'px';
	div.style.display = 'none';
	div.style.display = 'block';
	return false;
}

function ttt(evt) {
//	alert('test')
	alert(evt.clientX+' : '+evt.clientY+"\n"+window.scrollX+" : "+window.scrollY);
}

function fn_resize(e, intWidth, intHeigth) {
  
  //fn_resize(window,800,500); // вызов процедуры

}


	/*
	These cookie functions are downloaded from 
	http://www.mach5.com/support/analyzer/manual/html/General/CookiesJavaScript.htm
	*/
	function Get_Cookie(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 unescape(document.cookie.substring(len,end)); 
	} 
	// This function has been slightly modified
	function Set_Cookie(name,value,expires,path,domain,secure) { 
		expires = expires * 60*60*24*1000;
		var today = new Date();
		var expires_date = new Date( today.getTime() + (expires) );
	    var cookieString = name + "=" +escape(value) + 
	       ( (path) ? ";path=" + path : "") + 
	       ( (domain) ? ";domain=" + domain : "") + 
	       ( (secure) ? ";secure" : ""); 
	    document.cookie = cookieString; 
//	       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
	} 


function popup_player() {
	var  isplaying = Get_Cookie('lap_popup_player_sv');
//	alert(isplaying);
	if (isplaying == null) {
	 	Set_Cookie('lap_popup_player_sv', 1);
		  var intWidth = 430;
		  var intHeight = 60;
		  var newW;
		  newW = (intWidth == null || intWidth == '' || isNaN(parseInt(intWidth))) ? 800 : parseInt(intWidth);
		  var posX = Math.round(screen.width/2 - newW/2);
		  
		  var newH;
		  newH = (intHeight == null || intHeight == '' || isNaN(parseInt(intHeight))) ? 800 : parseInt(intHeight);
			
		  var posY = Math.round(screen.height/2 - newH/2);
		  
		  var param = "toolbar=no,resizable=no,scrollbars=no,status=no,menubar=no,target=_blank, width="+newW+", height="+newH+", left="+posX+",top="+posY;
		  
		
		  winp = window.open(siteURL + '/_files/music/xspf_player_slim.shtml', 'player', param);
		  try {
			  if (winp.sizeToContent) {
			    winp.sizeToContent(); // изменить размер по содержимому (для FireFox,Mozilla)
			  } 
			  winp.resizeTo(intWidth,1);
		  } catch(e) {}
	}
}

