window.onload=load;

var scroll;
var ua = navigator.userAgent.toLowerCase();
var path=location.pathname.toLowerCase();
var liArray = document.getElementsByTagName("li");
var aArray = document.getElementsByTagName("a");

function load(){
setnavs();
so_init();
if(scroll!=false){
startScroll();
}

if (ua.indexOf('firefox') != -1){
for(var i=105;i<119;++i){
if(path=="/categories/" + i + "/default.aspx"){
ffFleetFix();
}
}
if(path=="/categories/82/default.aspx"){
formFix();
}
}
}

function startScroll(){
var scroller  = null;
var scrollbar = null;
var d = document.getElementById("text");
scroller  = new jsScroller(d, 400, 180);
scrollbar = new jsScrollbar (document.getElementById("Scrollbar-Container"), scroller, true, scrollbarEvent);
}

var i;

function setnavs(){
//hnav
liArray[1].style.background="transparent url(\'/data/styleimages/nav_divider_horz.gif\') no-repeat 0px 1px";
liArray[4].style.background="transparent url(\'/data/styleimages/nav_divider_horz.gif\') no-repeat 0px 1px";
liArray[5].style.background="transparent url(\'/data/styleimages/nav_divider_horz.gif\') no-repeat 0px 1px";
//vnav
liArray[12].style.background="transparent url(\'/data/styleimages/topmenulibg.jpg\') no-repeat 0px 0px";
liArray[26].style.background="transparent url(\'/data/styleimages/topmenulibg.jpg\') no-repeat 0px 0px";
liArray[28].style.background="transparent url(\'/data/styleimages/topmenulibg.jpg\') no-repeat 0px 0px";
//vnav2
setVnav2();
}

var x = 2;
function setVnav2()
{
var allPageTags = new Array();
var theClass="verticalnav2";
var allPageTags=document.getElementsByTagName("*");
if(x<9)
{
if(x%2 == 0)
{
for (i=0; i<allPageTags.length; i++) {
if (allPageTags[i].className==theClass) { 
var a = allPageTags[i].getElementsByTagName("a");
a[0].style.background="transparent url('/data/styleimages/rvnavbgblue.jpg') no-repeat 15px 0px"; 
a[0].style.color="#ffffff";
} 
}
}
else
{
for (i=0; i<allPageTags.length; i++) {
if (allPageTags[i].className==theClass) { 
var a = allPageTags[i].getElementsByTagName("a");
a[0].style.background="transparent url('/data/styleimages/rvnavbgwhite.jpg') no-repeat 15px 0px"; 
a[0].style.color="#454545";
}
}
}
x+=1;
setTimeout("setVnav2()",500);
}
}

function jsScroller (o, w, h) {
  var self = this;
  var list = o.getElementsByTagName("div");
  for (var i = 0; i < list.length; i++) {
    if (list[i].className.indexOf("Scroller-Container") > -1) {
      o = list[i];
    }
  }
  
  //Private methods
  this._setPos = function (x, y) {
    if (x < this.viewableWidth - this.totalWidth) 
      x = this.viewableWidth - this.totalWidth;
    if (x > 0) x = 0;
    if (y < this.viewableHeight - this.totalHeight) 
      y = this.viewableHeight - this.totalHeight;
    if (y > 0) y = 0;
    this._x = x;
    this._y = y;
    with (o.style) {
      left = this._x +"px";
      top  = this._y +"px";
    }
  };
  
  //Public Methods
  this.reset = function () {
    this.content = o;
    this.totalHeight = o.offsetHeight;
    this.totalWidth   = o.offsetWidth;
    this._x = 0;
    this._y = 0;
    with (o.style) {
      left = "0px";
      top  = "0px";
    }
  };
  this.scrollBy = function (x, y) {
    this._setPos(this._x + x, this._y + y);
  };
  this.scrollTo = function (x, y) {
    this._setPos(-x, -y);
  };
  this.stopScroll = function () {
    if (this.scrollTimer) window.clearInterval(this.scrollTimer);
  };
  this.startScroll = function (x, y) {
    this.stopScroll();
    this.scrollTimer = window.setInterval(
      function(){ self.scrollBy(x, y); }, 40
    );
  };
  this.swapContent = function (c, w, h) {
    o = c;
    var list = o.getElementsByTagName("div");
    for (var i = 0; i < list.length; i++) {
      if (list[i].className.indexOf("Scroller-Container") > -1) {
        o = list[i];
      }
    }
    if (w) this.viewableWidth  = w;
    if (h) this.viewableHeight = h;
    this.reset();
  };
  
  //variables
  this.content = o;
  this.viewableWidth  = w;
  this.viewableHeight = h;
  this.totalWidth   = o.offsetWidth;
  this.totalHeight = o.offsetHeight;
  this.scrollTimer = null;
  this.reset();
};


//Written by Nathan Faubion: http://n-son.com
//Use this or edit how you want, just give me
//some credit!
function jsScrollbar (o, s, a, ev) {
  var self = this;
  
  this.reset = function () {
    //Arguments that were passed
    this._parent = o;
    this._src    = s;
    this.auto    = a ? a : false;
    this.eventHandler = ev ? ev : function () {};
    //Component Objects
    this._up   = this._findComponent("Scrollbar-Up", this._parent);
    this._down = this._findComponent("Scrollbar-Down", this._parent);
    this._yTrack  = this._findComponent("Scrollbar-Track", this._parent);
    this._yHandle = this._findComponent("Scrollbar-Handle", this._yTrack);
    //Height and position properties
    this._trackTop = findOffsetTop(this._yTrack);
    this._trackHeight  = this._yTrack.offsetHeight;
    this._handleHeight = this._yHandle.offsetHeight;
    this._x = 0;
    this._y = 0;
    //Misc. variables
    this._scrollDist  = 5;
    this._scrollTimer = null;
    this._selectFunc  = null;
    this._grabPoint   = null;
    this._tempTarget  = null;
    this._tempDistX   = 0;
    this._tempDistY   = 0;
    this._disabled    = false;
    this._ratio = (this._src.totalHeight - this._src.viewableHeight)/(this._trackHeight - this._handleHeight);
    
    this._yHandle.ondragstart  = function () {return false;};
    this._yHandle.onmousedown = function () {return false;};
    this._addEvent(this._src.content, "mousewheel", this._scrollbarWheel);
    this._removeEvent(this._parent, "mousedown", this._scrollbarClick);
    this._addEvent(this._parent, "mousedown", this._scrollbarClick);
    
    this._src.reset();
    with (this._yHandle.style) {
      top  = "0px";
      left = "0px";
    }
    this._moveContent();
    
    if (this._src.totalHeight < this._src.viewableHeight) {
      this._disabled = true;
      this._yHandle.style.visibility = "hidden";
      if (this.auto) this._parent.style.visibility = "hidden";
    } else {
      this._disabled = false;
      this._yHandle.style.visibility = "visible";
      this._parent.style.visibility  = "visible";
    }
  };
  this._addEvent = function (o, t, f) {
    if (o.addEventListener) o.addEventListener(t, f, false);
    else if (o.attachEvent) o.attachEvent('on'+ t, f);
    else o['on'+ t] = f;
  };
  this._removeEvent = function (o, t, f) {
    if (o.removeEventListener) o.removeEventListener(t, f, false);
    else if (o.detachEvent) o.detachEvent('on'+ t, f);
    else o['on'+ t] = null;
  };
  this._findComponent = function (c, o) {
    var kids = o.childNodes;
    for (var i = 0; i < kids.length; i++) {
      if (kids[i].className && kids[i].className == c) {
        return kids[i];
      }
    }
  };
  //Thank you, Quirksmode
  function findOffsetTop (o) {
    var t = 0;
    if (o.offsetParent) {
      while (o.offsetParent) {
        t += o.offsetTop;
        o  = o.offsetParent;
      }
    }
    return t;
  };
  this._scrollbarClick = function (e) {
    if (self._disabled) return false;
    
    e = e ? e : event;
    if (!e.target) e.target = e.srcElement;
    
    if (e.target.className.indexOf("Scrollbar-Up") > -1) self._scrollUp(e);
    else if (e.target.className.indexOf("Scrollbar-Down") > -1) self._scrollDown(e);
    else if (e.target.className.indexOf("Scrollbar-Track") > -1) self._scrollTrack(e);
    else if (e.target.className.indexOf("Scrollbar-Handle") > -1) self._scrollHandle(e);
    
    self._tempTarget = e.target;
    self._selectFunc = document.onselectstart;
    document.onselectstart = function () {return false;};
    
    self.eventHandler(e.target, "mousedown");
    self._addEvent(document, "mouseup", self._stopScroll, false);
    
    return false;
  };
  this._scrollbarDrag = function (e) {
    e = e ? e : event;
    var t = parseInt(self._yHandle.style.top);
    var v = e.clientY + document.body.scrollTop - self._trackTop;
    with (self._yHandle.style) {
      if (v >= self._trackHeight - self._handleHeight + self._grabPoint)
        top = self._trackHeight - self._handleHeight +"px";
      else if (v <= self._grabPoint) top = "0px";
      else top = v - self._grabPoint +"px";
      self._y = parseInt(top);
    }
    
    self._moveContent();
  };
  this._scrollbarWheel = function (e) {
    e = e ? e : event;
    var dir = 0;
    if (e.wheelDelta >= 120) dir = -1;
    if (e.wheelDelta <= -120) dir = 1;
    
    self.scrollBy(0, dir * 20);
    e.returnValue = false;
  };
  this._startScroll = function (x, y) {
    this._tempDistX = x;
    this._tempDistY = y;
    this._scrollTimer = window.setInterval(function () {
      self.scrollBy(self._tempDistX, self._tempDistY); 
    }, 40);
  };
  this._stopScroll = function () {
    self._removeEvent(document, "mousemove", self._scrollbarDrag, false);
    self._removeEvent(document, "mouseup", self._stopScroll, false);
    
    if (self._selectFunc) document.onselectstart = self._selectFunc;
    else document.onselectstart = function () { return true; };
    
    if (self._scrollTimer) window.clearInterval(self._scrollTimer);
    self.eventHandler (self._tempTarget, "mouseup");
  };
  this._scrollUp = function (e) {this._startScroll(0, -this._scrollDist);};
  this._scrollDown = function (e) {this._startScroll(0, this._scrollDist);};
  this._scrollTrack = function (e) {
    var curY = e.clientY + document.body.scrollTop;
    this._scroll(0, curY - this._trackTop - this._handleHeight/2);
  };
  this._scrollHandle = function (e) {
    var curY = e.clientY + document.body.scrollTop;
    this._grabPoint = curY - findOffsetTop(this._yHandle);
    this._addEvent(document, "mousemove", this._scrollbarDrag, false);
  };
  this._scroll = function (x, y) {
    if (y > this._trackHeight - this._handleHeight) 
      y = this._trackHeight - this._handleHeight;
    if (y < 0) y = 0;
    
    this._yHandle.style.top = y +"px";
    this._y = y;
    
    this._moveContent();
  };
  this._moveContent = function () {
    this._src.scrollTo(0, Math.round(this._y * this._ratio));
  };
  
  this.scrollBy = function (x, y) {
    this._scroll(0, (-this._src._y + y)/this._ratio);
  };
  this.scrollTo = function (x, y) {
    this._scroll(0, y/this._ratio);
  };
  this.swapContent = function (o, w, h) {
    this._removeEvent(this._src.content, "mousewheel", this._scrollbarWheel, false);
    this._src.swapContent(o, w, h);
    this.reset();
  };
  
  this.reset();
};


var scroller  = null;
var scrollbar = null;

function scrollbarEvent (o, type) {
}

function swapIt(o) {
  o.blur();
  if (o.className == "current") return false;
  
  var list = document.getElementById("Navigation").getElementsByTagName("a");
  for (var i = 0; i < list.length; i++) {
    if (list[i].className == "current") {
      list[i].className = "";
      document.getElementById(list[i].title).y = -scroller._y;
    }
    if (list[i].title == o.title) o.className = "current";
  }
  
  list = document.getElementById("Container").childNodes;
  for (var i = 0; i < list.length; i++) {
    if (list[i].tagName == "DIV") list[i].style.display = "none";
  }
  
  var top = document.getElementById(o.title);
  top.style.display = "block";
  scrollbar.swapContent(top);
  if (top.y) scrollbar.scrollTo(0, top.y);
  
  return false;
}

function changeImage(path,id,dir){
var s = document.getElementById(id).src;
var num = Number(s.charAt(s.length - 5));
var maxNum;
switch(id){
case "limo":
maxNum=6;
break;
case "van":
maxNum=3;
break;
}

if(dir=="next"){
if(num==maxNum){
num=0;
document.getElementById(id).src= "/data" + path + num + ".jpg";
}
else{
document.getElementById(id).src= "/data" + path + (num+1) + ".jpg";
}
}

if(dir=="prev"){
if(num==0){
num=maxNum;
document.getElementById(id).src= "/data" + path + num + ".jpg";
}
else{
document.getElementById(id).src= "/data" + path + (num-1) + ".jpg";
}
}
}

function formFix(){
var sArray = document.getElementsByTagName("span");
for(var i=0;i<sArray.length;++i){
if(sArray[i].className=="rt1"){
sArray[i].style.marginTop="-144px";
}
if(sArray[i].className=="rt2"){
sArray[i].style.marginTop="-120px";
}
if(sArray[i].className=="rt3"){
sArray[i].style.marginTop="-96px";
}
if(sArray[i].className=="rt4"){
sArray[i].style.marginTop="-72px";
}
if(sArray[i].className=="rt5"){
sArray[i].style.marginTop="-48px";
}
if(sArray[i].className=="rt6"){
sArray[i].style.marginTop="-24px";
}
if(sArray[i].className=="rt7"){
sArray[i].style.marginTop="0px";
}
}
}

function newWin(){
var l = (screen.width-1000)/2;
var t = (screen.height-600)/2;
var options = "toolbar=no,menubar=yes,scrollbars=yes,resizable=no,width=1000,height=600,top=" + t + ",left=" + l;
var url = "https://www.corporatecaronline.com/cust/SILSTAR/www/BookingListForm.cfm";
var resWin = window.open(url,"Reservations", options);
}

function ffFleetFix() {
//find fleet flash
var flash = document.getElementById("flashimg1");
flash.style.paddingLeft="69px";
flash.style.paddingTop="69px";
}

var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;

function so_init()
{
	if(!d.getElementById || !d.createElement)return;
	css = d.createElement('link');
	css.setAttribute('href','/data/style/slideshow2.css');
	css.setAttribute('rel','stylesheet');
	css.setAttribute('type','text/css');
	d.getElementsByTagName('head')[0].appendChild(css);

	imgs = d.getElementById('rotator').getElementsByTagName('img');
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = 'block';
	imgs[0].xOpacity = .99;

	setTimeout(so_xfade,4000);
}

function so_xfade()
{
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;

	cOpacity-=.05;
	nOpacity+=.05;

	imgs[nIndex].style.display = 'block';
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;

	setOpacity(imgs[current]);
	setOpacity(imgs[nIndex]);

	if(cOpacity<=0)
	{
		imgs[current].style.display = 'none';
		current = nIndex;
		setTimeout(so_xfade,4000);
	}
	else
	{
		setTimeout(so_xfade,50);
	}

	function setOpacity(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}requiredfields = new Array('first_name','First Name','last_name','Last Name','email','Email Address','phone','Phone','country','Country','00N30000000wQso','Fleet Size','company','Company Name');
var country;
var state;
var first_name;
var last_name;
var phone_number;
function formrules(frm)
{


    var thisform = frm;
    var elements = document.forms['aspnetForm'].elements;
    var ret = listAllRequiredFields(elements);
    if (ret == false) {return false;}
    
        for (var x = 0;x<elements.length;x++)
        {
            if (elements[x].FieldName != undefined)
            {
                
                if (elements[x].FieldName == 'country')
                {
                    country = elements[x].value;
                }
                else if (elements[x].FieldName == 'state')
                {
                    state = elements[x].value;
                }
                else if (elements[x].FieldName == 'first_name')
                {
                    ret = badFormValue(elements[x].value);
                    if (ret == true) {alert('Invalid first name');return false;}
			first_name = elements[x].value;
                }
		else if (elements[x].FieldName == 'last_name')
		{
			last_name = elements[x].value;
		}
		else if (elements[x].FieldName == 'phone')
		{
			if (phonenumber(elements[x].value).length <= 7)
			{alert('Invalid Phone Number');return false;}

		}
		else if (elements[x].FieldName == '00N30000001DYuT')
		{
			ret = badFormValue(elements[x].value);
                    if (ret == true) {alert('Invalid content in comments box');return false;}
		}

            }
        }
        if (country == 'US' && state == '')
        {
            alert('You must select a state.')
            return false;
        }
        else if (country != 'US' && state != '')
        {
            alert('Please delete your state selection.')
            return false;
        }
if (first_name == last_name)
{
alert('invalid name');
return false;
}

if (CheckBoxSelection() == false)
{
alert('Please select an interest');
return false;
}
            
    return true;
}

function badFormValue(frmvalue)
{
    var badwords = new Array('http://*');
    for (var b = 0;b<badwords.length;b++)
    {
    var re = new RegExp(badwords[b]);
          if (frmvalue.match(re)) 
          {
            return true;
          } 
    }
return false;
}

function phonenumber(phonevalue)
{
	var p = new RegExp(/\d/g);
    var s = '';
    var match = phonevalue.match(p);
    //alert(match.length);
    for (var m=0;m<match.length;m++)
    {
    s += match[m];
    }
    //alert(s);
	return s;
}

function listAllRequiredFields(elements)
{
                for (var x = 0;x<elements.length;x++)
                {
                    for (r=0;r<requiredfields.length;r++)
                    {
                        if (requiredfields[r] == elements[x].FieldName && elements[x].value == '')
                        {
                            alert(requiredfields[r+1] + ' is required');
                            r++
                            elements[x].focus()
                            return false;
                        }
                    }
                }
return true;
}

function validateEmail(elementValue)
{ 
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
return emailPattern.test(elementValue);
 }

function CheckBoxSelection()
{
	var c = document.getElementById('00N60000001YFpD');
	if (c == null) {return true;}
	if (document.getElementById('00N60000001YFpD').checked == true) {return true;}
	else if (document.getElementById('00N60000001YFpI').checked == true) {return true;}
	else if (document.getElementById('00N60000001YFpN').checked == true) {return true;}
	else if (document.getElementById('00N60000001YFpS').checked == true) {return true;}
	else if (document.getElementById('00N60000001YFpX').checked == true) {return true;}
	else if (document.getElementById('00N60000001YFpc').checked == true) {return true;}
	else if (document.getElementById('00N60000001YFph').checked == true) {return true;}
	else if (document.getElementById('00N60000001YFpr').checked == true) {return true;}
	else if (document.getElementById('00N60000001YFqE').checked == true) {return true;}
	return false;
}
