/*
Common scripts
www.apfelarzt.de
Start: 10.06.2009
Last modified: 03.07.2009
*/


/* view + alternate table rows
--------------------------------------------------------------------------------------- */
function initPage ()
{
	skypeButtons();
	alternateTablerows();
}

function skypeButtons ()
{
	if ( typeof skypeCheck == "function" )
	{
		if ( document.getElementById( "skypeButton" ) )
		{
			document.getElementById( "skypeButton" ).onclick = function () {
				return skypeCheck();
			};
		}
	}	
}

function alternateTablerows ()
{
	if ( document.getElementsByTagName )
	{
		var tables = document.getElementsByTagName( "table" );
		if ( tables.length > 0 )
		{
			for ( var i = 0; i<tables.length; i++ )
			{
				var table = tables[i];				
				var rows = table.getElementsByTagName( "tr" );
				
				for (var j = 0; j<rows.length; j++ )
				{
					if ( j % 2 == 0 )
					{
						rows[j].className = "even";
					}
					else
					{
						rows[j].className = "odd";
					}
				}
			}
		}
	}
}

window.onload = initPage;


/* support form
--------------------------------------------------------------------------------------- */
function checkReqInput ( field )
{
	if ( field.value == '' )
	{
		field.className = "error";
		if ( document.getElementById( "error-msg" ) )
		{
			document.getElementById( "error-msg" ).style.display = "block";
		}
	}
	else
	{
		field.className = "";
	}
}

function checkReqEmail ( field )
{
	if ( field.value == '' || field.value.indexOf("@") == -1 || field.value.indexOf(".") == -1)
	{
		field.className = "error";
		if ( document.getElementById( "error-msg" ) )
		{
			document.getElementById( "error-msg" ).style.display = "block";
		}
		alert('Die E-mail-Adresse ist nicht vollständig.');
	}
	else
	{
		field.className = "";
	}
}

function checkReqSel ( field )
{
	if ( field.options[field.selectedIndex].value == '' )
	{
		field.className = "error";
		if ( document.getElementById( "error-msg" ) )
		{
			document.getElementById( "error-msg" ).style.display = "block";
		}
	}
	else
	{
		field.className = "";
	}
}

function buildMachineDropdown ()
{
	if ( document.getElementById( "Geraet" ) )
	{
		var macDropdown = document.getElementById( "Geraet" );
		macDropdown.options.length = aModels.length + 2;
		macDropdown.options[0] = new Option( '-- Bitte wählen --', '' );
		macDropdown.options[1] = new Option( '-------------------', '' );
		
		if ( aModels.length > 0 )
		{
			counter = 2;
			for ( var i=0; i<aModels.length; i++ )
			{
				macDropdown.options[counter] = new Option( aModels[i]["machine"], aModels[i]["machine"] );
				counter++;
			}
		}
	}	
	
	macDropdown.onfocus = "";
}

function setModelList ( machineIndex )
{
	if ( document.getElementById( "Modell" ) )
	{
		var modelDropdown = document.getElementById( "Modell" );
		modelDropdown.options.length = aModels[machineIndex]["models"].length + 2;
		modelDropdown.options[0] = new Option( '-- Bitte wählen --', '' );
		modelDropdown.options[1] = new Option( '-------------------', '' );
		
		if ( aModels[machineIndex]["models"].length > 0 )
		{
			counter = 2;
			for ( var i=0; i<aModels[machineIndex]["models"].length; i++ )
			{
				modelDropdown.options[counter] = new Option( aModels[machineIndex]["models"][i], aModels[machineIndex]["models"][i] );
				counter++;
			}
		}
	}	
}
