﻿function Toyota_SaveNewPageWithTitle(titleElementId) 
{
    // find the title element
    if(!window.Page_ClientValidate || Page_ClientValidate()) {
        var titleInput = document.getElementById(titleElementId);
        var displayName = titleInput.value
        var name = CreateValidName(displayName);
     
        window.WBC_setNewPageInfo(name, displayName);  
        //window.WBC_setNewPageInfo('untitled', 'untitled'); 
        window.WBC_doAuthoringNewSaveAndExit();
    }
}

function CreateValidName(value) 
{
    return value;
}

function findElement(elementId, d) {
    d = (!d) ? document : d;
    // TODO: make browser friendly
    return d.getElementById(elementId);
}


function getElementLeft( element ) {
    xPos = element.offsetLeft;
    tempEl = element.offsetParent;
    while (tempEl != null) {
	    xPos += tempEl.offsetLeft;
	    tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getElementTop( element ) {
    yPos = element.offsetTop;
    tempEl = element.offsetParent;
    while (tempEl != null) {
	    yPos += tempEl.offsetTop;
	    tempEl = tempEl.offsetParent;
    }
    return yPos;
}    

function showMenu( menuName ) 
{
    //var dropdown = findElement(menuName);
    //dropdown.style.visibility = "visible";
    //dropdown.style.left = getElementLeft(dropdown.parentNode) + "px";
    //dropdown.style.top = (getElementTop(dropdown.parentNode) + 25) + "px";
    //dropdown.style.display = "block";
}

function hideMenu(menuName) 
{
    var dropdown = findElement(menuName);
    dropdown.style.visibility = "hidden";
    dropdown.style.display = "none";
    
}


function NewWindow(mypage, myname, w, h, scroll) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function selectUsedVehicleImage(carImage, mainImageId)
{
    document.getElementById(mainImageId).src = carImage;
    return true;
}