 var oImg = null;
 var oDiv = null;
 var oDiv1 = null;
 var fon = null;
 var xmlHttp = false;
 if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
				xmlHttp = new XMLHttpRequest();
 }  
 
  var ua = navigator.userAgent.toLowerCase();
  var isOpera = (ua.indexOf('opera')  > -1);
  var isIE = (!isOpera && ua.indexOf('msie') > -1);
  img_timer = 0;	
  opac_timer = 0;
  if (isIE )  {
	del=0;//delay
	}
	else {
		if (isOpera) {
			del = 30;
		}
		else {
			del = 30;
		}	
    }
  
  opac = 0.2;
  
  function getBodyScrollTop_ff()  
  {  
		return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);  
  }  
  function getBodyScrollLeft_ff()  
  {	  
    return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);  
  }
  
  function getWindowHeight() {
  var windowHeight=0;
  if (typeof(window.innerHeight)=='number') {
    windowHeight=window.innerHeight;
  }
  else {
    if (document.documentElement&&document.documentElement.clientHeight) {
      windowHeight=document.documentElement.clientHeight;
    }
    else {
      if (document.body&&document.body.clientHeight) {
        windowHeight=document.body.clientHeight;
      }
    }
  }
  return windowHeight;
 }

  
  function setElementOpacity(sElemId, nOpacity)
	{
		var opacityProp = getOpacityProperty();
		var elem = document.getElementById(sElemId);
		if (!elem || !opacityProp) return; // Если не существует элемент с указанным id или браузер не поддерживает ни один из известных функции способов управления прозрачностью
		if (opacityProp=="filter")  // Internet Exploder 5.5+
		{
			nOpacity *= 100;
			// Если уже установлена прозрачность, то меняем её через коллекцию filters, иначе добавляем прозрачность через style.filter
			var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
			if (oAlpha) oAlpha.opacity = nOpacity;
				else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")"; // Для того чтобы не затереть другие фильтры используем "+="
		}
		else // Другие браузеры
		elem.style[opacityProp] = nOpacity;
	}

function getOpacityProperty()
	{
	if (typeof document.body.style.opacity == 'string') // CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9)
		return 'opacity';
			else if (typeof document.body.style.MozOpacity == 'string') // Mozilla 1.6 и младше, Firefox 0.8  
				return 'MozOpacity';
					else if (typeof document.body.style.KhtmlOpacity == 'string') // Konqueror 3.1, Safari 1.1
						return 'KhtmlOpacity';
							else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) // Internet Exploder 5.5+
								return 'filter';
									return false; //нет прозрачности
	}

function getDocumentHeight() {
    return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, getViewportHeight());
}
 
function getViewportHeight() {
    return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight :document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}
 

function create_div(elem) {

	txt = elem.alt;
	a = elem.src.split('/');
	n=a.length;
	s=a[n-1].split('.');	
	n=s.length;
	new_url=s[n-2].substring(0,s[n-2].length-1);
	new_url=new_url+'.'+s[n-1];
	nn='';
	for ($i=0; $i<a.length-1; $i++) {
		nn=nn+a[$i]+'/';
	}
	new_url=nn+new_url;

	
	
	
	
	oImg = document.createElement('IMG');
	oImg.id='zImg';
	oImg.setAttribute("src", new_url);
		
	fon = document.createElement("DIV");
	fon.id='fon';
	fon.style.position="absolute";
    fon.style.top=0;
    fon.style.left=0;
    fon.style.background="#444450";
	fon.style.width=document.body.clientWidth;
    fon.style.height=getDocumentHeight();
	document.body.appendChild(fon);        
	setElementOpacity('fon',0.8);
	
	oDiv = document.createElement('DIV');
	oDiv.id = 'imgDiv';
	oDiv.style.padding=0;
	oDiv.style.borderStyle = 'none';
	oDiv.style.position='absolute';
	oDiv.style.backgroundColor='transparent';
	oDiv.style.left=0;
	
	oDiv1 = document.createElement('DIV');
	oDiv1.id = 'oDiv1';
	oDiv1.style.padding=0;
	oDiv1.style.borderStyle = 'none';
	oDiv1.style.position='absolute';
	oDiv1.style.backgroundColor='transparent';
	oDiv1.style.left=0;
	oDiv1.innerHTML = '<font style="font-family:Verdana; font-size:12pt; color:#FFFFFF">Загрузка</font> <a style="color:#FFFFFF; font-family:Verdana; font-size:12pt;" href="javascript:remove_div()">Отмена</>';
	div_url = location.href.split('/');
	
	if (div_url[div_url.length-1]=='index.html' || div_url[div_url.length-1]=='') {
		div_url="images/div/";
	}
	else {
		div_url="../images/div/";
	}
	
	oDiv.innerHTML = '<table cellpadding="0" cellspacing="0" style="background-color:transparent">' +
						'<tr>'+
							'<td background="'+div_url+'lu.gif" style="width:25px; height:20px;">' +
							'<td bgcolor="#FFFFFF" style="height:20px;">'+
							'<td background="'+div_url+'/ru.gif" style="width:25px; height:20px;">'+
						'<tr>'+
							'<td bgcolor="#FFFFFF" style="width:25px;">'+
							'<td name="target_td" id="target_td">'+
							'<td bgcolor="#FFFFFF" style="width:25px;">'+
						'<tr>'+
							'<td background="'+div_url+'ld.gif" style="width:25px; height:40px;">'+
							'<td bgcolor="#FFFFFF" style="height:40px; vertical-align:middle">'+
							'<div style="float:left; margin-bottom:5px; font-size:9pt;">'+txt+'</div>'+
							'<div style="float:right; margin-bottom:5px; font-size:9pt;"><a href="javascript:remove_div()">закрыть окно</a></div>'+
							'<td background="'+div_url+'rd.gif" style="width:24px; height:40px;">'+
					'</table>';
			
	
	//это поймут FireFox, Opera, Safari 
	if (document.addEventListener) {
		document.getElementById('fon').onclick=function () {remove_div()}	
	}		
	//это сработает в Explorerе 
	else 
		if (document.attachEvent) {
			document.getElementById ('fon').attachEvent ('onclick', function () {remove_div()},  false); 
		} 
		//ну а это - для всех прочих браузеров 
		else { 
			document.getElementById ('fon').onclick = function () {remove_div()}; 
		} 
	
	document.body.appendChild(oDiv1);
	oDiv1.style.top=getBodyScrollTop_ff() + getWindowHeight()/2 - document.getElementById('oDiv1').offsetHeight/2
	oDiv1.style.left=getBodyScrollLeft_ff() + screen.width / 2 - document.getElementById('oDiv1').offsetWidth/2;
	
	oImg.onload = function() {setPosition(oDiv,oImg)};
	oImg.setAttribute("src", new_url);
	
}

function setPosition(oDiv_loc,oImg_loc) {
	document.body.appendChild(oDiv_loc);
	remove_elem('oDiv1');
	document.getElementById('target_td').appendChild(oImg_loc);		
	setElementOpacity('imgDiv',opac);
	oDiv_loc.style.top=getBodyScrollTop_ff() + getWindowHeight()/2 - document.getElementById('imgDiv').offsetHeight/2
	oDiv_loc.style.left=getBodyScrollLeft_ff() + screen.width / 2 - document.getElementById('imgDiv').offsetWidth/2;
	img_timer= setTimeout ("inc_opac()");
}

function stop_time(timmer) {
	clearTimeout(timmer);
}
function remove_div () {
	//window.stop();
	if (document.getElementById('imgDiv')!=null) { remove_elem('imgDiv');}
	if (document.getElementById('fon')!=null) {remove_elem('fon');}
	if (document.getElementById('oDiv1')!=null) { remove_elem('oDiv1');}
	if (document.getElementById('zImg')!=null) { remove_elem('zImg');}
	oImg.onload = function() {};
	oDiv = null;
	fon = null;
	oDiv1 = null;
	oImg = null;	
}
function remove_elem(id_elem) {
        el=document.getElementById(id_elem);
        el.parentNode.removeChild(el);
     }
	 
function inc_opac () {
  if (opac < 0.8) {
 	opac+=0.1;
	setElementOpacity('imgDiv',opac);
	opac_timer = setTimeout("inc_opac()",del);	
  }
  else {
	setElementOpacity('imgDiv',1.0);
	stop_time(opac_timer);
  }
}

function trim (str) {
	return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

function send_func() {
	document.getElementById('butt').style.display='none';

	var user_fam = document.getElementById('user_fam').value;
	var user_nam = document.getElementById('user_nam').value;
	var user_otch = document.getElementById('user_otch').value;
	var user_mail = document.getElementById('user_mail').value;
	var user_mail1 = document.getElementById('user_mail1').value;
	var user_other = document.getElementById('user_other').value;
	var user_cap = document.getElementById('user_cap').value;
	var user_telephone = document.getElementById('user_telephone').value;

	user_fam=trim(user_fam);
	user_nam=trim(user_nam);
	user_otch=trim(user_otch);
	user_mail=trim(user_mail);
	user_mail1=trim(user_mail1);
	user_telephone=trim(user_telephone);
	
	var str = '';
	var str1 = '';
	var str2 = '';
	if (user_fam == '' || user_fam == null) { 
		str=str+'Фамилия, '
	}
	if (user_nam == '' || user_nam == null) { 
		str=str+'Имя, '
	}
	if (user_otch == '' || user_otch == null) { 
		str=str+'Отчество, '
	}
	if (user_mail == '' || user_mail == null) { 
		str=str+'E-mail, '
	}
	if (user_cap == '' || user_cap == null) {
		str=str+'Код с картинки'
	}
	if (user_mail != null && user_mail1 != null && user_mail != user_mail1) {
		str1='Введеный e-mail не совпадает с подтверждением'
	}
	
	if (str == '' && str1 == '') { 
		xmlHttp.open('POST', '../scripts/send_script.php', true);
		xmlHttp.onreadystatechange = updatePage;
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send('user_fam='+user_fam+'&user_nam='+user_nam+'&user_otch='+user_otch+'&user_mail='+user_mail+'&user_other='+user_other+'&user_telephone='+user_telephone+'&user_cap='+user_cap);
	}
	else {
		if (str != '') {
			str2='Обнаружены ошибки.'+"\n"+'Не заполнены поля: '+str+"\n";		
			
		}
		if (str1 != '') {
			str2=str2+str1; 
		}
		alert(str2);
		document.getElementById('butt').style.display='';
		tm=Math.floor(Math.random( ) * (9000+1))
		document.getElementById('capcha').setAttribute("src", "../asp/imaga.php?time="+tm);
	}
}


function updatePage() {
	if (xmlHttp.readyState == 4 && xmlHttp.status==200) {
		var response = xmlHttp.responseText //.split('|');		
		document.getElementById('butt').style.display='';
		if (response=='allright') {
			alert('Уважаемый посетитель, ваше письмо успешно отправлено');
			window.location.reload();
			
		} 
		else {
			if (response == 'nocapcha') {
				alert('Вы неверно ввели код с картинки');
				document.getElementById('butt').style.display='';
				tm=Math.floor(Math.random( ) * (9000+1));
				document.getElementById('capcha').setAttribute("src", "../asp/imaga.php?time="+tm);
			}
		}	
	}
}		

