/*
 *  Project:    AD747
 *  Author(s):  Frank Oh
 *  Website:    www.it747.com
 *  Copyright:  This is the property of IT747.COM
 *              You are not allowed to change anything in this file
 *              without the permission of the owner.
 */



function
open_box( name )
{
    var w = open( '', name );
    w.focus();
}



function
win( name, msg )
{
    var w = window.open( '', name, '' );
    var d = w.document;

    d.open();
    d.write( msg );
    d.close();
}

function
dump_obj( obj )
{
    var msg = '';

    for ( var p in obj ) {
        msg += "<b>" + p + "</b>" + ": " + typeof( obj[ p ]) + ":" + obj[ p ] + "<br>" + "\n";
    }
    // alert( msg );
    win( 'dump', msg );

}

function
not_object( obj )
{
    var ret = false;

    if ( typeof( obj ) === typeof( 'string' ) ) {
        ret = true;
    }

    return ( ret );
}

function
get_object( obj )
{
    var o = obj;

    if ( not_object( o ) ) {
        var o = document.getElementById( o );
    }

    return ( o );
}

function
hide_object( obj )
{
    var o = get_object( obj );
    var style = o.style;

    style.visibility = 'hidden';
}

function
show_object( obj )
{
    var o = get_object( obj );
    var style = o.style;

    style.visibility = 'visible';

}
function
get_absolute_left( obj_id )
{
    var obj = get_object( obj_id );
    var left = obj.offsetLeft;

    while ( obj.offsetParent ) {
        var parent = obj.offsetParent;
        left += parent.offsetLeft;
        obj = parent;
    }

    return ( left );

}



function
get_absolute_top( obj_id )
{
    var obj = get_object( obj_id );
    var top = obj.offsetTop;

    while ( obj.offsetParent ) {
        var parent = obj.offsetParent;
        top += parent.offsetTop;
        obj = parent;
    }

    return ( top );
}



function
create_element( element )
{
    var body = document.getElementsByTagName( "body" ).item(0);

    body.appendChild( element );

    return;
}

function
delete_element( element )
{
    var body = document.getElementsByTagName( "body" ).item(0);

    body.removeChild( element );

    return;
}

function
create_div( name, top, left, width, height )
{
    // <div class="" id="" name="" style=""></div>
    var id = name;
    var element;
    var ele = document.getElementsByName( name ).item( 0 );

    if ( ele ) {
        element = ele;
    } else {
        element = document.createElement( "div" );
        element.setAttribute( "id", id );
        element.setAttribute( "name", id );
        element.setAttribute( "class", id );
    }



    var css = "";
    css  = " " + "position: absolute; z-index: 10; visibility: visible;";
    css += " " + "top: " + top + "px; left: " + left + "px;";
    css += " " + "width: " + width + "px; height: " + height + "px;";
    css += " " + "background-color: white;";
    element.style.cssText = css;

    if ( !ele ) create_element( element );

    return ( element );
}

function
delete_div( name )
{
    var elements = document.getElementsByName( name );
    var n = elements.length;

    for ( var i=0; i<n; i++ ) {
        delete_element( elements.item( i ) );
    }
    return;
}



function
show_it( left, top, target_obj_id )
{
    var obj = document.getElementById( target_obj_id );
    var style = obj.style;

    style.position   = 'absolute';
    style.left       = left + 'px';
    style.top        = top  + 'px'
    style.zIndex     = 255;
    style.visibility = 'visible';

}

function
hide_it( target_obj_id )
{
    hide_object( target_obj_id );
}



// resource: http://javascript.internet.com/forms/check-email.html
function
is_valid_email ( emailStr )
{
    var emailPat=/^(.+)@(.+)$/;
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
    var validChars="\[^\\s" + specialChars + "\]";
    var quotedUser="(\"[^\"]*\")";
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom=validChars + '+';
    var word="(" + atom + "|" + quotedUser + ")";
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

    var matchArray=emailStr.match(emailPat);
    if (matchArray==null) {
        return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];

    if (user.match(userPat)==null) {
        return false;
    }

    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {
        return false;
    }

    var domainArray=domain.match(domainPat)
    if (domainArray==null) {
        return false;
    }

    var atomPat=new RegExp(atom,"g");
    var domArr=domain.match(atomPat);
    var len=domArr.length;
    if (domArr[domArr.length-1].length<2 ||
        domArr[domArr.length-1].length>3) {
       return false;
    }

    if (len<2) {
       return false;
    }

    return true;
}

function
is_valid_number( param )
{
  var numbers = '0123456789';

  if ( param == "") return false;

  for (i=0; i<param.length; i++) {
    if ( numbers.indexOf( param.charAt(i), 0 ) == -1 ) return false;
  }
  return true;

}

function
pdf_view( href )
{
    var w = open( href, '', 'toolbar=no,scrollbars=yes,resizable=yes,width=800' );
    w.focus();
}



function
doc( href )
{
    var w = open( href, '', 'toolbar=no,scrollbars=yes,resizable=yes,width=650' );
    w.focus();

}



function
tour( href )
{
    var w = open( href, '', 'toolbar=no,scrollbars=yes,resizable=yes,width=650' );
    w.focus();

}



function
map( href )
{
    var w = open( href, 'map', 'toolbar=no,scrollbars=yes,resizable=yes,width=650' );
    w.focus();
}

function
loan( href )
{
    var w = open( href, 'loan', 'toolbar=no' );
    w.focus();

}

function
big_image( href, name )
{
    var w = open( href, 'big_image', 'toolbar=no,scrollbars=yes,resizable=yes,width=650' );

    if ( !name ) name='';

    var s = '';
    s += '<html><head><title>' + name + '</title></head><body>';
    s += '<h2>' + name + '</h2>' + '<hr>';
    s += '<img src="' + href + '" />';
    s += '</body></html>';

    w.document.write( s );
    w.document.close();
    w.focus();

}



function
result_window( window_name )
{
    if ( ! window_name ) {
        window_name = 'result';
    }
    var w = open( '', window_name, 'toolbar=no,scrollbars=yes,width=650' );
    w.focus();
}



function
show_info( show_info_id )
{
    var top  = get_absolute_top( g_show_area_id );
    var left = get_absolute_left( g_show_area_id );

    hide_all();
    show_it( left, top, show_info_id );

}

function
hide_info( hide_info_id )
{
    hide_it( hide_info_id );
}



// show / hide layered components
var g_show_area_id          = 'tools_area';
var g_tell_your_friend_id   = 'tell_your_friend';
var g_ask_agent_id          = 'ask_agent';
var g_print_listing_id      = 'print_listing';
var g_our_community_id      = 'our_community';
var g_floor_plans_id        = 'floor_plans';
var g_area_information_id   = 'area_information';
function
hide_all()
{
    hide_info( g_tell_your_friend_id );
    hide_info( g_ask_agent_id );
    hide_info( g_print_listing_id );
	hide_info( g_our_community_id );
	hide_info( g_floor_plans_id );
	hide_info( g_area_information_id );
}


function show_tell_your_friend() { tell_your_friend_reset(); show_info( g_tell_your_friend_id ); }
function hide_tell_your_friend() { hide_info( g_tell_your_friend_id ); }
function show_ask_agent() { ask_agent_reset(); show_info( g_ask_agent_id ); }
function hide_ask_agent() { hide_info( g_ask_agent_id ); }
function show_print_listing() { show_info( g_print_listing_id ); }
function hide_print_listing() { hide_info( g_print_listing_id ); }
function show_our_community() { show_info( g_our_community_id ); }
function hide_our_community() { hide_info( g_our_community_id ); }
function show_floor_plans() { show_info( g_floor_plans_id ); }
function hide_floor_plans() { hide_info( g_floor_plans_id ); }
function show_area_information() { show_info( g_area_information_id ); }
function hide_area_information() { hide_info( g_area_information_id ); }

/* vim: set expandtab sw=4 ts=4 sts=4: */

