/* #################################################################
    Copyright 2005 BBB Systems, LLC, All rights reserved
################################################################## */

//format: html_id > type
var ajaxTabList = new Array( );

//don't forget to update the number in the loop
for(var i = 0; i < 18; i++){ ajaxTabList[i] = new Object( ); }
ajaxTabList[0].html_id = 'homeArticlesMenu';
ajaxTabList[0].ajax_type = 'articles_news';
ajaxTabList[1].html_id = 'homeNewsMenu';
ajaxTabList[1].ajax_type = 'news';
ajaxTabList[2].html_id = 'homePoliticsMenu';
ajaxTabList[2].ajax_type = 'politics';
ajaxTabList[3].html_id = 'homeRadioMenu';
ajaxTabList[3].ajax_type = 'radio';
ajaxTabList[4].html_id = 'homeDiscussionsMenu';
ajaxTabList[4].ajax_type = 'articles';
ajaxTabList[5].html_id = 'politicsCandidatesMenu';
ajaxTabList[5].ajax_type = 'candidates';
ajaxTabList[6].html_id = 'politicsCongressmenMenu';
ajaxTabList[6].ajax_type = 'congressmen';
ajaxTabList[7].html_id = 'politicsRepresentativesMenu';
ajaxTabList[7].ajax_type = 'representatives';
ajaxTabList[8].html_id = 'politicsStateRepresentativesMenu';
ajaxTabList[8].ajax_type = 'state_representatives';
ajaxTabList[9].html_id = 'politicsAllRepresentativesMenu';
ajaxTabList[9].ajax_type = 'all_representatives';
ajaxTabList[10].html_id = 'politicsSenatorsMenu';
ajaxTabList[10].ajax_type = 'senators';
ajaxTabList[11].html_id = 'politicsStateSenatorsMenu';
ajaxTabList[11].ajax_type = 'state_senators';
ajaxTabList[12].html_id = 'politicsAllSenatorsMenu';
ajaxTabList[12].ajax_type = 'all_senators';
ajaxTabList[13].html_id = 'politicsStateLegHouseMenu';
ajaxTabList[13].ajax_type = 'state_leg_house';
ajaxTabList[14].html_id = 'politicsStateLegSenateMenu';
ajaxTabList[14].ajax_type = 'state_leg_senate';
ajaxTabList[15].html_id = 'travelAttractionsMenu';
ajaxTabList[15].ajax_type = 'attractions';
ajaxTabList[16].html_id = 'moviesTrailersMenu';
ajaxTabList[16].ajax_type = 'movies';
ajaxTabList[17].html_id = 'dirTabs';
ajaxTabList[17].ajax_type = 'dir';

var scoreKey = -1;
var scoresPaused = false;

var rotator_stopped = false;
var home_pointer = 0;

function init( ){
    if(!document.getElementById){
        return;
    }

    if(window.ajaxEnabled != undefined){
        ajaxCheck( );
    }
    else{
        window.ajaxEnabled = false;
    }

    //scrollToDirAnchor( );

    initDirPhoneNumbers( );

    initA( );

    initBottomContent( );
    //initTopMenuLinks( );
    initClock( );
    initBlocks( );
    initForms( );
    initSliders( );
    initSearchBObjects( );
    //printAmazonBlock( );
    initObjects( );
    printStreamingRadio( );
    //loadReuters( );

    //initScoreRotator( );
    rotateScores( );

    loadYouTubeVideo( );

    initInputButtons( );

    initChat( );

    initMLSRecords( );

    initSaveArticleDraft( );
}

function initDirPhoneNumbers( ){
    /*
    var bizListings = document.getElementById('bizListings');
    if(!bizListings){
        return;
    }
    var l_divs = bizListings.getElementsByTagName('div');
    */

    var l_divs = document.getElementsByTagName('div');

    for(var i = 0; i < l_divs.length; i++){
        l_div = l_divs[i];

        if(l_div.className == 'l_phone_div'){
            var l_span = l_div.getElementsByTagName('span')[0];
            var l_inputs = l_div.getElementsByTagName('input');
            var l_phone = l_inputs[0];
            var l_id = l_inputs[1];

            l_span.phone_number = l_phone.value;
            l_span.listing_id = l_id.value;

            l_span.onclick = function( ){
                this.innerHTML = this.phone_number;
                this.style.cursor = 'default';

                if(b_xml.isCurrentRequest){ return false; }//this shouldn't ever happen on this page.

                var newHREF = '/phone_click.php?lid=' + this.listing_id;
                b_xml.request(newHREF);
                if(b_xml.isSupported){ return false; }

                this.onclick = null;//only click once

                return true;
            }
        }
    }
}

function scrollToDirAnchor( ){
    var dir_container = document.getElementById('dir_container');

    if(dir_container){
        var contentTable = document.getElementById('contentTable');
        window.scrollTo(0, contentTable.offsetTop);
        if(window.is_ie){
            window.scrollTo(0, 180);//ie sux, just hack it.
        }
    }
}

function loadYouTubeVideo( ){
    var article_youtube = document.getElementById('article_youtube');

    if(article_youtube){
        var lnk = article_youtube.innerHTML;
        article_youtube.innerHTML = '<div>&nbsp;</div><div style="text-align: center;"><object width="425" height="355"><param name="movie" value="' + lnk + '&rel=1"></param><param name="wmode" value="transparent"></param><embed src="' + lnk + '&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></div><div>&nbsp;</div>';
    }
}

function initForms( ){
    if(document.getElementById('gsch')){
        var gsch = document.getElementById('gsch');
        gsch.target = "google_window";
    }
}
function initInputButtons( ){
    var inputs = document.getElementsByTagName("input");
    var inputsA = new Array( );

    //this is a necessary evil for what we are doing with the inputs.
    /*for(var i = 0; i < inputs.length; i++){
        inputsA[i] = inputs[i];
    }

    for(var i = 0; i < inputsA.length; i++){
        if((inputsA[i].type == "submit" || inputsA[i].type == "reset" || inputsA[i].type == "button") && inputsA[i].className == "button" && !window.is_ie){
            hackSubmitButtons(inputsA[i]);
        }
    }*/
}


//This function is to add happy rounded corners to submit buttons.
//This is necessary because graphic designers like rounded submit buttons.
//this function takes in the submit button object.  You will need to add
//styles for the container classes sObj and sObjOver, and any styles in
//the custom html of this function.
function hackSubmitButtons(sObj){

    if(!sObj.parentNode){
        return;
    }

    if(sObj.className != 'button'){
        return;//don't replace non-button... er buttons.
    }

    var b_className = sObj.className;//just in case we delete the above if statement.
    var b_id = sObj.id;
    var b_name = sObj.name;
    var b_value = sObj.value;

    var btn = null

    //we must ensure that this is in fact an IE browser... so let's compensate
    //for Opera's stubborn blunders
    if(window.is_ie && window.createPopup){
        var bStr = '<button type="' + sObj.type + '">';
        btn = document.createElement(bStr);
    }
    else if(navigator.appName.match(/opera/i)){
        //don't do anything special;
        if(sObj.type == 'reset'){
            return;
        }
        btn = document.createElement('button');
    }
    else{
        btn = document.createElement('button');
        btn.type = sObj.type;

        //tried to catch it, didn't work on safari
        if(btn.type == '' && sObj.type == 'reset'){
            alert(btn.type + ' - ' + sObj.type);
            return;
        }

    }

    var newBtn;

    var sObjParent = sObj.parentNode;

    //if(window.isOldIE || window.isNewIE){
    //    newBtn = btn;
    //    newBtn.insertAdjacentElement("BeforeBegin", sObj);
    //}
    //else{
    //    newBtn = sObj.parentNode.insertBefore(btn, sObj);
    //}

    newBtn = sObjParent.insertBefore(btn, sObj);

    var newHTML = '<table class="btnTbl" border="0" cellpadding="0" cellspacing="0"><tr>';
    newHTML += '<td class="btnL">&nbsp;</td>';
    newHTML += '<td class="btnContent">' + b_value + '</td>';
    newHTML += '<td class="btnR">&nbsp;</td>';
    newHTML += '</tr></table>';

    /*var newHTML = '<div class="btnTbl">';
    newHTML += '<div class="btnL">&nbsp;</div>';
    newHTML += '<div class="btnContent">' + b_value + '</div>';
    newHTML += '<div class="btnR">&nbsp;</div>';
    newHTML += '</div>';*/

    //alert(newHTML);

    newBtn.name = 'submit';
    newBtn.className = b_className;
    newBtn.name = b_name;

    newBtn.onclick = sObj.onclick;
    newBtn.onmousedown = sObj.onmousedown;

    //lets hope there are none of these for ie's sake (which I don't think there are).
    newBtn.onmouseup = sObj.onmouseup;

    sObjParent.removeChild(sObj);

    newBtn.id = b_id;
    newBtn.value = b_value;

    newBtn.style.backgroundColor = 'transparent';
    newBtn.style.border = '0px solid #FFFFFF';

    newBtn.innerHTML = newHTML;

    if(window.is_ie){
        //newBtn.style.width = newBtn.getElementsByTagName('table')[0].offsetWidth + 'px';
        newBtn.onmouseover = function( ){
            newBtn.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=80)";
        }

        newBtn.onmouseout = function( ){
            newBtn.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
        }
    }
}


function initBlocks( ){
    if(document.getElementsByTagName){
        var imgs = document.getElementsByTagName("img");
        var bcnt = 0;
        for(var i = 0; i < imgs.length; i++){
            var img = imgs[i];
            if(img.src.match(/\/minus\.gif/) || img.src.match(/\/plus.gif/) || img.src.match(/\/blank.gif/)){
                //get the parent
                var iparent = img.parentNode;
                while(iparent){
                    if(iparent.className == 'blockH'){
                        break;
                    }
                    iparent = iparent.parentNode;
                }
                if(!iparent){ continue };
                var iblock = iparent.nextSibling;
                while(iblock){
                    if(iblock.tagName == 'div' || iblock.tagName == 'DIV'){
                        break;
                    }
                    iblock = iblock.nextSibling;
                }

                if(!iblock){ continue; }
                if(iblock.className != 'block1'){ continue; }

                var atags = iblock.getElementsByTagName('a');
                var doBlock = false;
                for(var j = 0; j < atags.length; j++){
                    var a = atags[j];
                    if(window.location == a.href){
                        doBlock = true;
                    }
                }

                iparent.onclick = function( ){
                    var iblock = this.nextSibling;
                    while(iblock.tagName != 'div' && iblock.tagName != 'DIV'){
                        iblock = iblock.nextSibling;
                    }
                }

                iparent.onmouseover = function( ){
                    this.style.textDecoration = 'underline';
                }

                iparent.onmouseout = function( ){
                    this.style.textDecoration = 'none';
                }

                if(window.is_ie){
                    //the ie way
                    iparent.style.cursor = 'hand';
                }
                else{
                    //every other way
                    iparent.style.cursor = 'pointer';
                }
            }
        }
    }
    else{

    }
}


function initA( ){
    if(!document.getElementsByTagName){
        return
    }
    var as = document.getElementsByTagName("a");
    var len = as.length;
    var i;

    for(i = 0; i < len; i++){
        if(as[i].href.match(/^mailto/)){
            continue;
        }

        var hostnm = as[i].href.replace(/https?\:\/\//, "");
        hostnm = hostnm.replace(/\/.*/, "");

        if(as[i].className == 'mls_listing_link'){
            as[i].onclick = function( ){ return false; }
            continue;
        }

        if(as[i].className == 'searchLink'){
            as[i].onclick = function( ){
                if(ajaxEnabled && b_xml && window.searchPhrase != undefined){
                    //escape characters that may be in the si
                    var s_href = encodeURIComponent(this.href.replace('http://' + window.location.hostname + '/', ''));
                    b_xml.request('/ajax.php/type/search/?si=' + s_href + '&sv=' + window.searchPhrase);
                    //alert('/ajax.php/type/search/?si=' + s_href + '&sv=' + window.searchPhrase);
                    //return false;
                }
            }
            continue;
        }

        if(as[i].href.match(/\/ad\.\php\?/) || as[i].href.match(/\/ldir\.\php/) || (hostnm != window.location.hostname && !hostnm.match(/(voiceof|vona\.com|voa\.test|voc\.test|secure\.test)/) ) ){
            as[i].target = "_blank";
            //as[i].style.position = "relative";
            //as[i].style.zIndex = "500";

            /*var span = document.createElement("span");
            span.style.position = "absolute";
            span.style.display = "none";
            span.className = "externTitle";
            span.style.zIndex = "30000";

            span.innerHTML += as[i].title;
            span.innerHTML += "<br />";
            span.innerHTML = "<strong>Opens in a new window</strong>";

            as[i].title = "";

            if(window.is_ie){
                document.body.insertAdjacentElement("beforeEnd", span);
            }
            else{
                document.body.appendChild(span);
            }

            as[i].span = span;

            as[i].onmouseout = function( ){
                this.span.style.display = "none";
            }

            as[i].onmousemove = toolTipHover;*/
        }
    }//end foreach a

    //Find specific links that use ajax (this has to be the last block in initA
    //homeArticlesMenu, homeNewsMenu, homePoliticsMenu
    if(ajaxEnabled){
        if(!b_xml){
            return;
        }

        initAjaxTabs( );

        initCalendarNav( );

        initTrailerLinks( );

    }//end if ajax enabled
}//end initA


function initAjaxTabs( ){

    var html_id;
    var ajax_type;
    var hObj = null;

    for(var cnt = 0; cnt < ajaxTabList.length; cnt++){

        html_id = ajaxTabList[cnt].html_id;
        ajax_type = ajaxTabList[cnt].ajax_type;

        hObj = document.getElementById(html_id);

        if(hObj){
            i = 0;
            as = hObj.getElementsByTagName("a");
            for(i = 0; i < as.length; i++){
                as[i].ajax_type = ajax_type;
                as[i].onclick = function( ){
                    if(this.ajax_type == 'dir' && window.is_ie && this.innerHTML == 'Reviews'){
                        return true;
                    }

                    if(b_xml.isCurrentRequest){ return false; }
                    //ul = a->li->ul (this->parent->parent)
                    //table = a->td->tr->table (this->parent->parent-parent)
                    var table = this.parentNode.parentNode.parentNode;
                    var p_as = table.getElementsByTagName('a');

                    for(var j = 0; j < p_as.length; j++){ p_as[j].className = ''; }
                    this.className = 'cur';
                    var newHREF = this.href;
                    newHREF = newHREF.replace(/(\#.*)$/, '');
                    newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php/');
                    newHREF = newHREF + '/type/' + this.ajax_type;
                    //alert('here');
                    //alert(newHREF);

                    b_xml.request(newHREF);

                    if(b_xml.isSupported){ return false; }

                    return true;
                }//end onclick
            }//end foreach a in homeArticlesMenu
        }

    }//end for each ajaxTabList
}

//phone is the html id of the phone input
function findBusinessPhone(phone_id){
    var phone_obj = document.getElementById(phone_id);
    if(!phone_obj){ return true; }

    var phone = phone_obj.value;
    if(!phone){ return true; }

    phone = phone.replace(/[^\d]/, '');
    phone = phone.replace(/^1+/, '');//strip any 1's at the beginning of the number.

    if(!phone.match(/\d{10,10}/)){
        alert("Phone number must be a 10 digit phone number");
        return false;
    }

    window.cur_biz_phone_search = phone;
    window.cur_biz_phone_tries = 0;

    var newHREF = "/ajax.php?type=biz_listing_check&bsearch_phone=" + phone;
    b_xml.request(newHREF);

    setTimeout("checkBizPhoneData( )", 200);

    if(b_xml.isSupported){ return false; }

    return true;
}
function checkBizPhoneData( ){
    var bsearch_results = document.getElementById('bsearch_results');

    if(!bsearch_results){
        return;
    }

    var biz_phone = document.getElementById('biz_listing_phone');
    if(window.cur_biz_phone_tries > 10){//to prevent it to go on forever in case of network lag, or something terrible... yes, lag is terrible, I hate it.
        bsearch_results.innerHTML = '<span class="error">Phone number not found in the directory</span>';
        return;
    }
    if(!biz_phone || biz_phone.innerHTML != window.cur_biz_phone_search){
        //it's not there or it hasn't got updated yet
        window.cur_biz_phone_tries++;
        setTimeout("checkBizPhoneData( )", 200);
        return;
    }

    window.cur_biz_phone_tries = 0;
    window.cur_biz_phone_search = null;

    //now we do good stuff

    updateListingAppForm( );
}

//this function is more specific than checkBizPhoneData
function updateListingAppForm( ){
    var formVars = new Array('phone', 'company', 'address', 'city', 'state', 'zip', 'fax', 'website', 'catid', 'idlist');

    for(var i = 0; i < formVars.length; i++){
        var item = formVars[i];

        var biz_data = document.getElementById('biz_listing_' + item).innerHTML;
        var biz_input = document.getElementById('biz_input_' + item);

        if(item == 'state'){
            for(var j = 0; j < biz_input.options.length; j++){
                var option = biz_input.options[j];

                if(option.value == biz_data){
                    biz_input.selectedIndex = j;
                    break;
                }
            }
        }
        else if(item == 'catid'){
            biz_input.value = biz_data;
            document.getElementById('namebiz_input_catid').value = document.getElementById('biz_listing_catname').innerHTML;
        }
        else{
            biz_input.value = biz_data;
        }
    }
}

function initCalendarNav( ){
    //similar to tabs but for the calendar
    hObj = document.getElementById('ajaxCalNav');
    if(hObj){
        i = 0;
        as = hObj.getElementsByTagName("a");
        for(i = 0; i < as.length; i++){
            if(as[i].id == 'mainDate'){
                continue;
            }

            as[i].onclick = function( ){
                if(b_xml.isCurrentRequest){ return false; }

                var newHREF = this.href;
                newHREF = newHREF.replace(/(\#.*)$/, '');

                if(newHREF.match(/\/members\//)){
                    newHREF = newHREF.replace(/(\/members\/)/, '/members/ajax.php');
                }
                else if(newHREF.match(/content/)){
                    newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php');
                }

                newHREF = newHREF + '&type=calnav';
                //alert(newHREF);
                b_xml.request(newHREF);
                if(b_xml.isSupported){ return false; }

                return true;
            }//end onclick
        }
    }
}

function initTrailerLinks( ){
    //bah to you IE! - too slow!
    if(window.is_ie){
        return;
    }

    var tObj = document.getElementById('trailerList');
    if(tObj){
        i = 0;
        as = tObj.getElementsByTagName('a');
        for(i = 0; i < as.length; i++){
            as[i].onclick = function( ){
                if(b_xml.isCurrentRequest){ return false; }

                var newHREF = this.href;
                newHREF = newHREF.replace(/(\#.*)$/, '');
                newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php/');
                newHREF = newHREF + '/type/trailers';

                //alert(newHREF);
                b_xml.request(newHREF);
                if(b_xml.isSupported){ return false; }

                return true;
            }//end onclick
        }
    }
}

function toolTipHover(e){
    var xpos, ypos;
    if(window.is_ie){
        if(this.span.style.display != "block"){
            this.span.style.display = "block";
        }

        if(event.screenX > (screen.availWidth/2)){
            xpos = event.screenX - this.span.clientWidth - 16;
        }
        else{
            xpos = event.screenX + 16;
        }


        if(event.screenY > (screen.availHeight/2)){
            ypos = (event.clientY + document.body.scrollTop) - this.span.clientHeight - 16;
        }
        else{
            ypos = (event.clientY + document.body.scrollTop) + 24;
        }
    }
    else{
        if(!e.pageX){
            this.title = this.span.innerHTML;
            return;
        }

        if(this.span.style.display != "block"){
            this.span.style.display = "block";
        }

        if(e.pageX > (window.innerWidth/2)){
            xpos = e.pageX - this.span.clientWidth - 16;
        }
        else{
            xpos = e.pageX + 16;
        }

        if(e.clientY > (window.innerHeight/2)){
            ypos = e.pageY - this.span.clientHeight - 16;
        }
        else{
            ypos = e.pageY + 16;
        }


    }
    //alert(xpos);
    //alert(ypos);
    this.span.style.left = xpos + "px";
    this.span.style.top  = ypos + "px";

}

function initObjects( ){
    if(document.getElementsByTagName){
        var objects = document.getElementsByTagName("div");
        var len = objects.length;

        for(var i = 0; i < len; i++){
            var obj = objects[i];
            if(obj.className && obj.className == 'bgzobject'){
                var paramStr = '';
                var objStr = '\n<object ';
                var embedStr = '\n<embed ';
                var params = obj.getElementsByTagName('param');
                var plen = params.length;
                var o_type = '';
                var o_filename = '';
                var o_width = '';
                var o_height = '';
                //need o_type, it will be first or second in the list, but just in case.
                for(j = 0; j < plen; j++){
                    var param = params[j];
                    var pn = param.name;
                    var pv = param.value;
                    if(pn == 'o_type'){
                        o_type = pv;

                        //do this here because we have to force video type for wmv files
                        var isWindows = false;
                        //if( o_type != 'wmv' && !window.is_ie){
                        //     isWindows = false;
                        //}else if(o_type == 'wmv' || navigator.userAgent.match(/windows/i)){
                        if(o_type == 'wmv' || navigator.userAgent.match(/windows/i)){
                            isWindows = true;
                        }

                        break;
                    }
                }
                for(j = 0; j < plen; j++){
                    var param = params[j];
                    var pn = param.name;
                    var pv = param.value;

                    switch(pn){
                    case 'o_type':
                        if(o_type == 'swf'){
                            embedStr += ' type="application/x-shockwave-flash" ';
                            objStr += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
                            objStr += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
                        }
                        else if(isWindows && o_type != 'mov'){

                            embedStr += ' type="application/x-mplayer2" ';
                            embedStr += '  pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" ';
                            objStr += ' classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ';
                            objStr += ' standby="Loading..." ';
                            objStr += ' type="application/x-oleobject" ';
                            objStr += ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" ';
                        }
                        else{
                            embedStr += ' pluginspage="http://www.apple.com/quicktime/download/" ';
                            objStr += ' classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ';
                            objStr += ' codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
                        }
                        break;
                    case 'o_filename':
                        o_filename = pv;
                        if(o_type == 'swf'){
                            paramStr += ' <param name="movie" value="/docs/' + pv + '" /> \n';
                        }
                        else if(isWindows && o_type != 'mov'){
                            paramStr += ' <param name="filename" value="/docs/' + pv + '" /> \n';
                        }
                        else{
                            paramStr += ' <param name="src" value="/docs/' + pv + '" /> \n';
                        }
                        embedStr += ' src="/docs/' + pv + '" ';

                        break;
                    case 'o_width':
                        o_width = pv;
                        obj.width = pv;
                        embedStr += ' width="' + pv + '" ';
                        objStr += ' width="' + pv + '" ';
                        break;
                    case 'o_height':
                        o_height = pv;
                        obj.height = pv;
                        embedStr += ' height="' + pv + '" ';
                        objStr += ' height="' + pv + '" ';
                        break;
                    default:
                        pn = pn.replace(/^(o\_)/, '');

                        if(!isWindows && pn == 'showcontrols'){
                            pn = 'controller';
                        }

                        if(pn == 'transparency'){
                            pn = 'wmode';
                            pv = 'transparent';
                        }

                        paramStr += ' <param name="' + pn + '" value="' + pv + '" /> ';

                        if(pv.toLowerCase( ) == 'false'){
                            pv = '0';
                        }
                        else if(pv.toLowerCase( ) == 'true'){
                            pv = '1';
                        }

                        if(pn == 'showcontrols'){
                            if(pv == '0'){
                                paramStr += ' <param name="ShowStatusBar" value="false" /> \n';
                                embedStr += ' showstatusbar="0" ';
                            }
                            else{
                                paramStr += ' <param name="ShowStatusBar" value="true" /> \n';
                                embedStr += ' showstatusbar="1" ';
                            }
                        }

                        embedStr += ' ' + pn + '="' + pv + '" ';


                        break;
                    }
                }//end params

                embedStr += '></embed>\n';
                objStr += '>\n';
                //alert(objStr + paramStr + embedStr + '</object>');
                obj.innerHTML = objStr + paramStr + embedStr + '</object>\n';
                //alert(obj.innerHTML);
                obj.style.display = 'block';
            }//end if bgzobject
        }
    }
}

function initSearchBObjects( ){
    var searchZipMiles = document.getElementById('searchZipMiles');
    var searchZipCode = document.getElementById('searchZipCode');
    var searchRefresh = document.getElementById('searchRefresh');

    if(!searchZipMiles || !searchZipCode || !searchRefresh) return;

    searchZipMiles.onchange = function( ){
        var sval = this.options[this.selectedIndex].value;
        setcookie('searchZipMiles', sval);
        document.getElementById('searchRefresh').style.visibility = 'visible';
    }
    searchZipCode.onchange = function( ){
        setcookie('searchZipCode', this.value);
        document.getElementById('searchRefresh').style.visibility = 'visible';
    }

    searchRefresh.onclick = function( ){
        window.location.reload( false );
    }
}

function initBottomContent( ){
    if(!document.getElementById('pageContainer')){
        return;
    }
    var pcontain = document.getElementById('pageContainer');

    if(document.getElementById('sitemap')){
        var sitemap = document.getElementById('sitemap');
        if(document.getElementById('sitemapButton')){
            var sitemapButton = document.getElementById('sitemapButton');
            sitemapButton.onclick = function( ){toggleBottomContent('sitemap');};
        }
        sitemap.style.display = 'none';
    }
    if(document.getElementById('pageInformation')){
        var pageInformation = document.getElementById('pageInformation');
        if(document.getElementById('pageInformationButton')){
            var pageInformationButton = document.getElementById('pageInformationButton');
            pageInformationButton.onclick = function( ){toggleBottomContent('pageInformation');};
        }
        pageInformation.style.display = 'none';
    }
}

function toggleBottomContent(contentId){
    if(!document.getElementById(contentId)){
        return;
    }

    var t1 = 'block';
    var t2 = 'none';

    contentObj = document.getElementById(contentId);

    if(document.getElementById('sitemap')){
        var sitemap = document.getElementById('sitemap');
        if(contentId != 'sitemap' && sitemap.style.display == t1){
            sitemap.style.display = t2;
        }
    }
    if(document.getElementById('pageInformation')){
        var pageInformation = document.getElementById('pageInformation');
        if(contentId != 'pageInformation' && pageInformation.style.display == t1){
            pageInformation.style.display = t2;
        }
    }

    if(contentObj.style.display != t1){
        contentObj.style.display = t1;
    }
    else{
        contentObj.style.display = t2;
    }
}


//classified stuff
function removeCaptionImages(fid){
    var ffs = "c_img_" + fid;
    var fis = "i_img_" + fid;
    var capt = "caption_" + fid;

    var field = document.getElementById(ffs);
    var fimg = document.getElementById(fis);
    var caption = document.getElementById(capt);

    if(field){
        field.value = '';
    }
    if(fimg){
        fimg.src = '/members/images/class_image_placeholder.gif';
    }
    if(caption){
        caption.value = '';
    }
}

function inputOver(e){
    this.className = "buttonOver";
}

function inputOut(e){
    this.className = "button";
}

//Popups
function generalPopUp(loc, w, h){
    gPopUp = window.open(loc, "gpopup", "width=" + w + ",height=" + h + ", scrollbars=1, status=no,toolbar=no,resizable=yes");
    gPopUp.focus( );
}
function generalPopUp2(loc, w, h){
    gPopUp = window.open(loc, "gpopup", "width=" + w + ",height=" + h + ", scrollbars=1, status=no,toolbar=no,resizable=yes,menubar=yes");
    gPopUp.focus( );
}

function imageSelectPopUp(pwinvar){
    imgSelectPopUp = window.open("./imageselect.php?mode=1&fieldID=" + pwinvar, "ImageSelector", "width=780,height=480, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );
}

function imageSelectPopUp_m(pwinvar){
    imgSelectPopUp = window.open("/members/imageselect.php?mode=1&fieldID=" + pwinvar, "ImageSelector", "width=780,height=480, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );
}

function openUploader( ){
    var imgSelectPopUp = window.open("./imageselect.php", "ImageSelector", "width=780,height=680, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );

    return false;
}

function fileSelectPopUp(pwinvar){
    imgSelectPopUp = window.open("./fileselect.php?mode=1&fieldID=" + pwinvar, "FileSelector", "width=780,height=580, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );
}

function openFUploader( ){
    var imgSelectPopUp = window.open("./fileselect.php", "FileSelector", "width=780,height=580, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );

    if(window.is_ie){
        window.event.cancelBubble = true;
    }
    else{
        e.stopPropagation( );
        e.preventDefault( );
    }
    return false;
}

function classImageSelectPopUp(pwinvar, pimgvar){
    imgSelectPopUp = window.open("./c_imageselect.php?mode=1&fieldID=" + pwinvar + "&imgID=" + pimgvar, "ImageSelector", "width=780,height=480, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );
}

function openRadioForm( ){
    radioPopup = window.open("/radio_form.php", "RadioForm", "width=620,height=690, scrollbars=1, status=yes,toolbar=no,resizable=yes");
    radioPopup.focus( );
}

function openLoginForm(hst){

    var prot = 'http';

    hst = 'www.voiceofnorthamerica.com';
    if(window.location.href.match(/\.test\.bbbwebsites\.com/)){
        hst = 'secure.test.bbbwebsites.com';
    }

    prot = 'https';

    var loc = window.location.href.replace(/^(https?\:\/\/[\w\d\-\.]+\/)/, '/');
    //loc = 'https://' + hst + loc + 'members/';

    //loc = 'https://' + hst + '/members/?newlogin=1' + '&referer=' + escape(window.location.href);
    loc = prot + '://' + hst + '/members/?newlogin=1' + '&referer=' + escape(window.location.href);


    window.location = loc;

    return false;

    var prot = 'http';
    if(window.location.href.match(/^https/)){
        prot = 'https';
    }
    var loginPopup = window.open("/members/login.php?prot=" + prot, "LoginForm", "width=320,height=320, scrollbars=1, status=yes, toolbar=no, resizable=yes");

    loginPopup.focus( );

    //alert(window.location.hostname + ' - ' + window.location.hst);

    if(window.location.hostname != hst){
        var loc = window.location.href.replace(/^(https?\:\/\/[\w\d\-\.]+\/)/, '/');
        loc = 'https://' + hst + loc;
        //alert(loc);

        //window.location.href = 'https://' + hst + loc;
    }

    return true;
}

function mm_load_bracket_page(loc){
    var w = 1460;
    var h = 830;

    var sw = screen.availWidth;
    var sh = screen.availHeight;

    if(sw){
        w = sw - 40;
    }
    if(sh && sh < h){
        h = sh - 40;
    }

    gPopUp = window.open(loc, "mm_bracket", "width=" + w + ",height=" + h + ", scrollbars=1, status=no,toolbar=no,resizable=yes");
    gPopUp.focus( );
}

//drop down menus ##################################################


var CurMenu = null;
var CurButton = null;
var isDropped = false;
var isHideCheck = false;
var subCurMenu = null;
var subIsDropped = false;
var subIsHideCheck = false;

function initTopMenuLinks( ){
    var tmenu = document.getElementById('tmenu');
    var submenubar = document.getElementById('submenubar');
    var tdA = tmenu.getElementsByTagName('td')
    var len = tdA.length;

    for(var i = 0; i < len; i++){
        var td = tdA[i];
        if(document.getElementById('submenubar')){
            td.onmouseover = pageON(i, 'submenubar');
            td.onmouseout = pageOFF(i, 'submenubar');
        }
        else{
            td.onmouseover = pageON(i);
            td.onmouseout = pageOFF(i);
        }
    }
}
function pageON(index, subloc){
    if(subloc){
        var tbls = document.getElementById(subloc).getElementsByTagName('table');
    }
    else{
        var tbls = this.getElementsByTagName('table');
    }

    var tmenu = document.getElementById('tmenu');
    var tds = tmenu.getElementsByTagName('td');

    if(tbls.length > 0){
        show(tbls[index], tds[index].getElementsByTagName('a')[0]);
    }

}
function pageOFF(index, subloc){
    if(!isHideCheck){
        hideMenu( );
    }
}
function show(menu, tbutton){
    if(CurMenu && CurMenu.parentNode.id != 'tdropCur'){
        CurMenu.style.display = "none";
        CurButton.className = 'none';
    }

    //opera is a bit of a nuisance
    if(window.is_ie && navigator.userAgent.indexOf("Opera") == -1){
        menu.style.display = "block";
    }
    else{
        menu.style.display = "table";
    }

    if(tbutton.className.match(/ta\_first/)){
        tbutton.className = 'ta_first ta_cur';
    }
    else{
        tbutton.className = 'ta_cur';
    }

    isDropped = true;
    CurMenu = menu;
    CurButton = tbutton;
}
function hideMenu( ){
    if(CurMenu && CurMenu.parentNode.id != 'tdropCur'){
        isDropped = false;
        isHideCheck = true;
        setTimeout("checkDropped( )", 200);
        isHideCheck = false;
    }
}
function checkDropped( ){
    if(!isDropped){
        CurMenu.style.display = "none";
        CurButton.className = 'none';
    }
}
//############################################################

function printView(plink) {
    var plink2 = "/print/p/" + plink;
    window.open(plink2, "ShoppingList", "width=620,height=400,status=yes,toolbar=no,resizable=yes,raised=yes,scrollbars=yes");
}

function printPage(buttonID) {
    var printButton = document.getElementById(buttonID);
    printButton.style.visibility = "hidden";
    window.print();
    window.close();
}

var ipreviewWin = null;
function ipreview(lnk){
    ipreviewWin = window.open(lnk, "ipreviewWin", "width=1000,height=600, menubar=yes, location=yes, scrollbars=yes, status=yes,toolbar=yes,resizable=yes");
    ipreviewWin.focus( );
    return false;
}

//category function
function lCategoryPopup(pwinvar){
    lCatPopUp = window.open("/include/category.php?lckey=" + pwinvar, "CategorySelect", "width=780,height=480, scrollbars=yes, status=yes,toolbar=no,resizable=yes");
    lCatPopUp.focus( );
}
function tlCategoryPopup(pwinvar){
    lCatPopUp = window.open("/include/tlcategory.php?lckey=" + pwinvar, "CategorySelect", "width=780,height=480, scrollbars=yes, status=yes,toolbar=no,resizable=yes");
    lCatPopUp.focus( );
}
function lCategoryPopup2(pwinvar, catid){
    lCatPopUp = window.open("/include/category.php?lckey=" + pwinvar + "&num=" + catid, "CategorySelect", "width=780,height=480, scrollbars=yes, status=yes,toolbar=no,resizable=yes");
    lCatPopUp.focus( );
}
function lCategoryPopupA(pwinvar){
    lCatPopUp = window.open("/include/category2.php?lckey=" + pwinvar, "CategorySelect", "width=780,height=480, scrollbars=yes, status=yes,toolbar=no,resizable=yes");
    lCatPopUp.focus( );
}
function lClassifiedPopup(pwinvar){
    lCatPopUp = window.open("/include/classified.php?lckey=" + pwinvar, "ClassifiedSelect", "width=780,height=480, scrollbars=yes, status=yes,toolbar=no,resizable=yes");
    lCatPopUp.focus( );
}
function wsbPopup(loc){
    lCatPopUp = window.open(loc, "wsb", "width=782,height=480, menubar=yes, location=yes, scrollbars=yes, status=yes,toolbar=yes,resizable=yes");
    lCatPopUp.focus( );
}

function whatisPopup(loc){
    whatisPopUp = window.open(loc, "whatis", "width=300,height=300, menubar=no, location=no, scrollbars=yes, status=no,toolbar=no,resizable=yes");
    whatisPopUp.focus( );
}
function generalPopup(loc, w, h){
    gPopUp = window.open(loc, "gpopup", "width=" + w + ",height=" + h + ", scrollbars=1, status=no,toolbar=no,resizable=yes");
    gPopUp.focus( );
}

function setcookie(cookieName,cookieValue){
    document.cookie = cookieName + "=" + escape(cookieValue) + ";path=/";
}

function printAmazonBlock( ){
    if(!document.getElementById('amazon')){
        return;
    }

    var amazon = document.getElementById('amazon');

    var modes = Array('books', 'dvd');

    if(amazonKeyWords == '' || amazonKeyWords.match(/electronic/i) || amazonKeyWords.match(/computer/i) || amazonKeyWords.match(/technology/i) || amazonKeyWords.match(/phone/i) || amazonKeyWords.match(/software/) || amazonKeyWords.match(/games/i) || amazonKeyWords.match(/video/i) || amazonKeyWords.match(/gadget/i) || amazonKeyWords.match(/wireless/i) ){
        modes.push('videogames');
        modes.push('wireless-phones');
        modes.push('electronics');
    }

    var randomnumber=Math.floor(Math.random()*modes.length)

    var mode = modes[randomnumber];

    var queryStr = "http://rcm.amazon.com/e/cm?t=voiceofarizon-20&o=1&p=14&l=st1&mode=" + mode + "&search=" + amazonKeyWords + "&=1&fc1=&lt1=&lc1=&bg1=&f=ifr";
    if(mode == 'wireless-phones'){
        queryStr = "http://rcm.amazon.com/e/cm?t=voiceofarizon-20&o=1&p=14&l=bn1&mode=wireless-phones&browse=1067706&=1&fc1=&lt1=&lc1=&bg1=&f=ifr";
    }

    //alert(amazonKeyWords + " --- " + mode + " " + randomnumber);

    amazon.innerHTML = '<div id="amazonSearch" style="text-align: center;"><iframe src="' + queryStr + '" marginwidth="0" marginheight="0" width="160" height="600" border="0" frameborder="0" style="border:none; margin: 0px auto;" scrolling="no"></iframe></div>';
}

function printStreamingRadio( ){
    if(!document.getElementById('streamRadio')){
        return;
    }

    var streamRadio = document.getElementById('streamRadio');
    var date = new Date( );
    var day = date.getDay( );

    //good thing AZ doesn't change
    var hour = date.getUTCHours( ) - 7;

    //only shows up 9-12 on Saturdays AZ time (11 because it will still be 11 at 11:59:59)
    //so 1 hour before and after show
    //alert(day + " - " + hour);
    if(day == '0' && (hour >= '13' && hour <= '16')){
        //streamRadio.innerHTML = '<object width="290" height="45" type="application/x-oleobject" standby="Loading Microsoft Windows Media Player Components..." codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" id="MediaPlayer"> <param value="1" name="AutoStart" /> <param value="http://www.voiceofarizona.com/radio.asx" name="Filename" /> <param value="1" name="ShowControls" /> <param value="1" name="ShowAudioControls" /> <param value="0" name="WindowlessVideo" /> <embed width="290" height="50" showstatusbar="1" showdisplay="0" showcontrols="1" autostart="1" autosize="1" pluginspage="http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=media&amp;sba=plugin&amp;" name="MediaPlayer" src="http://www.voiceofarizona.com/radio.asx" type="application/x-mplayer2"></embed> </object><table cellspacing="0" cellpadding="0" border="0" class="bzero" style="margin-right: auto; margin-left: 0px; width: 100%;"><tbody><tr><td style="width: 50%; text-align: center;" class="bzero"><a href="http://www.voiceofarizona.com/radio.asx">Click Here If You Don&#039;t Hear Anything</a></td><td style="width: 50%; text-align: center;" class="bzero"><a href="http://www.aaphx.com/">Air America Phoenix</a></td></tr></tbody></table>';
        streamRadio.innerHTML = '<br /><br /><div><table cellspacing="0" cellpadding="0" border="0" class="bzero" style="margin-right: auto; margin-left: 0px; width: 100%;"><tbody><tr><td style="width: 50%; text-align: center;" class="bzero"><a href="mms://wm3.spacialnet.com/novamradio55700">Click here if your player don&#039;t start within 5 seconds.</a></td><td style="width: 50%; text-align: center;" class="bzero"><a href="http://www.aaphx.com/">Air America Phoenix</a></td></tr></tbody></table></div><br /><br />';
        setTimeout('openStreamer( );', 3000);
    }
}

function openStreamer( ){
    window.location.href = "mms://wm3.spacialnet.com/novamradio55700";
}

function disableBoxes(form, check){
    for(var i = 0; i < form.elements.length; i++){
        if(form.elements[i].type == 'checkbox' && form.elements[i].id != 'acheck'){
            form.elements[i].disabled = check;
            form.elements[i].checked = check;
        }
    }
}

function submitComment(fieldID){
    var bgzFrame = document.getElementById('bgz');
    var hidField = document.getElementById(fieldID);

    /*if(bgzFrame.contentDocument){
        var frameSrc = bgzFrame.contentDocument.body.innerHTML;
    }
    else{
        var frameSrc = document.frames['bgz'].document.body.innerHTML;
    }*/

    var frameSrc = getDocHTML( );

    //inject frameSrc into hidField value
    hidField.value = frameSrc;
}

function loadReuters( ){
    var hVideoBlock = document.getElementById('hVideoBlock');

    if(hVideoBlock){
        var ihtml = '<iframe src="http://www.voiceofarizona.com/reuters.php" width="540" height="320" frameborder="0" scrolling="no"></iframe>';
        hVideoBlock.innerHTML = ihtml;
    }
}

function launchReutersPopUp( ){
    ruetersPopUp = window.open("http://www.voiceofarizona.com/reuters.php", "reuters", "width=540,height=318, scrollbars=0, status=no,toolbar=no,resizable=yes");
    ruetersPopUp.focus( );
}

function rotateScores(control, place){
    if(window.scoreRotatorA == undefined){
        return;
    }

    var numScores = scoreRotatorA.length;
    var interval = 4000;

    if((control == 'pause' || control == 'next' || control == 'previous') && !scoresPaused){
        //alert('pause');
        scoresPaused = true;
    }
    else if(scoresPaused && control == 'pause'){
        //alert('unpause');
        scoresPaused = false;
        control = 'play';
    }

    if(!control && !scoresPaused){
        control = 'play';
    }

    if(place){
        scoreKey = place;
    }

    if(control == 'next' || control == 'play'){
        if(scoreKey < numScores){
            scoreKey++;
        }

        if(scoreKey >= numScores){
            scoreKey = 0;
        }
    }
    else if(control == 'previous'){
        if(scoreKey > 0){
            scoreKey = scoreKey - 1;
        }
        else if(scoreKey <= 0){
            scoreKey = numScores - 1;
        }
    }

    if((control != 'pause' && !scoresPaused) || control == 'next' || control == 'previous'){
        var curScore = scoreRotatorA[scoreKey];

        var gDate = curScore.date;
        var aTeam = curScore.aTeam;
        var aScore = curScore.aScore;
        var hTeam = curScore.hTeam;
        var hScore = curScore.hScore;
        var winner = curScore.winner;

        //this is where we alter the HTML
        var gdObj = document.getElementById('gameDate');
        var atObj = document.getElementById('awayTeam');
        var asObj = document.getElementById('awayScore');
        var htObj = document.getElementById('homeTeam');
        var hsObj = document.getElementById('homeScore');

        if(winner == aTeam){
            htObj.style.fontWeight = "normal";
            hsObj.style.fontWeight = "normal";
            atObj.style.fontWeight = "bold";
            asObj.style.fontWeight = "bold";
        }
        else{
            atObj.style.fontWeight = "normal";
            asObj.style.fontWeight = "normal";
            htObj.style.fontWeight = "bold";
            hsObj.style.fontWeight = "bold";
        }

        gdObj.innerHTML = gDate;

        atObj.innerHTML = aTeam;
        asObj.innerHTML = aScore;

        htObj.innerHTML = hTeam;
        hsObj.innerHTML = hScore;
    }

    //alert(scoresPaused);
    if(control == 'play' && !scoresPaused){
        var rRotate = "rotateScores('"+control+"','"+scoreKey+"')";
        timerID = setTimeout(rRotate, interval);
    }
}

function hideById(tid){
    tObj = document.getElementById(tid);

    tObj.style.display = 'none';
}
function showById(tid, dispType){
    tObj = document.getElementById(tid);

    if(!dispType || window.is_ie){
        dispType = 'block';
    }

    tObj.style.display = dispType;
}

function replyToComment(cid, textStr){

    var under_comment = document.getElementById('under_comment');
    var under_comment_text = document.getElementById('under_comment_text');

    if(!under_comment || !under_comment_text){
        return;
    }

    under_comment.value = cid;
    under_comment_text.innerHTML = textStr + ' <button type="submit" class="button" name="clear" value="clear" onclick="clearReplyToComment( );return false;">Clear</button>';;
    window.location = "#rate";
}

function clearReplyToComment( ){
    var under_comment = document.getElementById('under_comment');
    var under_comment_text = document.getElementById('under_comment_text');

    if(!under_comment || !under_comment_text){
        return;
    }

    under_comment.value = "";
    under_comment_text.innerHTML = '';
}

function toggleCommentBlurb(cbid){
    var cb = document.getElementById(cbid);

    if(cb.style.display != 'block'){
        cb.style.display = 'block';
    }
    else{
        cb.style.display = 'none';
    }
}

function checkListingTextLength(numChars){
    ListingTextArea = document.getElementById('ListingTextArea');
    if(ListingTextArea.value.length >= numChars){
        ListingTextArea.value = ListingTextArea.value.substr(0, numChars);
    }
}

/* star ratings */

//will happen onmouseover
//will swap out images of stars seamlessly
function changeRating(rating){
    var starObj = document.getElementById('starImg');

    starObj.src = '/images/stars_' + rating + 'full.gif';
}

//will happen onclick
//will take the value and set it to a hidden input field on the form
function saveRating(rating, tObj){
    var mapObj = document.getElementById('starMap');
    mapObj.onmouseout = function( ){ changeRating(rating); }

    var newHREF = tObj.href;
    newHREF = newHREF.replace(/(\#.*)$/, '');
    newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php/');
    newHREF = newHREF + '/type/rate';
    b_xml.request(newHREF);

    if(b_xml.isSupported){ return false; }
}

function changeGrade(rating){
    var starObj = document.getElementById('starImg');

    starObj.src = '/images12/grade_rating_' + rating + '.gif';
}

//will happen onclick
//will take the value and set it to a hidden input field on the form
function saveGrade(rating, tObj){
    var mapObj = document.getElementById('starMap');
    mapObj.onmouseout = function( ){ changeGrade(rating); }

    var newHREF = tObj.href;
    newHREF = newHREF.replace(/(\#.*)$/, '');
    newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php/');
    newHREF = newHREF + '/type/rate';
    b_xml.request(newHREF);

    if(b_xml.isSupported){ return false; }
}


/* signup checks */
function checkUsername(val){
    b_xml.request('/ajax.php/type/scheck/f/username/v/' + val);

    if(b_xml.isSupported){ return false; }
}
function checkSiteHandle(val){
    b_xml.request('/ajax.php/type/scheck/f/sitehandle/v/' + val);

    if(b_xml.isSupported){ return false; }

}
function checkPassword(val){
    b_xml.request('/ajax.php/type/scheck/f/password/v/' + val);

    if(b_xml.isSupported){ return false; }

}
function checkPasswordR(val){
    var tForm = document.getElementById('form');
    var msgC = document.getElementById('signup_PasswordR');
    var orig_val = tForm.Password.value;

    msgC.innerHTML = '';
    if(val != ''){
        if(orig_val != val){
            msgC.innerHTML = '<div class="error">Passwords do not match.</div>';
        }
        else{
            msgC.innerHTML = '';
        }
    }
}
function checkEmailAddress(val){
    b_xml.request('/ajax.php/type/scheck/f/email/v/' + val);

    if(b_xml.isSupported){ return false; }

}
function checkEmailAddressR(val){
    var tForm = document.getElementById('form');
    var msgC = document.getElementById('signup_EmailAddressR');
    var orig_val = tForm.EmailAddress.value;

    msgC.innerHTML = '';
    if(val != ''){
        if(orig_val != val){
            msgC.innerHTML = '<div class="error">Emails do not match.</div>';
        }
        else{
            msgC.innerHTML = '';
        }
    }
}

function overlayPopUp( ){
    var overlay = document.getElementById('pop_overlay_dir');
    var container = document.getElementById('pop_container_dir');

    if(!overlay || !container){
        return;
    }

    var cur_style = overlay.style.display;

    if(cur_style == 'none' || cur_style == ''){
        overlay.style.display = 'block';
        container.style.display = 'block';
    }
    else{
        overlay.style.display = 'none';
        container.style.display = 'none';
    }
}

function openSplash(tObj){
    var newHREF = tObj.href;

    //until the non-js part is done
    if(window.is_ie && tObj.innerHTML.match('Reviews')){
        window.location = newHREF;
    }

    newHREF = newHREF.replace(/(\#.*)$/, '');
    newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php/');
    newHREF = newHREF + '?type=splash_dir';
    //alert(newHREF);
    b_xml.request(newHREF);

    overlayPopUp( );
    makeWindowed('pop_container_dir');

    if(b_xml.isSupported){ return false; }
}

/* GOOGLE MAPS */

function setDirections(toAddress, fromAddress){
    if(!fromAddress || !toAddress){
        return;
    }

    var mapObj = document.getElementById("bizMap");
    if(!mapObj){
        mapObj = document.getElementById('map');

        if(!mapObj){ return; }
    }

    var directions = document.getElementById('directions');
    if(!directions){
        return;
    }

    var map = new GMap2(mapObj);
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());

    gdir = new GDirections(map, directions);
    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", handleErrors);

    gdir.load("from: " + fromAddress + " to: " + toAddress);
}


function handleErrors( ){
    if (gdir.getStatus( ).code == G_GEO_UNKNOWN_ADDRESS)
        alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);

    else if (gdir.getStatus( ).code == G_GEO_SERVER_ERROR)
        alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);

    else if (gdir.getStatus( ).code == G_GEO_MISSING_QUERY)
        alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

    else if (gdir.getStatus( ).code == G_GEO_BAD_KEY)
        alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

    else if (gdir.getStatus( ).code == G_GEO_BAD_REQUEST)
        alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

    else alert("An unknown error occurred.");
}

function onGDirectionsLoad( ){
    var directions = document.getElementById('directions');
    directions.style.display = 'block';
}

function loadGoogleMaps( ){
    if(GBrowserIsCompatible( )){
        maps = document.getElementsByTagName("div");

        for(var i = 0; i < maps.length; i++){
            var curMap = maps[i];
            if(curMap.id == "bizMap"){
                var coords = curMap.innerHTML;

                if(coords.match(/address\:/g)){
                    var address = coords.replace(/address\:/, '');

                    var info = '';
                    if(address.match(/\|\|info\:/g)){
                        var addA = address.split('||');
                        address = addA[0];

                        var info = addA[1].replace(/info\:/, '');
                    }

                    markAddress(address, curMap, info);
                }
                else{
                    coords = coords.split(",");
                    if(!coords[1]){
                        return;
                    }

                    var map = new GMap2(curMap);
                    map.setCenter(new GLatLng(coords[0], coords[1]), 16);
                    map.addControl(new GSmallMapControl());
                    map.addControl(new GMapTypeControl());

                    //map.openInfoWindowHtml(map.getCenter(),"html goes here");
                    //map.setMapType(G_HYBRID_MAP);

                    //Create Custom Icon
                    //var icon = new GIcon();
                    //icon.image = "/images/map_icon.png";
                    //icon.iconSize = new GSize(65, 31);
                    //icon.iconAnchor = new GPoint(32.5, 31);
                    //icon.infoWindowAnchor = new GPoint(5, 1);

                    var point = new GLatLng(coords[0], coords[1]);
                    map.addOverlay(new GMarker(point, icon));

                }
            }
        }
    }
}

var map;
var active_markers = new Array( );
var old_markers = new Array( );
var old_location = new String( );
var cur_id;
var prop_type;
var myPano;
var panoClient;
function loadMLSGoogleMap(mls_id, mls_type){
    if(GBrowserIsCompatible( )) {
        var lat_obj = document.getElementById('map_lat');
        var lng_obj = document.getElementById('map_lng');
        var msg_obj = document.getElementById('map_msg');
        var msg2_obj = document.getElementById('map_msg2');

        if(!lat_obj || !lng_obj || !msg_obj || !msg2_obj){ return; }

        var lat = lat_obj.innerHTML;
        var lon = lng_obj.innerHTML;

        var msg = unescape(msg_obj.innerHTML);
        msg = msg.replace(/\+/g, ' ');

        var msg2 = unescape(msg2_obj.innerHTML);
        msg2 = msg2.replace(/\+/g, ' ');

        var infoTabs = [new GInfoWindowTab("Address", msg), new GInfoWindowTab("Details", msg2)];

        var google_map_div = document.getElementById("map");
        var google_map_width = google_map_div.style.width.replace('px', '');
        var google_map_height = google_map_div.style.height.replace('px', '');

        map = new GMap2(google_map_div);

        var point = new GLatLng(lat, lon);

        var prev_zoom = getCookie('gmap_zoom');
        prev_zoom = parseInt(prev_zoom);
        if(prev_zoom > 0){
            map.setCenter(point, prev_zoom);
        }
        else{
            map.setCenter(point, 14);
        }

        map.addControl(new ExtLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GScaleControl());
        map.setMapType(G_HYBRID_MAP);

        var cur_icon = new GIcon( );
        cur_icon.image = "/images/mls/mls_blue.png";
        cur_icon.iconSize = new GSize(18, 35);
        cur_icon.iconAnchor = new GPoint(9, 34);

        marker_options = { icon:cur_icon, zIndexProcess:markerZIndex };

        var marker = new GMarker(point, marker_options);
        marker.importance = 1;
        map.addOverlay(marker);

        var sv_container = document.getElementById("google_pano");
        if(sv_container){
            panoClient = new GStreetviewClient( );

            myPano = new GStreetviewPanorama(sv_container);
            svOverlay = new GStreetviewOverlay( );
            map.addOverlay(svOverlay);
            myPano.setLocationAndPOV(point);
            GEvent.addListener(myPano, "error", handleNoFlash);
        }

        GEvent.addListener(marker, "click", function( ){
            if(sv_container){
                panoClient.getNearestPanorama(point, showPanoData);
            }

            map.openInfoWindowTabsHtml(point, infoTabs);
        });

        cur_id = mls_id;
        prop_type = mls_type;

        googleMapsMove( );
        GEvent.addListener(map, "moveend", googleMapsMove);

        ad_options = { channel:9645357042 };
        google_ads = new GAdsManager(map, 'pub-1299387018575068', ad_options);
        //google_ads = new GAdsManager(map, 'pub-1299387018575068');
        google_ads.enable( );
    }
    else{
        alert("Your browser does not support Google Maps, it is recommended you download Firefox from http://www.mozilla.com.");
    }
}

function markerZIndex(marker, b){
    return GOverlay.getZIndex(marker.getPoint( ).lat( )) + marker.importance * 1000000;
}

function googleMapsMove( ){
    var google_map_div = document.getElementById("map");
    var google_map_width = google_map_div.style.width.replace('px', '');
    var google_map_height = google_map_div.style.height.replace('px', '');

    var tl_corner_px = new GPoint(0, 0);
    var tl_corner_ll = map.fromContainerPixelToLatLng(tl_corner_px, true);

    var tl_corner_ll = new String(tl_corner_ll);
    var tl_corner_ll = tl_corner_ll.replace(/\)|\(/g, '');
    var tl_corner_ll = tl_corner_ll.replace(/\s+/, '');

    var br_corner_px = new GPoint(google_map_width  - 5, google_map_height - 5);
    var br_corner_ll = map.fromContainerPixelToLatLng(br_corner_px, true);

    var br_corner_ll = new String(br_corner_ll);
    var br_corner_ll = br_corner_ll.replace(/\)|\(/g, '');
    var br_corner_ll = br_corner_ll.replace(/\s+/, '');

    cur_zoom = map.getZoom( );
    setcookie('gmap_zoom', cur_zoom);
    if(old_location != ''){
        var old_tl_llA = old_location.split(',');
        var old_tl_lat = parseFloat(old_tl_llA[0]);
        var old_tl_lng = parseFloat(old_tl_llA[1]);

        var new_tl_llA = tl_corner_ll.split(',');
        var new_tl_lat = parseFloat(new_tl_llA[0]);
        var new_tl_lng = parseFloat(new_tl_llA[1]);

        //only refresh the markers if they've moved far enough
        //alert(cur_zoom);
        //alert(old_tl_llA);
        //alert(new_tl_llA);
        //alert(Math.abs(old_tl_lat - new_tl_lat));
        //alert(Math.abs(old_tl_lng - new_tl_lng));
        if(cur_zoom <= 7 && Math.abs(old_tl_lat - new_tl_lat) < .384 && Math.abs(old_tl_lng - new_tl_lng) < .384){
            return;
        }
        if(cur_zoom == 8 && Math.abs(old_tl_lat - new_tl_lat) < .192 && Math.abs(old_tl_lng - new_tl_lng) < .192){
            return;
        }
        if(cur_zoom == 9 && Math.abs(old_tl_lat - new_tl_lat) < .096 && Math.abs(old_tl_lng - new_tl_lng) < .096){
            return;
        }
        if(cur_zoom == 10 && Math.abs(old_tl_lat - new_tl_lat) < .048 && Math.abs(old_tl_lng - new_tl_lng) < .048){
            return;
        }
        if(cur_zoom == 11 && Math.abs(old_tl_lat - new_tl_lat) < .024 && Math.abs(old_tl_lng - new_tl_lng) < .024){
            return;
        }
        if(cur_zoom == 12 && Math.abs(old_tl_lat - new_tl_lat) < .012 && Math.abs(old_tl_lng - new_tl_lng) < .012){
            return;
        }
        if(cur_zoom == 13 && Math.abs(old_tl_lat - new_tl_lat) < .006 && Math.abs(old_tl_lng - new_tl_lng) < .006){
            return;
        }
        if(cur_zoom == 14 && Math.abs(old_tl_lat - new_tl_lat) < .003 && Math.abs(old_tl_lng - new_tl_lng) < .003){
            return;
        }
        if(cur_zoom == 15 && Math.abs(old_tl_lat - new_tl_lat) < .001 && Math.abs(old_tl_lng - new_tl_lng) < .001){
            return;
        }
        if(cur_zoom == 16 && Math.abs(old_tl_lat - new_tl_lat) < .0005 && Math.abs(old_tl_lng - new_tl_lng) < .0005){
            return;
        }
        if(cur_zoom == 17 && Math.abs(old_tl_lat - new_tl_lat) < .00025 && Math.abs(old_tl_lng - new_tl_lng) < .00025){
            return;
        }
        if(cur_zoom == 18 && Math.abs(old_tl_lat - new_tl_lat) < .00012 && Math.abs(old_tl_lng - new_tl_lng) < .00012){
            return;
        }
        if(cur_zoom == 19 && Math.abs(old_tl_lat - new_tl_lat) < .00006 && Math.abs(old_tl_lng - new_tl_lng) < .00006){
            return;
        }
    }

    old_location = tl_corner_ll;

    //alert("/get_markers.php?tl=" + tl_corner_ll + "&br=" + br_corner_ll);

    var request = GXmlHttp.create( );
    request.open("GET", "/get_markers.php?tl=" + tl_corner_ll + "&br=" + br_corner_ll + "&cz=" + cur_zoom + "&id=" + cur_id + "&pt=" + prop_type, true);
    request.onreadystatechange = function() {
        if(request.readyState == 4){
            document.getElementById('map_loader').style.display = 'none';
            var xmlDoc = GXml.parse(request.responseText);
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");

            old_markers = active_markers;
            active_markers = new Array( );
            for(var i = 0; i < markers.length; i++){
                var lat = parseFloat(markers[i].getAttribute("lat"));
                var lng = parseFloat(markers[i].getAttribute("lng"));

                var point = new GLatLng(lat, lng);

                var tabs = markers[i].getElementsByTagName('tab');
                var tab1 = unescape(markers[i].getAttribute("tab1"));
                tab1 = tab1.replace(/\+/g, ' ');
                var tab2 = unescape(markers[i].getAttribute("tab2"));
                tab2 = tab2.replace(/\+/g, ' ');

                var address = unescape(markers[i].getAttribute("address"));
                address = address.replace(/\+/g, ' ');

                if(!old_markers[point]){
                    var t_marker = createMLSMarker(point, tab1, tab2, address);
                    active_markers[point] = t_marker;
                }
                else{
                    active_markers[point] = old_markers[point];
                }
            }

            for(var k in old_markers){
                if(!active_markers[k]){
                    map.removeOverlay(old_markers[k]);
                    old_markers[k] = false;
                }
            }
        }
        else{
            document.getElementById('map_loader').style.display = 'block';
        }
    }
    request.send(null);
}

function createMLSMarker(point, tab1, tab2, address){
    if(GBrowserIsCompatible( )) {
        var infoTabs = [new GInfoWindowTab("Address", tab1), new GInfoWindowTab("Details", tab2)];

        var icon = new GIcon( );
        icon.image = "/images/mls/mls_orange.png";
        icon.iconSize = new GSize(18, 35);
        icon.iconAnchor = new GPoint(9, 35);

        var marker = new GMarker(point, icon);
        map.addOverlay(marker);

        var sv_container = document.getElementById("google_pano");
        GEvent.addListener(marker, "click", function( ){
            map.openInfoWindowTabsHtml(point, infoTabs);

            document.getElementById('endAddress').value = address;
            document.getElementById('endAddressDisp').innerHTML = address;

            if(sv_container){
                panoClient.getNearestPanorama(point, showPanoData);
            }
        });

        return marker;
    }
    else{
        alert("Your browser does not support Google Maps, it is recommended you download Firefox from http://www.mozilla.com.");
    }
}

function showPanoData(panoData) {
    if (panoData.code != 200) {
        //GLog.write('showPanoData: Server rejected with code: ' + panoData.code);
        return;
    }

    var sv_container = document.getElementById("google_pano");
    sv_container.style.display = 'block';

    myPano.setLocationAndPOV(panoData.location.latlng);
}

function handleNoFlash(errorCode){
    if(errorCode == 603){
        //alert("Error: Flash doesn't appear to be supported by your browser");
        return;
    }
}

function markAddress(address, curMap, info){
    var map = new GMap2(curMap);
    var geocoder = new GClientGeocoder( );

    geocoder.getLatLng(address,
        function(point){
            if(!point){
                alert("Google was unable to find " + address + " at this time, please make sure the address provided, is correct.");
            }
            else{
                map.setCenter(point, 13);
                map.addControl(new GSmallMapControl());
                map.addControl(new GMapTypeControl());

                var marker = new GMarker(point);
                map.addOverlay(marker);
                marker.openInfoWindowHtml("<div style=\"line-height: 1.2em; font-size: .9em\">" + info + "</div>");
            }
        }
    );

}

/* END GOOGLE MAPS */

//http://www.actionscript.org/forums/showthread.php3?t=132324
function makeWindowed(div){
    var p_div = document.getElementById(div);
    if(window.is_ie && (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1)){
        var html = "<iframe style=\"filter: Alpha(Opacity=60, FinishOpacity=60, Style=2); background-color: #000000; position: absolute; display: inline; z-index: -1; width: 100%; height: 854px; top: 0; left: 0; filter: mask( );\"></iframe>";

        if(p_div){
            p_div.innerHTML += html;
        }

        //force refresh of div
        var olddisplay = p_div.style.display;
        p_div.style.display = 'none';
        p_div.style.display = olddisplay;

        initAjaxTabs( );
        initDirPhoneNumbers( );
        initInputButtons( );
    }
}

function updateWorkingStates(tObj){
    var selected_states = '';

    var t_len = tObj.options.length;

    for(var i = 0; i < t_len; i++){
        t_opt = tObj.options[i];
        if(t_opt.selected){
            if(selected_states == ''){
                selected_states = t_opt.value;
            }
            else{
                selected_states = selected_states + ',' + t_opt.value;
            }
        }
    }

    setcookie('SelectedStates', selected_states);
}


/* attempt at a chat for the radio page and perhaps other areas */

var chatTimer;
var errorTimer;
var chatScrolling = false;
var orig_height = 500;
var refreshCount = 0;
function initChat( ){
    if(!document.getElementById('chat_container')){
        return false;
    }

    var chat_area = document.getElementById('chat_area');
    chat_area.onscroll = function( ){ chatScrolling = true; }

    getChat( );
}

function sendChatMessage( ){
    if(!document.getElementById('chat_container')){
        return false;
    }

    var csid = document.getElementById('csid').value;
    var uid = document.getElementById('uid').value;

    var tmessage = encodeURIComponent(document.getElementById('chat_message').value);
    document.getElementById('chat_message').value = '';

    if(tmessage == ''){
        return false;
    }

    chatURL = '/chat_ajax.php/action/send/uid/' + uid + '/csid/' + csid + '/?msg=' + tmessage;
    //alert(chatURL);
    b_xml.request(chatURL);

    clearInterval(chatTimer);
    getChat( );
}

function getChat( ){
    if(!document.getElementById('chat_container') || !c_xml){
        clearInterval(chatTimer);
        return false;
    }

    if(document.getElementById('chat_force_refresh')){
        clearInterval(chatTimer);
        errorTimer = setTimeout("chatErrorRefresh( )", 2000);
        return false;
    }

    var chat_area = document.getElementById('chat_area');
    var overflow = chat_area.scrollHeight - orig_height;
    if(overflow - chat_area.scrollTop <= 0 || refreshCount <= 1){
        chatScrolling = false;
    }

    //alert(chatScrolling);
    //alert(refreshCount);

    var csid = document.getElementById('csid').value;

    //alert('/chat_ajax.php/action/get/csid/' + csid);

    c_xml.request('/chat_ajax.php/action/get/csid/' + csid);


    if(!chatScrolling){
        chat_area.scrollTop = chat_area.scrollHeight;
    }

    refreshCount++;
    chatTimer = setTimeout("getChat( )", 1000);
}

function chatErrorRefresh( ){
    clearInterval(errorTimer);
    window.location.reload(true);
}

//********************
//*******ARMLS********
//********************

function initMLSRecords( ){
    if(document.getElementsByTagName){
        var search_container = document.getElementById('search_mls');
        if(search_container){
            var search_link = document.getElementById('mls_search_link');
            //search_container.style.display = 'none';
            search_link.onclick = function( ){
                if(search_container.style.display == 'none'){
                    search_container.style.display = 'block';
                }
                else{
                    search_container.style.display = 'none';
                }

                return false;
            }
        }

        var tbls = document.getElementsByTagName('table');
        var tlen = tbls.length;

        mlsHashA = new Array( );
        //
        var mlsCookie = getCookie("vMLS");
        if(mlsCookie != ''){
            var mlsCA = mlsCookie.split(/\|/);
            var mlsCLen = mlsCA.length;

            //alert(mlsCLen);
            for(var i = 0; i < mlsCLen; i++){
                mlsHashA["-" + mlsCA[i] + "-"] = new Object;
                mlsHashA["-" + mlsCA[i] + "-"].num = mlsCA[i];
            }
        }
        //

        wl_mlsHashA = new Array( );
        //
        var mlsCookie = getCookie("wlMLS");
        if(mlsCookie != ''){
            var mlsCA = mlsCookie.split(/\|/);
            var mlsCLen = mlsCA.length;

            //alert(mlsCLen);
            for(var i = 0; i < mlsCLen; i++){
                wl_mlsHashA["++" + mlsCA[i] + "++"] = new Object;
                wl_mlsHashA["++" + mlsCA[i] + "++"].num = mlsCA[i];
            }
        }

        for(var i = 0; i < tlen; i++){
            var tbl = tbls[i];
            if(tbl.className != 'mls_show'){
                continue;
            }

            var trs = tbl.getElementsByTagName("tr");
            var len = trs.length;

            for(var j = 0; j < len; j++){
                var tr = trs[j];

                //
                var trID = tr.id;
                var idA = trID.split(/\-/);
                var mlsNum = idA[1];

                for(var m in mlsHashA){
                    mls = m.replace(/\-/g, '');
                    if(mlsNum == mls){
                        tr.className = "cellVisited";
                    }
                }
                //

                for(var m in wl_mlsHashA){
                    m = m.replace(/\+\+/g, '');
                    var mlsA = m.split(/\-/g);
                    //alert(m);

                    var mls = '';
                    if(mlsA[2]){
                        var mls = mlsA[2];
                        //alert(mls);
                    }

                    if(mlsNum == mls){
                        tr.className = "cellWishlist";
                    }
                }

                var tds = tr.getElementsByTagName("td");
                var tdlen = tds.length;

                for(var k = 0; k < tdlen; k++){
                    var td = tds[k];
                    if(tr.id != ''){

                        tr.onmouseover = function( ){
                            var tId = this.id;
                            this.classNameBak = this.className;
                            this.className = "cellOver";
                        }
                        tr.onmouseout = function( ){
                            this.className = this.classNameBak;
                        }
                        td.onclick = function( ){
                            //alert(this.className + " " + k);
                            if(this.className != 'mapLnk'){
                                //cid=489807&mlnum=1825375&ALLMLS=Y&class=2&themecolor=29048C&sTYPE=0&PUBLICID=
                                //http://www.har.com/search/idx/DispSearch.cfm?cid=489807&mlnum=2529844&ALLMLS=Y&class=2&themecolor=29048C&sTYPE=0&PUBLICID=
                                //http://www.har.com/search/idx/DispSearch.cfm?cid=489807&mlnum=1595059&ALLMLS=Y&class=2&themecolor=29048C&sTYPE=0&PUBLICID=


                                var trId = (this.parentNode.id);
                                //alert(trId);
                                var idA = trId.split(/\-/);

                                //
                                this.parentNode.classNameBak = "cellVisited";
                                this.parentNode.className = "cellVisited";
                                var mlsCookie = getCookie("vMLS");

                                setcookie("vMLS", mlsCookie + idA[1] + "|");
                                //

                                if(idA.length == 3){
                                    var t_type = idA[0].toLowerCase( );
                                    var t_id = idA[1];
                                    var t_class = null;

                                    //var lnk = "/mls/az/view_mls_" + t_type + ".php?mls=" + t_id;
                                    var lnk = "/text/view_arizona_mls_listing.html?propType=" + t_type + "&mls=" + t_id;

                                    mlsPopup(lnk);
                                }
                            }
                        }
                    }
                }
            }//end for each trs
        }//end foreach table
    }
}

function mlsPopup(lnk){
    if(!lnk){ return; }

    var mlsPop = window.open(lnk, "mlsPopUp", "width=820,height=580,menubar=yes,toolbar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
    mlsPop.focus( );

    return false;
}

function getCookie(cname){
    var dc = document.cookie;
    var prefix = cname + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1){
        begin = dc.indexOf(prefix);
        if (begin != 0) return '';
    }
    else{
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1){
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function mlsPopUp(loc, w, h, scrollB){
    if(!scrollB){
        scrollB = 0;
    }

    mlsPopUpWin = window.open(loc, "gpopup", "width=" + w + ",height=" + h + ", scrollbars=" + scrollB + ", status=no,toolbar=no,resizable=yes");
    mlsPopUpWin.focus( );
}

function changeMLSImg(imgIndex){
    var imgC = document.getElementById('imgMain');
    var imgD = document.getElementById('imgDesc');

    if(!imgC || !imgD || !imgA || !imgDescA){
        return;
    }

    imgC.src = imgA[imgIndex].src;
    imgD.innerHTML = imgDescA[imgIndex];
}

function changeGalleryImg(imgSrc, imgDesc){
    var imgC = document.getElementById('mainImage');
    var imgD = document.getElementById('mainImageDesc');

    if(!imgC || !imgD || !imgSrc){
        return;
    }

    imgC.getElementsByTagName('img')[0].src = imgSrc;
    imgD.innerHTML = imgDesc;
}

//***********************
//Google Map Properties *
//***********************

function getMap(mlsID, m_type){
    if(!m_type || m_type == ''){
        m_type = 'res';
    }

    var mapPopup = window.open('http://www.voiceofnorthamerica.com/mls/az/mls_map_' + m_type + '.php?id=' + mlsID + '&pt=' + m_type, "MLSMap", "width=600,height=500, menubar=no, location=no, scrollbars=yes, status=no,toolbar=no,resizable=yes");
    mapPopup.focus( );
}

//***************************
//END Google Map Properties *
//***************************


function changeImg(newImg, imgProps){
    var mainImg = document.getElementById('mainPropImg');

    if(!mainImg){
        return;
    }

    mainImg.src = newImg;
    mainImg.setAttribute('style', imgProps);

    if(document.all){
        var imgPropsA = imgProps.split('; ');

        var widthStr = imgPropsA[0];
        var widthStrA = widthStr.split(': ');

        var heightStr = imgPropsA[1];
        var heightStrA = heightStr.split(': ');

        var newWidth = widthStrA[1];
        var newHeight = heightStrA[1];

        mainImg.style.width = newWidth;
        mainImg.style.height = newHeight;
    }
}

function changeGalleryImg(imgSrc){
    var imgC = document.getElementById('mainImage');

    if(!imgC || !imgSrc){
        return;
    }

    imgC.getElementsByTagName('img')[0].src = imgSrc;
}

/*function initHomeRotator( ){
    var prop_container = document.getElementById('main_prop_info');
    if(!prop_container){
        return false;
    }

    if(!rotator_stopped){
        home_pointer++;
        setTimeout("loadHome('')", 5000);
    }
}*/

function loadHome(pointer){
    if(!b_xml){ return false; }

    //stop the home rotator in its tracks but allow for clicks
    if(rotator_stopped){ rotator_stopped = false; return false; }

    if(!pointer || pointer == ''){
        pointer = home_pointer;
    }
    else{
        //this means a click called this function
        rotator_stopped = true;
    }

    pointer = parseInt(pointer);

    if(pointer > 4 || pointer < 0){
        pointer = 0;
        home_pointer = pointer;
    }

    //alert('/ajax.php/type/hr/pointer/' + pointer);
    b_xml.request('/ajax.php/type/hr/pointer/' + pointer);

    /*if(!rotator_stopped){
        //alert('here');
        //home_pointer++;
        //setTimeout("loadHome('')", 5000);
    }*/

}

//********************
//*****END ARMLS******
//********************

//auto-save articles? sounds fun
function initSaveArticleDraft( ){
    var save_article_form = document.getElementById('save_article_form');
    var save_article = document.getElementById('save_article');
    var article_title = document.getElementById('ArticleTitle');

    if(!save_article_form || !save_article || !article_title){
        return;
    }

    //don't want it to save right away because there is no need to
    setTimeout("saveArticleDraft( )", 30000);
}

function saveArticleDraft( ){
    var save_article_form = document.getElementById('save_article_form');
    var save_article = document.getElementById('save_article');
    var article_title = document.getElementById('ArticleTitle');

    if(!save_article_form || !save_article || !article_title){
        return;
    }

    document.getElementById('save_title').value = article_title.value;

    var docText = '';
    if(window.is_ie){
        docText = bgz.document.body.innerHTML;
    }
    else{
        docText = document.getElementById('bgz').contentWindow.document.body.innerHTML;
    }

    document.getElementById('save_body').value = docText;

    save_article_form.submit( );

    //keep it going
    setTimeout("saveArticleDraft( )", 30000);
}

function refreshSImg(sImg){
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomStr = '';
	for (var i = 0; i < string_length; i++) {
		var rnum = Math.floor(Math.random( ) * chars.length);
		randomStr += chars.substring(rnum, rnum+1);
	}

	var sImgSrc = sImg.src;
	if(sImgSrc.match('&')){
	    sImgSrcA = sImgSrc.split('&');
	    sImgSrc = sImgSrcA[0];
	}

    sImg.src = sImgSrc + '&' + randomStr;
}