function getXmlHttp() {
  var xmlHttp;
  try {  // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e) {
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e)  {
      try {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  return xmlHttp;
}

  
 function setMessageDiv(what) {
    //alert("setTestDiv");
    xmlHttp = getXmlHttp();
    xmlHttp.onreadystatechange=function() {
      //alert (xmlHttp.readyState);
      if(xmlHttp.readyState==4) {
	    //document.getElementById("message").style.display = "block";
		inter=setInterval('showMessageBox()',5);
        window.document.getElementById("message").innerHTML = xmlHttp.responseText;
      } else {
        //alert("cart: " + " " + xmlHttp.readyState);
      }
    }
    xmlHttp.open("GET", what, true);
	xmlHttp.send(null);
  }
  
  
var messageBoxStep = 0;
var inter;
 
//we show the box by setting the visibility of the element and incrementing the height smoothly
function showMessageBox() {
  if (messageBoxStep == 140) {
    clearInterval(inter);
    return;
  }
  obj = document.getElementById("message");
  obj.style.visibility = 'visible';
  obj.style.display = 'block';
  messageBoxStep += 20;
  obj.style.height = messageBoxStep + 'px';
}
 
function hideMessageBox() {
  obj = document.getElementById("message");
  if (obj.style.visibility == 'visible') {
    if (messageBoxStep <= 20) {
      obj.style.visibility = 'hidden';
      obj.style.display = 'none';
      obj.style.height = '0px';
      clearInterval(inter);
      return;
    }
    messageBoxStep -= 20;
    obj.style.height = messageBoxStep + 'px';
  } else {
    clearInterval(inter);
    return;  
  }
}

function showPhoto(photoId) {
  increaseCounter(photoId);
//alert(1+ " " + photoId);
  window.document.getElementById("photo-pane").innerHTML = "";
//alert(2);  
  var img = window.document.createElement("IMG");
//alert(3);  
  img.style.visibility = "visible";
//alert(4);  
  setOpacity(img, 0);
//alert(5);  
  img.style.width='576px';
//alert(6);  
  img.style.height='386px'
  img.alt=photoId;
//alert(7);  
  img.id = "main_img";
//alert(8);  
  img.onload = function () {
    fadeIn("main_img",0);
  };
//alert(9);  
  img.src = "img/" + photoId + "_01_576.jpg";
//alert(10);  
  window.document.getElementById("photo-pane").appendChild(img);
//alert(11);  
}


function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  if (obj != undefined) {
    // IE/Win
    obj.style.filter = "alpha(opacity:"+opacity+")";
    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity/100;
    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity/100;
    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity/100;
  }
}


function fadeIn(objId,opacity) {
  if (window.document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}

 function setNumberOfPhotosSpan(init) {
 //alert("setNumberOfPhotosSpan");
    xmlHttpNumberOfPhotos = getXmlHttp();
    xmlHttpNumberOfPhotos.onreadystatechange=function() {
      if(xmlHttpNumberOfPhotos.readyState==4) {
        document.getElementById("number_of_photos").innerHTML = xmlHttpNumberOfPhotos.responseText;
		if (init != undefined) {
		  window.setTimeout("setKeywordsDiv(true);", 10);
		  //setKeywordsDiv(init);
		}
      }
    }
    xmlHttpNumberOfPhotos.open("GET", "number_of_photos.php", true);
	//try { xmlHttpNumberOfPhotos.overrideMimeType("text/html; charset=Windows-1251"); } catch (e) {}
	xmlHttpNumberOfPhotos.send(null);
  }

  function setKeywordsDiv(init) {
    xmlHttpKeywords = getXmlHttp();
    xmlHttpKeywords.onreadystatechange=function() {
      if(xmlHttpKeywords.readyState==4) {
        window.document.getElementById("keywords1").innerHTML = xmlHttpKeywords.responseText;
		if (init != undefined) {
		  window.setTimeout("setPhotoListDiv();", 10);
		  window.setTimeout("setMessageDiv('about.php');", 3000);
		}
      }
    }
    xmlHttpKeywords.open("GET", "keywords.php", true);
	//xmlHttpKeywords.overrideMimeType("text/html; charset=Windows-1251");
	xmlHttpKeywords.send(null);
  }

  function setPhotoListDiv(what) {
    search = "";
	if (what != undefined) {
	  search = "?what=" + what;
	}
    xmlHttpPhotoList = getXmlHttp();
    xmlHttpPhotoList.onreadystatechange=function() {
      if(xmlHttpPhotoList.readyState==4) {
	    s = xmlHttpPhotoList.responseText;
        window.document.getElementById("photo-list").innerHTML = s;
		showPhoto(s.substring(53, 59));
      }
    }
    xmlHttpPhotoList.open("GET", "photo_list.php" + search, true);
	//xmlHttpPhotoList.overrideMimeType("text/html; charset=Windows-1251");
	xmlHttpPhotoList.send(null);
  }

  function increaseCounter(what) {
	if (what != undefined) {
	  search = "?what=" + what;
	} else {
          return;
        }
    xmlHttpCounterList = getXmlHttp();
    xmlHttpCounterList.open("GET", "increase_counter.php" + search, true);
    xmlHttpCounterList.send(null);
  }
  
  
  function addCart(what, format) {
	if (what != undefined) {
	  search = "?what=" + what;
	} else {
      return;
    }
	if (format != undefined) {
	  search = search + "&format=" + format;
	} else {
	  search = search + "&format=20x30";
	}
    xmlHttpAddCart = getXmlHttp();
	xmlHttpAddCart.onreadystatechange=function() {
      if(xmlHttpAddCart.readyState==4) {
        window.document.getElementById("size_of_cart").innerHTML = xmlHttpAddCart.responseText;
      }
    }
    xmlHttpAddCart.open("GET", "add_cart.php" + search, true);
    xmlHttpAddCart.send(null);
  }
  
  function checkOrderForm() {
    check = true;
	if (window.document.forms['order'].fullname.value == '') check = false;
	if (window.document.forms['order'].phone.value == '') check = false;
	if (window.document.forms['order'].email.value == '') check = false;
	if (window.document.forms['order'].address.value == '') check = false;
	if (!check)  {
	  alert ("Âñå ïîëÿ äîëæíû áûòü çàïîëíåíû");
	}
	return check;
  }

  function submitOrderForm() {
    if (checkOrderForm()) {
	  setMessageDiv("order.php?name=" + escape(ru2en.translit(window.document.forms['order'].fullname.value)) + 
	                         "&phone="  + escape(ru2en.translit(window.document.forms['order'].phone.value)) + 
							 "&email="  + escape(ru2en.translit(window.document.forms['order'].email.value)) + 
							 "&address="  + escape(ru2en.translit(window.document.forms['order'].address.value)));
	}
  
  }
  
var ru2en = {
  ru_str : "ÀÁÂÃÄÅ¨ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäå¸æçèéêëìíîïðñòóôõö÷øùúûüýþÿ",
  en_str : ['A','B','V','G','D','E','JO','ZH','Z','I','J','K','L','M','N','O','P','R','S','T',
    'U','F','H','C','CH','SH','SHH',String.fromCharCode(35),'I',String.fromCharCode(39),'JE','JU',
    'JA','a','b','v','g','d','e','jo','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f',
    'h','c','ch','sh','shh',String.fromCharCode(35),'i',String.fromCharCode(39),'je','ju','ja'],
  translit : function(org_str) {
    var tmp_str = "";
    for(var i = 0, l = org_str.length; i < l; i++) {
      var s = org_str.charAt(i), n = this.ru_str.indexOf(s);
      if(n >= 0) { tmp_str += this.en_str[n]; }
      else { tmp_str += s; }
    }
    return tmp_str;
  }
}
