function save(){
var regularsale;
var regularsaleObj = document.getElementById("regularsale");
   //   alert( document.getElementById("disp_price").innerHTML);
	  var disp_price = document.getElementById("disp_price").innerHTML.replace("$","").replace(",","");
      
            //alert(regularsale/disp_price);
            //return;
			var regular;
var regularObj = document.getElementById("regular");

if (regularsaleObj != null)
			{
				regularsale = regularsaleObj.innerHTML.replace("$","").replace(",","");
			}
if (regularObj != null)
{
regular = regularObj.innerHTML.replace("$","").replace(",","");
}
//alert('Hello1');
// if (regularObj != null && disp_price != null)
if (regularObj != null && disp_price != null)
{
//innerHTML.replace("$","").replace(",","");
retaildiscountrate2 =100 - Math.round(100* disp_price/regular);

discount= regular-disp_price;
}

document.getElementById("savenum").innerHTML='$' + discount + '.00     (' + retaildiscountrate2 + '%)';

}
setTimeout("save()",2000);

var discountrate = 0;
var retaildiscountrate = 0;

function ModifyOptions()
        {
            var regularsale;

var regularsaleObj = document.getElementById("regularsale");
            var disp_price = document.getElementById("disp_price").innerHTML.replace("$","").replace(",","");
            
            //alert(regularsale/disp_price);
            //return;
			var regular;
var regularObj = document.getElementById("regular");

if (regularsaleObj != null)
			{
				regularsale = regularsaleObj.innerHTML.replace("$","").replace(",","");
			}


if (regularObj != null)
{
regular = regularObj.innerHTML.replace("$","").replace(",","");
}
//alert('Hello1');
// if (regularObj != null && disp_price != null)
if (regularObj != null && disp_price != null)
{
//innerHTML.replace("$","").replace(",","");
retaildiscountrate = disp_price/regular;
}
			if (regularsale != null && disp_price != null)
			{
				discountrate = disp_price/regularsale;
				var i;
				var j;
				var newPriceString;
				var selElements = document.getElementsByTagName("select")
				for (i=0;i<selElements.length;i++)
				{  
					
					for (j=0;j<selElements[i].options.length;j++)
					{
						//alert(selElements[i].options[j].value);
						newPriceString = GetModOptString(selElements[i].options[j].value,discountrate);
						selElements[i].options[j].value = newPriceString;
						selElements[i].options[j].text = newPriceString;
					}
				}
            }
        }
        
        function GetModOptString(optionString,percent)
        {
            var start = optionString.indexOf("(");
            var end = optionString.indexOf(")");
            var value;
            
            if (start != -1 && end != -1)
            {
				start +=1;
				end -=1;
                // get the value            
                value = optionString.toString().replace("$","").substring(start,end);    
                // make sure that it is a number within the parenths
                if (!isNaN(value))
                {
                    // make the number positive
                    if (value <0)
                        value = value * -1;
                    value  = Math.round(value * percent);
                    optionString = optionString.substring(0,start+2) + value + optionString.substring(end+1, 100);
                    //alert (optionString );
                }
                else
                {
					//alert(value);
                }
                
            }
            
            return optionString;
        }
        
        setTimeout("ModifyOptions()",2000);
		setTimeout("generateCode()",2000);


function generateCode(){
var yyyy=document.forms[0].elements["Color"];
if (yyyy !=null ){
var y= document.forms[0].elements["Color"].selectedIndex;

var yy=document.forms[0].elements["Color"].options[y].value
firstwo=yy.indexOf(' ');

first='-'+ yy.substring(0,firstwo);
if (first=="-CH")
{
	first='';
	}
//alert(first);
code = document.getElementById("sku2").innerHTML
//alert(code);
if (code.lastIndexOf('-')>0){
//alert('d');
newcode=code.substring(0,code.lastIndexOf('-')) +first;}
else 
{newcode=code+first;}

document.getElementById("sku2").innerHTML=newcode;
document.getElementById("sku").value=newcode;

var tee=document.getElementById("item-numb").value;
if (first!=null){
	gh=tee.substring(0,tee.lastIndexOf("-")).lastIndexOf("-d");
//	alert(gh);
	if (gh>=0){
document.getElementById("item-numb").value=tee.substring(0,tee.lastIndexOf("-"))+first.toLowerCase();
//alert(newcode);
	}
	else{
		document.getElementById("item-numb").value=document.getElementById("item-numb").value+first.toLowerCase()
		}
}}
	}

function updatePrice(frm,obj)
{
    // ----------for multi option any operation
 UpdateImage();
 generateCode();
    p =    document.getElementById("Base Price").value.replace(',','');
    document.getElementById("disp_price").innerHTML = p; 
    actual_price = p.substr(p.indexOf("$")+1, p.length);

    var price = parseFloat(actual_price);
    var pricevalAr = new Array(); 
    var direction = "add";
    
    for(i=0; i< frm.elements.length; i++)
    {
        e = frm.elements[i];
        if (e.type == "select-one")
        {
			var myindex  = e.selectedIndex;
			var SelValue = e.options[myindex].value;
			
            //if(e.checked )
            {
                //priceval = frm.elements[i].value;
                priceval = SelValue;
                if(priceval.indexOf("(+$") > -1) {
                    pricevalAr = priceval.split("(+$");
                    direction = "add"; 
                } else if(priceval.indexOf("(+") > -1) {
                    pricevalAr = priceval.split("(+");
                    direction = "add";
                } else if( priceval.indexOf("(-") > -1) {
                    pricevalAr = priceval.split("(-");
                    direction = "sub";
                }else if(priceval.indexOf("(-$") > -1) { 
                    pricevalAr = priceval.split("(-$");
                    direction = "sub";
                }else {pricevalAr = "";}
                

                if( pricevalAr.length > 1)
                {
                    priceval = pricevalAr[1].split(")");
                  //priceval = parseFloat(priceval[0]);

                    priceval = parseFloat(priceval[0].replace('$',''));
                }
                else
                {    priceval = 0;}
                
                
                    

                if(direction == "add")
                    price = price + priceval
                else if(direction == "sub") 
                    price = price - priceval
            }
        }
        //alert (price);
           document.getElementById("disp_price").innerHTML = "$" + addCommas(toDollarsAndCents(price));
		   if (document.getElementById("regularsale") != null)
				{
					document.getElementById("regularsale").innerHTML = "$" + addCommas(Math.round(toDollarsAndCents(price) * 1/discountrate)) + ".00";
				}
		if (document.getElementById("regular") != null)
			{
				document.getElementById("regular").innerHTML = "$" + addCommas(Math.round(toDollarsAndCents(price) * 1/retaildiscountrate)) + ".00";
			}

    }//for ends
	
save();	
  }
function toDollarsAndCents(n) {
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t 
}

function addCommas(nStr)
{
       nStr += '';
      var x = nStr.split('.');
      var x1 = x[0];
      var x2 = x.length > 1 ? '.' + x[1] : '';
       var rgx = /(\d+)(\d{3})/;
       while (rgx.test(x1)) {
               x1 = x1.replace(rgx, '$1' + ',' + '$2');
       }
       return x1 + x2;
}

function removeOptionsPrice(){
var yyyy=document.forms[0].elements["Color"];
if (yyyy !=null ){
	var y= document.forms[0].elements["Color"].selectedIndex;
	var yy=document.forms[0].elements["Color"].options[y].value;
var last=yy.lastIndexOf('(')
	if (last>1){
	var newvalue = yy.substring(0,last)
	document.forms[0].elements["Color"].options[y].value=newvalue;
		}						  
document.getElementById("Base Price").value=document.getElementById("disp_price").innerHTML;
}


}