function clickButton(e, buttonid) { 
    var bt = document.getElementById(buttonid); 
    if(typeof bt == 'object') { 
      	if(navigator.appName.indexOf("Netscape")>(-1)) { 
        	if(e.keyCode == 13) { 
          		bt.click(); 
          		return false; 
        	} 
      	} 
      	if(navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)) { 
        	if(event.keyCode == 13) { 
          		bt.click(); 
          		return false; 
        	} 
      	} 
    } 
}

function openPopup(passedUrl, passedWidth, passedHeight) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(passedUrl,'" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + passedWidth + ',height=' + passedHeight);");
}

function openGoDaddyPopup(passedUrl) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(passedUrl,'" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=536,height=433');");
}

function checkNCForm() {
    errMessage = "";

    if(document.getElementById('ddlMake').selectedIndex == 0) {
        errMessage += "Please select a make.\n";
    }
    if(document.getElementById('ddlModel').selectedIndex == 0) {
        errMessage += "Please select a model.\n";
    }
    if (!IsZipcode(document.getElementById('NCcustomer_address_zip_input').value)) {
        errMessage += "Please enter a valid zip code.\n";
    }

    if(errMessage != "") {
        errMessage = "Please Fix the follow Field(s):\n\n" + errMessage;
        alert(errMessage); 
        return false; 
    } 
    
    return true; 
} 

function replaceMainImage(newImage, newDesc) {
    document.getElementById('mainImage').src = newImage;
    document.getElementById('ImageDesc').innerHTML = "- " + newDesc;
}

function change_images(EVOX_IMAGE_PATH) 
{
    currentPhotoIndex = document.getElementById('bodyStyles').selectedIndex;
    
    htmlOutput = '<table cellspacing="3" cellpadding="0" border="0"><tr>';
    var columnCounter = 0;  
    if (photoArray[currentPhotoIndex].length != 0) 
    {
        for (var i = 0; i < photoArray[currentPhotoIndex].length; i++) 
        {
            if (i == 0)
                replaceMainImage(EVOX_IMAGE_PATH + photoArray[currentPhotoIndex][i]['photo'], photoArray[currentPhotoIndex][i]['desc']);
            
            htmlOutput += '<td><a href="javascript:;" onmouseover="Tip(\'' + photoArray[currentPhotoIndex][i]['desc'] + '\');" onmouseout="UnTip();" onclick="replaceMainImage(\'' + EVOX_IMAGE_PATH + photoArray[currentPhotoIndex][i]['photo'] + '\', \'' + photoArray[currentPhotoIndex][i]['desc'] + '\')"><img src="http://media.trafficdriver.com/' + photoArray[currentPhotoIndex][i]['photo'] + '" border="0" width="80" height="60" class="Image_Vehicle" onmouseover="this.className=\'Image_Vehicle_Selected\'" onmouseout="this.className=\'Image_Vehicle\'" /></a></td>'
            
            columnCounter += 1;
            if (columnCounter == 6) 
            {
                htmlOutput += '</tr><tr>';
                columnCounter = 0;
            }
        }
    } 
    else 
    {
        htmlOutput += '<td class="Copy_Small_Bold"><br />No Photos Available for the Search Criteria.<br /><br /></td>';
    }
    htmlOutput += '</tr></table>';
    
    document.getElementById('ImageThumbNails').innerHTML = htmlOutput;			
}

function replaceMainVideo(file) {
    var ext = file.substr(file.length - 3, 3);
    ext = ext.toLowerCase();
    if (ext == 'swf') {
    	document.getElementById('Evox360').innerHTML = '<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\'codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\'width=\'320\' height=\'240\' id=\'movie\'><param name=\'movie\' value=\'' + file + '\'><embed src=\'' + file + '\' quality=\'high\' width=\'320\'height=\'240\' name=\'movie\' align="" type=\'application/x-shockwave-flash\'plug inspage=\'http://www.macromedia.com/go/getflashplayer\'></object>';
        //document.getElementById('Evox360').innerHTML = '<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\'codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\'width=\'320\' height=\'240\' id=\'movie\' align=""><param name=\'movie\' value=\'' + file + '\'><embed src=\'' + file + '\' quality=\'high\' width=\'320\'height=\'240\' name=\'movie\' align="" type=\'application/x-shockwave-flash\'plug inspage=\'http://www.macromedia.com/go/getflashplayer\'></object>';			
    } else if (ext == 'mov') {
        document.getElementById('Evox360').innerHTML = '<embed src=\'' + file + '\' width="320" height="256" controller="true"></embed>';
    } else {
        document.getElementById('Evox360').src = file;
    }
}

function change_videos() 
{
    currentPhotoIndex = document.getElementById('bodyStyles').selectedIndex;
    
    htmlOutput = '';
    var columnCounter = 0;
    if (photoArray[currentPhotoIndex].length != 0) {
        for (var i = 0; i < photoArray[currentPhotoIndex].length; i++) {
            if (i == 0) {
                replaceMainVideo('http://media.automotive.com' + photoArray[currentPhotoIndex][i]['video']);
            }
            htmlOutput += '<table><tr><td class="Copy_Small">';
            htmlOutput += '<a class="Link_Normal_Bold" href="javascript:;" onclick="replaceMainVideo(\'http://media.trafficdriver.com' + photoArray[currentPhotoIndex][i]['video'] + '\')">' + photoArray[currentPhotoIndex][i]['desc'] + '</a><br />'
            if (photoArray[currentPhotoIndex][i]['desc'] == 'Exterior QuickTime 360') {
                htmlOutput += 'You must have the <a class="Link_Normal" href="http://www.apple.com/quicktime/download/win.html" target="_blank">QuickTime Plug-in</a> to view.';
            } else if (photoArray[currentPhotoIndex][i]['desc'] == 'Interior QuickTime 360') {
                htmlOutput += 'You must have the <a class="Link_Normal" href="http://www.apple.com/quicktime/download/win.html" target="_blank">QuickTime Plug-in</a> to view.';
            } else if (photoArray[currentPhotoIndex][i]['desc'] == 'Exterior Flash 360') {
                htmlOutput += 'You must have the <a class="Link_Normal" href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Flash Plug-in</a> to view.';
            } else if (photoArray[currentPhotoIndex][i]['desc'] == 'Interior Flash 360') {
                htmlOutput += 'You must have the <a class="Link_Normal" href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Flash Plug-in</a> to view.';
            }
            htmlOutput += '</td></tr></table>'
    
            columnCounter += 1;
            if (columnCounter == 6) {
                htmlOutput += '</tr><tr>';
                columnCounter = 0;
            }
        }
    } else {
        htmlOutput += '<div class="Copy_Small_Bold" align="center"><br />No 360 Photos Available for the Search Criteria.</div>';
    }    
    document.getElementById('ImageThumbNails').innerHTML = htmlOutput;			
}

function replaceMainColor(newImage) {
    document.getElementById('mainImage').src = newImage;
}

function change_colors(PAINT_COLOR_IMAGE_PATH) 
{
    currentPhotoIndex = document.getElementById('bodyStyles').selectedIndex;
    
    htmlOutput = '<table cellspacing="3" cellpadding="0" border="0" align="center"><tr>';
    var columnCounter = 0;
    if (photoArray[currentPhotoIndex].length != 0) {
        for (var i = 0; i < photoArray[currentPhotoIndex].length; i++) {
            if (i == 0) {
                replaceMainColor(PAINT_COLOR_IMAGE_PATH + photoArray[currentPhotoIndex][i]['url']);
            }
    
            htmlOutput += '<td style="border:1px solid black;" onmouseover="Tip(\'' + photoArray[currentPhotoIndex][i]['desc'] + '\');" onmouseout="UnTip();"><a href="javascript:;" onclick="replaceMainColor(\'' + PAINT_COLOR_IMAGE_PATH + photoArray[currentPhotoIndex][i]['url'] + '\')"><img src="/images/spacer.gif" border="0" width="80" height="60" style="background-color:RGB(' + photoArray[currentPhotoIndex][i]['r'] + ',' + photoArray[currentPhotoIndex][i]['g'] + ',' + photoArray[currentPhotoIndex][i]['b'] + ');" /></a></td>';
    
            columnCounter += 1;
            if (columnCounter == 6) {
                htmlOutput += '</tr><tr>';
                columnCounter = 0;
            }
        }
    } else {
        htmlOutput += '<td align="center" class="Copy_Small_Bold"><br />No Photos Available for the Search Criteria.<br /><br /></td>';
    }
    htmlOutput += '</tr></table>';
    
    document.getElementById('ImageThumbNails').innerHTML = htmlOutput;			
}

function display_review_section(review_order) {
    for (var i = 0; i < review_section_list.length; i++) {
        if (review_order == review_section_list[i]) {
            document.getElementById('Review_Section_' + review_section_list[i]).style.display = "";
        } else {
            document.getElementById('Review_Section_' + review_section_list[i]).style.display = "none";
        }
    }
}

function display_vehicle_spec(trim_id) {
    for (var i = 0; i < vehicle_spec_list.length; i++) {
        if (trim_id == vehicle_spec_list[i]) {
            document.getElementById('Vehicle_Spec_' + vehicle_spec_list[i]).style.display = "";
        } else {
            document.getElementById('Vehicle_Spec_' + vehicle_spec_list[i]).style.display = "none";
        }
    }
}

function check_new_car_form() 
{
    errMessage = "";

    if(document.getElementById('ddlNewMake').selectedIndex == 0)
        errMessage += "Please select a make.\n";
    if(document.getElementById('ddlNewModel').selectedIndex == 0)
        errMessage += "Please select a model.\n";
    if (!IsZipcode(document.getElementById('customer_address_zip_new_input').value))
        errMessage += "Please enter a valid zip code.\n";

    if(errMessage != "") 
    {
        errMessage = "Please Fix the follow Field(s):\n\n" + errMessage;
        alert(errMessage); 
        return false; 
    } 
    
    return true; 
} 

function check_used_car_form() 
{
    errMessage = "";

    if(document.getElementById('ddlUsedMake').selectedIndex == 0)
        errMessage += "Please select a make.\n";
    if(document.getElementById('ddlUsedModel').selectedIndex == 0)
        errMessage += "Please select a model.\n";
    if (!IsZipcode(document.getElementById('customer_address_zip_used_input').value))
        errMessage += "Please enter a valid zip code.\n";

    if(errMessage != "") 
    {
        errMessage = "Please Fix the follow Field(s):\n\n" + errMessage;
        alert(errMessage); 
        return false; 
    } 
    
    return true; 
}