// finds a control that had the given server id, of a the given type
// in the given parent.
function findControl(parent, tagName, serverId) 
{
    var items = parent.getElementsByTagName(tagName);
    
    // walk the items looking for the right guy
    for (var i = 0; i < items.length; i++) {
        var ctl = items[i];
        if (ctl && ctl.id) {
            // check the end of the name.
            //
            var subId = ctl.id.substring(ctl.id.length - serverId.length);
            if (subId == serverId) {
                return ctl;                        
            }
        }
    }   
    return null;
}

function loadTabPanel(sender, e) 
{ 
	var tabContainer = sender;           
               
    if (tabContainer) 
    {
        var updateControlId = "TabButton" + tabContainer.get_activeTabIndex();
         // get the active tab and find our button
        var activeTab = tabContainer.get_activeTab();            
               
        // check to see if we've already loaded
        if (findControl(activeTab.get_element(), "div", "TabContent" + tabContainer.get_activeTabIndex())) return;
                                
        var updateControl =  findControl(activeTab.get_element(), "input", updateControlId);
        
        if (updateControl) 
        {        
            // fire the update
            updateControl.click();
        } 
    }   
}
        
function goTo(url)
{ 
	document.location.href = url; 
}		

function ShowNewsLetter(NewsLetterID)
{ 
	window.open('/DesktopModules/MijnAEP/ShowNewsletter.aspx?NewsLetterID=' + NewsLetterID + '', null, 'width=700,height=600,status=yes,toolbar=no,menubar=no,location=no');
}

function showPrice(tempCount)
{
    // convert to price
    var strPrice = Math.round(tempCount*100)/100;
    strPrice = strPrice.toString().replace(".", ",");	
    
    if (strPrice.length - strPrice.indexOf(",") == 2)
    {
	    if (strPrice.indexOf(",") > 0)
	    {
		    strPrice += "0";
	    }
    }
    
    if (strPrice.indexOf(",") < 0)
    {
	    strPrice += ",00";
    }
    
    return "&euro; "+ strPrice;
}

function setAmmount()
{
	if (document.getElementById("puppySelect")) 
	{
	    var arrayCheckboxes = document.getElementById("puppySelect").getElementsByTagName("input");
	    var count = 0;
	    if (arrayCheckboxes.length != 0) 
	    {
		    for (i=0; i < arrayCheckboxes.length; i++)
		    {
			    if(arrayCheckboxes[i].type == "checkbox") 
			    {
			        if(arrayCheckboxes[i].checked)
			        {
				        count++;
			        }
			    }
		    }
		}
		
		if (count == 0)
		{
			count = 1;
		}
			
		if (document.getElementById("ammount")) 
		{
			document.getElementById("ammount").innerHTML = showPrice(count * 7.5);
		}
		else if (document.getElementById("ammount1"))
		{			
			document.getElementById("ammount1").innerHTML = showPrice(count * 45);
			document.getElementById("ammount2").innerHTML = showPrice(count * 90);
			document.getElementById("ammount3").innerHTML = showPrice(count * 150);
		}
		
	}
}

function changePuppySelect(id, targetControl)
{
    var element = document.getElementById(targetControl);
    if(element)
    {
        element.value = id;
    }
}

function hideModalPopupViaClient(ev) {
    ev.preventDefault();        
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.hide();
    changeZIndexContainer("2");
}

function changeZIndexContainer(zindex)
{
    if(document.getElementById("rightPartSite"))
    {
        document.getElementById("rightPartSite").style.zIndex = zindex;
    }
}

function checkPuppy(checkBoxID)
{
    if(document.getElementById(checkBoxID))
    {
        document.getElementById(checkBoxID).checked = true;
    }        
}
