var json = "";
var all_elements = new Array();

function clearConsultantForm() {
    $('askconsultant_form').reset();
    setTimeout("Dialog.cancelCallback();", 1500);
}

function clearConsultantForm1() {
    $('askconsultant_form').reset();
}

function open_img_dialog(image, title, width, height) {
    var win = new Window({className: "alphacube", width:width, height:height, title:"<b>"+title+"</b>",
                          maximizable: false, minimizable: false});
    win.getContent().update("<img onclick='Windows.closeAll();' src='"+image+"'/>");
    win.setDestroyOnClose();
    win.showCenter();
}

function menuAction(menuId, open) {
    var closeMenuId = "item_"+menuId+"_close";
    var openMenuId = "item_"+menuId+"_open";
    
    if (open) {
        $(closeMenuId).style.display = "none";
        $(openMenuId).style.display = "block";
        new Effect.Appear(openMenuId, {duration : 1, from: 0.0, to: 0.9 });
    } else {
        $(openMenuId).style.display = "none";
        $(closeMenuId).style.display = "block";
        new Effect.Appear(closeMenuId, {duration : 1, from: 0.0, to: 0.9 });
    }
}

function apply_menu_effect()
{
    new Effect.Appear("item_0_close", {duration : 0.5, from: 0.0, to: 0.9 });
    new Effect.Appear("item_1_close", {duration : 0.5, from: 0.0, to: 0.9 });
    new Effect.Appear("item_2_close", {duration : 0.5, from: 0.0, to: 0.9 });
    new Effect.Appear("item_3_close", {duration : 0.5, from: 0.0, to: 0.9 });
    new Effect.Appear("item_4_close", {duration : 0.5, from: 0.0, to: 0.9 });
}

function show_selected(obj) {
    $(obj).className='lmenu_selected';    
    var img = obj+"i";
    $(img).setAttribute("src", "/images/arrow3.jpg");
}

function hide_selected(obj) {
    $(obj).className='lmenu_item';    
    var img = obj+"i";
    $(img).setAttribute("src", "/images/arrow1.jpg");            
}

function change_arrow(obj) {
    var img = obj+"i";
    var div = obj+"d";
    var st = $(div).getStyle('display');
    if (st != "none") 
    {
        $(img).setAttribute("src", "/images/arrow.jpg");
    }else
    {
        $(img).setAttribute("src", "/images/arrow1.jpg");
    }
    return false;
}

function showEffect(id) {
    new Effect.Appear(id, {duration : 0.5, from: 0.0, to: 1 });
}

function getMouse(e) {
    e = e || window.event;
    var mouse = new Object();
        mouse.x = (e.pageX || e.clientX);
        mouse.y = (e.pageY || e.clientY);
    return mouse;
}

function getRandomNum(lbound, ubound)
{
    return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

function getRandomChar()
{
    var numberChars = "0123456789";
    var lowerChars = "abcdefghijklmnopqrstuvwxyz";
    var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
    var charSet = numberChars;
    charSet += lowerChars;
    charSet += upperChars;
  
    return charSet.charAt(getRandomNum(0, charSet.length));
}

function getPassword(length)
{
    var rc = "";
    if (length > 0)
        rc = rc + getRandomChar();
        
    for (var idx = 1; idx < length; ++idx)
    {
        rc = rc + getRandomChar();
    }
    return rc;
}

function generatePassword( destin_ids ) 
{
    var length = 8;
    var pwd = getPassword( length );
    for ( var i = 0; i < destin_ids.length; i++ )
        document.getElementById(destin_ids[i]).value = pwd;
}
