var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}
function openCloseBlock(name){
  var but=document.getElementById(name+'_block_minmax_but');
  var block=document.getElementById(name+'_block');
//	alert(block.style.display);
  if(block.style.display=='none'){
    block.style.display='block';
    but.style.backgroundPosition='0pt -75px';
  }
  else{
  //if(block.style.display='block'){
//	alert("Ok!");

    block.style.display='none';
    but.style.backgroundPosition='0pt -60px';
  }
//	return false;
}
function showHideItems(name){
  var block=document.getElementById(name);
  if(block.style.display=='none'){
    block.style.display='';
  }
  else{
    block.style.display='none';
  }
  return false;
}
function showHideFAQItems(name){
//alert(name);
	var text=document.getElementById('faq_text_'+name);
  var title=document.getElementById('faq_title_'+name);
//alert(text.style.display);
  if(text.style.display=='none' || text.style.display==''){
    text.style.display='block';
    title.className = 'product_faq_title_active';
  }
  else{
    text.style.display='none';
    title.className = 'product_faq_title';
  }
  return false;
}

function checkUserForm(form){
		var error='';
		var login = document.getElementById("UserLogin").value;
		var pass = document.getElementById("UserPass").value;
		var passConfirm = document.getElementById("UserPassConfirm").value;
		var name = document.getElementById("UserName").value;
		var surename = document.getElementById("UserSurename").value;
		if(login.length < 5) error+='Поле логина не заполнено или менее 5 символов!<br>';

		if(login != login.replace(/ /, '_')) error+='В логине присутствуют пробелы!<br>';

		//document.getElementById("UserLogin").value = login;
//		alert(login+"|"+pass+"|"+passCnfirm+"|"+name+"|"+surename);
		if(pass.length==0 || passConfirm.length==0) error+='Не заполнено поле пароля и/или подтверждения!<br>';

		if(pass != passConfirm) error+='Поле пароля не совпадает с подтверждением!<br>';

		if(name.length==0 || surename.length==0) error+='Не заполнены личные данные: Имя и/или Фамилия!<br>';

		if(error.length > 0) {
				document.getElementById("errorDiv").style.display='block';
				document.getElementById("errorSubDiv").innerHTML=error;
				return false;
		}
		return true;
}
function checkUserPassForm(form){
		var error='';
		var pass = document.getElementById("User_Pass").value;
		var passConfirm = document.getElementById("User_PassConfirm").value;

		if(pass.length==0 || passConfirm.length==0) error+='Не заполнено поле пароля и/или подтверждения!<br>';
		if(pass != passConfirm) error+='Поле пароля не совпадает с подтверждением!<br>';

		if(error.length > 0) {
				document.getElementById("errorDiv").style.display='block';
				document.getElementById("errorSubDiv").innerHTML=error;
				return false;
		}
		return true;
}

function checkParent(parent){
	if(document.getElementById(parent).checked!=true) document.getElementById(parent).checked=true;
}

function checkChildren(chkmb, form){
	var x=document.getElementsByName('MIid[]');
	var parentElm=document.getElementById('ch'+chkmb);
	for (var i=0;i<x.length;i++){
		var parval = x[i].attributes['par'].value;
		if(parval==chkmb) {
			if(parentElm.checked==true) x[i].checked=true;
			else x[i].checked=false;
		}
	}
}

function open_window(link,w,h) //opens new window
{
	var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
	newWin = window.open(link, 'newWin', win);
	newWin.focus();
}

function ShowPhoto(){
	document.getElementById('newPhoto').style.display='block';

	document.getElementById('oldPhoto').style.display='none';
	document.getElementById('ProductPhotoSaved').value = '';
}

function currencyFormSubmit()
{
	document.getElementById("currencyForm").submit();
}

function loginFormEnable(){
	document.getElementById('loginFormBack').style.display='block';
	document.getElementById('loginForm').style.display='block';
	document.getElementById('loginFormBack').style.visibility='visible';
	document.getElementById('loginForm').style.visibility='visible';
	document.getElementById('currency').style.visibility='hidden';
}

function submitLoginForm(){
	document.getElementById('loginFormBack').style.display='none';
	document.getElementById('loginForm').style.display='none';
	document.getElementById('loginFormBack').style.visibility='hidden';
	document.getElementById('loginForm').style.visibility='hidden';
	document.getElementById('currency').style.visibility='visible';

	return false;
}
function setLoginHeight(){
//alert(window.screen.availHeight);
	document.getElementById('loginFormBack').style.height=window.screen.availHeight+'px';
	//alert(document.getElementById('mainTable').scrollHeight);
}
function  OrderTypeDownSumm(exp, cur, summ){
//alert('OrderTypeDownSumm ' + exp+'-'+cur+'-'+summ);
	document.getElementById('orderTypeExpress').innerHTML = '0.00 '+cur;
	var cityPrice = parseFloat(document.getElementById('orderCityPrice').innerHTML);
	summ = summ + cityPrice;
	document.getElementById('orderSumm').innerHTML = summ.toFixed(2);
}
function  OrderTypeUpSumm(exp, cur, summ){
//alert('OrderTypeUpSumm' + exp+'-'+cur+'-'+summ);
//	document.getElementById('orderTypeExpress').innerHTML = (summ*0.5).toFixed(2)+' '+cur;
	document.getElementById('orderTypeExpress').innerHTML = exp.toFixed(2)+' '+cur;
	var cityPrice = parseFloat(document.getElementById('orderCityPrice').innerHTML);
	summ = summ + cityPrice + exp;
	document.getElementById('orderSumm').innerHTML = summ.toFixed(2);
}

function OrderSetDelivery(summ){
	var price = cityPrices[document.getElementById('City').value];
	document.getElementById('orderCityPrice').innerHTML = price.toFixed(2)+' ';
	var express = parseFloat(document.getElementById('orderTypeExpress').innerHTML);
	summ = summ+price+express;
	document.getElementById('orderSumm').innerHTML = summ.toFixed(2);
}

function openPrintWindow(type){
//		function open_window(link,w,h) //opens new window
//	{
		var win = "width="+500+",height="+200+",menubar=no,location=no,resizable=yes,scrollbars=yes";
		newwin = window.open('/print.html?type='+type+'','newwin',win);
		newwin.focus();
//	}
}

function openMailToFriendWindow(url){
		var win = "width="+500+",height="+400+",menubar=no,location=no,resizable=yes,scrollbars=yes";
		newwin = window.open('/mailtofriend.html?url='+url,'newwin',win);
		newwin.focus();
}
function OnlyPhone(){
	//var recName = document.getElementById('RecAddress');
	document.getElementById('RecAddress').disabled=!document.getElementById('RecAddress').disabled;
	//document.getElementById('City').disabled=!document.getElementById('City').disabled;
}

function CheckCartSumm(summ, message, link, minsumm){
	if(summ < minsumm){
		alert(message);
		return false;
	}
	else window.location = link;
}

function goBack(){
	window.history.go(-1);
}
