﻿function Pause(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 


function ComplexImage2(id, src1, src2, src3)
{
	var base = 'http://pcm.ws';  
	var img1 = new Image(193,138);
	var img2 = new Image(193,138);
	var img3 = new Image(193,138);
	img1.src = base + src1;
	img2.src = base + src2;
	img3.src = base + src3;
	$("#" + id).attr({src: img1.src});	
	$(window).load(function()
	{
		$("#" + id).mouseover(function() {
				if ($("#" + id).attr('src') == img1.src) 
				{
					$("#" + id).attr({src: img2.src});
					return;
				}	
				if ($("#" + id).attr('src') == img2.src)
				{ 
					$("#" + id).attr({src: img3.src});
					return;
				}				
				if ($("#" + id).attr('src') == img3.src)
				{ 
					$("#" + id).attr({src: img1.src});
					return;
				}															
			});
	});

}

function ComplexImage(id, src1, src2, src3)
{
	var idx = 0;
	var flag;
	var k;
	$('#' + id).html('<img src="'+ src1 + '"><img src="'+ src2 + '"><img src="'+ src3 + '">');
	$('#' + id + ' > *').each(function(i){
		$(this).css('display', 'block');
		$(this).css('position', 'absolute');
		$(this).css('z-index', 4-i);
		idx = i;
	});	
	
	$('#' + id).bind("mouseover", function() {
		flag = 0;
		$('#' + id + ' > *').each(function(i){
				if (flag == 1) return;
				if ($(this).css('display') != 'none')
				{
					flag = 1;
					$(this).fadeOut('slow', function(){$(this).hide();});
					if (i != idx)
					{
						k = i+1;
						$('#' + id + ' > *').eq(k).fadeIn('slow', function(){$('#' + id + ' > *').eq(k).show();});
					}
					else
					{
						k = 0;
						flag = 1;						
						$('#' + id + ' > *').eq(k).fadeIn('slow', function(){$('#' + id + ' > *').eq(k).show();});
					}
				}
		});
	});
}

function reultves()
{ 
     // вес листа, кг = коэф * толщина,мм * дтинна, м * ширина, м 
     // труба вес 1 м = (3,14/1000)*(внешний диаметр - толщина стенки)* толщину стенки * коэф 
     // вес 1 метра прутка = (3,14*диаметр прутка в квадрате * коэф) / 4000
     
     var koef = document.calculator.koef.value;	// Коэфициент плотности
     var type = document.calculator.type.value;		// Тип продукции
     var thickness = document.calculator.thickness.value;	// Толщина
     var width = document.calculator.width.value;	// Ширена
     var length = document.calculator.length.value;		// Длина
     
     var v_diameter = document.calculator.v_diameter.value;	// Ширена
     var bar_diameter = document.calculator.bar_diameter.value;		// Длина
     var wall_thickness = document.calculator.wall_thickness.value;		// Длина
      
     var sum = 0;

 
     if (type =='list')
     {
        sum =  thickness * length * width * koef
     }
     if (type =='pipe')
     {
        sum = 0.00314 * (v_diameter - wall_thickness) * wall_thickness * koef * length
     }
     if (type =='bar')
     {
        sum = 3.14*(bar_diameter*bar_diameter) * koef / 4000 * length
     }     
     
     document.calculator.sum.value = sum;
}
function hide(type)
{ 
	if (document.calculator.type.value == 'list')
	{
	  document.getElementById('thickness').style.display = "block"; 
	  document.getElementById('width').style.display = 'block'; 
	  
	  document.getElementById('v_diameter').style.display = 'none'; 
	  document.getElementById('bar_diameter').style.display = 'none'; 
	  document.getElementById('wall_thickness').style.display = 'none'; 
    }
	if (document.calculator.type.value == 'pipe')
	{
	  document.getElementById('thickness').style.display = 'none'; 
	  document.getElementById('width').style.display = 'none'; 
	  
	  document.getElementById('v_diameter').style.display = 'block'; 
	  document.getElementById('bar_diameter').style.display = 'none'; 
	  document.getElementById('wall_thickness').style.display = 'block'; 
	}
	if (document.calculator.type.value == 'bar')
	{
	  document.getElementById('thickness').style.display = 'none'; 
	  document.getElementById('width').style.display = 'none'; 
	  
	  document.getElementById('v_diameter').style.display = 'none'; 
	  document.getElementById('bar_diameter').style.display = 'block'; 
	  document.getElementById('wall_thickness').style.display = 'none'; 
	}
}




function generate_alias(str)
{
  str = translit(str);
  str = str.toLowerCase();
  str = str.replace(/^[^a-zA-Z01-9]+/g, '');
  str = str.replace(/[^a-zA-Z01-9]+$/g, '');
  str = str.replace(/[^a-zA-Z01-9]+/g, '-');
  return str;
}
function translit(str)
{
  repl = {
    'А' : 'A',
    'Б' : 'B',
    'В' : 'V',
    'Г' : 'H',
    'Ґ' : 'G',
    'Д' : 'D',
    'Е' : 'E',
    'Ё' : 'Jo',
    'Є' : 'Je',
    'Ж' : 'Zh',
    'З' : 'Z',
    'И' : 'Y',
    'І' : 'I',
    'Ї' : 'Ji',
    'Й' : 'Y',
    'К' : 'K',
    'Л' : 'L',
    'М' : 'M',
    'Н' : 'N',
    'О' : 'O',
    'П' : 'P',
    'Р' : 'R',
    'С' : 'S',
    'Т' : 'T',
    'У' : 'U',
    'Ф' : 'F',
    'Х' : 'Kh',
    'Ц' : 'Ts',
    'Ч' : 'Ch',
    'Ш' : 'Sh',
    'Щ' : 'Shch',
    'Э' : 'E',
    'Ю' : 'Ju',
    'Я' : 'Ja',
    'Ы' : 'Y',
    'Ь' : '‘',
    'Ъ' : '‘',
    'а' : 'a',
    'б' : 'b',
    'в' : 'v',
    'г' : 'h',
    'ґ' : 'g',
    'д' : 'd',
    'е' : 'e',
    'ё' : 'jo',
    'є' : 'je',
    'ж' : 'zh',
    'з' : 'z',
    'и' : 'y',
    'і' : 'i',
    'ї' : 'ji',
    'й' : 'y',
    'к' : 'k',
    'л' : 'l',
    'м' : 'm',
    'н' : 'n',
    'о' : 'o',
    'п' : 'p',
    'р' : 'r',
    'с' : 's',
    'т' : 't',
    'у' : 'u',
    'ф' : 'f',
    'х' : 'kh',
    'ц' : 'ts',
    'ч' : 'ch',
    'ш' : 'sh',
    'щ' : 'shch',
    'э' : 'e',
    'ю' : 'ju',
    'я' : 'ja',
    'ы' : 'y',
    'ь' : '‘',
    'ъ' : '‘'
  }
  for (i in repl)
  {
    str = str.replace(i, repl[i], 'g');
  }
  return str;
}
