var please_wait = null;
var NS = (navigator.appName=="Netscape")?true:false;

function open_url(url, target) {
 	if ( ! document.getElementById) {
  		return false;
 	}

 	if (please_wait != null) {
		var top=Math.round((document.getElementById(target).offsetHeight-18)/2);
		if(top<20) top=20;
		document.getElementById(target).innerHTML = "<div style='width:100%; margin-top:"+top+"px; margin-bottom:"+(top-2)+"px; text-align:center;'>"+please_wait+"</div>";
 	}

 	if (window.ActiveXObject) {
  		link = new ActiveXObject("Microsoft.XMLHTTP");
 	} else if (window.XMLHttpRequest) {
  		link = new XMLHttpRequest();
 	}

 	if (link == undefined) {
  		return false;
 	}
 	link.onreadystatechange = function() { response(url, target); }
 	link.open("GET", url, true);
 	link.send(null);
   
}

function open_url2(url, target) {
 	if ( ! document.getElementById) {
  		return false;
 	}

 	//if (please_wait != null) {
  	//	document.getElementById(target).innerHTML = please_wait;
 	//}

 	if (window.ActiveXObject) {
  		link = new ActiveXObject("Microsoft.XMLHTTP");
 	} else if (window.XMLHttpRequest) {
  		link = new XMLHttpRequest();
 	}

 	if (link == undefined) {
  		return false;
 	}
 	link.onreadystatechange = function() { response(url, target); }
 	link.open("GET", url, true);
 	link.send(null);
	   
}


function response(url, target) {
 	if (link.readyState == 4) {
	 	document.getElementById(target).innerHTML = (link.status == 200) ? link.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the fallowing errorcode: " + link.status;
	}
}

function set_loading_message(msg) {
 	
	please_wait = msg;
}


var newwindow;
function poptastic(fotosrc)
{  
	newwindow=window.open('image.html?'+fotosrc.replace(/catalog\//,"catalog/big_"),'Popup','height=600,width=1000');
	if (window.focus) {newwindow.focus()}
}


function change_chart(id, params) {
  document.getElementById('1d').className='';
  document.getElementById('1w').className='';
  document.getElementById('1m').className='';
  document.getElementById('6m').className='';
  document.getElementById('1Y').className='';
  document.getElementById('3Y').className='';
  
  //document.getElementById(id).src='chart.php?' + params;
}


function change_sector(id) {
  document.getElementById('bankai').className='';
  document.getElementById('finansines_paslaugos').className='';
  document.getElementById('pramone').className='';
  document.getElementById('zaliavos_ir_energetika').className='';
  document.getElementById('chemija_ir_statyba').className='';
  document.getElementById('technologijos').className='';
  document.getElementById('prekyba').className='';
 
  
  document.getElementById(id).className='on';
    
}


function roundNumber(number,decimals) {
	var newString;// The new rounded number
	decimals = Number(decimals);
	if (decimals < 1) {
		newString = (Math.round(number)).toString();
	} else {
		var numString = number.toString();
		if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
			numString += ".";// give it one at the end
		}
		var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
		var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
		var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
		if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
			if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
				while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
					if (d1 != ".") {
						cutoff -= 1;
						d1 = Number(numString.substring(cutoff,cutoff+1));
					} else {
						cutoff -= 1;
					}
				}
			}
			d1 += 1;
		} 
		newString = numString.substring(0,cutoff) + d1.toString();
	}
	if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
		newString += ".";
	}
	var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
	for(var i=0;i<decimals-decs;i++) newString += "0";
	
	return newString; 
}
function poptastic(url)
{
	newwindow=window.open(url,'Popup','height=620,width=770');
	if (window.focus) {newwindow.focus()}
}


function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}
