// JavaScript Document









function detailedLinksClick(todo,inventoryItemId){
	
	switch (todo){
	case 'requiremoreinfo':
		$("#popupBox").show();
		$("#overFlow").show();
		aligndiv('popupBox');
		var stuff = $.ajax({
			type: "GET",
			url: "_ajax_requiremoreinfo.cfm?inventoryItemId="+inventoryItemId,
			data: "msg=",
			async: false
		}).responseText;
		$("#popupBox").html(stuff);			
	break;
	case 'makeanoffer':
		$("#popupBox").show();
		$("#overFlow").show();
		aligndiv('popupBox');
		var stuff = $.ajax({
			type: "GET",
			url: "_ajax_makeanoffer.cfm?inventoryItemId="+inventoryItemId,
			data: "msg=",
			async: false
		}).responseText;
		$("#popupBox").html(stuff);			
	break;
	case 'scheduleatestdrive':
		$("#popupBox").show();
		$("#overFlow").show();
		aligndiv('popupBox');
		var stuff = $.ajax({
			type: "GET",
			url: "_ajax_scheduleatestdrive.cfm?inventoryItemId="+inventoryItemId,
			data: "msg=",
			async: false
		}).responseText;
		$("#popupBox").html(stuff);		
	break;
	case 'finance':
	break;
	case 'viewebrochure':
	break;
	case 'emailafriend':
		$("#popupBox").show();
		$("#overFlow").show();
		aligndiv('popupBox');
		var stuff = $.ajax({
			type: "GET",
			url: "_ajax_emailafriend.cfm?inventoryItemId="+inventoryItemId,
			data: "msg=",
			async: false
		}).responseText;
		$("#popupBox").html(stuff);		
	break;
	case 'getdirections':
	break;	
	
	default:	
		//alert('Invalid');
	}



}


function submit_requirementInfo(){
	
	var ermsg="";
	$("#loading").show();
	
	var firstname=trima($("#firstname").val());
	var lastname=trima($("#lastname").val());
	var email=trima($("#email").val());
	var phone=trima($("#phone").val());
	var comment=trima($("#comment").val());
	
	comment=comment.replace(/'/g,"'");
	comment=comment.replace("?","");
	comment=comment.replace(/&/g," ");
	
	if(firstname == ""){
		ermsg="First name is required";
	}else if(email == ""){
		ermsg="Email is required";
	}else if(phone == ""){
		ermsg="Phone is required";
	}
	
	if(ermsg==""){	
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;   		
	   if(reg.test(email) == false) {    	 
		 ermsg="Invalid email";	
		}
	}
	
	if(ermsg ==""){
		urlVar ="";
		urlVar ="?from=requiremoreinfo";
		urlVar +="&firstname="+firstname;
		urlVar +="&lastname="+lastname;
		urlVar +="&email="+email;
		urlVar +="&phone="+phone;
		urlVar +="&comment="+comment;
		urlVar +="&invItem="+trima($("#invItem").val());
		urlVar +="&inventoryItemId="+trima($("#inventoryItemId").val());

		var stuff = $.ajax({
			type: "GET",
			url: "_ajax_more_email.cfm"+urlVar,
			data: "msg=",
			async: false
		}).responseText;
		
		$("#popupContent").html('<div style="margin:20px 0 80px 0;">Thank you for submitting your information! A dealership representative will be in contact with you shortly.</div>');
		
		$("#popupBox").fadeOut(8000);
		$("#overFlow").fadeOut(8000);
		
	}else{				
		$("#errorMsg").show();
		$("#errorMsg").html(ermsg);  
		$("#errorMsg").fadeOut(1500);
	}
	$("#loading").hide();
}



function submit_makeanoffer(){
	
	var ermsg="";
	$("#loading").show();
	
	var firstname=trima($("#firstname").val());
	var lastname=trima($("#lastname").val());
	var email=trima($("#email").val());
	var phone=trima($("#phone").val());
	var offer=trima($("#offer").val());
	
	if(firstname == ""){
		ermsg="First name is required";
	}else if(offer == ""){
		ermsg="Offer is required";	
	}else if(email == ""){
		ermsg="Email is required";
	}else if(phone == ""){
		ermsg="Phone is required";
	}
	
	if(ermsg==""){	
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;   		
	   if(reg.test(email) == false) {    	 
		 ermsg="Invalid email";	
		}
	}
	
	if(ermsg ==""){
		urlVar ="";
		urlVar ="?from=makeanoffer";
		urlVar +="&firstname="+firstname;
		urlVar +="&lastname="+lastname;
		urlVar +="&email="+email;
		urlVar +="&phone="+phone;
		urlVar +="&offer="+offer;
		urlVar +="&invItem="+trima($("#invItem").val());
		urlVar +="&inventoryItemId="+trima($("#inventoryItemId").val());

		var stuff = $.ajax({
			type: "GET",
			url: "_ajax_more_email.cfm"+urlVar,
			data: "msg=",
			async: false
		}).responseText;
		
		$("#popupContent").html('<div style="margin:20px 0 80px 0;">Thank you for submitting your offer to us. Our staff will get back to you promptly with a response to your request. </div>');
		
		$("#popupBox").fadeOut(8000);
		$("#overFlow").fadeOut(8000);
		
	}else{				
		$("#errorMsg").show();
		$("#errorMsg").html(ermsg);  
		$("#errorMsg").fadeOut(1500);
	}
	$("#loading").hide();
}



function submit_scheduleatestdrive(){
	
	var ermsg="";
	$("#loading").show();
	
	var firstname=trima($("#firstname").val());
	var lastname=trima($("#lastname").val());
	var email=trima($("#email").val());
	var phone=trima($("#phone").val());
	var dateTestDrive=trima($("#dateTestDrive").val());
	
	if(firstname == ""){
		ermsg="First name is required";
	}else if(email == ""){
		ermsg="Email is required";
	}else if(phone == ""){
		ermsg="Phone is required";
	}else if(dateTestDrive == ""){
		ermsg="Date for Test drive is required";
	}
	
	if(ermsg==""){	
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;   		
	   if(reg.test(email) == false) {    	 
		 ermsg="Invalid email";	
		}
	}
	
	if(ermsg ==""){
		urlVar ="";
		urlVar ="?from=scheduleatestdrive";
		urlVar +="&firstname="+firstname;
		urlVar +="&lastname="+lastname;
		urlVar +="&email="+email;
		urlVar +="&phone="+phone;
		urlVar +="&dateTestDrive="+dateTestDrive;
		urlVar +="&invItem="+trima($("#invItem").val());
		urlVar +="&inventoryItemId="+trima($("#inventoryItemId").val());

		var stuff = $.ajax({
			type: "GET",
			url: "_ajax_more_email.cfm"+urlVar,
			data: "msg=",
			async: false
		}).responseText;
		
		$("#popupContent").html('<div style="margin:20px 0 80px 0;">Thank you for submitting your information! A dealership representative will be in contact with you shortly. </div>');
		
		$("#popupBox").fadeOut(8000);
		$("#overFlow").fadeOut(8000);
		
	}else{				
		$("#errorMsg").show();
		$("#errorMsg").html(ermsg);  
		$("#errorMsg").fadeOut(1500);
	}
	$("#loading").hide();
}



function submit_emailafriend(){
	
	var ermsg="";
	$("#loading").show();
	
	var firstname=trima($("#firstname").val());
	var lastname=trima($("#lastname").val());
	var email=trima($("#email").val());
	var comment=trima($("#comment").val());
	var friendsfirstname=trima($("#friendsfirstname").val());
	var friendslastname=trima($("#friendslastname").val());
	var friendsemail=trima($("#friendsemail").val());
	
	comment=comment.replace(/'/g,"'");
	comment=comment.replace("?","");
	comment=comment.replace(/&/g," ");
	
	if(firstname == ""){
		ermsg="First name is required";
	}else if(email == ""){
		ermsg="Email is required";
	}else if(friendsfirstname == ""){
		ermsg="Friends first name is required";
	}else if(friendsemail == ""){
		ermsg="Friends email is required";
	}
	
	if(ermsg==""){	
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;   		
	   if(reg.test(email) == false) {    	 
		 ermsg="Invalid email";	
		}
	}
	
	if(ermsg==""){	
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;   		
	   if(reg.test(friendsemail) == false) {    	 
		 ermsg="Friends email is invalid";	
		}
	}
	
	if(ermsg ==""){
		urlVar ="";
		urlVar ="?from=emailafriend";
		urlVar +="&firstname="+firstname;
		urlVar +="&lastname="+lastname;
		urlVar +="&email="+email;
		urlVar +="&comment="+comment;
		urlVar +="&friendsfirstname="+friendsfirstname;
		urlVar +="&friendslastname="+friendslastname;
		urlVar +="&friendsemail="+friendsemail;
		urlVar +="&invItem="+trima($("#invItem").val());
		urlVar +="&inventoryItemId="+trima($("#inventoryItemId").val());

		var stuff = $.ajax({
			type: "GET",
			url: "_ajax_more_email.cfm"+urlVar,
			data: "msg=",
			async: false
		}).responseText;
		
		$("#popupContent").html('<div style="margin:20px 0 80px 0;">We have just E-Mailed the vehicle information to your friend.</div>');
		
		$("#popupBox").fadeOut(8000);
		$("#overFlow").fadeOut(8000);
		
	}else{				
		$("#errorMsg").show();
		$("#errorMsg").html(ermsg);  
		$("#errorMsg").fadeOut(1500);
	}
	$("#loading").hide();
}



function closePopup(){
	//$("#popupBox").fadeOut(5500);
	//$("#overFlow").fadeOut(5500);
		$("#popupBox").hide();
		$("#overFlow").hide();
}





/*var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();*/

function aligndiv(Myid){

var scrolledX, scrolledY;
if( self.pageYOffset ) {
  scrolledX = self.pageXOffset;
  scrolledY = self.pageYOffset;
} else if( document.documentElement && document.documentElement.scrollTop ) {
  scrolledX = document.documentElement.scrollLeft;
  scrolledY = document.documentElement.scrollTop;
} else if( document.body ) {
  scrolledX = document.body.scrollLeft;
  scrolledY = document.body.scrollTop;
}

// Determine the coordinates of the center of the page

var centerX, centerY;
if( self.innerHeight ) {
  centerX = self.innerWidth;
  centerY = self.innerHeight;
} else if( document.documentElement && document.documentElement.clientHeight ) {
  centerX = document.documentElement.clientWidth;
  centerY = document.documentElement.clientHeight;
} else if( document.body ) {
  centerX = document.body.clientWidth;
  centerY = document.body.clientHeight;
}

var leftOffset = scrolledX + (centerX - 250) / 2;
//var topOffset = scrolledY + (centerY - 250) / 2;
var topOffset = scrolledY + (centerY - 500) / 2;

topOffset +=100;

 document.getElementById(Myid).style.top = topOffset + "px";
	  
	  
}

function trima(str, chars) {
	return ltrima(rtrima(str, chars), chars);
}
 
function ltrima(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrima(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

