﻿
var EventCalenderMonth;
var ActualEventID = null;

var CurrentCalendarObj = null;
var LastCalendarObj = null;
var AngebotDropOut = false;
var LinkTarget="_parent";

var AC_FL_RunContent = 0;

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0



// Main function to retrieve mouse x-y pos.s






function nObj(arid) {
    
     document.getElementById("hT" + arid ).style.color="#5b5b5b";
     document.getElementById("aT" + arid ).style.background="#ffffff";
     document.getElementById("aT" + arid ).style.border="1px solid #a0a0a0";
        
} 

function hObj(arid) {
         
     document.getElementById("hT" + arid ).style.color="white";
     document.getElementById("aT" + arid ).style.background="#f8b41f";
     document.getElementById("aT" + arid ).style.border="1px solid #ffde9d";
        
}








var shownElement = null;
var hTimeout = null;

function showMenu(sourceObject) {
        doHideMenu();
         var xid = sourceObject.id.replace("n","")
         shownElement=document.getElementById("m" + xid)
         shownElement.style.visibility="visible";
         shownElement.style.left=sourceObject.offsetLeft-1;
	//	 shownElement.style.width=sourceObject.width;
        holdMenu();
}

function holdMenu() {
 clearTimeout(hTimeout);
}

function hideMenu() {
 if (shownElement != null) {
  hTimeout = setTimeout("doHideMenu();",500);
 }
}

function doHideMenu() {
 if (shownElement != null)  {
        
         document.getElementById("hT" + arid ).style.color="white";
         document.getElementById("aT" + arid ).style.background="#f8b41f";
         document.getElementById("aT" + arid ).style.border="1px solid #ffde9d";
        
        
        shownElement.style.visibility="hidden";
        shownElement = null;
 }
}







function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY

  return true
}


function EventDetail(id,floatType) {


    if (ActualEventID) {
    
    
        
        document.getElementById('ed' + ActualEventID).style.display='none';
      //  document.getElementById('eAll' + ActualEventID).style.background='none';
     //   document.getElementById('Event' + ActualEventID ).style.styleFloat="left";
     //   document.getElementById('Event' + ActualEventID ).style.cssFloat="left";
        
        
       // document.getElementById('Event' + ActualEventID ).style.borderLeft='7px solid #e5e5e5';
        
     }   
     
     
     
     // document.getElementById('eAll' + id ).style.background='#f0f0f0';
     // document.getElementById('Event' + id ).style.borderLeft='7px solid #f7b41f';
    
    if (floatType == 1) { 
        // document.getElementById('Event' + id ).style.styleFloat="right";
        // document.getElementById('Event' + id ).style.cssFloat="right";
    
     document.getElementById('ed' + id).style.top = tempY - 400;
     document.getElementById('ed' + id).style.left = tempX - 600;
     
    }    
    
   
   document.getElementById('ed' + id).style.top = tempY + 10 ;
   document.getElementById('ed' + id).style.left = tempX + 10;
     
   
   
    // document.getElementById('Event' + id ).style.height="200px";
    
    //alert( document.getElementById('Event' + id ).style.Float)
     //Effect.Appear('ed' + id);
     document.getElementById('ed' + id).style.background = "white";
     //document.getElementById('ed' + id).style.display='block';
     Effect.Appear('ed' + id);
     document.getElementById('ed' + id).style.position='absolute';
     document.getElementById('ed' + id).style.width = "236px";
     //document.getElementById('ed' + id).style.height = "200px";
     document.getElementById('ed' + id).style.border = "2px solid #f7b41f";
     document.getElementById('ed' + id).style.padding = "4px";
    ActualEventID = id;
}



function SwitchCalObj(newObj)
{
    
    var tval = newObj.id.split("@")[0] + "_value";
    var tObj = document.getElementById(tval);
   
  
    
    if (tObj.value != '')
    {
      var tCalObj = newObj.id.split("@")[0] + "@" + tObj.value;
      if (document.getElementById(tCalObj) != null) {document.getElementById(tCalObj).className = "Date_Standard";}
     // alert(tCalObj);
      //  LastCalendarObj = CurrentCalendarObj;
    }
   
    
    
    
    CurrentCalendarObj = newObj;
    var cit = CurrentCalendarObj.id.split("@");
    var telem = document.getElementById(cit[0] + "_value")
    telem.value = cit[1];
    telem.focus();
    
  //  CurrentCalendarObj.className = "Date_Event";
}


function ChangeCalStyle(Obj){
    
    if (Obj.value != '') {
    
    var CalObj = Obj.id.split("_value")[0] + "@" + Obj.value;
    
    if (LastCalendarObj != null) {

        if (LastCalendarObj.id.split("@")[0] == CurrentCalendarObj.id.split("@")[0]) {
        LastCalendarObj.className = "Date_Standard";
        }
    }
    
    document.getElementById(CalObj).className = "Date_Event";
    
    
    }
    
}

function gimmeField(obj) {
    document.getElementById(obj).style.background="#edce9d";
    document.getElementById(obj).focus();
}

function gimmeField2(obj) {
    document.getElementById(obj).style.color="red";
    document.getElementById(obj).value = "??.??.????";
    
}


function chkAngebotFRM() {

var go = true;
    
    if (document.getElementById("nachname").value == '' ) {
        gimmeField("nachname"); 
       go = false;
    }
    
    if (document.getElementById("email").value == '' ) { 
    
        gimmeField("email"); 
        go = false
    
    }
    
    if (document.getElementById("calendar1_value").value == '' || document.getElementById("calendar1_value").value == '??.??.????'  ) {
        gimmeField2("calendar1_value"); 
       go = false;
    }
    
    if (document.getElementById("calendar2_value").value == '' || document.getElementById("calendar2_value").value == '??.??.????') { 
    
        gimmeField2("calendar2_value"); 
        go = false
    
    }
            
 
    
    if ( go == true) {
       var myURL = "angebot_send.aspx?vorname=hansi&nachname=" + gObjVal("nachname") + "&email=" + gObjVal("email") + "&telefon=" + gObjVal("telefon") + "&strasse=" + gObjVal("strasse") + "&plz=" +gObjVal("PLZ") + "&ort=" + gObjVal("Ort") + "&d1=" + gObjVal("calendar1_value") + "&d2=" +gObjVal("calendar2_value") + "&anmerkung=" + gObjVal("anmerkung") + "&e1=" + gObjVal("e1") + "&e2=" + gObjVal("e2")
        
        mURL(myURL);
        alert(myURL);
    }
}


function gObjVal(obj) {

    return URLEncode(document.getElementById(obj).value);
    

}




function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	
	return encoded;
}



function initCalendar(elem,y,m,LAid) 
{

    mURL("calendar.asp?y=" + y + "&m=" + m + "&elem=" + elem + "&LAid=" + LAid);
}







function mURL(murl) {
murl=murl + '&rnd=' + Math.random();
RequestURL(murl);

}

function RequestURL(url) 
{
    var http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
            // See note below about this line
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {w
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    
  //  alert(url);
   //document.getElementById("reservation_box").innerHTML=url;
    http_request.onreadystatechange = function() { alertBox(http_request); };
    http_request.open('GET', url, true);
    http_request.send(null);

}

function alertBox(http_request) 
{



    if (http_request.readyState == 4) {
        if (http_request.status == 200) {



    myCommand=http_request.responseText.split("|||")[0];
    myHTML=http_request.responseText.split("|||")[1];
	elem=document.getElementById(http_request.responseText.split("|||")[2]);
	
	
			  
	if (myCommand == "send_ok") {
	    new Effect.SwitchOff ('angebotBox');
        document.getElementById('angebotBoxHead').style.display="none";
        setTimeout("document.getElementById('angebotSent').style.display='block';",1000);
	}
	
	if (myCommand == "send_error") {
	    new Effect.SwitchOff ('angebotBox');
        document.getElementById('angebotBoxHead').style.display="none";
        setTimeout("document.getElementById('angebotSentError').style.display='block';",1000);
	}
			
			    
			   elem.innerHTML=myHTML;
			    
			
			  	        
			
        } else {
            alert('There was a problem with the request.');
        }
    }
	
}






