//<![CDATA[

/* ################## ImmonetHpModul ############## */
/* ################################################ */
var ImmonetHpModul = function () {

    var myHost = "http://module.immonet.de/" + "widgets/js/";
    var iID = '823e516d86177c9d50d0b50a8';
    var linkErrorTold = false;

    /* Backlink Configuration */
    /* ###################### */

    var stdBacklinkMessage = "Der Code des Homepage-Moduls von Immonet.de wurde verändert. Bitte fügen Sie den Code des Moduls unverändert ein.";
    var requiredBacklink = '<a href="http://www.immonet.de" title="immobilien und wohnungen" target="_blank">immobilien</a> - suche powered by immonet.de<br />';
    var standardBacklink = '';

    /* DOM object to deal with */
    /* ####################### */
    var myWrapper = document.getElementById("immonetHpm");
    var myDiv = document.getElementById("immonetHpm-content");
    var myScripts = document.getElementById("immonetHpm-scripts");
    var myLinkBox = document.getElementById("immonet_hpmodul_info");
    var myHead = document.getElementsByTagName("head")[0];

    /* Map URL parameters and functions to execute */
    /* ########################################### */
    var myFunctions = new Array()
    myFunctions["null"]= "writeSearchMask";
    myFunctions["start"]= "writeSearchMask";
    myFunctions["sel"]= "getResults";
    myFunctions["sort"]= "getResultsSorted";
    myFunctions["expose"]= "getExpose";
    myFunctions["pics"]= "getPics";
    myFunctions["print"]= "getPrint";
    myFunctions["contact"]= "sendContact";
    myFunctions["contactdetails"]= "getContactDetails";
    myFunctions["contactlong"]= "sendContactLong";
    myFunctions["largeimage"]= "writeLargeImage";
    myFunctions["offererview"]= "writeOffererView";
    myFunctions["exposeshort"]= "exposeShort";

    /* Load HP Module and show search mask */
    /* ################################### */
    this.initialize = function () {
        this.loadHistoryScript();
	this.loadTrackingScript();
	this.getCss('823e516d86177c9d50d0b50a8');
	if(this.createHolder()) {
	    window.setTimeout(this.initHistory, 800);
	}
    }

    /* Check if backlink is set nicely */
    /* ############################### */
    this.checkModuleEnvironment = function () {
	var isInvalid = true;

	if (!myWrapper || !myLinkBox) {
	  isInvalid = true;
	} else {
    
	    boxLinks = myLinkBox.getElementsByTagName("a");
	    if(!boxLinks || !boxLinks[0]) {
		isInvalid = true;
	    } else {

		boxLink = boxLinks[0];
		
		/* was ist gesetzt? */
		myhref = boxLink.href.toLowerCase();
		if(myhref.charAt(myhref.length-1) == "/") {
		    myhref = myhref.substring(0, myhref.length-1);
		}
		
		myhref = 'href="' + myhref + '"';
		mytitle = 'title="' + boxLink.title.toLowerCase() + '"';
		if(boxLink.text) {
		    mytext = '>' + boxLink.text.toLowerCase() + '</a>';
		} else if(boxLink.innerText) {
		    mytext = '>' + boxLink.innerText.toLowerCase() + '</a>';
		}

		/* was wird verlangt? */

		if(
		    (requiredBacklink.indexOf(mytitle) >= 0 && requiredBacklink.indexOf(myhref) >= 0 && requiredBacklink.indexOf(mytext) >= 0)
		    ||
		    (standardBacklink.indexOf(mytitle) >= 0 && standardBacklink.indexOf(myhref) >= 0 && standardBacklink.indexOf(mytext) >= 0)
		  )
		{ isInvalid = false; }
	    
	    }

	    if(requiredBacklink == "" && standardBacklink == "") {
		isInvalid = false;
	    }
	}

	if(isInvalid && !linkErrorTold) {
	    alert(stdBacklinkMessage);
	    linkErrorTold = true;
	}

        return !isInvalid;
    }

    /* Create the holder for all the content */
    /* ##################################### */
    this.createHolder = function () {
        if(!this.checkModuleEnvironment()) {
            return false;
	} else {
            if(!myDiv) {
		var holder = document.createElement('div');
		holder.setAttribute("id", "immonetHpm-content");
		myWrapper.insertBefore(holder, myLinkBox);
                myDiv = document.getElementById("immonetHpm-content");
            }
	    if(!myScripts) {
		var iscripts = document.createElement('div');
		iscripts.setAttribute("id", "immonetHpm-scripts");
		myWrapper.insertBefore(iscripts, myDiv);
                myScripts = document.getElementById("immonetHpm-scripts");
            }

	    return true;
	}
    }

    /* SearchEntry JS */
    
    
    /*write configured search mask into the module */
    /* ########################################### */
    this.writeSearchMask = function () {
        this.appendJavaScript("" + myHost + "search/m/" + iID, "scripts", true, true);
    }

    this.writeLargeImage = function (page, cpp, searchs, exposeid, offset, sort, picnum) {
        this.immonetHpmPopup("" + myHost + "largeimage/m/" + iID + "/ihpmpage/" + page + "/ihpmcpp/" + cpp + "/ihpmSortBy/" + sort + "/ihpmexposeid/" + exposeid + "/ihpmss/" + searchs + "/ihpmoffset/" + offset + "/ihpmPicNum/" + picnum);
	this.lightupPage();
    }

    this.writeOffererView = function () {
        this.appendJavaScript("" + myHost + "offererview/m/" + iID, "scripts", true, true);
    }

    this.exposeShort = function (exposeid, immosearch) {
        this.appendJavaScript("" + myHost + "expose/m/" + iID + "/ihpmexposeid/" + exposeid + "/ihpmSearch/" + immosearch, "scripts", true, true);
    }

    this.setSearchMaskCode = function (icode) {
	this.appendData(icode);
    }

    /* empty up html code of the module */
    /* ################################ */
    this.clearData = function () {
	if(myDiv)
	    myDiv.innerHTML = "";
    };

    /* write html code into the module */
    /* ############################### */
    this.appendData = function (iData) {
        if(this.checkModuleEnvironment()) {
            myDiv.innerHTML += iData;
	}
    }

    
    /* load custom java script and append it */
    /* ######################################### */
    this.appendJavaScript = function (script_url, holder, replace, sendurl, external) {

	if(!this.checkModuleEnvironment()) {
	    return false;
	}

	//vorher löchen?
	if(holder == "scripts" && replace == true) {
	    for (a = 0; a < myScripts.childNodes.length; a ++) {
		myScripts.removeChild(myScripts.firstChild);
	    }
	}

	var java_script      = document.createElement('script');
	java_script.language = "JavaScript";
	java_script.type     = "text/javascript";
	java_script.charset = "utf-8";

	mysrc = script_url;

	if(!external) {
	    mysrc += "?ts=" + new Date().getTime();
	    if(sendurl) {
		 mysrc += "&u=" + escape(document.URL);
	    }
	    mysrc += "&h=" + document.location.host;
	}
	java_script.src     = mysrc;
	switch (holder) {
	    case "scripts":
		myScripts.appendChild(java_script);
		break;
	    case "head":
		myHead.appendChild(java_script);
		break;
	    default:
		myScripts.appendChild(java_script);
		break;
	}
    }

    /* load the sel java script and append it */
    /* ###################################### */

    this.getResultsSorted = function (page, cpp, params) {
	this.getResults(page, cpp, params, 1);
    }

    this.getResults = function (page, cpp, params, setsortcookie) {
	var sortsel = document.getElementById("ihpmSortBy");
	var sortdis = document.getElementById("ihpmSortDistrict");
	var sort = 2;
	var sortStr = '';
	var sortDisStr = '';
	if (sortsel) {
	    sort = sortsel.options[sortsel.selectedIndex].value;
	    var sortStr = "/ihpmSortBy/" + sort;
	}
	if (sortdis) {
	    sortd = sortdis.options[sortdis.selectedIndex].value;
	    var sortDisStr = "/ihpmSortDistrict/" + sortd;
	}
	if(params.indexOf('ihpmSortBy') >=  0) {
	    sort = params.substr(params.indexOf('ihpmSortBy') + 11);
	    document.cookie = "ihpmsorting="+sort+";path=/";
	} else if( sortStr == '') {
	    if(document.cookie) {
		cookie_array = document.cookie.split(';');
		for( i=0; i<cookie_array.length; i++) {
		    a = cookie_array[i];
		    cookiename = a.substr(0,a.search('='));
		    cookiewert = a.substr(a.search('=')+1,a.length);
		    if(this.trim(cookiename) == "ihpmsorting") {
			sort = cookiewert;
			sortStr = "/ihpmSortBy/" + cookiewert;
		    }
		}
	    }
	}
	if(setsortcookie) {
	    document.cookie = "ihpmsorting="+sort+";path=/";
	}

	this.appendJavaScript("" + myHost + "sel/m/" + iID + "/ihpmpage/" + page + "/ihpmcpp/" + cpp + sortStr + sortDisStr + params, "scripts", true);
    }

    /* load the expose java script and append it */
    /* ######################################### */
    this.getExpose = function (page, cpp, searchs, exposeid, offset, sort, sortdistrict) {
	this.appendJavaScript("http://module.immonet.de/js/image-switcher.js", "scripts", true);
	this.appendJavaScript("" + myHost + "expose/m/" + iID + "/ihpmpage/" + page + "/ihpmcpp/" + cpp + "/ihpmSortBy/" + sort + "/ihpmSortDistrict/" + sortdistrict + "/ihpmexposeid/" + exposeid + "/ihpmss/" + searchs + "/ihpmoffset/" + offset, "scripts", false);
    };

    this.getContactDetails = function (page, cpp, searchs, exposeid, offset, sort, sortdistrict) {
	this.appendJavaScript("" + myHost + "contactdetails/m/" + iID + "/ihpmpage/" + page + "/ihpmcpp/" + cpp + "/ihpmSortBy/" + sort + "/ihpmSortDistrict/" + sortdistrict +"/ihpmexposeid/" + exposeid + "/ihpmss/" + searchs + "/ihpmoffset/" + offset, "scripts", false);
    };

    /* load the media java script and append it */
    /* ######################################### */
    this.getPics = function (page, cpp, searchs, exposeid, offset, sort, sortdistrict, picnum) {
	this.appendJavaScript("http://module.immonet.de/js/image-switcher.js", "scripts", true);
	this.appendJavaScript("" + myHost + "pics/m/" + iID + "/ihpmpage/" + page + "/ihpmcpp/" + cpp + "/ihpmSortBy/" + sort + "/ihpmSortDistrict/" + sortdistrict +"/ihpmexposeid/" + exposeid + "/ihpmss/" + searchs + "/ihpmoffset/" + offset + "/ihpmPicNum/" + picnum, "scripts", false);
    }

    /* load the contact java script and append it */
    /* ######################################### */
    this.sendContact = function () {

	//collect the form data
	
	iAnrede = document.ihpmForm.ihpmContactAnrede.options[document.ihpmForm.ihpmContactAnrede.selectedIndex];
	iName = document.ihpmForm.ihpmContactName;
	iEmail = document.ihpmForm.ihpmContactEmail;
	iPhone = document.ihpmForm.ihpmContactPhone;
	iImmonetNr = document.ihpmForm.ihpmExposeId;
	iMessage = document.ihpmForm.ihpmContactRemarks;
	iVisit = document.ihpmForm.ihpmExposeCheckVisit;
	iInfo = document.ihpmForm.ihpmExposeCheckInfo;

	iError = document.getElementById("ihpmContactError");
	iSuccess = document.getElementById("ihpmContactSuccess");
	
	email_error = false;
	phone_error = false;

	if( iName.value == "" || iImmonetNr.value == "" ||
	    (iPhone.value != "" && !this.validatePhone(iPhone.value)) ||
	    (iEmail.value != "" && !this.validateEmail(iEmail.value)) ||
	    (iEmail.value == "" && iPhone.value == ""))
	 {
	    var errString = "Bitte ergänzen oder korrigieren Sie Ihre Angaben in den rot umrandeten Feldern.<ul>";

	    if(iImmonetNr.value == "") {
		errString += "<li>Objekt unbekannt</li>";
	    }
	    if(iName.value == "") {
		errString += "<li>Name fehlt</li>";
		iName.setAttribute("class", "ihpmXL ihpmErrorField");
	    } else {
		iName.setAttribute("class", "ihpmXL");
	    }
	     if(iEmail.value == "" && iPhone.value == "") {
		errString += "<li>Telefonnummer oder E-Mail-Adresse fehlt</li>";
		email_error = true;
		phone_error = true;
	    }
	    if(iEmail.value != "" && !this.validateEmail(iEmail.value)) {
		errString += "<li>E-Mail-Adresse (Format pr&uuml;fen)</li>";
		email_error = true;
	    }
	    if(iPhone.value != "" && !this.validatePhone(iPhone.value)) {
		errString += "<li>Telefonnummer (Format pr&uuml;fen)</li>";
		phone_error = true;
	    } 
	    if(email_error) {
		iEmail.setAttribute("class", "ihpmXL ihpmErrorField");
	    } else {
		iEmail.setAttribute("class", "ihpmXL");
	    }
	    if(phone_error) {
		iPhone.setAttribute("class", "ihpmXL ihpmErrorField");
	    } else {
		iPhone.setAttribute("class", "ihpmXL");
	    }

	    errString += "</ul>";

	    if(iError) {
		iError.innerHTML = errString;
		iError.style.display = "block";
	    } else {
		alert(errString);
	    }

	    if(iSuccess) {
		iSuccess.style.display = "none";
	    }
	 } else {
	    if(iError) {
		iError.innerHTML = "";
		iError.style.display = "none";
	    }
	     if(iSuccess) {
		iSuccess.style.display = "none";
	    }

	    this.dimPage();

	    //formular versenden für javascript
	    var iinf = (iInfo.checked == true) ? 1 : 0;
	    var ivis = (iVisit.checked == true) ? 1 : 0;
	    var imes = (iMessage.value != '') ? encodeURI(iMessage.value.replace(/[\r\n]+/g, " ")) : 'keine';
	    var myphone = (iPhone.value != '') ? iPhone.value : '-';
	    var mymail = (iEmail.value != '') ? iEmail.value : '-';	    
	    
	    this.appendJavaScript("" + myHost + "contact/m/" + iID + "/ihpmexposeid/" + iImmonetNr.value + "/ihpmanrede/" + iAnrede.value + "/ihpmname/" + encodeURI(iName.value) + "/ihpmemail/" + mymail + "/ihpmtelefon/" + myphone + "/ihpmmessage/" + imes + "/ihpminfo/" + iinf + "/ihpmvisit/" + ivis, "scripts", false);

	 }

	//formular nicht abschicken bei js version
	return false;
    }

    /* load the contact java script and append it */
    /* ######################################### */
    this.sendContactLong = function () {

	//collect the form data	
	iAnrede = document.ihpmForm.ihpmContactAnrede.options[document.ihpmForm.ihpmContactAnrede.selectedIndex];
	iName = document.ihpmForm.ihpmContactName;
	iEmail = document.ihpmForm.ihpmContactEmail;
	iPhone = document.ihpmForm.ihpmContactPhone;
	iImmonetNr = document.getElementById('ihpmExposeId');
	iMessage = document.ihpmForm.ihpmContactRemarks;
	iVisit = document.ihpmForm.ihpmExposeCheckVisit;
	iInfo = document.ihpmForm.ihpmExposeCheckInfo;

	iError = document.getElementById("ihpmContactError");
	iSuccess = document.getElementById("ihpmContactSuccess");

	iFirstname = document.getElementById("ihpmContactFirstname");
	iStreetHouseNo = document.getElementById("ihpmContactStreetHouseNo");
	iZip = document.getElementById("ihpmContactZip");
	iTown = document.getElementById("ihpmContactTown");

	iName.setAttribute("class", "ihpmXL");
	iEmail.setAttribute("class", "ihpmXL");
	iPhone.setAttribute("class", "ihpmXL");
	iStreetHouseNo.setAttribute("class", "ihpmXL");
	iZip.setAttribute("class", "ihpmXS");
	iTown.setAttribute("class", "ihpmXL");

	name_error = false;
	email_error = false;
	phone_error = false;
//	streethousenumber_error = false;
//	zip_error = false;
//	town_error = false;

	if( iName.value == "" || iImmonetNr.value == "" ||
	    (iPhone.value != "" && !this.validatePhone(iPhone.value)) ||
	    (iEmail.value != "" && !this.validateEmail(iEmail.value)) ||
	    (iEmail.value == "" && iPhone.value == "") ||
	    iStreetHouseNo.value == "" ||
	    iZip.value == "" ||
	    iTown.value == "")
	 {
	    var errString = "Bitte ergänzen oder korrigieren Sie Ihre Angaben in den rot umrandeten Feldern.<ul>";

	    if(iImmonetNr.value == "") {	       
		errString += "<li>Objekt unbekannt</li>";
	    }
	    if(iName.value == "") {
	        name_error = true;
		errString += "<li>Name fehlt</li>";
		iName.setAttribute("class", "ihpmXL ihpmErrorField");
	    } else {
		iName.setAttribute("class", "ihpmXL");
	    }

	    if(iStreetHouseNo.value == "") {
	        //streethousenumber_error = true;
		errString += "<li>Straße/HNr fehlt</li>";
		iStreetHouseNo.setAttribute("class", "ihpmXL ihpmErrorField");
	    } else {
		iStreetHouseNo.setAttribute("class", "ihpmXL");
	    }

	    if(iZip.value == "") {
	        //zip_error = true;
		errString += "<li>PLZ fehlt</li>";
		iZip.setAttribute("class", "ihpmXS ihpmErrorField");
	    } else {
		iZip.setAttribute("class", "ihpmXS");
	    }
	    
	    if(iTown.value == "") {
	        //town_error = true;
		errString += "<li>Ort fehlt</li>";
		iTown.setAttribute("class", "ihpmXL ihpmErrorField");
	    } else {
		iTown.setAttribute("class", "ihpmXL");
	    }
	     if(iEmail.value == "" && iPhone.value == "") {
		errString += "<li>Telefonnummer oder E-Mail-Adresse fehlt</li>";
		email_error = true;
		phone_error = true;
	    }
	    if(iEmail.value != "" && !this.validateEmail(iEmail.value)) {
		errString += "<li>E-Mail-Adresse (Format pr&uuml;fen)</li>";
		email_error = true;
	    }
	    if(iPhone.value != "" && !this.validatePhone(iPhone.value)) {
		errString += "<li>Telefonnummer (Format pr&uuml;fen)</li>";
		phone_error = true;
	    }
	    if(email_error) {
		iEmail.setAttribute("class", "ihpmXL ihpmErrorField");
	    } else {
		iEmail.setAttribute("class", "ihpmXL");
	    }
	    if(phone_error) {
		iPhone.setAttribute("class", "ihpmXL ihpmErrorField");
	    } else {
		iPhone.setAttribute("class", "ihpmXL");
	    }

	    errString += "</ul>";

	    if(iError) {
		iError.innerHTML = errString;
		iError.style.display = "block";
	    } else {
		alert(errString);
	    }

	    if(iSuccess) {
		iSuccess.style.display = "none";
	    }
	 } else {
	    if(iError) {
		iError.innerHTML = "";
		iError.style.display = "none";
	    }
	     if(iSuccess) {
		iSuccess.style.display = "none";
	    }

	    this.dimPage();	    

	    //formular versenden für javascript
	    var iinf = (iInfo.checked == true) ? 1 : 0;
	    var ivis = (iVisit.checked == true) ? 1 : 0;
	    var imes = (iMessage.value != '') ? encodeURI(iMessage.value.replace(/[\r\n]+/g, " ")) : 'keine';
	    var myphone = (iPhone.value != '') ? iPhone.value : '-';
	    var mymail = (iEmail.value != '') ? iEmail.value : '-';
	    var myFirstname = (iFirstname != null && iFirstname != undefined && iFirstname.value != '') ? iFirstname.value : '-';
	    var myStreetHouseNo = (iStreetHouseNo != null && iStreetHouseNo != undefined && iStreetHouseNo.value != '') ? iStreetHouseNo.value : '-';
	    var myZip = (iZip != null && iZip != undefined && iZip.value != '') ? iZip.value : '-';
	    var myTown = (iTown != null && iTown != undefined && iTown.value != '') ? iTown.value : '-';	    
	     
	    this.appendJavaScript("" + myHost + "contactlong/m/" + iID + "/ihpmexposeid/" + iImmonetNr.value + "/ihpmanrede/" + iAnrede.value + "/ihpmname/" + encodeURI(iName.value) + "/ihpmemail/" + mymail + "/ihpmtelefon/" + myphone + "/ihpmmessage/" + imes + "/ihpminfo/" + iinf + "/ihpmvisit/" + ivis+ "/ihpmfirstname/" + myFirstname + "/ihpmstreet/" + myStreetHouseNo + "/ihpmcity/" + myTown + "/ihpmpostcode/" + myZip, "scripts", false);
	 }

	//formular nicht abschicken bei js version
	return false;
    }

    /* show success box if contact was sent */
    /* #################################### */
    this.contactSuccess = function () {

	this.lightupPage();

	iName = document.ihpmForm.ihpmContactName;
	iEmail = document.ihpmForm.ihpmContactEmail;
	iPhone = document.ihpmForm.ihpmContactPhone;
	
	if(iName && iEmail && iPhone) {
	    iName.setAttribute("class", "ihpmXL");
	    iPhone.setAttribute("class", "ihpmXL");
	    iEmail.setAttribute("class", "ihpmXL");
	}
    }

    /* load the print java script and append it */
    /* ######################################### */
    this.getPrint = function (page, cpp, searchs, exposeid) {
	//this.appendJavaScript("" + myHost + "print/m/" + iID + "/ihpmpage/" + page + "/ihpmcpp/" + cpp + "/ihpmexposeid/" + exposeid + "/ihpmss/" + searchs, "scripts", true);
	this.immonetHpmPopup("" + myHost + "print/m/" + iID + "/ihpmpage/" + page + "/ihpmcpp/" + cpp + "/ihpmexposeid/" + exposeid + "/ihpmss/" + searchs);
	this.lightupPage();
    }

    /* get the custom css for the module */
    /* ################################# */
    this.getCss = function (iID) {
        if(document.createStyleSheet) {
            document.createStyleSheet( myHost + "css/m/" + iID );
	} else {
            var modulCss = document.createElement("link");
            modulCss.rel = "stylesheet";
            modulCss.type = "text/css";
            modulCss.href =  myHost + "css/m/" + iID;
            modulCss.media = "screen";
            myWrapper.appendChild(modulCss);
	}
    }

    /* load the history java script and append it */
    /* ########################################### */
    this.loadHistoryScript = function () {

	this.appendJavaScript("http://module.immonet.de/js/unFocus-History-p.js", "head");
	this.appendJavaScript("http://module.immonet.de/js/history-keeper.js", "head");
	//this.appendJavaScript("http://module.immonet.de/js/jquery-1.3.2.js", "head");

    }

    /* load GA tracking java script and append it */
    /* ########################################### */
    this.loadTrackingScript = function () {
	this.appendJavaScript("http://www.google-analytics.com/ga.js", "head", true, false, true);
    }

    /* executes the function and puts it in "the brain" */
    /* ################################################ */
    runMyFunction = function (functionString) {

	//first hide the old content
	immonetHpModul.dimPage();

	//default function
	myFunction = myFunctions["start"] + "(";

	if(functionString != "") {

	    //split the arguments into an aray
	    myParams = functionString.split(";");

	    //find the matching function name
	    if(myParams.length >= 0 ) {
		if(myFunctions[myParams[0]] != undefined) {
		    myFunction = myFunctions[myParams[0]] + "(";
		}
	    }

	    //add arguments if there are any
	    if(myParams.length > 1 ) {
		for (var i = 1; i < (myParams.length); i++) {
		    myFunction += "'" + myParams[i] + "'";
		    if(i < (myParams.length - 1))
			myFunction += ",";
		}
	    }

	    myFunction += ");";

	}

        //execute the function
	eval("immonetHpModul." + myFunction);

    }

    /* the history listener - executes the functions too */
    /* ################################################# */
    this.historyListener = function (historyHash) {
	runMyFunction(historyHash);
    }

    /* load the history listener and make it listen */
    /* ############################################ */
    this.loadHistoryListener = function () {
        unFocus.History.addEventListener('historyChange', immonetHpModul.historyListener);
	//check if this is a deeplink
	if(document.URL.indexOf("#") > 0) {
	    deeplink = document.URL.substring(document.URL.indexOf("#")+1, document.URL.length);
	    immonetHpModul.execute(deeplink);
	} else {
	    immonetHpModul.execute("start");
	}
    }

    /* check if we have the unFocus object and load the listener */
    /* ######################################################### */
    this.initHistory = function () {
	if( typeof(unFocus) == 'undefined') {
	    window.setTimeout("immonetHpModul.initHistory()" ,100);
	} else {
	    immonetHpModul.loadHistoryListener();
	}
    }

    /* execute any function called and save it in history */
    /* ################################################## */
    this.execute = function (functionToExecute) {
    
	loadComplete = document.getElementById("ihpm_loaded_complete");
	if(loadComplete) {
	    loadComplete.innerHTML = "outdated";
	}
	var actfunc = functionToExecute.substring(0, functionToExecute.indexOf(";"));
	if(actfunc != "print" && actfunc != "contact" && actfunc != "sort" && actfunc != "contactlong") {
	    unFocus.History.addHistory(functionToExecute);
	    this.scrollWhenLoaded();
	} else  {
	    runMyFunction(functionToExecute);
	} 
    }

    /* check if site is loaded an scroll to top */
    /* ######################################## */
    this.scrollWhenLoaded = function () {
	loadComplete = document.getElementById("ihpm_loaded_complete");
	if( loadComplete && loadComplete.innerHTML != "outdated" ) {
	    window.scrollTo(0, 0);
	} else {
	    window.setTimeout(immonetHpModul.scrollWhenLoaded,250);
	}
    }

    /* Dim page and show the spinner */
    /* ############################# */
    this.dimPage = function ()
    {
	//$("#immonetHpm-content").fadeTo("slow", 0.2);
	myDiv.className = "ihpmDimmer";
	
	var spinner = document.createElement('img');
	spinner.setAttribute("id", "immonetHpm-spinner");
	spinner.setAttribute("src", "http://module.immonet.de//images/spinner.gif");
	myWrapper.insertBefore(spinner, myDiv);

	//center the spinner
	var centerX, centerY;
	var scrolledX, scrolledY;
	var mySpinner = document.getElementById("immonetHpm-spinner");

	if( self.innerHeight ) {
	    centerX = self.innerWidth;
	    centerY = self.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
	    centerX = document.documentElement.clientWidth;
	    centerY = document.documentElement.clientHeight;
	} else if( document.body ) {
	    centerX = document.body.clientWidth;
	    centerY = document.body.clientHeight;
	}

	if( self.pageYOffset ) {
	    scrolledX = self.pageXOffset;
	    scrolledY = self.pageYOffset;
	} else if( document.documentElement && document.documentElement.scrollTop ) {
	    scrolledX = document.documentElement.scrollLeft;
	    scrolledY = document.documentElement.scrollTop;
	} else if( document.body ) {
	    scrolledX = document.body.scrollLeft;
	    scrolledY = document.body.scrollTop;
	}

	if(mySpinner) {
	    mySpinner.style.left = (scrolledX + centerX / 2) + "px";
	    mySpinner.style.top = (scrolledY + centerY / 2) + "px";
	}

    }

    /* Light page up and remove the spinner */
    /* #################################### */
    this.lightupPage = function ()
    {
	//$("#immonetHpm-content").fadeTo("fast", 1.0);
	myDiv.className = "";
	var spinner = document.getElementById("immonetHpm-spinner");
	if(spinner) {
	    myWrapper.removeChild(spinner);
	}
    }

    /* Helper methos to execute JavaScript that has been   */
    /* loaded with innerHTML within the appenData() method */
    /* ################################################## */
    this.execAdditionalJS = function ()
    {
	
	var node = document.getElementById("ihpmAdditionalScripts");

	var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
	var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
	var bMoz = (navigator.appName == 'Netscape');

	if (!node) return;

	/* IE wants it uppercase */
	//var st = node.getElementsByTagName("SCRIPT");
	var st = node.childNodes;
	var strExec;

	for(var i=0;i<st.length; i++)
	{
	    if (bSaf) {
		strExec = st[i].innerHTML;
		st[i].innerHTML = "";
	    } else if (bOpera) {
		strExec = st[i].text;
		st[i].text = "";
	    } else if (bMoz) {
		strExec = st[i].textContent;
		st[i].textContent = "";
	    } else {
		strExec = st[i].text;
		try { st[i].text = ""; }
		catch (ex) {}
	    }

	    try {
		var x = document.createElement("script");
		x.type = "text/javascript";

		/* In IE we must use .text! */
		if ((bSaf) || (bOpera) || (bMoz))
		    x.innerHTML = strExec;
		else
		    x.text = strExec;

		myScripts.appendChild(x);

	    } catch(e) {
		alert(e);
	    }
	}
    }

    /* validate Email */
    /* ############## */
    this.validateEmail = function (s)
    {
	var a = false;
	var res = false;
	if(typeof(RegExp) == 'function')
	{
	    var b = new RegExp('abc');
	    if(b.test('abc') == true){a = true;}
	}

	if(a == true)
	{
	    reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                   '(\\@)([a-zA-Z0-9\\-\\{3,}]+)'+
                   '(\\.)([a-zA-Z]{2,4})$');
	    res = (reg.test(s));
	}
	else
	{
	    res = (s.search('@') >= 1 &&
	    s.lastIndexOf('.') > s.search('@') &&
	    s.lastIndexOf('.') >= s.length-5)
	}

	return res;
    }

    /* validate Phone */
    /* ############## */
    this.validatePhone = function (s)
    {
	var a = false;
	var res = false;

	if(typeof(RegExp) == 'function')
	{
	    var b = new RegExp('abc');
	    if(b.test('abc') == true){a = true;}
	}

	if(a == true)
	{
	    reg = new RegExp(/^[\d\/\\\s+-]+$/);
	    res = (reg.test(s));
	}
	else
	{
	    return true;
	}

	return res;

    }

    /* open a popup window */
    /* ################### */
    this.immonetHpmPopup = function(url, width, height) {
	var immonetHpmNewWindow;
        immonetHpmNewWindow = window.open(url, "immonetHpmPopupXy", "width=" + width + ",height=" + height + ",status=yes,scrollbars=yes,resizable=yes");
        if (immonetHpmNewWindow && immonetHpmNewWindow.focus) {immonetHpmNewWindow.focus()}
    }

     /* trim function */
    /* ################### */
    this.trim = function (str, chars) {
	return this.ltrim(this.rtrim(str, chars), chars);
    }

    this.ltrim =  function (str, chars) {
	chars = chars || "\\s";
	str = str + "";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
    }

    this.rtrim = function(str, chars) {
	chars = chars || "\\s";
	str = str + "";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
    }

};

function ihpmHelperObjectProperties (obj) {
    var str = "";
    for(prop in obj) {
	str += prop + " value :" + obj[prop] + "\n";
    }
    alert(str);
}

function ihpmAddOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var ihpmOldOnload = window.onload;
      window.onload = function ( e ) {
        ihpmOldOnload( e );
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}

function ihpmRenderHpm() {
    immonetHpModul = new ImmonetHpModul;
    immonetHpModul.initialize();
}

ihpmAddOnloadEvent(ihpmRenderHpm);

/*
window.onload = function () {
    immonetHpModul = new ImmonetHpModul;
    immonetHpModul.initialize();
}
*/

//]]>
