function checkEmpty (val){
	if (val=="" || val.search(/[^\s]+/)==-1) {
		return false;
	}
	return true;
}

function RestoreColor()
	{
	document.MessageForm.name.style.background="#ffffff";	
	document.MessageForm.content.style.background="#ffffff";	
	document.MessageForm.contacts.style.background="#ffffff";	
	}

function SubmitMessage()
{
	sm=true;
	if (!checkEmpty(document.MessageForm.name.value)) 
		{
	document.MessageForm.name.style.background="#FF5059";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.contacts.value)) 
		{
	document.MessageForm.contacts.style.background="#FF5059";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.content.value)) 
		{
	document.MessageForm.content.style.background="#FF5059";
	sm=false;	
		}
	if (sm==true) {document.MessageForm.submit();}		
}

function ShowPhoto(path,width,height)
{
	int = document.getElementById('interlaced');
	int.style.height = document.documentElement.scrollHeight + 'px';
	int.style.visibility = 'visible';
	view = document.getElementById('ViewPhoto');
	vd = document.getElementById('Vdiv');
	foto = document.getElementById('Fotka');
	foto.innerHTML = '<img src="'+path+'" onclick="HidePhoto();">';
	view.style.width = width + 'px';
	vd.style.width = width + 'px';
	view.style.height = height + 30 + 'px';
	view.style.marginLeft = -Math.round(width/2) + 'px';
	view.style.marginTop = -Math.round(height/2) - 35 + document.documentElement.scrollTop + 'px';
	view.style.display = 'block';
}

function HidePhoto()
{
	view = document.getElementById('ViewPhoto');
	view.style.display = 'none';
	int = document.getElementById('interlaced');
	int.style.visibility = 'hidden';
}

var AnsOp; AnsOp = new Array();

function OpenAns(id)
{
	if (!AnsOp[id]) AnsOp[id] = 0;
	
	an = document.getElementById('a'+id);
	
	if (AnsOp[id]==0)
	{
		an.style.display = 'block';
		AnsOp[id]=1;
	} else
		{
			an.style.display = 'none';
			AnsOp[id]=0;
		}
}

	
function ChangeMet()
{
	document.getElementById('prob'+CurMet).style.display = 'none';
	document.getElementById('prob'+document.forma.metal.value).style.display = 'inline';
	CurMet = document.forma.metal.value;
}

function createHttpRequest() {

var httpRequest;
var browser = navigator.appName;

if (browser == "Microsoft Internet Explorer") {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else {
httpRequest = new XMLHttpRequest();
}

return httpRequest;
} 
	
var httpRq;
	
function ChangeCountry()
{
    httpRq=createHttpRequest();
    file = '/country_ajax.php?country='+document.forma.country.value+'&epoch='+document.forma.epoch.value;
    sendCountryRequest(file);
}

function ChangeEpoch()
{
    httpRx=createHttpRequest();
    file = '/epoch_ajax.php?country='+document.forma.country.value+'&epoch='+document.forma.epoch.value;
    sendEpochRequest(file);
}

function sendEpochRequest(file)
{
    httpRx.open('get',file);
    httpRx.onreadystatechange = ChangeEBoxes;
    httpRx.send(null);
}


function sendCountryRequest(file)
{
    httpRq.open('get',file);
    httpRq.onreadystatechange = ChangeBoxes;
    httpRq.send(null);
}

function ChangeEBoxes()
{
	
	txt = httpRx.responseText;
	x = txt.indexOf('+<select');
	txt1 = txt.substring(0,x);
	txt2 = txt.substring(x+1);

	document.getElementById('y1').innerHTML = txt1;
	document.getElementById('y2').innerHTML = txt2;
}


function ChangeBoxes()
{
	txt = httpRq.responseText;
	x = txt.indexOf('+<select');
	txt1 = txt.substring(0,x);
	txt2 = txt.substring(x+1);
	x = txt2.indexOf('+<select');
	txt22 = txt2.substring(0,x);
	txt3 = txt2.substring(x+1);
	txt2 = txt22;

	document.getElementById('time').innerHTML = txt1;
	document.getElementById('y1').style.width = document.getElementById('y1').offsetWidth + 'px';
	document.getElementById('y1').innerHTML = txt2;
	document.getElementById('y2').innerHTML = txt3;
}



function SetCnt()
{
	flag = true; x=0;
	while (flag==true)
	{
		if (document.getElementById('time'+x))
		{
			document.getElementById('time'+x).style.display = 'none';
		} else
			{
				flag = false;
			}			
		x++;	
	}
	document.getElementById('time'+document.forma.country.value).style.display = 'block';
}

function digo(id)
{
	inp = document.getElementById('bnum'+id);
	reg = /[À-ßà-ÿA-Za-z\]\[{};':",/ <>?\-=\\_.+|`~\!@#$%^\&*\(\)¹]/g;
	result = inp.value.replace(reg,'');
	if (result.substring(0,1)==0) result = result.substring(1,100);
	inp.value = result;
}

function DigOnly(id)
{
	eval ('setTimeout("digo('+id+');",100)');
}

function OpenSearch()
{
	if (document.getElementById('srform').style.display=='block') {document.getElementById('srform').style.display='none'; document.forma.opened.value = 0;} else {document.getElementById('srform').style.display = 'block'; document.forma.opened.value = 1;}
}


	