﻿// VarUserControlTime
var commonTimeClientID;
var commonCheckBoxClientID;

function loadMyMap2(mapcontrol,point) {    
    if (GBrowserIsCompatible()) {
        var mapElement = document.getElementById(mapcontrol);
        if( mapElement != null )
        {
            var map = new GMap2(mapElement);
            map.enableDoubleClickZoom();
            map.enableContinuousZoom();
            map.addControl(new GLargeMapControl());
            map.addControl(new GMapTypeControl());
            map.addControl(new GOverviewMapControl());
            map.setCenter(point,14);
            map.addOverlay(new GMarker(point));
            map.setMapType(G_SATELLITE_MAP);
        }
     }
     else {
        alert("Sorry, the Google Maps API is not compatible with this browser");
     }
}

function GV2_UpdateTimeLabels(index)
{
    if (index == 0)
    {
        $get(commonTimeClientID+'__lblAnreise1').style.display = "block"; 
        $get(commonTimeClientID+'__lblAnreise2').style.display = "none"; 
        $get(commonTimeClientID+'__lblAbreise1').style.display = "block"; 
        $get(commonTimeClientID+'__lblAbreise2').style.display = "none";
    }
    else if (index == 1)
    {
        $get(commonTimeClientID+'__lblAnreise1').style.display = "none"; 
        $get(commonTimeClientID+'__lblAnreise2').style.display = "block"; 
        $get(commonTimeClientID+'__lblAbreise1').style.display = "none"; 
        $get(commonTimeClientID+'__lblAbreise2').style.display = "block";
    }
}

function GV2_ActiveSearchTabChanged(indexarray, targetobjindex)
{
    var ullist=$get('maintab').getElementsByTagName("li");
    for (var i=0; i<ullist.length; i++)
        ullist[i].className="";  //deselect all tabs
    ullist[targetobjindex].className="selected";  //highlight currently clicked on tab
    
    var divlist=$get('maincontent');
    for (var i=0; i<divlist.childNodes.length; i++)
        divlist.childNodes[i].style.display = "block";  //show all tabs
    for (var i=0; i<indexarray.length; i++)
        divlist.childNodes[indexarray[i]].style.display = "none";
        
    divlist=$get('maincontentsearchstatus');
    for (var i=0; i<divlist.childNodes.length; i++)
        divlist.childNodes[i].style.display = "block";  //show all tabs
    if (indexarray[0] != 3)
        divlist.childNodes[3].style.display = "none";
        
    GV2_UpdateTimeLabels(targetobjindex);
}

function activate(value, sender)
{
    if (value)
    {
        if (sender == 'alle')
        {
            $get(commonTimeClientID+'__txtAnreise').disabled = 'disabled';
            $get(commonTimeClientID+'__txtAbreise').disabled = 'disabled';
            $get(commonCheckBoxClientID+'CheckBoxFree').checked = false;
        }
        if (sender == 'frei')
        {
            $get(commonCheckBoxClientID+'CheckBoxIgnore').checked = false;
            $get(commonTimeClientID+'__txtAnreise').disabled = '';
            $get(commonTimeClientID+'__txtAbreise').disabled = '';  
        }
        
    }
    else
    {
        if (sender == 'alle')
        {
            $get(commonTimeClientID+'__txtAnreise').disabled = '';
            $get(commonTimeClientID+'__txtAbreise').disabled = '';
            $get(commonCheckBoxClientID+'CheckBoxFree').checked = true;
        }
        if (sender == 'frei')
        { 
            $get(commonTimeClientID+'__txtAnreise').disabled = 'disabled';
            $get(commonTimeClientID+'__txtAbreise').disabled = 'disabled';
            $get(commonCheckBoxClientID+'CheckBoxIgnore').checked = true;
        }
    }   
}

function GV2_formatDate(d) {
		var days = d.getDate();
		var month = d.getMonth()+1;
		var year = d.getFullYear();

		if (days < 10) days = '0'+days;
		if (month < 10) month = '0'+month;

		return ''+days+'.'+month+'.'+year;
}

function bindAnAbreiseAutoAdjust(txtAnreise, txtAbreise) {
	if(typeof txtAnreise == 'string') txtAnreise = document.getElementById(txtAnreise);
	if(typeof txtAbreise == 'string') txtAbreise = document.getElementById(txtAbreise);

	if (txtAnreise==null||txtAbreise==null) return;

	var addEventListener = function(t, e, f) {
		if (t.addEventListener) t.addEventListener(e, f, false);
		else if (t.attachEvent) t.attachEvent('on'+e, f); //m$
	}

	var formatDate = GV2_formatDate;

	var an2ab = function() {
		var d = new Date(  ValidatorConvert(txtAnreise.value, 'Date', {dateorder:'dmy'}) )
		var ab = new Date(  ValidatorConvert(txtAbreise.value, 'Date', {dateorder:'dmy'}) )
		d.setDate(d.getDate()+1);

		if (d.getTime() > ab.getTime())
			txtAbreise.value = formatDate(d);
	};

	var ab2an = function() {
		var d = new Date(  ValidatorConvert(txtAbreise.value, 'Date', {dateorder:'dmy'}) )
		var an = new Date(  ValidatorConvert(txtAnreise.value, 'Date', {dateorder:'dmy'}) )
		d.setDate(d.getDate()-1);

		if (d.getTime() < an.getTime())
			txtAnreise.value = formatDate(d);
	};

	addEventListener(txtAnreise, 'change', an2ab);
	txtAnreise.onchangebycalendar = an2ab;
	
	addEventListener(txtAbreise, 'change', ab2an);
	txtAbreise.onchangebycalendar = ab2an;
}

function notifyParentIframeResize() {
	if (!window.parent) return;
	if (!window.parent.postMessage) return;

	//var h = document.body.scrollHeight;

	
	try {
		var h = document.body.offsetHeight;// + 50;
		//var h2 = ( document.documentElement ? document.documentElement.offsetHeight : 0); //msie: around h1
		//var h3 = document.body.clientHeight; //msie always same as body.offsetHeight
		var h4 = document.forms[0].offsetHeight; //msie: better it seems, assuming we have one big asp.net form containing the whole page

		/*if (window.navigator.appName == "Microsoft Internet Explorer")*/ h = h4;

		parent.postMessage('eContent.CMS.iframeresize?height='+h, '*');
		//parent.postMessage('eContent.CMS.iframeresize?height='+h + "&h2="+h2 + "&h3="+h3 + "&h4="+h4 , '*');
	} catch(e) {
	}
}

$addHandler(window, 'load', notifyParentIframeResize);
$addHandler(window, 'load', function() {
	setTimeout(notifyParentIframeResize, 200); //MSIE hack

	if (window.Sys) Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(notifyParentIframeResize);
 });




