function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}
	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}
function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}
	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}
}

function closeForm() {
	var lioverLoading = document.getElementById('lioverLoading');
	var messageLoading = document.getElementById('messageLoading');
	if(lioverLoading) {
		lioverLoading.style.innerHTML = '';
		lioverLoading.style.display = 'none';
	}
	if(messageLoading) {
		messageLoading.style.innerHTML = '';
		messageLoading.style.display = 'none';
	}
	return false;
}

function sendMail(forma) {
	if (!document.getElementsByTagName)  return false; 
	var body = document.getElementsByTagName('body');
	if(body) body = body[0];
	if(!body) return false;
	var lioverLoading = document.getElementById('lioverLoading');
	var messageLoading = document.getElementById('messageLoading');
	PageSize = getPageSize();
	PageScroll = getPageScroll()
	if(!lioverLoading) {
		var lioverLoading = document.createElement("div");
		lioverLoading.setAttribute('id',"lioverLoading");
		lioverLoading.style.position = 'absolute';
		lioverLoading.style.top = '0px';
		lioverLoading.style.left = '0px';
		lioverLoading.style.width = '100%';
		lioverLoading.style.height = '100%';
		lioverLoading.style.zIndex = '9998';
		lioverLoading.style.display = 'none';
		lioverLoading.style.cursor = 'pointer';
		lioverLoading.style.backgroundColor = '#2f1400';
		lioverLoading.innerHTML = '&nbsp;';
		lioverLoading.onclick = closeForm;
		body.appendChild(lioverLoading);
	}
	if(!messageLoading) {
		var messageLoading = document.createElement("div");
		messageLoading.setAttribute('id',"messageLoading");
		messageLoading.style.position = 'absolute';
		messageLoading.style.background = 'url(/img/popup_bg.gif) repeat-y left top';
		messageLoading.style.top = '0px';
		messageLoading.style.left = '0px';
		messageLoading.style.zIndex = '9999';
	}
	messageLoading.style.display = 'block';
	// 
	if(forma == 'sendForm') formhtml = '<div class="popup_t"><div class="popup"><div class="ttl">Отправка письма</div><table border="0" cellspacing="0" cellpadding="0" class="forma"><tr><td align="right"><span id="title_fio">Ф.И.О:</span></td><td colspan="2"><div class="field1"><input name="" type="text" id="input_fio" /></div></td></tr><tr><td align="right" width="68" id="title_email">e-mail:</td><td width="298"><div class="field2"><input name="" type="text"  id="input_email" /></div></td><td rowspan="2"><div class="text1"><span>*</span> Пожалуйста, укажите номер вашего телефона либо адрес электронной почты, чтобы  мы могли связаться с вами</div></td></tr><tr><td align="right" id="title_phone">тел:</td><td><div class="field2"><input name="" type="text"  id="input_phone"/></div></td></tr><tr><td align="right" id="title_message">текст:</td><td colspan="2"><div class="textarea"><textarea name="" cols="" rows="" id="input_text"></textarea></div></td></tr><tr><td align="right" id="title_code">Код:</td><td width="298"><div class="field2"><input name="" type="text"  id="input_code" /></div></td><td><img src="/verimage.php?n=28937&w=180&h=40" width="180" height="40"></td></tr><tr><td colspan="3"><br></td></tr><tr><td>&nbsp;</td><td>&nbsp;<a href="#" onClick="return sendRequest();"><img src="/img/btn_send.gif" alt="" /></a></td><td class="close"><a href="#" onClick="return closeForm();"><img src="/img/btn_close.gif" alt="" /></a></td></tr></table></div></div>';
	else formhtml = document.getElementById(forma).innerHTML;
	messageLoading.innerHTML = formhtml;
	if(messageLoading) body.appendChild(messageLoading);

	messageLoading._offsetWidth = parseInt(messageLoading.offsetWidth);
	messageLoading._offsetHeight = parseInt(messageLoading.offsetHeight);
	messageLoading.style.left =  Math.round(PageSize[2]/2 + PageScroll[0] - messageLoading._offsetWidth/2) +"px";
	messageLoading.style.top =  Math.round(PageSize[3]/2 + PageScroll[1] - messageLoading._offsetHeight/2) +"px";
	lioverLoading.style.width = PageSize[0] + "px";
	lioverLoading.style.height = PageSize[1] + "px";
	messageLoading.style.display = 'none';
	lioverLoading.style.display  = 'block';
	$("#lioverLoading").fadeTo("fast", 0.8);
	$("#messageLoading").fadeIn("slow");
	return false;
}

function sendRequest() {
			var ok = 1;
			var fio = "";
			var inp = document.getElementById('input_fio');
			var ttl = document.getElementById('title_fio');
			if(ttl && inp && inp.value == '') {
				ttl.style.color = "#ff0000";
				ok = 0;
			} else {
				ttl.style.color = "#e4c296";
				fio = inp.value;
			}
			var inp1 = document.getElementById('input_email');
			var ttl1 = document.getElementById('title_email');
			var inp2 = document.getElementById('input_phone');
			var ttl2 = document.getElementById('title_phone');
			email = inp1.value;
			phone = inp2.value;
			if( email == "" && phone == "" ) {
				ttl1.style.color = "#ff0000";
				ok = 0;
			} else {
				ttl1.style.color = "#e4c296";
			}
			var message = "";
			var inp = document.getElementById('input_text');
			var ttl = document.getElementById('title_message');
			if(ttl && inp && inp.value == '') {
				ttl.style.color = "#ff0000";
				ok = 0;
			} else {
				ttl.style.color = "#e4c296";
				message = inp.value;
			}

			var inp = document.getElementById('input_code');
			var ttl = document.getElementById('title_code');
			if(ttl && inp && inp.value != "personaladd" ) {
				ttl.style.color = "#ff0000";
				ok = 0;
			} else {
				ttl.style.color = "#e4c296";
			}


			if(ok) {
				var xmlhttp=create_http_handle();
				if(xmlhttp) {
					var params = "";
					params += 'name='+encodeURIComponent(fio)+"&";
					params += 'email='+encodeURIComponent(email)+"&";
					params += 'phone='+encodeURIComponent(phone)+"&";
					params += 'message='+encodeURIComponent(message)+"&";
					xmlhttp.open("POST", 'sendmail.php', true);
					xmlhttp.setRequestHeader("Content-type", "application/x-www-form-URLencoded; charset=utf-8");
					xmlhttp.setRequestHeader("Content-length", params.length);
					xmlhttp.setRequestHeader("Connection", "close");
					xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
					xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
					xmlhttp.setRequestHeader("Pragma", "no-cache");
					xmlhttp.onreadystatechange=function() {
						if (xmlhttp.readyState==4) {
							if(xmlhttp.responseText == "1") {
								closeForm();
								sendMail("sendTrue");
							} else {
								closeForm();
								sendMail("sendFalse");
							}
						}
					}
					xmlhttp.send(params);
				}
			}
			return false;
		}

		function create_http_handle(TYPE){
			var http_handle = false;
			if (window.XMLHttpRequest){
				http_handle = new XMLHttpRequest();
				if (http_handle.overrideMimeType){
					if (TYPE == "XML"){
						http_handle.overrideMimeType('text/xml');
					} else {
						http_handle.overrideMimeType('text/html');
					}
				}
			} else if (window.ActiveXObject){
				try {
					http_handle = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						http_handle = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {}
				}
			}
			if (!http_handle){
				alert("We are sorry but you are using an outdated browser.  To view this site you must update your browser.");
				return false;
			} else {
				return http_handle;
			}
		}

		function getPageSize(){
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {  
					xScroll = window.innerWidth + window.scrollMaxX;
					yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
					xScroll = document.body.scrollWidth;
					yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
					xScroll = document.body.offsetWidth;
					yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) { // all except Explorer
					if(document.documentElement.clientWidth){
							windowWidth = document.documentElement.clientWidth; 
					} else {
							windowWidth = self.innerWidth;
					}
					windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
					windowWidth = document.documentElement.clientWidth;
					windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
					windowWidth = document.body.clientWidth;
					windowHeight = document.body.clientHeight;
			}       
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
					pageHeight = windowHeight;
			} else { 
					pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){      
					pageWidth = xScroll;            
			} else {
					pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight, document.body.scrollLeft, document.body.scrollTop) 
			return arrayPageSize;
		}

		function getPageScroll(){
			var xScroll, yScroll;

			if (self.pageYOffset) {
					yScroll = self.pageYOffset;
					xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){      // Explorer 6 Strict
					yScroll = document.documentElement.scrollTop;
					xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
					yScroll = document.body.scrollTop;
					xScroll = document.body.scrollLeft;     
			}

			arrayPageScroll = new Array(xScroll,yScroll) 
			return arrayPageScroll;
		}

