function bindrep(selectColors,series)
{
// define binding color array
var bindcols= new Array()

bindcols[1]= new Array(new Array("alizarin", "cadet-blue", "chino", "chocolate", "honey", "latte", "midnight-blue", "mocha", "natural", "pitch-black", "sage", "thyme", "venetian-red"), new Array( "artichoke", "cappuccino", "chardonnay", "chick-pea", "coral", "hedgehog", "onyx", "raffia", "sherry"), new Array("bark", "blue-jay", "camouflage", "capri-blue", "chinese-red", "cinder-gray", "curry", "deep-brown", "desert-tan", "ebony", "emerald", "georgia-clay", "glacial-green", "white-sand", "jade", "london-tan", "mojave", "royal-navy", "smoky-blue"), new Array("anthracite", "dark-khaki", "blackberry", "brick-red", "brown", "jute", "light-green", "mustard", "navy-blue", "royal-blue", "rust"))


var arrayColors ="bindcols[" +series +"]"


// replace lower 5050 images 
var d,i,color
var seriestext = ""
	 for (i = selectColors.options.length; i >= 0; i--)
	 {selectColors.options[i] = null; }

	for (d in bindcols[1][series]) {
	color=bindcols[1][series][d];
	seriestext += "<div class=\"flow\"><a href=\"javascript:cb('" + color + "');\"><img src='http://site.ecorug.net/bindings/" + color + ".jpg' alt=\"" 	+  color + " binding image\"</a><br>" + color + "</div>"; 
	selectColors.options[d] = new Option(color); 
	selectColors.options[d].value = color; }

document.getElementById('bindfloats').innerHTML =seriestext;
selectColors.options[0].selected = true; 
document.getElementById('rborder').src = "http://site.ecorug.net/bindings/" + bindcols[1][series][0]+ "s.jpg";
document.getElementById('bborder').src ="http://site.ecorug.net/bindings/" + bindcols[1][series][0]+ "b.jpg";



// replace binding options  
var n,x
var r   = document.main.bindwidth
var s  = document.main.bindcorner
var m = "this.form.mcs"
var b  = "this.form.bcs"
switch(series){
  case 0:
	 for (n = r.options.length; n >= 0; n--)
	      {r.options[n] = null; }
	 r.options[0] = new Option("3/4\" on Face");
	 r.options[1] = new Option("1\" on Face");
	 r.options[2] = new Option("1-1/4\" on Face");
	 r.options[3] = new Option("1-1/2\" on Face");
	 for (x = s.options.length; x >= 0; x--)
	      {s.options[x] = null; }
	 s.options[0] = new Option("Lapped Corners");
	 s.options[1] = new Option("Mitered Corners");
	 document.main.mcs.value=90;
	 document.main.bcs.value=6.53;
	getprice();
	 break;
  case 1:
	 for (n = r.options.length; n >= 0; n--)
	      {r.options[n] = null; }
	 r.options[0] = new Option("1/2\" on Face");
	 for (x = s.options.length; x >= 0; x--)
	      {s.options[x] = null; }
	 s.options[0] = new Option("Lapped Corners");
	 document.main.mcs.value=0;
	 document.main.bcs.value=5.17;
	getprice();
	 break;	
  case 2:
	 for (n = r.options.length; n >= 0; n--)
	      {r.options[n] = null; }
	 r.options[0] = new Option("3/4\" on Face");
	 r.options[1] = new Option("1\" on Face");
	 r.options[2] = new Option("1-1/4\" on Face");
	 r.options[3] = new Option("1-1/2\" on Face");
	 r.options[4] = new Option("1-3/4\" on Face");
	 r.options[5] = new Option("2\" on Face");
	 r.options[6] = new Option("2-1/4\" on Face");
	 r.options[7] = new Option("2-1/2\" on Face");
	 r.options[8] = new Option("2-3/4\" on Face");
	 r.options[9] = new Option("3\" on Face");
	 for (x = s.options.length; x >= 0; x--)
	      {s.options[x] = null; }
	 s.options[0] = new Option("Lapped Corners");
	 s.options[1] = new Option("Mitered Corners");
	 document.main.mcs.value=135;
	 document.main.bcs.value=11.70;
	getprice();
	 break;	
  case 3:
	 for (n = r.options.length; n >= 0; n--)
	      {r.options[n] = null; }
	 r.options[0] = new Option("3/4\" on Face");
	 r.options[1] = new Option("1\" on Face");
	 r.options[2] = new Option("1-1/4\" on Face");
	 r.options[3] = new Option("1-1/2\" on Face");
	 r.options[4] = new Option("1-3/4\" on Face");
	 r.options[5] = new Option("2\" on Face");
	 r.options[6] = new Option("2-1/4\" on Face");
	 r.options[7] = new Option("2-1/2\" on Face");
	 r.options[8] = new Option("2-3/4\" on Face");
	 r.options[9] = new Option("3\" on Face");
	 for (x = s.options.length; x >= 0; x--)
	      {s.options[x] = null; }
	 s.options[0] = new Option("Lapped Corners");
	 s.options[1] = new Option("Mitered Corners");
	 document.main.mcs.value=135;
	 document.main.bcs.value=10.24;
	getprice();
	 break;	}

}

function cb(color)
{

document.getElementById('rborder').src = "http://site.ecorug.net/bindings/" +color+ "s.jpg";
document.getElementById('bborder').src ="http://site.ecorug.net/bindings/" + color+ "b.jpg";
for (var i = 0; i <document.main.bindcolor.options.length; ++i) {
 if (document.main.bindcolor.options[i].text == color) {
document.main.bindcolor.options[i].selected=true;  }}
}
function cc(color)
{

document.getElementById('rborder').src = "http://site.ecorug.net/bindings/" +document.main.bindcolor.options[color].text+ "s.jpg";
document.getElementById('bborder').src ="http://site.ecorug.net/bindings/" + document.main.bindcolor.options[color].text+ "b.jpg";
}

function checkSize() {
 if (parseFloat(document.getElementById("length1").value)>=0 && parseFloat(document.getElementById("width1").value)>=0){
	var  maxWidth = parseFloat(document.main.mw.value);
	switch(maxWidth){
		case 12.833333333333334 :
		  var maxWidthText = "12ft. 10in";
		  break;		
		case 12.916666666666667 :
		  var maxWidthText = "12ft. 11in";
		  break;}
	var l2 = parseFloat(document.main.length2.value) * 0.083333333333333333333333333333333;
	var w2 = parseFloat(document.main.width2.value) * 0.083333333333333333333333333333333;
	var checkLength = parseFloat(document.main.length1.value) +l2;
	var checkWidth = parseFloat(document.main.width1.value) + w2;
	if(checkLength > maxWidth && checkWidth > maxWidth){
			document.getElementById('rugprice').innerHTML ="Price: $0.00";
			document.main.btn1.style.visibility=  "hidden";
			alert("This rug is too large for our broadloom. At least one Dimension should be less then or equal to " + maxWidthText);
			return;
	}else{
			var lengthStatus = "OK";
			var widthStatus = "OK";}
	if(lengthStatus == "OK" && widthStatus == "OK"){

	  if(checkWidth>=checkLength && checkLength<=maxWidth){
	  	  		document.main.width.value =  checkLength;
				document.main.length.value = checkWidth;
			}else {
	  			document.main.width.value = checkWidth;
				document.main.length.value = checkLength; }			
		}

}
	getprice()	;
}
function getprice(){
var w = (parseFloat(document.main.length.value)*1.4537)*parseFloat(document.main.wcs.value);
var x = (parseFloat(document.main.length.value) +parseFloat(document.main.width.value))*2;

x*=parseFloat(document.main.bcs.value);
var y = 0;
if (document.main.bindcorner.selectedIndex=="1"){y=parseFloat(document.main.mcs.value);}
var z=0;
if (document.main.length.value>8 && document.main.width.value>8){ z=100;}
document.main.pr.value=Math.round(w+x+y+z);
if( document.main.length.value<1 || isNaN(document.main.length.value)){ document.main.pr.value =0;}
if( document.main.width.value<1 || isNaN(document.main.width.value)){ document.main.pr.value =0;}
if (document.main.pr.value==0){document.main.btn1.style.visibility=  "hidden";}else{document.main.btn1.style.visibility= "visible";}
document.getElementById('rugprice').innerHTML ="Price: $" +document.main.pr.value +".00";

}

function sf() {
var l =parseFloat(document.main.length1.value +(document.main.length2.value/12));
var l1, w1
if(document.main.length2.value==0){l1=document.main.length1.value +"'"} else{l1=document.main.length1.value +"'-" +document.main.length2.value  +"\"" };
var w =parseFloat(document.main.width1.value +(document.main.width2.value/12));
if(document.main.width2.value==0){w1=document.main.width1.value +"'"} else{w1=document.main.width1.value +"'-" +document.main.width2.value  +"\"" };

var ret
if (l>=w) { ret=l1 + " by " +w1;}else{ret=w1 + " by " +l1;}
ret += " ";
ret += document.main.wn.value;
ret += " with ";
ret +=document.main.bindcolor[document.main.bindcolor.selectedIndex].text.toLowerCase();
ret += " ";
ret +=document.main.bindcoll[document.main.bindcoll.selectedIndex].text.toLowerCase();
ret += "  border applied at ";
ret +=document.main.bindwidth[document.main.bindwidth.selectedIndex].text.toLowerCase();
ret += " with ";
ret +=document.main.bindcorner[document.main.bindcorner.selectedIndex].text.toLowerCase();
ret += ". Price quoted $";
ret += document.main.pr.value
ret += ".  Quote valid for 30 days.";

document.getElementById("rugdesc").innerHTML = ret;
document.CustomRugOrder.Description.value = ret;


document.getElementById("rugorder").style.display= "block";
document.getElementById("rugdetails").style.display= "none";
document.getElementById("bindfloats").style.display="none";
document.getElementById("btextr").style.display="none";
}

function formvalid(){
var n = document.getElementById('cname');
var e=document.getElementById('cemail');
var p = document.getElementById('cphone');
var Msge ="It appears that the email address entered is incorrect. We need either a valid phone number or email address in order to contact you";
var Msgn ="It appears that your contact information is incomplete. Please enter your name in the form above so that we can contact you regarding this quote.";
var Msgep ="It appears that your contact information is incomplete. We need either a valid phone number or email address in order to contact you";

   if(n.value.length==0) { alert(Msgn);  document.rugorder.cname.focus();  } 
   if(n.value.length==0 && e.value.length==0) { alert(Msgep);  p.focus();} 	
   


}

function emvalid(t){
var Msg1 ="It appears that the email address entered is incorrect. Please re-enter the address, or call us at 603-206-6220 to place your order";
var vstring = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(t.value.match(vstring)) { ckform();
}else if (t.value==""){ckform();t.style.background ="#FFFFFF";
}else{  alert(Msg1); document.getElementById("btnSubmit").disabled = true; fld.style.background = "#F6E84A"; t.focus(); } 

}

function nvalid(n){
if(n.value==""){
} else if (n.value.length < 2){ alert("Please enter at least 2 characters in the \"Contact Name\" field.") ;n.style.background = "#F6E84A";}
n.style.background ="#FFFFFF";
ckform();
}


function pvalid(fld) {
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    
   if (fld.value == "") {
        fld.style.background =  "#FFFFFF";
    } else if (isNaN(parseInt(stripped))) {
       alert("The phone number contains illegal characters.");
        fld.style.background =  "#F6E84A";
    } else if (!(stripped.length == 10)) {
        alert("The phone number is the wrong length. Make sure you included an area code.");
        fld.style.background = "#F6E84A";
     }else if (fld.value=="") {
        document.getElementById("btnSubmit").disabled = true;
    } else if ((stripped.length == 10)) {
         fld.style.background ="#FFFFFF";}

  ckform();
}

function ckform(){
var p=document.getElementById('cphone');
var n = document.getElementById('cname');
var e=document.getElementById('cemail');
document.getElementById("btnSubmit").disabled = true;
var n = document.getElementById('cname');

if(  n.value.length==0 || (p.value.length==0 && e.value.length==0) )
{document.getElementById("btnSubmit").disabled = true; }
else 
{document.getElementById("btnSubmit").disabled = false;}
}

function noenter() {
  return !(window.event && window.event.keyCode == 13); }

function goBack(){
document.getElementById("rugorder").style.display= "none";
document.getElementById("bindfloats").style.display="block";
document.getElementById("btextr").style.display="block";
document.getElementById("rugdetails").style.display= "block";
}

function start(URL) {
var timeout =30;
windowprops = "left=0,top=0,width=475px,height=500px";

text = "<html><head><title> Color-way detail</title></head><body bgcolor='ffffff'";

if (timeout != 0) text +=" onLoad=\"setTimeout('window.close()', " + timeout*1000 + ");\"";

text += "><center><img src='" + URL + "'>";

if (timeout != 0) text +="<br><font face='arial, helvetica' size='-1'>Preview closes after " + timeout + " seconds.</font>";

text += "<br><FORM><INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\"></FORM>"

text += "</center></body></html>";

preview = window.open("", "preview", windowprops);
preview.document.open();
preview.focus();
preview.document.write(text);
preview.document.close();
}
function wvinfo(loc) {
var newwindow
newwindow=window.open(loc,'Info','width=600, height=600, scrollbars=yes');

if (window.focus) {newwindow.focus()};
}


