<!-- Copyright (c) 2004, 2007 by Cisco Systems, Inc. -->
// smartports.js - Will create the frontPanel for Xmen2 devices.
// <include a list of SKUs here>

function createDevice(deviceType, uiPortDataArr) {
	
	var device = null;
	if(deviceType.indexOf("C2950G")!=-1){
		
		document.writeln('<table border="0" cellpadding="0" cellspacing="0">');
		device = new WSC2955(uiPortDataArr);
		document.writeln('</table>');
	}else{
	document.write('<table width="100%"  border="0" cellpadding="0" cellspacing="5" align="center"><tr>');
	document.write('<td height=100%><table class="tblecontentstyle" border="0" cellpadding="1" cellspacing="1" align="center" height="100%"><tr>');
	//if(Is8PortDevice(uiPortDataArr) == false ){
	if(top.getSelectedDevice().image.indexOf("rock_4")!=-1 ||top.getSelectedDevice().image.indexOf("magneto_4")!=-1 ){
		document.write('<td colspan="8" width="135">&nbsp;</td></tr><tr>');
	}	
	document.write('<td height=100%><table width="100%" border="0" cellpadding="1" cellspacing="1" height="100%" >');
	device = new WSC2955RckWell(uiPortDataArr,deviceType);
	document.write('</table></td>');
	//document.write('</tr><tr><td colspan="8" bgcolor="#f4f4f4">&nbsp;</td>');
	document.write('</tr></table></td>');
	var indxValue2="Fa2";var indxValue3="Fa3";
	if(top.getSelectedDevice().expander1 !=null && top.getSelectedDevice().expander1 !=""){
	document.write('<td height=100%><table  height="100%" class="tblecontentstyle" border="0" cellpadding="1" cellspacing="1"><tr>');
	document.write('<td colspan="3" bgcolor="#f4f4f4">&nbsp;<td></tr><tr>');
	document.write('<td valign="top" height="100%"  bgcolor="#f4f4f4">');
	if(top.getSelectedDevice().expander1.indexOf("FE")!=-1){
		WriteCell(indxValue2);
		document.write('</td></tr><tr><td colspan="3" bgcolor="#f4f4f4">&nbsp;<td></tr></table></td>');
	}else if(top.getSelectedDevice().expander1.indexOf("FX")!=-1){
		WriteFpCell(indxValue2);
		document.write('</td></tr><tr><td colspan="3" bgcolor="#f4f4f4">&nbsp;<td></tr></table></td>');
	}
	}
	if(top.getSelectedDevice().expander2!=null && top.getSelectedDevice().expander2 !=""){
		document.write('<td height=100%><table  height="100%" class="tblecontentstyle" border="0" cellpadding="1" cellspacing="1"><tr>');
		document.write('<td colspan="3" bgcolor="#f4f4f4">&nbsp;</td></tr><tr>');
		document.write('<td valign="top" height=100%  bgcolor="#f4f4f4">');
		if(top.getSelectedDevice().expander2.indexOf("FE")!=-1){
		WriteCell(indxValue3);
		document.write('</td></tr><tr><td colspan="3" bgcolor="#f4f4f4">&nbsp;<td></tr></table></td>');
		document.write('<td><table height="100%" class="tblecontentstyle" border="0" cellpadding="1" cellspacing="1"><tr>');
		document.write('<td colspan="3" bgcolor="#f4f4f4">&nbsp;</td></tr><tr>');
		document.write('<td valign="top" height=100%  bgcolor="#f4f4f4">');
		}else if(top.getSelectedDevice().expander2.indexOf("FX")!=-1){
		WriteFpCell(indxValue3);
		}
		document.write('</td></tr><tr><td colspan="3" bgcolor="#f4f4f4">&nbsp;</td></tr></table></td>');				
	}
	document.write('</tr></table>');
	}
}
function Is8PortDevice(PortNames){
	var is8Port = false;
	for(var t=0;t<PortNames.length;t++){
		if(PortNames[t].portName.indexOf("Fa1/5")!=-1){
			is8Port = true;
			}
	}
	return is8Port;
}
/*
 *  This is unit tested.
 */
function WSC2955(uiPortDataArr) {

	portCount = uiPortDataArr.length;
	
	document.writeln('\
				  <tr><td colspan= "25" height="3" bgcolor="#f4f4f4">')
   	document.writeln('\
				  </td></tr>')
	document.writeln('\
	  						<tr>')
	writeSpaceCell();
	for (var portId = 0; portId < portCount - 2 ; portId++) {
  		// This is extra space between port 12 and 13
		if( (portId) % 12 == 0)
		  document.writeln('\
			<td nowrap width="10" bgcolor="#f4f4f4">&nbsp;</td>')
			if ( portId % 2 == 0) {
				document.writeln('\
					<td align="center" width="21" bgcolor="#f4f4f4"><font style="font-size:9px"\
					face="Helvetica">', getPortLabel(uiPortDataArr[portId].portName), '<br>\
					</font><a href="javascript:void(0)"\
					onMouseOver="showPortInfo(\'', portId, '\', \'', uiPortDataArr[portId].portName, '\', \'', uiPortDataArr[portId].vlan, '\')"\
					onMouseOut="resetPort(); hideLayerWrapper(2000); raise(\'', portId, '\')"\
					onMouseDown="lower(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\')"\
					onMouseUp="window.status=\'\'; return true"\
					onClick="toggle(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\'); return false"><img\
					src="', cellImages[0][uiPortDataArr[portId].macro].src, '"\
					border="0"\
				    width="21" height="21" name="cell', '_', portId, '"></a></td>')
			}
		}
		writeSpaceCell();	writeSpaceCell();	writeSpaceCell();	writeSpaceCell();	writeSpaceCell();
		writeSpaceCell();	writeSpaceCell();	writeSpaceCell();
		document.writeln('\
				  </tr>')
		document.writeln('\
				  <tr><td colspan= "25" height="5" bgcolor="#f4f4f4">')
    	document.writeln('\
				  </td></tr>')				  
		writeSpaceCell();
						  
	    for (var portId = 0; portId < portCount-2 ; portId++) {
	  		// This is extra space between port 12 and 13
			if( (portId) % 12 == 0)
		  document.writeln('\
			<td nowrap width="10" bgcolor="#f4f4f4">&nbsp;</td>')
			if ( portId % 2 != 0) {
				document.writeln('\
					<td align="center" width="21" bgcolor="#f4f4f4"><a href="javascript:void(0)"\
					onMouseOver="showPortInfo(\'', portId, '\', \'', uiPortDataArr[portId].portName, '\', \'', uiPortDataArr[portId].vlan, '\')"\
					onMouseOut="resetPort(); hideLayerWrapper(2000); raise(\'', portId, '\')"\
					onMouseDown="lower(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\')"\
					onMouseUp="window.status=\'\'; return true"\
					onClick="toggle(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\'); return false"><img\
					src="', cellImages[0][uiPortDataArr[portId].macro].src, '"\
					border="0"\
				    width="21" height="21" name="cell', '_', portId, '"></a><br>\
					<font style="font-size:9px" face="Helvetica">', getPortLabel(uiPortDataArr[portId].portName), '\
					</td>')
			}
		}
		document.writeln('\
				  <td nowrap width="20" bgcolor="#f4f4f4">&nbsp;</td>')  
		document.writeln('\
				  <td nowrap width="20" bgcolor="#f4f4f4">&nbsp;</td>')  
		for (var portId = portCount-2; portId < portCount ; portId++) {
			document.writeln('\
				  <td nowrap width="10" bgcolor="#f4f4f4">&nbsp;</td>') 
			document.writeln('\
					<td align="center" width="21" bgcolor="#f4f4f4"><a href="javascript:void(0)"\
					onMouseOver="showPortInfo(\'', portId, '\', \'', uiPortDataArr[portId].portName, '\', \'', uiPortDataArr[portId].vlan, '\')"\
					onMouseOut="resetPort(); hideLayerWrapper(2000); raise(\'', portId, '\')"\
					onMouseDown="lower(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\')"\
					onMouseUp="window.status=\'\'; return true"\
					onClick="toggle(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\'); return false"><img\
					src="', cellImages[0][uiPortDataArr[portId].macro].src, '"\
					border="0"\
				    width="21" height="21" name="cell', '_', portId, '"></a><br>\
					<font style="font-size:9px" face="Helvetica">', getPortLabel(uiPortDataArr[portId].portName), '\
					</td>')
		}
		writeSpaceCell(); writeSpaceCell();                                                         
		
		document.writeln('\
			  </tr>')
		document.writeln('\
				  <tr><td colspan= "25" height="5" bgcolor="#f4f4f4">')
    	document.writeln('\
				  </td></tr>')		
}

function WSC2955RckWell(uiPortDataArr,deviceType) {
	
	
	portCount = uiPortDataArr.length;
	
	
	document.writeln('\<tr><td height="100%">');//Table to display the gigs bits links 	
	document.writeln('\<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">');
	
	InsertEmptyRow();
	document.writeln('\<tr bgcolor="#f4f4f4"><td height="100%" valign="bottom">&nbsp;');
	
	document.writeln('\<table  border="0" cellpadding="1" cellspacing="1" bgcolor="#f4f4f4">');
	
	for (var portId = portCount-2; portId < portCount ; portId++) {
		document.writeln('\
					<tr><td bgcolor="#f4f4f4" align="left"><font style="font-size:9px"\
					face="Helvetica">', getPortLabel(uiPortDataArr[portId].portName), '\
					</font></td><td valign="top" align="left" width="65" bgcolor="#f4f4f4"><a href="javascript:void(0)"\
					onMouseOver="showPortInfo(\'', portId, '\', \'', uiPortDataArr[portId].portName, '\', \'', uiPortDataArr[portId].vlan, '\')"\
					onMouseOut="resetPort(); hideLayerWrapper(2000); raise(\'', portId, '\')"\
					onMouseDown="lower(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\')"\
					onMouseUp="window.status=\'\'; return true"\
					onClick="toggle(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\'); return false"><img\
					src="', cellImages[0][uiPortDataArr[portId].macro].src, '"\
					border="0"\
				    width="21" height="21" name="cell', '_', portId, '"></a></td></tr>')
	}
	
	
	document.writeln('\</table>');
	document.writeln('\</td></tr>');
	document.writeln('\</table>');
	
	document.writeln('\</td>');
	
	
	document.writeln('\<td valign="top" height=100%>');
	//document.writeln('\<table height="100%" width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#f4f4f4">');
	
	//table to display the port and its details
	var indxValue="Fa1";
	//if(Is8PortDevice(uiPortDataArr) == false ){
		if(top.getSelectedDevice().image.indexOf("rock_4")!=-1 ||top.getSelectedDevice().image.indexOf("magneto_4")!=-1 ){
	WriteCell(indxValue);	
	}else{
	
	Write8PCell(indxValue);
	}
	document.writeln('\</td></tr>'); 
}
function Write8PCell(indxValue){
for (var portId = 0; portId < portCount - 2 ; portId++) {
		var cellindx=parseInt(getPortLabel(uiPortDataArr[portId].portName));
		
		if(uiPortDataArr[portId].portName.indexOf(indxValue)!=-1){
			
		if(cellindx==1){
		document.writeln('\<table width=100% border="0" cellpadding= 0 cellspacing=0><tr>');
		document.writeln('<td colspan=2 bgcolor="#f4f4f4" width="21" height="42" style="font-size:2px">&nbsp;</td></tr>')	
		
		}
		if( cellindx==5){
		document.write('</table></td>');	
		document.write('<td><table width=100%  border="0" cellpadding=0 cellspacing=0>');
		}
		document.writeln('<tr>');
		if(cellindx<=4 ){
			
			document.writeln('<td bgcolor="#f4f4f4" align="right"><font style="font-size:9px"\
					face="Helvetica">', getPortLabel(uiPortDataArr[portId].portName), '\
					</font></td>')
		}
		
		
				document.write('\
					<td height="21" width="21" bgcolor="#f4f4f4"><a href="javascript:void(0)"\
					onMouseOver="showPortInfo(\'', portId, '\', \'', uiPortDataArr[portId].portName, '\', \'', uiPortDataArr[portId].vlan, '\')"\
					onMouseOut="resetPort(); hideLayerWrapper(2000); raise(\'', portId, '\')"\
					onMouseDown="lower(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\')"\
					onMouseUp="window.status=\'\'; return true"\
					onClick="toggle(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\'); return false"><img\
					src="', cellImages[0][uiPortDataArr[portId].macro].src, '"\
					border="0"\
				    width="21" height="21" name="cell', '_', portId, '"></a></td>');
					
		if(cellindx>4){
			
			document.writeln('<td bgcolor="#f4f4f4"><font style="font-size:9px"\
					face="Helvetica">&nbsp;', getPortLabel(uiPortDataArr[portId].portName), '\
					</font></td>')
		}
		document.writeln('</tr>');
		if(cellindx!=0 && (cellindx==2 || cellindx==6 )){
			InsertEmptyCell(cellindx,indxValue);
		}			
		
		if(cellindx == 8){
		document.writeln('<tr><td colspan=2 bgcolor="#f4f4f4" width="21" height="21" style="font-size:2px">&nbsp;</td></tr>')	
		}			
		}
		
		
		
	}
	
	document.writeln('\</tr></table>');	
}
function WriteCell(indxValue){
	
	for (var portId = 0; portId < portCount - 2 ; portId++) {
		var cellindx=parseInt(getPortLabel(uiPortDataArr[portId].portName));
		
		if(uiPortDataArr[portId].portName.indexOf(indxValue)!=-1){
			
		if(cellindx==1){
		document.writeln('\<table width=100% border="0" cellpadding= 0 cellspacing=0><tr>');
		//if(indxValue.indexOf("Fa1")==-1 && (Is8PortDevice(uiPortDataArr) == true) ){
		if(indxValue.indexOf("Fa1")==-1 && (top.getSelectedDevice().image.indexOf("rock_4")==-1 || top.getSelectedDevice().image.indexOf("magneto_4")==-1 ) ){
		document.writeln('<td colspan=2 bgcolor="#f4f4f4" width="21" height="21" style="font-size:2px">&nbsp;</td></tr>')	
		}
				
		}
		if( cellindx==5){
		document.write('</table></td>');	
		document.write('<td height="100%"><table width=100% height="100%" border="0" cellpadding=0 cellspacing=0>');
		}
		document.writeln('<tr>');
		if(cellindx<=4  && indxValue.indexOf("Fa1")==-1 ){//To place the label either left of image or right of image 
			
			document.writeln('<td bgcolor="#f4f4f4" align="right"><font style="font-size:9px"\
					face="Helvetica">', getPortLabel(uiPortDataArr[portId].portName), '\
					</font></td>')
		}
		
		
				document.write('\
					<td height="21" width="21" bgcolor="#f4f4f4"><a href="javascript:void(0)"\
					onMouseOver="showPortInfo(\'', portId, '\', \'', uiPortDataArr[portId].portName, '\', \'', uiPortDataArr[portId].vlan, '\')"\
					onMouseOut="resetPort(); hideLayerWrapper(2000); raise(\'', portId, '\')"\
					onMouseDown="lower(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\')"\
					onMouseUp="window.status=\'\'; return true"\
					onClick="toggle(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\'); return false"><img\
					src="', cellImages[0][uiPortDataArr[portId].macro].src, '"\
					border="0"\
				    width="21" height="21" name="cell', '_', portId, '"></a></td>');
					
		if((cellindx<=4  && indxValue.indexOf("Fa1")!=-1)||(cellindx>4  && indxValue.indexOf("Fa1")==-1)){
			
			document.writeln('<td bgcolor="#f4f4f4"><font style="font-size:9px"\
					face="Helvetica">&nbsp;', getPortLabel(uiPortDataArr[portId].portName), '\
					</font></td>')
		}
		document.writeln('</tr>');
		if(cellindx!=0 && (cellindx==2 || cellindx==6 )){
			InsertEmptyCell(cellindx,indxValue);
		}			
		
		if(cellindx == 8){
		document.writeln('<tr><td colspan=2 bgcolor="#f4f4f4" width="21" height="21" style="font-size:2px">&nbsp;</td></tr>')	
		}			
		}
		
		
		
	}
	
	document.writeln('\</tr></table>');
}
function WriteFpCell(indxValue){
	for (var portId = 0; portId < portCount - 2 ; portId++) {
		var cellindx=parseInt(getPortLabel(uiPortDataArr[portId].portName));
		
		if(uiPortDataArr[portId].portName.indexOf(indxValue)!=-1){
			
		if(cellindx==1){
		document.writeln('\<table width=100% border=0 cellpadding= 0 cellspacing=0><tr>');
		document.writeln('<td colspan=2 bgcolor="#f4f4f4" width="21" height="21" style="font-size:2px">&nbsp;</td></tr>')
		}
		if( cellindx==5){
		document.write('</table></td>');	
		document.write('<td height="100%"><table width=100% height="100%" border=0 cellpadding=0 cellspacing=0>');
		document.writeln('<tr><td colspan=2 bgcolor="#f4f4f4" width="21" height="21" style="font-size:2px">&nbsp;</td></tr>')
		}
		document.writeln('<tr>');
		if(cellindx<=4){
			document.writeln('<td bgcolor="#f4f4f4" align="right"><font style="font-size:9px"\
					face="Helvetica">', getPortLabel(uiPortDataArr[portId].portName), '\
					</font></td>')
		}
		
		
				document.write('\
					<td height="21" width="21" bgcolor="#f4f4f4"><a href="javascript:void(0)"\
					onMouseOver="showPortInfo(\'', portId, '\', \'', uiPortDataArr[portId].portName, '\', \'', uiPortDataArr[portId].vlan, '\')"\
					onMouseOut="resetPort(); hideLayerWrapper(2000); raise(\'', portId, '\')"\
					onMouseDown="lower(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\')"\
					onMouseUp="window.status=\'\'; return true"\
					onClick="toggle(\'', portId, '\', \'', uiPortDataArr[portId].macro, '\'); return false"><img\
					src="', cellImages[0][uiPortDataArr[portId].macro].src, '"\
					border="0"\
				    width="21" height="21" name="cell', '_', portId, '"></a></td>');
					
		if(cellindx>4){
			document.writeln('<td bgcolor="#f4f4f4"><font style="font-size:9px"\
					face="Helvetica">&nbsp;', getPortLabel(uiPortDataArr[portId].portName), '\
					</font></td>')
		}
		document.writeln('</tr>');
		if(cellindx!=0 && (cellindx==2 || cellindx==6 )){
			InsertEmptyCell(cellindx,indxValue);
		}			
		}
		
		
		
	}
	
	document.writeln('\</tr></table>');
}
function InsertEmptyRow(){
	document.writeln('\<tr bgcolor="#f4f4f4"><td>&nbsp;</td></tr>');
	document.write('<tr><td bgcolor="#f4f4f4" height="28">&nbsp;</td></tr>')	
	document.write('<tr><td bgcolor="#f4f4f4" height="28">&nbsp;</td></tr>')
	
}
function InsertEmptyCell(cellIndex,indxValue){
	document.write('<tr><td colspan=2 bgcolor="#f4f4f4" width="21" height="21" style="font-size:2px">&nbsp;</td></tr>')	
	document.write('<tr><td colspan=2 bgcolor="#f4f4f4" width="21" height="21" style="font-size:2px">&nbsp;</td></tr>')
}
function getPortLabel(intName) {
	var intNumber = intName.substring(intName.indexOf('/')+1);
	return parseInt(intNumber)
}

function isExtVlanSupported() {
	return true;
}

function getMaxVlans() {
      return 250;
}
