
var iOldHeight = 0; 

function getElementsByClassName(oElm, strTagName, strClassName) {
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements);
}


function quicksearch_draw_input(spItemName, spTpl)
{
 var sInput = sLength = '';
 var sItemNamePraefix = 'quicksearch_specific_';
 var oElement = document.getElementById( 'ipt' + sItemNamePraefix + spItemName );

 if( spTpl == '' )      spTpl   = '';
 if( spTpl == 'small' ) sLength = ' maxlength="5" ';
 else  sLength = ' maxlength="36" ';

 sInput += '<div class="quicksearch_' + spTpl + 'text_active">';
 sInput += '<input id="' + sItemNamePraefix + spItemName + '" onchange="choose_inputspecification(\'' + spItemName + '\', this.value )" class="quicksearch_' + spTpl + 'textfield"' + sLength + 'type="text" name="' + sItemNamePraefix + spItemName + '" value="' + oElement.value + '" />';
 sInput += '</div>';

    return sInput;
}


function quicksearch_draw_selectbox(spItemName, apItemItems, ipTpl)
{
 var sBox = '';
 var sTmp = '';
 var sTitle = '';
 var sItemNamePraefix = 'quicksearch_specific_';
 var oElement = document.getElementById( 'ipt' + sItemNamePraefix + spItemName );
 
 if ( ipTpl == '' ) ipTpl = '';
 
    sTmp = oElement.value.split("|");
    sTitle = '';

    if( sTmp.length == 2 ) {
        sTitle = sTmp[1];
    } else {
        sTitle = oElement.value;
    }

 sBox += '<div id="quicksearch_specific" class="quicksearch_text_' + ipTpl + 'item_active">';
 sBox += ' <a href="javascript:quicksearch_specific_arrow_click(\'' + sItemNamePraefix + spItemName + '\');">';
 sBox += '    <div id="quicksearch_specific_headline_' + spItemName + '" class="quicksearch_text_active_' + ipTpl + 'item_headline">' + sTitle + '</div>';
 sBox += '    <div id="quicksearch_specific_arrow" class="quicksearch_text_active_' + ipTpl + 'item_arrow">';
 sBox += '         <img title="" alt="" src="/fileadmin/power-systems/images/quicksearch_arrow_active.png">';
 sBox += '    </div>';
 sBox += ' </a>';
 sBox += '</div>';
 sBox += '<div id="' + sItemNamePraefix + spItemName + '" class="quicksearch_' + ipTpl + 'item_list" style="display: none;">';
 sBox += '<p>';

 sBox += '<a href="javascript:choose_specific_' + spItemName + '(\'' + spItemName + '\', \'\');"> ' + PSLT_LBLNOSELECTION + ' </a>';

  for(i = 0; i < apItemItems.length; i++) 
  {
    sTmp = apItemItems[i].split("|");
    sTitle = '';

    if( sTmp.length == 2 ) {
        sTitle = sTmp[1];
    } else {
        sTitle = apItemItems[i];
    }

    sBox += '<a href="javascript:choose_specific_' + spItemName + '(\'' + spItemName + '\', \'' + apItemItems[i] + '\');">' + sTitle + '</a>';
  }

 sBox += '  </p>';
 sBox += '</div>';

    return sBox;
}


function quicksearch_element_visibility_handler(spEleID) 
{
    var oEle     = document.getElementById(spEleID);
    var sEleQScl = 'quicksearch_category_list';
    var oEleQScl = document.getElementById(sEleQScl);
    var sEleQSpl = 'quicksearch_product_list';
    var oEleQSpl = document.getElementById(sEleQSpl);

    if( oEle.style.display == 'block' ) oEle.style.display = 'none';
    else oEle.style.display = 'block';

//    var aItems = getElementsByClassName(document, 'div', 'quicksearch_item_list');    // kleine Dropdown Box
    var aItems = getElementsByClassName(document, 'div', 'quicksearch_largeitem_list'); // große Dropdown Box

    for(i = 0; i < aItems.length; i++)
    {
        if( aItems[i].style.display == 'block' && aItems[i].id != spEleID ) {
            aItems[i].style.display = 'none';
            break;
        }
    }

    if( spEleID != sEleQScl || spEleID != sEleQSpl )
    {
        if( oEleQScl.style.display == 'block' && spEleID != sEleQScl ) oEleQScl.style.display = 'none';
        if( oEleQSpl.style.display == 'block' && spEleID != sEleQSpl ) oEleQSpl.style.display = 'none';
    }
}


function choose_inputspecification(spSpecificationElement, spSpecificationValue)
{
	document.getElementById("iptquicksearch_specific_" + spSpecificationElement).value = spSpecificationValue;
}


function choose_specification(spSpecificationElement, spSpecificationValue)
{
 var sTmp = '';
 var sTitle = '';

    sTmp = spSpecificationValue.split("|");

    if( sTmp.length == 2 ) {
        sTitle = sTmp[1];
    } else {
        sTitle = spSpecificationValue;
    }

    document.getElementById("quicksearch_specific_headline_" + spSpecificationElement).innerHTML = sTitle;
	document.getElementById("iptquicksearch_specific_" + spSpecificationElement).value = spSpecificationValue;
	document.getElementById("quicksearch_specific_" + spSpecificationElement).style.display = 'none';
}


function choose_category(category,category_name,product_ids_string,product_groups_string,product_names_string) {
	var products_string = '';
	
	var product_ids = product_ids_string.split(';');
	var product_groups = product_groups_string.split(';');
	var product_names = product_names_string.split(';');
	
	if (product_ids.length > 0) {
	
		products_string = '<p>';
		
			for (var i=0;i<product_ids.length;i++) 
            {
				if( product_groups[i] == category )
					products_string = products_string + '<a href="javascript:choose_product(\''+category+'\',\''+product_ids[i]+'\',\''+product_names[i]+'\');">'+product_names[i].replace(/_/g, " ")+'</a>';
			}

		products_string = products_string + '</p>';

		document.getElementById("quicksearch_category_headline").innerHTML = category_name.replace(/_/g, " ");
		document.getElementById("quicksearch_category_list").style.display = 'none';
		document.getElementById("quicksearch_category_search").value = category;
		
		document.getElementById("quicksearch_product_headline").innerHTML = PSLT_LBLQSRESULTPRODUCT.toUpperCase();
		document.getElementById("quicksearch_product_search").value = '';
		
		document.getElementById("quicksearch_product").className = "quicksearch_text_active";
		document.getElementById("quicksearch_product_headline").className = "quicksearch_text_active_headline";
		document.getElementById("quicksearch_product_arrow").className = "quicksearch_text_active_arrow";

        document.getElementById("quicksearch_product").innerHTML = '<a href="javascript:quicksearch_product_arrow_click();">'+document.getElementById("quicksearch_product").innerHTML+'</a>';

		document.getElementById("quicksearch_product_arrow").innerHTML = '<img src="/fileadmin/power-systems/images/quicksearch_arrow_active.png" alt="" title="" />';
		document.getElementById("quicksearch_product_list").innerHTML = products_string;
		
		document.getElementById("quicksearch_specification").innerHTML = '';
	}
}


function choose_product(category,product,product_name) {
	var content = '';

	document.getElementById("quicksearch_product_headline").innerHTML = product_name.replace(/_/g, " ");
	document.getElementById("quicksearch_product_list").style.display = 'none';
	document.getElementById("quicksearch_product_search").value = product;
	document.getElementById("quicksearch_specification").innerHTML = "";

    // ZWISCHENSPEICHER RESETEN
    document.getElementById('iptquicksearch_specific_ProductTitle').value = '';
    document.getElementById('iptquicksearch_specific_OutputPower').value = '';
    document.getElementById('iptquicksearch_specific_InputVoltage').value = '';
    document.getElementById('iptquicksearch_specific_OutputVoltage').value = '';
    document.getElementById('iptquicksearch_specific_OutputCurrent').value = '';
    document.getElementById('iptquicksearch_specific_NoofLamps').value = '';
    document.getElementById('iptquicksearch_specific_Manufacturer').value = '';

    document.getElementById('iptquicksearch_specific_OutputCableNo').value = '';
    document.getElementById('iptquicksearch_specific_InputCableNo').value = '';
    document.getElementById('iptquicksearch_specific_OutputConnector').value = '';
    document.getElementById('iptquicksearch_specific_InputConnector').value = '';
    document.getElementById('iptquicksearch_specific_LTTech').value = '';

    // Netzteile - Wall/Desktop
    if( product == 1 )        content = getwalldesktop(category, product);
	// Netzteile - LED Netzteile
    else if( product == 2 )  content = getledadapter(category, product);
    // DC/DC Wandler - Module
    else if( product == 3 )  content = getmodules(category, product);
    // DC/DC Wandler - Fahrzeug-Adapter
    else if( product == 4 )  content = getautoadapter(category, product);
    // Backlight Inverter - Inverter für CCFL
    else if( product == 5 )  content = getbacklightinverter(category, product); 
    // Backlight Inverter - Inverter Kabel
    else if( product == 6 )  content = getinvertercables(category, product);
    // Backlight Inverter - Display Inverter
    else if( product == 7 )  content = getdisplayinverter(category, product); 
    // Touch Screens - PCT TECHNOLOGY
    else if( product == 8 )  content = gettouchscreens(category, product);
    // Touch Screens - SCT TECHNOLOGY
    else if( product == 9 )  content = gettouchscreens(category, product);
    // Touch Screens - CONTROLLER
    else if( product == 10 ) content = gettouchscreens(category, product);
    // LED Konverter - Konverter für LED
    else if( product == 11 ) content = getledconverter(category, product); 
    // LED Konverter - LED Konverter Kabel
    else if( product == 12 ) content = getledconvertercable(category, product); 
    // LED Konverter - Display Konverter
    else if( product == 13 ) content = getdisplayconverter(category, product);

    // ---

    if( document.getElementById("torso_left_contenthome") && ( product == 12 || product == 6 ) )
    {
            if( !iOldHeight ) {
                iOldHeight = document.getElementById("torso_left_contenthome").offsetHeight;
            }

        iNewHeight = document.getElementById("torso_left_contenthome").offsetHeight + 49;

        document.getElementById("torso_left_contenthome").style.minHeight = iNewHeight + 'px';
		document.getElementById("backgroundhome-wrapper").style.minHeight = iNewHeight + 'px';

    } else if( document.getElementById("torso_left_contenthome") && ( product != 12 && product != 6 ) ) {

        if( iOldHeight ) {
            document.getElementById("torso_left_contenthome").style.minHeight = iOldHeight + 'px';
            document.getElementById("backgroundhome-wrapper").style.minHeight = iOldHeight + 'px';
        }

    }

    // ---

	document.getElementById("quicksearch_specification").innerHTML = content;
}


function Numsort (a, b) {
  return a - b;
}

function quicksearch_specific_arrow_click(spEleID) {
    quicksearch_element_visibility_handler(spEleID);
}

function quicksearch_category_arrow_click() {
    quicksearch_element_visibility_handler('quicksearch_category_list');
}

function quicksearch_product_arrow_click() {
    quicksearch_element_visibility_handler('quicksearch_product_list');
}


function choose_specific_OutputVoltage(spSpecificationElement, spSpecificationValue) {
    choose_inputspecification(spSpecificationElement, spSpecificationValue);
}

function choose_specific_InputVoltage(spSpecificationElement, spSpecificationValue) {
    choose_inputspecification(spSpecificationElement, spSpecificationValue);
}

function choose_specific_OutputPower(spSpecificationElement, spSpecificationValue) {
    choose_inputspecification(spSpecificationElement, spSpecificationValue);
}

function choose_specific_OutputCurrent(spSpecificationElement, spSpecificationValue) {
    choose_inputspecification(spSpecificationElement, spSpecificationValue);
}

function choose_specific_NoofLamps(spSpecificationElement, spSpecificationValue) {
    choose_inputspecification(spSpecificationElement, spSpecificationValue);
}

function choose_specific_ProductTitle(spSpecificationElement, spSpecificationValue) {
    choose_inputspecification(spSpecificationElement, spSpecificationValue);
}

// ---

function choose_specific_Manufacturer(spSpecificationElement, spSpecificationValue) {
    choose_specification(spSpecificationElement, spSpecificationValue);
}

function choose_specific_OutputCableNo(spSpecificationElement, spSpecificationValue) {
    choose_specification(spSpecificationElement, spSpecificationValue);
}

function choose_specific_InputCableNo(spSpecificationElement, spSpecificationValue) {
    choose_specification(spSpecificationElement, spSpecificationValue);
}

function choose_specific_OutputConnector(spSpecificationElement, spSpecificationValue) {
    choose_specification(spSpecificationElement, spSpecificationValue);
}

function choose_specific_InputConnector(spSpecificationElement, spSpecificationValue) {
    choose_specification(spSpecificationElement, spSpecificationValue);
}

function choose_specific_LTTech(spSpecificationElement, spSpecificationValue) {
    choose_specification(spSpecificationElement, spSpecificationValue);
}

// ---

function contactFrm_arrow_click()
{
    var oEle = document.getElementById('contactFrm_category_list');

    if( oEle.style.display == 'block' ) oEle.style.display = 'none';
    else oEle.style.display = 'block';
}

function choose_Anrede(spSpecificationElement, spSpecificationValue) 
{
    document.getElementById("contactFrm_category_headline").innerHTML = spSpecificationValue;
	document.getElementById("ipt" + spSpecificationElement).value = spSpecificationValue;
	document.getElementById("contactFrm_category_list").style.display = 'none';
}

