var lastloc=0;

function calculateTotal(single_price, fix_weight, base_price, points, point_price, stone_numbers, stone_price, letter_weight) {
        var qty = document.product_order.qty.value;
        var line1 = document.product_order.line1.value;
        var silver_single_price = document.product_order.letter_price.value;
        
        if (document.product_order.line2) {
           var line2 = document.product_order.line2.value;
        } else {
           var line2 = "";
        }
        var total_length = line1.length + line2.length;
                
        if (total_length > 0) {
        	if (silver_single_price == 0) {
        		 ////For Other Pendant
             total_price = single_price*total_length*letter_weight + fix_weight*single_price + base_price;
          } else {
             ////For Silver Pendant
             total_price = silver_single_price*total_length + base_price;
          }
          stone_enabled = document.product_order.stone_enabled.value;
          
          if (stone_enabled == 1) {
          	total_price = total_price + stone_numbers*stone_price;
          } else {
            total_price = total_price + points*point_price;
          }
          total_price = total_price * qty;
        } else {
          total_price = 0;
        }
        total_price = total_price.toFixed(0);
        tmp_price = total_price + ".00";
        document.product_order.total_price.value = tmp_price;
        document.product_order.total_price1.value = tmp_price;
        //document.product_order.sample_price.value = tmp_price;
}


function calculateChain() {
	  var gram = document.product_order.gram.value;
	  var metal_price = document.product_order.metal_price.value;
	  var radioLength = document.forms['product_order'].elements['thelength'];
	  var radioLength_L = radioLength.length;
	  
	  thelength = 0;
	  for(var i = 0; i < radioLength_L; i++) {
		  if(radioLength[i].checked) {
			  thelength = (radioLength[i].value);
		  }
	  }
	  
	  
	  tmp_price = gram * metal_price * thelength;
	  tmp_price = tmp_price.toFixed(0);
	  tmp_price = tmp_price + ".00";
	  document.product_order.total_price.value = tmp_price;
	  document.product_order.total_price1.value = tmp_price;
}



//Drop Down Menu
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { // Modified by Kirk
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	cat1.style.display = "none";
	cat2.style.display = "none";
	cat3.style.display = "none";
	cat4.style.display = "none";
	cat5.style.display = "none";
	cat6.style.display = "none";
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style.display == "none") { 
    	obj.style.display = "block";
    } else {
    	obj.style.display = "none";
    }
  }
}

function winBRopen(theURL, Name, popW, popH, scroll) { // V 1.0
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable=no'
Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }

}

function showHideText(box,id)  {
	var elm = document.getElementById(id);
	var test = document.getElementById(box);
	
	if(test.checked == true) {
		elm.style.display = "none";
	}else{
		elm.style.display = "block";
	}
}


function showHideState()  {
	if (document.getElementById("country").value == "UNITED STATES" || document.getElementById("country").value == "CANADA") {
		document.getElementById("state_america").style.display = "block";
		document.getElementById("state_intl").style.display = "none";
  } else {
    document.getElementById("state_america").style.display = "none";
		document.getElementById("state_intl").style.display = "block";
  }

}


function showHideState_Add()  {
	if (document.getElementById("country").value == "US" || document.getElementById("country").value == "CA") {
		document.getElementById("state_america").style.display = "block";
		document.getElementById("state_intl").style.display = "none";
  } else {
    document.getElementById("state_america").style.display = "none";
		document.getElementById("state_intl").style.display = "block";
  }
}


function showHideLength(obj, gram, metal_price, diameter_id, diameter_name, cur_pos)  {

      var el = document.getElementById(obj);
      var ar = document.getElementById("master_length").getElementsByTagName("span");
      var thelength;
      
      var radioLength = document.forms['product_order'].elements['thelength'];
	    var radioLength_L = radioLength.length;
      for(var i = 0; i < radioLength_L; i++) {
		    if(radioLength[i].checked) {
			    thelength = (radioLength[i].value);
			    radioLength[i].checked = 0;
		    }
	    }
      
      for (var i=0; i<ar.length; i++){
         ar[i].style.display = "none";
	    }
      el.style.display = "block";
	    
      var tmp_ar = ar.item(parseInt(cur_pos));
      tmp_ar = tmp_ar.getElementsByTagName("input");
      for (var j=0; j<tmp_ar.length; j++){
         if (tmp_ar[j].value == thelength) {
            tmp_ar[j].checked = 1;
         }
      }
      
     	document.product_order.diameter_id.value = diameter_id;
      document.product_order.diameter_name.value = diameter_name;
      document.product_order.gram.value = gram;
	    document.product_order.metal_price.value = metal_price;
      
	    calculateChain();
}


function showHideText2(box,id)  {
	
	var elm = document.getElementById(id);
	var test = document.getElementById(box);
	
	if(test.checked == true) {
		elm.style.display = "block";
	}else{
		elm.style.display = "none";
	}
	
	}
	

function alpha(e) {
   var k;
   document.all ? k = e.keyCode : k = e.which;
   return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8);
}


function stone_click() {
	document.product_order.replace[1].checked=1; 
	document.product_order.stone_enabled.value=1; 
}

function diamond_click() {
	document.product_order.replace[1].checked=1; 
	document.product_order.stone_enabled.value=0; 
}


function dsp(loc,e,xpos){
	if(document.getElementById){
		if(lastloc!=0){
			thediv=document.getElementById("div"+lastloc);
      		thediv.style.display=thediv.style.display=='block'?'none':'block';
			lastloc=0;
		}
	var x=y=0;
    if (e != '') {
		if(document.layers){x=e.pageX; y=e.pageY}
		else{x=event.x; y=event.y;}
    }
	
	var isIE = (navigator.appName.toLowerCase() == "microsoft internet explorer")
	var isNN = (navigator.appName.toLowerCase() == "netscape")
	if(isIE){myScrollX = document.body.scrollLeft;}
	else{myScrollX = window.pageXOffset;}
	if(isIE){myScrollY = document.body.scrollTop;}
	else{myScrollY = window.pageYOffset;}
	x=x+myScrollX;
	y=y+myScrollY;

	thediv=document.getElementById("div"+loc);
    //thediv.style.left=x-(70*xpos);
    if (loc != 999) {
    		if (loc == 888) {
	       thediv.style.left=-150;
	       thediv.style.top=200;
      } else {
         thediv.style.left=420;
	       thediv.style.top=y-400;
	    }
    } else {
         thediv.style.left=270;
	       thediv.style.top=y;
    }
    thediv.style.display=thediv.style.display=='block'?'none':'block';
	lastloc=loc;
	}
} 

function dsp_finish(loc,e,xpos){
	if(document.getElementById){
		if(lastloc!=0){
			thediv=document.getElementById("div"+lastloc);
      		thediv.style.display=thediv.style.display=='block'?'none':'block';
			lastloc=0;
		}
	var x=y=0;
    if (e != '') {
		if(document.layers){x=e.pageX; y=e.pageY}
		else{x=event.x; y=event.y;}
    }
	
	var isIE = (navigator.appName.toLowerCase() == "microsoft internet explorer")
	var isNN = (navigator.appName.toLowerCase() == "netscape")
	if(isIE){myScrollX = document.body.scrollLeft;}
	else{myScrollX = window.pageXOffset;}
	if(isIE){myScrollY = document.body.scrollTop;}
	else{myScrollY = window.pageYOffset;}
	x=x+myScrollX;
	y=y+myScrollY;

	thediv=document.getElementById("div"+loc);
	thediv.style.left=x-(200*xpos);
  //thediv.style.left=270;
  thediv.style.top=y;
  thediv.style.display=thediv.style.display=='block'?'none':'block';
	lastloc=loc;
	}
} 

function closediv(tmpObj){
	if(lastloc!=0){
		thediv=document.getElementById("div"+lastloc);
      	thediv.style.display=thediv.style.display=='block'?'none':'block';
		lastloc=0;
	}
}


function finish_i_like() {
	  var radioLength = document.forms['product_order'].elements['finish[]'];
	  var radioLength_L = radioLength.length;
	  
	  for(var i = 0; i < radioLength_L; i++) {
		  if(radioLength[i].checked) {
			  radioLength[i].checked = 0;
		  }
	  }
}


function finish_i_select() {
	  var radioLength = document.forms['product_order'].elements['finish[]'];
	  var radioLength_L = radioLength.length;
	  
	  for(var i = 0; i < radioLength_L; i++) {
		  if(radioLength[i].checked) {
			  radioLength[i].checked = 0;
		  }
	  }	  
	  radioLength[0].checked = 1;
}


function finish_i_select_below(theValue) {
	  document.product_order.select_finish.value=theValue;
	  
	  var radioLength = document.forms['product_order'].elements['choose_finish'];
	  radioLength[0].checked = 0;
	  radioLength[1].checked = 1;
}


function showCustomPopUp(thisUrl,thisName,theseParams){
		remote = open(thisUrl, thisName, theseParams);
}

function MouseOver(src,BackColor) 
{ 
       if (!src.contains(event.fromElement)) 
        {
            src.bgColor = BackColor;
            src.style.bordercolor = "#000000";
        }
}
function MouseOut(src, BackColor)
{
        if (!src.contains(event.toElement))
        {
            src.bgColor = BackColor; 
            src.style.bordercolor = "#000000";
        }
}
