var YUD = YAHOO.util.Dom;
var YUE = YAHOO.util.Event;

function fillText(element, value){
	if (element.value == ""){
		element.value = value;
		YUD.setStyle(element,'color','#C4C4C4');
	}
	else if (element.value == value){
		element.value = "";
		YUD.setStyle(element,'color','#000000');
	} 
}

function loginUser() {
	var element = YUD.getElementsByClassName('error','span','login')[0];
	var t = setTimeout(function(){
			YUD.setStyle(element,'display','block');
		},420);
}

function toggleVisible(elementID) {
	var element = YUD.get(elementID);
	if(YUD.hasClass(element,'visible')) {
		YUD.removeClass(element,'visible');
	}
	else {
		YUD.addClass(element,'visible');
	}
}

function toggle_visibility(id, num) {
    var e = document.getElementById(id + num);
    if (e.style.display == 'block') {
        e.style.display = 'none';
        e.style.visibility = 'hidden';
    }
    else {
        e.style.display = 'block';
        e.style.visibility = 'visible';
    }
}


function designTable(tableID) {
	var tableRows = YUD.get(tableID).getElementsByTagName('tr');
	
	for (var i=0; i<tableRows.length; i++) {
		var lastTD = YUD.getLastChild(tableRows[i]);
		YUD.addClass(lastTD,'last');
	}
}

var allChecked = false;
function selectAll(wrapperID) {
	var selectBoxes = YUD.get(wrapperID).getElementsByTagName('input');
	if (!allChecked) {
		for (var i = 0; i < selectBoxes.length; i++) {
			selectBoxes[i].checked = true;
		}
		allChecked = true;
	}
	else {
		for (var i = 0; i < selectBoxes.length; i++) {
			selectBoxes[i].checked = false;
		}
		allChecked = false;
	}
}

var initImageScrollers = function(anchorID) {
  
    var anchorEl;
    if (typeof anchorID != 'undefined') {
        anchorEl = document.body;
    }
    else {
        anchorEl = anchorID;
    }
    var scrollers = YUD.getElementsByClassName('scroller_pager', 'div', anchorEl, function() {
        var prevButton = YUD.getElementsByClassName('lnk_prv', 'a', this)[0];
        var nextButton = YUD.getElementsByClassName('lnk_fwd', 'a', this)[0];

        var images = YUD.getPreviousSibling(this).getElementsByTagName('img');

        //hide buttons if no additional images found
        if (images.length < 2) {
            YUD.setStyle([prevButton, nextButton], 'visibility', 'hidden');
        }
        else {
            ///hide the additional images
            for (var i = 1; i < images.length; i++) {
                YUD.setStyle(images[i], 'display', 'none');
            }
        }
        var currentImage = 0;

        var prevImage = function() {
            if (currentImage > 0) {
                YUD.setStyle(images[currentImage], 'display', 'none');
                YUD.setStyle(images[currentImage - 1], 'display', 'block');
                currentImage = currentImage - 1;
            }
            else
                if (currentImage == 0) {
                YUD.setStyle(images[0], 'display', 'none');
                YUD.setStyle(images[images.length - 1], 'display', 'block');
                currentImage = images.length - 1;
            }
        }
        var nextImage = function() {
            YUD.setStyle(images[currentImage], 'display', 'none');
            if (currentImage < images.length - 1) {
                YUD.setStyle(images[currentImage + 1], 'display', 'block');
                currentImage = currentImage + 1;
            }
            else {
                YUD.setStyle(images[0], 'display', 'block');
                currentImage = 0;
            }
        }

        YUE.on(prevButton, 'click', prevImage);
        YUE.on(nextButton, 'click', nextImage);

    });
}
function initImageScrollersInIframe() {
	initImageScrollers('dynamicInwin');
}

function CookieHandler() {

    this.setCookie = function(name, value, seconds) {

        if (seconds != '' && typeof (seconds) != 'undefined') {
            var date = new Date();
            date.setTime(date.getTime() + (seconds * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else {
            var expires = "";
        }

        document.cookie = name + "=" + value + expires + "; path=/";
    }

    this.getCookie = function(name) {

        name = name + "=";
        var carray = document.cookie.split(';');

        for (var i = 0; i < carray.length; i++) {
            var c = carray[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }

        return null;
    }

    this.deleteCookie = function(name) {
        this.setCookie(name, "", -1);
    }

}

function deleteCookie(cookieName){
    var cookies = new CookieHandler();
    cookies.deleteCookie(cookieName);
}

function AddToCookie(element, cookieName, expireDays) {
    if (cookieName == "") {
        return;
    }
    if (element != null && element.getAttribute("id") != null && element.getAttribute("id") != "") {
        var id = element.getAttribute("id");
        var addedValue = id + "#";
        processCookie(addedValue, cookieName);
    }
}

function GetFromCookie(cookieName){
    var cookies = new CookieHandler();
    var existingValue = cookies.getCookie(cookieName);
    if (existingValue != null) 
        existingValue = unescape(existingValue);
    return existingValue;
}

function RemoveFromCookie(value, cookieName){
    var cookies = new CookieHandler();
    var existingValue = cookies.getCookie(cookieName);
    var newValue = "";
    if (existingValue != null) {
        existingValue = unescape(existingValue);
        if (existingValue.indexOf(value) >= 0) {
            newValue = existingValue.replace(value, '');
        }
    }    
    cookies.setCookie(cookieName, escape(newValue), '');
}

function processCookie(value, cookieName) {
    var cookies = new CookieHandler();
    var existingValue = cookies.getCookie(cookieName);
    var newValue = "";
    if (existingValue != null) {
        existingValue = unescape(existingValue);
        if (existingValue.indexOf(value) < 0) {
            newValue = existingValue + value;
        }
    }
    else {
        newValue = value;
    }

    if (newValue != "") {
        cookies.setCookie(cookieName, escape(newValue), '');
    }
}

function openPopup(url,w,h)
{
var left = Math.floor( (screen.width - w) / 2);
var top = Math.floor( (screen.height - h) / 2);
var cond = window.open(url, null, 'status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1, scrollbars=yes, height='+h+', width='+w+', top='+top+',left='+left);
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function validateContactForm(txtName, txtPhone, lstAreas, showAlert)
{
	var name = document.getElementById(txtName).value;
	var phone = document.getElementById(txtPhone).value;
	var area = document.getElementById(lstAreas).value;
	var result = true;
	var resultText = '';
	var reg = /^(\d{4,7})$/;
	var br = showAlert ? "\n" : "<br />";

	if(name==''){
		resultText += 'נא ציין שם ושם משפחה' + br;
		result = false;
	}
	if(phone==''){
		resultText += 'נא ציין טלפון או טלפון נייד' + br;
		result = false;
	}
	else if(!reg.test(phone)){
		resultText += 'מספר טלפון לא תקין' + br;
		result = false;
	}
	if(area=='בחר אזור'){
		resultText += 'נא בחר אזור בארץ' + br;
		result = false;
	}

	if(!result){
		if(!showAlert)
		showError(resultText);
		else
		alert(resultText);
	}
	return result;
}

function prepareContactForm(txtName, txtPhone, lstAreas, txtInterested, lstDialingRegion, nameId, phoneId, areasId, interestedId, showAlert)
{
    if(validateContactForm(txtName, txtPhone, lstAreas, showAlert))
    {
        document.getElementById(nameId).value = document.getElementById(txtName).value;
        document.getElementById(phoneId).value = document.getElementById(lstDialingRegion).value + "-" + document.getElementById(txtPhone).value;
        document.getElementById(areasId).value = document.getElementById(lstAreas).value;
        document.getElementById(interestedId).value = document.getElementById(txtInterested).value;
        
        return true;
    }
    
    return false;
}

//init TooltipManager
function initToolTips() {
    var tooltips = YUD.getElementsByClassName("tooltip_link","a",document.body,function(){
		var tooltipWindow = YUD.getNextSibling(this); 
		
		YUE.on(this,"mouseover", function(){
            YUD.setStyle(tooltipWindow,"display","block");
        });
        
        YUE.on(this,"mouseout", function(){
            YUD.setStyle(tooltipWindow,"display","none");
        });
        
        if(YAHOO.env.ua.ie > 0) {
			YUD.setStyle(tooltipWindow.parentNode,"zoom","1");
        }
    });			
}

var win= null;
function newWindow(mypage,myname,w,h,scroll){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=no';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
//onclick="newWindow('link.html','terms','560','500','auto'); return false" OR
//<a href="link.html" onclick="newWindow(this.href,'terms','560','500','auto'); return false">...</a>

function fixTable(tableID, tdClass) {
	var wrapper = YUD.get(tableID);
	var myOffsetHeights = new Array();
	
	var fixTDs = YUD.getElementsByClassName(tdClass, '', wrapper);
	
	for (var j=0; j< fixTDs.length; j++) {
		myOffsetHeights[j] = fixTDs[j].offsetHeight;
		if (fixTDs[j].innerHTML == "") {
			fixTDs[j].innerHTML = "&nbsp";
		}
	}

	var maxOffsetHeight = maxValue(myOffsetHeights);
	
	if(YAHOO.env.ua.ie > 0) {
		maxOffsetHeight = maxOffsetHeight - 24;
	}
	YUD.setStyle(fixTDs, 'height', maxOffsetHeight +'px');

}

function maxValue(array) {
	mxm = array[0];
	for (i=0; i<array.length; i++) {
		if (array[i]>mxm) {
			mxm = array[i];
			}
		}
	return mxm;
};

function fixCheckboxes() {
	var selectBoxes = YUD.getElementsByClassName('type_checkbox', 'input', document.body, function(){
		YUE.on(this, 'click', function(event){
			YUE.stopPropagation(event);
		})
	})
}
/********************************************************************************************************/
var _car = function()
{
    return {
        
    } // Return
} // Car

var car = new _car();
/********************************************************************************************************/
car.pages = function()
{
    return {
        firsthand: function()
        {
            var _me, _rows = {}, cookieName;
            
            return {
                init: function(cookieName)
                {
                    _me = this;                    
					_cookieName = cookieName;
		            _me.initRows();
    		        
                },
                     
		        initRows: function()
		        {
		            var rows = YUD.getElementsByClassName("row");
    		       
		            for (var i = 0; i < rows.length; i++) {
					    _me.initRow(rows[i]);
		            }
		        },
    		    
		        initRow: function(element)
		        {
		            var id = element.id;
				    if (id != "") {
				        var row = {
				            "element": element,
				            "id": id,
				            "details": YUD.get(id + "_details")
				        };
				        
				        row.close = YUD.getElementsByClassName("btn_close", "", row.details)[0];
				        
					    YUE.on(row.element, "click", function(event) {
							    _me.toggleDetailsVisible(row);
								AddToCookie(this,_cookieName,1);
						    });
    			        
					    YUE.on(row.close, "click", function(event) {
							    _me.hideDetails(row);
						    });
						   
						YUE.on(row.element, "mouseover", function() {
							    YUD.addClass(this, "hover");
						    });
						
						YUE.on(row.element, "mouseout", function() {
							    YUD.removeClass(this, "hover");
						    });  
						    
						// Keep data.
						_rows[row.id] = row;
						
				    }
		        },
		       
		        toggleDetailsVisible: function(row)
		        {
		            if(YUD.hasClass(row.element, "active"))
		            {
		               YUD.replaceClass(row.details, "opened", "closed"); 
		               YUD.removeClass(row.element, "active");
		               YUD.addClass(row.element, "visited");
		            }
		            else
		            {
		                YUD.replaceClass(row.details, "closed", "opened"); 
		                YUD.addClass(row.element, "active");
//		                var test = YUD.getElementsByClassName("imgWrap");
//		                YUD.setStyle(YUD.get(test),"zoom",1);
		            }		        
		        },
    		
			    hideDetails: function(row)
			    {
				    YUD.removeClass(row.details, "opened");
				    YUD.addClass(row.details, "closed");
				    YUD.removeClass(row.element, "active");
			    },
    		
			    showDetails: function(row, jumpTo)
			    {
				    YUD.addClass(row.details, "opened");
				    YUD.removeClass(row.details, "closed");
				    YUD.addClass(row.element, "active");
				    
				    if (jumpTo)
				    {
				        window.location = "#" + row.id + "_a";
				    }
			    }		    
            } // Return
        }() // Firsthand
    } // Return
}(); // Pages

//set top offset of inwin
var topOffset = 80;

//inwin object
function Inwin() {

	var self = this,
		panel,
		inwinWidth,
		inwinHeight,
		currentCssClass = "";
	
	panel = new YAHOO.widget.Panel('dynamicInwin', 
	{ 	
		fixedcenter:false, 
		close:true, 
		draggable:false, 
		zindex:4,
		iframe:true,
		monitorresize:false,
		modal:true,
		visible:false,
		underlay:"none"
	});
	
	panel.setBody('');
	panel.render(document.body);
	
	inwinEl = YUD.get('dynamicInwin');
	inwinWrap = YUD.get('dynamicInwin_c');
	
	this.blankInInwin = function() {
		YUD.setStyle(inwinWrap, 'display', 'block');
		panel.show();
	}
	
	this.blankOutInwin = function(){
		YUD.setStyle(inwinWrap, 'display', 'none');
		panel.hide();
	}
	
	this.close = function(){
		panel.hide();
		panel.setBody('');
		return false;
	}
	
	this.openInwin = function(cfg){
		//inwin default size
		var size = cfg.inwinSize;
		if((typeof size == 'undefined') || size == "small") {
			inwinWidth = "404px";
			inwinHeight = "448px";
		}
		
		//big
		else if(size == "big") {
			inwinWidth = "914px";
			inwinHeight = "614px";
		}
		
		//custom class
		YUD.replaceClass(inwinEl,currentCssClass, cfg.cssClass);

		currentCssClass = cfg.cssClass;
		panel.cfg.setProperty("width", inwinWidth);
		//panel.cfg.setProperty("height", inwinHeight);
		
		panel.setBody(cfg.inwinContent);
		
		self.reposition();
		
		//run custom JS function on inwin content
		if(typeof cfg.jsFunction != 'undefined') {
			cfg.jsFunction.call();
		}
		
		self.blankInInwin();
	}
	
	this.reposition = function() {
		
		// x
		var viewportWidth = YUD.getViewportWidth();
		var newX = (viewportWidth - parseInt(inwinWidth,10))/2 - 20;
		YUD.setStyle(inwinWrap,'left',newX+'px');
		
		//y
		var scrollTop = YUD.getDocumentScrollTop();		
		var newY = (scrollTop + topOffset);
		YUD.setStyle(inwinWrap,'top',newY+'px');
	}
}

//attach event to map buttons
function initMapInwins() {
	var mapButtons = YUD.getElementsByClassName('btn_map','a','branches',function() {
		
			YUE.on(this, 'click' , function(event) {
					inwin.openInwin({
							inwinContent:"<span class=\"frame\"></span><img src=\""+this.href+"\" alt=\""+this.title+"\"/>" , 
							cssClass: 'map_inwin'
							//jsFunction: inwinFunction_1
						});
					
					YUE.preventDefault(event);
				});
		});
}

//personal deal inwin
function initPersonalDealInwin(id) {
	var obj = document.getElementById(id);
	YUE.on('mailme', 'click' , function(event) {
	
		// Fix for IE7: We first want to delete the object from inside the inwin if it exists there,
		// and only then look for it in the html, in order to make sure we use the original object
		// and not its duplicate.
		var inwin_bd = YUD.getElementsByClassName("bd")[0];
		inwin_bd.innerHTML = "";
		obj = document.getElementById(id);
		
		// Open the inwin.
		inwin.openInwin({
			inwinContent:obj.innerHTML,
			cssClass: 'sendme_inwin'
		});
		
		YUE.preventDefault(event);
	});
}

//error inwin
function showError(msg) {
	inwin.openInwin({
		inwinContent:"<div class=\"inwin_t\"></div><div class=\"inwin_m\" ><p class=\"title\">שימו לב!</p><p>" + msg + "</p><div class=\"clearfix\"></div></div><div class=\"inwin_b\"></div>",
		cssClass: 'mailme_inwin'
	});
}

function inwinTable() {
	inwin.openInwin({
		inwinSize:'small',
		inwinContent: inwinTableContent,
		cssClass: 'inwin tblinfo_inwin'
	});
}

function initSpecialButtons() {
	// Get all special items.
	var items = YUD.getElementsByClassName("item", "div", "special");
	
	// Loop through all items.
	for (var i = 0; i < items.length; i++)
	{
		initSpecialButton(items[i]);
	}
}

function initSpecialButton(item) {
	// Get image link.
	var image = YUD.getElementsByClassName("image", "a", item)[0];
	
	// Get details link.
	var details = YUD.getElementsByClassName("btn_details", "a", item)[0];
	
	// Get hidden content
	var hiddenContent = YUD.getElementsByClassName("hidden_content", "div", item)[0];
	
	if (hiddenContent) {
		// Add listeners.
		YUE.on([image, details], "click", function(e, args) {
				// Find out if images srcs are set.
				var imgs = YUD.getElementsByClassName("my_image", "img", hiddenContent);
				if (imgs.length > 0 && (imgs[imgs.length-1].src == undefined || imgs[imgs.length-1].src == ""))
				{
					// Postpone opening the inwin in one second.
					setTimeout(
						function()
						{
							inwin.openInwin({
								inwinSize:'big',
								inwinContent: hiddenContent.innerHTML,
								cssClass: 'specialinwin',
								jsFunction: initImageScrollersInIframe
							});
						},
						500);
				}
				else
				{
					// Open the inwin.
					inwin.openInwin({
						inwinSize:'big',
						inwinContent: hiddenContent.innerHTML,
						cssClass: 'specialinwin',
						jsFunction: initImageScrollersInIframe
					});
				}
			});
	}
}

//dropdown menu object
function DropDown(){
    var element;
    var container;
	var self = this;
	var height;

    this.init = function(dropdownId, liHeight){
        element = YUD.get(dropdownId);
		
        var buttonEl = YUD.getElementsByClassName("nav_main_link", "a", element)[0];
        button = new Button(buttonEl);
        
        var containerEl = YUD.getElementsByClassName("submenu", "DIV", element)[0];
		
        container = new Container(containerEl, liHeight);
        
        var linkEl = YUD.getElementsByClassName("link", "a", element)[0];
        linkEl = new Link(linkEl);
    }
    
    function Button(buttonEl){
        var self = this,
            element = buttonEl;
                
		YUE.addListener(element, "mouseover", function(){
			container.open();
        });
		
		YUE.addListener(element, "mouseout", function(event){
			if (!YUD.isAncestor(this.parentNode, YUE.getRelatedTarget(event))) {
                container.close();
            }
        });
    }
   
   function Link(linkEl) {            
        YUE.addListener(linkEl, "mouseout", function(event){
			if (!YUD.isAncestor(this.parentNode, YUE.getRelatedTarget(event))) {
				container.close();
			}
		});
   }
    
    function Container(containerEl, liHeight){
        var self = this,
            element = containerEl,
            itemArr = [],
		    dropdown_list = YUD.getElementsByClassName("submenu_list", "UL", element)[0],
		    isOpen = false,
		    durration = 0.1; // in seconds

		YUE.addListener(element, "mouseout", function(event){
			if (!YUD.isAncestor(this.parentNode, YUE.getRelatedTarget(event))) {
                self.close();
            }
		});
		
		YUE.addListener(element, "mouseover", function(event){
			if (!YUD.isAncestor(this.parentNode, YUE.getRelatedTarget(event))) {
                self.open();
            }
		});
			
		var countElements = containerEl.getElementsByTagName("li");
		
		//add class "last" to the last LI of the dropdown menu (for rounded corners)
		YUD.addClass(countElements[countElements.length-1],'last');
		
		this.height = countElements.length*liHeight;
		durration = durration*countElements.length;
		
	    var openAnimAttributes = {height: {to: this.height}} 
        var closeAnimAttributes = {height: {to: 0}}
                    
        var openAnim = new YAHOO.util.Anim(element, openAnimAttributes, durration, YAHOO.util.Easing.easeOut);
		openAnim.onStart.subscribe(function(){
			YUD.addClass(element.parentNode, 'open');
		});

		openAnim.onComplete.subscribe(function(){
			isOpen = true;
		}); 
		
		var closeAnim = new YAHOO.util.Anim(element, closeAnimAttributes, durration*0.5);
		
		closeAnim.onComplete.subscribe(function(){
			isOpen = false;
			YUD.removeClass(element.parentNode, 'open');
		}); 
        
        this.open = function(){
            if(!isOpen){
				openAnim.animate();
            }
            else{
				closeAnim.stop();
				openAnim.animate();                
            }
        }
        
        this.close = function(){
			if (isOpen){
				closeAnim.animate();
			}
			else if (openAnim.isAnimated()) {
				openAnim.stop();
				closeAnim.animate();			
			}			
        }
    }
}
//initialize the menu
YUE.onDOMReady(function(){
    var liHeight = (YAHOO.env.ua.ie === 6) ? 27 :29;
	var dd1 = new DropDown();
	//the ID of the LI element, wrapping the menu
	dd1.init('nav_search', liHeight);

	var dd3 = new DropDown();
	dd3.init('nav_LeasingArticles', liHeight);
	
	//the ID of the LI element, wrapping the menu
	//var dd2 = new DropDown();
	//dd2.init('nav_about', liHeight);
});


function fixIE6(){
    YUD.getElementsByClassName('f_ckie6','',document.body,function(){
            YUD.setStyle(this,'zoom','');
            YUD.setStyle(this,'zoom','1');
        });
}

function openItemByUrlAnchor() {
	var urlQuery=location.href.split("#");
	var itemID = urlQuery[1];
	var pos = (location.href.indexOf("pos=1") > -1) ? 1 : 2;
	
	if (typeof itemID != 'undefined')
	{
		// Open an item in the specials section.
		if (pos == 1)
		{
			itemID = itemID.replace("id_", "");
			/*
			// Get special item.
			var item = YUD.get("special_" + itemID);
			
			// Get hidden content
			var hiddenContent = YUD.getElementsByClassName("hidden_content", "div", item)[0];
			
			inwin.openInwin({
				inwinSize:'big',
				inwinContent: hiddenContent.innerHTML,
				cssClass: 'specialinwin',
				jsFunction: initImageScrollersInIframe
			});*/			
			
			// Simulate click.			
			var link = document.getElementById("specials_link_" + itemID);
			simulateEvent("click", link);
		}
		else // Open an item in the main table.
		{
			YUD.addClass(itemID, 'active');
			YUD.addClass(itemID + '_details', 'opened');
			YUD.removeClass(itemID + "_details", "closed");
		}
	}
}

function jumpToTop(top) {
	if (location.href.indexOf("#top") != -1 && location.href.indexOf("#top_") == -1) {
		top = (top == undefined) ? 550 : top;
		window.scroll(0,top);
	}
}

function simulateEvent(eventType, targetElement) {
    var event;
    
    if (targetElement) {
     // check for IE
     if (window.ActiveXObject) {
         event = document.createEventObject();
         targetElement.fireEvent("on"+eventType,event);
     } else {
         switch (eventType) {
             case "abort":
             case "blur":
             case "change":
             case "error":
             case "focus":
             case "load":
             case "reset":
             case "resize":
             case "scroll":
             case "select":
             case "submit":
             case "unload":
                 event = document.createEvent("HTMLEvents");
                 event.initEvent(eventType, "true", "true");
                 break;
             case "click":
             case "mousedown":
             case "mousemove":
             case "mouseout":
             case "mouseover":
             case "mouseup":
                 event = document.createEvent("MouseEvents");
                 event.initMouseEvent(eventType, true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
                 break;
         }
         targetElement.dispatchEvent(event);
     }
    }
};
/*
onerror = function(e)
{
alert(e);
}
*/
function printCarDetails(url)
{
    openPopup(url, 580, 500);    
};

function emailCarDetails(carId)
{
    document.getElementById("sendCarId").value = carId;
    var inwin_bd = YUD.getElementsByClassName("bd")[0];
    inwin_bd.innerHTML = "";
    obj = document.getElementById("emailCarDetailsInwin");
	
    // Open the inwin.
    inwin.openInwin({
        inwinContent:obj.innerHTML,
        cssClass: 'email_car_details_inwin'
    });
};

/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj){
    var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length>mlength)
        obj.value=obj.value.substring(0,mlength)
}

function RedirectTo(path) {
    location.href = path;
}


//Disable Submit on Enter key press
function noenter() {
    return !(window.event && window.event.keyCode == 13);
}
