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 ='L';
        var descleadtime='1-2 days';
    	var user_input = '';

// Gee, 5/7/2007
// 10 chars format eg. 1M3000R1B1
// 1st 6 chars are constants, and 9th loc = "B"
// ie. 1M3000 (1=touchmon, M=M5 series, 3=dark grey color)
// user definable:
// - touch
// - opt (spkr)
// - addon (msr, fpr)


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

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

// 9th loc is constant = "B" for Base
	textstring += "B";

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

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

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

		var newwhich=0;
		newwhich=replace(document.partno_form.output.value,' ','');
        var count=partno_form.output.value.length;

		if (count>10){
 			alert("Incorrect PartNo");
  	 	 	document.partno_form.leadtime.value = "";
		 	document.partno_form.output.value = "";
			document.partno_form.output.focus();
     	return false; 
		}

//CPU
//   Upwhich= newwhich.toUpperCase();
//   user_input = Upwhich.substring(0,1);

/*    if (user_input=="G"){
      document.partno_form.cpu[0].checked = true;
    }
	
 	if ( user_input=="K"){
      document.partno_form.cpu[0].selected = true;
    }
		
   if ( user_input=="M"){
     document.partno_form.cpu[1].selected = true;
    }
*/
//LCD 
  Upwhich= newwhich.toUpperCase(); 
  user_input = Upwhich.substring(1,2);

   if (user_input=="M"){
     document.partno_form.lcd[0].selected = true;
    }
	
	
//Touch
	Upwhich= newwhich.toUpperCase();         
	user_input = Upwhich.substring(6,7);

   if (user_input=="R"){
     document.partno_form.touch[0].selected = true;
    }
	
   if (user_input=="C"){
     document.partno_form.touch[1].selected = true;
    }

   if (user_input=="S"){
     document.partno_form.touch[2].selected = true;
    }
	
   if (user_input=="U"){
     document.partno_form.touch[3].selected = true;
    }

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

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

//ADDON
  Upwhich= newwhich.toUpperCase();         
  user_input = Upwhich.substring(9,10);

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

//msr	
   if (user_input=="2"){
     document.partno_form.addon[1].selected = true; 
    }

//msr + fingerprint combo
   if (user_input=="A"){
     document.partno_form.addon[2].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);
   noteui = Upwhich.substring(5,6);
   touchui = Upwhich.substring(6,7);
   optui = Upwhich.substring(7,8);
   pwrui = Upwhich.substring(8,9);
   addonui = Upwhich.substring(9,10);

if (Upwhich==""){
checkit();
return true;
}

else if  (((optui=="1")||(optui=="S"))&&
         ((touchui=="R")||(touchui=="C")||(touchui=="S")||(touchui=="U"))&&
	     ((addonui=="1")||(addonui=="2")||(addonui=="A"))&&
		 (cpuui=="1")&&
		 (lcdui=="M")&&
		 (memui=="3")&&
		 (hddui=="0")&&
		 (osui=="0")&&
		 (noteui=="0")&&
		 (pwrui=="B"))
		{
		}
else{    alert("Incorrect PartNo");
    	
 	 	document.partno_form.leadtime.value = "";
	 	document.partno_form.output.value = "";
		document.partno_form.output.focus();
     	return false;   
  	   
	   }//end of else

}//end of function
