function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}


function checkit()
{
	    var textstring = '';
        var logostring ='1';
		var spkrstring ='0';
        var descleadtime='2-5 days';
 
// Get value of the 'cpu' radio buttons.

	user_input = '';
	for (i=0;i<document.forms[0].cpu.length;i++)
	{
		if (document.forms[0].cpu[i].selected)
		{
			user_input = document.forms[0].cpu[i].value;
		}
	}

    textstring += user_input;

// Get value of the 'lcd' radio buttons.   
          
    user_input="X";

	textstring += user_input;
     
// Get value of the 'mem' radio buttons.

    for (i=0;i<document.forms[0].mem.length;i++)
	{
		if (document.forms[0].mem[i].selected)
		{
			user_input = document.forms[0].mem[i].value;
		}
	}
  
	textstring += user_input;

// Get value of the 'hdd' radio buttons.

    for (i=0;i<document.forms[0].hdd.length;i++)
	{
		if (document.forms[0].hdd[i].selected)
		{
			user_input = document.forms[0].hdd[i].value;
		}
	}
 
	textstring += user_input;

// Get value of the 'os' radio buttons.

        for (i=0;i<document.forms[0].os.length;i++)
	{
		if (document.forms[0].os[i].selected)
		{
			user_input = document.forms[0].os[i].value;
		}
	}

    textstring += user_input;


// no touch option
    user_input="0";
	textstring += user_input;

// Use Standard I/O port, No Spkr
    user_input="0";
	textstring += user_input;

// Get value of the 'opt' radio buttons. (Add on 1)

        for (i=0;i<document.forms[0].opt.length;i++)
	{
		if (document.forms[0].opt[i].selected)
		{
			user_input = document.forms[0].opt[i].value;
		}
	}
 
	textstring += user_input;

	
	// Get value of the 'vga' radio buttons. (Add on 1)

        for (i=0;i<document.forms[0].vga.length;i++)
	{
		if (document.forms[0].vga[i].selected)
		{
			user_input = document.forms[0].vga[i].value;
		}
	}
 
	textstring += user_input;
	
// NO PCI add on
 //   user_input="0";
//	textstring += user_input;

// NO Add on 2
    user_input="0";
	textstring += user_input;

// Logo
    user_input="1";
	textstring += user_input;

// Base included
//    user_input="1";

	
	 for (i=0;i<document.forms[0].base.length;i++)
	{
		if (document.forms[0].base[i].selected)
		{
			user_input = document.forms[0].base[i].value;
		}
	}

	textstring += user_input;

	document.forms[0].output.value =textstring;
	document.forms[0].leadtime.value = " "+descleadtime;
	}

function valid(form){
	
        var logostring ='1';
		var spkrstring='0';
        var descleadtime='2-5 days';
    	var user_input = '';

		var newwhich=0;
		newwhich=document.partno_form.output.value;
		var count=partno_form.output.value.length;
		
	if (count>12){
  		 alert("Incorrect PartNo");
    	
 	 	document.partno_form.leadtime.value = "";
	 	document.partno_form.output.value = "";
		document.partno_form.output.focus();
     	return false; 
		}
// ARRAY COUNTS TO THE RIGHT
// [0]  [1]  [2]
// [3]  [4]
		
//CPU
   Upwhich= newwhich.toUpperCase();
   user_input = Upwhich.substring(0,1);

	if ( user_input=="S"){
       document.partno_form.cpu[0].selected = true;
    }
	
	if ( user_input=="T"){
       document.partno_form.cpu[1].selected = true;
    }

	if ( user_input=="V"){
       document.partno_form.cpu[2].selected = true;
    }
	

//LCD 
  Upwhich= newwhich.toUpperCase(); 
  user_input = Upwhich.substring(1,2);

   if (user_input=="X"){
 //  document.partno_form.lcd[0].checked = true;
     }
   
//MEM
  Upwhich= newwhich.toUpperCase();   
  user_input = Upwhich.substring(2,3);

   if (user_input=="1"){
       document.partno_form.mem[0].selected = true;
    }
	
   if (user_input=="B"){
       document.partno_form.mem[1].selected = true;
    }
	
 
//HDD
   Upwhich= newwhich.toUpperCase();   
   user_input = Upwhich.substring(3,4);
	
   if (user_input=="A"){
       document.partno_form.hdd[0].selected = true;
    }
	
   if (user_input=="C"){
       document.partno_form.hdd[1].selected = true;
    }

   if (user_input=="D"){
       document.partno_form.hdd[2].selected = true;
    }
	
   if (user_input=="K"){
       document.partno_form.hdd[3].selected = true;
    }
	
   if (user_input=="M"){
       document.partno_form.hdd[4].selected = true;
    }

   if (user_input=="N"){
       document.partno_form.hdd[5].selected = true;
    }
	
//OS
  Upwhich= newwhich.toUpperCase();          
  user_input = Upwhich.substring(4,5);

   if (user_input=="0"){
       document.partno_form.os[0].selected = true;
    }
	
   if (user_input=="X"){
       document.partno_form.os[1].selected = true;
    }
		
   if (user_input=="W"){
       document.partno_form.os[2].selected = true;
    }
	

//Touch
	Upwhich= newwhich.toUpperCase();         
	user_input = Upwhich.substring(5,6);

   if (user_input=="0"){
//       document.partno_form.touch[0].checked = true;
    }
	
// I/O
  Upwhich= newwhich.toUpperCase(); 
  user_input = Upwhich.substring(6,7);

   if (user_input=="0"){
 //  document.partno_form.lcd[0].checked = true;
     }

	
//OPT (Add on 1)
  Upwhich= newwhich.toUpperCase();         
  user_input = Upwhich.substring(7,8);

   if (user_input=="0"){
      document.partno_form.opt[0].selected = true;
    }
	
   if (user_input=="5"){
      document.partno_form.opt[1].selected = true;
    }

	
	
	//VGA(Add on 1)
  Upwhich= newwhich.toUpperCase();         
  user_input = Upwhich.substring(8,9);

   if (user_input=="0"){
      document.partno_form.vga[0].selected = true;
    }
	
//   if (user_input=="V"){
//      document.partno_form.vga[1].selected = true;
//    }
	
	
	
	
/*PCI ADD ON
  Upwhich= newwhich.toUpperCase(); 
  user_input = Upwhich.substring(8,9);

   if (user_input=="0"){
 //  document.partno_form.lcd[0].checked = true;
     }
*/
// ADD ON 2
  Upwhich= newwhich.toUpperCase(); 
  user_input = Upwhich.substring(9,10);

   if (user_input=="0"){
 //  document.partno_form.lcd[0].checked = true;
     }

// LOGO
  Upwhich= newwhich.toUpperCase(); 
  user_input = Upwhich.substring(10,11);

   if (user_input=="1"){
 //  document.partno_form.lcd[0].checked = true;
     }

// BASE
  Upwhich= newwhich.toUpperCase(); 
  user_input = Upwhich.substring(11,12);

 if (user_input=="0"){
      document.partno_form.base[0].selected = true;
    }
	
   if (user_input=="4"){
      document.partno_form.base[1].selected = true;
    }

	

//check if correct part no or not

   cpuui = Upwhich.substring(0,1);
   lcdui = Upwhich.substring(1,2);
   memui = Upwhich.substring(2,3);
   hddui = Upwhich.substring(3,4);
   osui = Upwhich.substring(4,5);
   touchui = Upwhich.substring(5,6);
   ioui = Upwhich.substring(6,7);
   optui = Upwhich.substring(7,8);
   pciui = Upwhich.substring(8,9);
   addonui = Upwhich.substring(9,10);
   logoui = Upwhich.substring(10,11);
   baseui = Upwhich.substring(11,12);
if (Upwhich==""){
checkit();
return true;
}
else if (((cpuui =="S")||(cpuui =="T")||(cpuui =="V")) &&
			(lcdui =="X")&&
			((memui =="1")||(memui =="B"))&&
			((hddui =="A")||(hddui =="C")||(hddui =="D")||(hddui =="K")||(hddui =="M")||(hddui =="N"))&&
			((osui =="X")||(osui =="W")||(osui =="0"))&&
			(touchui =="0")&&
			(ioui =="0")&&
			((optui =="0")||(optui =="5"))&&
			(pciui =="0")&&
			(addonui == "0")&&
			(logoui =="1")&&
			(baseui =="0")||(baseui =="4"))
{
}
 else {
 	alert("Incorrect PartNo");
   	 document.partno_form.leadtime.value = "";
	 document.partno_form.output.value = "";
     return false;
    }  
return true;
}//end of function


