if (parent.location.href != window.location.href){
		parent.location.href=window.location.href;
	}

var server = "http://www.specializedengraving.com/";

function replace_image(container, file){
  
  if(document.images){
    var path = server+"images/products/"+file;
    theObj = eval(document.images[container]);
    theObj.src = path;
  }
}

function checkMaxLength(obj, maxlen, form, index){
  
  fontRef = eval("form.font_id" + index);
  if(fontRef.selectedIndex < 0){
  	alert("Be sure to select a font for your text");
  }
  
  var str = new String(obj.value);
  if(str.length > maxlen){
    alert("The maximum characters per line for this sign is "+maxlen+". Try another size, or put your message in the comments of your order and we'll see what we can do!");
  }
  obj.value = str.substr(0, maxlen);

}

function format(expr, decplaces){
  var str = "" + Math.round(eval(expr) * Math.pow(10, decplaces));
  while(str.length <= decplaces){
    str = "0" + str;
  }
  var decpoint = str.length - decplaces;
  return str.substring(0, decpoint) + "." + str.substring(decpoint, str.length); 
}

//Included in se-scripts.js
//function enlargedWindow(type, id){
//  var url = new String(server+"products/enlarged.php?type="+type+"&id="+id);
//  window.open(url,"","width=400,height=400");
//}

function tipWindow(tip){
  var url = new String(server+"products/tips.php?tip="+tip);
  window.open(url,"Tips","width=350,height=500");
}

function checkBordersAndCorners(element){
  
  if(element.name == "corners" && element.options[element.selectedIndex].value == "0") {
  	document.forms[0].num_corners.selectedIndex = 0;
  	calculateSignTotal(document.forms[0]);
  	return true;
  }
  
  if((element.name == "corners") && document.forms[0].num_corners.selectedIndex <= 0){
    alert("Be sure to select how many corners you'd like");
    return false; 
  }
 
 	if(document.forms[0].borders){
		if((element.name == "corners" || element.name == "num_corners") && document.forms[0].borders.selectedIndex > 0){
			alert("A sign cannot have both a border and corners. Click on None in one, then return to the other");
			element.options.selectedIndex = 0;
			return false;
		}
		else if(element.name == "borders" && (document.forms[0].corners.selectedIndex > 0 || document.forms[0].num_corners.selectedIndex > 0)){
			alert("A sign cannot have both a border and corners. Click on None in one then return to the other.");
			element.options.selectedIndex = 0;
			return false;
		} 
  }
  return true;
}   

function calculateSignTotal(form){
  var total = 0.00;
  var attachment_total = 0.00;
  var hole_total = 0.00;
  var holder_total = 0.00;
  
  total += parseFloat(base);
  for(i = 0; i < form.max.value; ++i){
    var theObj = eval("document.forms[0].font_id"+i);
    var re = /Fancy/;
    if(theObj.options.selectedIndex > 0){
      var index = parseInt(theObj.options.selectedIndex);
      if(re.test(theObj.options[index].text)){
        total += parseFloat(fancy_font_price);
      }
    }
  }
  if(form.borders){
    if(form.borders.options.selectedIndex > 0){
       total += 5.00;
    }
  }
  if(form.num_corners){
		if(form.num_corners.options.selectedIndex > 0){
			if(form.num_corners.options[form.num_corners.options.selectedIndex].value != 0){
				total += parseInt(form.num_corners.options[form.num_corners.options.selectedIndex].value) * 1.25;
			}
		}
	}
	if(form.line_art){
	  if(form.line_art.options.selectedIndex > 0){
	    total += parseFloat("2.50");
	  }
	}
  if(form.attachment){
		if(form.attachment.options.selectedIndex > 0){
			attachment_total = parseFloat(attachment_array[form.attachment.options[form.attachment.options.selectedIndex].value]);
		}
	}
	if(form.hole){
		if(form.hole.options.selectedIndex > 0){
			hole_total = parseFloat(attachment_array[form.hole.options[form.hole.options.selectedIndex].value]);
		}
	}
	if(form.holder){
		if(form.holder.options.selectedIndex > 0){
			holder_total = parseFloat(attachment_array[form.holder.options[form.holder.options.selectedIndex].value]);
		}
	}
  if(parseFloat(total) > parseFloat(max_price)){
    total = parseFloat(max_price) + attachment_total + hole_total + holder_total;
    form.base_price.value = format(total, 2);
  }
  else{
    total += attachment_total + hole_total + holder_total;
    form.base_price.value = format(total, 2);
  }
}

function validateEngravingForm(form) {
	
	if (form.material.selectedIndex <= 0) {
		alert("Be sure to select your engraving material!");
		return false;
	}	
	
	return true;
}
