////////////////////////////////////////////////////

function setElementOpacity(oElem, nOpacity)
{
	var p = getOpacityProperty();
	(setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;	var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
	return false;
}

function getOpacityProperty()
{
	var p;
	if (typeof document.body.style.opacity == 'string') p = 'opacity';
	else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
	else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
	else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';
	
	return (getOpacityProperty = new Function("return '"+p+"';"))();
}

function fadeOpacity(sElemId, sRuleName, bBackward)
{
	var elem = document.getElementById(sElemId);
	if (!elem || !getOpacityProperty() || !fadeOpacity.aRules[sRuleName]) return;
	
	var rule = fadeOpacity.aRules[sRuleName];
	var nOpacity = rule.nStartOpacity;
	
	if (fadeOpacity.aProc[sElemId]) {clearInterval(fadeOpacity.aProc[sElemId].tId); nOpacity = fadeOpacity.aProc[sElemId].nOpacity;}
	if ((nOpacity==rule.nStartOpacity && bBackward) || (nOpacity==rule.nFinishOpacity && !bBackward)) return;

	fadeOpacity.aProc[sElemId] = {'nOpacity':nOpacity, 'tId':setInterval('fadeOpacity.run("'+sElemId+'")', fadeOpacity.aRules[sRuleName].nDalay), 'sRuleName':sRuleName, 'bBackward':Boolean(bBackward)};
}

fadeOpacity.addRule = function(sRuleName, nStartOpacity, nFinishOpacity, nDalay){fadeOpacity.aRules[sRuleName]={'nStartOpacity':nStartOpacity, 'nFinishOpacity':nFinishOpacity, 'nDalay':(nDalay || 30),'nDSign':(nFinishOpacity-nStartOpacity > 0?1:-1)};};

fadeOpacity.back = function(sElemId){fadeOpacity(sElemId,fadeOpacity.aProc[sElemId].sRuleName,true);};

fadeOpacity.run = function(sElemId)
{
	var proc = fadeOpacity.aProc[sElemId];
	var rule = fadeOpacity.aRules[proc.sRuleName];
	
	proc.nOpacity = Math.round(( proc.nOpacity + .1*rule.nDSign*(proc.bBackward?-1:1) )*10)/10;
	setElementOpacity(document.getElementById(sElemId), proc.nOpacity);
	
	if (proc.nOpacity==rule.nStartOpacity || proc.nOpacity==rule.nFinishOpacity) 
	{		
		clearInterval(fadeOpacity.aProc[sElemId].tId);
		if (proc.bBackward) document.getElementById ('questionForm').style.display = 'none';
	}
}
fadeOpacity.aProc = {};
fadeOpacity.aRules = {};

fadeOpacity.addRule('show_question_form', 0, 1, 50);

////////////////////////////////////////////////////

function ShowQuestionForm ()
{
	setTimeout (ShowQuestionForm_Continue, 1);
	return false;
}

function ShowQuestionForm_Continue ()
{
	var canvas = document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];
	var n = canvas.clientWidth - (document.getElementById ('right_banners').offsetLeft + 13 + document.getElementById ('rbanner').offsetWidth);
	if (ie || (window.innerWidth != canvas.clientWidth)) n -= 6;	
	else n -= 15;
	if (ie) n += 2;
	if (ie6 && canvas.scrollLeft) n += (canvas.scrollLeft + 4);
	else 
	{
		if (!canvas.scrollLeft && n < 0) n = 0;
		else if (canvas.scrollLeft) n += 6;
	}
	document.getElementById ('questionForm').style.right = n + 'px';
	document.getElementById ('questionForm').style.display = '';
	fadeOpacity ('questionForm', 'show_question_form');
}

function HideQuestionForm2 ()
{
	document.getElementById ('questionForm').style.display = 'none';
	document.getElementById ("questionFormError").innerHTML = '';
	document.frmQuestion.reset ();
	setTimeout (HideQuestionForm_Continue, 1);
	return false;
}

function HideQuestionForm ()
{
	document.getElementById ("questionFormError").innerHTML = '';
	document.frmQuestion.reset ();
	setTimeout (HideQuestionForm_Continue, 1);
	return false;
}

function HideQuestionForm_Continue ()
{	
	fadeOpacity ('questionForm', 'show_question_form', true);
}

var randCounter = 0;
function RefreshCaptcha (rand)
{
	document.getElementById ('captcha').src = 'captcha.php?' + rand + randCounter;
	document.frmQuestion.elements['captcha'].value = '';
	randCounter++;
	return false;
}

var randCounter2 = 0;
function RefreshCaptcha2 (rand)
{
	document.getElementById ('captcha2').src = 'captcha2.php?' + rand + randCounter2;
	document.frmOrder.elements['captcha2'].value = '';
	randCounter2++;
	return false;
}

function AskQuestion ()
{
	var req = new JsHttpRequest();
    // Code automatically called on load finishing.	
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            // Write result to page element ($_RESULT become responseJS). 
			RefreshCaptcha ('');
            document.getElementById ("questionFormError").innerHTML = req.responseJS.msg;
        }
    }	
    // Prepare request object (automatically choose GET or POST).
    req.open(null, 'ajax/on_ask_question.php', true);
    // Send data to backend.
	req.send( { 
		name: document.frmQuestion.elements['name'].value,
		email: document.frmQuestion.elements['email'].value,
		subject: document.frmQuestion.elements['subject'].value,
		question: document.frmQuestion.elements['question'].value,
		//city: document.frmQuestion.elements['city'].options[document.frmQuestion.elements['city'].selectedIndex].value,
		other_city: document.frmQuestion.elements['other_city'].value,
		professional: document.frmQuestion.elements['professional'].options[document.frmQuestion.elements['professional'].selectedIndex].value,
		captcha: document.frmQuestion.elements['captcha'].value
		} );		
	
	return false;
	
}

window.onresize = HideQuestionForm2;


function ShowAboutPravisSubmenu ()
{
	document.getElementById ('about_pravis_submenu').style.display = '';
}

function HideAboutPravisSubmenu ()
{
	document.getElementById ('about_pravis_submenu').style.display = 'none';
}

