// JavaScript Document GBA
var imageArray = new Array();


function onLoad()
{
	preloadMenuImages();
}

function preloadMenuImages()
{
	imageArray[0] = "";
	
	for (var i = 1; i <= 8; i++)
	{
		imageArray[i] = new Image();
		imageArray[i].src = "img/layout/navi" + String(i) + "MouseOver.jpg";
	}
	
}

function getRandom( min, max ) 
{
	if( min > max ) return( max );
	if( min == max ) return( min );
	return( min + parseInt( Math.random() * ( max-min + 1 ) ) );
}

function checkDocument(obj_id) 
{
	if (document.getElementById) return document.getElementById(obj_id);
	if (document.all) return document.all[obj_id];
	if (document.layers) return document.layers[obj_id];
	return null;
}

function changeMainmenuImage(id, type, changeSubmenu)
{
	var imageID = "naviImage" + id;
	var imageElement = checkDocument(imageID);
	var imageURL = "";
	
	if (type == "Over")
	{
		if (imageArray[id] != null) // wenn Preload-Images noch nicht fertig initialisiert sind
		{
			imageURL = imageArray[id].src;
		}
		else
		{
			//imageURL = "img/layout/transparent.gif";
		}
		
		if (changeSubmenu) changeSubmenuText(id, "Over", false);
	}
	
	if (type == "Out")
	{
		imageURL = "img/layout/navi" + id + "MouseOut.jpg";
		if (changeSubmenu) changeSubmenuText(id, "Out", false);
	}
	
	imageElement.src = imageURL;
}

function changeSubmenuText(id, type, changeMainmenu)
{
	var background = "sidemenuBackground"+id;
	var naviBackground = checkDocument(background);
	
	var element = "sidemenuItemIndicator" + id;
	var naviItem = checkDocument(element);
	
	if (type == "Over")
	{
		naviItem.innerHTML = "&#0172;";
		naviBackground.style.backgroundImage = "url(img/layout/sideNaviBackgroundMouseOver.jpg)";
	}
	
	if (type == "Out")
	{
		naviItem.innerHTML = "&nbsp;"
		naviBackground.style.backgroundImage = "url(img/layout/sideNaviBackgroundMouseOut.jpg)";
	}
	
	if (changeMainmenu)
	{
		if (type == "Out")
		{
			changeMainmenuImage(id, type, false)
		}
		
		if (type == "Over")
		{
			changeMainmenuImage(id, type, false)
		}
	}
}

function createTooltip(id, title, iLink, targetPosition, tipPosition, stemPosition)
{
	var road2Object = checkDocument(id);
	road2Object.title = "";
	//road2Object.style.cursor="default";
	
	
	
	new Tip(id,iLink , {
		title: title.replace("[br]", "<br />"),
		border: 5,
		radius: 5,
		hook: { target: targetPosition, tip: tipPosition },
		offset: { x: 0, y: 0 },
		stem: stemPosition,
		hideOthers: true,
		width: 'auto',
		style: 'darkgrey'
	});
}

function checkContactform()
{
	var contactformName = checkDocument("contactformName");
	var contactformEmail = checkDocument("contactformEmail");
	var contactformPlace = checkDocument("contactformPlace");
	var contactformSubject = checkDocument("contactformSubject");
	var contactformMessage = checkDocument("contactformMessage");
	var contactformCaptchainput = checkDocument("contactformCaptchainput");
	var isOK = true;
	
	contactformName.style.border = "#333333 1px solid";
	contactformPlace.style.border = "#333333 1px solid";
	contactformEmail.style.border = "#333333 1px solid";
	contactformSubject.style.border = "#333333 1px solid";
	contactformMessage.style.border = "#333333 1px solid";
	contactformCaptchainput.style.border = "#333333 1px solid";
	
	if (contactformName.value == "")
	{
		contactformName.style.border = "#bf0c1d 1px solid";
		isOK = false;
	}
	
	if (!checkMail(contactformEmail.value))
	{
		contactformEmail.style.border = "#bf0c1d 1px solid";
		isOK = false;
	}
	
	if (contactformSubject.value == "")
	{
		contactformSubject.style.border = "#bf0c1d 1px solid";
		isOK = false;
	}
	
	if (contactformPlace.value == "")
	{
		contactformPlace.style.border = "#bf0c1d 1px solid";
		isOK = false;
	}
	
	if (contactformMessage.value == "")
	{
		contactformMessage.style.border = "#bf0c1d 1px solid";
		isOK = false;
	}
	
	if (contactformCaptchainput.value.length != 5)
	{
		contactformCaptchainput.style.border = "#bf0c1d 1px solid";
		isOK = false;
	}

	return isOK;
}

function checkMail(s)
{
	var a = false;
	var res = false;
	if(typeof(RegExp) == 'function')
	{
		var b = new RegExp('abc');
		if(b.test('abc') == true){a = true;}
	 }
	
	 if(a == true)
	 {
	 	reg = new RegExp('^([a-zA-Z0-9\-\.\_]+)'+'(\@)([a-zA-Z0-9\-\.]+)'+'(\.)([a-zA-Z]{2,4})$');
	 	res = (reg.test(s));
	 }
	 else
	 {
	  	res = (s.search('@') >= 1 && s.lastIndexOf('.') > s.search('@') && s.lastIndexOf('.') >= s.length-5)
	 }
	 return(res);
}

function checkOfferSearchTextfield(textfield)
{
	if (textfield.value == 'Suchbegriff eingeben')
	{
		textfield.value = '';
	}
}

// OfferViewer

function onLoadOfferViewer()
{
	var backButton = checkDocument("backButton");
	backButton.style.display = "none";
}

function showDetailsContainer(id)
{
	var detailsContainer = checkDocument("detailsContainer" + String(id));
	detailsContainer.style.display = "block";
}

function showDetails(id)
{
	var showDetailsLink = checkDocument("showDetails" + String(id));
	var hideDetailsLink = checkDocument("hideDetails" + String(id));
	
	showDetailsLink.style.display = "none";
	hideDetailsLink.style.display = "block";
}

function hideDetails(id)
{
	var showDetailsLink = checkDocument("showDetails" + String(id));
	var hideDetailsLink = checkDocument("hideDetails" + String(id));
	
	showDetailsLink.style.display = "block";
	hideDetailsLink.style.display = "none";
}
