var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;


var gAutoPrint = true; // Flag for whether or not to automatically call the print function

function printSpecial()
{
	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}

		html += '\n</HE' + 'AD>\n<BODY>\n';

		var printReadyElem = document.getElementById("printReady");

		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}

		html += '\n</BO' + 'DY>\n</HT' + 'ML>';

		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}


function setBackExtraAmount(extra, id)
{
    
    // if call by td-onclick
    // first check or uncheck
    //
    if (!extra) {
        extra =  document.main.elements["extra" +id];
        extra.checked =  extra.checked? false : true;
    }
    
	if(extra.checked) document.main.elements["extraAmount" +id].value =  1;
	else document.main.elements["extraAmount" +id].value =  "";
}

function setDropOffStation(id){

	var s_options = document.main.carDropOffStationId.options;
	var index = document.main.carDropOffStationId.selectedIndex;
	var val = document.main.carDropOffStationId.options[index].value;


	if(val=="-1")
	{
		for(i=0; i<s_options.length; i++)
		{
			var myvalue = s_options[i].value;

			if(myvalue==id)
			{
				document.main.carDropOffStationId.selectedIndex=i;
				break;
			}
		}
	}
}



function setPickUpBack()
{
	var s_pickups  = document.main.carPickUpStationId;
	var pickups  = document.main.carPickUpStationId.options;
	var selectedValue = "";


	// Pickups zurücksetzen
	for (i = 0; i<pickups.length; i++)
	{
		selectedValue = pickups[i].value;

		if(selectedValue=="-1")
		{
			s_pickups.selectedIndex=i;
			break;
		}
	}
}

function setDropOffBack()
{
	var s_pickups  = document.main.carDropOffStationId;
	var pickups  = document.main.carDropOffStationId.options;
	var selectedValue = "";

	for (i = 0; i<pickups.length; i++)
	{
		selectedValue = pickups[i].value;

		if(selectedValue=="-1")
		{
			s_pickups.selectedIndex=i;
			break;
		}
	}
}


/*function setAreasBack()
{
	var s_areas = document.main.carArea;
	var areas = document.main.carArea.options;

	// areas zurücksetzen
	for (i = 0; i<areas.length; i++)
	{
		selectedValue = areas[i].value;
		if(selectedValue == "-1")
		{
			s_areas.selectedIndex=i;
			break;
		}
	}
}*/
function setObjectBack()
{
	if(typeof (document.main.carArea) != "undefined")
		setCommonObjectsBack();
	
	setPickUpBack();
	setDropOffBack();
    /*setAreasBack();*/
    
}
function checkDropOff(def){

	var s_dropoff  = document.main.carDropOffStationId;
	var dropoff  = document.main.carDropOffStationId.options;
	var selectedValue = dropoff[s_dropoff.selectedIndex].value;

	// Dropoffs zurücksetzen
	if(selectedValue == "-1" )
	{
		for (i = 0; i<dropoff.length; i++)
		{
			selectedValue = dropoff[i].value;

			if(selectedValue == def)
			{
				s_dropoff.selectedIndex=i;
				break;
			}
		}
	}
	else
		document.main.submit();
}

function setExtraBack()
{
	var page3_extras = document.main.page3_extras;

	for (i = 0; i<page3_extras.length; i++)
	{
		if(page3_extras[i].checked)
			document.main.page3_extras[i].checked=false;
	}
}

function setCommonObjectsBack()
{
	var s_areas = document.main.carArea;
	var areas = document.main.carArea.options;

	// areas zurücksetzen
	for (i = 0; i<areas.length; i++)
	{
		selectedValue = areas[i].value;
		if(selectedValue == "-1")
		{
			s_areas.selectedIndex=i;
			break;
		}
	}
}

var ie = document.all ? 1 : 0;
var ns = document.layers ? 1 : 0;

if(ns)
{
	doc = "document.";
	sty = "";
}

if(ie)
{
	doc = "document.all.";
	sty = ".style";
}

var initialize = 0;
var Ex, Ey, topColor, subColor, ContentInfo;

if(ie)
{
	Ex = "event.x";
	Ey = "event.y";

	topColor = "#808080";
	subColor = "#C0C0C0";
}

if(ns)
{
	Ex = "e.pageX";
	Ey = "e.pageY";
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=overhere;

	topColor = "#808080";
	subColor = "#C0C0C0";
}

function ReplaceContent(layerName)
{

	if(ie)
		document.all[layerName].innerHTML = ContentInfo;

	if(ns)
	{
		with(document.layers[layerName].document)
		{
			open();
			write(ContentInfo);
			close();
		}
	}
}

function check_mail(mail_field)
{
	email_correct = false;
	if(mail_field.value.replace(/\s+/,"") == "")
	{
		email_correct = false;
	}
	else
	{
		mailValue = mail_field.value.replace(/\s+/,"");
		if((mailValue.indexOf('@')<1)||(mailValue.indexOf('@') > mailValue.lastIndexOf('.')) ||(mailValue.indexOf('@')==(mailValue.length - 1)) || (mailValue.lastIndexOf('.')>mailValue.length - 3)||(mailValue.lastIndexOf('.') < (mailValue.length - 5)) )
		{
			email_correct = false;
		}
		else
		{
			mail_field.value = mailValue;
			email_correct = true;
		}
	}

	return email_correct;
}