      function Left(str, n)
    	{
    		if (n <= 0)
    		    return "";
    		else if (n > String(str).length)
    		    return str;
    		else
    		    return String(str).substring(0,n);
    	}
    
	function getText(el)
	{
		if (el.textContent) return el.textContent;
		if (el.innerText) return el.innerText;
		return el.innerHTML.replace(/<[^>]*>/g,'');
	}
	
    	function Right(str, n)
    	{
    		if (n <= 0)
    		   return "";
    		else if (n > String(str).length)
    		   return str;
    		else {
    		   var iLen = String(str).length;
    		   return String(str).substring(iLen, iLen - n);
    		}
    	}
    	function trim(stringToTrim) 
	{
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	
    	function validatelength()
    	{
    		//this function validates the length of a cable.  for now
    		//i am assuming that length is between 1 and 999
    		//it does not work yet
    
    	}
    	
    	function filltypes()
    	{
    		
    		document.forms['connectorform'].option.options.length = 0;
    		document.forms['connectorform2'].option.options.length = 0;
    		calculateprice();
			
    		document.forms['connectorform'].type.options.length = 0;
    		document.forms['connectorform2'].type.options.length = 0;
    		document.forms['connectorform'].type.options[document.forms['connectorform'].type.length]=new Option(' ', ' ')
    		document.forms['connectorform2'].type.options[document.forms['connectorform2'].type.length]=new Option(' ', ' ')
    				
    		//j is equal to the name of the cable
    		j=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		j=j+'^';
    		j=String(j);
    		
    		q=j.length;
    		
    		for(i=0;i<CompatType.length;i++)
    		{
    			if(Left(CompatType[i], q)==j)
    			{
    			
    				myval=Right(CompatType[i], CompatType[i].length-q);
    				document.forms['connectorform'].type.options[document.forms['connectorform'].type.length]=new Option(myval, myval);
    				document.forms['connectorform2'].type.options[document.forms['connectorform2'].type.length]=new Option(myval, myval);
    			}
    		}
    		
    	}
    	
	function fillmultitypes()
    	{
    		
    		document.forms['connectorform'].option.options.length = 0;
    		document.forms['connectorform2'].option.options.length = 0;
    					
    		document.forms['connectorform'].type.options.length = 0;
    		document.forms['connectorform2'].type.options.length = 0;
    		document.forms['connectorform'].type.options[document.forms['connectorform'].type.length]=new Option(' ', ' ')
    		document.forms['connectorform2'].type.options[document.forms['connectorform2'].type.length]=new Option(' ', ' ')
    				
    		document.forms['multiform'].multiinfo.value ="";
		
		//j is equal to the name of the cable
    		j=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		
		for(i=0;i<cables.length;i++)
		{
			if (j == cables[i])
			{
				document.forms['multiform'].multiinfo.value ="Cable: " + j + " " + trim(cabdescription[i]);
				index = i;
			}
		}
    		
		//then fill in values for the thing
                document.getElementById('sideamulti').innerHTML = "Side A has " + cabchannels[index] + " channel(s) available.";
                sideachannels = cabchannels[index];
                document.getElementById('sidebmulti').innerHTML = "Side B has " + cabchannels[index] + " channel(s) available.";
                sidebchannels = cabchannels[index];
		
		j=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		   				
		j=j+'^';
		q=j.length;
    		j=String(j);
		
    		for(i=0;i<CompatType.length;i++)
    		{
    			if(Left(CompatType[i], q)==j)
    			{
				myval=Right(CompatType[i], CompatType[i].length-q);
				document.forms['connectorform'].type.options[document.forms['connectorform'].type.length]=new Option(myval, myval);
    				document.forms['connectorform2'].type.options[document.forms['connectorform2'].type.length]=new Option(myval, myval);
    			}
    		}
    		
    	}
	
	function fillmultiside(whichSide)
    	{
    		
		//alert('hi');
		if(whichSide == 1)
		{
			//alert('=1');
			document.forms['connectorform'].option.options.length = 0;
			document.forms['connectorform'].type.options.length = 0;
			document.forms['connectorform'].type.options[document.forms['connectorform'].type.length]=new Option(' ', ' ')
    		}
		else if(whichSide==2)
		{
			document.forms['connectorform2'].option.options.length = 0;
			document.forms['connectorform2'].type.options.length = 0;
			document.forms['connectorform2'].type.options[document.forms['connectorform2'].type.length]=new Option(' ', ' ')
		}		
    		
    				//j is equal to the name of the cable
    		j=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		
		for(i=0;i<cables.length;i++)
		{
			if (j == cables[i])
			{
				index = i;
			}
		}
    		
		//then fill in values for the thing
		if(whichSide == 1)
		{
			document.getElementById('sideamulti').innerHTML = "Side A has " + cabchannels[index] + " channel(s) available.";
                	sideachannels = cabchannels[index];
                }
		else
		{
			document.getElementById('sidebmulti').innerHTML = "Side B has " + cabchannels[index] + " channel(s) available.";
			sidebchannels = cabchannels[index];
		}
		j=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		   				
		j=j+'^';
		q=j.length;
    		j=String(j);
		//alert("j is " + j);
    		for(i=0;i<CompatType.length;i++)
    		{
    			if(Left(CompatType[i], q)==j)
    			{
				//alert("iscompatible");
				myval=Right(CompatType[i], CompatType[i].length-q);
				if(whichSide == 1)
				{
					//alert("adding option" + myval);
					document.forms['connectorform'].type.options[document.forms['connectorform'].type.length]=new Option(myval, myval);
    				}
				else
					document.forms['connectorform2'].type.options[document.forms['connectorform2'].type.length]=new Option(myval, myval);
    			}
    		}
    		
    	}
	
	
	/* this function does a number of different tasks.
	  1st-- It checks to see how many connector slots are left on the side
	        it is being called for.
	  2nd-- It then takes a connector, takes the number of connections for
	        that connector and multiples it by connector count
		then it subtracts from the availalbe slots
		if that number is < 0, then an error appears.
          3rd-- if that number is >=0, then it adds the connector to the list box
	        calculates the price
		and updates the number of available connectors--that's it!
	*/	
	function AddMulti(whichform)
	{
		/* How many of each connector do we want to add */
		if(whichform==1)
		{
			conCount = document.forms['connectorform'].sideANumber.value;
			availableSlots =  getText(document.getElementById('sideamulti'));
		}
		else
		{
			conCount = document.forms['connectorform2'].sideBNumber.value;
			availableSlots =  getText(document.getElementById('sidebmulti'));
		}
		/* Now parse available slots so we can get the number of entries left */
		
		
		
		availableSlots = Left(availableSlots, 13); /* Just get the "Side X has XX" */
	
		availableSlots = Right(availableSlots, 2);
	
		availableSlots = trim(availableSlots);
	
		
		/* What connector do we want to add */
		if(whichform==1)
			connector = document.forms['connectorform'].option.options[document.forms['connectorform'].option.selectedIndex].value;
    	else
			connector = document.forms['connectorform2'].option.options[document.forms['connectorform2'].option.selectedIndex].value;
    		
		/* Find the index of the connector */
		index=0;
		for(i=0; i < connectors.length;i++)
		{
			if( (Left(connector, connectors[i].length) == connectors[i]) && connectors[i].length == connector.length )
				index=i;
		}
			
		/* Ok, index is now set */
		/* Get the things we need */
		connectorchannels = conchannels[index];
		connectordescription = condescription[index];
		connectorpart = connectors[index];
		if((availableSlots - (conCount * connectorchannels)) < 0)
		{
			if(conCount > 1 || availableSlots == 0)
			{
				alert(	"Adding " + conCount + " of "+ connectordescription + 
				" is not possible.\n" + 
				"There are " + availableSlots + " available channels left on this side, " +
				"and adding these connectors would require " + (conCount * connectorchannels) +
				" channels.");
				return;
				
			}
			
			
		}
				      
		//alert(conCount * connectorchannels);
		availableSlots = availableSlots - (conCount * connectorchannels);
		if (availableSlots < 0)
			availableSlots = 0;
		
		/* Now add to the list */
		if(whichform == 1)
		{
			document.forms['multiform'].multiinfo.value += "\nSide A: " + conCount +
			"x " + connectorpart + ":" + connectordescription;
				
			document.images.leftconpic.src=conimages[index];
			document.getElementById('sideamulti').innerHTML = "Side A has " + availableSlots + " channel(s) available.";
		}
		else 
		{
			
			document.forms['multiform'].multiinfo.value += "\nSide B: " + conCount +
			"x " + connectorpart + ":" + connectordescription;
							
			document.images.rightconpic.src=conimages[index];
			document.getElementById('sidebmulti').innerHTML = "Side B has " + availableSlots + " channel(s) available.";
		}
		
		document.forms['connectorform'].sideANumber.value = 1;
		document.forms['connectorform2'].sideBNumber.value = 1;
		calculatemultiprice();
	}
	
	function resetSide(whichSide)
	{
		if(whichSide==1)
		{
			findMe="Side A";
			document.forms['connectorform'].option.options.length = 0;
			document.forms['connectorform'].type.options.length = 0;
			document.images.leftconpic.src='images/thumbs/conn_side_a.jpg' ;

		}
		else
		{
			findMe="Side B";
			document.forms['connectorform2'].option.options.length = 0;
			document.forms['connectorform2'].type.options.length = 0;
			document.images.rightconpic.src='images/thumbs/conn_side_b.jpg';
		}
		
		fillmultiside(whichSide);
		
		
		//get the text string
    		textString = document.forms['multiform'].multiinfo.value;
		
		//eliminate first line
		endline = textString.indexOf('\n');
		newString = trim(Left(textString, endline)) ;
		
		textString = Right(textString, textString.length - (endline+1));
		
		//alert("new string is : " + newString);
		
		tempString ="";
		
		
		while(textString.indexOf('\n') != -1)
		{
			endline = textString.indexOf('\n');
			tempString=Left(textString, textString.indexOf('\n'));
			//alert("tempString is " + tempString);
			
			if(tempString.indexOf(findMe) > -1)
				;//do nothing, we do not add this line to the new String
			else
				newString = newString + '\n' + trim(tempString) ;
			
			//alert("new string is : " + newString);
			
			
			/* Move to next row */
			endline = textString.indexOf('\n');
			textString = Right(textString, textString.length - endline-1);

		}
		
		if (textString.length > 0 && (textString.indexOf("Side A") != -1 
			|| textString.indexOf("Side B") != -1))
		{
			
			tempString=textString;
			//alert("tempString is " + tempString);
			
			if(tempString.indexOf(findMe) > -1)
				;//do nothing, we do not add this line to the new String
			else
				newString = newString + '\n' + trim(tempString);
		}
		
		
		document.forms['multiform'].multiinfo.value = newString;
		calculatemultiprice();
	}
	
	/* Calculates the price based on the formula and what is in the listbox*/
	function calculatemultiprice()
        {
		//Price = ([Overhead Cost] + [Cable Length]*[Cost per Ft] +[Channels]*[Connector A Cost] + [Channels]*[Connector B Cost])*(1 +MarkUp)
    
       		price=0;
    		index=0;
    		
    		//this is the TOTAL number of channels on each side
    		sideachannels=1;
    		sidebchannels=1; 
    		
    		cab=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    
    		//find cab in the arrays of cables
    		for(i=0;i<cables.length;i++)
    			if(cables[i]==cab)
    				index=i;
    	    
                sideachannels= cabchannels[index];
                sidebchannels= cabchannels[index];
   
	        document.images.cablepic.src=cabimages[index];
    
    		//index is the location of where the cable is in the arrays
    		//add overhead to price
    		price=price+caboverhead[index];
    		    
    		//calcuate length * cost per foot
    		price=parseFloat(price)+parseFloat(document.forms['cableform'].cablelength.value * cabprice[index]);
    		
    		//get the text string
    		//get connector 1, multiply that by number of connections, multiply that by price
    		textString = document.forms['multiform'].multiinfo.value;
		
		//first, find the \n that talks about what type of cable it is
		//we don't care about that
		
		endline = textString.indexOf('\n');

		textString = Right(textString, textString.length - (endline+1));

		
		tempString ="";
		while(textString.indexOf('\n') != -1)
		{
			endline = textString.indexOf('\n');
			tempString=Left(textString, textString.indexOf('\n'));
			//alert("tempString is " + tempString);
			/* First, get the number of connectors (found before the 'x') */
			tempString = Right(tempString, tempString.length - 8); //Length of "Side A: "
			
			//alert("After cutting the Side A stuff" + tempString);
			xSpot = tempString.indexOf('x');
			//alert("xSpot is " + xSpot);
			numConnectors = Left(tempString, xSpot);
			numConnectors = trim(numConnectors);
			//alert("Num connectors is " + numConnectors);
						
			/* Then, find the part # and look up its price */
			tempString = Right(tempString, tempString.length - xSpot-1);
			tempString = Left(tempString, tempString.indexOf(":"));
			tempString = trim(tempString);
			//alert("Part Number is" + tempString);
			
			for(i=0; i<connectors.length;i++)
			{
				if (tempString == connectors[i])
					index=i;
			}
			//alert("con price is" + conprice[index]);
			//alert("num connectors is " + numConnectors);
			
			/* Add to the total price */
			price = price + (numConnectors * conprice[index]);
			//alert("price is " + price);
			/* Move to next row */
			endline = textString.indexOf('\n');
			textString = Right(textString, textString.length - endline-1);

		}
			
		/* There may be one left, just check to be sure */
		if (textString.length > 0 && (textString.indexOf("Side A") != -1 
			|| textString.indexOf("Side B") != -1))
		{
			tempString = textString;
			tempString = Right(tempString, tempString.length - 8); //Length of "Side A: "
			
			//alert("After cutting the Side A stuff" + tempString);
			xSpot = tempString.indexOf('x');
			//alert("xSpot is " + xSpot);
			numConnectors = Left(tempString, xSpot);
			numConnectors = trim(numConnectors);
			//alert("Num connectors is " + numConnectors);
						
			/* Then, find the part # and look up its price */
			tempString = Right(tempString, tempString.length - xSpot-1);
			tempString = Left(tempString, tempString.indexOf(":"));
			tempString = trim(tempString);
			//alert("Part Number is" + tempString);
			
			for(i=0; i<connectors.length;i++)
			{
				//alert("connectors[i] = " + connectors[i]);
				if (tempString == connectors[i])
					index=i;
			}
			//alert("connectors[index] = " + connectors[index]);
			//alert("con price is" + conprice[index]);
			//alert("num connectors is " + numConnectors);
			
			/* Add to the total price */
			price = price + (numConnectors * conprice[index]);
			//alert("price is " + price);
				
		}
		
    		price=parseFloat(price) * (1+ MarkUp)
    		price=10*price;		//1/27/06
    		price = price.toFixed(0);
    		price=price/10;		//1/27/06
    		//document.forms['priceform'].theprice.value=price.toFixed(2);
			
			
			
			//VPASP Customization
			//Send ajax call to ajaxcustomerprice.asp to retrieve discount
			
			new Ajax.Request('ajaxcustomerprice.asp?id='+currCatalogId,
			{
				method:'get',
				asynchronous: false,
				onSuccess: function(transport){
					var response = transport.responseText;
					if(response != '--')
					{
						if (response >=1)
						{
							price = price - (response/10);
							
						}
						else
						{
							price = price * (1 - response);			
						}
						
					}
						document.getElementById('theprice').innerHTML='US$' + price.toFixed(2).toString();
					},
					onFailure: function(){
						document.getElementById('theprice').innerHTML='US$' + price.toFixed(2).toString(); 
						}
			});
			//-------------------------------------------------------------
			
			
    		//document.getElementById('theprice').innerHTML='US$' + price.toFixed(2).toString();
    		
            }
	/* Calculates the weight based on the formula and what is in the listbox*/
	function calculatemultiweight()
	{
		weight=0;
    		index=0;
    		cab=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		    
    		//find cab in the arrays of cables
    		for(i=0;i<cables.length;i++)
    			if(cables[i]==cab)
    				index=i;
    
             		//weight of the cables themselves
    		weight=weight+document.forms['cableform'].cablelength.value*cabweight[index];
		
		
		//get the text string
    		//get connector 1, multiply that by number of connections, multiply that by price
    		textString = document.forms['multiform'].multiinfo.value;
		
		//first, find the \n that talks about what type of cable it is
		//we don't care about that
		
		endline = textString.indexOf('\n');

		textString = Right(textString, textString.length - (endline+1));

		
		tempString ="";
		while(textString.indexOf('\n') != -1)
		{
			endline = textString.indexOf('\n');
			tempString=Left(textString, textString.indexOf('\n'));
			//alert("tempString is " + tempString);
			/* First, get the number of connectors (found before the 'x') */
			tempString = Right(tempString, tempString.length - 8); //Length of "Side A: "
			
			//alert("After cutting the Side A stuff" + tempString);
			xSpot = tempString.indexOf('x');
			//alert("xSpot is " + xSpot);
			numConnectors = Left(tempString, xSpot);
			numConnectors = trim(numConnectors);
			//alert("Num connectors is " + numConnectors);
						
			/* Then, find the part # and look up its weight */
			tempString = Right(tempString, tempString.length - xSpot-1);
			tempString = Left(tempString, tempString.indexOf(":"));
			tempString = trim(tempString);
			//alert("Part Number is" + tempString);
			
			for(i=0; i<connectors.length;i++)
			{
				if (tempString == connectors[i])
					index=i;
			}
			
			/* Add to the total weight */
			weight = weight + (numConnectors * conweight[index]);
			
			/* Move to next row */
			endline = textString.indexOf('\n');
			textString = Right(textString, textString.length - endline-1);

		}
			
		/* There may be one left, just check to be sure */
		if (textString.length > 0 && (textString.indexOf("Side A") != -1 
			|| textString.indexOf("Side B") != -1))
		{
			tempString = textString;
			tempString = Right(tempString, tempString.length - 8); //Length of "Side A: "
			
			//alert("After cutting the Side A stuff" + tempString);
			xSpot = tempString.indexOf('x');
			//alert("xSpot is " + xSpot);
			numConnectors = Left(tempString, xSpot);
			numConnectors = trim(numConnectors);
			//alert("Num connectors is " + numConnectors);
						
			/* Then, find the part # and look up its weight */
			tempString = Right(tempString, tempString.length - xSpot-1);
			tempString = Left(tempString, tempString.indexOf(":"));
			tempString = trim(tempString);
			//alert("Part Number is" + tempString);
			
			for(i=0; i<connectors.length;i++)
			{
				if (tempString == connectors[i])
					index=i;
			}
			
			/* Add to the total weight */
			weight = weight + (numConnectors * conweight[index]);
			
			return weight;
			
		}
	}
    	function fillconnections(whichform)
    	{
    	
		//step one delete any old connections
    		if (whichform==1)
    			document.forms['connectorform'].option.options.length = 0;
    		else if (whichform=2)
    			document.forms['connectorform2'].option.options.length = 0;
    
    		//step 2, get the value of the cable
    		j=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		j=String(j);
	    	   		
    		//step 2a--find the value of the index of the cable
    		//find cab in the arrays of cables
    		for(i=0;i<cables.length;i++)
		{	
    			if(cables[i]==j)
    				index=i;
    		}
		j=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		j=j+'^';
    		j=String(j);
	
    		q=j.length;
    		
    		var whichtype;
    		if (whichform==1) //this if connector form 1
    			whichtype=document.forms['connectorform'].type.options[document.forms['connectorform'].type.selectedIndex].value;
    		else if (whichform==2) //this is connector form 2
    			whichtype=document.forms['connectorform2'].type.options[document.forms['connectorform2'].type.selectedIndex].value;
    		else
    			alert('Error');
    		
    		for(i=0;i<compatible.length;i++)
    		{
    			if(Left(compatible[i], q)==j)
    			{
    				for(c=0;c<connectors.length;c++)
    					//alert(Right(compatible[i], compatible[i].length-q) + '---'+connectors[c]);
    					if(Right(compatible[i], compatible[i].length-q)==connectors[c] && contype[c]==whichtype)
    					{
    						if (whichform==1)
							if(document.getElementById('sideaycable') != null)
								document.forms['connectorform'].option.options[document.forms['connectorform'].option.length]=new Option(connectors[c] + " " + condescription[c] +"(" + calculateconnectors(cabchannels[index]/2, conchannels[c]) + ")", connectors[c]);
    							else
								document.forms['connectorform'].option.options[document.forms['connectorform'].option.length]=new Option(connectors[c] + " " + condescription[c] +"(" + calculateconnectors(cabchannels[index], conchannels[c]) + ")", connectors[c]);
						else if (whichform==2)

 							document.forms['connectorform2'].option.options[document.forms['connectorform2'].option.length]=new Option(connectors[c] + " " + condescription[c] +"(" + calculateconnectors(cabchannels[index], conchannels[c]) + ")", connectors[c]);
    					}
    			}
    		}
    		calculateprice();
    		
    }
    
    function fillmulticonnections(whichform)
    {
    	
		//step one delete any old connections
    		if (whichform==1)
    			document.forms['connectorform'].option.options.length = 0;
    		else if (whichform=2)
    			document.forms['connectorform2'].option.options.length = 0;
    
    		//step 2, get the value of the cable
    		j=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		j=String(j);
	    	   		
    		//step 2a--find the value of the index of the cable
    		//find cab in the arrays of cables
    		for(i=0;i<cables.length;i++)
		{	
    			if(cables[i]==j)
    				index=i;
    		}
		j=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		j=j+'^';
    		j=String(j);
	
    		q=j.length;
    		
    		var whichtype;
		if (whichform==1) //this if connector form 1
    			whichtype=document.forms['connectorform'].type.options[document.forms['connectorform'].type.selectedIndex].value;
    		else if (whichform==2) //this is connector form 2
    			whichtype=document.forms['connectorform2'].type.options[document.forms['connectorform2'].type.selectedIndex].value;
    		else
    			alert('Error');

    		for(i=0;i<compatible.length;i++)
    		{
    			if(Left(compatible[i], q)==j)
    			{
    				for(c=0;c<connectors.length;c++)
    					//alert(Right(compatible[i], compatible[i].length-q) + '---'+connectors[c]);
    					if(Right(compatible[i], compatible[i].length-q)==connectors[c] && contype[c]==whichtype)
    					{
    						if (whichform==1)
							if(document.getElementById('sidea') != null)
								document.forms['connectorform'].option.options[document.forms['connectorform'].option.length]=new Option(connectors[c] + " " + condescription[c] +"(" + conchannels[c] + ")", connectors[c]);
    							else
								document.forms['connectorform'].option.options[document.forms['connectorform'].option.length]=new Option(connectors[c] + " " + condescription[c] +"(" + conchannels[c] + ")", connectors[c]);
						else if (whichform==2)

 							document.forms['connectorform2'].option.options[document.forms['connectorform2'].option.length]=new Option(connectors[c] + " " + condescription[c] +"(" + conchannels[c] + ")", connectors[c]);
    					}
    			}
    		}
    		calculatemultiprice();
    }
    
    
    function calculateweight()
    	{
    		weight=0;
    		index=0;
    		cab=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    		sideachannels =1;
    		sidebchannels =1;
    
    		//find cab in the arrays of cables
    		for(i=0;i<cables.length;i++)
    			if(cables[i]==cab)
    				index=i;
    
            //if this field exists
            if(document.getElementById('sideaycable') != null)
            {
                    //then fill in values for the thing
                    document.getElementById('sideaycable').innerHTML = "Side A has " +cabchannels[index]/2 + " connection(s)";
                    sideachannels = cabchannels[index]/2;
                    document.getElementById('sidebycable').innerHTML = "Side B has " +cabchannels[index] + " connection(s)";
                    sidebchannels = cabchannels[index];
            }
            else
            {    
                    sideachannels= cabchannels[index];
                    sidebchannels= cabchannels[index];
            }
               
    		//weight of the cables themselves
    		weight=weight+document.forms['cableform'].cablelength.value*cabweight[index];
    
    		//weight+connector1
    		//add connector 1
    		//get connector 1, multiply that by number of connections, multiply that by price
    
    		connector1=document.forms['connectorform'].option.options[document.forms['connectorform'].option.selectedIndex].value;
    		for(i=0;i<connectors.length;i++)
    			if(connectors[i]==connector1)
    				con1=i;
 		var numconnectors=calculateconnectors(sideachannels, conchannels[con1]);
 		weight=parseFloat(weight)+parseFloat(conweight[con1])* numconnectors;

    
    		//add connector 2
    		//get connector 2, multiply that by number of connections, multiply that by price
    		connector2=document.forms['connectorform2'].option.options[document.forms['connectorform2'].option.selectedIndex].value;
    		for(i=0;i<connectors.length;i++)
    			if(connectors[i]==connector2)
    				con2=i;
    
		var numconnectors2=calculateconnectors(sidebchannels, conchannels[con2]);
		weight=parseFloat(weight)+parseFloat(conweight[con2])*numconnectors2;

    
    		return weight;
    	}
    	
	function calculateconnectors(cablechannels, connectorchannels)
	{
		var connectorcount;
 		//alert('cable channels is ' + cablechannels);
		//alert('connector channels is' + connectorchannels);
		connectorcount=Math.floor(cablechannels/connectorchannels);
 		if(cablechannels % connectorchannels == 0)
 			return connectorcount;
 		else
			return connectorcount + 1;		
	}
	
    	function calculateprice()
    	{
    		//Price = ([Overhead Cost] + [Cable Length]*[Cost per Ft] +[Channels]*[Connector A Cost] + [Channels]*[Connector B Cost])*(1 +MarkUp)
    
       		price=0;
    		index=0;
    		
    		//this is the TOTAL number of channels on each side
    		sideachannels=1;
    		sidebchannels=1; 
    		
    		cab=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;
    
    		//find cab in the arrays of cables
    		for(i=0;i<cables.length;i++)
    			if(cables[i]==cab)
    				index=i;
    
	    if(document.getElementById('sideaycable') != null)
            {

                    //then fill in values for the thing
                    document.getElementById('sideaycable').innerHTML = "Side A has " + cabchannels[index]/2 + " connection(s).";
                    sideachannels = cabchannels[index]/2;
                    document.getElementById('sidebycable').innerHTML = "Side B has " + cabchannels[index] + " connection(s).";
                    sidebchannels = cabchannels[index];
            }
            else
            {    
                    sideachannels= cabchannels[index];
                    sidebchannels= cabchannels[index];
            }
	    
              
    
	        document.images.cablepic.src=cabimages[index];
    
    		//index is the location of where the cable is in the arrays
    		//add overhead to price
    		price=price+caboverhead[index];
    		    
    		//calcuate length * cost per foot
    		price=parseFloat(price)+parseFloat(document.forms['cableform'].cablelength.value * cabprice[index]);
    		
    		//add connector 1
    		//get connector 1, multiply that by number of connections, multiply that by price
    		if (document.forms['connectorform'].option.options.length > 0) 
    		{
    			connector1=document.forms['connectorform'].option.options[document.forms['connectorform'].option.selectedIndex].value;
    			for(i=0;i<connectors.length;i++)
    				if(connectors[i]==connector1)
    					con1=i;
	        
			var numconnectors=calculateconnectors(sideachannels, conchannels[con1]);

			price=parseFloat(price)+parseFloat(conprice[con1])*numconnectors;

			document.images.leftconpic.src=conimages[con1];
    		}
    		else
    		{
    		//Reset connector picture 1/9/06 PLK
			document.images.leftconpic.src='images/thumbs/conn_side_a.jpg' ;
    		}
    		if (document.forms['connectorform2'].option.options.length > 0) 
    		{
    			//get connector 2, multiply that by number of connections, multiply that by price
    			connector2=document.forms['connectorform2'].option.options[document.forms['connectorform2'].option.selectedIndex].value;
    			for(i=0;i<connectors.length;i++)
    				if(connectors[i]==connector2)
    					con2=i;
			var numconnectors2=calculateconnectors(sidebchannels, conchannels[con2]);

			price=parseFloat(price)+parseFloat(conprice[con2]) *numconnectors2;
			
			document.images.rightconpic.src=conimages[con2];

    		}
    		else
    		{
    		//Reset connector picture 1/9/06 PLK
			document.images.rightconpic.src='images/thumbs/conn_side_b.jpg';
    		}
    		price=parseFloat(price) * (1+ MarkUp)
    		price=10*price;		//1/27/06
    		price = price.toFixed(0);
    		price=price/10;		//1/27/06
    		//document.forms['priceform'].theprice.value=price.toFixed(2);
			
			//VPASP Customization
			//Send ajax call to ajaxcustomerprice.asp to retrieve discount		
			new Ajax.Request('ajaxcustomerprice.asp?id='+currCatalogId,
			{
				method:'get',
				asynchronous:false,
				onSuccess: function(transport){
					var response = transport.responseText;
					if(response != '--')
					{
						if (response >=1)
						{
							price = price - (response/10);
							
						}
						else
						{
							price = price * (1 - response);			
						}
						
					}
						//alert(response.toString());
						document.getElementById('theprice').innerHTML='US$' + price.toFixed(2).toString();
					},
					onFailure: function(){
						document.getElementById('theprice').innerHTML='US$' + price.toFixed(2).toString(); 
						}
			});
			//-------------------------------------------------------------

    	}
    
    
    function fillcableform()
    	{
    		document.forms['cableform'].option.options.length = 0;
    		document.forms['connectorform'].option.options.length = 0;
    		document.forms['connectorform2'].option.options.length = 0;
    		document.forms['connectorform'].type.options.length = 0;
    		document.forms['connectorform2'].type.options.length = 0;
    		//document.forms['priceform'].theprice.value=0.0;
     		//Reset the images to default - 1/9/06 PLK
			document.images.cablepic.src='images/thumbs/cable.jpg';
			document.images.rightconpic.src='images/thumbs/conn_side_b.jpg';
			document.images.leftconpic.src='images/thumbs/conn_side_a.jpg' ;
   			
   			document.getElementById('theprice').innerHTML = "US$0.00";	
    
    		document.forms['cableform'].option.options[document.forms['cableform'].option.length]=new Option(' ', ' ');
    		
    		for(i=0; i<cables.length;i++)
    		{
    			if( cabtype[i]==document.forms['cabletype'].option.options[document.forms['cabletype'].option.selectedIndex].value )

				document.forms['cableform'].option.options[document.forms['cableform'].option.length]=new Option(cables[i] + " " + cabdescription[i], cables[i]);
    		}
    		//cableform.mycheckbox.checked=true;
    	}
    
	function fillmulticableform()
    	{
    		document.forms['cableform'].option.options.length = 0;
    		document.forms['connectorform'].option.options.length = 0;
    		document.forms['connectorform2'].option.options.length = 0;
    		document.forms['connectorform'].type.options.length = 0;
    		document.forms['connectorform2'].type.options.length = 0;
    		document.forms['multiform'].multiinfo.value ="";
	
		//document.forms['priceform'].theprice.value=0.0;
     		//Reset the images to default - 1/9/06 PLK
		document.images.cablepic.src='images/thumbs/cable.jpg';
		document.images.rightconpic.src='images/thumbs/conn_side_b.jpg';
		document.images.leftconpic.src='images/thumbs/conn_side_a.jpg' ;
		
		document.getElementById('theprice').innerHTML = "US$0.00";	

    		document.forms['cableform'].option.options[document.forms['cableform'].option.length]=new Option(' ', ' ');
    		
    		for(i=0; i<cables.length;i++)
    		{
    			if( cabtype[i]==document.forms['cabletype'].option.options[document.forms['cabletype'].option.selectedIndex].value )

				document.forms['cableform'].option.options[document.forms['cableform'].option.length]=new Option(cables[i] + " " + cabdescription[i], cables[i]);
    		}
    		//cableform.mycheckbox.checked=true;
    	}
	
    	function fillcabletypes()
    	{
    		
    		document.forms['cabletype'].option.options[document.forms['cabletype'].option.length]=new Option(' ', ' ');
    		
    		for(i=0; i<CableTypeList.length;i++)
    		{
    			document.forms['cabletype'].option.options[document.forms['cabletype'].option.length]=new Option(CableTypeList[i], CableTypeList[i]);
    		}
    		//cabletype.mycheckbox.checked=true;
    	}
    	
    	function resetall()
    	{
    	
    	    if(document.getElementById('sidea') != null)
   	        {
   	          
   	           document.getElementByID('sidea').innerHTML = "Side A has 0 connection(s)";
                   document.getElementByID('sideb').innerHTML = "Side B has 0 connection(s)";
		}    
    		document.forms['cabletype'].option.options.length = 0;
    		document.forms['cableform'].option.options.length = 0;
    		document.forms['connectorform'].option.options.length = 0;
    		document.forms['connectorform2'].option.options.length = 0;
    		document.forms['connectorform'].type.options.length = 0;
    		document.forms['connectorform2'].type.options.length = 0;
    		//Reset the images to default - 1/9/06 PLK
			document.images.cablepic.src='images/thumbs/cable.jpg';
			document.images.rightconpic.src='images/thumbs/conn_side_b.jpg';
			document.images.leftconpic.src='images/thumbs/conn_side_a.jpg' ;

    		//document.forms['priceform'].theprice.value=0.0;
    		document.getElementById('theprice').innerHTML = "US$0.00";
    		fillcabletypes();
    	}
    	
    	function resetfromybox()
    	{
    	   if(document.getElementById('sideaycable') != null)
   	        {
   	          
   	           document.getElementByID('sideaycable').innerHTML = "Side A has 0 connection(s)";
                   document.getElementByID('sidebycable').innerHTML = "Side B has 0 connection(s)";
		}    
    		docume
    		document.forms['cabletype'].option.options.length = 0;
		document.forms['cableform'].option.options.length = 0;
		document.forms['connectorform'].option.options.length = 0;
		document.forms['connectorform2'].option.options.length = 0;
		document.forms['connectorform'].type.options.length = 0;
		document.forms['connectorform2'].type.options.length = 0;
		
		//Reset the images to default - 1/9/06 PLK
			document.images.cablepic.src='images/thumbs/cable.jpg';
			document.images.rightconpic.src='images/thumbs/conn_side_b.jpg';
			document.images.leftconpic.src='images/thumbs/conn_side_a.jpg' ;

		//document.forms['priceform'].theprice.value=0.0;
		document.getElementById('theprice').innerHTML = "US$0.00";
    		fillcabletypes();
    	}
    	
	function resetfrommulti()
    	{
    	
    		document.forms['cabletype'].option.options.length = 0;
		document.forms['cableform'].option.options.length = 0;
		document.forms['connectorform'].option.options.length = 0;
		document.forms['connectorform2'].option.options.length = 0;
		document.forms['connectorform'].type.options.length = 0;
		document.forms['connectorform2'].type.options.length = 0;
		document.forms['multiform'].multiinfo.value ="";
		
		//Reset the images to default - 1/9/06 PLK
			document.images.cablepic.src='images/thumbs/cable.jpg';
			document.images.rightconpic.src='images/thumbs/conn_side_b.jpg';
			document.images.leftconpic.src='images/thumbs/conn_side_a.jpg' ;

		//document.forms['priceform'].theprice.value=0.0;
		document.getElementById('theprice').innerHTML = "US$0.00";
    		fillcabletypes();
    	}
	
    	function senddata()
    	{
    		//alert("the weight is " + calculateweight());
		
		j="shopaddtocartnodb.asp?weight=" + calculateweight() + "&productname=";

 		 if(document.getElementById('sideaycable') != null)
			 j+="Y-CABLE <BR>";
	
		j+="Cable Length: " + document.forms['cableform'].cablelength.value + " ft <BR>";

 		j+="Cable Type: " +document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].text;
 		j+="<BR> Connector 1: " + document.forms['connectorform'].option.options[document.forms['connectorform'].option.selectedIndex].text + " ";
 		j+="<BR> Connector 2: " + document.forms['connectorform2'].option.options[document.forms['connectorform2'].option.selectedIndex].text;
		j+="<BR> Special Instructions: " + document.forms['instform'].specInst.value;
 		j+="&Price=";
 		p=document.getElementById('theprice').innerHTML;
 		p=p.substring(p.indexOf("$")+1, p.indexOf(".")+3);
 		//alert ('p is' + p);
 		//j+="$21.18";		
 		j+=p;
		j+="&quantity=" + document.forms['checkoutform'].quantity.value;
		j+="&returncatalogid=" + currCatalogId;
 		//alert(j);
    		window.location.href=j;
    	}
	
	function sendmultidata()
    	{
    		
		//alert("the weight is " + calculatemultiweight() );
		j="shopaddtocartnodb.asp?weight=" + calculatemultiweight() + "&productname=";

 			
		j+="Cable Length: " + document.forms['cableform'].cablelength.value + " ft <BR>";
		
		tempString = document.forms['multiform'].multiinfo.value + "<BR>";
		
		lastSpot = tempString.length - 4;
		
		for(i = 0; i< lastSpot; i++)
		{
		
			if(tempString.charAt(i) == 'S' && tempString.charAt(i+1) == 'i' &&
				tempString.charAt(i+2) =='d' && tempString.charAt(i+3) =='e')
			{
		
			tempString = tempString.substring(0,i) + "<BR>"
			+ tempString.substring(i, tempString.length);
			i+=4;
			lastSpot +=4;
			}
		}
		j+=tempString;
 		j+="<BR> Special Instructions: " + document.forms['instform'].specInst.value;
 		j+="&Price=";
 		p=document.getElementById('theprice').innerHTML;
 		p=p.substring(p.indexOf("$")+1, p.indexOf(".")+3);
 		//alert ('p is' + p);
 		//j+="$21.18";		
 		j+=p;
		j+="&quantity=" + document.forms['checkoutform'].quantity.value;
		j+="&returncatalogid=" + currCatalogId;
 		//alert(j);
    		window.location.href=j; 
    	}
    	
    	
    	function addtocart()
    	{
    	
    		if (document.forms['cableform'].option.options.length == 0)
    		{
    			alert ('You must select a cable type.')
    			document.cabletype.option.focus();
    		}
    		else
    		{
    		
    			j=document.forms['cableform'].option.options[document.forms['cableform'].option.selectedIndex].value;//type of cable
    			x=document.forms['cableform'].cablelength.value;//length of cable
    			re=/^[0-9]|[0-9][0-9]|[0-9][0-9][0-9]$/
    			a1=document.forms['connectorform'].option.length;
    			a2=document.forms['connectorform2'].option.length;
    			if (a1 >0) 
    				b1=document.forms['connectorform'].option.options[document.forms['connectorform'].option.selectedIndex].value;
    			else
    				b1='';
    				
    			if (a2 >0) 
    				b2=document.forms['connectorform2'].option.options[document.forms['connectorform2'].option.selectedIndex].value;
    			else
    				b2='';	
    		
    		
    		
    			if (j == ' ' || j == '')
    			{
    				alert('You must select a cable');
    				document.cableform.option.focus();
    			}
    			else if (!re.test(x))
    			{
    				alert('You must enter a whole number smaller than 1000.')
    				document.cableform.cablelength.focus();
    			}
    			else if (x < 1)
    			{
    				alert('You cannot enter 0.')
    				document.cableform.cablelength.focus();
    			}
    			else if (a1 <=0)
    			{
    				alert('You must select a connector type');
    				document.connectorform.type.focus();
    			}		
    			else if (b1== ' ' || b1== '')
    			{
    				alert('You must select a connector');
    				document.connectorform.option.focus();
    			}
    			else if (a2 <=0)
    			{
    				alert('You must select a connector type');
    				document.connectorform2.type.focus();
    			}
    			else if (b2== ' ' || b2== '')
    			{
    				alert('You must select a connector');
    				document.connectorform2.option.focus();
    			}
    			else
    			{
    				if(document.getElementById('multiinfo') == null) 
				{
					  calculateprice();
					  senddata();
				}
				else
				{
					/* Check and make sure they have used all
					connector slots */
					
					
					if("Side A has 0 channel(s) available." != getText(document.getElementById('sideamulti')))
					{
						alert("You must use all available Side A channels.  Use the Blunt End option to specify 'No Channel'");
						return;
					}
					else if("Side B has 0 channel(s) available." != getText(document.getElementById('sidebmulti')))
					{
						alert("You must use all available Side B channels.  Use the Blunt End option to specify 'No Channel'");
						return;
					}
					
					calculatemultiprice();
					sendmultidata();
				}
    			}
    		}
    	}
