function a(){
	var url = window.location.href;
	var start = url.lastIndexOf('=')+1;
	var end = url.length;
	var siteId = url.slice(start, end);
	var img = document.getElementById(siteId);
	//alert(start + ' ,' + end + ' -> ' + siteId);
	try{
		img.style.borderBottom = '3px solid white';
	}
	catch(err){
		//alert(err);
		img = document.getElementById('yritys');
		img.style.borderBottom = '3px solid white';
	}
}

function mOver(id){
	var img = document.getElementById(id);
	img.src = "img/" +id+ "_over.gif";
}
function mOut(id){
	var img = document.getElementById(id);
	img.src = "img/" +id+ ".gif";
}

function startUpload(){
      document.getElementById('upload_process').style.visibility = 'visible';
      document.getElementById('upload_form').style.visibility = 'hidden';
      return true;
}

function stopUpload(success){
      var result = '';
	  
	  if (success == 1){
		document.getElementById('upload_process').style.visibility = 'hidden';		
		alert('Tiedosto on lähetetty onnistuneesti.');		
		location.reload(true);
	}
      else {
		alert('Tiedoston siirrossa tapahtui virhe.');	
      }
      document.getElementById('upload_process').style.visibility = 'hidden';
      document.getElementById('upload_form').style.visibility = 'visible'; 
			  
      return true;   
}

function stopUploadEng(success){
      var result = '';
	  
	  if (success == 1){
		document.getElementById('upload_process').style.visibility = 'hidden';		
		alert('File has been transfered succesfully.');		
		location.reload(true);
	}
      else {
		alert('An error occured during file transfer. File was not sent.');	
      }
      document.getElementById('upload_process').style.visibility = 'hidden';
      document.getElementById('upload_form').style.visibility = 'visible'; 
			  
      return true;   
}


function formValidator(){
	
	var company = document.getElementById('company');
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var uploadEmpty = document.getElementById('upload');
	var fileName = document.getElementById('upload');
	
	// Tarkastaa joka kohdan järjestyksessä
	if(notEmpty(company, "Yrityksen nimi on pakollinen tieto")){
		if(isAlphabet(company, "Yrityksen nimi saa sisältää vain kirjaimia")){
			if(notEmpty(name, "Nimi on pakollinen pakollinen tieto")){
				if(isAlphabet(name, "Nimi saa sisältää vain kirjaimia")){
					if(notEmpty(email, "Sähköpostiosoite on pakollinen tieto")){
						if(emailValidator(email, "Sähköpostiosoite ei ole oikeassa muodossa")){
							if(notEmpty(uploadEmpty, "Valitse lähetettävä tiedosto")){
								if(getFileParams(fileName, "Voit lähettää vain '.zip .pdf .tif .eps .sit' tiedostoja")){
									document.getElementById('upload_process').style.visibility = 'visible';
									document.getElementById('upload_form').style.visibility = 'hidden';
									return true;
								}	
							}
						}
					}
				}
			}
		}
	}
		
	return false;
	
}

function formValidatorEng(){
	
	var company = document.getElementById('company');
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var uploadEmpty = document.getElementById('upload');
	var fileName = document.getElementById('upload');
	
	// Tarkastaa joka kohdan järjestyksessä
	if(notEmpty(company, "Company name is required")){
		if(isAlphabet(company, "The company name can only contain letters")){
			if(notEmpty(name, "Name is required")){
				if(isAlphabet(name, "Name can only contain letters")){
					if(notEmpty(email, "Email address is required")){
						if(emailValidator(email, "Check the email address")){
							if(notEmpty(uploadEmpty, "Choose the file you want to transfer")){
								if(getFileParams(fileName, "File extensions which are allowed are '*.zip, *.pdf, *.tif, *.sit, and *.eps'")){
									document.getElementById('upload_process').style.visibility = 'visible';
									document.getElementById('upload_form').style.visibility = 'hidden';
									return true;
								}	
							}
						}
					}
				}
			}
		}
	}
		
	return false;
	
}

// Ei saa olla tyhjä
function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
	}
	return true;
}

// Vain aakkosia
function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-öA-Ö -]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
/*
function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

*/
// Sähköpostiosoitteen tarkastus
function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

// Tiedostopäätteen tarkastus
function getFileParams(elem, helperMsg){ 
	var re_text = /\.pdf|\.tif|\.zip|\.sit|\.eps/i;
    
    /* Checking file type */
    if (elem.value.search(re_text) == -1)
    {
        alert(helperMsg);
		elem.focus();
        return false;
    }
    return true;
}
