var tabView = new YAHOO.widget.TabView('rugBuilder');

function rd(){
document.getElementById('rugdescription').innerHTML= "Selected Rug:<br><blockquote>Weave: " + document.getElementById('weavecol').innerHTML + "<br>Border: " + document.getElementById('bindcol').innerHTML + "<br>Size: " + document.getElementById('dimension').innerHTML + "<br>Price: " + document.getElementById('rugprice').innerHTML + "</blockquote>";
document.getElementById('Rug').value=document.getElementById('dimension').innerHTML + " " + document.getElementById('weavecol').innerHTML + " bound in "+document.getElementById('bindcol').innerHTML;
document.getElementById('Rug-Quote').value="(+" + document.main.pr.value + ".00)";

}
function matrep(nm,wvclr,wx,wy){
	document.images['mat'].src = "http://site.ecorug.net/weaves/" + nm + "-150160.jpg";
	document.getElementById('weavecol').innerHTML =wvclr;
	getprice();

}

function cr(){
document.getElementById('bindcol').innerHTML=document.main.bc.value +" "+document.main.bn.value +" to show "+document.main.bindwidth.options[document.main.bindwidth.selectedIndex].text +" with "+document.main.bindcorner.options[document.main.bindcorner.selectedIndex].text;
getprice();

}

function bindrep(series){
var bindnc=new Array("Fuchia+Coral+Violet+Chick-Pea+Sweet-Pea+Artichoke+Banana-Cream+Moss-Brown+Hedgehog+Onyx+Butter-Cream+Cappuccino+Chardonnay+Fudge+Blue-Isle+Raffia+Sherry+Smoke+Taffy+Ivory","Narrow Cotton",1,1,0,8.36);
var bindwc=new Array("Pitch-Black+Cadet-Blue+Midnight-Blue+Lavender+Cobalt-Blue+Cornflower-Blue+Viridian-Green+Thyme+Antique-Gold+Yellow+Tangerine+Venetian-Red+Alizarin+Lipstick-Red+Persimmon+Berry-Red+Chino+Beige+Ochre+Natural+Sage+Honey+Chamois+Latte+Mocha+Chocolate+Chestnut","Wide Cotton",2,2,160,10.64);
var bindsct=new Array("American-Beauty+Canyon+Chartreuse+Chasm+Dark-Roast+Dolphin+Gardenia+Gray-Green+Inkberry+Legion+Malibu+Meadow+Mesa-Verde+Prairie-Mist+Pumpkin+Riviera+Sawdust+Seed-Brown+Shoreline+Soapstone+Soldier-Blue+Tan", "Soft Cotton Twill",4,2,200,19.19);
var bindpw=new Array("Bark+Blue-Jay+Camouflage+Capri-Blue+Chinese-Red+Deep-Brown+Desert-Tan+Ebony+Emerald+Georgia-Clay+Glacial-Green+Jade+London-Tan+Smoky-Blue+White-Sand","Cotton Pebble Weave",4,2,200,19.19);
var bindbw=new Array("Bumble-Bee+Otter+Lynx+Catfish+Chipmunk+Mallard+Leapfrog+Blue-Rhino+Harbor-Seal+Hummingbird+Dragon+Moose+Jaguar","basketweave",4,2,220,17.1);
var bindww=new Array("Coal+Bourbon+Cabernet+Cashmere+Fig+Ginger+Mink+Redrock","Wide Wool",4,2,220,19.76);
var bindsl=new Array("Antler+Auburn+Banana+Bravo-Red+California+Dunes+Gull+Moth+Peanut-Brittle+Quarry+Sable+Seal-Brown+Spearmint+Toast+Vermilion+Wild-Silk+Yellowstone+Yosemite","Smooth Linen",4,2,200,19.76);
var bindle=new Array("Black+Cinnabar+Espresso+Jamocha+Moss+Saddle+Taupe+Wine","Leather",4,3,0,35.53);
var bindps=new Array("Aztec-Gold+Buckeye+Fern+Marble+Mediterranean-Blue+Old-Cork+Sahara-Sand+Sesame+Shadow+Shale","Pigskin Suede",4,3,0,35.53);
var bindes=new Array("Sevilla+Espana+Marbella+Costa-Del-Sol+Valencia+Pamplona+Cordoba+Costa-Brava+Barcelona+Madrid","Espadrille",5,3,0,27.17);
var bindwj=new Array("Anthracite+Dark-Khaki+Blackberry+Brick-Red+Brown+Light-Green+Mustard+Jute+Navy-Blue+Royal-Blue+Rust","Wide Jute",4,2,200,16.91);
var bindjb=new Array("Gold+Silver","Jute Braid",3,2,0,28.31);
var bindsfl=new Array("Baguette+Black-Jack+Derby+Golden-Nugget+Horseshoe+Ice+Mirage+Monte-Carlo+Roulette+Tavern+Thunderbird+Valencia+Whale","Super Fabulous Leather",4,3,0,44.27);
//Change icons, selected text, and corner sample images
var b1, b2, b3, b4, u1, bcollects
u1="<p class=\"expred\">Select a weave below by clicking on an image</p>";
bcollects = new Array();
xxb=eval("bind"+series);
bcollects=xxb[0].split("+");
b3=bcollects[0].toLowerCase();
document.getElementById('rborder').src="http://site.ecorug.net/bindings/" + b3 + "s.jpg";
document.getElementById('bborder').src="http://site.ecorug.net/bindings/" + b3 + "b.jpg";
b4=bcollects[0].replace(/-/, " ");

document.getElementById('bc').value=xxb[1];

for (n=0; n<bcollects.length; n++){ 
  b1=bcollects[n];

  b2=b1.replace(/-/, " ");
  b3= b1.toLowerCase();
  u1+= "<div class=\"smbdimg\"><a href=\"javascript:cb('" + b1 + "','"+n+"');\"><img src=\"http://site.ecorug.net/bindings/" + b3 + "-sm.jpg\" id=\"bordericon" + n +"\" alt=\"" + b2 + "\" style=\"border-color:#FF4B4B;\"></a></div>" ;}
u1+= "<hr>";
document.getElementById('biconflow').innerHTML= u1;
//Change bwidth options
var bw0 = document.main.bindwidth;
for (n = bw0.options.length; n >= 0; n--){bw0.options[n] = null; };
var bw1 =	new Array("1/2 inch on Face");
var bw2 = 	new Array("3/4 inch on Face","1 inch on Face","1-1/4 inches on Face","1-1/2 inches on Face");
var bw3 =	new Array("2 inches on Face");
var bw4 = 	new Array("1 inch on Face","1-1/4 inches on Face","1-1/2 inches on Face","1-3/4 inches on Face","2 inches on Face","2-1/4 inches on Face","2-1/2 inches on Face","2-3/4 inches on Face","3 inches on Face");	
var bw5 =	new Array("1 inch on Face","1-1/2 inches on Face","2 inches on Face","2-1/2 inches on Face","3 inches on Face","3-1/2 inches on Face","4 inches on Face","4-1/2 inches on Face","5 inches on Face");	
var bx=eval("bw"+xxb[2]);
for (var i = 0; i<bx.length; ++i) {bw0.options[i]=new Option(bx[i]);}
//Change bcorner options
var bc0=document.main.bindcorner;
for (n = bc0.options.length; n >= 0; n--){bc0.options[n] = null; };		
var bc1 =	new Array("Lapped Corners");
var bc2 =	new Array("Lapped Corners","Mitered Corners");	
var bc3 =	new Array("Mitered Corners");
var bz=eval("bc"+xxb[3]);
for (var i = 0; i<bz.length; ++i) {bc0.options[i]=new Option(bz[i]);}
document.main.mcs.value = xxb[4];
document.main.bcs.value = xxb[5];
document.getElementById('bindcol').innerHTML=xxb[1] +" "+b4 +" -"+document.main.bindwidth.options[0].text +" with "+document.main.bindcorner.options[0].text;
getprice();
}

function cb(color){
var b6=color.toLowerCase();
document.getElementById('rborder').src = "http://site.ecorug.net/bindings/" +b6+ "s.jpg";
document.getElementById('bborder').src ="http://site.ecorug.net/bindings/" + b6+ "b.jpg";
document.getElementById('bindcol').innerHTML=document.main.bc.value +" "+color +" to show "+document.main.bindwidth.options[document.main.bindwidth.selectedIndex].text +" with "+document.main.bindcorner.options[document.main.bindcorner.selectedIndex].text;
document.getElementById('bn').value = color
rd()
}

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.91666667:
		  var maxWidthText = "12ft. 11in";
		  break;
		case 11.833333333333334:
		  var maxWidthText = "11ft. 10in";
		  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.getElementById('btnSubmit').disabled = true;
	document.getElementById('rugprice').style.display="block";
	document.getElementById('rugdescript').style.display="none";
	alert("This rug is too large for our broadloom. At least one Dimension should be less then or equal to " + maxWidthText);
	return;
  }else if ((checkLength>maxWidth)||(checkWidth>=checkLength && checkWidth<=maxWidth)){
	document.main.width.value = checkWidth;
	document.main.length.value = checkLength; 
	document.getElementById('rl').value = document.main.length1.value  +"\'-"+ document.main.length2.value + "\"";
	document.getElementById('rw').value = document.main.width1.value +"\'-"+ document.main.width2.value + "\"";
	document.getElementById('standard').value = document.main.width1.value +document.main.width2.value+document.main.length1.value+document.main.length2.value;
  }else {
	document.main.width.value =  checkLength;
	document.main.length.value = checkWidth;
	document.getElementById('rw').value = document.main.length1.value  +"\'-"+ document.main.length2.value + "\"";
	document.getElementById('rl').value = document.main.width1.value +"\'-"+ document.main.width2.value + "\"";
	document.getElementById('standard').value = document.main.length1.value+document.main.length2.value+document.main.width1.value +document.main.width2.value;
  }}
document.getElementById('dimension').innerHTML= document.getElementById('rw').value +" wide by "+document.getElementById('rl').value+" long";
getprice();


}

function getprice(){

	var w = (parseFloat(document.main.length.value)*1.4537)*parseFloat(document.main.weavec.value);
	var x = (parseFloat(document.main.length.value) +parseFloat(document.main.width.value))*2;
	var y = 0;
	var z=0;
	x*=parseFloat(document.main.bcs.value);
	if (document.main.bindcorner.selectedIndex=="1"){
	y=parseFloat(document.main.mcs.value);}
	if (document.main.length.value>8 && document.main.width.value>8){ z=100;}
	document.main.pr.value=Math.round(w+x+y+z+20);
	if (document.getElementById('standard').value=="6040") {document.main.pr.value = Math.floor(document.main.pr.value*.9)};
	if (document.getElementById('standard').value=="8050") {document.main.pr.value = Math.floor(document.main.pr.value*.9)};
	if (document.getElementById('standard').value=="9060") {document.main.pr.value = Math.floor(document.main.pr.value*.9)};
	if (document.getElementById('standard').value=="12090"){document.main.pr.value = Math.floor(document.main.pr.value*.9)};
	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;}
	document.getElementById('rugprice').innerHTML ="Price: $" +document.main.pr.value +".00";
rd();

}


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()};
}
