// constants
// compare table
var COMPARE_PRODUCTS_PAGE_URL = 'CompareProducts.aspx';
var COMPARE_SERVICES_PAGE_URL = 'CompareServices.aspx';
var COMARRE_PAGE_WIDTH = 1000;
var COMARRE_PAGE_HEIGHT = 550;
var COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX = "oCellPropertyLine";

// error message
var ERROR_MSG_COMARE_SELECT_NONE = 'Please select at least one item.';
var ERROR_MSG_COMARE_SELECT_TOO_MANY = 'Please Select no more than 4 items.';
var COMPARE_TABLE_CONTENT_WIDTH = 750;

// gloal vars
var popUpWidow = null;

window.onload = page_OnLoad;

function page_OnLoad()
{	
	// show pop-up message on load
	if ( "undefined" != typeof(bShowMsg) )
	{	
		if(sPopUpMsg == "Operation Success.")
			sPopUpMsg = "Thank you very much for submitting the infomation.Its publication must be approved.We appreciate your patience.!";
		else if(sPopUpMsg == "Leave message success.")
			sPopUpMsg = "Done.";
		window.alert( sPopUpMsg );
		//window.alert( "sPopUpMsg" );
	}
	
	// init selectable control if there is one
	if ( "undefined" != typeof(sSelectedIndexesHidenFieldId) )
	{	
		initMultiSelectableControl();
	}
	
	// init compare control if there is one
	if ( "undefined" != typeof(sItemUnderCompare) )
	{	
		initMultiCompareControl();
	}
}



function initMultiSelectableControl()
{
	if ( "undefined" == typeof(sSelectedIndexesHidenFieldId) || "undefined" == typeof(arrRadioButtonIds) )	
	{
		return;
	}
		
	// hook handler to each radio button to sync selection hidden field value	
	for ( var i = 0; i < arrRadioButtonIds.length; i++ )
	{
		document.getElementById( arrRadioButtonIds[i] ).onclick = syncSelectionHiddenField;
	}
	
	// restore status of selection CheckBoxes
	restoreSelectionCheckBoxes();
}

function syncSelectionHiddenField()
{
	// get previous selected item indexes
	var ctlHidden = document.getElementById( sSelectedIndexesHidenFieldId );
	var sEncodedLastSelection = ctlHidden.value;
	
	// put all selected items into hash table
	var arrSelectedItems = sEncodedLastSelection.split('|');	
	var oSelectedTable = new Object();	
		
	for ( var i = 0; i < arrSelectedItems.length; i++ )
	{
		if ( "" == arrSelectedItems[i] )
		{
			continue;
		}
						
		// value 1 for hash table entry indicates item selected, 0 indicates unselected
		oSelectedTable[ arrSelectedItems[i] ] = 1;		
	}
	
	// validate selected item count and refresh selection status of items in the current page
	var selectedItemCount = 0;
	
	for ( var i = 0; i < arrRadioButtonIds.length; i++ )
	{		
		var control = document.getElementById( arrRadioButtonIds[i] );
				
		oSelectedTable[ control.value ] = control.checked ? 1 : 0;		
	}
	
	// concatenate all selected items
	var sEncodedCurrentSelection = '|';
	
	for ( var key in oSelectedTable )
	{
		if ( oSelectedTable[ key ] )
		{
			sEncodedCurrentSelection += key + '|';
		}
	}
	
	// set hidden to "||" if selected none
	sEncodedCurrentSelection = '|' == sEncodedCurrentSelection ? '||' : sEncodedCurrentSelection;	
		
	// set hidden field	
	ctlHidden.value = sEncodedCurrentSelection;
	
	// window.alert( document.getElementById( sSelectedIndexesHidenFieldId ).value );
	
	// validate selection count: 1-5 inclusive is acceptable for product service compare, 1-* for messaeg manage
	//validateSelectedItemNumber(sEncodedCurrentSelection);	
}

function restoreSelectionCheckBoxes()
{
	//window.alert( document.getElementById( sSelectedIndexesHidenFieldId ).value );
	
	// get previous selected item indexes
	var ctlHidden = document.getElementById( sSelectedIndexesHidenFieldId );
	var sEncodedLastSelection = ctlHidden.value;
	
	// put all selected items into hash table
	var arrSelectedItems = sEncodedLastSelection.split('|');	
	var oSelectedTable = new Object();	
	
	for ( var i = 0; i < arrSelectedItems.length; i++ )
	{
		if ( "" == arrSelectedItems[i] )
		{
			continue;
		}
		
		// value 1 for hash table entry indicates item selected, 0 indicates unselected
		oSelectedTable[ arrSelectedItems[i] ] = 1;
	}
	
	// refresh selection status of items in the current page		
	for ( var i = 0; i < arrRadioButtonIds.length; i++ )
	{		
		var control = document.getElementById( arrRadioButtonIds[i] );
		
		control.checked = oSelectedTable[ control.value ];
	}
}

function showChooseItemPage( comparePageUrl )
{
	var sComparePageFullUrl = '';
	
	// get previous selected item indexes
	var ctlHidden = document.getElementById( sSelectedIndexesHidenFieldId );
	var sEncodedLastSelection = ctlHidden.value;	
	
	// validate selection count: 1-5 inclusive is acceptable
	if ( !validateSelectedItemNumber(sEncodedLastSelection) )
	{
		return;		
	}
	
	// prepare to pop up window
	sComparePageFullUrl = comparePageUrl + '?ids=' + sEncodedLastSelection;
	
	// build feature string to adapt to client screen resolution
	var sFeature = '';

	var height = COMARRE_PAGE_HEIGHT;
	var width = COMARRE_PAGE_WIDTH;
	
	sFeature = 'height=' + height + ',width=' + width + ',resizable=yes,status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes';
	
	// open window
	if ( null != popUpWidow && !popUpWidow.closed )
	{
		popUpWidow.close();	
	}
	
	popUpWidow = window.open(sComparePageFullUrl,null,sFeature);		
	popUpWidow.focus();
}

function validateSelectedItemNumber(sEncodedLastSelection)
{
	// validate selection count: 1-5 inclusive is acceptable	
	var arrSelectedItems = sEncodedLastSelection.split('|');		
	var selectedItemCount = 0;
	var bIsValid = 1;
		
	for ( var i = 0; i < arrSelectedItems.length; i++ )
	{		
		if ( "" == arrSelectedItems[i] )
		{
			continue;
		}
		
		selectedItemCount++;
	}
	
	if ( selectedItemCount <= 0 )
	{
		window.alert(ERROR_MSG_COMARE_SELECT_NONE);
		bIsValid = 0;
	}
	
	if ( 'undefined' == typeof(bIsMessageView) && selectedItemCount > 5 )
	{	
		window.alert(ERROR_MSG_COMARE_SELECT_TOO_MANY);
		bIsValid = 0;	
	}
		
	return bIsValid;
}

function initMultiCompareControl()
{
	// create tables that hold rows for collection of item properties
	createCompareControlHolderTable();	
	
	createCompareControlContentTable();	
	
	// fill content
	if ( 'Product' == sItemUnderCompare )
	{
		fillProductContentTable();
	}
	
	if ( 'Service' == sItemUnderCompare )
	{
		fillServiceContentTable();
	}	
}

// create tables that hold rows for collection of item properties
function createCompareControlHolderTable()
{
	var rowIndex = 0;
	var oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// traverse each row
	while ( null != oRowContainerCell )
	{		
		// create table
		var oRowTable = document.createElement('TABLE');
		oRowTable.border = 0;
		oRowTable.cellPadding = 0;
		oRowTable.cellSpacing = 0;
		
		// create row
		var oRow = oRowTable.insertRow(oRowTable.rows.length-1);
		
		// insert first cell
		var oFirstCell = oRow.insertCell(-1);
		// oFirstCell.innerHTML = 'row' + rowIndex; // debug use
		
		// insert other cells
		for ( var i = 1; i < arrItemsForCompare.length; i++ )
		{
			var oCell = oRow.insertCell(-1);
            oCell.className = 'orangeLeftBoder';
			// oCell.innerHTML = 'cell' + i; // debug use
		}
				
		// add table to container cell
		oRowContainerCell.appendChild(oRowTable)		
		
		// get ref of next row cell container
		rowIndex++;
		oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	}
}	

function createCompareControlContentTable()
{
	// calculate content table width	
	var itemCount = Math.min( arrItemsForCompare.length, 5 );
	var itemWidth = Math.round( COMPARE_TABLE_CONTENT_WIDTH / itemCount );
			
	// create content table
	var rowIndex = 0;
	var oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// traverse each row
	while ( null != oRowContainerCell )
	{		
		// traverse each cell		
		for ( var i = 0; i < oRowContainerCell.lastChild.rows[0].cells.length - 1; i++ )
		{
			// create table
			var oCellTable = document.createElement('TABLE');
			
			// set width
			oCellTable.width = itemWidth;
			oCellTable.border = 0;
			oCellTable.cellPadding = 0;
			oCellTable.cellSpacing = 0;
						
			// create row
			var oRow = oCellTable.insertRow(-1);
			
			// insert first cell
			var oCell = oRow.insertCell(-1);
			oCell.align = 'left';
			//oCell.innerHTML = 'row' + rowIndex;		
			
			oRowContainerCell.lastChild.rows[0].cells[i].appendChild(oCellTable);
		}
		
		// process table for the last column whose width is not set
		// create table
		var oCellTable = document.createElement('TABLE');		
		oCellTable.border = 0;
		oCellTable.cellPadding = 0;
		oCellTable.cellSpacing = 0;
		
		// create row
		var oRow = oCellTable.insertRow(-1);
		
		// insert first cell
		var oCell = oRow.insertCell(-1);
		oCell.align = 'left';
		//oCell.innerHTML = 'row' + rowIndex;		
						
		// add table to container cell
		oRowContainerCell.lastChild.rows[0].cells[i].appendChild(oCellTable);
		
		// get ref of next row cell container
		rowIndex++;
		oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	}	
}

function fillProductContentTable()
{			
    var channelId=Request("channelId"); 		
	// prepare to fill each cell				
	var itemCount = Math.min( arrItemsForCompare.length, 5 );
	
	// ProductName		
	// get ref of container cell
	var rowIndex = 0;
	var oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		
//		"Product/"+rechannel(channelId)+"/"+ arrItemsForCompare[i][0]+"-"+fltr(arrItemsForCompare[i][1])+".html"
		var href ="http://www.ushelf.com/ProductDetail/"+rechannel(channelId)+"-"+ arrItemsForCompare[i][0]+"/"+arrItemsForCompare[i][26]+".html"
		var oNode = createHyperLinkNode(arrItemsForCompare[i][1], href)
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// OrganizationName		
	// get ref of container cell
	rowIndex = 1;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		
		var href = "http://www.ushelf.com/CompanyHome/"+rechannel(channelId)+"-"+arrItemsForCompare[i][9]+"/"+arrItemsForCompare[i][27]+".html";
		var oNode = createHyperLinkNode(arrItemsForCompare[i][10], href)
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);		
	}
		
	// ManufacturerName 	
	// get ref of container cell
	rowIndex = 2;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;		
		var oNode = document.createTextNode(arrItemsForCompare[i][13])
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
		
	// Synonyms	
	// get ref of container cell
	rowIndex = 3;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(arrItemsForCompare[i][14])
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Country_Area
	// get ref of container cell
	rowIndex = 4;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(arrItemsForCompare[i][15])
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Advantages
	// get ref of container cell
	rowIndex = 5;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(fltbr(arrItemsForCompare[i][12]));

		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Certification
	// get ref of container cell
	rowIndex = 6;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(fltbr(arrItemsForCompare[i][3]))
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Quantity
	// get ref of container cell
	rowIndex = 7;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(arrItemsForCompare[i][4])
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Price
	// get ref of container cell
	rowIndex = 8;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;		
		var oNode = null;
		
		if ( '-1' != arrItemsForCompare[i][5].substr( 0, 2 ) )
		{
			oNode = document.createTextNode('$'+arrItemsForCompare[i][5]);
		}
		else
		{
			oNode = getQueryPriceLink(arrItemsForCompare[i][9], arrItemsForCompare[i][10], 
				arrItemsForCompare[i][1], arrItemsForCompare[i][18] );
		}	
		
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// UnitPrice
	// get ref of container cell
	rowIndex = 9;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = null;
		
		if ( '-1' != arrItemsForCompare[i][16].substr( 0, 2 ) )
		{
			oNode = document.createTextNode('$'+arrItemsForCompare[i][16]);
		}
		else
		{
			oNode = getQueryUnitPriceLink(arrItemsForCompare[i][9], arrItemsForCompare[i][10], 
				arrItemsForCompare[i][1], arrItemsForCompare[i][18] );
		}	
		
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
		
	// Content
	// get ref of container cell
	rowIndex = 10;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(fltbr(arrItemsForCompare[i][6]))
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}	
	
	// References		
	// get ref of container cell
	rowIndex = 11;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var href = arrItemsForCompare[i][8];
		var oNode = createHyperLinkNode(arrItemsForCompare[i][7], href)
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Notes
	// get ref of container cell
	rowIndex = 12;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(fltbr(arrItemsForCompare[i][17]))
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
}
function Request(strName) 
{ 
    var strHref=window.location.href;
    var intPos = strHref.indexOf("?"); 
    var strRight = strHref.substr(intPos + 1); 
    var arrTmp = strRight.split("&"); 
    for(var i = 0; i < arrTmp.length; i++) 
    { 
        var arrTemp = arrTmp[i].split("="); 
        if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1]; 
    } 
        return ""; 
} 

function fillServiceContentTable()
{	
     var channelId=Request("channelId"); 				
	// prepare to fill each cell				
	var itemCount = Math.min( arrItemsForCompare.length, 5 );
	
	// ServiceName		
	// get ref of container cell
	var rowIndex = 0;
	var oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		
		var href = "http://www.ushelf.com/ServiceDetail/"+rechannel(channelId)+"-"+ arrItemsForCompare[i][0]+"/"+arrItemsForCompare[i][25]+".html"
		var oNode = createHyperLinkNode(arrItemsForCompare[i][1], href)
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// OrganizationName		
	// get ref of container cell
	rowIndex = 1;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var href = "http://www.ushelf.com/CompanyHome/"+rechannel(channelId)+"-"+arrItemsForCompare[i][9]+"/"+arrItemsForCompare[i][26]+".html";
		var oNode = createHyperLinkNode(arrItemsForCompare[i][10], href)
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
		
	// SupplierName 	
	// get ref of container cell
	rowIndex = 2;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;		
		var oNode = document.createTextNode(arrItemsForCompare[i][13])
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
		
	// Synonyms	
	// get ref of container cell
	rowIndex = 3;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(fltbr(arrItemsForCompare[i][14]))
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Country_Area
	// get ref of container cell
	rowIndex = 4;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(arrItemsForCompare[i][15])
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Advantages
	// get ref of container cell
	rowIndex = 5;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(fltbr(arrItemsForCompare[i][12]))
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Certification
	// get ref of container cell
	rowIndex = 6;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(fltbr(arrItemsForCompare[i][3]))
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Quantity
	// get ref of container cell
	rowIndex = 7;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(arrItemsForCompare[i][4])
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Price
	// get ref of container cell
	rowIndex = 8;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = null;
		
		if ( '-1' != arrItemsForCompare[i][5].substr( 0, 2 ) )
		{
			oNode = document.createTextNode('$'+arrItemsForCompare[i][5]);
		}
		else
		{
			oNode = getQueryPriceLink(arrItemsForCompare[i][9], arrItemsForCompare[i][10], 
				arrItemsForCompare[i][1], arrItemsForCompare[i][17] );
		}	
		
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
			
	// Content
	// get ref of container cell
	rowIndex = 9;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(fltbr(arrItemsForCompare[i][6]))
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}	
	
	// References		
	// get ref of container cell
	rowIndex = 10;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var href = arrItemsForCompare[i][8];
		var oNode = createHyperLinkNode(arrItemsForCompare[i][7], href)
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
	
	// Notes
	// get ref of container cell
	rowIndex = 11;
	oRowContainerCell = document.getElementById( COMPARE_PAGE_PROPERTY_LINE_ID_PREFIX + rowIndex );
	
	// set cell content value
	for ( var i = 0; i < itemCount; i++ )
	{
		// get ref of cell of content table
		var oInnerMostCell = oRowContainerCell.lastChild.rows[0].cells[i].lastChild;
		var oNode = document.createTextNode(fltbr(arrItemsForCompare[i][16]))
		oInnerMostCell.rows[0].cells[0].appendChild(oNode);
	}
}


function getQueryPriceLink(orgId, orgName, itemName, itemString )
{
	var href = '';
	href += 'RequestInfo.aspx?organizationId=';
	href += orgId;
	href += '&organizationName=';
	href += orgName;
	href += '&itemName=';
	href += itemName;
	href += '&itemString=';
	href += itemString;
	href += '&queryAction=';
	href += 'QueryPrice';
	href += '&queryExt1=';
	
	var oNode = createHyperLinkNode('Request...', href)
	
	return oNode;
}

function getQueryUnitPriceLink(orgId, orgName, itemName, itemString )
{
	var href = '';
	href += 'RequestInfo.aspx?organizationId=';
	href += orgId;
	href += '&organizationName=';
	href += orgName;
	href += '&itemName=';
	href += itemName;
	href += '&itemString=';
	href += itemString;
	href += '&queryAction=';
	href += 'QueryUnitPrice';
	href += '&queryExt1=';
	
	var oNode = createHyperLinkNode('Request...', href)
	
	return oNode;
}

function fillDropDownList(ctlId, arrText, arrValue)
{
	var control = document.getElementById(ctlId);
	
	if ( !control )
	{
		return;
	}
	
	for ( var i = 0; i < arrText.length; i++ )
	{	
		var oOption = document.createElement("OPTION");		
		control.options.add(oOption);	
		oOption.innerHTML = arrText[i];
		oOption.value = arrValue[i];		
	}
}

function createHyperLinkNode(text,href)
{
	var node = document.createElement('A');
	node.innerHTML = text;
	node.href = href;
	node.target = '_parent';
	
	return node;
}

function resetForm()
{
	document.forms[0].reset();
}

function openUploadFileWindow()
{
  //var url = 'UploadFile.aspx';
	//var feature = 'height=80,width=250,resizable=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=no';
	//window.open( url, null, feature );	
  var url= 'UploadFile.aspx';              //转向网页的地址;                          //网页名称，可为空;
  var iWidth=360;                          //弹出窗口的宽度;
  var iHeight=130;                        //弹出窗口的高度;
  var iTop = (window.screen.availHeight-30-iHeight)/2;       //获得窗口的垂直位置;
  var iLeft = (window.screen.availWidth-10-iWidth)/2;           //获得窗口的水平位置;
  window.open(url,null,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=no,resizeable=no,location=no,status=no');

}

function openReplyMessageWindow(i)
{
	var url = 'ReplyMessage.aspx?itemId=' + i;
	var feature = 'height=242,width=350,resizable=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=no';
	window.open( url, null, feature );	
}

function openEditForNew(i)
{
	var url = 'EditForNew.aspx?itemId=' + i;
	var feature = 'height=800,width=800,resizable=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=no';
	window.open( url, null, feature );	
}

function selectAllCheckboxesInList(checked)
{
	for( var i = 0; i < arrRadioButtonIds.length; i++ )
	{
		document.getElementById( arrRadioButtonIds[i] ).checked = checked;
	}
	
	syncSelectionHiddenField();
}

function openRecommandwindow()
{

  var url= '/Recommend.aspx';              //转向网页的地址;                          //网页名称，可为空;
  var iWidth=380;                          //弹出窗口的宽度;
  var iHeight=160;                        //弹出窗口的高度;
  var iTop = (window.screen.availHeight-30-iHeight)/2;       //获得窗口的垂直位置;
  var iLeft = (window.screen.availWidth-10-iWidth)/2;           //获得窗口的水平位置;
  window.open(url,null,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=no,resizeable=no,location=no,status=no');
}


function openRetrivePasswordWindow()
{
	
	
	var url= 'PasswordRecoveryStep1.aspx';              //转向网页的地址;                          //网页名称，可为空;
  var iWidth=300;                          //弹出窗口的宽度;
  var iHeight=170;                        //弹出窗口的高度;
  var iTop = (window.screen.availHeight-30-iHeight)/2;       //获得窗口的垂直位置;
  var iLeft = (window.screen.availWidth-10-iWidth)/2;           //获得窗口的水平位置;
  window.open(url,null,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=no,resizeable=no,location=no,status=no');
}

function   sAlert(str){    
    var msgw,msgh,bordercolor;    
    msgw=400;//提示窗口的宽度    
    msgh=500;//提示窗口的高度    
    titleheight=25   //提示窗口标题高度    
    bordercolor="#336699";//提示窗口的边框颜色    
    titlecolor="#99CCFF";//提示窗口的标题颜色    
  
    var   sWidth,sHeight;    
    sWidth=document.body.offsetWidth;//浏览器工作区域内页面宽度    
    sHeight=screen.height;//屏幕高度（垂直分辨率）    
  
  
  
    //背景层（大小与窗口有效区域相同，即当弹出对话框时，背景显示为放射状透明灰色）    
    var   bgObj=document.createElement("div");//创建一个div对象（背景层）    
       
    //定义div属性，即相当于    
    // <div   id="bgDiv"   style="position:absolute;   top:0;   background-color:#777;   filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);   opacity:0.6;   left:0;   width:918px;   height:768px;   z-index:10000;"> </div>    
    bgObj.setAttribute("id","bgDiv");   
    //alert("***********")   
    bgObj.style.position="absolute";    
    bgObj.style.top="0";    
    bgObj.style.background="#777";    
    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";    
    bgObj.style.opacity="0.6";    
    bgObj.style.left="0";    
    bgObj.style.width=sWidth   +  "px";    
    bgObj.style.height=sHeight   +  "px";    
    bgObj.style.zIndex   =  "10000";    
    document.body.appendChild(bgObj);//在body内添加该div对象    
  
  
  
    var   msgObj=document.createElement("div")//创建一个div对象（提示框层）    
    //定义div属性，即相当于    
    // <div   id="msgDiv"   align="center"   style="background-color:white;   border:1px   solid   #336699;   position:absolute;   left:50%;   top:50%;   font:12px/1.6em   Verdana,Geneva,Arial,Helvetica,sans-serif;   margin-left:-225px;   margin-top:npx;   width:400px;   height:100px;   text-align:center;   line-height:25px;   z-index:100001;"> </div>    
    msgObj.setAttribute("id","msgDiv");    
    msgObj.setAttribute("align","center");    
    msgObj.style.background="white";    
    msgObj.style.border="1px   solid  "   +   bordercolor;    
    msgObj.style.position   =  "absolute";    
    msgObj.style.left   =  "50%";    
    msgObj.style.top   =  "50%";    
    msgObj.style.font="12px/1.6em   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif";    
    msgObj.style.marginLeft   =  "-225px"   ;    
    msgObj.style.marginTop   =   -75+document.documentElement.scrollTop+"px";    
    msgObj.style.width   =   msgw   +  "px";    
    msgObj.style.height   =msgh   +  "px";    
    msgObj.style.textAlign   =  "center";    
    msgObj.style.lineHeight   ="25px";    
    msgObj.style.zIndex   =  "10001";    
    //alert("***********")   
    var   title=document.createElement("h4");//创建一个h4对象（提示框标题栏）    
    //定义h4的属性，即相当于    
    // <h4   id="msgTitle"   align="right"   style="margin:0;   padding:3px;   background-color:#336699;   filter:progid:DXImageTransform.Microsoft.Alpha(startX=20,   startY=20,   finishX=100,   finishY=100,style=1,opacity=75,finishOpacity=100);   opacity:0.75;   border:1px   solid   #336699;   height:18px;   font:12px   Verdana,Geneva,Arial,Helvetica,sans-serif;   color:white;   cursor:pointer;"   onclick=""> 关闭 </h4>    
    title.setAttribute("id","msgTitle");    
    title.setAttribute("align","right");    
    title.style.margin="0";    
    title.style.padding="3px";    
    title.style.background=bordercolor;    
    title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20,   startY=20,   finishX=100,   finishY=100,style=1,opacity=75,finishOpacity=100);";    
    title.style.opacity="0.75";    
    title.style.border="1px   solid  "   +   bordercolor;    
    title.style.height="18px";    
    title.style.font="12px   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif";    
    title.style.color="white";    
    title.style.cursor="pointer";    
    title.innerHTML="Close";    
    title.onclick=removeObj;    
  
   
       
    function   removeObj(){//点击标题栏触发的事件    
        document.body.removeChild(bgObj);//删除背景层Div    
        document.getElementById("msgDiv").removeChild(title);//删除提示框的标题栏    
        document.body.removeChild(msgObj);//删除提示框层    
    }    
    document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj    
    document.getElementById("msgDiv").appendChild(title);//在提示框div中添加标题栏对象title    
  
    var   txt=document.createElement("p");//创建一个p对象（提示框提示信息）    
    //定义p的属性，即相当于    
    // <p   style="margin:1em   0;"   id="msgTxt"> 测试效果 </p>    
    txt.style.margin="1em   0"    
    txt.setAttribute("id","msgTxt");    
    txt.innerHTML=str;//来源于函数调用时的参数值    
    document.getElementById("msgDiv").appendChild(txt);//在提示框div中添加提示信息对象txt    
     
  
}    
//用于比较页面
function Request(strName) 
{ 
    var strHref=window.location.href;
    var intPos = strHref.indexOf("?"); 
    var strRight = strHref.substr(intPos + 1); 
    var arrTmp = strRight.split("&"); 
    for(var i = 0; i < arrTmp.length; i++) 
    { 
        var arrTemp = arrTmp[i].split("="); 
        if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1]; 
    } 
        return ""; 
} 
//用于比较页面
 function getbooklist() 
    { 
        var j = 0;
		
        var valueList=""; 
        var cbs=document.getElementsByTagName("input"); 
        var channelId = document.getElementById("hidden").value;
        for(var i=0;i <cbs.length;i++) 
        { 
          if(cbs[i].type=='checkbox'&&cbs[i].checked) 
          { 
             valueList=valueList+cbs[i].value+"|"; 
             j=j+1;
          } 
           
        } 
        if (j > 4)
		{
			alert("You are attempting to compare more than 5 products.");
		}
		else
		{
          if(j==0)
           { 
            alert("No items selected to compare");
           }
           else
           {
              valueList="|"+valueList;
              window.location = 'http://www.ushelf.com/CompareServices.aspx' + '?ids='+valueList+'&channelId='+channelId;
              
           }
        }
         


    } 
    
    //用于比较页面
 function getbooklist1() 
    { 
        var j = 0;
		
        var valueList=""; 
        var cbs=document.getElementsByTagName("input"); 
        var channelId = document.getElementById("hidden").value;
        for(var i=0;i <cbs.length;i++) 
        { 
          if(cbs[i].type=='checkbox'&&cbs[i].checked) 
          { 
             valueList=valueList+cbs[i].value+"|"; 
             j=j+1;
          } 
           
        } 
        if (j > 4)
		{
			alert("You are attempting to compare more than 5 products.");
		}
		else
		{
          if(j==0)
           { 
            alert("No items selected to compare");
           }
           else
           {
              valueList="|"+valueList;
              window.location = 'http://www.ushelf.com/CompareProducts.aspx' + '?ids='+valueList+'&channelId='+channelId;
              
           }
        }
         


    }
    
    function fltr(str) 
    {  
       var str1;
       
       str1=str.replace(/&/g,'n');
       str1=str.replace(/%/g,'-percent-');
       str1=str.replace(/./g,'');
       str1=str.replace(/,/g,'');
       str1=str.replace(/:/g,'');
       str1=str.replace(/ /g,'-');
       
       
       return  str1;

     }  
     
     function fltbr(str) 
     {  
       var str1;
       str1=str.replace(/\<br \/\>/g,'\r\n');
       return  str1;
     }  
     
     function rechannel(str) 
     {  
       var str1;
       if(str==2)
       {
         str1="2";
       }
       else if(str==7)
       {
         str1="7";
       }
       else if(str==9)
       {
         str1="9";
       }
       else if(str==11)
       {
         str1="11";
       }
        else if(str==12)
       {
         str1="12";
       }
       else if(str==13)
       {
         str1="13";
       }
       else
       {
         str1="16";
       }
       return  str1;
     }  
     
     
     
     
     


