﻿// Resizes the paper background's height to fit variable text (content) size
function setHeight() {
 content_height = document.getElementById('content').offsetHeight;
 bground = document.getElementById('bg');
 md = document.getElementById('middle');
 
 if(content_height > 700) {		// 700px ir max content augstums, lai vel nebutu jastiepj garuma bg 
  new_bground_height = content_height + 110;
  new_md_height = content_height - 680;
  
  if(new_bground_height+"px" != bground.style.height) {
   bground.style.height = new_bground_height + "px";
   md.style.height = new_md_height + "px";
  }
 }
 window.setTimeout('setHeight()',1000);
}

// Shows/hides the contactinfo and changes the cursor to represent an clickable area
function revealContactinfo(show) {
 block = document.getElementById('blocknote');
 if(show == 1) {
  block.style.zIndex = "5";
  block.style.cursor = "default";
 } else {
  block.style.zIndex = "0";
  block.style.cursor = "pointer";
 }
}

// shows/hides the message layer
function revealMessage() {
 msg = document.getElementById('aploksne');
 // !msg.style.display - lai nebutu divreiz jaklikskina, jo 1. reizi uzsaucot si ipasiba vel neeksiste 
 if(msg.style.display == 'none' || !msg.style.display) {
  msg.style.display = 'block';
 } else {
  msg.style.display = 'none';
 }
 return false;
}

// parbauda nosutamas zinas saturu
function checkMessage() {
 email = document.forms['message'].email;
 text = document.forms['message'].text;
 i = 0;
 j = 0;
 error = "";
 
 if(email.value == "") {
  error += "Lūdzu ievadiet savu epasta adressi,\nlai būtu iespējams jums atbildēt!";
  i++;
  j = 1;
  email.focus();
 } 
 if(text.value == "") {
  if(i>0) { error += "\n\n"; }
  error += "Nav ievadīts nekāds ziņojuma teksts!"; 
  i++;
  text.focus();
 }
 
 // parbauda noradito epasta adresi
 pattern = /(^[a-zA-Z0-9\-\_]+(\.[a-zA-Z0-9\-\_]+)*\@[a-zA-Z0-9]+[a-zA-Z0-9\-]*[a-zA-Z0-9]+(\.[a-zA-Z0-9]+[a-zA-Z0-9\-]*[a-zA-Z0-9]+)*\.[a-zA-Z]{2,4}$)/;
 check = pattern.test(email.value);
 
 if(!check  && j==0) {
  if(i>0) { error += "\n\n"; }
  error += "Norādītā epasta adrese nav derīga!";
  i++;
  email.select(); 
 }
 
 if(i>0) {
  alert(error);
  return false;
 } else {
  return true;
 }
}

// parbauda nosutamas zinas saturu, izdod anglu val. pazinojumus
function checkMessageEN() {
 email = document.forms['message'].email;
 text = document.forms['message'].text;
 i = 0;
 j = 0;
 error = "";
 
 if(email.value == "") {
  error += "Please type in your e-mail, so we \ncan contact you!";
  i++;
  j = 1;
  email.focus();
 } 
 if(text.value == "") {
  if(i>0) { error += "\n\n"; }
  error += "You haven't written anything!"; 
  i++;
  text.focus();
 }
 
 // parbauda noradito epasta adresi
 pattern = /(^[a-zA-Z0-9\-\_]+(\.[a-zA-Z0-9\-\_]+)*\@[a-zA-Z0-9]+[a-zA-Z0-9\-]*[a-zA-Z0-9]+(\.[a-zA-Z0-9]+[a-zA-Z0-9\-]*[a-zA-Z0-9]+)*\.[a-zA-Z]{2,4}$)/;
 check = pattern.test(email.value);
 
 if(!check  && j==0) {
  if(i>0) { error += "\n\n"; }
  error += "It seems that the e-mail you provided \nisn't valid!";
  i++;
  email.select(); 
 }
 
 if(i>0) {
  alert(error);
  return false;
 } else {
  return true;
 }
}