//tyyliluokan vaihto lennossa
function setClass(el,luokka){
	document.getElementById(el).className=luokka;
}

//kuvaurlin vaihto (mm. nappien efektit)
function imgSrc(el,url){
	document.getElementById(el).src = url;
}

//tarkistetaan kirjautuminen
function checkLoginFields(){
	
	if(document.loginform.lemail.value=="" && document.loginform.lpass.value==""){
		alert("Tunnus ja salasana on pakollinen");
		return false;
	}
	return true;
}

//haku
function search(){
	
	var haku = document.getElementById('haku').value;
	if(haku.length>1){
		window.location = "http://www.ainagroup.fi/haku/"+haku;
	}
	else{
		alert("Syötä vähintään kaksi merkkiä");
		document.getElementById('haku_fix').focus();
	}
}

//google-maps ajo-ohjeissa
function valitseKaupunki(value){

	window.location = 'http://www.ainagroup.fi/'+value;
}
	
//HAKU: haetaan vaihtoehdot etusivulla
function lookup(inputString) {
 	
	if(inputString.length < 2) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	}else{
		$.post("http://www.ainagroup.fi/sivu_haku.php", {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
}

//HAKU: valitaan vaihtoehto	
function fill(thisValue) {
	$('#haku_fix').val(thisValue);
	$('#haku').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}

//HAKU: purkka kun ei muuten meinaa toimia ääkköset
function fillIt(thisValue){
	document.getElementById("haku_fix").value = document.getElementById("val"+thisValue).value;
	document.getElementById("haku").value = document.getElementById("val"+thisValue).value;

	var hakusana 	= document.getElementById("haku_fix").value;
	window.location = "haku/"+hakusana;
}

//mene jonnekin ainan sivulle
function goToPage(value){

	window.location = 'http://www.ainagroup.fi/'+value;
}

//HAKU: syötetään hakuarvo piilokenttään
function updateValue(thisValue){
	document.getElementById("haku").value = thisValue;
}

	//onko elementti olemassa
	function checkobject(obj) {
		if (document.getElementById(obj)) { return true; } else { return false; }
	}
	
	//alasivujen näyttäminen ja piiloitus
	function showSubMenu(el){
		
		var open_submenu = document.getElementById("open_submenu").value;
		var display = "block";
		var img_url = "minus";
		
		if(document.getElementById(el).style.display=="block"){
			var display = "none";
			var img_url = "plus";
		}
		
		if(display=="block" && open_submenu!="" && checkobject(open_submenu)){
			
			document.getElementById(open_submenu).style.display="none";
			//$("#top_"+open_submenu+"").css('font-weight', 'normal');
			//$("#top_"+open_submenu+" b").css('font-weight', 'normal');
			//$("#top_"+open_submenu+" a").css('font-weight', 'normal');
			document.getElementById(open_submenu+"_img").src = 'http://www.ainagroup.fi/admin/fckeditor/plus2.gif';
		}

		if(display=="block" && open_submenu!="" && checkobject("top_"+open_submenu)){
			$("#top_"+open_submenu+"").css('font-weight', 'normal');
			$("#top_"+open_submenu+" b").css('font-weight', 'normal');
			$("#top_"+open_submenu+" a").css('font-weight', 'normal');
		}

		//IE-PURKKA
		if(document.all){ document.getElementById(el).style.display=""+display+""; }
		else{ $('#'+el+'').slideToggle("normal"); }

		document.getElementById("open_submenu").value = el;
		$("#top_"+el+"").css('font-weight', 'bold');
		$("#top_"+el+" b").css('font-weight', 'bold');
		$("#top_"+el+" a").css('font-weight', 'bold');
		document.getElementById(el+"_img").src = 'http://www.ainagroup.fi/admin/fckeditor/'+img_url+'2.gif';
	}

//näytetään soittopyyntö -lomake
function showForm(){
	
	$("#yht_otto_tausta").css('zIndex', 990);
	document.getElementById('yht_otto_tausta').style.display='block';
	document.getElementById('yht_otto').style.display='block';
}

//näytetään soittopyyntö -lomake
function hideForm(){
	
	document.getElementById('yht_otto_tausta').style.display='none';
	document.getElementById('yht_otto').style.display='none';
}

function hideForms(){
	if($('#yht_otto_tausta').length==1){ document.getElementById("yht_otto_tausta").style.display="none"; }
	if($('#yht_otto_tausta3').length==1){ document.getElementById("yht_otto_tausta3").style.display="none"; }
	return;
}

function hideFormById(id){
	document.getElementById(el).style.display="none";
}
	
window.onload=hideForms;

//tarkistetaan yhteydenottolomakkeiden täytettyjä tietoja
function formCheck()
{
	//peruskenttien tarkistus
	if(document.lomake.Nimi.value=="")
	{
		alert("Nimi on pakollinen");
		document.lomake.Nimi.focus();
		return false;
	}
	else if(document.lomake.Puhelinnumero.value=="")
	{
		alert("Puhelinnumero on pakollinen");
		document.lomake.Puhelinnumero.focus();
		return false;
	}
	else if(document.lomake.Sähköpostiosoite.value=="")
	{
		alert("Sähköpostiosoite on pakollinen");
		document.lomake.Sähköpostiosoite.focus();
		return false;
	}
	else if(document.lomake.Asia.value=="")
	{
		alert("Asia on pakollinen");
		document.lomake.Asia.focus();
		return false;
	}
	
	if($('#contact').length==1)
	{
		if(document.getElementById("contact").checked && !document.lomake.Sahkopostilla.checked && !document.lomake.Puhelimella.checked)
		{
			alert("Valitse vähintään toinen yhteydenottomuodoista: sähköposti tai puhelin");
			return false;
		}
	}

	return true;
}

//näytetään soittopyyntö -lomake
function showOrderForm(){
	
	$("#yht_otto_tausta3").css('zIndex', 990);
	document.getElementById('yht_otto_tausta3').style.display='block';
	document.getElementById('yht_otto3').style.display='block';
}

//näytetään soittopyyntö -lomake
function hideOrderForm(){
	
	document.getElementById('yht_otto_tausta3').style.display='none';
	document.getElementById('yht_otto3').style.display='none';
}
