// JavaScript Document


function isValidEmail(str) {
	if (str.indexOf("..") >= 0){return false;}
	return (str.indexOf(".") > 0) && (str.lastIndexOf(".") > str.indexOf("@")) && (str.indexOf("@") >= 1) && (str.indexOf("@") < str.length -3) && (str.lastIndexOf(".") < str.length -2);
}

function isEnter(e) {
    var charCode;
    
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }
	 if(charCode == 13) {
        return true;
    }else {
		return false;}
}

// Show floating image by Ilya Titov for clifton hotel
//get scroll position


function showIt(picLink, picTitle, picHeight, picWidth, orderId){
	var y;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;
	if (orderId == 0 || !orderId){orderId = 1;}
	if (picLink == 0 || !picLink){picLink = galleryPicLink[orderId];}
	if (picTitle == 0 || !picTitle){picTitle = 'Click to close';}
	if (picHeight == 0 || !picHeight){picHeight = galleryPicHeight[orderId];}
	if (picWidth == 0 || !picWidth){picWidth = galleryPicWidth[orderId];}
	if (test1 > test2) // all but Explorer Mac
	{
		y = document.body.scrollHeight;
	}
	else // Explorer Mac;
		 //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		y = document.body.offsetHeight;
	}
	
	var f = document.getElementById("fill");
	f.style.top = 0+"px";
	f.style.height = (y+40)+"px";
	
	var scrollTop = document.body.scrollTop;
	if (scrollTop == 0){
		if (window.pageYOffset){
			scrollTop = window.pageYOffset;
		}else {
			scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
	}
	//visible area
	 var winW;
	 var winH;
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  winW = window.innerWidth,
		  winH = window.innerHeight
	 }else if (typeof document.documentElement != 'undefined'// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   winW = document.documentElement.clientWidth,
		   winH = document.documentElement.clientHeight
	 }else {// older versions of IE
		   winW = document.getElementsByTagName('body')[0].clientWidth,
		   winH = document.getElementsByTagName('body')[0].clientHeight
	 }
	

	
	
	var e = document.getElementById("floatingPic");
	e.style.top = (scrollTop+((winH)/2)-((picHeight+20)/2))+'px';
	e.style.marginLeft = "-"+((picWidth+20)/2)+"px";
	e.innerHTML = '<img src="'+picLink+'" alt="'+picTitle+'" /><br /><!--span style=\"position:absolute; margin-top:10px; color:#ddd; font-size:.8em; background-color:#707070; margin-left:-10px; padding:.3em 1em .3em 10px; \">This photograph is&nbsp;protected by&nbsp;copyright and&nbsp;can&nbsp;not be&nbsp;used without written permission.</span -->';
	
	var le = document.getElementById("floatingLeft");
	//alert(orderId);
	if (orderId>1){
		le.style.top = scrollTop+'px';
		le.style.height = winH+'px';
		le.style.width = 50+'px';
		le.style.left = 0+'px';
		le.onclick =function(){showIt(galleryPicLink[orderId-1], picTitle, galleryPicHeight[orderId-1],galleryPicWidth[orderId-1], orderId-1);}
		document.getElementById('preload1').src = galleryPicLink[orderId-1];
	}else {
		le.style.top = '-2000px';
	}
	
	
	var re = document.getElementById("floatingRight");
	if (orderId < galleryTotal){
		re.style.top = scrollTop+'px';
		re.style.height = winH+'px';
		re.style.width = 50+'px';
		re.style.right = 0+'px';
		re.onclick =function(){showIt(galleryPicLink[orderId+1], picTitle, galleryPicHeight[orderId+1],galleryPicWidth[orderId+1], orderId+1);}
		document.getElementById('preload2').src = galleryPicLink[orderId+1];
	}else {
		re.style.top = '-2000px';
	}

}
function hideIt(){
	var e = document.getElementById("floatingPic");
	e.style.top = "-2000px";
	var f = document.getElementById("fill");
	f.style.top = "-2000px";
	f.style.height = "1px";
	var le = document.getElementById("floatingLeft");
	le.style.top = "-2000px";

	var re = document.getElementById("floatingRight");
	re.style.top = "-2000px";

	
	document.getElementById('projectsmap').style.visibility = 'hidden';
}

function showMap(){
	var pm = document.getElementById('projectsmap')	
		var y;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;
	if (test1 > test2) // all but Explorer Mac
	{
		y = document.body.scrollHeight;
	}
	else // Explorer Mac;
		 //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		y = document.body.offsetHeight;
	}
	
	var f = document.getElementById("fill");
	f.style.top = 0+"px";
	f.style.height = y+"px";
	
	pm.style.visibility = 'visible';
}
function subscribe(){
	document.getElementById('interactive').innerHTML = '<div style="width:400px; border:3px solid #a99a6f; background-color:#333; padding:25px; position:absolute; top:0px; left:50%; margin-left:-225px;"><a href=""  onclick="this.parentNode.parentNode.innerHTML = \'\'; return false;" style="float:right; font-size:.8em;">Close</a> <form action="/" onsubmit="if(validateSubscribe()==false){return false;}" method="post"> <h3 style="padding:0px; margin:0px;">Subscribe to news</h3> <small>*All fields with a star are mandatory.<br /></small><br /> <table cellpadding="3" cellspacing="0" border="0"> 	<tr>   	<td>Name* </td>     <td><input style="width:200px;" type="text" name="name" id="subscribe_name" /></td>   </tr>   <tr>   	<td>Company </td>     <td><input type="text" name="company" id="subscribe_company" /></td>   </tr>   <tr>   	<td>Profession </td>     <td><input type="text" name="profession" /></td>   </tr>   <tr>   	<td>Email* </td>     <td><input type="text" style="width:250px;" name="subscribe" id="subscribe_email" /></td>   </tr> </table> <input type="submit" value="Subscribe" style="width:100px; height:30px; float:right; margin:10px;" /> </form></div>';
}
function validateContact(){
	var flag = 1;
	var errors = '';
	if (isValidEmail(document.getElementById('contact_email').value) == false){flag = 0; errors = errors+'Invalid email address entered.\n\r'}	
if (document.getElementById('contact_name').value.length < 3 || document.getElementById('contact_name').value.length > 40){flag=0;  errors = errors+'Name length is inadequate.\n\r'}
if (document.getElementById('contact_company').value.length < 3 || document.getElementById('contact_company').value.length > 75){flag=0;  errors = errors+'Company name length is inadequate.\n\r'}
var ttext = document.getElementById('contact_message').value;
if (ttext.length < 3 || ttext.length > 6000){flag=0;  errors = errors+'Message length is inadequate.\n\r'}	
	if (flag==0){alert(errors); return false;}
	return true;
}
function validateSubscribe(){
	var flag = 1;
	var errors = '';
	if (isValidEmail(document.getElementById('subscribe_email').value) == false){flag = 0; errors = errors+'Invalid email address entered.\n\r'}	
	if (document.getElementById('subscribe_name').value.length < 3 || document.getElementById('subscribe_name').value.length > 40){flag=0;  errors = errors+'Name entered is too short or too long.\n\r'}
	if (flag==0){alert(errors); return false;}
	return true;
}
function expandNews(doYear){
	document.getElementById('year'+doYear).style.display = 'block';
	location.href = '#a'+doYear;
}
