<!--
/**  function.js	: provides all needed javascript functions.
  *  @author  		: Ibrahim En-nali
  *  @version 		: 1.0
  *  @since   		: 08 june 2005
  */
  
  //-----------------------------------------------------------------------------
  // functions provides the needed functionality.
  //-----------------------------------------------------------------------------
  
/**
  * This function formats the provided product code/device code:
  * Product code: it trims, upper-cases, splits the provided value into 3 parts, each part 
  * with 5 letters and digits. This makes the provided code more readable for the end user.
  * Device code: it trims, upper-cases, splits the provided value into 2 parts, each part 
  * with 5 letters and digits. This makes the provided code more readable for the end user.
  * device code or produc. 
  * Product code consists of 15 letters and digits.
  * Device code consists of 10 letters and digits.
  * @param string $str 		This code is provided by the form; the provided string can be
  */
  function formatCode(str,type){
	// Gets the lenght of the provided product code/ device code.
	strLength = str.value.length;
	//-----------------------------------------------------------------------------
  	// Inisialization variables.
  	//-----------------------------------------------------------------------------
	var counter = 0;
	var arrCode 			= new Array(strLength);
	var strNewCodeString 	= "";
	var strCodeFirstPart 	= "";
	var strCodeSecondPart 	= "";
	var strCodethirdPart 	= "";
	
	// Trims all white spaces in the product code string and puts the rest into arrCode array.
	while(counter<strLength){
		arrCode[counter] = str.value.substring(counter, counter+1);
		if( (arrCode[counter].indexOf(" "))==-1){
			strNewCodeString = strNewCodeString+arrCode[counter];
		}; 
		counter++;
	}
	
	// Uppercases the provided product code.
	strNewCodeString = strNewCodeString.toUpperCase();
	
	if(type=='productCode'){
		// splits the provided product code into 3 parts, each part with 5 letters and digits.
		strFirstPart = strNewCodeString.substring(0, 5);
		strSecondPart = strNewCodeString.substring(5, 10);
		strCodethirdPart = strNewCodeString.substring(10, strLength);	
		
		// Rewrites the old product code value in the form by the new well formatted value.
		document.forms['EnterProductCode'].strProductCode.value = strFirstPart+' '+strSecondPart+' '+strCodethirdPart;
	}else if(type=='deviceCode'){
		// splits the provided product code into 3 parts, each part with 5 letters and digits.
		strFirstPart = strNewCodeString.substring(0, 5);
		strSecondPart = strNewCodeString.substring(5, strLength)
		// Rewrites the old device code value in the form by the new well formatted value.
		document.forms['EnterDeviceCode'].strDeviceCode.value = strFirstPart+' '+strSecondPart;
	}

//-->
}