// TenSquare JavaScript Functions
function showDateTime(){
	var currentTime = new Date();
	var date = currentTime.getDate();
	var day = currentTime.getDay();
	var month = currentTime.getMonth();
	var year = currentTime.getFullYear();
	var hour = currentTime.getHours();
	var mins = currentTime.getMinutes();
	if(mins < 10) mins = "0"+mins;
	switch(day){
		case 1:
			day = 'Mon';
		break;
		case 2:
			day = 'Tues';
		break;
		case 3:
			day = 'Wens';
		break;
		case 4:
			day = 'Thurs';
		break;
		case 5:
			day = 'Fri';
		break;
		case 6:
			day = 'Sat';
		break;
		case 7:
			day = 'Sun';
		break;
	}
	document.write("<span class=\"datetime\"><span class=\"time\">"+hour+":"+mins+"</span><br />"+day+" "+date+"/"+(month+1)+"/"+year+"</span>");
	return;
}

var tourActiveIntervalId = 0;
var containerwidth = 367;
var activeinc = 0;
var time = 12; // milliseconds of setInterval
var step = 10; // px step of animation

function virtualTourAnimate(inc){
	clearInterval(tourActiveIntervalId);
	inc = Math.round(inc*containerwidth);
	dir = 'right';
	if(activeinc>inc) dir = 'left';
	tourActiveIntervalId = setInterval("animate(window.document.getElementById('tour_information'), '"+dir+"', "+inc+", tourActiveIntervalId)", time);
	activeinc = inc;
	
	return;
}

function animate(obj, dir, endpos, id){
	endpos *= -1;
	
	var targetreached = false;
	var currentleftmargin = obj.style.left;
	currentleftmargin = currentleftmargin.replace("px", "");
	
	if(dir=='left'){
		if(currentleftmargin>=endpos){
			targetreached = true;
			obj.style.left = endpos+'px';
		}else{
			currentleftmargin = Math.round(parseInt(currentleftmargin) + step);
			obj.style.left = currentleftmargin+'px';
		}
	}else{
		if(currentleftmargin<=endpos){
			targetreached = true;
			obj.style.left = endpos+'px';
		}else{
			obj.style.left = (Math.round(currentleftmargin-step))+'px';
		}
	}
	if(targetreached){
		clearInterval(id);
	}
	return;
}

function isEmpty(val){
                if(!val.value){
                                return false;
                }
                return true;
}

function isValidEmail(val) {
                val = val.value;
                return (val.indexOf(".") > 0) && (val.indexOf("@") > 0);
 
}


function validateform(){
                var name = document.getElementById('name');
                var email = document.getElementById('email');            
                var error = 'Please insert your ';
                
                if(!isEmpty(name)){
                                name.focus();
                                window.alert(error+'Name');
                                return false;
                }
                if(!isValidEmail(email)){
                                email.focus();
                                window.alert(error+'Email Address');
                                return false;
                }
                
                return true;
}
