<!-- Personalization Script - CUSTOMIZED
// ©2007 G.E. Masana

RATE = .60;


//////
function currency(anynum) {
   anynum=eval(anynum);
   workNum=Math.abs((Math.round(anynum*100)/100));workStr=""+workNum
   if (workStr.indexOf(".")==-1){workStr+=".00"}
   dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
   pStr=workStr.substr(workStr.indexOf("."))
   while (pStr.length<3){pStr+="0"}
      if (dNum>=1000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
   }
   if (dNum>=1000000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
   }
   retval = dStr + pStr 
   //-- Put numbers in parentheses if negative.
   if (anynum<0) {retval="("+retval+")"}
   return retval
}
function CharacterCount(theForm){

 var text = theForm.text.value;
 var i;
 var total = 0;

 for (i = 0; i < text.length; i++)
 {
  // Count anything with an ASCII value higher than a space
  if (text.charAt(i) > ' ')
  {
   total++;
  }
 }

 return total;
}


function PerformCalculation(theForm){
price=0;

 // Compute the RATE as a decimal number
 fee = CharacterCount(theForm) * RATE;

// Update the cost display field
 theForm.cost.value = currency(fee);
 
 }

function Final(theForm){

PerformCalculation(theForm);

if (theForm.text.value){if(confirm('Please Check Your Personalization for Accuracy:\n\n'+theForm.text.value+'\n\nIs This Correct?')){

 // Update form fields
price=eval(theForm.productpr1.value.split(":")[1])+eval(fee);
BasePrice=theForm.productpr1.value.split(":")[1];
segments=theForm.productpr1.value.split(":");

theForm.productpr1.options[theForm.productpr1.selectedIndex].value=segments[0]+"{br}Base price $"+BasePrice+"{br}Personalize "+CharacterCount(theForm)+" letters at "+currency(RATE)+" ("+currency(fee)+"){br}{b}Personalized Text{/b}{br}"+theForm.text.value+":"+currency(price)+":"+segments[2];

return true;
}

else {theForm.text.select();return false;}

}

}
//-->