function initPage() {
    if(!supportsHTTPRequest()) {
        setTextById('myContent', 'You current browser does not support the advanced features of this web application!<br /><div class="unsupported">Please upgrade your browser to the latest version available from the vendor.</div>');
    }
//showConfirm('XXX');
}




function doAdvancedSearch(){
    doSearch('advancedSearch');
}
function doApplicationSearch(){
    doSearch('applicationSearch');
}
function doSearch(formname){
    
    //get form data
    var params = "";
    
    if( document[formname]['workload'] ){
        var wl = document[formname]['workload'].options;
        for(i=0; i < wl.length; i++){
            if( wl[i].selected && wl[i].value.length>0 ){
                if( params.length>0){ params+="&"}
                params += "workload=" + wl[i].value;
            }
        }
    }    
    
    if( document[formname]['industry'] ){
        var industry = document[formname]['industry'].options;
        for(i=0; i < industry.length; i++){
            if( industry[i].selected && industry[i].value.length>0 ){
                if( params.length>0){ params+="&"}
                params += "industry=" + industry[i].value;
            }
        }
    }
    
    if( document[formname]['platform'] ){
        var platform = document[formname]['platform'].options;
        for(i=0; i < platform.length; i++){
            if( platform[i].selected && platform[i].value.length>0 ){
                if( params.length>0){ params+="&"}
                params += "platform=" + platform[i].value;
            }
        }
    }    
    
    if( document[formname]['architecture'] ){
        var architecture = document[formname]['architecture'].options;
        for(i=0; i < architecture.length; i++){
            if( architecture[i].selected && architecture[i].value.length>0 ){
                if( params.length>0){ params+="&"}
                params += "architecture=" + architecture[i].value;
            }
        }
    }
    
    if( document[formname]['solutionarea'] ){
        var solutionarea = document[formname]['solutionarea'].options;
        for(i=0; i < solutionarea.length; i++){
            if( solutionarea[i].selected && solutionarea[i].value.length>0 ){
                if( params.length>0){ params+="&"}
                params += "solutionarea=" + solutionarea[i].value;
            }
        }
    }
    
    if( document[formname]['isvname'] ){
        var isvname = document[formname]['isvname'].value;
        if( isvname.length>0 ){
            params += "&isvname=" + isvname;
        }
    }    
    
    if( document[formname]['appname'] ){
        var appname = document[formname]['appname'].value;
        if( appname.length>0 ){
            params += "&appname=" + appname;
        }
    }
    
    params += "&tstring=" + new Date().getTime();
    var action = document[formname].action;
	if( action.indexOf('?')>0 ){
    	params = action.substring(action.indexOf('?')) + "&" + params;
		action = action.substring(0, action.indexOf('?'));
	}
    
    sndRequest(action, 'result', params, 'do_after_result');
    
}
function doBrowse(type, params){

    //get form data
    //params += "";
    params = "&action=BrowseActions.doBrowse"+ type + "&tstring=" + new Date().getTime() + (params.length>0&&params.charAt(0)!='&'?'&':'') + params;
    sndRequest('isvcatalog', 'result', params, 'do_after_result');
    
}
function onSelectDoBrowse(type, paramname, selection){

//    if( selection.selectedIndex > 0 ){
        var params = getMultiValues( selection, paramname );
        doBrowse( type, params);
//    }
}

function loadISVList(type){
    //get form data
    var params = "&action=BrowseActions.loadISVList&tstring=" + new Date().getTime() + "&isvlisttype=" + type;
    
    sndRequest('isvcatalog', 'isvlist', params);
}
function loadApplicationList(type){
    //get form data
    var params = "&action=BrowseActions.loadApplicationList&tstring=" + new Date().getTime() + "&applisttype=" + type;
    
    sndRequest('isvcatalog', 'applist', params);
}

function loadISVApplicationList(type){
    //get form data
    var params = "&action=BrowseActions.loadISVApplicationList&tstring=" + new Date().getTime() + "&applisttype=" + type;
    
    sndRequest('isvcatalog', 'applist', params);
}

function loadProductList(isvdivid, isvid, link){
    var productdiv = document.getElementById('productdiv_'+isvdivid);
    var show=true;

    //if it is a html object (link)
    if( ! link.className ){
        var possiblerows= document.getElementById('isvlist').getElementsByTagName('a');
        for(var i=0; i< possiblerows.length; i++){
            if( possiblerows[i].className.indexOf('allproductslink')>=0 ){
                var tlink = possiblerows[i];
                if( tlink.innerHTML.substr(0,1).toLowerCase() == 's' ){
                    show=true;
                }else{
                    show=false;
                }
            }
        }
    }else{
        if( productdiv.innerHTML.length >= 1){ 
            show=false;
        }
    }
    
    //get corner image
    var cornerImage = document.getElementById('isv-corner' + isvdivid);
    
    
    if( !show ){
        productdiv.style.display='none';
        //productdiv.innerHTML='';
        removeChilds(productdiv);
        if( typeof( oldisvdivid ) != "undefined" ){
            delete oldisvdivid;
        }
        if( cornerImage ){
            cornerImage.src='images/plus-corner.png';
        }
    }else{
        var params = "&action=BrowseActions.loadProducts&tstring=" + new Date().getTime() + "&isvid="+isvid;
    
        sndRequest('isvcatalog', 'productdiv_'+isvdivid, params, 'do_after_productlist_result_' + isvdivid);
        if( cornerImage ){
            cornerImage.src='images/minus-corner.png';
        }
        productdiv.style.display='';
    }
    
    
}

function loadProductInfo(productid){
    var productdiv = document.getElementById('product_info_div_'+productid);
    
    var switchbutton;
    var childs = productdiv.parentNode.childNodes;
    for(var i=0; i< childs.length; i++){
        if( childs[i].className == 'even_cell_container' || childs[i].className == 'odd_cell_container' || childs[i].className == 'even2_cell_container' || childs[i].className == 'odd2_cell_container' ){
            var cols = childs[i].childNodes;
            for(var j=0; j< cols.length; j++){
                if( cols[j].className && ( cols[j].className == 'even_cell_end' || cols[j].className == 'odd_cell_end') || cols[j].className && ( cols[j].className == 'even2_cell_end' || cols[j].className == 'odd2_cell_end') ) {
                    switchbutton=cols[j];
                    break;
                }
            }
            if( switchbutton){
                break;
            }
        }
    }
    
    if( productdiv.innerHTML.length > 1 ){
        //productdiv.innerHTML='';
        removeChilds(productdiv);
        productdiv.style.display='none';

        if( typeof( oldproductdivid ) != "undefined" ){
            var oldproductdiv = document.getElementById('product_info_div_' + oldproductdivid);
            if( oldproductdiv ){
                delete oldproductdivid;
            }
        }
        if(switchbutton){
            switchbutton.style.backgroundImage='url(images/list-more-info.png)';
        }
    }else{
        var params = "&action=BrowseActions.loadProductInfo&tstring=" + new Date().getTime() + "&product="+productid;
        
        sndRequest('isvcatalog', 'product_info_div_'+productid, params, 'doafterProductInfo_' + productid);
        if(switchbutton){
            switchbutton.style.backgroundImage='url(images/list-close-arrow.png)';
        }
        productdiv.style.display='';
    }
}

function removeProductList(element){
    var elem = element.parentNode.parentNode.parentNode;
    elem.style.display='none';
    //elem.innerHTML='';
    removeChilds(elem);
    
}

function resetForm(formid){
    //document.getElementById('result').innerHTML='';
    var result = document.getElementById('result');
    if( result ){
        removeChilds(result);
    }
    document.getElementById(formid).reset();
    return false;
}
function clearSubPage(){
    var subpage = document.getElementById('subpage');
    if( subpage ){
        removeChilds(subpage);
    }
}

function getMultiValues(selection, paramname){
    var params="";
    for(var i=0; i < selection.length; i++){
        if( selection.options[i].selected==true ){        
            params += (params.length > 0?"&":"") + paramname + "=" + selection.options[i].value;
        }
    }
    return params;
}
function hideOtherProductInfos(newproductdivid){

    if( typeof( oldproductdivid ) != "undefined" && newproductdivid!=oldproductdivid ){
        var oldproductdiv = document.getElementById('product_info_div_' + oldproductdivid);
        if( oldproductdiv ){
            loadProductInfo( oldproductdivid );
        }
    }
    
    //global javascript variable
    oldproductdivid=newproductdivid;

}
function hideOtherISVInfos(newisvdivid){

    if( typeof( oldisvdivid ) != "undefined" && newisvdivid!=oldisvdivid ){
        var isvlink = document.getElementById('isv-click-' + oldisvdivid);
        if( isvlink ){
            loadProductList( oldisvdivid, '' , isvlink );
        }
    }
    
    //global javascript variable
    oldisvdivid=newisvdivid;

}
//function showAllProducts(clickedlink){
//
//    var possiblerows= document.getElementById('isvlist').getElementsByTagName('a');
//    for(var i=0; i< possiblerows.length; i++){
//        if( possiblerows[i].parentNode.className.indexOf('isv-click')>=0 ){
//            eval( 'function autoloadProductList(){' + possiblerows[i].parentNode.attributes['onclick'].nodeValue + '}; autoloadProductList();');
//        }
//    }
//
//    var possiblerows= document.getElementById('isvlist').getElementsByTagName('a');
//    for(var i=0; i< possiblerows.length; i++){
//        if( possiblerows[i].className.indexOf('allproductslink')>=0 ){
//            var link = possiblerows[i];
//            if( link.innerHTML.substr(0,1).toLowerCase() == 's' ){
//                link.innerHTML= getString('js.all.hideallproducts');
//            }else{
//                link.innerHTML= getString('js.all.showallproducts');
//            }
//        }
//    }
//
//}

//function fixCellHeight(productid){
//
//    var divs = document.getElementById('product_info_div_' + productid).parentNode.childNodes;

//    //we neeed to substract the padding from height when setting it, currently we have 5px top and bottom
//    var padding=10;
//    var maxheight = 0;
//
//
//    for(var j=0; j < divs.length; j++){
//        if( divs[j].className && (
//                divs[j].className.indexOf('even_cell_container')>=0 || 
//                divs[j].className.indexOf('odd_cell_container')>=0 
//            )
//        ){
//            var childs=divs[j].childNodes;
//            for(var i=0; i < childs.length; i++){
//            //    alert(childs[i].className);
//                if( childs[i].className && ( childs[i].className.indexOf('odd_')>=0 ||
//                    childs[i].className.indexOf('even_')>=0 )
//                ){
//
////                    alert( childs[i].offsetHeight + ' > ' + maxheight );
//                    if( childs[i].offsetHeight > maxheight ){
//                        maxheight=childs[i].offsetHeight;
//                    }    
//                }
//            }
//
//            for(var i=0; i < childs.length; i++){
//                if( childs[i].className && ( childs[i].className.indexOf('odd_')>=0 ||
//                    childs[i].className.indexOf('even_')>=0 )
//                ){
//                    childs[i].style.height= (maxheight-padding) + 'px';
//                }
//            }
//
//        }
//    }
//
//}

//function fixHeaderHeight(){
//    var padding=10;
//    document.getElementById('the').style.height= (document.getElementById('th1').offsetHeight-padding) + 'px';
//}

//needed to convert &lt back to < for the for loop within ajax
function callProductlistCode(productdivid){
    var childs = document.getElementById(productdivid).childNodes;
    for(var i=0; i < childs.length; i++){
        if( childs[i].className && childs[i].className.indexOf('productlistcode')>=0 ){
            eval( childs[i].innerHTML );
        }
    }                
}

//function to fix page height currently not in use
//function fixPageHeight(){
//    var pageheight = Position.cumulativeOffset($('mailto'))[1];
//    if( pageheight > document.getElementById('contentcontainer').offsetHeight ){
//        alert( 'fixing pageheight ' + pageheight + ' > ' + document.getElementById('contentcontainer').offsetHeight );
//        document.getElementById('contentcontainer').style.height=(pageheight+50) + 'px';
//    }
//}

function showAdvancedSearch(){
    if( document.getElementById('initial').style.display == 'none' ){
        document.getElementById('initial').style.display='block';
        document.getElementById('advanced').style.display='none';
    }else{
        document.getElementById('initial').style.display='none';
        document.getElementById('advanced').style.display='block';
    }
    
}

function removeChilds (xobject) {
    var childs = xobject.childNodes;
    if( childs && childs.length>0){
        var child = childs[0];
        var removed = xobject.removeChild( child );
        removeChilds(xobject);
    }
}

function loadSubPage(type, commandsequence){
    clearSubPage();
    
    var params = "&action=BrowseActions." + type + "&tstring=" + new Date().getTime();

    sndRequest('isvcatalog', 'subpage', params, commandsequence);
    
}

function changeHighlight(link){
    
    var pchilds = document.getElementById('browseoptions').childNodes;
    for(var i=0; i< pchilds.length; i++){
        var pchild = pchilds[i];
        if( pchild.childNodes){
            var achilds = pchilds[i].childNodes;
            for(var j=0; j< achilds.length; j++){
                if( achilds[j].className && achilds[j].className=='browseoption' ){
                    achilds[j].style.color='#464744';
                }
            }
        }
    }
    
    if(link) { 
        link.style.color='#55A61D';
    }
}

function selectABC(link){

    var childs=document.getElementById('abc-row').childNodes;
    for(var i=0; i<childs.length; i++){
        if( childs[i].className && 
            childs[i].className.length > 0 && 
            childs[i].className.indexOf('abc_selected') > 0
        ){
            childs[i].className='abc_link';
            
        }
    }

    link.className = 'abc_link abc_selected';
}