// JavaScript Document

var strCMailBody="";
var strCSubject="";
var strMailBody="";
var strSubject="";
var strSender="";
var iMessageCount=-1;
var strMailMessage="";
var strContactUrl="";
var strInfoUrl="";
var strContactUrl="";
var strGSUrl="";
var strFPUrl="";
var strPSUrl="";
var strPSMessage="";
var strPSData="";
var strContactData="";
var strWindowTitle="";
var strFailedErrorTimeout="";
var strFailedError="";
var WebService="WebServiceDE.asmx";
var strProdInfoLink = "";

var dTimeout   = 5000;

function Init()
{
    AmbienteSlider.initSlider("SliderAmbienteImg", "sliderHouseBtnUp", "sliderHouseBtnDown", "containerHouse", "contentHouse");
    SelectionSlider.initSlider("SliderSelectionImg", "sliderSelectionBtnUp", "sliderSelectionBtnDown", "containerChoice", "contentChoice");

    Sys.Net.WebServiceProxy.invoke(strWebService, 
        "Command", false,{"strCommand":"Init", "strParameter":""}, OnSucceeded, OnFailed,null,dTimeout);
}

function Send(cmd, param)
{
    Sys.Net.WebServiceProxy.invoke(strWebService, 
        "Command", false,{"strCommand":cmd, "strParameter":param}, OnSucceeded, OnFailed,null,dTimeout);
}


// This is the callback function invoked 
// if the Web service succeeded.
function OnSucceeded(result, eventArgs)
{
    Command_callback(result);
}

// This is the callback function invoked 
// if the Web service failed.
function OnFailed(error)
{
    var strError = "";
    if (error.get_timedOut())
    {
        strError = strFailedErrorTimeout;
    }
    else
    {
        strError = strFailedError;
        strError = strError.replace("@Error@", error.get_message());
    }
    if (strError != "")
    {
        var bResult = window.confirm(strError);
        if(bResult)
        {
            Init();
        }
    }
}

//preload image for buttons
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//reset image for buttons
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//find image for buttons
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//swap image for buttons
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Show selection
function showselection()
{
	alert ('showselection')
}
	
//Show selection
function resetselection()
{
	alert ('resetselection')
}	
	
	
// Nur zur Initialisierung
function Command_callback(res)
{
	window.status="";
	try	{
		var stateMessage=res;
		
		if (-1 == iMessageCount || stateMessage._iMessageCount == iMessageCount + 1)
		{
    		iMessageCount = stateMessage._iMessageCount;
			for (var iIdx=0; iIdx<stateMessage._arrCmds.length; iIdx++)
			{
				var cmd=stateMessage._arrCmds[iIdx];
				var strCmd=cmd._strCommand;
				var strValue=cmd._strValue;
				var strParam=cmd._strParam;
				switch (strCmd)
				{
				
					case "SetContent":
						var elem=document.getElementById(strValue);
						if (null != elem)
						{
						    elem.innerHTML=strParam;
						    if (elem.style.top!=0)
							    elem.style.top=0;
						}
					break;
					case "SetStyle":
					    SetStyle(strValue, strParam);
					break;
					case "AddStyle":
					    AddStyle(strValue, strParam);
					break;
					case "RemoveStyle":
					    RemoveStyle(strValue, strParam);
					break;
					case "SetFirstStyle":
						var elem=document.getElementById(strValue);
						if (null != elem)
						{
						    var strNewClass = elem.className;
						    var arrClass    = strNewClass.split(" ");
    						
						    arrClass[0] = strParam;
						    strNewClass = "";
						    for (var i=0;i < arrClass.length;i++)
						    {
							    if (strNewClass.length > 0)
							    {
								    strNewClass += " ";
							    }
							    strNewClass += arrClass[i];
						    }
						    elem.className=strNewClass;
						}
					break;
					case "SetVisibility":
						var elem=document.getElementById(strValue);
						if (null != elem)
						{
    						elem.style.visibility = strParam;
    					}
					break;
					case "UpdateSlider":
					    Slider.updateSlider(strValue, strParam);
					break;	
					case "SetImg":
						var elem=document.getElementById(strValue);
						if (null != elem)
						{
						    elem.src=strParam;
						    elem.imgNotHo=null;
						}
					break;
					case "SetVar":
						window[strValue]=strParam;
					break;
					case "DisableZoom":
                        var elem=document.getElementById("DynImage");
                        if (null != elem)
                        {
	                        elem.title='';
	                        elem.onclick=null;
                        }
					break;
					case "Reload":
						window.location.replace(window.location);;
					break;
	                case "SetTitle":
	                    strWindowTitle = strValue;
	                    break;
				}
			}
		}
		else if (null != stateMessage)
		{
			//Message verloren 
    		iMessageCount = stateMessage._iMessageCount;
			window.setTimeout("Send('Init', '');",10);
		}
	}
	catch(e) 
	{
		window.status="Fehler:"+e;
	}
}

function SetStyle(ID, strStyle)
{
    var elem=document.getElementById(ID);
    if (null != elem)
    {
	    elem.className=strStyle;
    }
}

function AddStyle(ID, strStyle)
{
    var elem=document.getElementById(ID);
    var bAdd=true;
    if (null != elem)
    {
        var strNewClass = elem.className;
        var arrClass    = strNewClass.split(" ");
    	
        strNewClass = "";
        for (var i=0;i < arrClass.length;i++)
        {
            if (strNewClass.length > 0)
            {
	            strNewClass += " ";
            }
            strNewClass += arrClass[i];
            if (arrClass[i] ==  strStyle)
            {
                bAdd = false;
	        }
        }
        if (bAdd)
        {
	        strNewClass += " ";
	        strNewClass += strStyle;
	    }
        elem.className=strNewClass;
    }
}

function RemoveStyle(ID, strStyle)
{
	var elem=document.getElementById(ID);
	if (null != elem)
	{
	    var strNewClass = elem.className;
	    var arrClass    = strNewClass.split(" ");
		
	    strNewClass = "";
	    for (var i=0;i < arrClass.length;i++)
	    {
	        if (arrClass[i] !=  strStyle)
	        {
		        if (strNewClass.length > 0)
		        {
			        strNewClass += " ";
		        }
		        strNewClass += arrClass[i];
		    }
	    }
	    elem.className=strNewClass;
	}
}


function OpenPopup(width, height, title, url, param)
{
	if ('no' == param)
	{
		mywin = window.open(url, title);
	}
	else
	{
		var xsize = screen.availWidth;
		var ysize = screen.availHeight;

		var x=(xsize-width)/2, y=(ysize-height)/2;

		mywin = window.open(url, title, param+', width='+width+', height='+height+', left='+x+', top='+y);
	}
	
	if (null != mywin)
	{
		mywin.focus();
	}
}

function MoreInfo(strUrl) 
{
    var myUrl = strUrl;
    if (null != myUrl && "" != myUrl)
    {
        myUrl = strProdInfoLink;
    }
    if (null != myUrl && "" != myUrl)
    {
        OpenPopup(840, 700, 'Extern', myUrl, 'no');
    }
    else
    {
        alert(strMailMessage);
    }
}

function Info()
{
	if ("" != strInfoUrl)
	{
		OpenPopup(840, 700, 'Extern', strInfoUrl, 'no');
	}
}

function Argumente()
{
	var arg = null;
	var location = window.location.search;
	
	if (location.length > 0)
	{
		arg = new Array()
		location = location.substr(1, location.length - 1);
		arg = location.split("&");
	} 
	return arg;
}

function VArgumente()
{
	var erg = null;
	var arg = new Array();

	erg = Argumente();
	
	if (null != erg)
	{
		for (i=0; i < erg.length; i++) 
		{
			var x = new Array();
			x =  erg[i].split("=");
			arg[x[0]] = x[1];
		}
	}
	return arg;
}

function SetTitle(strTitle)
{
	var strMyTitle = strTitle;
	if ('undefined' == typeof(strMyTitle))
	{
		var arg  = VArgumente();
		if (null != arg)
		{
			strMyTitle = arg['title'];
		}
	}

	var strWinTitle = window.document.title;
	var strName     = "";
	if (null != strMyTitle && "" != strMyTitle)
	{
		strName  = strMyTitle;
	}
	strWinTitle = strWinTitle.replace("Gallery", strName);
	window.document.title = unescape(strWinTitle);
}

function ZoomWindow(x, y)
{ 
	var elem=document.getElementById("DynImage");
	if (null != elem)
	{
		var strImage = elem.src;
		var iPos = strImage.indexOf("?");
		if (0 <= iPos)
		{
			var strTeil = strImage.substring(iPos, strImage.length-1);
			strImage = strTeil;
		}
		iPos = strImage.indexOf("&");
		if (0 <= iPos)
		{
			var strTeil = strImage.substring(0, iPos);
			strImage = strTeil;
		}
		if (null != strWindowTitle && "" != strWindowTitle)
		{
			strImage = strImage + "&" + "title=" + strWindowTitle;
		}
		OpenPopup(x, y, 'Zoom', 'zoom.htm'+strImage, toolbar='no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, fullscreen=no');
	}
}
	
function InfoWindow()
{ 
	var strParam = "";
	if (null != strWindowTitle && "" != strWindowTitle)
	{
		strParam = strParam + "?" + "title=" + strWindowTitle;
	}
	OpenPopup(570, 200, 'Info', 'info.htm'+strParam, toolbar='no, location=no, directories=no, status=no, menubar=no');
}

function InfoWindow()
{ 
	var strParam = "";
	if (null != strWindowTitle && "" != strWindowTitle)
	{
		strParam = strParam + "?" + "title=" + strWindowTitle;
	}
	OpenPopup(570, 200, 'Info', 'info.htm'+strParam, toolbar='no, location=no, directories=no, status=no, menubar=no');
}	

function HelpWindow()
{ 
	var strParam = "";
	if (null != strWindowTitle && "" != strWindowTitle)
	{
		strParam = strParam + "?" + "title=" + strWindowTitle;
	}
	OpenPopup(840, 700, 'Help', 'help.htm' + strParam, toolbar='no, location=no, directories=no, status=no, menubar=no, scrollbars=no');
}

function SendMail()
{
	if ("" == strCMailBody)
	{
		alert(strMailMessage);
	}
	else
	{
		var strParam  = "";
		if ("" != strCSubject)
		{
			strParam += "subject=" + strCSubject;
			strParam += "&";
		}
		strParam += "body=" + strCMailBody;
		strParm = "mailto:?" + strParam
		window.location.href =  strParm;
	}
}

function Contact(strTitle)
{
	if ("" == strMailBody)
	{
		alert(strMailMessage);
	}
	else
	{
		var strParam  = "?";
		if (null != strWindowTitle && "" != strWindowTitle)
		{
			strParam = strParam + "title=" + strWindowTitle;
			strParam = strParam + "&";
		}
		if (null != strSender && "" != strSender)
		{
			strParam = strParam + "sender=" + strSender;
			strParam = strParam + "&";
		}
		if ("" != strContactUrl)
		{
			strParam += "ContactUrl=" + strContactUrl;
			strParam += "&";
		}
		if ("" != strSubject)
		{
			strParam += "Betreff=" + strSubject;
			strParam += "&";
		}
		strParam += "Produktdaten=" + strMailBody;
		OpenPopup(640, 500, 'Contact', "Contact.aspx"+strParam, '');
	}
}

function SelectProduct()
{
	if ("" == strPSData)
	{
		alert(strMailMessage);
	}
	else 
	{
	    if ("" == strPSUrl)
	    {
    		alert(strPSMessage);
	    }
	    else
	    {
		    var strParam  = "?" + strPSData;
		    var strUrl    = strPSUrl + strParam; 
    		window.location.href = strUrl;
		}
	}
}

function ButtonClick(Obj)
{
	if (null != Obj)
	{
		Send( "ButtonClick", Obj.id);
	}
}

function CloseButtonClick()
{
	window.close();
}

function ChangeSource(Obj, strNewSource)
{
	if (null != Obj)
	{
	    Obj.src = strNewSource;
	}

}

function ShowFotoPlus()
{
	if ("" != strFPUrl)
	{
		OpenPopup(840, 700, 'Extern', strFPUrl, 'no');
	}
}

function ShowGestallungsSerivce()
{
	if ("" != strGSUrl)
	{
		OpenPopup(840, 700, 'Extern', strGSUrl, 'no');
	}
}

function ButtonHoverChoice(Obj, strDIVStyle, strTextStyle)
{
	if (null != Obj)
	{
	    var strDIV_ID, strTextID;
	    
	    strDIV_ID = Obj.id;
	    strTextID = Obj.id;
	    
	    strTextID = strTextID.replace("CHOICE_", "TEXT_");
	    
	    SetStyle(strDIV_ID, strDIVStyle);
	    AddStyle(strTextID, strTextStyle);
	}
}

function ButtonUnhoverChoice(Obj, strDIVStyle, strTextStyle)
{
	if (null != Obj)
	{
	    var strDIV_ID, strTextID;
	    
	    strDIV_ID = Obj.id;
	    strTextID = Obj.id;
	    
	    strTextID = strTextID.replace("CHOICE_", "TEXT_");
	    SetStyle(strDIV_ID, strDIVStyle);
	    RemoveStyle(strTextID, strTextStyle);
	}
}

function ButtonHoverText(Obj, strStyle)
{
	if (null != Obj)
	{
	    AddStyle(Obj.id, strStyle);
	}
}

function ButtonUnhoverText(Obj, strStyle)
{
	if (null != Obj)
	{
	    RemoveStyle(Obj.id, strStyle);
	}
}

function ButtonHoverImg(Obj)
{
	if (null != Obj)
	{
		var strAttrib = Obj.getAttribute("imgHo");
		
		if (strAttrib)
		{
			Obj.setAttribute("imgNotHo", Obj.src);
			Obj.src = strAttrib;
		}
	}
}

function ButtonUnhoverImg(Obj)
{
	if (null != Obj)
	{
		var strAttrib = Obj.getAttribute("imgNotHo");
		
		if (strAttrib)
		{
			Obj.src = strAttrib;
			Obj.setAttribute("imgNotHo", null);
		}
	}
}

	
