/* ::=================================================================

	Author:			ravi gupta
	Author URL: 	http://www.enhancedesignstudio.com/
	Date:			May 20, 2009
	Email:			ravigupta.exe@gmail.com
	
 ================================================================ ::*/

//<![CDATA[
var activeControl = '';
var selectedControl = '';
var mouseOut = false;
var disableColor = '#cccccc';
var selectedItem = Array();
var disabledItems = Array();
var itemHeights = Array();
var listHeights = Array();
  
function bodyclick() {
	if(mouseOut && activeControl!='') {
		combobox_click(activeControl);
	}
}
function combobox_enable(control, v) {
	disabledItems[control] = !v;
	if(v) {
		document.getElementById('combobox_'+control).style.color = 'black'; 
		document.getElementById(control+'_dropdownimage').src = 'images/dropdown.gif';
	} else {
		document.getElementById(control+'_dropdownimage').src = 'images/dropdown_disabled.gif';
		document.getElementById('combobox_'+control).style.color = disableColor;
		if(selectedControl!='') {
			document.getElementById('selection2_'+selectedControl).style.background = 'white';
		}
	}
}
function combobox_getEnabled(control) {
	return !disabledItems[control];
}
function combobox_click(control) {
	if(!combobox_getEnabled(control))
		return;
	if(selectedControl!='') {
		document.getElementById('selection2_'+selectedControl).style.background = 'white';
	}
	document.getElementById('selection2_'+control).style.background = '#cccccc';
	selectedControl = control;
	mouseOut = false;
	if(activeControl!='') {
		document.getElementById('list'+activeControl).style.visibility='hidden';
		if(activeControl==control) {
			activeControl = '';
			return;
		}
	}
	if(document.getElementById('list'+control).style.visibility=='inherit') {
		document.getElementById('list'+control).style.overflow='hidden';
		document.getElementById('list'+control).style.display='none';
		document.getElementById('list'+control).style.visibility='hidden';
	} else {
		document.getElementById('list'+control).style.display='block';
		document.getElementById('list'+control).style.overflow='auto';
		document.getElementById('list'+control).style.visibility='inherit';
		document.getElementById('selection_'+control).style.backgroundColor = 'white';
		if(selectedItem[control]!="") {
			if(document.getElementById(control+'_item_'+selectedItem[control])) {
				document.getElementById(control+'_item_'+selectedItem[control]).style.backgroundColor = '#cccccc';
				document.getElementById(control+'_item_'+selectedItem[control]).style.border = '1px dashed #555555';
			}
		}
		activeControl = control;
	}
}
function combobox_item_mouseover(control, id) {
	mouseOut = false;
	document.getElementById(control+'_item_'+id).style.backgroundColor = '#aaaaaa';
	//document.getElementById(control+'_item_'+id).style.border = '1px dashed #555555';
}
function combobox_item_mouseout(control, id) {
	mouseOut = true;
	document.getElementById(control+'_item_'+id).style.backgroundColor = 'white';
	//document.getElementById(control+'_item_'+id).style.border = '1px solid white';
}
function combobox_mouseout(control) {
	mouseOut = true;
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
function changeAmount()
{
    try
    {
    
        var form = $('aspnetForm');
        var initPrice_input = form['initPrice'];    
        var initNormalPrice_input = form['initNormalPrice'];    
        var price, normalprice;
        var sPrice = "";        
        var sCent = "00";
        
        var sNPrice = "";
        var sNCent = "00";
        
        
        if ((initPrice_input.value.indexOf(",") != -1) && (initPrice_input.value.indexOf(".") == -1))
        {
            initPrice_input.value = initPrice_input.value.replace(",", ".");
        }
        
        if ((initNormalPrice_input.value.indexOf(",") != -1) && (initNormalPrice_input.value.indexOf(".") == -1))
        {
            initNormalPrice_input.value = initNormalPrice_input.value.replace(",", ".");
        }
                
        var price = parseFloat($F(initPrice_input),2);
        var normalprice = parseFloat($F(initNormalPrice_input),2);
        
        var normalpricetext = "";
        
        price = (aantal * price); 
        normalprice = (aantal * normalprice);
        
        sPrice = "" + roundNumber(price, 2);
        sNPrice= "" + roundNumber(normalprice, 2);
        
        if (sPrice.indexOf('.') > -1) 
        {
            sCent = sPrice.substr(sPrice.indexOf('.') + 1, (sPrice.length - 1 - sPrice.indexOf('.')));
            sPrice = sPrice.split('.')[0];
            
            if (sCent.length == 1)
                sCent += "0";           
        }
        
        if (normalprice > 0)
        {
            if (sNPrice.indexOf('.') > -1) 
            {
                sNCent = sNPrice.substr(sNPrice.indexOf('.') + 1, (sNPrice.length - 1 - sNPrice.indexOf('.')));
                sNPrice = sNPrice.split('.')[0];
            
                if (sNCent.length == 1)
                    sNCent += "0";                                                     
            }
            
            normalpricetext = "<strike>" + sNPrice + "," + sNCent + "</strike>";
        }

                
        sPrice = normalpricetext + "<p class=\"prijs\">&euro; " + sPrice + "<span>" + sCent + "</span></p>";        
        $('p1right').update("<div>" + sPrice + "</div>");                                
    }
    catch (e)
    {
        alert(e.message);
    }
}


function combobox_set_value(control, id) {
	document.getElementById('display'+control).innerHTML = document.getElementById(control+'_text_'+id).innerHTML;
	
	if (control == "frmModel")
	{
	    maat = document.getElementById('display'+control).innerHTML;
	    maat = maat.replace("&nbsp;","");
	    maat = maat.replace(" ","");
	    maat = maat.replace(/^\s+/,'');
	    maat = maat.replace(/\s+$/,'');	    
	}
	if (control == "frmCuff")
	{
	    aantal = document.getElementById('display'+control).innerHTML;
	    aantal = aantal.replace("&nbsp;","");
	    aantal = aantal.replace(" ","");
	    aantal = aantal.replace(/^\s+/,'');
	    aantal = aantal.replace(/\s+$/,'');	
	    changeAmount();
	}
	
	if(document.getElementById('image'+control)) {
		document.getElementById('image'+control).src = document.getElementById(control+'_image_'+id).src;
	}
	document.getElementById(control).value = id;
	// unset old selection
	if (selectedItem[control] != "") {
		if (document.getElementById(control + '_item_' + selectedItem[control])) {
			document.getElementById(control + '_item_' + selectedItem[control]).style.backgroundColor = 'white';
			document.getElementById(control + '_item_' + selectedItem[control]).style.border = '1px solid white';
		}
	}
	// set new selection
	selectedItem[control] = id;
}
function combobox_set_item_text(control, id, text) {
	document.getElementById(control+'_text_'+id).innerHTML = text;
	if(selectedItem[control] == id) {
		combobox_set_value(control, id);
	}
}
function combobox_item_click(control,id) {
	if(selectedItem[control]!="") {
		if(document.getElementById(control+'_item_'+selectedItem[control])) {
			document.getElementById(control+'_item_'+selectedItem[control]).style.backgroundColor = 'white';
			document.getElementById(control+'_item_'+selectedItem[control]).style.border = '1px solid white';
		}
	}
	combobox_click(control);
	selectedItem[control] = id;
	combobox_set_value(control, id);
}
function combobox_item_hide(control, id, defaultchoice) {
	document.getElementById(control+'_item_'+id).style.visibility = 'hidden';
	document.getElementById(control+'_item_'+id).style.height = '0px';
	document.getElementById('list'+control).style.height = listHeights[control].replace("px","") - itemHeights[control].replace("px","") + "px";
	combobox_set_value(control, defaultchoice);
}
function combobox_item_unhide(control, id) {
	document.getElementById(control+'_item_'+id).style.visibility = 'inherit';
	document.getElementById(control+'_item_'+id).style.height = itemHeights[control];
	document.getElementById('list'+control).style.height = listHeights[control];
}

if (document.body != null)
    document.body.onclick = bodyclick;
//]]>