function relatedScrollStop(){
    clearTimeout(relt);
}
function relatedScroll(d){
    var it = document.getElementById('relatedScrollBox')
    if(d=='left'){i=-5}else{i=5};
    it.scrollLeft = it.scrollLeft + i;
    relt=setTimeout("relatedScroll('"+d+"')",100) 
}
function closerelatedinfo(){
document.getElementById('relatedInfo').innerHTML=' '; 
}
function relatedinfo(event,mycode){
        var nan = new String(navigator.appName)
            nan = nan.toLowerCase();
        //x=event.clientX - 290
        //y=event.clientY - 500
            if(nan.indexOf('microsoft')!=-1){
                x = 64
                y = 62 
                yt = "-59px"
                yl = "35px"
            }else{
                x = 74
                y = 69
                yt = "-68px"
                yl = "25px"
            }
        mycode = '<div style="position:absolute;top:'+yt+';left:'+yl+';"><div class=popupraisedleftblack style="height:50px;"><b class=b1></b><b class=b2></b><b class=b3></b><b class=b4></b><div class=popupboxcontent id=viewcontents style="font-family:arial;font-size:9pt;height:53px;width:150px;"><img src=images/tip.gif style=position:absolute;left:'+(x)+';top:'+(y)+';z-index:1; />'+mycode+'</div><b class=b4b></b><b class=b3b></b><b class=b2b></b><b class=b1b></b></div></div>'
        //mycode = '<div class=relatedpopup style=position:absolute;left:'+x+';top:'+y+';z-index:1;width:135px;height:30px; >'+mycode+'</div>'
        document.getElementById('relatedInfo').innerHTML=mycode; 
}

var checkoutpage = 'https://secure.culverduck.com/cart/billinginfo.asp'

function showCart(whichview)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  //alert ("Your browser does not support AJAX!");
  return;
  } 
var xmlBrowser=navigator.appName;
var url="AJAX/yourshoppingcart.asp";
url=url+"?&sid="+Math.random()
url=url+"&view="+whichview;
switch(whichview){
    case 'contents':    
    document.getElementById("yourShoppingCartContents").innerHTML = '<div id=here style="position:absolute;top:-165;left:-30;z-index:6;"></div>'
    document.getElementById("here").innerHTML = '<div class=popupraisedleftblack><b class=b1></b><b class=b2></b><b class=b3></b><b class=b4></b><div class=popupboxcontent id=viewcontents><div style=text-align:center;padding-top:20px;><img src=images/loading.gif /></div></div><b class=b4b></b><b class=b3b></b><b class=b2b></b><b class=b1b></b></div>'
    //document.getElementById("yourShoppingCartContents").style.zIndex = 20;
    //document.getElementById("yourShoppingCartContents").style.top = -120;
    //document.getElementById("yourShoppingCartContents").style.left = 205;
    xmlHttp.onreadystatechange=stateChangedContents;
    break;
    case 'normal': xmlHttp.onreadystatechange=stateChanged;
    break;
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 
function stateChanged() 
{ 
    if (xmlHttp.readyState==4)
    { 
        document.getElementById("yourShoppingCart").innerHTML=xmlHttp.responseText;
    }
}
function stateChangedContents() 
{ 
    if (xmlHttp.readyState==4)
    { 
        document.getElementById("viewcontents").innerHTML=xmlHttp.responseText;
    }
}
function numbers(type,you){
    var capture
    var key
    if(type=='qty'){
        var indexof = new String("0123456789");
        you.maxLength = 3;
    }
	if(type=='cvv2'){
        var indexof = new String("0123456789");
        you.maxLength = 4;
    }
    if(type=='ext'){
        var indexof = new String("0123456789#*");
        you.maxLength = 6;
    }
    if(type=='phone'||type=='zip'){
        var indexof = new String("0123456789-");
        if(type=='phone'){
            you.maxLength = 12;
            }else{
            you.maxLength = 10;
            }
    }
    if(type=='email'){
        var indexof = new String("abcdefghijklmnopqrstuvwxyz0123456789_.@");
        you.maxLength = 255;
    }
    if(type=='card'){
        var indexof = new String("0123456789");
        you.maxLength = 16;
    }
    capture = window.event.keyCode;
    key = String.fromCharCode(capture);
    if(indexof.indexOf(key)!=-1){
        if(type=='phone'){
            var where;
            var thisinfo;
            var whereat;
            thisinfo = you.value + key;
            where = new String(thisinfo);
            whereat = where.length;
                if(whereat==4||whereat==8){
                    if(!(key=='-')){
                    you.value = you.value + '-';
                    }
                }else{
                    if(key=='-'){
                    return false;
                    }
                }
        }
        if(type=='email'){
            var where;
            var thisinfo;
            var whereat;
            thisinfo = new String(you.value);
            if(key=='@'){
                if(thisinfo.indexOf('@')!=-1){
                    return false;
                }
                if(thisinfo.length==0){
                    return false;
                }
            }
        }
        if(type=='zip'){
            var where;
            var thisinfo;
            var whereat;
            thisinfo = you.value + key;
            where = new String(thisinfo);
            whereat = where.length;
                if(whereat==6){
                    if(!(key=='-')){
                    you.value = you.value + '-';
                    }
                }else{
                    if(key=='-'){
                        return false;
                    }
                }
        }
        }else{
            return false;
        }
    }
//highlight
function highlightCategory(t,c,e){
    if(e.type=='mouseover'){
        t.style.backgroundColor=c;
    }else{
        t.style.backgroundColor=c;
    }
}
function highlightMe(t,o){
    var x = new String(t.className);
    if(o=='off'){
        if(x.indexOf('over')!=-1){
            t.className = x.replace('over','');
        }
    }
    if(o=='on'){
        if(x.indexOf('over')==-1){
            t.className = t.className+'over';
        }
    }
}
function highlight(id,color,color2,alph){
    //document.getElementById('productTable_'+id).style.borderColor = color;
    if(document.getElementById('productTable_'+id)){
        document.getElementById('productTable_'+id).style.borderColor = color;
    }
}

function orderlight(id,color){
    document.getElementById('bt1_'+id).style.color = color;
}

//cart
function home(){
	location.href=" ";
}

function generate_click(where){
    var addme;
    var gohere;
        addme = document.getElementById('gotopage').value;
        gohere = where + '&pgnum=' + addme;
        location.href = gohere;
}

//search
function searchme(){
    document.search.action='/search/searchCranberryBarn.asp';
    document.search.method='get';
    document.search.zoom_query.value=document.getElementById('products_zoom_query').value;
	document.search.submit();
}

function searchmeCart(){
    document.searchCart.action='/search/searchStore.asp';
    document.searchCart.method='get';
    document.searchCart.zoom_query.value=document.getElementById('products_zoom_query').value;
    document.searchCart.submit();
}

function clearProductSearch(t,v){
    if(t.value==v){
        t.value='';
    }
}

function searchover(color){
    document.getElementById('go').style.color=color;
}

//options
function change(t){
    var y = document.getElementsByTagName('div')
    for(i=0;i<=y.length;i++){
        if(y[i]==t){
            var z = new String(y[i+1].className);
            if(z.indexOf('over')!=-1){
                z = z.replace('over','');
                y[i+1].className = z;
            }else{
                y[i+1].className = z + 'over';
            }
        }
    }
}
function change2(t,c,tc,fid,fclass){
    document.getElementById('optionName'+c).value=t.value;
    h = document.getElementsByName('hidOption_'+fid)[tc].value;
    d = document.getElementById('optionValue'+c);
    d.value = h;
    var v = document.getElementsByName('option'+c);
        var y = document.getElementById('optionDiv'+c);
        var z = new String(y.className);
        if(z.indexOf('over')!=-1){
            z = z.replace('over','');
            y.className = z;
        }else{
            y.className = z + 'over';
        }
        return optCount(fid,fclass);
        return true;
}
function optCount(fid,fclass){
    oc = document.getElementById('optionCount_'+fid);
    oz = document.getElementById('optionValue_'+fid);
    for(i=1;i<=oc.value;i++){
    ov = document.getElementById('optionValue'+i+'_'+fid);
        if(i==1){
            if(ov.value!=''){
                oz.value = ov.value;
            }else{
                oz.value = 0;
            }
        }
        if(i!=1){
            if(ov.value!=''){
                oz.value = oz.value +'*'+ ov.value;
            }else{
                oz.value = oz.value +'*'+ 0;
            }
        }
    }
   // alert(oz.value);
   //document.frmSubmit.optionValue.value = oz.value
   document.getElementById('optionValue'+fid).value = oz.value
   if(fclass=='small'){
   AddProduct(fid,'','','categoryoption');
   }
//   alert(document.frmSubmit.optionValue.value)
    return true;
}
function change3(){
    var d = document.getElementsByTagName('div')
    for(i=0;i<d.length;i++){
        var n = new String(d[i].className);
        if(n=='divxover'){
            d[i].className='divx';
        }
    }
}
function hideselect(fid,ftype){
		if(document.getElementById(fid)){
			if(document.getElementById(fid).className!='divx'+ftype){
				 document.getElementById(fid).className='divx'+ftype;
			}
		}
}

function hideoptions(t,fid,ftype){
	var selectdelay = 200;
	setTimeout("hideselect('"+fid+"','"+ftype+"')",selectdelay);
}
function AddOptions(fid,fcode,event){
    if(document.getElementById('lastclicked').value!='0'){
        CloseOptions(document.getElementById('lastclicked').value);
    }
    if(AddProduct(fid,'','','category')==false){
        x=document.getElementById('raised_'+fid).offsetLeft + 540
        y=document.getElementById('raised_'+fid).offsetTop - 73
        fcode = '<div style=position:absolute;left:'+x+';top:'+y+';z-index:6; >'+fcode+'</div>'
        document.getElementById('optinsert').innerHTML=fcode;
        document.getElementById('lastclicked').value = fid;
    }
}
function CloseOptions(fid){
    //myreplace = String(document.getElementById('mainOptionDivId_'+fid).innerHTML)
    //myreplace = myreplace.replace(/"/ig, "\&quot;");
    //myreplace = myreplace.replace(/'/ig, "\\'");
    //document.getElementById('mainOptionDivId_'+fid).onclick=function(){AddOptions(fid,myreplace);};
    //alert(document.getElementById('mainOptionDivId_'+fid).onclick)
    document.getElementById('mainOptionDivId_'+fid).style.width='0';
    document.getElementById('mainOptionDivId_'+fid).style.height='0';
    document.getElementById('mainOptionDivId_'+fid).style.border='0';
    document.getElementById('mainOptionDivId_'+fid).style.position='relative';
    document.getElementById('mainOptionDivId_'+fid).style.top='50px'
    document.getElementById('mainOptionDivId_'+fid).innerHTML='';   
    document.getElementById('optionValue'+fid).value = '';
    }
//checkout
var changesmade = false;
function AddProduct(item,iwidth,iheight,ipage){
    var cont = true;
    if(document.getElementById('optionValue'+item)){
        //var x = document.frmSubmit.optionValue;
        var x = document.getElementById('optionValue'+item)
        if(x.value!=''){
            y = new String(x.value);
            if(y!='0'){
                if(y.indexOf('*')!=-1){
                    z = y.split('*');
                    for(i=0;i<z.length;i++){
                        if(z[i]=='0'){
                            cont = false;
                        }
                    }
                }
            }else{
                cont = false;
            }
        }else{
            cont = false;
        }
    }
    if(cont==true){
        if(ipage!='categoryoption'){
        if(document.getElementById('optionValue'+item)){
        document.frmSubmit.optionValue.value = document.getElementById('optionValue'+item).value;
            if(ipage=='category'){
            document.getElementById('optionValue'+item).value='';
            }
        }
	    document.frmSubmit.productid.value = item;
	    document.frmSubmit.submit();
	    }else{
	    document.getElementById('hidoptionadd_'+item).innerHTML = '<div class="divoptionadd" onclick="AddProduct(\''+item+'\',\'\',\'\',\'category\');"><img src="images/addtocartsm.gif" /></div>' ;
	    }
	}else{
	    //document.getElementById('optionMessage').innerHTML='Please Select Product Options';
	    //document.getElementById('arrowLeftDown').style.visibility='visible';
		    if(iwidth){
		        document.getElementById('arrowRightDown').width=iwidth;
		    }
		    if(iheight){
		        document.getElementById('arrowRightDown').height=iheight;
		        document.getElementById('arrowRightDown').src='images/arrow2.gif';
		        document.getElementById('arrowRightDown').style.visibility='visible';
		        document.getElementById('mainOptionDivId_'+item).className='mainOptionDivRed';
		        document.getElementById('divId').className='divRed';
		        document.getElementById('optionName1_'+item).className='trxshortRed';
		    }else{
		        if(document.getElementById('mainOptionDivId_'+item)){
		        document.getElementById('mainOptionDivId_'+item).className='mainOptionDivRed';
		        //document.getElementById('divId').className='divRed';
		        //document.getElementById('optionName1').className='trxshortRed';
		        }
		    }
	    return false;
	}
}
function fViewCart(){
    document.frmSubmit.action.value = 'view';
    document.frmSubmit.submit();
}
function swapaddtocart(o,t){
    if(o=='off'){
        t.src = '/cart/addtocartdown.jpg';
    }
    if(o=='on'){
        t.src = '/cart/addtocartup.jpg';
    }
}
function changeOption(element) {
	if(element.value!=""){
	    window.location.href="changeOption.asp?a="+element.value;
	}
}
function Recalculate(form){
	var formlen = eval("document."+form+".length;");
	var namearray = new Array();
	var valuearray = new Array();
	var optarray = new Array();
	var optpricearray = new Array();
	var arraycount = -1;
	for(var i=0;i<formlen;i++){
		var tempname = eval("document."+form+".elements[i].name;");
		var tempvalue = eval("document."+form+".elements[i].value;");
		if(tempname.indexOf("id:")!=-1 && parseInt(tempvalue)!=0 && tempvalue!=''){
		var optvalue = eval("document."+form+".elements[i+1].value;");
		var optprice = eval("document."+form+".elements[i+2].value;");
			arraycount++;
			namearray[arraycount] = tempname;
			valuearray[arraycount] = tempvalue;
			optarray[arraycount] = optvalue;
			optpricearray[arraycount] = optprice;
		}
	}
	if(arraycount==-1){
		alert("You do not have any items in your shopping cart.");
	}
	else{
		document.shoppingcart.productid.value = namearray;
		document.shoppingcart.productquantity.value = valuearray;
		document.shoppingcart.optionValue.value = optarray;
		document.shoppingcart.optionPrice.value = optpricearray;
		document.shoppingcart.action.value = 'recalculate';
		document.shoppingcart.submit();
	}
}
function RemoveItem(form,id){
	var cont = window.confirm('Remove this item from shopping cart?');
	if(cont){
		var formlen = eval("document."+form+".length;");
		var namearray = new Array();
		var valuearray = new Array();
		var cardarray = new Array();
		var optarray = new Array();
		var optpricearray = new Array();
		var arraycount = 0;
		for(var i=0;i<formlen;i++){
			if(document.productlist.elements[i].name=="OrderID" && document.productlist.elements[i].value!=id){
				namearray[arraycount] = eval("document."+form+".elements[i+1].name;");
				valuearray[arraycount] = eval("document."+form+".elements[i+1].value;");
				optarray[arraycount] = eval("document."+form+".elements[i+2].value;");
				optpricearray[arraycount] = eval("document."+form+".elements[i+3].value;");
				arraycount++;
			}
			if(document.productlist.elements[i].value==id){
			    
			}
		}
		document.shoppingcart.productid.value = namearray;
		document.shoppingcart.productquantity.value = valuearray;
		document.shoppingcart.optionValue.value = optarray;
		document.shoppingcart.optionPrice.value = optpricearray;
		document.shoppingcart.action.value = 'recalculate';
		document.shoppingcart.submit();
	}
}

function ContinueShopping(){
	window.location.href = document.getElementById('x_refer').value;
}

function CheckOut(form){
	if(changesmade){
		var cont = window.confirm("Do you want to recalculate changes made?")
		if(cont){Recalculate('productlist');}
	}
	var formlen = eval("document."+form+".length;");
	var namearray = new Array();
	var valuearray = new Array();
	var optarray = new Array();
	var optpricearray = new Array();
	var arraycount = -1;
	for(var i=0;i<formlen;i++){
		var tempname = eval("document."+form+".elements[i].name;");
		var tempvalue = eval("document."+form+".elements[i].value;");
		var optvalue = eval("document."+form);
		var optpricearray = eval("document."+form);
		if(tempname.indexOf("id:")!=-1 && parseInt(tempvalue)!=0){
			arraycount++;
			tempname = new String(tempname);
			tempname = tempname.replace('id:','');
			namearray[arraycount] = tempname;
			valuearray[arraycount] = tempvalue;			
			if(optvalue.hidopt[arraycount]){
			optarray[arraycount] = optvalue.hidopt[arraycount].value;
			}else{
			optarray[arraycount] = optvalue.hidopt.value;
			}
			//optpricearray[arraycount] = optpricearray.hidoptprice[arraycount].value;
		}
	}
	if(arraycount==-1){
		alert("You do not have any items in your shopping cart.");
	}
	else{
		document.formCheckOut.productId.value = namearray;
		document.formCheckOut.productQuantity.value = valuearray;
		document.formCheckOut.optionValue.value = optarray;
		document.formCheckOut.presubtotal.value = document.productlist.subtotal_amount.value;
		document.formCheckOut.refer.value = document.getElementById('x_refer').value;
		document.formCheckOut.action = checkoutpage;
		document.formCheckOut.submit();
	}
}
