function popUp(url, w, h){
    window.open(url, "win", 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width='+w+',height='+h);
}

function addToFavorites()
{
    var urlAddress = "http://www.e-golfguide.com/";
    var pageName = "E-Golfguide.com (BCgolfguide.com Inc 1-877-223-7226)";

    if (window.external)
    {
        window.external.AddFavorite(urlAddress,pageName)
    }
    else
    {
        alert("Sorry! Your browser doesn't support this function.");
    }
}

function checkEmailAddress(field) {
    var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.ca)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
    if (goodEmail) return true;
    alert('Enter a valid e-mail address.')
    field.focus()
    field.select()
    return false;
}

function mailThisUrl(){
    if (checkEmailAddress(document.email_page.sendaddress))
        window.location = "mailto:"+document.email_page.sendaddress.value+"?subject=This golf web page and site may interest you.&body="+document.title+" "+window.location;
}

$.fn.outerHTML = function(s) {
    return (s)
    ? this.before(s).remove()
    : jQuery("<p>").append(this.eq(0).clone()).html();
};

$(function(){
    /* Print
--------------------------------------------------------------------------------------- */   
    try{
        $('#btnPrint').click(function(e){
            e.stopImmediatePropagation();
            e.stopPropagation();
            
            var $header = $('#header').eq(0).clone();
            var $content = $('#content-wrapper').eq(0).clone();
            
            $content.find('#rightcol').remove();
            $content.find('script[src]').remove();
            $header.find('#header-navigation').remove();
            $header.find('.tickercontainer').remove();
            
            var html = [
            '<!doctype html><html><head>',
            $('head').html(),
            '</head><body class="print">',
            $header.outerHTML(),
            $content.outerHTML(),
            '</body></html>'
            ];
            
            var wwin = window.open("","printWebPart", "scrollbars=1,status=1,toolbar=0,width=840, height=400");
            if(window.focus) wwin.focus();
            wwin.document.open();
            wwin.document.write(html.join(''));
            wwin.document.close();
            wwin.print();
        });
    }catch(e){}
    
    /* Ticker
--------------------------------------------------------------------------------------- */   
    try{
        $("ul#ticker01").liScroll();
    }catch(e){}
    
    /* Fade callouts
--------------------------------------------------------------------------------------- */   
    try{
        $('.fade').innerfade({
            speed: 'slow',
            timeout: 8000,
            type: 'sequence',
            containerheight: '390px'
        });
    }catch(e){}
    
    /* Calendar
--------------------------------------------------------------------------------------- */   
    try{
        $( ".dates_arrival" ).val(arrival!=''?arrival:checkin).datepicker({
            showOn: "button",
            buttonImage: "/inc/calendar/calendar6.gif",
            buttonImageOnly: true,
            dateFormat: "yy-mm-dd"
        });
        $( ".dates_depart" ).val(depart!=''?depart:checkout).datepicker({
            showOn: "button",
            buttonImage: "/inc/calendar/calendar6.gif",
            buttonImageOnly: true,
            dateFormat: "yy-mm-dd"
        });
        $( ".dates_arrival_" ).val(arrival!=''?arrival:checkin).datepicker({
            showOn: "button",
            buttonImage: "/inc/calendar/calendar6.gif",
            buttonImageOnly: true,
            dateFormat: "yy-mm-dd"
        });
        $( ".dates_depart_" ).val(depart!=''?depart:checkout).datepicker({
            showOn: "button",
            buttonImage: "/inc/calendar/calendar6.gif",
            buttonImageOnly: true,
            dateFormat: "yy-mm-dd"
        });
    }catch(e){}
    
    /* bgStretcher
--------------------------------------------------------------------------------------- */   
//    try{
//        if(! $('body').hasClass('print')){
//            $(document).bgStretcher({
//                images: ['/2011/images/interface/bg-01.jpg'],
//                imageWidth: 1423, 
//                imageHeight: 1018
//            });
//        }
//    }catch(e){}
    
    /* sendEmail
--------------------------------------------------------------------------------------- */   
    try{
        $('#send-email').hide(); // Hide even though it's already hidden
   
        $('#sendEmail').click(function() {
            $('#send-email').toggle(400); // First click should toggle to 'show'
            return false;
        });	   
	   

        $('#sendCancel').click(function() {
            $('#send-email').toggle(400); // First click should toggle to 'show'
            return false;
        });
    }catch(e){}

});

