function show_img_gd(id_image,width,height)
{
   var a
   var b
   var url
   vidWindowWidth=width;
   vidWindowHeight=height;
   a=(screen.height-vidWindowHeight)/5;
   b=(screen.width-vidWindowWidth)/2;
   features="top="+a+",left="+b+",width="+vidWindowWidth+",height="+vidWindowHeight+",toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=no";
   url="../gallery/showorigin.php?id_photo="+id_image+"&style=origin";
   window.open(url,'',features,true);
   return false;
}

function show_img(img,width,height)
{
   var a
   var b
   var url
   vidWindowWidth=width;
   vidWindowHeight=height;
   a=(screen.height-vidWindowHeight)/5;
   b=(screen.width-vidWindowWidth)/2;
   features="top="+a+",left="+b+",width="+vidWindowWidth+",height="+vidWindowHeight+",toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=no";
   url="../shared/show.php?img="+img;
   window.open(url,'',features,true);
   return false;
}

function photo_info(id_photo,width,height)
{
   var a
   var b
   var url
   vidWindowWidth=width+150;
   vidWindowHeight=height+140;
   a=(screen.height-vidWindowHeight)/5;
   b=(screen.width-vidWindowWidth)/2;
   features="top="+a+",left="+b+",width="+vidWindowWidth+",height="+vidWindowHeight+",toolbar=no,menubar=no,location=no,directories=no,scrollbars=1,resizable=1";
   url="../shared/photoinfo.php?id_photo="+id_photo;
   window.open(url,'',features,true);
   return false;
}

function printpage()
{
  window.print();

}

function submit(id_product)
{
  var a
  var b
  var url
  var wndNewWindow
  titl= "";
  vidWindowWidth=330;
  vidWindowHeight=240;
  a=(screen.height-vidWindowHeight)/2;
  b=(screen.width-vidWindowWidth)/2;
  features="top="+a+",left="+b+",width="+vidWindowWidth+",height="+vidWindowHeight+",toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=no";
  url="addproduct.php?id_product="+id_product+"&rand="+Math.random();
  name="";
  wndNewWindow = parent.open(url,name,features);
}

// Отправка формы с заказом.
// Проверяются значения и открывается скрипт-отправки
function submitorder(name, phone, email, cont)
{
  if (name=="") 
  {
    alert("Не введено имя"); 
    return false;	
  }	
  if (phone=="" && email=="" && cont=="" ) 
  {
    alert("Не введены контактные данные"); 
    return false;
  }	

  var a
  var b
  var url
  var wndNewWindow
  titl= "";
  vidWindowWidth=360;
  vidWindowHeight=250;
  a=(screen.height-vidWindowHeight)/2;
  b=(screen.width-vidWindowWidth)/2;
  features="top="+a+",left="+b+",width="+vidWindowWidth+",height="+vidWindowHeight+",toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=no";
  url="order.php?name="+name+"&phone=" + phone + "&email=" + email + "&contact="+cont;
  name="";
  wndNewWindow = parent.open(url,name,features);
  
}

// Отправка письма
// Проверяются значения и открывается скрипт-отправки
function submitgb(name, msg)
{
  if (name=="") 
  {
    alert("Не введено имя"); 
    return false;	
  }	
  if (msg=="") 
  {
    alert("Не введено сообщение"); 
    return false;
  }	
  
  return true;
  
}

function submitorder(prod, count, name, phone, email, address)
{
  if (prod=="") 
  {
    alert("Не введено наименование продукции"); 
    return false;	
  }	
  if (count=="") 
  {
    alert("Не указано количество продукции"); 
    return false;	
  }	
  if (name=="") 
  {
    alert("Не введено ФИО контактного лица"); 
    return false;	
  }	

  if (phone=="") 
  {
    alert("Не введен контактный телефон"); 
    return false;	
  }	
  if (email=="") 
  {
    alert("Не введен контактный e-mail"); 
    return false;
  }	
  if (address=="") 
  {
    alert("Не введен адрес"); 
    return false;
  }	
  
  return true;
  
}

// Перемещение мышки над кнопкой
function over(obj)
{
  var d=new getObject(obj)
  x=d.left;
  if (x=="") x=0;
  else x=x.substring(0,x.length-2)
  d.left=parseInt(x);
  y=d.top;
  if (y=="") y=0
  else y=y.substring(0,y.length-2)
  d.top=parseInt(y)+1;
}

// Перемещение мышки над кнопкой
function out(obj)
{
  var d=new getObject(obj)
  x=d.left;
  if (x=="") x=0;
  else x=x.substring(0,x.length-2)
  d.left=parseInt(x);
  y=d.top;
  if (y=="") y=0
  else y=y.substring(0,y.length-2)
  d.top=parseInt(y)-1;
}

function getObject(obj) { 
    var theObj 
    if (document.layers) { 
        if (typeof obj == "string") { 
            return document.layers[obj]
        } else { 
            return obj 
        } 
    } 
    if (document.all) { 
        if (typeof obj == "string") { 
		   if(document.all(obj)!=null) return document.all(obj);
		   else return null;
        } else { 
            return obj; 
        } 
    } 
    if (document.getElementById) { 
        if (typeof obj == "string") { 
            return document.getElementById(obj) 
        } else { 
            return obj 
        } 
    } 
    return null 
} 

// Отображение объекта
function show(obj) { 
  var theObj = getObject(obj);
  if (typeof theObj.style.visibility != "undefined") 
                                       theObj.style.visibility = "visible" 
  if (typeof theObj.style.display != "undefined") theObj.style.display = "block" 	
} 
// Функция для скрытия объектов
function hide(obj)
{ 
  var theObj = getObject(obj) 
  if (typeof theObj.style.visibility != "undefined") 
                                       theObj.style.visibility = "hidden"
  if (typeof theObj.style.display != "undefined") theObj.style.display = "none" 		 
} 

function resize(w,h) { 
  if (navigator.userAgent.indexOf("Mac")!=-1 || 
      navigator.userAgent.indexOf("Gecko")!=-1 ||   
      navigator.userAgent.indexOf("Netscape")!=-1) 
    var offset = 0; 
  else     var offset = 4; 
  window.moveTo(50, 50); 
  window.resizeTo(w, h) 
} 

function maxwind() { 
  if (navigator.userAgent.indexOf("Mac")!=-1 || 
      navigator.userAgent.indexOf("Gecko")!=-1 ||   
      navigator.userAgent.indexOf("Netscape")!=-1) 
    var offset = 0; 
  else     var offset = 4; 
  window.moveTo(-offset, -offset); 
  window.resizeTo(screen.availWidth+(2*offset), screen.availHeight+(2*offset)) 
}

/////////////////////////// 
// Java-script меню
/////////////////////////////
// Идентификатор предыдущего открытого меню
var oldsubmenu;
// Открытое меню закрывается по таймеру
var timeOnMenu;
// Функция скрытия блока выпадающего меню
function showmenu(obj)
{
  if (timeOnMenu) {
  // Если установлено скрытие меню, по таймеру,
  // то удалить таймер и отменить скрытие
    clearTimeout(timeOnMenu);
  }
  // Скрыть существующий открытый блок выпадающего меню
  if (oldsubmenu) hide(oldsubmenu);
  // Показать блок выпадающего меню с идентификатором obj
  show(obj);
  // Идентификатор текущего открытого меню
  oldsubmenu=obj;
}
// Функция скрытия блока выпадающего меню
function hidemenu()
{
  // Если есть открытий блок выпадающего меню, то 
  // скрыть его через 0.5 секунды по таймеру
  if (oldsubmenu) timeOnMenu = setTimeout("hide(oldsubmenu)",200)
}

//////////////////////////////////
function setActiveRow(id, nme, countrow)
{
  for (i=1; i<=countrow; i++)
  { 
	var theObj = getObject(nme+i);
	if (typeof theObj != "undefined") theObj.className = "lockrow";
  }
  var theObj = getObject(nme+id); 
  if (typeof theObj != "undefined") theObj.className = "activerow";
  return true;
} 

function translit(name)
{
  var rusChars = new Array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ч','Ц','Ш','Щ','Э','Ю','Я','Ы','Ъ','Ь','Ё','а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ч','ц','ш','щ','э','ю','я','ы','ъ','ь','ё');
  var transChars = new Array('A','B','V','G','D','E','Jo','Zh','Z','I','J','K','L','M','N','O','P','R','S','T','U','F','H','Ch','C','Sh','Shch','E','Ju','Ja','Y','','','E','a','b','v','g','d','e','jo','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f','h','ch','c','sh','shch','e','ju','ja','y','','','e');

	var to = "";
	var len = name.length;
	var character, isRus;
	for ( var i = 0; i < len; i++ )
	{
		character = name.substr(i,1);
		isRus = false;
		for ( var j = 0; j < rusChars.length; j++ )
		{
			if ( character == rusChars[j] )
			{
				isRus = true;
				break;
			}
		}
		to += (isRus) ? transChars[j] : character;
	}
	return to;
}

function convertFIO()
{
	with (document.all['form'])
	{
	  fio_name_en.value = translit(fio_name.value);
	  fio_family_en.value = translit(fio_family.value);
	  fio_patronymic_en.value = translit(fio_patronymic.value);		
	}
}

function convertFirma()
{
	with (document.all['form'])
	{
	
	  tmp = company_form.value.toUpperCase();
	  if (tmp=="ЗАО") tmp="Joint Stock Company";
	  if (tmp=="ООО") tmp="Limited Company";	  
	  if (tmp=="ОАО") tmp="Public Corporation";
	  company_en.value = translit(tmp + " " + company.value);
	}
}

function convertAddress()
{
	with (document.all['form'])
	{
	  jure_zip.value = zip.value;
	  jure_city.value = city.value;
	  jure_district.value = district.value;
	  jure_address.value = address.value;
	}
}
