/* PRE VARS START */
var d=document;
var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera')  > -1);
var isIE = (!isOpera && ua.indexOf('msie') > -1);
/* PRE VARS END */

/* DOCUMENT SIZE FUNC START */
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 getClientWidth(){
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
/* DOCUMENT SIZE FUNC END */

/* SCREEN BLOCKER  STARTS */
function showScreenBlock(){
	d.getElementById('scr_block').style.display='block';
	d.getElementById('scr_block').style.height=getDocumentHeight()+'px';
	screenBlockerFadeIn();
}
function screenBlockerFadeIn(){
	var elem = document.getElementById('scr_block');
	if(isIE == false){ // ЕСЛИ НЕ БЫДЛОБРАУЗЕР
		var op = Number(elem.style.opacity);
		if(op <= 0.6){
			op+=0.15;
			elem.style.opacity=op;
			setTimeout(screenBlockerFadeIn,30);
		}
	}else{
		var alph = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
		var op=Number(alph.opacity);
		if(op <= 60){
			op = op+15;
			alph.opacity=op;
			setTimeout(screenBlockerFadeIn,30);
		}
	}

}

function screenBlockerFadeOut(){
	var elem = document.getElementById('scr_block');
	if(isIE == false){ // ЕСЛИ НЕ БЫДЛОБРАУЗЕР
		var op = Number(d.getElementById('scr_block').style.opacity);
		if(op > 0){
		op-=0.15;
		elem.style.opacity=op;
		setTimeout(screenBlockerFadeOut,30);
		}else{elem.style.display='none';}
	}else{
		var alph = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
		var op=Number(alph.opacity);
		if(op > 0){
		op-=15;
		alph.opacity=op;
		setTimeout(screenBlockerFadeOut,30);
		}else{elem.style.display='none';}
	}
}
/* SCREEN BLOCKER  ENDS */

/* COMMON STARTS */
function showPopup(w,h,tpos,makereq,ajaxurl,ajaxdata){
	showScreenBlock();
	setTimeout(function(){
		var lpos=(getClientWidth()-w)/2;
		d.getElementById('popupContainer').style.width=w+'px';
		if(h != 'auto'){d.getElementById('popupContainer').style.height=h+'px';}
		d.getElementById('popupContainer').style.display='block';
		d.getElementById('popupContainer').style.top=tpos+'px';
		d.getElementById('popupContainer').style.left=lpos+'px';
		if(makereq == true){
			postReq(ajaxurl, ajaxdata, 'popupContainer', 'popupContainer');
			}
	},200);
	}
	
function closePopup(){
	msgId=0;
	screenBlockerFadeOut();
	d.getElementById('popupContainer').style.display='none';
	}	
function tfFocus(id){
	document.getElementById(id).style.border='1px solid rgb(219,239,246)';
	document.getElementById(id).style.color='rgb(255,255,255)';
	}
function tfBlur(id){
	document.getElementById(id).style.border='1px solid rgb(169,224,244)';
	document.getElementById(id).style.color='rgb(169,224,244)';
	}
function isValidEmail(email, strict){
 if ( !strict ) email = email.replace(/^\s+|\s+$/g, '');
 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}
 
 function submitFeedbackMsg(){
	var errs=0;
	// Убираем красный цвет
	d.getElementById('senderName').style.border='1px solid rgb(169,224,244)';
	d.getElementById('senderEmail').style.border='1px solid rgb(169,224,244)';
	d.getElementById('subj').style.border='1px solid rgb(169,224,244)';
	d.getElementById('msg').style.border='1px solid rgb(169,224,244)';
	d.getElementById('pplcode').style.border='1px solid rgb(169,224,244)';
	// Убираем и обнуляем сообщение об ошибке
	d.getElementById('errMsg').innerHTML='';
	d.getElementById('errMsg').style.display='none';
	
	if(d.getElementById('senderName').value.length < 3){
		errs++;
		d.getElementById('senderName').style.border='1px solid rgb(192,53,133)';
		d.getElementById('errMsg').innerHTML='Поле "Ваше имя" заполнено неверно.<br />';
		}
	if(isValidEmail(d.getElementById('senderEmail').value, false) == false){
		errs++;
		d.getElementById('senderEmail').style.border='1px solid rgb(192,53,133)';
		d.getElementById('errMsg').innerHTML+='E-mail указан неверно.<br />';
		}
	if(d.getElementById('subj').value == ''){
		d.getElementById('subj').value='Без темы';
		}
	if(d.getElementById('msg').value.length < 20){
		errs++;
		d.getElementById('msg').style.border='1px solid rgb(192,53,133)';
		d.getElementById('errMsg').innerHTML+='Сообщение слишком короткое.<br />';
		}
	if(d.getElementById('pplcode').value.length < 4 || d.getElementById('pplcode').value.length > 5){
		errs++;
		d.getElementById('pplcode').style.border='1px solid rgb(192,53,133)';
		d.getElementById('errMsg').innerHTML+='Проверочный код введен неверно.<br />';
		}
	if(errs > 0){
		d.getElementById('errMsg').style.display='block';
	}else{
		postReq('http://'+host+'/engine/ajax/feedback.php', 'act=submit&name='+d.getElementById('senderName').value+'&email='+d.getElementById('senderEmail').value+'&subj='+d.getElementById('subj').value+'&msg='+d.getElementById('msg').value+'&captcha='+d.getElementById('pplcode').value, 'feedbackStatus', 'feedbackCont');
		}
	}
	
 function clearFeedbackMsg(){
	// Убираем красный цвет
	d.getElementById('senderName').style.border='1px solid rgb(169,224,244)';
	d.getElementById('senderEmail').style.border='1px solid rgb(169,224,244)';
	d.getElementById('subj').style.border='1px solid rgb(169,224,244)';
	d.getElementById('msg').style.border='1px solid rgb(169,224,244)';
	d.getElementById('pplcode').style.border='1px solid rgb(169,224,244)';
	// Убираем и обнуляем сообщение об ошибке
	d.getElementById('errMsg').innerHTML='';
	d.getElementById('errMsg').style.display='none';	
	// Очищаем поля
	d.getElementById('senderName').value='';
	d.getElementById('senderEmail').value='';
	d.getElementById('subj').value='';
	d.getElementById('msg').value='';
	d.getElementById('pplcode').value='';
	}
/* COMMON ENDS */	

/* AUTH FUNC START */
function keyPressed(keycode,ctrl_down){
if(keycode == '81' && ctrl_down == true){
showAuth();
}
}
function showAuth(){
	if(d.getElementById('scr_block').style.display == 'none'){
		showScreenBlock();
		setTimeout(function(){
		d.getElementById('auth_popup').style.display='block';
		d.getElementById('auth_popup').style.top=(getViewportHeight()-200)/2+'px';
		d.getElementById('auth_popup').style.left=(getClientWidth()-250)/2+'px';
		}, 200);
		}
	}
	
function hideAuth(){
	d.getElementById('auth_popup').style.display='none';
	screenBlockerFadeOut();
}	
/* AUTH FUNC END */





















	
