

 //doubleclick
var axel = Math.random() + "";
var ord = axel * 1000000000000000000;
 //end doubleclick

function goTo(strLoc, popup){	
    var dest = '';
    if (strLoc.substring(0,1) == '/')
  	    dest = "http://" + window.location.host + strLoc;		
    else
  	    dest = strLoc;		

    if (popup) {
        n = window.open(dest, 'n', 'width=780,height=555,location=yes,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	    n.focus(); 
    } else {
  	    window.parent.location = dest;
    }
    
}

function swapClass(id, className){
    var obj = document.getElementById(id);
    obj.className = className;
}


//##REGION GENERICHEADER.ASCX
function submitManufacturerSelect(strFormItemName){
	document.location = "/" + document.getElementById(strFormItemName).value + ".aspx";
}
function submitPriceSelect(strFormItemName){
	var objValue = document.getElementById(strFormItemName).value;
	document.location = "/search.aspx?price=" + objValue;
}
function submitUse(strFormItemName){
	var objValue = document.getElementById(strFormItemName).value;
	document.location = "/search.aspx?category=" + objValue;
}
//#ENREGION



function changeVehicle(thisvehicle,thiscompetitor, competitors){
	loc = "/changevehicle.aspx?id=" +thisvehicle + "&comp=" + thiscompetitor + "&competitors=" + competitors;
	height= 100;
	width=300;
	window_options = "'toolbar=no,location=no,buttons=no;directories=no,status=no,menubar=no,toolbar=no,resizable=no,scrollbars,copyhistory=yes,height=" + height + ",width=" + width + ",screenX=100,screenY=400'";
	nwn = window.open(loc,"myVehicleSelect",window_options);
	nwn.focus();
	
}
function selectModel(){
	var obj = document.getElementById("oModelSelect");
	document.location = obj.value;
}



function submitEmail(){
	var obj = document.getElementById("frm_strEmail");
	if(isEmail(obj.value) && obj.value.length > 0){
		document.location = "/emailsignup.aspx?email=" + obj.value;
	}else{
		alert("Please enter a valid e-mail address.");
		obj.focus();
	}

}
function submitInfo(){
	var obj = document.getElementById("frm_strInfoEmail");
	var obj2 = document.getElementById("frm_strInfoMake");
	var obj3 = document.getElementById("frm_strName");
	
	if(isEmail(obj.value) && obj2.value.length > 0 && obj3.value != "Enter your name."){
		document.location = "/Thankyou.aspx?action=submit&name=" + obj3.value + "&make=" +  obj2.value+ "&email=" + obj.value;
	}else{
		if(! isEmail(obj.value)){
			alert("Please enter a valid e-mail address.");
			obj.value = "";
			obj.focus();
			return;
		}
		if(obj2.value.length <= 0){
			alert("Please select a make.");
			obj2.focus();
			return;
		}		
		if(obj3.value == "Enter your name."){
			alert("Please enter your name.");
			obj3.focus();
			return;
		}

		if((obj.value.length <=0)){
			alert("Please enter a valid e-mail address.");
			obj.value = "";
			obj.focus();
			return;
		}

	}

}


function isEmail (sEmail) {
	var regEmail = /^([\w-]+\.?)*\w+@([\da-zA-z-]+\.)+[a-zA-z]{2,3}$/
	if (sEmail==null || sEmail == "") { 
		if (isEmail.arguments.length == 1) return true;
	else {return (isEmail.arguments[1] == true);}
	} else {
	return regEmail.test(sEmail)
	}
}

function isValidRegex(ele,sExpr) {
    var bResult = false;
    if (ele && sExpr) {
        if (sExpr.text(ele.value)) {
            bResult = true;
            document.getElementById(ele.id + "_regex").style.display = "block";
        }
        else
            bResult = false;
    }
    return bResult;
}


function submitZip(){
	var obj = document.getElementById("frm_strZip");
	var obj2 = document.getElementById("frm_Manufacturers");
	
	if(obj2.value.length <= 0){
		alert("Please select a manufacturer.");
		obj2.focus();
		return;
	}
	 if(isZip(obj.value) && obj.value.length > 0){
		document.location = "/dealers.aspx?zip=" + obj.value + "&id=" + obj2.value;
	}else{
		alert("Please enter a valid zip code.");
		obj.focus();
	} 
}

function findDealersShort(sEle,nId){
	var ele = document.getElementById(sEle);		
	if(isZip(ele.value) && ele.value.length > 0){
		document.location = "/dealerssearchresult.aspx?zip=" + ele.value + "&make=" + nId;
	}else{
		alert("Please enter a valid zip code.");
		ele.focus();
	} 
}



function submitMake(){
	var obj = document.getElementById("frm_strMake");
	if(obj.value.length <= 0){
		alert("Please select a make.");
		obj.focus();
	}else{
		document.location = "/make.aspx?id=" + obj.value;
	}
	
}

function isZip(sZip) {
    if (sZip.indexOf('-') >=0 ) {
        regexp = /^\d{5}-\d{4}$/
    } else {
        regexp = /^\d{5}$/
    }
    return regexp.test(sZip);
}

function setSelectBoxValue(strSelectID, strValue){
    var obj = document.getElementById(strSelectID);
    obj.value = strValue;
}

function getQueryStringValue(queryStringName) {
		var value = "";
		var qsName = queryStringName + "=";
		var theURL = new String(document.URL);
		var startValue = 0;
		var endValue = 0;
		
		var remainStr = "";
		
		//check to see if the queryStringName is in the url
		if (theURL.indexOf(qsName) > -1) {
			startValue = theURL.indexOf(qsName) + qsName.length;
		}
		
		remainStr = theURL.substring(startValue);
		
		if(remainStr.indexOf("&") > -1) {
			endValue = remainStr.indexOf("&");
		} else {
			endValue = remainStr.length;
		}
		
		if(endValue > 0) {
			if(remainStr.substring(0,endValue) == theURL){
			return "";
			
			}else{
			return remainStr.substring(0,endValue);
			}
		} else {
			return "";
		}
	}	


 function roll(ele) {
	var img = ele.getElementsByTagName("img")[0];
	var src = img.src;
	img.src = (/_on/.test(src)) ? src.replace('_on', '_off') : src.replace('_off', '_on');
}

function createflash(width, height, swfname, flashvars, sbghex, wmode, connection){
		if (typeof(sbghex)=="undefined") sbghex="ffffff";
		if (typeof(wmode)=="undefined") wmode="";
		if (connection!="https") connection="http";		
	
		document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"" + connection + "://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"start\" align=\"middle\" VIEWASTEXT>");
		document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
		document.write("<param name=\"movie\" value=\"" + swfname + "\" />");
		document.write("<param name=\"FlashVars\" value=\"" + flashvars + "\" />");
		document.write("<param name=\"quality\" value=\"best\" />");
		document.write("<param name=\"bgcolor\" value=\"#" + sbghex + "\" />");
		document.write("<param name=\"menu\" value =\"false\" />");
		document.write("<param name=\"wmode\" value =\"" + wmode + "\" />");
		document.write("<embed name=\"start\" SWLIVECONNECT=\"true\" src=\"" + swfname + "\" FlashVars=\"" + flashvars + "\" quality=\"best\" bgcolor=\"#" + sbghex +"\" width=\"" + width +"\" height=\"" + height + "\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"" + connection + "://www.macromedia.com/go/getflashplayer\" wmode=\"" + wmode + "\" />");
		document.write("</object>");
}


var arQsParm = new Array();
function getQueryString() {
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
	   var pos = parms[i].indexOf('=');
	   if (pos > 0) {
	      var key = parms[i].substring(0,pos);
	      var val = parms[i].substring(pos+1);
	      arQsParm[key] = val;
	      }
	   }
}

 function openRate(strURL) {
    window.open(strURL,'rt','width=650,height=700,scrollbars=yes,resizable=yes');           
 }
	   	
function submitSearch(){
    var man = document.getElementById("frm_strSearchReviews").value;
    if(man.length > 0) {
       document.location = "/motorcycle-reviews.aspx?make=" + man;
    }
    else {
       alert("Please choose a manufacturer");     
    }
}

function OpenWindow(strURL, strTarget, strOptions){
    if(strTarget=="new"){
      window.open(strURL,"mywindow",strOptions);
    }else{
      document.location = strURL;
    
    }
} 

function Search(){
    var obj;
    if ( obj = document.getElementById("ctl00_globalNav_TextBox1"))
		document.location = "/search.aspx?q=" + obj.value;
}

function doMetrics(sTarget) {
    //urchinTracker(sTarget);
    if (typeof(pageTracker)!="undefined" && pageTracker!=null)
        pageTracker._trackPageview(sTarget);
    
}

var session;
var oComp;

function oCompareBox() {
    this.smallCountText = document.getElementById("compareBoxCount");
    this.bigBox = document.getElementById("compareBox");
    session = new CJL_CookieUtil("session_cookie",null,"/");
    
       
    this.getCookies = function() {
        return session.getSubValue("cmp");
    }
    
    this.cookieStr = "";
    this.arr = null;
    
    this.getCount = function() {
        var nCount = 0;
        
        this.cookieStr = this.getCookies();
        
        if(this.cookieStr!=undefined) {
            this.arr = this.cookieStr.split(",");
            nCount = (this.arr)? this.arr.length : 1;
        }
        return nCount;
    }
    this.setCounterText = function(nCount) {
        this.smallCountText.innerHTML = nCount;
    }
    
    this.count = this.getCount();
      
    this.setCounterText(this.count); 
    
    this.addToCompare = function(nId) {
        this.cookieStr = this.getCookies();
        this.count = this.getCount();
        
        var sTrack = '/addtocompare/'+nId;
        if (this.cookieStr==undefined) {
            session.setSubValue("cmp", nId);
			doMetrics(sTrack);
        }    
        else {
            if (this.cookieStr.indexOf(nId)!= -1) 
              alert("You've already added this Bike in your Compare Box!");
            else {                
                if (this.count==3)
                    alert("You can have up to 3 bikes in your Compare Box!");
                else {
                    session.setSubValue("cmp", this.cookieStr + "," + nId);    
					doMetrics(sTrack);
				}	
           }
        }    
        
        this.setCounterText( this.getCount());      
    }
    
    this.cleanBox = function() {
        session.setSubValue("cmp","");
        this.setCounterText( this.getCount()); 
    }
    
    
    this.finalH = 310;
    this.finalW = 450;
    this.hStep = 10;
    this.heightR = this.finalH/this.hStep;
    this.wStep = this.finalW/this.heightR;
    this.height=0;
    this.width=0;    
    
    var nL = getPageSize()[0]/2 - this.finalW/2;
    this.bigBox.style.left = nL + "px";     
        
    this.openBigBox = function() {
       screenOff();
       this.bigBox.style.display = "block"; 
       this.growBox();    
    }
    
        
    this.growBox = function() {
        if (this.height>=this.finalH) {
            this.renderBox();
            
            document.getElementById("hideCompareBox").style.display = "block";
			//if (document.getElementById("dbl_1_2"))	{document.getElementById("dbl_1_2").style.visibility = "hidden";}
            return;
        }
          
        this.bigBox.style.height =  this.height + "px";
        this.bigBox.style.width = this.width + "px";
        
        this.height += this.hStep;
        this.width += this.wStep; 
        
        setTimeout("oComp.growBox()",5);
    }
    
    
    this.closeBigBox = function() {
        if (this.height<=0) {
            this.height=0;
            this.width=0;
            this.bigBox.style.height =  this.height + "px";
            this.bigBox.style.width = this.width + "px";
                   
            this.bigBox.style.display = "none";
            screenOn();   
            return;
        }
        document.getElementById("hideCompareBox").style.display = "none";  
		//if (document.getElementById("dbl_1_2"))	{document.getElementById("dbl_1_2").style.visibility = "visible";}
        this.bigBox.style.height =  this.height + "px";
        this.bigBox.style.width = this.width + "px";
        
        this.height -= this.hStep;
        this.width -= this.wStep; 
        
         setTimeout("oComp.closeBigBox()",5);
    }
    
    this.renderBox = function() {
        var strResult = '<br><table cellpadding="0" cellspacing="0" border=0 width="95%" class="font">';
        var strImage = "";
        var strId = ""; 
        var arr;
        var nCount = this.getCount();
       
       if ( nCount >= 1) {
            for (var i=0; i<this.arr.length;++i) {
                arr = this.arr[i].split("/");
                strId = arr[3];
                arr[3] = "hero_thumb.jpg";
                
                strImage = "/images/photogallery/" + arr.join("/");
               
                strResult += '<tr valign=middle><th class="compareBoxTd" width=15>' + (i+1) + '</th><td width=90 class="compareBoxTd"><img src="' + strImage +'" /></td><td class="compareBoxTd" width=200>' + arr[1] + ' ' + arr[0] + ' ' + arr[2] + '</td><td class="compareBoxTd"><a href="javascript:oComp.removeBike(' + i + ')">Remove this Bike from Compare Box</a></td></tr>\n';                  
            }    
       }
       else
            strResult += "<tr valign=middle><th class='compareBoxTd'>You have not choosen bikes to compare!</th></tr>";
       
       strResult += "</table>";
               
        document.getElementById("compareBoxContent").innerHTML = strResult;     
    }
        
    this.removeBike = function(nArrId) {
        this.arr.splice(nArrId,1);
        
        session.setSubValue("cmp",this.arr.join(","));
        this.setCounterText( this.getCount()); 
         
        this.renderBox();        
    } 
    
    this.compareBikes = function() {
		if (this.getCount()>1) {
			setTimeout("parent.document.location = '/CompareATV.aspx'",1);
        }
        else {
            alert("You need to have at least 2 atv in your Compare Box!");
        }
    }    
       
}

var oRecentViewed;

function oViewed() {
    this.cookieStr = "";
    this.arr = null;
       
    
    this.cookies = new CJL_CookieUtil("rec_viewed",100000,"/");
      
    this.getCookies = function() {
        return this.cookies.getSubValue("vwd");
    }
          
    this.getCount = function() {
        var nCount = 0;
        
        this.cookieStr = this.getCookies();
               
        if(this.cookieStr!=undefined) {
            this.arr = this.cookieStr.split(",");
            nCount = (this.arr)? this.arr.length : 1;
        }
        return nCount;
    }  
           
    
    this.addViewed = function(nId) {
       this.count = this.getCount();
            
       if (this.count==0) {    
			this.cookies.setSubValue("vwd", nId);
        }    
        else {
            if (this.cookieStr.indexOf(nId)!= -1) {
              //alert("You've already added this Bike in your cookies!");
            }
            else {                
                if (this.count==5) {
                    this.arr.shift();
                }
                this.arr.push(nId);   
                this.cookies.setSubValue("vwd", this.arr.join(","));    
           }
        }    
                
    }
    
     this.renderBox = function() {
        var strResult = '<ul>';
        var strLink = "";
        var arr;
        var nCount = this.getCount();
      
       if ( nCount >= 1) {
            for (var i=0; i<this.arr.length;++i) {
                arr = this.arr[i].split("/");
                strLink = "/atv/" + arr[0] + "/" + arr[1] + "/" + arr[2].replace(/\s/g,"-") + ".aspx?id=" + arr[3];
             
                strResult += '<li><a href="' + strLink + '" onclick="doMetrics(\'/recentlyviewed' + strLink + '\');"  class="linkblue">' + arr[1] + ' ' + arr[0] + ' ' + arr[2] + '</a></li>\n';                  
            }    
       }
       else
            strResult += "</ul>";
        
        return strResult;              
    }
    
    this.bViewedOpen = false;        
    this.open = function(ele) {
        var oRWB = document.getElementById("recentViewedBox");
        
        if (!this.bViewedOpen) {
            document.getElementById("recentViewedContent").innerHTML = this.renderBox();
            
            var oTrgPos = findPos(document.getElementById("recentViewedLink"));
            var nL = oTrgPos[0]
            var nT = oTrgPos[1]
            
            oRWB.style.left = nL -56+ "px";
            oRWB.style.top = nT + 30 + "px";
            
            oRWB.style.display = "block";
                      
            document.getElementById("vwdimg").innerHTML = "(-)";
            this.bViewedOpen = true;        
        }
        else {
            document.getElementById("vwdimg").innerHTML  = "(+)";
            oRWB.style.display = "none";
            this.bViewedOpen = false;        
        }
    }
       
    if (typeof strVeh != 'undefined') {
       this.addViewed(strVeh);
    }
}
function screenOff() {
     document.getElementById("ie6iframe").style.display = "block";
     document.getElementById("mainBodyCover").style.display = "block";
}
function screenOn() {
    document.getElementById("mainBodyCover").style.display = "none";
    document.getElementById("ie6iframe").style.display = "none";  
}

function initMain() {
   oComp = new oCompareBox();
   oRecentViewed = new oViewed();   
  
}

function rollNav(ele) {
    var strClass = ele.className;
    strClass = (/_on/.test(strClass)) ? strClass.replace('_on', '_off') :strClass.replace('_off', '_on');
    ele.className = strClass;
  
}

var oSubnav, oSubParent;

function rollSub(eleName,oParent,ev) {
    var oSub = document.getElementById(eleName);
    
    var coors = findPos(oParent);
    oSub.style.top = (coors[1]) + 'px';
    oSub.style.left = (coors[0]+158) + 'px';
    
    if (!oSub.style.display || oSub.style.display=="none") {
        oSub.style.display="block";
        oSubnav = oSub;
        oSubParent = oParent;
    }
    else if (isMouseInOrOut(ev, oSub))
        oSub.style.display="none";
}
function subAreaOut(ev,ele) {
    if (isMouseInOrOut(ev, ele))
        ele.style.display="none";
}

function subAreaOver(ele) {
}

function isMouseInOrOut(ev, ele) {
	if (ev.type != 'mouseout' && ev.type != 'mouseover') return false;
	var reltg = ev.relatedTarget ? ev.relatedTarget :
	ev.type == 'mouseout' ? ev.toElement : ev.fromElement;
	while (reltg && reltg != ele) reltg = reltg.parentNode;
	return (reltg != ele);
}


function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function posBox(parentObj, objName) {
	var coors = findPos(parentObj);	
	var x = document.getElementById(objName);
	x.style.top = (coors[1]-0) + 'px';
	x.style.left = coors[0] + 'px';
}

function $(o) { return((typeof(o)=='object'?o:document).getElementById(o)); }
function $S(o) { return($(o).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$(o)), z={X:0,Y:0}; while(o!=null) { z.X+=o.offsetLeft; z.Y+=o.offsetTop; o=o.offsetParent; }; return(z); }
function XY(e,v) { var o=agent('msie')?{'X':event.clientX+document.body.scrollLeft,'Y':event.clientY+document.body.scrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); }

function readComments(eId) {
    var oCom = document.getElementById("comments_"+ eId);
    var sLinkText = document.getElementById("commentLink_"+eId).innerHTML;
    var stl = oCom.style.display;
     
    if((/block/.test(stl))) {
        oCom.style.display = "none"
        sLinkText = sLinkText.replace("Close","Read");
    } else {   
        oCom.style.display = "block";
        sLinkText = sLinkText.replace("Read","Close");
   }
   document.getElementById("commentLink_"+eId).innerHTML = sLinkText;
}

var arTipContent = new Array();
arTipContent[0] = "Click on the link bellow to add this motorcycle to the compare list (up to 3 bikes). Then go the top menu and click on 'Compare List' to compare technical specifications.";
arTipContent[1] = "Click on the link to search by manufacturer, by year, by name. Examples: Honda<br />kymco 2009<br />qlink 500";

function tipsOnOff(ele,nId) {
	var oTip = document.getElementById("ttip");
	var nLeft = 50;
	if (nId==1)
	    nLeft = 180;
	    
	if (!oTip.style.visibility || oTip.style.visibility == "hidden") {
		var pos = findPos(ele);
		oTip.style.left = (pos[0]-nLeft) + "px";
		oTip.style.top = (pos[1] -74) + "px";
		oTip.innerHTML = "<div class='tipsBox'>" + arTipContent[nId] + "</div>";
		oTip.style.visibility = "visible";
	}
	else
		oTip.style.visibility = "hidden";
}


function rollMyClass(ele) {
	var sClass= ele.className;
	ele.className = (/_on/.test(sClass)) ? sClass.replace('_on', '_off') : sClass.replace('_off', '_on');
}

		
function tabOn(nTabId, sTabName, nTabCount) {
    var sDivName = "";
    
    if (sTabName)
        sDivName = sTabName.replace(/tab_/,"div_");
    
	if (nTabId>=0) {
	    if (nTabCount>0)
	        tabAllOff(sTabName, sDivName, nTabCount);
        
	    document.getElementById(sDivName + "_" + nTabId).style.display = "block";
	    var sTabClass = document.getElementById(sTabName + "_" + nTabId).className.replace(/_on|_off/,"_at");
		document.getElementById(sTabName + "_" + nTabId).className = sTabClass;
		
		doMetrics(sDivName + "_" + nTabId);
	}	
}
function tabAllOff(sTabName, sDivName, nTabCount) {
    for (var i=0; i<nTabCount; ++i) {
        var sTabClass = document.getElementById(sTabName + "_" + i).className.replace(/_at|_on/,"_off");
	    document.getElementById(sTabName + "_" + i).className = sTabClass
	    
	    if (document.getElementById(sDivName + "_" + i))
	        document.getElementById(sDivName + "_" + i).style.display = "none";
    
    }
}

function getPageSize() {
	var w = window.innerWidth
	var h = window.innerHeight

	if(navigator.userAgent.toLowerCase().search("msie") > -1){
		w = document.body.offsetWidth
		h = document.body.offsetHeight
	}
	if(document.body.offsetWidth > w) w = document.body.offsetWidth
	if(document.body.offsetHeight > h) h = document.body.offsetHeight

	if(document.body.scrollWidth > w) w = document.body.scrollWidth
	if(document.body.scrollHeight > h) h = document.body.scrollHeight
	
	return [w, h];
}
	


