jsHover = function alpha() {
		var hEls = gebi("nav").getElementsByTagName("li");
		for (var i=0, len=hEls.length; i<len; i++) {
			hEls[i].onmouseover=function() { this.className+=" jshover"; }
			hEls[i].onmouseout=function() { this.className=this.className.replace(" jshover", ""); }
		}
	}
	if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1){ window.attachEvent("onload", jsHover);}

function gebi(id)
{
	return document.getElementById(id);
}

function createHttpRequest()
{
	var httpRequest=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5) try{httpRequest = new ActiveXObject("Msxml2.XMLHTTP");}
	catch(e){
	    try{httpRequest = new ActiveXObject("Microsoft.XMLHTTP");}
		catch (e){httpRequest = false;}
	}
	@end @*/
	if (!httpRequest && typeof XMLHttpRequest!='undefined') {
		try{httpRequest = new XMLHttpRequest();}
		catch(e){httpRequest=false;}
	}
	if (!httpRequest && window.createRequest) {
		try {httpRequest = window.createRequest();}
		catch (e){httpRequest=false;}
	}
    return httpRequest;
}


function bgbody() {
	return document.body.style.backgroundColor;
}

function searchsubmit() {
	httpRequest = new createHttpRequest();
	txtsource = document.find.txtsearch;
	if(txtsource.value.length > 2)
	{
		sendRequest(false);
	}
	return false;
}

function sendRequest(searchpage)
{
	els = document.find.txtsearch;
	if(searchpage)
	{
		var queryString = 'txtsearch=' + encodeURIComponent(els.value) + '&page=' + encodeURIComponent(searchpage) + '';
	}
	else
	{
		progresbar = gebi('sLoading');
		shadowblock = gebi('sBG');
		shadowblock.style.height = document.body.scrollHeight;
		shadowblock.style.width = document.body.scrollWidth;
		gebi('SearchContinue').style.display = 'block';
		var queryString = 'txtsearch=' + encodeURIComponent(els.value) + '';
	}
	httpRequest.open('post', '/search.php', true);
	httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	httpRequest.setRequestHeader("Content-length", queryString.length);
	httpRequest.setRequestHeader("Connection", "close");
	httpRequest.onreadystatechange = result;
	httpRequest.send(queryString);
}

function result()
{
	if (httpRequest.readyState == 4)
	{
		progresbar = gebi('sLoading');
		shadowblock = gebi('sBG');
		shadowblock.style.height = '100%';
		shadowblock.style.width = '100%';
		gebi('SearchContinue').style.display = 'none';
		gebi('rBlock').innerHTML = decodeURIComponent(httpRequest.responseText);
	}
}

function hideIt(id,all){
	for ( var i = 1; i <= all; i++) {
		if (i != id){
			gebi('faq' + i + '') ? gebi('faq' + i + '').style.display = 'none' : null;
		}
	}
	faqid = gebi('faq' + id + '');
	if(	faqid.style.display == 'none'){
		faqid.style.display = 'block';
	}else{
		faqid.style.display = 'none';
	}
}

function showlaws() {
	if((document.sibform.ulaw[0].checked == true) && (document.sibform.ulaw[1].checked == false)){
		gebi('divforlaw').style.display = 'block';
	}
	if((document.sibform.ulaw[1].checked == true) && (document.sibform.ulaw[0].checked == false)){
		gebi('divforlaw').style.display = 'none';
	}

}

function showservices() {
	if((document.sibform.uorder[0].checked == true) && (document.sibform.uorder[1].checked == false)){
		gebi('divforfavour').style.display = 'block';
		gebi('divforwares').style.display = 'none';
	}
	if((document.sibform.uorder[1].checked == true) && (document.sibform.uorder[0].checked == false)){
		gebi('divforfavour').style.display = 'none';
		gebi('divforwares').style.display = 'block';
	}
}

function oImgRefresh() {
	oImages = gebi('oImg');
	oImg = Math.random().toString().substr(2);
	oImages.src = '/templates/captcha.php?img='+ oImg +'';
	return false;
}

function valid(o,w)
{
	var err = 0;
	if (w == 'special') {
		var r={'special':/['`"~<|>^#$%&]/g};
		o.value = o.value.replace(r[w],'');
	}
	if (w == 'email') {
		 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,7})$/;
		 if(reg.test(o.value) == false) {
			 o.style.border = '1px solid red';
			 err += 1;
		 }else {
			 o.style.border = '1px solid #c9c9c9';
		 }
	}
	if (w == 'password') {
		 if((o.value.length < 4) || (o.value.length > 35)) {
			 o.style.border = '1px solid red';
			 err += 1;
		 }else {
			 o.style.border = '1px solid #c9c9c9';
		 }
	}
	if(err == 0)
	{
		gebi('nbfield').style.display = 'none';
	}
	return err;
}

function checkItem(itemId) {
	var err = 0;
	var itemtocheck = gebi(itemId);
	valid(itemtocheck,'special');
	if(itemtocheck.value.length < 1) {
		err += 1;
		itemtocheck.style.border = '1px solid red';
	} else {
		itemtocheck.value = itemtocheck.value;
		itemtocheck.style.border = '1px solid #c9c9c9';
	}
	if(err == 0)
	{
		gebi('nbfield').style.display = 'none';
	}
	return err;
}

function faqsubmit() {
	var err = 0;
	err += checkItem('qname');
	err += valid(gebi('qemail'),'email');
	err += checkItem('question');
	err += gebi('securityCode') ? checkItem('securityCode') : 0; 
	if(err > 0)
	{
		gebi('nbfield').style.display = 'block';
	}else 
	{
		gebi('nbfield').style.display = 'none';
		document.sibform.submit();
	}
	return false;
}

function ordersubmit() {
	var err = 0;
	err += valid(gebi('email'),'email');
	err += checkItem('name');
	err += checkItem('uphone');
	err += checkItem('ucity');
	//err += checkItem('textcoment');
	err += gebi('securityCode') ? checkItem('securityCode') : 0;
	if((document.sibform.ulaw[0].checked == true) && (document.sibform.ulaw[1].checked == false)) {
		err += checkItem('uinn');
		err += checkItem('ufirm');
	}
	if(err > 0)
	{
		gebi('nbfield').style.display = 'block';
	}else 
	{
		gebi('nbfield').style.display = 'none';
		document.sibform.submit();
	}
	return false;
}
function usersubmit() {
	var err = 0;
	err += checkItem('login');
	err += valid(gebi('password'),'password');
	err += valid(gebi('email'),'email');
	err += checkItem('name');
	err += checkItem('uphone');
	err += checkItem('ucity');
	err += gebi('securityCode') ? checkItem('securityCode') : 0; 
	if((document.sibform.ulaw[0].checked == true) && (document.sibform.ulaw[1].checked == false)) {
		err += checkItem('uinn');
		err += checkItem('ufirm');
	} 
	if(err > 0)
	{
		gebi('nbfield').style.display = 'block';
	}else 
	{
		gebi('nbfield').style.display = 'none';
		document.sibform.submit();
	}
	return false;
}

function loginsubmit() {
	var err = 0;
	err += checkItem('login');
	err += checkItem('password');
	if(err > 0)
	{
		gebi('nbfield').style.display = 'block';
	}else 
	{
		gebi('nbfield').style.display = 'none';
		document.sibform.submit();
	}
	return false;
}

function userlogout() {
	outform = document.sibformlogout ? document.sibformlogout : document.sibform;
	outform.submit();
	return false;
}

function addfile(i){
	if (i < 5){
		if (i == 4)
		{
			gebi('Attachment' + i + '').innerHTML = '<div class="biginput"><div class="attacment"><input type="file" name="attachfile[]" id="attachfile' + i + '" /></div><a id="delatt' + i +'" class="attachbutton" href="" title="Удалить дополнительное поле для файла" onclick="delfile(' + i +'); return false;"><img src="/templates/images/button_del.gif" alt="Удалить дополнительное поле для файла"/></a></div><div class="biglabel"><label for="attachfile' + i +'"></label></div><div class="clear"></div>';
			gebi('addatt' + (i-1) + '').style.display = 'none';
			gebi('delatt' + (i-1) + '').style.display = 'none';
			gebi('Attachment' + i + '').style.display = 'block';
		}
		else
		{
			gebi('Attachment' + i + '').innerHTML = '<div class="biginput"><div class="attacment"><input type="file" name="attachfile[]" id="attachfile' + i + '" /></div><a id="addatt' + i +'" class="attachbutton" href="" title="Добавить дополнительное поле для файла" onclick="addfile(' + (i+1) +'); return false;"><img src="/templates/images/button_add.gif" alt="Добавить дополнительное поле для файла"/></a><a id="delatt' + i +'" class="attachbutton" href="" title="Удалить дополнительное поле для файла" onclick="delfile(' + i +'); return false;"><img src="/templates/images/button_del.gif" alt="Удалить дополнительное поле для файла"/></a></div><div class="biglabel"><label for="attachfile' + i +'"></label></div><div class="clear"></div>';
			gebi('Attachment' + i + '').style.display = 'block';
			if(i == 1)
			{
				gebi('addatt' + (i-1) + '').style.display = 'none';
			}
			else
			{
				gebi('addatt' + (i-1) + '').style.display = 'none';
				gebi('delatt' + (i-1) + '').style.display = 'none';				
			}
		}
	}
}

function delfile(i){
	if ((i < 5)){
		if (i == 1)
		{
			gebi('Attachment' + i + '').style.display = 'none';
			gebi('Attachment' + i + '').innerHTML = '';
			gebi('addatt' + (i-1) + '').style.display = 'block';
		}
		else
		{
			gebi('Attachment' + i + '').style.display = 'none';
			gebi('Attachment' + i + '').innerHTML = '';
			gebi('addatt' + (i-1) + '').style.display = 'block';
			gebi('delatt' + (i-1) + '').style.display = 'block';				

		}
	}
}
