<?php
if ($_GET ["lang"] == "en") {
	$title = "VeOn Solutions - Contact us";
	$description = "Do you have any questions for VeOn Solutions team? Our managers are more than happy to answer all of them.";
	$keywords = "VeOn Solutions,contact,contact details,questions,about the company,information technology";
	
	$txt_intro = "<H1>Do you have any questions for VeOn Solutions team?</H1>
		<p>Our managers are more than happy to answer all of them.<br />
		They know everything about the company. They know even more about information technologies.<br />
		They make complex things simple. They are always there to talk about business.<br />
		Do not hesitate to contact them!</p>";
	
	$txt_email_header = "Send a message to us:";
	$txt_email_name = "Name";
	$txt_email_email = "Email";
	$txt_email_message = "Message";
	$txt_email_send = "Send";

	$txt_company_header = "Our requisites:";
	$txt_company_name_txt = "Company name:";
	$txt_company_name = "VeOn Solutions LLC";
	$txt_company_number = "Registration Number:";
	$txt_company_vat = "VAT";
	$txt_company_bank = "Bankers:";

	$txt_error_msg = "Please, fill in all fields!";
	$txt_error_email_msg = "Wrong email address format!";
	$txt_error_email_send_msg = "Error! An email could not be sent! Please, try again.";
	$txt_success_msg = "Thank you, your request has been sent.";
	
} else if ($_GET ["lang"] == "ru") {
	$title = "VeOn Solutions - Контакт";
	$description = "Возникли вопросы к коллективу VeOn Solutions? Наши менеджеры работают для того, чтобы на них отвечать.";
	$keywords = "VeOn Solutions,контакт,реквизиты,вопросы,о компании,информационные технологии";
	
	$txt_intro = "<H1>Возникли вопросы к коллективу VeOn Solutions?</H1>
		<p>Наши менеджеры работают для того, чтобы на них отвечать.<br />
		Они знают все о компании, а еще больше — об информационных технологиях.<br />
		О сложном они говорят просто, но главное — всегда готовы к деловому диалогу.<br />
		В общем, они ждут вопросов от Вас!</p>";
	
	$txt_email_header = "Отправить нам сообщение:";
	$txt_email_name = "Имя";
	$txt_email_email = "Электронная почта";
	$txt_email_message = "Сообщение";
	$txt_email_send = "Отправить";
	
	$txt_company_header = "Наши реквизиты:";
	$txt_company_name_txt = "Название:";
	$txt_company_name = "OOO VeOn Solutions";
	$txt_company_number = "Регистрационный номер:";
	$txt_company_vat = "Номер НДС";
	$txt_company_bank = "Банковские реквизиты:";
	
	$txt_error_msg = "Пожалуйста, заполните все поля!";
	$txt_error_email_msg = "Неверный формат адреса электронной почты!";
	$txt_error_email_send_msg = "Ошибка! Письмо не было отправлено! Пожалуйста, попробуйте еще раз.";
	$txt_success_msg = "Спасибо, ваше сообщение было отправлено.";
	
} else if ($_GET ["lang"] == "ee") {
	$title = "VeOn Solutions - Kontakt";
	$description = "Tekisid küsimused VeOn Solutions’i meeskonnale? Meie haldurid töötavad selle nimel, et vastata teie küsimustele.";
	$keywords = "VeOn Solutions,kontakt,rekvisiidid,küsimused,ettevõttest,informatsioonitehnoloogiad";
	
	$txt_intro = "<H1>Tekisid küsimused VeOn Solutions’i meeskonnale?</H1>
		<p>Meie haldurid töötavad selle nimel, et vastata teie küsimustele.<br />
		Nemad teavad kõikke ettevõttest ja veelgi rohkem infotehnoloogiast.<br />
		Keerulisest räägivad nad lihtsas keeles ja on alati valmis asjalikuks dialoogiks.<br />
		Teie küsimused on teretulnud!</p>";
	
	$txt_email_header = "Saatke meile teade:";
	$txt_email_name = "Nimi";
	$txt_email_email = "E-post";
	$txt_email_message = "Teade";
	$txt_email_send = "Saada";
	
	$txt_company_header = "Meie rekvisiidid:";
	$txt_company_name_txt = "Nimetus:";
	$txt_company_name = "VeOn Solutions OÜ";
	$txt_company_number = "Reg. Nr.:";
	$txt_company_vat = "KMKR nr.:";
	$txt_company_bank = "Panga rekvisiidid:";
	
	$txt_error_msg = "Palun täitke kõik väljad!";
	$txt_error_email_msg = "E-posti aadress on vale kujul!";
	$txt_error_email_send_msg = "Viga! Kiri ei olnud saadetud! Palun proovige uuesti.";
	$txt_success_msg = "Täname, Teie kiri on saadetud.";
	
}else {
	header ( "Location: contact.php?lang=en" );
	exit ();
}

//Send mail
if ($_POST['send_mail']) {
	$email_name_val = $_POST["email_name"];
	$email_name_val = filter_var($email_name_val, FILTER_SANITIZE_STRING);
	$email_email_val = $_POST["email_email"];
	$email_email_val = filter_var($email_email_val, FILTER_SANITIZE_EMAIL);
	$email_message_val = $_POST["email_message"];
	$email_message_val = filter_var($email_message_val, FILTER_SANITIZE_STRING);
	$error_msg = '';
	$success_msg = '';
	
	$bg_name = ($email_name_val == "") ? "Pink" : "White";
	$bg_email = ($email_email_val == "") ? "Pink" : "White";
	$bg_message = ($email_message_val == "") ? "Pink" : "White";
	
	//Validate input
	if(($email_name_val == '') || ($email_email_val == '') || ($email_message_val == '')){
		$error_msg = $txt_error_msg; 
	}else{
		//Validate email
		if(check_email($_POST["email_email"])){
			$to      = 'info@veonsolutions.com';
			$subject = "New message from VeOn's site";
			$message = 'Name: '.$email_name_val.'<br/>Email: '.$email_email_val.'<br/>Message: '.$email_message_val;
			$headers = 'From: no-reply@veonsolutions.com'."\r\n" .
		    		   'Reply-To: no-reply@veonsolutions.com'."\r\n".
					   'MIME-Version: 1.0'."\r\n".
					   'Content-type: text/html; charset=UTF-8';
			if(mail($to, $subject, $message, $headers)){
				$success_msg = $txt_success_msg;
				$email_name_val = $email_email_val = $email_message_val = "";
			}else{
				$error_msg = $txt_error_email_send_msg;
			}
		}else{
			$error_msg = $txt_error_email_msg;
		}
	}
}

function check_email($email) {
  // First, we check that there's one @ symbol, 
  // and that the lengths are right.
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    return false;
  }
  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
    if(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&↪'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
      return false;
    }
  }
  // Check if domain is IP. If not, 
  // it should be valid domain name
  if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
        return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|↪([A-Za-z0-9]+))$",$domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<script type="text/javascript">
		function validateFormOnSubmit(theForm) {
			validateEmpty(theForm.email_name);
			validateEmpty(theForm.email_email);
			validateEmpty(theForm.email_message);
			validateEmail(theForm.email_email);
			return true;
		}
		
		function validateEmpty(fld) {
		    if (fld.value.length == 0) {
		        fld.style.background = 'Pink'; 
		    } else {
		        fld.style.background = 'White';
		    }   
		}
		
		function trim(s)
		{
		  return s.replace(/^\s+|\s+$/, '');
		} 
		
		function validateEmail(fld) {
		    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
		    var emailFilter = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})/;
		    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
		    
		    if (fld.value == "") {
		        fld.style.background = 'Pink';
		    } else if (!emailFilter.test(fld.value)) {
		        fld.style.background = 'Pink';
		    } else if (fld.value.match(illegalChars)) {
		        fld.style.background = 'Pink';
		    } else {
		        fld.style.background = 'White';
		    }
		}
		
		function onFocusOut(fld) {
			if (fld.value == "") {
		        fld.style.background = 'Pink';
		    }else if(fld.name == "email_email"){
		    	validateEmail(fld);
		    } 
		}
	</script>
	<head>
		<title><?php echo ($title);	?></title>
		<meta name="description" content="<?php	echo ($description); ?>" />
		<meta name="keywords" content="<?php echo ($keywords); ?>" />
		<?php include 'include/meta.php' ?>
	</head>
	<body id="inn">
		<div id="container">
			<div id="logo">
				<a href="index.php?lang=<?php echo ($_GET ["lang"]);?>" id="logo_link"><img src="/img/transparent.gif"></img></a>
				<div>
				<?php include 'include/header.php'; ?>
				</div>
			</div>	
			<?php include 'include/ie6nomore.php'; ?>
			<div id="top">
				<div>
					<div>
					<?php include 'include/menu.php'?>
					</div>
				</div>
			</div>
			<div id="main">
				<div id="main2">
					<?php echo($txt_intro); ?>
					<br />
					<table width="100%">
						<tr>
							<td valign="top" width="42%">
								<H3><?php echo($txt_email_header);?></H3>
								<div id="fform">
									<form action="contact.php?lang=<?php echo($_GET["lang"]); ?>" method="POST" name="formmessage" onsubmit="return validateFormOnSubmit(this)"><?php echo($txt_email_name);?><br />
										<input name="email_name" size="30" type="text" onfocus="this.style.background = 'White';" onblur="onFocusOut(this)" value="<?php echo($email_name_val); ?>" style="background-color: <?php echo($bg_name);?>" /><br />
										<?php echo($txt_email_email);?><br />
										<input name="email_email" size="30" type="text" onfocus="this.style.background = 'White';" onblur="onFocusOut(this)" value="<?php echo($email_email_val); ?>" style="background-color: <?php echo($bg_email);?>"/><br />
										<?php echo($txt_email_message);?><br />
										<textarea name="email_message" cols="23" rows="5" onfocus="this.style.background = 'White';" onblur="onFocusOut(this)" style="background-color: <?php echo($bg_message);?>"><?php echo($email_message_val); ?></textarea> <br />
										<?php 
											if($error_msg != ""){
												echo('<div id="error_msg">'.$error_msg.'</div>');
											}
											if($success_msg != ""){
												echo('<div id="success_msg">'.$success_msg.'</div>');
											}
										?>
										<input name="sid" type="hidden" value="'.$_SESSION['uid'].'">
										<input name="send_mail" value="<?php echo($txt_email_send);?>" type="submit" class="submit"/>
									</form>
								</div>
							</td>
							<td valign="top" width="58%">
								<H3><?php echo($txt_company_header);?></H3>
								<table style="padding-left: 2em;">
									<tr>
										<td><?php echo($txt_company_name_txt);?></td>
										<td style="padding-left: 1em;"><b><?php echo($txt_company_name);?></b></td>
									</tr>
									<tr>
										<td><?php echo($txt_company_number);?></td>
										<td style="padding-left: 1em;"><b>11653805</b></td>
									</tr>
									<tr>
										<td><?php echo($txt_company_vat);?></td>
										<td style="padding-left: 1em;"><b>EE101370422</b></td>
									</tr>
									<tr>
										<td valign="top"><?php echo($txt_company_bank);?></td>
										<td style="padding-left: 1em;">
											<b>IBAN: EE812200221048194401</b><br />
											SWEDBANK AS<br />
											SWIFT: HABA EE 2X<br />
											Liivalaia 8, 15040 Tallinn<br />
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
					<div class="mbot">
						<?php include 'include/menu.php'?>
					</div>
					<div id="bl"></div>
					<div id="bc"></div>
					<div id="br"></div>
				</div>
			</div>
			<div id="footer">
				<?php include 'include/copyright.php'?>
			</div>
		</div>
		<?php include 'include/google.php'?>
	</body>
</html>