// CONFIRM PROMPT
function confirm_prompt(text, url) {
    if (confirm(text)) {
        window.location = url;
    }
    return false;
}


// POPUP
/* <a href="http://www.google.com/" onclick="return doPopup(this.href, {location:'yes'});" target="_new">Test</a> */
function doPopup(url, options) {
    var Popup = {
        open: function(url, options) {
            this.options = {
                width: 600,
                height: 500,
                name: '_blank',
                location: 'no',
                menubar: 'no',
                toolbar: 'no',
                status: 'yes',
                scrollbars: 'yes',
                resizable: 'yes',
                top: '',
                left: '',
                center: true
            }
            Object.extend(this.options, options || {});
            this.options.width = this.options.width < screen.availWidth ? this.options.width : screen.availWidth;
            this.options.height = this.options.height < screen.availHeight ? this.options.height : screen.availHeight;
            if (this.options.center) {
                this.options.top = (screen.height - this.options.height) / 2 ;
                this.options.left = (screen.width - this.options.width) / 2;
            }
            var openoptions = 'width=' +this.options.width+ ',height=' +this.options.height+ ',location=' +this.options.location+ ',menubar=' +this.options.menubar+ ',toolbar=' +this.options.toolbar+ ',scrollbars=' +this.options.scrollbars+ ',resizable=' +this.options.resizable+ ',status=' +this.options.status
            if (this.options.top != '') openoptions += ',top=' +this.options.top;
            if (this.options.left != '') openoptions += ',left=' +this.options.left;
            window.open(url, this.options.name, openoptions);
            return false;
        }
    }
    return Popup.open(url, options);
}


/* PRELOADING IMAGES */

var preloadFlag = false;

function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function preloadImages() {
    if (document.images) {
        over_findlodging = newImage('http://images1.statecollege.com/homenav/lodging_over.jpg');
        over_diningguide = newImage('http://images1.statecollege.com/homenav/diningguide_over.jpg');
        over_rentalguide = newImage('http://images1.statecollege.com/homenav/rentalguide_over.gif');
        over_realestateguide = newImage('http://images1.statecollege.com/homenav/realestate_over.jpg');
        over_autosearch = newImage('http://images1.statecollege.com/homenav/autosearch_over.jpg');
        preloadFlag = true;
    }
}


function changeImages() {
    if (document.images && (preloadFlag == true)) {
        for (var i=0; i<changeImages.arguments.length; i+=2) {
            document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
        }
    }
}

// TURN ON OR OFF THE ADD TO MYCALENDAR DIV
function setAdding (adding, url) {

    new Ajax.Request('/mycalendar/calls/set_adding.php', {
        asynchronous: true, method:'post', postBody:'adding=' +adding,
        onSuccess: function (t) {
            if (t.responseText != '1') {
                $('addingBox').style.display = 'none';
            }
            if (url) {
                window.location.href = url;
            }
            return false;
        },
        onFailure: function (t) {
            return true;
        }
    });
    
    return false;
    
}

function personalsNotInterested (account, id, flag) {
    
    new Ajax.Request('/personals/calls/not_interested.php', {
        method: 'post', postBody: 'account=' + account + '&not_interested=' + id + '&flag=' + flag,
        onSuccess: function(transport) {
            resp = transport.responseText;
            if (resp == '1') {
                $('personal_' + id).fade();
            }
        }
    });
    
}

function personalsToggle (id) {

    if ($('personal_expand_' +id).style.display != 'none') {
        $('personal_expand_' +id).style.display = 'none';
        $('personal_collapse_' +id).style.display = 'block';
    } else {
        $('personal_expand_' +id).style.display = 'block';
        $('personal_collapse_' +id).style.display = 'none';
    }
    new Effect.toggle($('personal_details_' + id), 'blind', {duration: .4});
    

}

// ADD MY BUSINESS POPUP
function addmybusiness_popUp(URL, w, h) {
    day = new Date();
    id = day.getTime();
    var loc_w = (screen.width - w) / 2;
    var loc_h = (screen.height - h) / 2;
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + w + ",height=" + h + ",left=" + loc_w + ",top=" + loc_h + "');");
}

// LOG & SHOW PHONE # CLICK
function ajax_clicklogPhone(span_id, business_id, phone_number, clicklog_area, clicklog_itemid) {
    new Ajax.Request('/includes/ajax/calls/clicklogPhone.php', {
        method:'get',
        parameters: {span_id: span_id, business_id: business_id, phone_number: phone_number, clicklog_area: clicklog_area, clicklog_itemid: clicklog_itemid},
        onSuccess: function(transport) {
            var resp = (transport.responseText).evalJSON();
            if ((resp['span_id']) && (resp['phone_number'])) {
                $(resp['span_id']).update(resp['phone_number']);
            }
        }
    });
}



/* AUTOS */

function autosearch_changeTab(el, mode) {

    $$('.astab').each(function(item) {
        item.removeClassName(item.id+ '_on');
        item.removeClassName(item.id+ '_off');
        if (item != el) item.addClassName(item.id+ '_off');
    });

    el.addClassName(el.id+ '_' +mode);

    if (el.id == 'nctab') {
        $('div_autosearch').removeClassName('uctab');
        $('div_autosearch').addClassName('nctab');
        $('input_asnew').value = '1';
        $('input_asused').value = '';
    }

    if (el.id == 'uctab') {
        $('div_autosearch').removeClassName('nctab');
        $('div_autosearch').addClassName('uctab');
        $('input_asnew').value = '';
        $('input_asused').value = '1';
    }

}

// TRACK THE BUSINESS CLICK
function trackBusiness(business_id, mode)
{

    var url = '/business/calls/track.php?business_id=' + business_id + '&mode=' + mode;

    new Ajax.Request(url, 
    {
        method: 'get',
        onComplete: function(transport) 
        {
            return true;
        }
        
    }); 
    
    //return false;
    return true; // even if it fails we still want them to be able to use the link
       
}


