/***************************************
* Closeable Popup Panel
****************************************/

//Struct for Collapse / Expand:
function CloseableItem(element, Preview, Detail, ExpandToolTip, CollapseToolTip, expandIconID)
{
	this.element = element;
	this.Preview = Preview;
	this.Detail= Detail;
	this.ExpandToolTip = ExpandToolTip;
	this.CollapseToolTip = CollapseToolTip;
	this.expandIconID = expandIconID;
}

function ExpandAll(expArr)
{	
	for(var i = 0; i< expArr.length; i++)
	{
		var Details		= document.getElementById(expArr[i].Detail);
		if(Details != null)
			Details.style.display="block";
		
		var Preview		= document.getElementById(expArr[i].Preview);
		
		if(Preview != null)
			Preview.style.display="none";
			
		var expandIcon	= document.getElementById(expArr[i].expandIconID);
		expandIcon.innerHTML = "-";			
	}
}

function CollapseAll(expArr)
{	
	for(var i = 0; i< expArr.length; i++)
	{	    
		var Details		= document.getElementById(expArr[i].Detail);
		
		if(Details != null)
			Details.style.display="none";
		
		var Preview		= document.getElementById(expArr[i].Preview);
		
		if(Preview != null)
			Preview.style.display="block";
		var expandIcon	= document.getElementById(expArr[i].expandIconID);
		expandIcon.innerHTML = "+";	
	}
}

function ExpandCloseAblePopup(element, Preview, Detail, ExpandToolTip, CollapseToolTip, expandIconID)
{
	var Details		= document.getElementById(Detail);
	var Preview		= document.getElementById(Preview);
	var expandIcon	= document.getElementById(expandIconID);
	var link		= document.getElementById(element+ "Link");
	
	if(Details == null)
		return;
		
	if(Details.style.display == "none")
	{	
		Details.style.display="block";
		
		if(Preview != null)
			Preview.style.display = "none"			
		expandIcon.innerHTML = "-";		
		
		if(link != null)
		{
			link.title	= CollapseToolTip;
			link.alt		= CollapseToolTip;
		}
	}
	else
	{
		Details.style.display="none";
		if(Preview != null)
			Preview.style.display = "block"
		expandIcon.innerHTML	= "+";
		
		if(link != null)
		{
			link.title		= ExpandToolTip;
			link.alt			= ExpandToolTip;
		}
	}
	
}

/***************************************
* END Closeable Popup Panel
****************************************/

/***************************************
* Number Search Panel - Can only be set Once Per Page!
****************************************/
var hasCleared = false;

function ClearInputText(inpID)
{	
	if(!hasCleared)
	{
		var inpCont = document.getElementById(inpID);		
		inpCont.value="";
	}
	hasCleared = true;
}

/***************************************
* END Number Search Panel
****************************************/

/**************************************
* Location Plan Popup
***************************************/
var locPopID= null;
var hideLocationPopupTimer;
var locationPopupActive = false;
var locationPopupTimeout = 5000;
var locationHover = false;

//Use Hover Defines that we use A Timeout!!
function ShowLocationPopup(e, ControlID, useHover, useClick) {	
	
	if(useClick != null && useClick && locationPopupActive)
	{		
		document.getElementById(ControlID).style.display = 'none';			
		locationPopupActive = false;			
		return;
	}
	
	if (locationPopupActive && useHover)
	{		
		if(useHover)
		{		
			return;
		}
		else
		{							
			document.getElementById(ControlID).style.display = 'none';			
			locationPopupActive = false;			
			return;
		}
	}		

	var div = document.getElementById(ControlID);
	
	if(div == null)	//well, useless
	{	
		div = null;
		return;
	}
	else
	{
		
		locationPopupActive = true;

		if (!e)
			e = window.event;
				
		
		var posx = 0;
		var posy = 0;
		
		/***********************************************
		* Pop-it menu-  Dynamic Drive (www.dynamicdrive.com)
		* This notice MUST stay intact for legal use
		* Visit http://www.dynamicdrive.com/ for full source code
		***********************************************/

		var ie5=document.all && !window.opera
		var ns6=document.getElementById
		
		var eventX=ie5 ? event.clientX : e.clientX
		var eventY=ie5 ? event.clientY : e.clientY
		
		//Find out how close the mouse is to the corner of the window	
		var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX
		var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		try
		{
			if (rightedge < div.width)
			{
				//move the horizontal position of the menu to the left by it's width
				posx =ie5 ? iecompattest().scrollLeft + eventX - div.style.width : window.pageXOffset+eventX-div.style.width;
			}
			else
			{
				//position the horizontal position of the menu where the mouse was clicked
				posx =ie5? iecompattest().scrollLeft + eventX  : window.pageXOffset+eventX;
			}
			//same concept with the vertical position	
			if (bottomedge < div.height)	
			{
				posy =ie5? iecompattest().scrollTop + eventY-div.style.height  : window.pageYOffset+eventY-div.style.height;
			}
			else
			{
				posy =ie5? iecompattest().scrollTop + event.clientY  : window.pageYOffset+eventY;
			}
		}
		catch(e){}
		/*******************
		* End PopitMenu
		*******************/

		div.style.display = 'block';
		div.style.visibility = 'visible';	
		
		//TODO: keine ahnung wieso das funkt :)?
		posx = posx - 260;
		posy = posy - 90;
		
		div.style.left = (posx) +"px";	
		div.style.top = (posy) +"px";
		
		locPopID = ControlID;
		
		if(useHover)
			hideLocationPopupTimer = setInterval('HideLocationPopup()', locationPopupTimeout);		
	}		
}

function iecompattest(){
	return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}

function HideLocationPopup() {
	if (!locationPopupActive || locationHover)
		return;

	clearInterval(hideLocationPopupTimer);
	
	var div = document.getElementById(locPopID);

	div.style.display = 'none';
	div.style.visibility = 'hidden';

	locationPopupActive = false;
}

/**************************************
* END Location Plan Popup
***************************************/

/**************************************
* Request Panel
***************************************/
var toggleList = new Array();
      
var cbViewID = null;
var cbCallBackID = null;
var cbMailID = null;
            
function EnsureInitialized()
{
    if(toggleList.length == 0)
    {
        addToggleButton(cbViewID);
        addToggleButton(cbCallBackID);
        addToggleButton(cbMailID);    
    }
}

function addToggleButton(cb1)
{   
    //document.getElementById(cb1).onclick = doCBChange;            
    toggleList.push(cb1);
}

function doCBChange(sender)
{    
    EnsureInitialized();    
    toggleClick(sender);
    ChangeValidationDisplay(sender);
}

function toggleClick(sender)
{
    for(var i = 0; i < toggleList.length; i++)
    {   
        if(sender.checked)
        {
            if(sender.id != toggleList[i])
            {
                document.getElementById(toggleList[i]).checked = false;
            }                
        }
    }
}

function ChangeValidationDisplay(sender)
{
    var phoneValidation = document.getElementById('valDispPhone');
    
    if(phoneValidation != null)
    {
        phoneValidation .style.display = "none";
        
        if(sender.checked)
        {           
            if(sender.id == cbCallBackID || sender.id == cbViewID)
            {            
                phoneValidation.style.display = "";
            }
        }
    }
}

function InitializeValDisplay()
{
    document.getElementById('valDispPhone').style.display = "none";
    for(var i = 0; i < toggleList.length; i++)
    {
        var cb = document.getElementById(toggleList[i]);
        if(cb.checked)
        {
            if(cb.id == cbCallBackID || sender.id == cbViewID)
            {
                document.getElementById('valDispPhone').style.display = "";
            }
        }
    }
}

var reqEmailTB = null;
var reqLastNameTB = null;
var reqPhone = null;

function ValidateRequest()
{   
    var emailtb = document.getElementById(reqEmailTB);
    var lastNameTB = document.getElementById(reqLastNameTB);
    var phoneTP = document.getElementById(reqPhone);
    
    var cbView = document.getElementById(cbViewID);
    var cbCall = document.getElementById(cbCallBackID);
    var cbMail = document.getElementById(cbMailID);
     
    if(emailtb != null && emailtb.value == "")
        return false;
    else        
    {
        var regex = new RegExp("\\w+([-+.]\w+)*@\\w+([-.]\w+)*\\.\\w+([-.]\\w+)*", "i");               
        var match = regex.exec(emailtb.value);
                        
        if(match == null)
            return false;
    }
    if(lastNameTB != null &&  lastNameTB.value == "")
        return false;
    
    if((cbCall.checked || cbView.checked) && (phoneTP != null && phoneTP.value == ""))
        return false;
     
    if(cbView != null && cbCall != null && cbMail != null) // At least one CHeckbox required!
    {   
        if(!(cbView.checked || cbCall.checked || cbMail.checked))
            return false;
    }
        
    return true;
}

/**************************************
* END Request Panel
***************************************/

/*************************************
* My IN RealEstaet Comparision
**************************************/
function ResizeComparisonPopup(count) {
	document.getElementById('myRECompareList').style.width = count*30+'em';
}
