//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////
 
var agt = navigator.userAgent.toLowerCase ();
var isMajor = parseInt (navigator.appVersion);
var isMinor = parseFloat (navigator.appVersion);

var isSafari = (agt.indexOf ("safari") != -1);

var isNav  = ((agt.indexOf ('mozilla') != -1) && (agt.indexOf ('spoofer') == -1) && (agt.indexOf ('compatible') == -1) && (agt.indexOf ('opera') == -1) && (agt.indexOf ('webtv') == -1) && (agt.indexOf ('hotjava') == -1) && (agt.indexOf ('safari') == -1));

var isNav2 = (isNav && (isMajor == 2));
var isNav3 = (isNav && (isMajor == 3));
var isNav4 = (isNav && (isMajor == 4));
var isNav4up = (isNav && (isMajor >= 4));
var isNavonly = (isNav && ((agt.indexOf (";nav") != -1) || (agt.indexOf ("; nav") != -1)));
var isNav6 = (isNav && (isMajor == 5) && (agt.indexOf("netscape") != -1) && (agt.indexOf ("netscape/7") == -1));
var isNav6up = ((isNav && (isMajor >= 5)) || (isNav && (agt.indexOf ('netscape/7') != -1)));
var isGecko = (agt.indexOf ('gecko') != -1);

var isIe     = ((agt.indexOf ("msie") != -1) && (agt.indexOf ("opera") == -1) && (agt.indexOf ("safari") == -1));
var isIe3    = (isIe && (isMajor < 4));
var isIe4    = (isIe && (isMajor == 4) && (agt.indexOf ("msie 4")!=-1) );
var isIe4up  = (isIe && (isMajor >= 4));
var isIe5    = (isIe && (isMajor == 4) && (agt.indexOf ("msie 5.0") != -1) );
var isIe55  = (isIe && (isMajor == 4) && (agt.indexOf ("msie 5.5") != -1));
var isIe5up  = (isIe && !isIe3 && !isIe4);
var isIe55up =(isIe && !isIe3 && !isIe4 && !isIe5);
var isIe6    = (isIe && (isMajor == 4) && (agt.indexOf ("msie 6.") != -1));
var isIe6up  = (isIe && !isIe3 && !isIe4 && !isIe5 && !isIe55 && !isSafari);
var isIeMac = ((agt.indexOf ("msie") != -1) && (agt.indexOf ("mac_") != -1));

var isOpera = (agt.indexOf ("opera") != -1);
var isOpera2 = (agt.indexOf ("opera 2") != -1 || agt.indexOf ("opera/2") != -1);
var isOpera3 = (agt.indexOf ("opera 3") != -1 || agt.indexOf("opera/3") != -1);
var isOpera4 = (agt.indexOf ("opera 4") != -1 || agt.indexOf("opera/4") != -1);
var isOpera5 = (agt.indexOf ("opera 5") != -1 || agt.indexOf("opera/5") != -1);
var isOpera5up = (isOpera && !isOpera2 && !isOpera3 && !isOpera4 && !isOpera5);
var isOpera7 = ((agt.indexOf ("opera/7.") != -1) || (agt.indexOf ("opera 7.") != -1));
var isOpera70 = (((agt.indexOf ("opera/7.0") != -1) || (agt.indexOf ("opera 7.0") != -1)) && !((agt.indexOf ("opera/7.03") != -1) || (agt.indexOf ("opera 7.03") != -1)));
var isOpera7up = (((agt.indexOf ("opera/7.") != -1) || (agt.indexOf ("opera 7.") != -1)) && !isOpera70);


//////////////////////////////////////////////////////////////////////////////
function openModel(o){
	openWindow ('model', o.href, 600, 700, 'status=no,resizable=0,scrollbars=yes');	
}

function $(id){
	return document.getElementById(id);
}

function checkMail(obj){
			var pat=/^[a-zA-Z][a-zA-Z\_\.\-\d]*@[a-zA-Z\_\.\-\d]+.[a-zA-Z]{2,4}$/;
			if(pat.test(obj.value)) return true;
				else return false;
		}
	
function checkFeedback(){
	if (document.feedback.fio.value=='' || document.feedback.email.value=='' || document.feedback.message.value=='' || document.feedback.number.value=='')
	{
		alert(Lang["fill_mandatory_fields"]);
		return false;
	} 
	if(!checkMail(document.feedback.email)) {
		alert(Lang["enter_valid_email"]);
		return false;
	}
	return true;
}


var oldOpenedFAQ = false;
var arrowDown = new Image(); arrowDown.src = "/webroot/delivery/pic/misc/icon-paging-down.gif";
var arrowUp = new Image(); arrowUp.src = "/webroot/delivery/pic/misc/icon-paging-up.gif";
var arrowNone = new Image(); arrowNone.src = "/webroot/delivery/pic/misc/x.gif";

function openFAQ(idN){
	if (oldOpenedFAQ) 
		if (idN==oldOpenedFAQ){
			closeFAQ(oldOpenedFAQ); 
			overFAQ(idN);
			return false;
		} else closeFAQ(oldOpenedFAQ);
	oldOpenedFAQ=idN;
	$("faq_arrow_"+idN).src=arrowUp.src;
	$("faq_question_"+idN).className="search-results-selected";
	$("faq_answer_"+idN).style.display="block";
}

function closeFAQ(idN){
	oldOpenedFAQ=false;
	$("faq_arrow_"+idN).src=arrowNone.src;
	$("faq_question_"+idN).className="";
	$("faq_answer_"+idN).style.display="none";
}

function overFAQ(idN){
	if (idN!=oldOpenedFAQ) {
		$("faq_arrow_"+idN).src=arrowDown.src;
	}
}

function outFAQ(idN){
	if (idN!=oldOpenedFAQ) {
		$("faq_arrow_"+idN).src=arrowNone.src;
	}
}

//////////////////////////////////////////////////////////////////////////////
 
 
 
function initStyles() 
{
	if (isIe55) document.body.className += (document.body.className.length > 0 ? ' ' : '') + 'browserIe55';
	if (isIe5up) document.body.className += (document.body.className.length > 0 ? ' ' : '') + 'browserIe5up';
	if (isOpera70) document.body.className += (document.body.className.length > 0 ? ' ' : '') + 'browserOpera70';
	if (isOpera7up) document.body.className += (document.body.className.length > 0 ? ' ' : '') + 'browserOpera7Up';
}




//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////
 
function getObj(idElement, parentObject) 
{
	var objElement;  

	if (!parentObject) 
		parentObject = document; 

	if (document.getElementById)
		objElement = parentObject.getElementById(idElement); 
	
	return objElement;
}


//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////

function genUID()
{
	return String(Math.floor(Math.random()*Math.pow(9, 19)) + Math.pow(10, 19));
}

 
//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////
 
function openWindow (windowName, sourceFile, width, height, attr)
{
	var left = Math.round ((screen.width - width) / 2);
	var top =  Math.round ((screen.height - height) / 2) - 35;

	var newAttr = '';
	if (attr.indexOf('status') < 0)     newAttr += 'status=yes,';
	if (attr.indexOf('menubar') < 0)    newAttr += 'menubar=no,';
	if (attr.indexOf('toolbar') < 0)    newAttr += 'toolbar=no,';
	if (attr.indexOf('resizable') < 0)  newAttr += 'resizable=yes,';
	if (attr.indexOf('scrollbars') < 0) newAttr += 'scrollbars=yes,';
	if (attr.indexOf('location') < 0)   newAttr += 'location=no,';
	newAttr += 'width='  + width;
	newAttr += ',height=' + height;
	newAttr += ',left='   + left;
	newAttr += ',top='    + top;

	var objectWindow = window.open (sourceFile, windowName, newAttr + ((attr != '')?','+attr:''));
	objectWindow.focus();

	return objectWindow;
}


//////////////////////////////////////////////////////////////////////////////
//
// Get/Set elements value
//
//////////////////////////////////////////////////////////////////////////////

function setSelectedOption(element, value)
{
	for (var i = 0; i < element.length; i++)
	{
		if (element.options[i].value == value)
		{
			element.options[i].selected = true;
		}
	}
}

function getElementValue(element)
{
	var objectElement;

	if (typeof(element) != 'object')
	{ 
		if (( objectElement = getObj(element) ) == null)
		{
			return false;
		}
	}
	else
	{
		objectElement = element;
	}

	if (objectElement.tagName == 'SELECT')
	{
		return objectElement.options[objectElement.options.selectedIndex].value;
	}

	if (objectElement.tagName == 'INPUT')
	{
		if (objectElement.type == 'checkbox')
		{
			return objectElement.checked;
		}
		else
		{
			return objectElement.value;
		}
	}

	return false;
}

function setElementValue(element, value)
{
	var objectElement;

	if (typeof(element) != 'object')
	{ 
		if (( objectElement = getObj(element) ) == null)
		{
			return false;
		}
	}
	else
	{
		objectElement = element;
	}

	if (objectElement.tagName == 'SELECT')
	{
		setSelectedOption(objectElement, value);

		return true;
	}

	if (objectElement.tagName == 'INPUT' ||
		objectElement.tagName == 'TEXTAREA')
	{
		objectElement.value = value;

		return true;
	}

	if (objectElement.innerHTML)
	{
		objectElement.innerHTML = value;
	}
	
	return false;
}


//////////////////////////////////////////////////////////////////////////////
//
//  hideElement
//
//////////////////////////////////////////////////////////////////////////////
function hideElement(element)
{
	var objectElement;

	if (typeof(element) != 'object')
	{ 
		if (( objectElement = getObj(element) ) == null)
		{
			return false;
		}
	}
	else
	{
		objectElement = element;
	}

	objectElement.style.display = 'none';
}


//////////////////////////////////////////////////////////////////////////////
//
//  showElement
//
//////////////////////////////////////////////////////////////////////////////
function showElement(element)
{
	var objectElement;

	if (typeof(element) != 'object')
	{ 
		if (( objectElement = getObj(element) ) == null)
		{
			return false;
		}
	}
	else
	{
		objectElement = element;
	}

	objectElement.style.display = '';
}


//////////////////////////////////////////////////////////////////////////////
//
//  disableElement
//
//////////////////////////////////////////////////////////////////////////////
function disableElement(element)
{
	var objectElement;

	if (typeof(element) != 'object')
	{ 
		if (( objectElement = getObj(element) ) == null)
		{
			return false;
		}
	}
	else
	{
		objectElement = element;
	}

	objectElement.disabled = true;
}


//////////////////////////////////////////////////////////////////////////////
//
//  enableElement
//
//////////////////////////////////////////////////////////////////////////////
function enableElement(element)
{
	var objectElement;

	if (typeof(element) != 'object')
	{ 
		if (( objectElement = getObj(element) ) == null)
		{
			return false;
		}
	}
	else
	{
		objectElement = element;
	}

	objectElement.disabled = false;
}


//////////////////////////////////////////////////////////////////////////////
//
//  isDisabledElement
//
//////////////////////////////////////////////////////////////////////////////
function isDisabledElement(element)
{
	var objectElement;

	if (typeof(element) != 'object')
	{ 
		if (( objectElement = getObj(element) ) == null)
		{
			return false;
		}
	}
	else
	{
		objectElement = element;
	}

	return objectElement.disabled;
}


//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////
 
function disableForm(idForm) 
{
	var objForm = getObj(idForm);

	if (objForm) 
	{
		for (var indexForm = 0; indexForm < objForm.elements.length; indexForm++) 
		{
			if (objForm.elements[indexForm].disabled != null)
			{
				objForm.elements[indexForm].disabled = true;
			}
		}
	}
}


//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////

function openPopup (obj)
{
	var url = obj.href;
	
	openWindow ('popup', url, 740, 540, '');
	
	return false;
}

function doSubcribe (idBlock, idElement)
{
	var objBlock = getObj (idBlock);
	var objElement = getObj (idElement);
	
	if (objBlock && objElement)
	{
		if (objBlock.className == 'menu-subscribe menu-subscribe-open')
		{
			objBlock.className = 'menu-subscribe menu-subscribe-close';
		}
		else
		{
			objBlock.className = 'menu-subscribe menu-subscribe-open';
			/* objElement.focus (); */
		}
	}
	
	return false;
}

function doFocusSearch (objElement)
{
	if (objElement.value == Lang["find"] || objElement.className == 'search-query')
	{
		objElement.className = 'search-query search-query-edited';
		objElement.value = '';
	}
	
	return false;
}

function doBlurSearch (objElement)
{
	if (objElement.value == '')
	{
		objElement.className = 'search-query';
		objElement.value = Lang["find"];
	}
	
	return false;
}

function doFocusEmail (objElement)
{
	if (objElement.value == Lang["your_emal"] || objElement.className == 'subscribe-field')
	{
		objElement.className = 'subscribe-field subscribe-field-edited';
		objElement.value = '';
	}
	
	return false;
}

function doBlurEmail (objElement)
{
	if (objElement.value == '')
	{
		objElement.className = 'subscribe-field';
		objElement.value = Lang["your_emal"];
	}
	
	return false;
}





