var ParametricStepSearch = Class.create();
ParametricStepSearch.prototype = {
	initialize: function(table) {
	    // Local variables
		this.table = table;
		this.table_css = '#' + this.table.id + ' ';
		this.sort_key = '';
		this.sort_key_index = -1;
		this.sort_key_criteria = null;
		this.bookmark = '';
		this.comparing = false;
		this.lastaction='';
		this.filtimer = new ExtendedPeriodicalExecuter(this.hideme.bind(this), 3000, "");
		this.db = (document.body) ? 1 : 0;
		this.scroll = (window.scrollTo) ? 1 : 0;
		this.x=0;
		this.y=0;
		/*
		// Loop through the columns and set draggable
		$$(this.table_css + 'div.pf_col_attr').each( function(div) {
			new Draggable(div.id,{revert:true});
			Droppables.add(div.id, 
				{
					accept: 'pf_col_attr',
					hoverclass: 'drophover',
					onDrop: this.moveColumn.bind(this)
				}
			);
		}.bind(this));
		*/
		
		// Loop though the close images
		$$(this.table_css + 'img.pf_close').each( function(img) {
			Event.observe(img, 'click', this.closeColumn.bindAsEventListener(this));
		}.bind(this));
		
		// Loop through the sort images
		$$(this.table_css + 'img.pf_sort').each( function(img) {
			Event.observe(img, 'click', this.sort.bindAsEventListener(this));
		}.bind(this));
		
		// Loop through the filter images
		$$(this.table_css + 'img.pf_filter').each( function(img) {
			Event.observe(img, 'click', this.popup.bindAsEventListener(this));
		}.bind(this));
		
		// Loop through the popups and hide them
		$$(this.table_css + 'div.pf_popup').each( function(div) {
			Element.hide(div);
			//Event.observe(div, 'mouseleave', this.hideme.bindAsEventListener(this));
		}.bind(this));
		
		// Loop through the filter checkboxes
		$$(this.table_css + 'input.pf_popup_checkbox').each( function(cbx) {
		        Event.observe(cbx, 'click', this.chxboxevent.bindAsEventListener(this));
			//Event.observe(cbx, 'click', this.reload.bindAsEventListener(this));
		}.bind(this));
		
		Event.observe('pf_undo', 'click', this.undoLastAction.bindAsEventListener(this));
		
		// Bind the column and excel buttons
		//Event.observe('pf_bookmark', 'click', this.showBookmarkableUrl.bindAsEventListener(this));
		//Event.observe('pf_part_compare', 'click', this.compare.bindAsEventListener(this));
		//Event.observe('pf_product_table_tips', 'click', this.tips.bindAsEventListener(this));
		//Event.observe('pf_display_columns', 'click', this.displayColumns.bindAsEventListener(this));
		//Event.observe('pf_update_columns', 'click', this.updateColumns.bindAsEventListener(this));
		//Event.observe('pf_export_excel', 'click', this.exportExcel.bindAsEventListener(this));
		//Event.observe('pf_error_no_parts_reset', 'click', this.reset.bindAsEventListener(this));
		//Event.observe('pf_error_no_columns_select', 'click', this.displayColumns.bindAsEventListener(this));
		
        var options = getArgs();
		if (options) {
		    for (var option in options) {
			    if (option == 'cols') {
			        closeTableColumns = false;
		            // Set all columns to visible
				    for (var i = 1; i < this.table.tHead.rows[0].cells.length; i++) {
					    Element.show(this.table.tHead.rows[0].cells[i]);
				    }
		            // Position all columns specified in the options
				    var cols = options.cols.split(',');
				    var colCount = 0;
				    for (var i = cols.length - 1; i >= 0; i--) {
					    var col = $('pf_col_' + cols[i]);
					    if (col) {
						    var oldIndex = 1;
						    var newIndex = this._getColumnIndex(col);
						    for (var j = 0; j < this.table.rows.length; j++) {
							    this.table.rows[j].insertBefore(this.table.rows[j].cells[newIndex], 
								    this.table.rows[j].cells[oldIndex]);
						    }
							colCount++;
					    }
				    }
				    // Close the columns not included in the querystring
				    for (var i = 1 + colCount; i < this.table.tHead.rows[0].cells.length; i++) {
					    Element.hide(this.table.tHead.rows[0].cells[i]);
				    }
			    } else if (option == 'sort') {
				    var key = eval('options.' + option);
				    if (key.indexOf(' DESC') > -1) {
					    key = key.replace(/ DESC/, '');
					    // Set the div so the sort will be desc
					    this.sort_key = key;
				    }
				    this._sort($('pf_sort_' + key));
			    } else {
				    var cbx = this._getComboBox(option);
				    if (cbx) {
				        var values = eval('options.' + option).split(',');
				        for (var cbxCount = 0; cbxCount < cbx.length; cbxCount++) {
					        for (var valCount = 0; valCount < values.length; valCount++) {
						        if (cbx[cbxCount].value == values[valCount]) {
							        cbx[cbxCount].checked = true;
						        }
					        }
				        }
				    }
			    }
		    }
		}
        // Close all columns where the header is hidden
        for (var i = 1; i < this.table.tHead.rows[0].cells.length; i++) {
	        if (!Element.visible(this.table.tHead.rows[0].cells[i])) {
	            this._closeColumn(i);
	        }
	    }
	    // Reload the table.
		this.reload();
		// Don't show the compare error on load.
		//Element.hide('pf_error_no_compare');
		// Don't show the column list on load.
		//Element.hide('pf_columns');
		// Show the help on page load.
		//Element.hide('pf_tips');
		//setTimeout(this._openTips.bind(this), 500);
		//setTimeout(this._closeTips.bind(this), 10000);
	},

 saveScroll: function() {
  if (!this.scroll) return;
  
  this.x = (this.db) ? document.body.scrollLeft : pageXOffset;
  this.y = (this.db) ? document.body.scrollTop : pageYOffset;
  
},

loadScroll: function() {
  if (!this.scroll) return;
   scrollTo(this.x, this.y);
},

	reload: function(event) {
	var startTime,endTime;
	startTime=new Date().getTime();
		this.saveScroll();
        // Loop through links and stop observing them
   //    $$('#pf_selections span.pf_selections_link').each( function(link) {
//		    Event.stopObserving(link, 'click', this.removeFilter.bindAsEventListener(this));
//	    }.bind(this));



    		endTime=new Date().getTime();
	   // alert('Elapsed time using : '+((endTime-startTime)/1000)+' seconds.');
	    
	    // Set all the rows to show before we apply the filters
	    for (var bodyCount=0; bodyCount < this.table.tBodies.length; bodyCount++) {
		    for (var rowCount=0; rowCount < this.table.tBodies[bodyCount].rows.length; rowCount++) {
			    Element.show(this.table.tBodies[bodyCount].rows[rowCount]);
		    }
	    }

	    // Loop through the columns and filter the table
	    var selections = '';
	    var crit = '';
	    var critSep = '&';
	    var cols = '?cols=';
	    var colSep = '';
	    var colCount = 0;
	    var cbx = '';
	    var criteria = [];
	    var selectionsOptions = '';
	    var tableRow;
	    var tableBody;
	    $$(this.table_css + 'div.pf_col_attr').each( function(div) {
		    var key = this._getKey(div, 'pf_col_attr_');
		    var col = this._getColumn(div);
		    var colIndex = this._getColumnIndex(col);
		    if (Element.visible(col)) {
		        cols += colSep + escape(key);
		        colSep = ',';
		        colCount++;
		    }
		    cbx = this._getComboBox(key);
		    if (null != cbx) {
			    criteria=[];
			    selectionsOptions = '';
			    for (var cbxCount = 0; cbxCount < cbx.length; cbxCount++) {
				    if (cbx[cbxCount].checked) {
				        criteria.push(cbx[cbxCount].value);			        
				        selectionsOptions += '<li>' + cbx[cbxCount].value + ' <span class="pf_selections_link" id="pf_selections_link_'+key+'|'+cbxCount+'">[remove]</span>';
				    }
				}
				if (criteria.length > 0) {
				    var attrName = $('pf_attr_name_' + key).innerHTML;
				    selections += '<li>' + attrName + '<ul>';
				    selections += selectionsOptions;
				    selections += '</ul></li>';
					crit += critSep + escape(key) + '=' + criteria;
				    for (var bodyCount=0; bodyCount < this.table.tBodies.length; bodyCount++) {
					     tableBody = this.table.tBodies[bodyCount];
					    for (var rowCount=0; rowCount < tableBody.rows.length; rowCount++) {
						    tableRow = tableBody.rows[rowCount];
						    // loop through rows and hide non-matching
						    var display = false;
						    for (var criteriaCount = 0; criteriaCount < criteria.length; criteriaCount++) {
							    if (criteria[criteriaCount] == tableRow.cells[colIndex].innerHTML) {
								    // filter this row!
								    display = true;
							    }
						    }
						    if (Element.visible(tableRow)) {
								if (display) Element.show(tableRow);
								else Element.hide(tableRow);
						    }
					    }
				    }
			    }
		    }
	    }.bind(this));
    	

	    var partCount = this._reloadTableRows();

   	    this.bookmark = window.location.protocol + '//' + window.location.hostname + window.location.pathname + cols + ((this.sort_key.length > 0)?'&sort='+escape(this.sort_key):'') + crit;
   	    this.loadScroll();
    },

	_reloadTableRows: function(event) {
	    // Update the row CSS classes
	    var partCount = 0;
	    var rowCss = 'even';
	    for (var bodyCount=0; bodyCount < this.table.tBodies.length; bodyCount++) {
		    var tableBody = this.table.tBodies[bodyCount];
		    for (var rowCount=0; rowCount < tableBody.rows.length; rowCount++) {
			    var tableRow = tableBody.rows[rowCount];
			    if (Element.visible(tableRow)) {
				    tableRow.className = rowCss;
				    rowCss = ((rowCss=='even')?'odd':'even');
				    partCount++
			    }
		    }
	    }
	    return partCount;
    },
   chxboxevent: function(event)
       {
       	var element = Event.element(event);
       	var key = '';
       	//alert(element.value);
       	if (element && element.name && element.name.indexOf('pf_checkbox_')==0) 
       	{
   		    key = element.name.substr('pf_checkbox_'.length);
   		    this.filtimer.stop();
   		    this.filtimer.id=key;
   		    this.filtimer.start();
   
   	}
   	if(key!='')
   	{
   		this.lastaction='fltr|'+ key+'|'+ element.value;
   		this.reload(event);
   		//alert(this.lastaction);
   	}
       	
    },
	sort: function(event) {
	    this._sort(Event.element(event));
        this.reload();
    },

	_sort: function(img) {
	    var key = this._getKey(img, 'pf_sort_');
	    var colIndex = this._getColumnIndex(this._getColumn(img));
	    
	    
	    var desc = (this.sort_key == key);
	    this.sort_key = key + ((desc)?' DESC':'')
    	
	    $$(this.table_css + 'img.pf_sort').each( function(i) { i.src='/taec/Catalog/images/sort_off.png'; i.alt='Click to Sort'; });
	    if (desc) {
		  img.src = '/taec/Catalog/images/sort_descending.png';
		} else {
		  img.src = '/taec/Catalog/images/sort_ascending.png';
		  img.alt='Click to Sort Descending';
		}
		
    	
	    var criteria = new Array;
	    var cbx = this._getComboBox(key);
	    if (null != cbx && cbx.length > 0) {
		    // Sort the column by the checkbox sort
		    for (var cbxCount = 0; cbxCount < cbx.length; cbxCount++) {
			    criteria[cbxCount] = cbx[cbxCount].value;
		    }
	    }

	    for (var bodyCount=0; bodyCount < this.table.tBodies.length; bodyCount++) {
		    var tableBody = this.table.tBodies[bodyCount];

		    var newRows = new Array;
		    for (var rowCount=0; rowCount < tableBody.rows.length; rowCount++) {
			    newRows[rowCount] = tableBody.rows[rowCount];
		    }
    	
		    this.sort_key_index = colIndex;
		    this.sort_key_criteria = (criteria.length > 0)?criteria:null;
		    newRows.sort(this._sortTableRows.bind(this));
    	
		    var fragment = document.createDocumentFragment();
		    if (desc) {
			    for (var rowCount=newRows.length-1; rowCount >= 0; rowCount--) {
				    fragment.appendChild(newRows[rowCount]);
			    }
		    } else {
			    for (var rowCount=0; rowCount < newRows.length; rowCount++) {
				    fragment.appendChild(newRows[rowCount]);
			    }
		    }
		    tableBody.appendChild(fragment);
	    }
    },

    _sortTableRows: function(row1, row2) {
	    var sValue1 = row1.cells[this.sort_key_index].innerHTML;
	    var sValue2 = row2.cells[this.sort_key_index].innerHTML;
	    if(this.sort_key_index ==0)
	    {
	    	var elem1 = row1.cells[this.sort_key_index].firstChild;
	    	if(elem1.id=="partnumlink")
	    	{
	    	    sValue1 = elem1.firstChild.nodeValue;
	    	}
	    	
	    	var elem2 = row2.cells[this.sort_key_index].firstChild;
		if(elem2.id=="partnumlink")
		{
		    sValue2 = elem2.firstChild.nodeValue;
	    	}
	    }
	    if (sValue1 == sValue2) {
		    // Get the material values and compare.
		    var sValue1 = row1.cells[0].firstChild.value;
		    var sValue2 = row2.cells[0].firstChild.value;
		    if (sValue1 == sValue2)
			    return 0;
		    return (sValue1 < sValue2)?-1:1;
	    }
	    // Get the string values
	    if (this.sort_key_criteria) {
		    var intValue1 = 999;
		    var intValue2 = 999;
		    for (var criteriaCount = 0; criteriaCount < this.sort_key_criteria.length; criteriaCount++) {
			    if (sValue1 == this.sort_key_criteria[criteriaCount])
				    intValue1 = criteriaCount;
			    if (sValue2 == this.sort_key_criteria[criteriaCount])
				    intValue2 = criteriaCount;
		    }
		    if (intValue1 == intValue2) return 0;
		    return (intValue1 < intValue2)?-1:1;
	    } else {
		    if (sValue1 == sValue2) return 0;
		    return (sValue1 < sValue2)?-1:1;
	    }
    },

	popup: function(event) {
		    var img = Event.element(event);
		    var key = this._getKey(img, 'pf_filter_');
		    var popup = $('pf_popup_'+key);
		    if (popup) {
		    	    this.infilterdiv=0;
		    	    
			    if (Element.visible(popup)) {
				    new Effect.BlindUp(popup,{duration:.2});
				    img.src = '/taec/Catalog/images/filter_off.png';
				    img.alt = 'Click to Filter';
				    this.filtimer.stop();
				    this.filtimer.id='';
			    } else {
				    new Effect.BlindDown(popup,{duration:.2});
				    img.src = '/taec/Catalog/images/filter_quit.png';
				    img.alt = 'Click to Close Filter';
				    this.hideme();
				    this.filtimer.id=key;
				    //
				    //this.filtimer.start();
				    
			    }
		    }
	    },
	
		hideme: function() 
		{
			try
			{
				//alert(this.filtimer.id);
				if(this.filtimer.id!='')
				{
					var key = this.filtimer.id;
					var img = $('pf_filter_'+key);
					var popup = $('pf_popup_'+key);
					new Effect.BlindUp(popup,{duration:.2});
					img.src = '/taec/Catalog/images/filter_off.png';
					img.alt = 'Click to Filter';
					
					this.filtimer.stop();
					this.filtimer.id='';
				}
			}
			catch(e)
			{
				this.filtimer.stop();
				//alert(e);
				 $('log').innerHTML += 'Error############            :';
			}
	
	
    	},
	closeColumn: function(event) {
	    var colIndex = this._getColumnIndex(this._getColumn(Event.element(event)));
	    this._closeColumn(colIndex);
	    this.lastaction='clcc|'+ colIndex;
	    this.reload();
    },

	_closeColumn: function(colIndex) {
	    for (var i = 0; i < this.table.rows.length; i++) {
		    Element.hide(this.table.rows[i].cells[colIndex]);
	    }
    },

	showColumn: function(colIndex)
	{
	    for (var i = 0; i < this.table.rows.length; i++) {
			    Element.show(this.table.rows[i].cells[colIndex]);
	    }
	},
    moveColumn: function(element, source, event) {
	    var newIndex = this._getColumnIndex(this._getColumn(element));
	    var oldIndex = this._getColumnIndex(this._getColumn(source));
	    if (this.table.insertBefore && newIndex != oldIndex) {
		    newIndex = Number(newIndex);
		    oldIndex = Number(oldIndex);
		    if (newIndex == oldIndex - 1 || newIndex == oldIndex + 1) {
			    if (newIndex < oldIndex) {
				    var tempIndex = newIndex;
				    newIndex = oldIndex;
				    oldIndex = tempIndex;
			    }
		    }
		    for (var i = 0; i < this.table.rows.length; i++) {
			    var row = this.table.rows[i];
			    row.insertBefore(row.cells[newIndex], row.cells[oldIndex]);
		    }
	    }
	    this.reload();
	    return true;
    },
    
	compare: function(event) {
	    var img = Event.element(event);
	    var parts = document.aspnetForm.parts;
        if (this.comparing) {
            /*if (parts) {
		        for (var count = 0; count < parts.length; count++) {
			        parts[count].checked = false;
		        }
	        }*/
	        img.src = '/images/btn_compare.gif';
	        this.comparing = false;
	        this.reload();
        } else {
	        var checkedCount = 0;
	        if (parts) {
		        for (var count = 0; count < parts.length; count++) {
			        if (parts[count].checked) checkedCount++;
		        }
	        }
	        if (checkedCount > 1) {
		        for (var bodyCount=0; bodyCount < this.table.tBodies.length; bodyCount++) {
			        var tableBody = this.table.tBodies[bodyCount];
			        for (var rowCount=0; rowCount < tableBody.rows.length; rowCount++) {
				        // loop through rows and hide non-matching
				        var display = false;
				        if (tableBody.rows[rowCount].cells[0].firstChild.checked) {
					        display = true;
				        }
						if (display) Element.show(tableBody.rows[rowCount]);
						else Element.hide(tableBody.rows[rowCount]);
			        }
		        }
	            img.src = '/images/btn_compare_clear.gif';
	            this.comparing = true;
				this._reloadTableRows();
	        } else {
	            
		        new Effect.BlindDown('pf_error_no_compare');
	            new Effect.Highlight('pf_error_no_compare', {duration:5, afterFinish:function(){ new Effect.BlindUp('pf_error_no_compare'); } });
	        }
        }
    },
    
	tips: function(event) {
		var tips = $('pf_tips');
		if (Element.visible(tips)) {
			this._closeTips();
		} else {
			this._openTips();
		}
    },
    
	removeFilter: function(event) {
		var span = Event.element(event);
	    var val = this._getKey(span, 'pf_selections_link_').split('|');
	    var key = val[0];
	    var index = parseInt(val[1]);
	    var cbx = this._getComboBox(key);
	    if (cbx) {
	        cbx[index].checked = false;
	    }
	    this.reload();
    },
      	undoLastAction: function(event) {
        		
        	    var val = this.lastaction.split('|');
        	    var key = val[1];
        	    if(val[0]=='fltr')
        	    {
    		    var cbx = this._getComboBox(key);
    		    for(var id =0;id<cbx.length;id++)
    		    {
    
    			if(cbx[id].value==val[2])
    			{
    			 
    			 if( cbx[id].checked == false)
    			 {
    				cbx[id].checked=true;
    			 }
    			 else
    			 {
    				cbx[id].checked=false;
    			 }
    			}
    		    }
    		}
    		else if(val[0]=='clcc')
    		{
    			this.showColumn(val[1]);
    		}
    		else
    		{}
       	
        	    this.reload();
    },
    
	_openTips: function() {
		new Effect.BlindDown('pf_tips', {afterFinish:function(){ $('pf_product_table_tips').src='/images/btn_product_table_tips_close.gif'; }});
	    new Effect.Highlight('pf_tips', {duration:3});
    },
    
	_closeTips: function() {
		new Effect.BlindUp('pf_tips', {afterFinish:function(){ $('pf_product_table_tips').src='/images/btn_product_table_tips.gif'; }});
    },

	reset: function(event) {
        // Reload the page without arguments in the querystring
        window.location = window.location.protocol + '//' + window.location.hostname + window.location.pathname;
    },

	showBookmarkableUrl: function(event) {
        window.location = this.bookmark;
    },
    
	displayColumns: function(event) {
		Element.hide('pf_columns');
		
        var head = this.table.tHead.rows[0];
        var list = '';
        for (var cellCount = 1; cellCount < head.cells.length; cellCount++) {
            var key = this._getColumnKey(head.cells[cellCount]);
            if (key) {
                var attrName = $('pf_attr_name_' + key).innerHTML;
                list += '<li><input name="columns" value="' + key + '" type="checkbox"' + ((Element.visible(head.cells[cellCount]))?' checked':'') + '> ' + attrName + '</li>\n';
            }
        }
        $('pf_column_list').innerHTML = list;
        Sortable.create('pf_column_list');

		Element.hide('pf_display');
		new Effect.BlindDown('pf_columns');
    },

	updateColumns: function(event) {
		Element.show('loading');
		new Effect.BlindUp('pf_columns',{duration:0.1, afterFinish:this._updateColumns.bind(this)});
    },
	
	_updateColumns: function() {
        for (var i = $('pf_column_list').childNodes.length - 1; i >= 0; i--) {
            var cbx = $('pf_column_list').childNodes[i].firstChild;
            var col = $('pf_col_' + cbx.value);
            var oldIndex = 1;
            var newIndex = this._getColumnIndex(col);
            for (var j = 0; j < this.table.rows.length; j++) {
		        var row = this.table.rows[j];
	            var cell1 = row.cells[newIndex];
	            var cell2 = row.cells[oldIndex];
	            // Before we move, set the visibility
				if (cbx.checked) Element.show(cell1);
				else Element.hide(cell1);
	            row.insertBefore(cell1, cell2);
            }
        }
        this.reload();
		
		Element.hide('loading');
		Element.show('pf_display');
    },

	exportExcel: function(event) {
        var table = document.createElement("table");
        var head = document.createElement("thead");
        var row = document.createElement("tr");
        var cell = document.createElement("th");
        cell.innerHTML = 'Part';
        row.appendChild(cell);
        
        for (var cellCount = 1; cellCount < this.table.tHead.rows[0].cells.length; cellCount++) {
            if (Element.visible(this.table.tHead.rows[0].cells[cellCount])) {
                var colKey = this._getColumnKey(this.table.tHead.rows[0].cells[cellCount]);
                var cell = document.createElement("th");
                cell.innerHTML = $('pf_attr_name_' + colKey).innerHTML;
                row.appendChild(cell);
            }
        }
        head.appendChild(row);
        table.appendChild(head);
        
        
	    for (var bodyCount=0; bodyCount < this.table.tBodies.length; bodyCount++) {
	        var body = document.createElement("tbody");
		    var tableBody = this.table.tBodies[bodyCount];
		    for (var rowCount=0; rowCount < tableBody.rows.length; rowCount++) {
                if (Element.visible(tableBody.rows[rowCount])) {
                    var row = document.createElement("tr");
                    var cell = document.createElement("td");
                    //cell.innerHTML = tableBody.rows[rowCount].cells[1].innerHTML;
					cell.innerHTML = tableBody.rows[rowCount].cells[0].firstChild.value;
                    row.appendChild(cell);
                    for (var cellCount = 1; cellCount < tableBody.rows[rowCount].cells.length; cellCount++) {
	                    if (Element.visible(tableBody.rows[rowCount].cells[cellCount])) {
	                        var cell = document.createElement("td");
	                        cell.innerHTML = tableBody.rows[rowCount].cells[cellCount].innerHTML;
	                        row.appendChild(cell);
	                    }
                    }
                    head.appendChild(row);
                }
		    }
            table.appendChild(body);
	    }
        
        document.export_excel.elements[0].value=table.innerHTML;
        document.export_excel.submit();
        //new Ajax.Request('demo-08-excel.ashx', {method:'post', postBody:'table='+escape(table.innerHTML)});
    },

    _getColumn: function(element) {
	    while (element.parentNode != null && element.tagName && 
			    (element.tagName.toLowerCase() != 'th' && 
			     element.tagName.toLowerCase() != 'td')) {
		    element = element.parentNode;
	    }
	    return element;
    },

    _getColumnIndex: function(col) {
	    var cellIndex = col.cellIndex;
	    // Loop through to get the real cell index. (IE bug)
	    var cells = col.parentNode.cells;
	    for (var i = 0; i < cells.length; i++) {
		    if (col == cells[i]) cellIndex = i;
	    }
	    return cellIndex;
    },

    _getColumnKey: function(col) {
	    return this._getKey(col, 'pf_col_');
    },

    _getKey: function(element, startsWith) {
	    if (element && element.id && element.id.indexOf(startsWith)==0) {
		    return element.id.substr(startsWith.length);
	    }
	    return null;
    },

    _getComboBox: function(key) {
	    if (key) {
		    return eval('document.aspnetForm.pf_checkbox_'+key);
	    }
	    return null;
    }
}

function getArgs() {
	var args = new Object();
	var query = window.location.search.substring(1);
	var pairs = query.split('&');
	for (var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var key = pairs[i].substring(0, pos);
		var value = pairs[i].substring(pos + 1);
		args[key] = unescape(value);
	}
	return args;
}
