var bPageLoaded 	= false;
var oXmlHttp 		= null;		// The XMLHttp object

function floatAppear()
{
	if(document.getElementById('main_float').style.display == "")
	{
		new Effect.Fade('main_float', {duration: 1});
		new Effect.MoveBy('main_float_top', 376, 0);
		
		document.getElementById('floatBut').style.display = 'none';
	}
	else
	{
		new Effect.MoveBy('main_float_top', -376, 0 );
		new Effect.Appear('main_float', {duration: 10.0, from: 0.0, to: 100.0});
		
		if(bPageLoaded == false)
		{
			loadLoader('main_float_inner', 'ajax.shopmain.php');
			bPageLoaded = true;
		}
	}
}

function loadLoader(div, page)
{
	document.getElementById('floatBut').style.display = '';
	
	oXmlHttp = zXmlHttp.createRequest();
    oXmlHttp.open("get", 'ajax.loader.php', true);
    oXmlHttp.setRequestHeader("Content-type", "text/html");
    
    oXmlHttp.onreadystatechange = function () {    
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
				document.getElementById(div).innerHTML	= oXmlHttp.responseText;
				
				if(page != null)
				{
					loadPage(div, page);
				}
			} else {
				document.getElementById(div).innerHTML	= "An error has occured: " + oXmlHttp.statusText;
			}
        }
    };
    
	oXmlHttp.send(null);
}

function loadPage(div, page)
{
	oXmlHttp = zXmlHttp.createRequest();
    oXmlHttp.open("get", page, true);
    oXmlHttp.setRequestHeader("Content-type", "text/html");
    
    oXmlHttp.onreadystatechange = function () {    
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
				document.getElementById(div).innerHTML	= oXmlHttp.responseText;
			} else {
				document.getElementById(div).innerHTML	= "An error has occured: " + oXmlHttp.statusText;
			}
        }
    };
    
	oXmlHttp.send(null);
}

function rollup(page)
{
	bPageLoaded = true;

	if(document.getElementById('main_float').style.display == "")
	{
		// Do nothing
	}
	else
	{
		new Effect.MoveBy('main_float_top', -376, 0 );
		new Effect.Appear('main_float', {duration: 10.0, from: 0.0, to: 100.0});
	}
	
	loadLoader('main_float_inner', 'ajax.rollup.php?rollup='+page);
}

function shopup(page)
{
	bPageLoaded = true;

	if(document.getElementById('main_float').style.display == "")
	{
		// Do nothing
	}
	else
	{
		new Effect.MoveBy('main_float_top', -376, 0 );
		new Effect.Appear('main_float', {duration: 10.0, from: 0.0, to: 100.0});
	}
	
	loadLoader('main_float_inner', 'ajax.shopmain.php?cat='+page);
}

function shoppage(page,link,extra)
{
	bPageLoaded = true;

	if(document.getElementById('main_float').style.display == "")
	{
		// Do nothing
	}
	else
	{
		new Effect.MoveBy('main_float_top', -376, 0 );
		new Effect.Appear('main_float', {duration: 10.0, from: 0.0, to: 100.0});
	}
	
	loadLoader('main_float_inner', 'ajax.shoppage.php?page='+page+'&link='+link+'&extra='+extra);
}


function productsList(cat,company,start,bShow)
{
	loadLoader('product_links', 'ajax.shoppage.php?page=product_links&company='+company+'&start='+start+'&cat='+cat+'&bShow='+bShow);
}

function bookup(page)
{
	bPageLoaded = true;

	if(document.getElementById('main_float').style.display == "")
	{
		// Do nothing
	}
	else
	{
		new Effect.MoveBy('main_float_top', -376, 0 );
		new Effect.Appear('main_float', {duration: 10.0, from: 0.0, to: 100.0});
	}
	
	document.getElementById('main_float_inner').className = "main_float_inner_book";
	
	loadLoader('main_float_inner', 'ajax.bookmain.php?id='+page);
}

function progup(page)
{
	bPageLoaded = true;

	if(document.getElementById('main_float').style.display == "")
	{
		// Do nothing
	}
	else
	{
		new Effect.MoveBy('main_float_top', -376, 0 );
		new Effect.Appear('main_float', {duration: 10.0, from: 0.0, to: 100.0});
	}
	
	document.getElementById('main_float_inner').className = "main_float_inner_book";
	
	loadLoader('main_float_inner', 'ajax.progmain.php?id='+page);
}

function progupin(page,num)
{
	bPageLoaded = true;

	if(document.getElementById('main_float').style.display == "")
	{
		// Do nothing
	}
	else
	{
		new Effect.MoveBy('main_float_top', -376, 0 );
		new Effect.Appear('main_float', {duration: 10.0, from: 0.0, to: 100.0});
	}
	
	document.getElementById('main_float_inner').className = "main_float_inner_book";
	
	loadLoader('main_float_inner', 'ajax.progmain.php?id='+page+'&page='+num);
}

function booksendup()
{
	bPageLoaded = true;
	page	= document.getElementById('travel').value;
	
	if(document.getElementById('main_float').style.display == "")
	{
		// Do nothing
	}
	else
	{
		new Effect.MoveBy('main_float_top', -376, 0 );
		new Effect.Appear('main_float', {duration: 10.0, from: 0.0, to: 100.0});
	}
	
	document.getElementById('main_float_inner').className = "main_float_inner_book";
	
	loadLoader('main_float_inner', 'ajax.book.php?id='+page);
}

function sendBooking()
{
	var theform = document.bookform;
	
	var name = theform.name.value;
	var city = theform.city.value;
	var email= theform.email.value;
	var addr = theform.address.value;
	var country = theform.country.value;
	var parts= theform.participants.value;
	var zip  = theform.zip.value;
	var phone= theform.phone.value;
	var date = theform.date.value;
	var id = theform.id.value;
	
	if(name.length < 3) {
		alert("Please state your full name.");
		return false;
	}
	else if(city == "") {
		alert("Please enter your city.");
		return false;
	}
	else if(email == "") {
		alert("Please enter your email address.");
		return false;
	}
	else if(addr == "") {
		alert("Please enter your address.");
		return false;
	}
	else if(country == "") {
		alert("Please enter your country.");
		return false;
	}
	else if(parts == "") {
		alert("Please enter the total tour participants.");
		return false;
	}
	else if(zip.length < 3) {
		alert("Please enter your full zip/postal code.");
		return false;
	}
	else if(phone.length < 3) {
		alert("Please enter your full telephone number.");
		return false;
	}
	else if(date.length < 10) {
		alert("Please enter the date in YYYY-MM-DD order.");
		return false;
	}
	
	loadLoader('main_float_inner', 'ajax.booksend.php?id='+id+'&name='+name+'&city='+city+'&email='+email+'&addr='+addr+'&country='+country+'&parts='+parts+'&zip='+zip+'&phone='+phone+'&date='+date);
}

function switchImage(div,newImg)
{
	document.getElementById(div).src = newImg;
}

function sendTip(theForm)
{
	var name = theForm.name.value;
	var email = theForm.email.value;
	var friend = theForm.email_friend.value;
	var msg = theForm.message.value;
	
	if(name.length < 3)
	{
		alert("VŠnligen skriv in din namn.");
		return false;
	}
	
	if(email.length < 3)
	{
		alert("VŠnligen skriv in din e-post adress.");
		return false;
	}
	
	if(friend.length < 3)
	{
		alert("VŠnligen skriv in din vŠns e-post adress.");
		return false;
	}
	
	bPageLoaded = true;

	if(document.getElementById('main_float').style.display == "")
	{
		// Do nothing
	}
	else
	{
		new Effect.MoveBy('main_float_top', -376, 0 );
		new Effect.Appear('main_float', {duration: 10.0, from: 0.0, to: 100.0});
	}
	
	loadLoader('main_float_inner', 'tipfriend.php?name='+name+'&email='+email+'&friend='+friend+'&message='+msg);
	
	return false;
}

function showHide(div, action)
{
	document.getElementById(div).style.display	= action;
}

function checkNewsSubmit(theform) {
	if(theform.email.value.length < 5)
	{
		return false;
	}
	
	var goodEmail = theform.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
	if (!goodEmail) {
		alert("Invalid email adress");
		return false;
	}
}
