var Currtop = '<div class=t2a2 style="margin:17px 0 20px;"><div class=t2a1><div class=t2a3><div class="co4 fs23" style="padding:8px 0 0 7px;">Recently viewed items</div><table style="margin:7px 0 0 0;"><tr valign="top">';
var CurrItema = '<td class="t1e8 marg3a"><center>';
var CurrItemab = '</center><br></td>';
var CurrItemb = '</tr><tr valign="top">';
var CurrItembc = '<td class="t1e8 marg3a"><div class="t1e10">';
var CurrItembd = '<br><div style="margin-top:2px;"><span class="co5 bd fs14">';
var CurrItemd = '</span><br></div></td>';
var Currbot = '</tr></table><br></div></div></div>';

    function pasteRelated() {
	var items_count=5;
    var asd=0;
    var Rell=false;
    for (var i=1;i<(items_count+1);i++) {
        ccc='rel_'+i;
        if (GetCookie(ccc)) {
            Rell=true;
            asd=asd+1;
            }
        }
//  alert(GetCookie('rel_5'));
    if (Rell) {
		document.write(Currtop);
    for (var i=1;i<(items_count+1);i++) {
        ccc='rel_'+i;
        if (GetCookie(ccc)) {
            tempvall=GetCookie(ccc).split('-||-');
            document.write(CurrItema);
            document.write(tempvall[0]);
            document.write(CurrItemab);
            }
        }
	document.write(CurrItemb);	
    for (var i=1;i<(items_count+1);i++) {
        ccc='rel_'+i;
        if (GetCookie(ccc)) {
            tempvall=GetCookie(ccc).split('-||-');
            document.write(CurrItembc);
            document.write(tempvall[1]);
            document.write(CurrItembd);
            document.write(tempvall[2]);
            document.write(CurrItemd);
            }
        }		
		
        document.write(Currbot);
        }
    } 

function addtorel() {
	var items_count=6;
    related[CurrItemId]=CurrItem;
	rel_itms = new Array();
	inarr = false;
    for (i=1;i<=items_count;i++) {
    	cc='rel_'+i;
		if (!GetCookie(cc)) {
    	    SetCookie(cc, related[CurrItemId]);
        	break;
		} else {
			 if (GetCookie(cc)==related[CurrItemId]){
				 break;
			} else {
				for (i=0;i<items_count;i++) {
					ncc='rel_'+(i+1);
					if (GetCookie(ncc)==related[CurrItemId]) inarr=true;
					if (GetCookie(ncc))	rel_itms[i] = GetCookie(ncc);
				}
				if (!inarr){
					if (rel_itms.length == items_count) {
						rel_itms.splice(items_count-1,1);
					}
					rel_itms.unshift(related[CurrItemId]);
					for (i=1;i<=items_count;i++) {
						scc='rel_'+i;
						if (rel_itms[i-1]) SetCookie(scc, rel_itms[i-1]);
					}
				}
			}	
		}
	}
}	


var savingArray = false;

function updateall(num) {
num=0;
var totalprice=0;
calcq(num);
qvSaving = 0;
((eval("optionvalue"+num).length>0)?(totalprice=eval("qtyvalue"+num)*(eval("ipr"+num)+calcoptions(num))):(totalprice=eval("qtyvalue"+num)*eval("ipr"+num)));
  if(savingArray){
	if(eval("qtyvalue"+num) < savingArray.length){
		qvSaving = savingArray[eval("qtyvalue"+num)]*eval("qtyvalue"+num)
	}
	else{
		qvSaving = savingArray[(savingArray.length - 1)]*eval("qtyvalue"+num)
	}
    totalprice = totalprice - qvSaving;
  }

/*
for (i=0;i<=calcitems;i++) {
  calcq(i);
 ((eval("optionvalue"+i).length>0)?(price=eval("qtyvalue"+i)*(eval("ipr"+i)+calcoptions(i))):(price=eval("qtyvalue"+i)*eval("ipr"+i)));
  qvSaving = 0;
  if(savingArray){
	if(eval("qtyvalue"+i) < savingArray.length){
		qvSaving = savingArray[eval("qtyvalue"+i)]*eval("qtyvalue"+i)
	}
	else{
		qvSaving = savingArray[(savingArray.length - 1)]*eval("qtyvalue"+i)
	}
    price = price - qvSaving;
  }



totalprice=totalprice+price;
}
*/
chprice(totalprice,0); 
}


function calcq(num) {
obj=eval("ranges"+num);
for (var i in obj) {
    q=eval("qtyvalue"+num);
    ((obj[i]['q']<=q)?(eval("ipr"+num+"=obj[i]['pr']")):(''))
    }
} 



function calcoptions(num) {
var optval=0;
len=eval("optionvalue"+num+".length");
for (j=1;j<len;j++) {
optcheck=eval("optionvalue"+num+"["+j+"]");
if (optcheck.indexOf('+$')!=-1) {
    optval=optval+eval(optcheck.split('(+$')[1].split(')')[0]);
 }
 else {
        if (optcheck.indexOf('-$')!=-1) {
            optval=optval+eval('-'+optcheck.split('(-$')[1].split(')')[0]);
        }
        else {
            optval=optval+0;
        }
 }
//alert("optionvalue"+num+"["+i+"]"+optcheck+"optval="+optval); 
}
return eval(optval);
}


function chprice(pr,num) {
//alert('pricetxt'+num);
if (Layer('pricetxt'+num)) {
		obj=Layer('pricetxt'+num);
		//obj2=Layer('pricetxt0');
		pr=Math.round(pr*100)/100;
		if (pr.toString().indexOf('.')!=-1) {
			pr=pr.toString().substring(0,pr.toString().indexOf('.')+3);
			if (pr.toString().split('.')[1].length==1) pr=pr+'0';
			}else{
			pr=pr+'.00';
			}
	    obj.innerHTML='$'+pr;
	//	obj2.innerHTML='$'+pr;
}
}


function makeavailable(num,state) {
    obj=eval("document.forms.multiorder.vwquantity"+num)
    obj.disabled=!state;
    ((state)?(obj.value=1):(obj.value=0))
    obj2=eval("document.forms.multiorder.vwitem"+num)
    obj2.disabled=!state;
    ((state)?(obj.value=1):(obj.value=0))

for(i=0;i<document.forms.multiorder.elements.length; i++){
obj3 = document.forms.multiorder.elements[i];

	if(obj3.name.indexOf('vwattr'+num)!=-1){
		    obj3.disabled=!state;
    ((state)?(obj.value=1):(obj.value=0))
	}

}
	
	//alert(document.forms.multiorder.elements.length)
	
}

function insertMore() {
if (moretxtvalue!='') {
    var leftPos = (screen.availWidth-900) / 2;
    var topPos = (screen.availHeight-600) / 2;
    var MoreInfo = new Object();
	txt1='<html><head><title>BeachTowelsPlus.com - Product more info</title><link rel=stylesheet href=http://site.beachtowelsplus.com/css/main.css type=text/css title="main style sheet"></head>';
    txt1=txt1+'<body marginheight=0 marginwidth=0 topmargin=0 bottommargin=0 leftmargin=0 rightmargin=0><center><table width=635 height=360 style="margin-top:20px;border:1px solid #4a4a4a;"><tr><td valign=top><img src=http://site.beachtowelsplus.com/i/logo-m.gif width=375 height=77 alt="" border=0><br>';
    txt1=txt1+'<div class="al1 bd co1 fs15 t3a2" style="padding:5px 0px 7px 0px;"><img src=http://site.beachtowelsplus.com/i/ar3.gif width=11 height=6 alt="" border=0 hspace=8>More Info<img src=http://site.beachtowelsplus.com/i/ar3.gif width=11 height=6 alt="" border=0 hspace=8></div>';
    txt1=txt1+'<img width=1 height=12><br><center><table border=0 cellpadding=0 cellspacing=0 width=600><tr><td><p style="padding:0px;margin:5px 0px;">';
    txt2='</p></td></tr></table></td></tr></table></center></body></html>';
    MoreInfo = window.open('more_info.html', 'EnlargePicture','width=663,height=395,scrollbars=yes,resizable=no,statusbar=no,location=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
    MoreInfo.document.write(txt1+moretxtvalue+txt2);
    }
else {
    alert('Your browser settings not allow to run scripts or version of your browser is old.');
    }
}