

$(document).ready(function() {
	
	var hover_timeout = undefined;
	
	$("#contentmenu > li").bind("mouseenter", function() {
		
		// anytime we roll over, make sure they all disappear
		$("#contentmenu > li").find("div:first").css("display:none;");
	
		if (hover_timeout != undefined) {
			clearTimeout(hover_timeout);
		}
		
		// gotta do this so we can access this
		var $this = this;
		
		// after 500ms, slide it down
		hover_timeout = setTimeout(function() {
			hover_timeout = undefined;
			//$($this).find("div").slideDown('fast');
			$($this).find("div:first").slideDown('fast');
			//alert('yes');
		}, 200);

	});

	$("#contentmenu > li").bind("mouseleave", function() {
		clearTimeout(hover_timeout);
		$(this).find("div:first").slideUp('fast');
	});
	
	$('#fade').cycle({
		fx:    'fade',
		speed: 6000,
		pause: 1,
		random: 1
		

	});
	
	$('#fade2').cycle({
		fx:    'turnDown',
		speed: 5900,
		pause: 1,
		random: 1
		

	});

	$('#fade3').cycle({
		fx:    'fade',
		speed: 5000,
		pause: 1,
		random: 1
		

	});
	
		var hover_timeout2 = undefined;
	
	$("#brandmenu > li").bind("mouseenter", function() {
		
		// anytime we roll over, make sure they all disappear
		$("#brandmenu > li").find("div:first").css("display:none;");
	
		if (hover_timeout2 != undefined) {
			clearTimeout(hover_timeout2);
		}
		
		// gotta do this so we can access this
		var $this = this;
		
		// after 500ms, slide it down
		hover_timeout2 = setTimeout(function() {
			hover_timeout2 = undefined;
			//$($this).find("div").slideDown('fast');
			$($this).find("div:first").fadeIn('fast');
			//alert('yes');
		}, 200);

	});

	$("#brandmenu > li").bind("mouseleave", function() {
		clearTimeout(hover_timeout2);
		$(this).find("div:first").fadeOut('fast');
	});

	$("ul.menu_body li:even").addClass("alt");

    $('img.menu_head').mouseover(function () {
		$('ul.menu_body').slideToggle('medium');
    });

    $('body').click(function () {
		$('ul.menu_body').slideToggle('medium');
    });
});

function showDivision(division) {
	document.getElementById(division).style.display = 'block';
}

function hideDivision(division) {
	document.getElementById(division).style.display = 'none';
}

function SetContent(curcont) {

	if (document.getElementById(curcont)) {
		curdiv = document.getElementById(curcont);
		curdiv.style.display = 'block';
	}

	return;

}

function SwitchContent(curcont, choice) {
	curdiv = document.getElementById(curcont);
	curdiv.style.display = 'none';
	newdiv = document.getElementById(choice);
	newdiv.style.display = 'block';
	curcont = choice;
	return;

}


function toggleDisplay(divToToggle){
	curdiv = document.getElementById(divToToggle);
	if(curdiv.style.display == 'none') curdiv.style.display = 'block';
		else curdiv.style.display = 'none';
	return;
}

function changePage(newLoc)
 {
 	var dd = document.salesform.country.selectedIndex;
	var ss = document.salesform.country[dd].text; 
 	if( ss == 'Other' ) {
 		nextPage = newLoc.options[newLoc.selectedIndex].value		
	    document.location.href = nextPage
 	} 
 }
 
 

function validate_email(theControl) {

	if ( theControl.value == "" || theControl.value.length <= 0 )   {
	   alert("I'm sorry. This email address must be filled in correct to send the form to our server. Please"

   		+" check the prefix and '@' sign.");
	   theControl.focus()

	   return false;

    }

    var reEmail = /^.+\@.+\..+$/
    var holderValue;
    var thisValue = theControl.value;

    // Check for e-mail addresses from ISPs and other sources that have been consistently
    // entered incorrectly.  If detected, correct the situation.
    if  (

            (thisValue.substring(thisValue.length - 4, thisValue.length).toLowerCase()) == '@aol' ||
            (thisValue.substring(thisValue.length - 4, thisValue.length).toLowerCase()) == '@msn' ||
            (thisValue.substring(thisValue.length - 6, thisValue.length).toLowerCase()) == '@yahoo' ||
            (thisValue.substring(thisValue.length - 6, thisValue.length).toLowerCase()) == '@lycos' ||
            (thisValue.substring(thisValue.length - 7, thisValue.length).toLowerCase()) == '@excite' ||
            (thisValue.substring(thisValue.length - 10, thisValue.length).toLowerCase()) == '@altavista' ||
            (thisValue.substring(thisValue.length - 11, thisValue.length).toLowerCase()) == '@compuserve' ||
            (thisValue.substring(thisValue.length - 8, thisValue.length).toLowerCase()) == '@prodigy' ||
            (thisValue.substring(thisValue.length - 8, thisValue.length).toLowerCase()) == '@hotmail' ||
            (thisValue.substring(thisValue.length - 9, thisValue.length).toLowerCase()) == '@netscape'
        )

        {

            holderValue = thisValue.concat('.com');
            thisValue = holderValue;
            theControl.value = thisValue;

        }

    if  (

            (thisValue.substring(thisValue.length - 5, thisValue.length).toLowerCase()) == '@home'

        )

        {

            holderValue = thisValue.concat('.net');
            thisValue = holderValue;
            theControl.value = thisValue;

        }

    // Now check the actual value of the e-mail address for validity.

    var flagFirstCheck = (theControl.value.length < 6) ||
        (thisValue.indexOf('@') == -1) ||
        (thisValue.indexOf('.') == -1) ||
        (thisValue.indexOf('@',(thisValue.indexOf('@')+1)) != -1) ||
        ((thisValue.indexOf('.')+1) == thisValue.length) ||
        ((thisValue.indexOf('@')+1) == thisValue.length)

    var flagSecondCheck = reEmail.test(thisValue)
    if ( flagFirstCheck || !flagSecondCheck)
    {

   alert("I'm sorry. This email address seems to be incorrect. Please"
   +" check the prefix and '@' sign.");
   theControl.focus()

        return false;

    }

    else {
        return true;

    }

}
function validate_vin(theControl) {
// if ( theControl.value.length > 16 && theControl.value.length < 18 )

 if (theControl.value.length != 17)

{

alert("I'm sorry. The VIN must be filled in correct to send the form to our server. Please"
   +" enter 17 digits.");
   theControl.focus()
        return false;
          }
    else {
        return true;
    }
}

function ValidateControl(control, prompt) {
  if (control.value=="") {
    alert("The " + prompt +" field is a required field, and it must be filled in before your form can be sent to our server.")
    control.focus()
    return false }
  return true
}

function SalesSubmitValidation(form) {
        var count = 0;
        if (!ValidateControl(form.country,'country')) return false        
        if (!ValidateControl(form.realname,'Name')) return false
        if (!ValidateControl(form.address,'Address')) return false
        if (!ValidateControl(form.city,'City')) return false
        if (!ValidateControl(form.state,'State')) return false
        if (!ValidateControl(form.zipcode,'Zip')) return false

        if (form.bigsky.checked) { count++; form.division.value = form.division.value + "," + form.bigsky.value }
        if (form.bullet.checked) { count++; form.division.value = form.division.value + "," + form.bullet.value }        
        if (form.challenger.checked) { count++; form.division.value = form.division.value + "," + form.challenger.value }
        if (form.cougar.checked) { count++; form.division.value = form.division.value + "," + form.cougar.value }
        if (form.everest.checked) { count++; form.division.value = form.division.value + "," + form.everest.value }
        if (form.fuzion.checked) { count++; form.division.value = form.division.value + "," + form.fuzion.value }
        if (form.hideout.checked) { count++; form.division.value = form.division.value + "," + form.hideout.value }
        if (form.hornet.checked) { count++; form.division.value = form.division.value + "," + form.hornet.value }
        if (form.laredo.checked) { count++; form.division.value = form.division.value + "," + form.laredo.value }
        if (form.montana.checked) { count++; form.division.value = form.division.value + "," + form.montana.value }
        if (form.mountaineer.checked) { count++; form.division.value = form.division.value + "," + form.mountaineer.value }
        if (form.energy.checked) { count++; form.division.value = form.division.value + "," + form.energy.value }
        if (form.outback.checked) { count++; form.division.value = form.division.value + "," + form.outback.value }
        if (form.passport.checked) { count++; form.division.value = form.division.value + "," + form.passport.value }
        if (form.raptor.checked) { count++; form.division.value = form.division.value + "," + form.raptor.value }
        if (form.residence.checked) { count++; form.division.value = form.division.value + "," + form.residence.value }         if (form.retreat.checked) { count++; form.division.value = form.division.value + "," + form.retreat.value }
        if (form.springdale.checked) { count++; form.division.value = form.division.value + "," + form.springdale.value }
        if (form.sprinter.checked) { count++; form.division.value = form.division.value + "," + form.sprinter.value }
        if (form.summerland.checked) { count++; form.division.value = form.division.value + "," + form.summerland.value }
        if (form.sydney.checked) { count++; form.division.value = form.division.value + "," + form.sydney.value }
        if (form.vr1.checked) { count++; form.division.value = form.division.value + "," + form.vr1.value }
        if (form.xlite.checked) { count++; form.division.value = form.division.value + "," + form.xlite.value }

        if (count == 0) {
              alert("You must choose at least one brochure to proceed !");
              return false   }

        return true
}

function SpecialsSubmitValidation(form) {

        if (!validate_email(form.email, 'Your Email')) return false
        if (!ValidateControl(form.your_realname,'Your Name')) return false
        if (!ValidateControl(form.address,'Your Address')) return false
        if (!ValidateControl(form.city,'Your City')) return false
        if (!ValidateControl(form.state,'Your State')) return false 
        if (!ValidateControl(form.zip,'Your Zip')) return false      
        if (!ValidateControl(form.phone,'Your Phone')) return false        

        return true

}

function SalesSubmitValidation2(form) {
        var count = 0;
        if (!ValidateControl(form.country,'Country')) return false
        if (!ValidateControl(form.realname,'Name')) return false
        if (!ValidateControl(form.address,'Address')) return false
        if (!ValidateControl(form.city,'City')) return false
        if (!ValidateControl(form.state,'State')) return false
        if (!ValidateControl(form.zipcode,'Zip')) return false
        return true
}

function MailSubmitValidation(form) {
        if (!ValidateControl(form.realname,'Name')) return false
        if (!ValidateControl(form.address,'Address')) return false
        if (!ValidateControl(form.city,'City')) return false
        if (!ValidateControl(form.state,'State')) return false
        if (!ValidateControl(form.zipcode,'Zip')) return false
        if (!ValidateControl(form.country,'country')) return false        
        if (form.division.value == "0" || form.division.value == "") {
              alert("You must choose a product to proceed !");
              form.division.focus();
              return false   }
        return true
}

function DownloadSubmitValidation(form) {
		var Yoptin = document.getElementById('y');
        if (!ValidateControl(form.realname,'Name')) return false
   	    if (!ValidateControl(form.zipcode,'Zip')) return false
        if (form.division.value == "0" || form.division.value == "") {
              alert("You must choose a product to proceed !");
       	      form.division.focus();
              return false   }
        if (Yoptin.checked && form.email.value == "") {
              alert("If you wish to Opt In, you must provide an email address");
       	      form.division.focus();
              return false   }        
        return true
}

function DownloadSubmitValidation2(form) {
        if (!ValidateControl(form.realname,'Name')) return false
   	    if (!ValidateControl(form.zipcode,'Zip')) return false
        if (form.division.value == "0" || form.division.value == "") {
              alert("You must choose a product to proceed !");
       	      form.division.focus();
              return false   }
  		return true      	  
        }
        
function FriendSubmitValidation(form) {
        if (!validate_email(form.friend_email, 'Your Friends email')) return false
   	    if (!validate_email(form.your_email, 'Your email')) return false
        if (!ValidateControl(form.your_realname,'Your Name')) return false
        if (!ValidateControl(form.friend_realname,'Friends Name')) return false
        return true
}

function SpecialsSubmitValidation(form) {

        if (!validate_email(form.email, 'Your Email')) return false
        if (!ValidateControl(form.your_realname,'Your Name')) return false
        if (!ValidateControl(form.address,'Address')) return false
        if (!ValidateControl(form.city,'City')) return false
        if (!ValidateControl(form.state,'State')) return false 
        if (!ValidateControl(form.zip,'Zip')) return false      
        if (!ValidateControl(form.phone,'Phone')) return false        

        return true

}

function WarrantySubmitValidation(form) {
        if (!validate_email(form.email)) return false
        if (!ValidateControl(form.realname,'Name')) return false
        if (!ValidateControl(form.Address,'Address')) return false
        if (!ValidateControl(form.City,'City')) return false
        if (!ValidateControl(form.State,'State')) return false
        if (!ValidateControl(form.ZipCode,'Zip')) return false
        if (!ValidateControl(form.PhoneNumber,'Phone Number')) return false
        if (form.division.value == "0") {
      	      alert("You must select a division to proceed !");
              form.division.focus();
              return false   }

        if (!ValidateControl(form.SerialNumber,'Serial Number')) return false
        if (!validate_vin(form.VINNumber)) return false
        if (!ValidateControl(form.Comments,'Comments')) return false

        return true
}

function generalSubmitValidation(form) {

        if (!validate_email(form.email)) return false
        if (!ValidateControl(form.realname,'Name')) return false
        if (!ValidateControl(form.Address,'Address')) return false
        if (!ValidateControl(form.City,'City')) return false
        if (!ValidateControl(form.State,'State')) return false
        if (!ValidateControl(form.ZipCode,'Zip')) return false
        if (!ValidateControl(form.PhoneNumber,'Phone Number')) return false
        if (!ValidateControl(form.Comments,'Comments')) return false

        return true

}

function webmasterSubmitValidation(form) {
        if (!validate_email(form.email)) return false
        if (!ValidateControl(form.realname,'Name')) return false
        if (!ValidateControl(form.Comments,'Comments')) return false

        return true
}

function dealerSubmitValidation(form) {

        if (!ValidateControl(form.DealerNumber,'Dealer Number')) return false
        if (!ValidateControl(form.DealerName,'Dealer Name')) return false
        if (!ValidateControl(form.Address,'Address')) return false
        if (!ValidateControl(form.City,'City')) return false
        if (!ValidateControl(form.State,'State')) return false
        if (!ValidateControl(form.ZipCode,'Zip')) return false
        if (!validate_email(form.Email)) return false
        if (!ValidateControl(form.PhoneNumber,'Phone Number')) return false

        return true
}

function mediaValidation(form) {

		if (!ValidateControl(form.fullname,'Full Name')) return false
     	if (!ValidateControl(form.email,'Email')) return false
        if (!ValidateControl(form.comments,'Comments')) return false
        return true

}

function PhoneFormat(evt) {
	IE = document.all;
        if (IE) {
        var keycode = window.event.keyCode;
        var shift   = window.event.shiftKey;
        var ctrl    = window.event.ctrlKey;
        var alt     = window.event.altKey;
        var pos = this.value.length + 1;
        var lparen  = (shift  && !ctrl && !alt && keycode == 40);
        var rparen  = (shift  && !ctrl && !alt && keycode == 41);
        var space   = (!shift && !ctrl && !alt && keycode == 32);
        var dash    = (!shift && !ctrl && !alt && keycode == 45);
        var slash   = (!shift && !ctrl && !alt && keycode == 47);
        var digit   = (!shift && !ctrl && !alt && keycode >= 48 && keycode <= 57);


                if (!lparen && !rparen && !space && !dash && !digit) return false;
                if (pos == 1  && lparen) return true;
                if (pos == 1  && digit) { this.value = '('; return true; }
                if (pos == 2  && digit) return true;
                if (pos == 3  && digit) return true;
                if (pos == 4  && digit) return true;
                if (pos == 5  && rparen) { this.value += ') '; return false; }
                if (pos == 5  && dash)   { this.value += ') '; return false; }
                if (pos == 5  && slash)  { this.value += ') '; return false; }
                if (pos == 5  && space)  { this.value += ') '; return false; }
                if (pos == 5  && digit)  { this.value += ') '; return true; }
                if (pos == 6  && space) return true;
                if (pos == 6  && digit) { this.value += ' '; return true; }
                if (pos == 7  && digit) return true;
                if (pos == 8  && digit) return true;
                if (pos == 9  && digit) return true;
                if (pos == 10 && dash) return true;
                if (pos == 10 && space) { this.value += '-'; return false; }
                if (pos == 10 && digit) { this.value += '-'; return true; }
                if (pos == 11 && digit) return true;
                if (pos == 12 && digit) return true;
                if (pos == 13 && digit) return true;
                if (pos == 14 && digit) return true;
        } else {
        keycode = evt.which;
        var bs = String.fromCharCode(evt.which);
                if (keycode >= 48 && keycode <= 57) return true;
                if (keycode == 0) return true;
                if ((keycode == 32) || (keycode >= 40 && keycode <= 41) || (keycode >= 45 && keycode <= 46)) return true;
                if (bs == "\b") return true;
                if (keycode == 13) wr4_hitReturn(); return false;
        }
return false;
}

function validateFeedback(form) {
	
	if (!ValidateControl(form.name,'Full Name')) return false
	if (!ValidateControl(form.email,'Email')) return false
	if (!ValidateControl(form.comments,'Comments')) return false
        
	return true	
	
}

function FSubmitValidation(form) {

   if ( form.division.value == "") {
	  alert('You MUST select a division');
	  return false
   }

   if ( (form.zip.value == "") && (form.city.value == "" || form.state.value == "") ) {
	  alert("You must enter EITHER a zip code or city/state to proceed !");
	  form.zip.focus();
	  return false   }

   return true }


function check_division() {
  var i, ok = false;
  for (i=0; i<document.f.elements.length; i++) {
	if (document.f.elements[i].name == 'class_id[]' && document.f.elements[i].checked) {
	  ok = true;
	  break;
	}
  }
  return ok;
}

function PhoneFormat(evt) {
	IE = document.all;
        if (IE) {
        var keycode = window.event.keyCode;
        var shift   = window.event.shiftKey;
        var ctrl    = window.event.ctrlKey;
        var alt     = window.event.altKey;
        var pos = this.value.length + 1;
        var lparen  = (shift  && !ctrl && !alt && keycode == 40);
        var rparen  = (shift  && !ctrl && !alt && keycode == 41);
        var space   = (!shift && !ctrl && !alt && keycode == 32);
        var dash    = (!shift && !ctrl && !alt && keycode == 45);
        var slash   = (!shift && !ctrl && !alt && keycode == 47);
        var digit   = (!shift && !ctrl && !alt && keycode >= 48 && keycode <= 57);


                if (!lparen && !rparen && !space && !dash && !digit) return false;
                if (pos == 1  && lparen) return true;
                if (pos == 1  && digit) { this.value = '('; return true; }
                if (pos == 2  && digit) return true;
                if (pos == 3  && digit) return true;
                if (pos == 4  && digit) return true;
                if (pos == 5  && rparen) { this.value += ') '; return false; }
                if (pos == 5  && dash)   { this.value += ') '; return false; }
                if (pos == 5  && slash)  { this.value += ') '; return false; }
                if (pos == 5  && space)  { this.value += ') '; return false; }
                if (pos == 5  && digit)  { this.value += ') '; return true; }
                if (pos == 6  && space) return true;
                if (pos == 6  && digit) { this.value += ' '; return true; }
                if (pos == 7  && digit) return true;
                if (pos == 8  && digit) return true;
                if (pos == 9  && digit) return true;
                if (pos == 10 && dash) return true;
                if (pos == 10 && space) { this.value += '-'; return false; }
                if (pos == 10 && digit) { this.value += '-'; return true; }
                if (pos == 11 && digit) return true;
                if (pos == 12 && digit) return true;
                if (pos == 13 && digit) return true;
                if (pos == 14 && digit) return true;
        } else {
        keycode = evt.which;
        var bs = String.fromCharCode(evt.which);
                if (keycode >= 48 && keycode <= 57) return true;
                if (keycode == 0) return true;
                if ((keycode == 32) || (keycode >= 40 && keycode <= 41) || (keycode >= 45 && keycode <= 46)) return true;
                if (bs == "\b") return true;
                if (keycode == 13) wr4_hitReturn(); return false;
        }
return false;
}


$(document).ready(function(){ 
	$("div.roundbox") .wrap('<div class="dialog">'+
	'<div class="bd">'+
	'<div class="c">'+
	'<div class="s">'+
	'</div>'+
	'</div>'+
	'</div>'+
	'</div>');
	
	$('div.dialog').prepend('<div class="hd">'+
	'<div class="c"></div>'+
	'</div>')
	.append('<div class="ft">'+
	'<div class="c"></div>'+
	'</div>'
	);

});