// Wird nach Aufruf der Startseite aufgerufen:
// Ueberprueft, ob Cookies erlaubt, setzt Parameter und leitet diese ans IndexServlet weiter
function startServlet( startUrl )
{
    checkCookies();
    setParams();
     
    if ( startUrl != undefined && startUrl != '' )
    {
    	document.forms[0].STARTURL.value = location.href;
    }
    
    document.forms[0].submit();
}


function searchString( agent, data )
{
	for( var i = 0; i < data.length; i++ )
	{
		var dataString = data[i];
		
		if ( agent.indexOf( dataString ) != -1 )
		{
			return true;
		}
	}
	
	return false;
};

function userAgentMobileCheck() 
{
	var agent = navigator.userAgent;
	
	var strings = new Array( 	"BlackBerry", "Mobile", "iPhone", "iPod", "Palm", "HTC", "Fennec", "PIE", 
								"IEMobile", "PPC", "Android", "Smartphone" );
	
	var isMobile = searchString( agent, strings );
	
	return( isMobile );
};

function setMediaInfo()
{
	var mediaInspector  = document.getElementById( 'mediaInspector' );
	var mediaValue 		= -1;
	var isMobile 		= "false";
	
	var userAgentMobile = userAgentMobileCheck();

	if( mediaInspector != null && mediaInspector.currentStyle )
	{
		mediaValue = mediaInspector.currentStyle['width'];	
	}
	else if( mediaInspector != null && window.getComputedStyle )
	{
		mediaValue = window.getComputedStyle(mediaInspector,null).getPropertyValue('width');		
	}
	
	//mediaValue 1px -> normal
	//mediaValue 2px -> mobile
	if( userAgentMobile || mediaValue == "2px" )
	{
		isMobile = "true";
	}
	
	if( document.forms[0].MEDIAINFO != null )
	{
		document.forms[0].MEDIAINFO.value = isMobile;
	}	
}
	
// Setze Parameter ins Formular
function setParams()
{
	setMediaInfo();
	
    // z.B. ?var1=wert1&var2=wert2
    values = location.search;
    und    = 0; 
	    
    // Parameter sind vorhanden
    if ( values.length > 1 )
    {
		var oneValue;
		var gleich;
	
		// Entferne ?
		values = values.substring(1,values.length);
	
		// Solange noch & in values
		while ( und != -1 )
		{
		    und = values.indexOf("&");
	
		    // Bestimme Wertepaar, z.B. var1=wert1
		    if ( und == -1 )
		    {
				oneValue = values;
		    }
		    else
		    {
				oneValue = values.substring(0,und);
		    }
			    
		    // Trenne Paramter und Wert
		    gleich   = oneValue.indexOf("=");
	
		    if ( gleich != -1 && gleich != oneValue.length-1 )
		    {
				// Setze Wert in Formular
				setParam( oneValue.substring(0,gleich), oneValue.substring(gleich+1,oneValue.length) );
		    }
	
		    // Schneide bearbeiteten Paramter aus values
		    if ( und != -1 )
		    {
				values = values.substring(und+1,values.length);
		    }
		}
    }
}

// Setze einen Parameter ins Formular
function setParam( param, value )
{
    if ( param.toUpperCase() == "HN" )
    {
		document.forms[0].HN.value = value;
    }
    else if ( param.toUpperCase() == "LINKS" )
    {
		document.forms[0].LINKS.value = value;
    }
    else if ( param.toUpperCase() == "SPRACHE" )
    {
		document.forms[0].SPRACHE.value = value;
    }
    else if ( param.toUpperCase() == "IP" )
    {
		document.forms[0].IP.value = value;
    }
    else if ( param.toUpperCase() == "ARR" )
    {
		document.forms[0].ARR.value = value;
    }
    else if ( param.toUpperCase() == "DEP" )
    {
		document.forms[0].DEP.value = value;
    }
    else if ( param.toUpperCase() == "LN" )
    {
		document.forms[0].LN.value = value;
    }
    else if ( param.toUpperCase() == "NOPAX" )
    {
		document.forms[0].NOPAX.value = value;
    }
    else if ( param.toUpperCase() == "STREET" )
    {
		document.forms[0].STREET.value = value;
    }
    else if ( param.toUpperCase() == "CITY" )
    {
		document.forms[0].CITY.value = value;
    }
    else if ( param.toUpperCase() == "ZIP" )
    {
		document.forms[0].ZIP.value = value;
    }
    else if ( param.toUpperCase() == "EMAIL" )
    {
		document.forms[0].EMAIL.value = value;
    }
    else if ( param.toUpperCase() == "PHONE" )
    {
		document.forms[0].PHONE.value = value;
    }
    else if ( param.toUpperCase() == "COUNTRY" )
    {
		document.forms[0].COUNTRY.value = value;
    }
    else if ( param.toUpperCase() == "NOROOMS" )
    {
		document.forms[0].NOROOMS.value = value;
    }
    else if ( param.toUpperCase() == "NOCHILDS" )
    {
		document.forms[0].NOCHILDS.value = value;
    }
    else if ( param.toUpperCase() == "DEST" )
    {
		document.forms[0].DEST.value = value;
    }
    else if ( param.toUpperCase() == "ID" )
    {
		document.forms[0].ID.value = value;
    }
    else if ( param.toUpperCase() == "PW" )
    {
		document.forms[0].PW.value = value;
    }
    else if ( param.toUpperCase() == "CATRANGE" )
    {
		document.forms[0].CATRANGE.value = value;
    }
    else if ( param.toUpperCase() == "FSLINK" )
    {
		document.forms[0].FSLINK.value = value;
    }
    else if ( param.toUpperCase() == "FSTITLE" )
    {
		document.forms[0].FSTITLE.value = value;
    }
    else if ( param.toUpperCase() == "RATES" )
    {
		document.forms[0].RATES.value = value;
    }
    else if ( param.toUpperCase() == "SHOWSERVICES" )
    {
		document.forms[0].SHOWSERVICES.value = value;
    }
    else if ( param.toUpperCase() == "STARTURL" )
    {
		document.forms[0].STARTURL.value = value;
    }
    else if ( param.toUpperCase() == "ANY" )
    {
		document.forms[0].ANY.value = value;
    }
    else if ( param.toUpperCase() == "MHN" )
    {
		document.forms[0].MHN.value = value;
    }
    else if ( param.toUpperCase() == "NOPAXPERGT" )
    {
		document.forms[0].NOPAXPERGT.value = value;
    }
    else if ( param.toUpperCase() == "RESETNAVI" )
    {
		document.forms[0].RESETNAVI.value = value;
    }
    else if ( param.toUpperCase() == "MC" )
    {
		document.forms[0].MC.value = value;
    }
    else if ( param.toUpperCase() == "PACKAGE" )
    {
		document.forms[0].PACKAGE.value = value;
    }
    else if ( param.toUpperCase() == "CAT" )
    {
		document.forms[0].CAT.value = value;
    }
    else if ( param.toUpperCase() == "LINKSINTITLE" )
    {
		document.forms[0].LINKSINTITLE.value = value;
    }
    else if ( param.toUpperCase() == "LOGOASBACK" )
    {
		document.forms[0].LOGOASBACK.value = value;
    }
    else if ( param.toUpperCase() == "FLAGS" )
    {
		document.forms[0].FLAGS.value = value;
    }
    else if ( param.toUpperCase() == "PFRAME" )
    {
		document.forms[0].PFRAME.value = value;
    }
    else if ( param.toUpperCase() == "SHOWAV" )
    {
		document.forms[0].SHOWAV.value = value;
    }
    else if ( param.toUpperCase() == "CURRENCY" )
    {
		document.forms[0].CURRENCY.value = value;
    }
    else if ( param.toUpperCase() == "ALLOTONLY" )
    {
		document.forms[0].ALLOTONLY.value = value;
    }
    else if ( param.toUpperCase() == "ALLOTANDINVENT" )
    {
		document.forms[0].ALLOTANDINVENT.value = value;
    }
    else if ( param.toUpperCase() == "PCAT" )
    {
		document.forms[0].PCAT.value = value;
    }
    else if ( param.toUpperCase() == "NOPAXPERFIELD" )
    {
		document.forms[0].NOPAXPERFIELD.value = value;
    }
    else if ( param.toUpperCase() == "SHOWPRICES" )
    {
		document.forms[0].SHOWPRICES.value = value;
    }
    else if ( param.toUpperCase() == "FFPROG" )
    {
		document.forms[0].FFPROG.value = value;
    }
    else if ( param.toUpperCase() == "SALECHANNEL" )
    {
		document.forms[0].SALECHANNEL.value = value;
    }
    else if ( param.toUpperCase() == "STARTVIEW" )
    {
		document.forms[0].STARTVIEW.value = value;
    }
    else if ( param.toUpperCase() == "ALLOTORINVENT" )
    {
		document.forms[0].ALLOTORINVENT.value = value;
    }
    else if ( param.toUpperCase() == "STYLESHEET" )
    {
		document.forms[0].STYLESHEET.value = value;
    }
    else if ( param.toUpperCase() == "CHECKAVDJHBV" )
    {
		document.forms[0].CHECKAVDJHBV.value = value;
    }
    else if ( param.toUpperCase() == "DJHBV" )
    {
		document.forms[0].DJHBV.value = value;
    }
    else if ( param.toUpperCase() == "HOUSE" )
    {
		document.forms[0].HOUSE.value = value;
    }
    else if ( param.toUpperCase() == "ARRIVAL" )
    {
		document.forms[0].ARRIVAL.value = value;
    }
    else if ( param.toUpperCase() == "DEPARTURE" )
    {
		document.forms[0].DEPARTURE.value = value;
    }
    else if ( param.toUpperCase() == "NUMPEOPLE" )
    {
		document.forms[0].NUMPEOPLE.value = value;
    }
    else if ( param.toUpperCase() == "GUESTTYPE" )
    {
		document.forms[0].GUESTTYPE.value = value;
    }
    else if ( param.toUpperCase() == "MEDIAINFO" )
    {
		document.forms[0].MEDIAINFO.value = value;
    }
    else if ( param.toUpperCase() == "SHOWPRICECALENDAR" )
    {
		document.forms[0].SHOWPRICECALENDAR.value = value;
    }
    else if ( param.toUpperCase() == "MCEXT" )
    {
		document.forms[0].MCEXT.value = value;
    }
    else if ( param.toUpperCase() == "RLINK" )
    {
		document.forms[0].RLINK.value = value;
    }
}
	
	// Ueberpruefe, ob Cookies erlaubt sind
	function checkCookies()
	{
	    document.cookie = "SIHOTWEBTestCookie";
	    
	    //if ( document.cookie.length == 0 )
	    //{
		//alert( "You have to accept session cookies in your browser" );
	    //}
	    //else
	    //{
		//document.cookie = "";
   	    //}
	}


