﻿var ip = 0.0;
var obj, timeout, src, dest, reset;

function scroll(sSrc, sDest, sReset) {
	document.getElementById('banner_left').src = 'images/banner_1000_left_01.gif';
	ip = 0.0;
	obj = document.getElementById('p1000_clip');
	window.clearInterval(timeout);
	timeout = window.setInterval(move, 20);
	src = sSrc;
	dest = sDest;
	reset = sReset;
}

function validate(email,name,from) {
	var send = true;
	var msg = "";

	
	var txtRecipients;
	var arrRecipients;

	txtRecipients = email;

	arrRecipients = txtRecipients.split(" ");
	txtRecipients = arrRecipients.join("");

	arrRecipients = txtRecipients.split(",");
	txtRecipients = arrRecipients.join(";");

	arrRecipients = txtRecipients.split(";");
	
	for (var i=0; i<arrRecipients.length; i++) {
		var recipient = arrRecipients[i].trim();
		if ( !isValidEmail(recipient) ) {		
			send = false;
			msg = "Nogle af modtagernes e-mailadresser er ikke gyldige\n";
		}
	}
	
	if ( !isValidEmail(from) ) {		
		send = false;
		msg = "Din e-mail er ikke gyldig\n";
	}
	
	if (name == ""){
		send = false;
		msg = "Du har ikke angivet navnet på afsenderen\n";
	}
	
	if (send)
		document.getElementById('tips').submit();
	else
		alert(msg);
}

function gostart() {
	reset = false;
	ip = 0.0;
	obj = document.getElementById('p1000_clip');
	window.clearInterval(timeout);
	timeout = window.setInterval(move, 20);
	src = obj.scrollLeft;
	dest = -696;
	//resetforms();
}

function move() {
	if(ip < 100) {
		ip+=4;
	} else {
		ip = 100;
		window.clearInterval(timeout);
		if(reset)
			timeout = window.setTimeout(goback, 1000);
	}
	obj.scrollLeft = easeInOutCubic(ip, src, dest, 100);
}

function setResponse(){
	obj = document.getElementById('p1000_clip');
	obj.scrollLeft = (696);
	
	timeout = window.setTimeout(gostart, 2000);
}

function easeInOutCubic (t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t + b;
	return c/2*((t-=2)*t*t + 2) + b;
}

function resetforms() {
	tmp = document.getElementById('tips').getElementsByTagName('input');
	for(var i=0;i<tmp.length;i++)
		tmp[i].value = "";
}
