var reqObj;
var _cookieName='BFVisitor';
var _url = 'http://sites.bridgevine.com/VisitHandler.ashx';
var _searchRequestUrl = 'https://cart.bridgevine.com/searchrequest.aspx';
var _partnerID = 146;
var _visitField = 'VisitID';
var _visitID;
var _visitIDElement;
var _dateLoaded = '2/9/2010 5:08:31 AM';
var _zip='';
var _streetAddress1='';
var _streetAddress2='';
var _city='';
var _state='';
var _promoCode='';
var _sid;
if(document.addEventListener){document.addEventListener('DOMContentLoaded', page_OnLoad, false);}else if(window.attachEvent){window.attachEvent('onload', page_OnLoad);}else if(window.addEventListener){window.addEventListener('load', page_OnLoad, false);}
function readCookie(cookieName){var name = cookieName + "=";var cookieString = document.cookie.split(';');for(var i=0;i<cookieString.length;i++){var cookie = cookieString[i];while (cookie.charAt(0)==' ') cookie = cookie.substring(1, cookie.length);if (cookie.indexOf(name) == 0) return cookie.substring(name.length,cookie.length);}return null;}
function createCookie(cookieName,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = cookieName+"="+value+expires+"; path=/";}
function eraseCookie(cookieName){createCookie(cookieName,"",-1);}
function page_OnLoad(){
	_visitID = 0;
	var cookie = readCookie(_cookieName);
	var url = _url;
	if(cookie == null){
		url += '?callback=registerVisit&PartnerID=146';
		var qs = window.location.search;
		if(document.referrer){
			qs += '&refer=' + document.referrer;
		}
		else if( window.opener && window.opener.location){
			try{qs += '&refer=' + window.opener.location;}catch(e){}
		}
		if(qs.length > 0){url += '&' + qs.substring(1, qs.length);}
		reqObj = new bvJSONscriptRequest(url);reqObj.buildScriptTag();reqObj.addScriptTag();
	}
	else{
		_visitID = cookie;
	}
	refreshVisitIdElement();
}
function registerVisit(visitID, sid){_sid=sid;_visitID = visitID;createCookie(_cookieName, visitID, 0);reqObj.removeScriptTag();var VisitID = document.getElementById(_visitField);if(VisitID){VisitID.value=visitID;}refreshVisitIdElement();}
function registerVisitIdElement(visitIdElement){_visitIDElement=visitIdElement;if(_visitID>0){_visitIDElement.innerHTML=_visitID;}}
function refreshVisitIdElement(){if(_visitIDElement){_visitIDElement.innerHTML=_visitID;}}
function registerStreetAddress(streetAddress1){_streetAddress1 = streetAddress1;}
function registerZipCode(zipCode){_zip = zipCode;}
function registerAddress(streetAddress1,streetAddress2, city, state, zipCode){_streetAddress1=streetAddress1;_streetAddress2=streetAddress2,_city=city;_state=state;_zip=zipCode;}
function registerPromoCode(code){_promoCode = code;}

function buildurl(flowtype,productid,verticaltypeid,productcategoryid)
{
	var searchUrl =				_searchRequestUrl + '?FlowType='+ flowtype +'&IsSignatureNew=True';
    if(_visitID != '')			searchUrl += '&VisitID='+_visitID;
    if(_partnerID != '')		searchUrl += '&PartnerID='+_partnerID;
	if(productid != '')			searchUrl += '&ProductID='+productid;
	if(verticaltypeid != '')	searchUrl += '&VerticalType='+verticaltypeid;
	if(productcategoryid != '')	searchUrl += '&ProductCategory='+productcategoryid;
	if(_streetAddress1 != '')	searchUrl += '&StreetAddress1='+_streetAddress1;
	if(_streetAddress2 != '')	searchUrl += '&StreetAddress2='+_streetAddress2;
	if(_city != '')				searchUrl += '&City='+_city;
	if(_state != '')			searchUrl += '&State='+_state;
	if(_zip != '')				searchUrl += '&Zip='+_zip;
	if(_promoCode != '')		searchUrl += '&PromoCode='+_promoCode;
	if(_sid != ''){
		searchUrl += '&SID=' + _sid;
		var visitCookie = readCookie(_cookieName);
		if(visitCookie){
			eraseCookie(_cookieName);
			createCookie(_cookieName + '_' + _sid, _visitID,'');
		}
	}
    return searchUrl;
}

function jumpToUrl(url){document.location.href=url;}
function shopProduct(productid){jumpToUrl(buildurl("Shop",productid,"",""));}
function buyProduct(productid){jumpToUrl(buildurl("Buy",productid,"",""));}
function checkoutProduct(productid){jumpToUrl(buildurl("Checkout",productid,"",""));}
function shopProductCategory(productcategoryid){jumpToUrl(buildurl("Shop","","",productcategoryid));}
function buyProductCategory(productcategoryid){jumpToUrl(buildurl("Buy","","",productcategoryid));}
function buyVertical(verticaltypeid){jumpToUrl(buildurl("Buy","",verticaltypeid,""));}
function shopVertical(verticaltypeid){jumpToUrl(buildurl("Shop","",verticaltypeid,""));}

function productResponse(result){if(result.length > 0 && result.indexOf('http') == 0){document.location = result;}}

// jsr_class.js
// JSONscriptRequest -- a simple class for making HTTP requests
// using dynamically generated script tags and JSON
// Author: Jason Levitt
// Date: December 7th, 2005
function bvJSONscriptRequest(fullUrl) {
    this.fullUrl = fullUrl; 
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    this.headLoc = document.getElementsByTagName('head').item(0);
    this.scriptId = 'JscriptId' + bvJSONscriptRequest.scriptCounter++;
}
bvJSONscriptRequest.scriptCounter = 1;
bvJSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement('script');
    
    // Add script object attributes
    this.scriptObj.setAttribute('type', 'text/javascript');
    this.scriptObj.setAttribute('charset', 'utf-8');
    this.scriptObj.setAttribute('src', this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute('id', this.scriptId);
}
bvJSONscriptRequest.prototype.removeScriptTag = function () {this.headLoc.removeChild(this.scriptObj);}
bvJSONscriptRequest.prototype.addScriptTag = function () {this.headLoc.appendChild(this.scriptObj);}


if(typeof(Sys) !== "undefined")Sys.Application.notifyScriptLoaded();