function getLayer(name) {
	return (document.all)?document.all[name]:document.getElementById(name);
}

function makePopUp(urlValue,widthValue,heightValue) {
    var leftPos = (screen.availWidth-900) / 2;
    var topPos = (screen.availHeight-600) / 2;
    NewWidthValue=widthValue+20;
    NewHeightValue=heightValue+20;
    window.open(urlValue, 'PopUpWindow','width='+NewWidthValue+',height='+NewHeightValue+',menubar=0,scrollbars=yes,resizable=no,statusbar=no,location=no,titlebar=0,toolbar=0,status=0,top=' + topPos + ',left=' + leftPos);
}

function preloadImages(){
	var d = document;  if(!d.pics) d.pics = [];
	for(var i = 0, a = preloadImages.arguments; i < a.length; i++)
		(d.pics[d.pics.length] = new Image()).src = a[i];
}

function fullscreen(){
	window.resizeTo(screen.availWidth, screen.availHeight);
	window.moveTo(0,0);
}

function AddBookmark(){
  if (document.all)
    window.external.AddFavorite(document.location.href,document.title)
}

function GoURL(s){
  document.location = s;
}

function fadeMenu(oId) {
	menu = getLayer(oId);
	menu.style.display='none';
}

function showSubMenu(oId) {  
   menu = getLayer('submenu_'+oId);
	arr = getLayer('submenuarr_'+oId);
	
	clearTimeout(menu.fade);
	menu.fade = null;
	menu.style.display='block';
		
	clearTimeout(arr.fade);
	arr.fade = null;
	arr.style.display='block';
}

function hideSubMenu(oId) {
	menu = getLayer('submenu_'+oId);
	arr = getLayer('submenuarr_'+oId);
	
	clearTimeout(menu.fade);
	menu.fade = setTimeout("fadeMenu('submenu_"+oId+"')", 50);

	clearTimeout(arr.fade);
	arr.fade = setTimeout("fadeMenu('submenuarr_"+oId+"')", 50);
}      


///////
//  Calculator    
 ////////////////  
 
  var Rent = 0;
  var MinCupCount = 0;
  var Quantity = 0;
  var MidCupCost = 0;
  var CupCost    = 0;

 function setDefaultValues(midCupCost, cupCost){
  	 MidCupCost = parseFloat(midCupCost);
  	 CupCost = parseFloat(cupCost);
  	 return MidCupCost, CupCost;
 }       
 
 void function setContactsData(object_ref){ 
	 	getLayer('Contact').innerHTML = object_ref.options[object_ref.selectedIndex].value;
	 	return;
 }          
 
 function setModifier(object_ref){
  		parsed_string = __parse_value(object_ref.options[object_ref.selectedIndex].value);
  		Rent = parseFloat(parsed_string[0]);
  		MinCupCount = parseInt(parsed_string[1]);
  		if(isNaN(MinCupCount)) MinCupCount = 0;
  		getLayer('CupCount').value = MinCupCount;
  		getLayer('Error').style.display = 'none';
  		getLayer('Rent').innerHTML = __round(Rent) + ' ãðí.';  
  		__process();
  		return Rent, MinCupCount;
 }    
 
 function __parse_value(unparsed_string){
     parsed_strings = new Array(); 
     parsed_strings = unparsed_string.split(':'); 
     return parsed_strings;
 }  
 
 void function setQuantity(object_ref){
     if(__inLimit(object_ref.value)){
       getLayer('Error').style.display = 'none';
 	  	 Quantity = object_ref.value;
 	  	 __process();    
 	  }else{
 	    getLayer('Error').style.display = 'block';
 	    getLayer('Error').innerHTML = 'Çàìàëà ê³ëüê³ñòü! Äëÿ öüîãî àïàðàòó — ì³í³ìóì ' + MinCupCount;
		Quantity = object_ref.value;
 	  	 __process();
 	  }
  	  return;
 } 
 
 function __inLimit(current_value){
     if(parseInt(current_value) >= MinCupCount){
     	  return true;
     	}else{ 
     	  return false;
     	}
 }    
 
 void function __process(){
  		total =  parseInt(getLayer('CupCount').value) * 30 *  (CupCost - MidCupCost)/1.2 - Rent;  
  		getLayer('Total').innerHTML = __round(total) + ' ãðí.';
  		return;
 }  
 
 void function setCupCost(object_ref){
  		CupCost = parseFloat(object_ref.value);
  		__process();
  		return;
 }  
 
 function __round(value){
      return value.toFixed(2);
 }          