var bgBad = "#C0C0C0";
var bgGood = "#FFFFFF";

function setColor(el, bg) {
  if (el.style) el.style.backgroundColor = bg;
}

function isInputEmpty(o,field){
  if (o.value.length==0){alert("Please fill in the: "+field); setColor(o, bgBad); o.focus(); return true;}
  else{setColor(o, bgGood);}}

function isNotNumber(o){
	var number_format = "0123456789";
	var check_char;
	for (var i = 0; i < o.value.length; i++){
		check_char = number_format.indexOf(o.value.charAt(i))
		if (check_char < 0){alert("Enter a number"); setColor(o, bgBad); o.focus(); return true;}
		else{setColor(o, bgGood);}}
}

function isNotDecimal(o){
	var number_format = "0123456789.,";
	var check_char;
	for (var i = 0; i < o.value.length; i++){
		check_char = number_format.indexOf(o.value.charAt(i))
		if (check_char < 0){alert("Enter a number"); setColor(o, bgBad); o.focus(); return true;}
		else{setColor(o, bgGood);}}
}

function isNotPrice(o){
	var number_format = "$0123456789.,";
	var check_char;
	for (var i = 1; i < o.value.length; i++){
		check_char = number_format.indexOf(o.value.charAt(i))
		if (check_char < 0){alert("Enter a dollar value"); setColor(o, bgBad); o.focus(); return true;}
		else{setColor(o, bgGood);}}
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function stringFilterPrice (input) {
	s = input.value;
	filteredValues = "#<>,$";     // Characters stripped out
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
	var c = s.charAt(i);
	if (filteredValues.indexOf(c) == -1) returnString += c;
//	if ((filteredValues.indexOf(c) == -1) && (c != '"')) returnString += c;
	}
	input.value = returnString;
}

function stringFilterLoose (input) {
	s = input.value;
	filteredValues = "#<>";     // Characters stripped out
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
	var c = s.charAt(i);
	if (filteredValues.indexOf(c) == -1) returnString += c;
//	if ((filteredValues.indexOf(c) == -1) && (c != '"')) returnString += c;
	}
	input.value = returnString;
}

function viewpic(picpath,Width,Height){
	mywin = window.open("/viewpic.cfm?picpath="+picpath, "win", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width="+Width+",height="+Height+"");
}

function viewpic_scroll(carid,filename){
	mywin = window.open("/viewpic.cfm?CarID="+carid+"&filename="+filename, "win", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=740,height=575");
}

function viewpic_scroll_pg(photoid,picpath,Width,Height){
	mywin = window.open("/viewpic_pg.cfm?PhotoID="+photoid+"&picpath="+picpath, "win", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+Width+",height="+Height+"");
}

function p_viewpic_scroll(partid){
	mywin = window.open("/p_viewpic.cfm?PartID="+partid, "win", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=740,height=575");
}

function open_xe(price,currency){
	mywin = window.open("/find/xe.cfm?Price="+price+"&Currency="+currency, "win", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=550,height=330");
}