<!--   copyright 2010 Coastal Style, LLC All Rights Reserved


var pi = document.getElementById("pageinfo").value.split(',');
var cpf = document.getElementById("weavec").value.split(',');

function getprice(){
checkSize();
}

function cb(bc, wx, wy){
var bclow = bc.toLowerCase();
document.getElementById('rborder').src="http://lib.store.yahoo.net/lib/coastal-style/"+bclow+"-sidebinding.jpg";
document.getElementById('bborder').src="http://lib.store.yahoo.net/lib/coastal-style/"+bclow+"-bottombinding.jpg";
for (n=0; n<wy; n++){
  document.getElementById('flow3img'+n+wy).style.borderColor="#CCD3B3";}
document.getElementById('flow3img'+wx+wy).style.borderColor="#7D775C";
var toMatch=bc.replace(/-/, " ");
var r = toMatch.replace(/(\w)(\w*)/g, function (_, i, r) {return i.toUpperCase()+(r != null ? r : "");})
pi[3]= r;
var t1=document.getElementById('bindcoll');
var t = t1[t1.selectedIndex].innerHTML;
var t2 =bc.replace(/-/g, " ");
document.getElementById('dbo').innerHTML=t +" "+t2;
document.getElementById('bindcol').innerHTML=t +" "+t2;
document.getElementById('Border').value=t +" "+t2;
checkSize();
}

function cw(nm,wvclr,wx, wy){   
if(document.selection.weavec[0]){
  var wp = parseFloat(document.selection.weavec[document.getElementById('wvarrayno').value].value);
  }else{var wp = parseFloat(document.selection.weavec.value);}
var bhldr = document.getElementById('bindcoll');
var bholder = bhldr[bhldr.selectedIndex].value;
switch(bholder){
    case "unb":
  	document.images['mat'].src = "http://lib.store.yahoo.net/lib/coastal-style/" + nm + "-large.jpg";
        	break;
    default:
  	document.images['matlg'].src = "http://lib.store.yahoo.net/lib/coastal-style/" + nm + "-190200.jpg";
	break;}
for (n=0; n<wy; n++){
  document.getElementById('flowimg' + n + wy).style.borderColor="#CCD3B3";}
document.getElementById('flowimg' + wx + wy).style.borderColor="#7D775C";
pi[1] =nm;
var a =pi[0];
a += " " + wvclr;
document.getElementById('weavecol').innerHTML =a;
document.getElementById('Rug').value = a;
document.getElementById('ddw').innerHTML= a;
if(pi[13]=="1"){pi[12] = cpf[wx];}
checkSize();	 
}

function wvrep(wc,wci){
  document.getElementById('blnmat').src="http://lib.store.yahoo.net/lib/coastal-style/" + wc + "-corner.jpg";

  checkSize();
}

function checkSize() {
var l2, w2, checkLength, checkWidth, perYdPrice,r,lenSeam,lxwRug,widSeam,wxlRug,fp,s,t,bor,bor2;

 if (parseFloat(document.getElementById("length1").value)>=0 && parseFloat(document.getElementById("width1").value)>=0){
      bor = parseFloat(pi[7]) 
      l2 = parseFloat(document.selection.length2.value) * 0.083333333333333333333333333333333;
      w2 = parseFloat(document.selection.width2.value) * 0.083333333333333333333333333333333;
      checkLength = parseFloat(document.selection.length1.value) +l2;
      checkWidth = parseFloat(document.selection.width1.value) + w2;
      bor2= Math.floor(bor * ((checkLength + checkWidth)*2));
      perYdPrice = parseFloat(pi[12]);}
      r = pi[6];
      lenSeam = Math.floor(checkLength / 6.51);  
      lxwRug = Math.floor((lenSeam * checkWidth * r)+((lenSeam+1) * checkWidth * perYdPrice*6.6667)+bor2);
      widSeam = Math.floor(checkWidth / 6.51);     
      wxlRug = Math.floor((widSeam * checkLength * r)+((widSeam+1) * checkLength * perYdPrice*6.6667)+bor2);
      if(parseFloat(checkWidth) == 0 || parseFloat(checkLength) == 0){
          document.getElementById('btn1').disabled = true;
          document.getElementById('ddseam').innerHTML ="size not chosen";
     }else if (lxwRug>0 && wxlRug>0){
          if(checkWidth<=6.5 && checkLength<=6.5){
	document.getElementById('ddseam').innerHTML ="No seams required";
	if(checkWidth>checkLength){
        	     fp = wxlRug;
	     pi[5] = document.selection.length1.value  +"\'-"+ document.selection.length2.value + "\"";
	     pi[4] = document.selection.width1.value +"\'-"+ document.selection.width2.value + "\"";
  	}else{
        	     fp = lxwRug;
        	     pi[4] = document.selection.length1.value  +"\'-"+ document.selection.length2.value + "\"";
        	     pi[5] = document.selection.width1.value +"\'-"+ document.selection.width2.value + "\""; 
	}
          }else if (checkWidth<=6.5 && checkLength>6.5){     
	document.getElementById('ddseam').innerHTML ="No seams required";
	fp = wxlRug;
	pi[5] = document.selection.length1.value  +"\'-"+ document.selection.length2.value + "\"";
	pi[4] = document.selection.width1.value +"\'-"+ document.selection.width2.value + "\"";
          }else if (checkWidth>6.5 && checkLength<=6.5){     
	document.getElementById('ddseam').innerHTML ="No seams required";
	fp = lxwRug;
	pi[4] = document.selection.length1.value  +"\'-"+ document.selection.length2.value + "\"";
	pi[5] = document.selection.width1.value +"\'-"+ document.selection.width2.value + "\""; 
          }else if ((checkWidth>13 && checkLength>13)||(checkWidth>20 || checkLength>20)){    
	document.getElementById('btn1').disabled = true;
	document.getElementById('ddseam').innerHTML ="size not chosen";
	alert("This rug is too large for us to ship. We can not create a rug with dimensions greater than 13' wide and 20' long.");
          }else if (lxwRug>wxlRug){
	fp = wxlRug;
	pi[5] = document.selection.length1.value  +"\'-"+ document.selection.length2.value + "\"";
	pi[4] = document.selection.width1.value +"\'-"+ document.selection.width2.value + "\"";
	if(widSeam == 1){document.getElementById('ddseam').innerHTML ="This rug requires 1 seam";}
	else{ document.getElementById('ddseam').innerHTML ="This rug requires " + widSeam +" seams";}
          }else{
	fp = lxwRug;
	pi[4] = document.selection.length1.value  +"\'-"+ document.selection.length2.value + "\"";
	pi[5] = document.selection.width1.value +"\'-"+ document.selection.width2.value + "\""; 
	if(lenSeam == 1){document.getElementById('ddseam').innerHTML ="This rug requires 1 seam";}
	else{ document.getElementById('ddseam').innerHTML ="This rug requires " + lenSeam +" seams";}    
	} 

    pi[11] =fp;
    pi[10] = checkWidth;
    pi[9] = checkLength;  	
if( pi[9]<1 || isNaN(pi[9])){ pi[11] =0;}
if( pi[10]<1 || isNaN(pi[10])){ pi[11] =0;}
if (pi[11]==0){document.getElementById('btn1').disabled = true;
	}
  else{ document.getElementById('btn1').disabled = false;
	document.getElementById('rugprice').innerHTML ="Price: $" +fp +".00";
	document.getElementById('Rug-Quote').value = "(+" + fp +".00)";
	s = pi[4] +" wide by "+pi[5]+" long.";
	document.getElementById('dds').innerHTML= s;
	document.getElementById('Rug-Dim').value= s;
	document.getElementById('dimension').innerHTML= s;
	t = document.getElementById('weavecol').innerHTML;
}}}


function brdlmcw(nm,wvclr,wx,wy){
	document.images['bdlm'].src = "http://lib.store.yahoo.net/lib/coastal-style/" + nm + "-large.jpg";
	var a =pi[0];
	a += " " + wvclr;
	document.getElementById('bddw').innerHTML =a;
	for (n=0; n<wy; n++){ document.getElementById('flowimg' + n + wy).style.borderColor="#CCD3B3";}
	document.getElementById('flowimg' + wx + wy).style.borderColor="#7D775C";
	if(pi[13]=="1"){pi[12] = cpf[wx];}
brdlmCkSize()
}

function brdlmCkSize() {
	var  brdlmLen, brdlmWid, brdlmSqFt, frt,bdlen,bp,bpfrt;
	brdlmLen = parseFloat(document.getElementById('length8').value) * 0.083333333333333333333333333333333;
	brdlmLen += parseFloat(document.getElementById('length7').value);
	if( isNaN(brdlmLen)){
	   document.getElementById('btn2').style.display="none";
	   document.getElementById('bdlmprice').style.display="none";			
	}else{
	  document.getElementById('btn2').style.display="block";
	  document.getElementById('bdlmprice').style.display="block";	
	  bdlen =document.getElementById('length7').value +"'-"+ document.getElementById('length8').value+ "\" long ";	
	  document.getElementById('bdds').innerHTML= document.getElementById('bwidhold').innerHTML+" by "+bdlen;	
	  brdlmWid =  parseFloat(pi[8] + 0.18333333);
	  brdlmSqFt = brdlmLen*brdlmWid;
	  document.getElementById('Brdlm').value= bdlen + " "+document.getElementById('bddw').innerHTML +" broadloom";
	if (brdlmLen ==0){frt=0;
	}else if (brdlmLen <=8.51){frt=120;
	}else if (brdlmLen <=12.1){frt=150;
	}else if (brdlmLen <=17.1){frt=180;
	}else if (brdlmLen <=22.1){frt=220;
	}else if (brdlmLen <=30.1){frt=280;
	}else {frt=375;}      
	  bp =Math.round(brdlmSqFt * pi[12] *0.842);
	  bpfrt =bp+frt;
	  if (bp==0){document.getElementById('btn2').style.display="none"}else {document.getElementById('btn2').style.display="block"};
	  document.getElementById('Brdlm-Quote').value = "(+"+bpfrt +".00)";  
	  document.getElementById('bdlmprice').innerHTML ="&nbsp;&nbsp;&nbsp;Price $"+ bp +".00<br>Freight  $"+frt+".00";
//	  document.getElementById('bquoteprice').innerHTML ="Total $"+ bpfrt +".00";
}	  
}

function cbc(series){
var cimg, blgth;
var bind2= 3.35;
var bind3=new Array("BKB-Sisal-Plain-Creme+BKB-Sisal-Plain-Pale+BKB-Sisal-Plain-Mole+RIPS-Cocos-Plain-Seagrass+RIPS-Cocos-Plain-Beige+RIPS-Cocos-Plain-Granite+RIPS-Cocos-Plain-Burdock+RIPS-Cocos-Plain-Indigo+RIPS-Cocos-Plain-Black","Unbacked Bolon");

switch(series){
    case "unb":
       var bcollects = new Array();
       bcollects=bind3[0].split("+");
       var b5=bcollects[0].toLowerCase();
       cimg =    "<img id=\"mat\" src=\"http://lib.store.yahoo.net/lib/coastal-style/" + pi[1];
       cimg +=  "-large.jpg\"><img id=\"rborder\" src=\"http://lib.store.yahoo.net/lib/coastal-style/" + b5 + "-sidebinding.jpg\">";
       cimg +=  "<img id=\"bborder\" src=\"http://lib.store.yahoo.net/lib/coastal-style/" + b5 + "-bottombinding.jpg\">";
     document.getElementById('bindinginfo').innerHTML="";
       blgth = bcollects.length;
       break;
    default:
       cimg=    "<img id=\"matlg\" src=\"http://lib.store.yahoo.net/lib/coastal-style/";
       cimg +=  pi[1];
       cimg +=  "-190200.jpg\">";
       blgth =0;
       break;}
document.getElementById('crnrsmpl').innerHTML= cimg;
var u1;
switch(series){
    case "Select":
       pi[7]=0;
       document.getElementById('dbo').innerHTML="Unbound";
       document.getElementById('bindcol').innerHTML="Unbound";
       document.getElementById('Border').value="Unbound";
       document.getElementById('bindinginfo').innerHTML= "";
       break;
    case "mat":
       pi[7]=0;
       document.getElementById('dbo').innerHTML="Unbound";
       document.getElementById('bindcol').innerHTML="Unbound";
       document.getElementById('Border').value="Unbound";
       document.getElementById('bindinginfo').innerHTML= "";
       break;		
    case "self":
       pi[7]=3.35;
       document.getElementById('dbo').innerHTML="self-bound";
       document.getElementById('bindcol').innerHTML="self-bound";
       document.getElementById('Border').value="self-bound";
       document.getElementById('bindinginfo').innerHTML= "";
       break;
    case "unb":
       pi[7]=11.95; 
       var t1=bind3[1];
       var t2=bcollects[0].replace(/-/g, " ");
       document.getElementById('dbo').innerHTML=t1 +" "+t2;	
       document.getElementById('bindcol').innerHTML=t1 +" "+t2;
       document.getElementById('Border').value=t1 +" "+t2;	
       var u1 ="<br>";
       for (n=0; n<blgth; n++){ 
          var b1=bcollects[n];
          var b2=b1.replace(/-/, " ");
          var b3= b1.toLowerCase();
          u1 += "<div class=\"flow3\"><a href=\"javascript:cb('" + b1 + "','"+n+"','"+blgth+"');\"><img src=\"http://lib.store.yahoo.net/lib/coastal-style/" + b3 + "-sm.jpg\" id=\"flow3img" + n + blgth   +"\" alt=\"" + b2 + "\"></a></div>";}
    document.getElementById('bindinginfo').innerHTML= u1;	
         break;}

checkSize();


}





