var domain = 'http://localhost/strahovanie/';
var imagePrefix='insImage';
var imagePrefixSmall='smallInsImage'; 


function showFootnote(evt, id) {
	   pause(100);
	   var winWidth = document.body.clientWidth;
       var evt = evt || window.event;
       var o = evt.target || evt.srcElement;
       var div = document.getElementById('current_footnote');
       var coords = getElementPosition(o);
       div.innerHTML = '<a href="#" hint=\'Закрыть\' onclick="return hideFootnotes()"><img alt=\'Закрыть\' src="./images/x.gif" height="13" width="13" border="0" id="x_image" /></a><div style="float: right; width: 17px; height: 17px"></div><div style="padding: 7px">' + document.getElementById(id).innerHTML + '</div>';
       div.className = 'footnote_new_active';
       //div.attachEvent('onmouseleave',CloseHint);
       addEvent(div,'mouseleave',CloseHint);
       div = document.getElementById('current_footnote');
       var w = 300;
       div.style.top = (coords.top + o.offsetHeight) + 'px';
       if((winWidth - coords.left) < w) 
       		div.style.left = (coords.left  - 10 - (w - (winWidth - coords.left)))+ 'px';
       else
	       div.style.left = coords.left + 'px';  
       div.style.display = 'none';
       div.style.display = 'block';
       evt.cancelBubble = true;
       return false;
}

function CloseHint()
{
pause(100);
hideFootnotes();
}

function addEvent(obj, evType, fn)
{
  if (obj.addEventListener)
  {
    obj.addEventListener(evType, fn, false);
    return true;
  }
  else if (obj.attachEvent)
  {
  var r = obj.attachEvent("on"+evType, fn);
    return r;
  }
  else
  {
    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 hideFootnotes() {
	var div = document.getElementById('current_footnote');
        div.className = 'footnote_new';
        div.style.display = 'none';
        return false;
}


function SetDefaultImage()
{	
	var mImg=document.images;	
	for (i=0;i<mImg.length;++i)
	{					
		var str=new String(trim(mImg[i].name));
		var nameParts=str.split('_',2);	
		if (nameParts[0]==imagePrefix || nameParts[0]==imagePrefixSmall)
		{		
			var urlSrc= new String(trim(mImg[i].src)); //url from image
			var url=domain+'image.aspx?'; //new url for full image
			var urlSmall=domain+'imagesmall.aspx?';	//new url for miniature								
			var imageId=0; // default imageId
			var width=200; // default width 
			var height=250; // default height
			var typeImage='inform';//default type image
			var linkId=urlSrc.match(/id=\d+/);
			var linkWidth=urlSrc.match(/width=\d+/);		
			var linkHeight=urlSrc.match(/height=\d+/);
			var linkType=urlSrc.match(/type=\w+/);			
			if (linkId!=null && linkId.length==1)
			{
				var tId=linkId[0].split('=',2);
				if (tId!=null && tId.length==2)
					imageId=tId[1];	
			}
			if (linkWidth!=null && linkWidth.length==1)
			{
				var tWidth=linkWidth[0].split('=',2);
				if (tWidth!=null && tWidth.length==2)
					width=tWidth[1];	
			}	
			if (linkHeight!=null && linkHeight.length==1)
			{
				var tHeight=linkHeight[0].split('=',2);
				if (tHeight!=null && tHeight.length==2)			
					height=tHeight[1];	
			}
			if (linkType!=null && linkType.length==1)
			{
				var tType=linkType[0].split('=',2);
				if (tType!=null && tType.length==2)
					typeImage=tType[1];	
			}
			url+='id='+imageId+'&type='+typeImage;
			urlSmall+='id='+imageId;
			urlSmall+='&width='+width;		
			urlSmall+='&height='+height;	
			urlSmall+='&type='+typeImage;	
			if (nameParts[0]==imagePrefix && urlSrc!=url)
			{						
				mImg[i].src=url;
			}else
			if (nameParts[0]==imagePrefixSmall && urlSrc!=urlSmall)
			{						
				mImg[i].src=urlSmall;		
			}	
		}		
	}
}



function ShowImage(sImgPath, width, height,type)
{
	var scroll = 'no';
	var top=0, left=0;
	if(width > screen.width-10 || height > screen.height-28)
		scroll = 'yes';
	if(height < screen.height-28)
		top = Math.floor((screen.height - height)/2-14);
	if(width < screen.width-10)
		left = Math.floor((screen.width - width)/2);
	width = Math.min(width, screen.width-10);	
	height = Math.min(height, screen.height-28);
	width+=20;
	height+=25;	
	if (type.length>0)
		type='type='+type+'&';
	else
		type='type=inform&';	
	window.open(domain+'image.aspx?'+type+'id='+sImgPath,'','scrollbars='+scroll+',resizable=no,width='+width+',height='+height+',left='+left+',top='+top);
} 

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function SetEventForUsherb()
{
	var cb1 = document.getElementById('ctl00_ContentPlaceHoldeCenter_TCalcFirstForm1_RiskList_0');
	cb1.onclick=ChangeUsherbCB;
}

function ChangeUsherbCB()
{
   var cb1 = document.getElementById('ctl00_ContentPlaceHoldeCenter_TCalcFirstForm1_RiskList_0');
   var cb2 = document.getElementById('ctl00_ContentPlaceHoldeCenter_TCalcFirstForm1_RiskList_1');
   if (cb1!=null && cb2!=null)
   {	
	if (cb1.checked=="")
	{
		cb2.disabled=true;
		cb2.checked="";
	}else
	{
		cb2.disabled=false;
		cb2.checked="";
	}
   }	
}

function pause(numberMillis) 
{
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) 
    {
    now = new Date();
    if (now.getTime() > exitTime)
    return;
    }
} 



